- def __init__(self, config=None, name=None, flavor=None, port_settings=list(), security_group_names=set(),
- floating_ip_settings=list(), sudo_user=None, vm_boot_timeout=900,
- vm_delete_timeout=300, ssh_connect_timeout=180, availability_zone=None, userdata=None):
- """
- Constructor
- :param config: dict() object containing the configuration settings using the attribute names below as each
- member's the key and overrides any of the other parameters.
- :param name: the name of the VM
- :param flavor: the VM's flavor
- :param port_settings: the port configuration settings (required)
- :param security_group_names: a set of names of the security groups to add to the VM
- :param floating_ip_settings: the floating IP configuration settings
- :param sudo_user: the sudo user of the VM that will override the instance_settings.image_user when trying to
- connect to the VM
- :param vm_boot_timeout: the amount of time a thread will sleep waiting for an instance to boot
- :param vm_delete_timeout: the amount of time a thread will sleep waiting for an instance to be deleted
- :param ssh_connect_timeout: the amount of time a thread will sleep waiting obtaining an SSH connection to a VM
- :param availability_zone: the name of the compute server on which to deploy the VM (optional)
- :param userdata: the cloud-init script to run after the VM has been started
- """
- if config:
- self.name = config.get('name')
- self.flavor = config.get('flavor')
- self.sudo_user = config.get('sudo_user')
- self.userdata = config.get('userdata')
-
- self.port_settings = list()
- if config.get('ports'):
- for port_config in config['ports']:
- if isinstance(port_config, PortSettings):
- self.port_settings.append(port_config)
- else:
- self.port_settings.append(PortSettings(config=port_config['port']))
-
- if config.get('security_group_names'):
- if isinstance(config['security_group_names'], list):
- self.security_group_names = set(config['security_group_names'])
- elif isinstance(config['security_group_names'], set):
- self.security_group_names = config['security_group_names']
- elif isinstance(config['security_group_names'], str):
- self.security_group_names = [config['security_group_names']]
- else:
- raise Exception('Invalid data type for security_group_names attribute')
- else:
- self.security_group_names = set()