def execute(self, compute_id, amphora_id, availability_zone): """Wait for the compute driver to mark the amphora active :param compute_id: virtual machine UUID :param amphora_id: id of the amphora object :param availability_zone: availability zone metadata dictionary :raises: Generic exception if the amphora is not active :returns: An amphora object """ if availability_zone: amp_network = availability_zone.get(constants.MANAGEMENT_NETWORK) else: amp_network = None for i in range(CONF.controller_worker.amp_active_retries): amp, fault = self.compute.get_amphora(compute_id, amp_network) if amp.status == constants.ACTIVE: if CONF.haproxy_amphora.build_rate_limit != -1: self.rate_limit.remove_from_build_req_queue(amphora_id) return amp.to_dict() if amp.status == constants.ERROR: raise exceptions.ComputeBuildException(fault=fault) time.sleep(CONF.controller_worker.amp_active_wait_sec) raise exceptions.ComputeWaitTimeoutException(id=compute_id)
def build(self, name="amphora_name", amphora_flavor=None, image_id=None, image_tag=None, key_name=None, sec_groups=None, network_ids=None, port_ids=None, config_drive_files=None, user_data=None, server_group_id=None): '''Create a new virtual machine. :param name: optional name for amphora :param amphora_flavor: image flavor for virtual machine :param image_id: image ID for virtual machine :param image_tag: image tag for virtual machine :param key_name: keypair to add to the virtual machine :param sec_groups: Security group IDs for virtual machine :param network_ids: Network IDs to include on virtual machine :param port_ids: Port IDs to include on virtual machine :param config_drive_files: An optional dict of files to overwrite on the server upon boot. Keys are file names (i.e. /etc/passwd) and values are the file contents (either as a string or as a file-like object). A maximum of five entries is allowed, and each file must be 10k or less. :param user_data: Optional user data to pass to be exposed by the metadata server this can be a file type object as well or a string :param server_group_id: Optional server group id(uuid) which is used for anti_affinity feature :raises ComputeBuildException: if nova failed to build virtual machine :returns: UUID of amphora ''' try: network_ids = network_ids or [] port_ids = port_ids or [] nics = [] if network_ids: nics.extend([{"net-id": net_id} for net_id in network_ids]) if port_ids: nics.extend([{"port-id": port_id} for port_id in port_ids]) server_group = None if server_group_id is None else { "group": server_group_id} image_id = _get_image_uuid( self._glance_client, image_id, image_tag) amphora = self.manager.create( name=name, image=image_id, flavor=amphora_flavor, key_name=key_name, security_groups=sec_groups, nics=nics, files=config_drive_files, userdata=user_data, config_drive=True, scheduler_hints=server_group ) return amphora.id except Exception: LOG.exception(_LE("Error building nova virtual machine.")) raise exceptions.ComputeBuildException()
def execute(self, compute_id, amphora_id): """Wait for the compute driver to mark the amphora active""" for i in range(CONF.a10_controller_worker.amp_active_retries): amp, fault = self.compute.get_amphora(compute_id) if amp.status == constants.ACTIVE: if CONF.a10_controller_worker.build_rate_limit != -1: self.rate_limit.remove_from_build_req_queue(amphora_id) return amp elif amp.status == constants.ERROR: raise exceptions.ComputeBuildException(fault=fault) time.sleep(CONF.a10_controller_worker.amp_active_wait_sec) raise exceptions.ComputeWaitTimeoutException(id=compute_id)
def execute(self, compute_id): """Wait for the compute driver to mark the amphora active :raises: Generic exception if the amphora is not active :returns: An amphora object """ for i in range(CONF.controller_worker.amp_active_retries): amp = self.compute.get_amphora(compute_id) if amp.status == constants.ACTIVE: return amp elif amp.status == constants.ERROR: raise exceptions.ComputeBuildException() time.sleep(CONF.controller_worker.amp_active_wait_sec) raise exceptions.ComputeWaitTimeoutException()
def execute(self, compute_id, amphora_id): """Wait for the compute driver to mark the amphora active :raises: Generic exception if the amphora is not active :returns: An amphora object """ for i in range(CONF.controller_worker.amp_active_retries): amp = self.compute.get_amphora(compute_id) if amp.status == constants.ACTIVE: if CONF.haproxy_amphora.build_rate_limit != -1: self.rate_limit.remove_from_build_req_queue(amphora_id) return amp elif amp.status == constants.ERROR: raise exceptions.ComputeBuildException() time.sleep(CONF.controller_worker.amp_active_wait_sec) raise exceptions.ComputeWaitTimeoutException()
def build(self, name="amphora_name", amphora_flavor=None, image_id=None, image_tag=None, image_owner=None, key_name=None, sec_groups=None, network_ids=None, port_ids=None, config_drive_files=None, user_data=None, server_group_id=None): '''Create a new virtual machine. :param name: optional name for amphora :param amphora_flavor: image flavor for virtual machine :param image_id: image ID for virtual machine :param image_tag: image tag for virtual machine :param key_name: keypair to add to the virtual machine :param sec_groups: Security group IDs for virtual machine :param network_ids: Network IDs to include on virtual machine :param port_ids: Port IDs to include on virtual machine :param config_drive_files: An optional dict of files to overwrite on the server upon boot. Keys are file names (i.e. /etc/passwd) and values are the file contents (either as a string or as a file-like object). A maximum of five entries is allowed, and each file must be 10k or less. :param user_data: Optional user data to pass to be exposed by the metadata server this can be a file type object as well or a string :param server_group_id: Optional server group id(uuid) which is used for anti_affinity feature :raises ComputeBuildException: if nova failed to build virtual machine :returns: UUID of amphora ''' try: network_ids = network_ids or [] port_ids = port_ids or [] nics = [] if network_ids: nics.extend([{"net-id": net_id} for net_id in network_ids]) if port_ids: nics.extend([{"port-id": port_id} for port_id in port_ids]) server_group = None if server_group_id is None else { "group": server_group_id } image_id = _get_image_uuid(self._glance_client, image_id, image_tag, image_owner) if CONF.nova.random_amphora_name_length: r = random.SystemRandom() name = "a{}".format("".join([ r.choice(string.ascii_uppercase + string.digits) for i in range(CONF.nova.random_amphora_name_length - 1) ])) block_device_mapping = {} if CONF.nova.use_cinder: # creating volume LOG.debug('Creating volume for amphorae') cinder_id = _create_cinder_volume( self._cinder_client, image_id, CONF.cinder.volume_size, CONF.cinder.availability_zone) # If use volume based, does not require image ID anymore image_id = "" block_device_mapping = {'vda': '%s:::true' % cinder_id} amphora = self.manager.create( name=name, image=image_id, flavor=amphora_flavor, block_device_mapping=block_device_mapping, key_name=key_name, security_groups=sec_groups, nics=nics, files=config_drive_files, userdata=user_data, config_drive=True, scheduler_hints=server_group, availability_zone=CONF.nova.availability_zone) return amphora.id except Exception as e: LOG.exception("Nova failed to build the instance due to: %s", e) raise exceptions.ComputeBuildException(fault=e)
def build(self, name="amphora_name", amphora_flavor=None, image_tag=None, image_owner=None, key_name=None, sec_groups=None, network_ids=None, port_ids=None, config_drive_files=None, user_data=None, server_group_id=None, availability_zone=None): '''Create a new virtual machine. :param name: optional name for amphora :param amphora_flavor: image flavor for virtual machine :param image_tag: image tag for virtual machine :param key_name: keypair to add to the virtual machine :param sec_groups: Security group IDs for virtual machine :param network_ids: Network IDs to include on virtual machine :param port_ids: Port IDs to include on virtual machine :param config_drive_files: An optional dict of files to overwrite on the server upon boot. Keys are file names (i.e. /etc/passwd) and values are the file contents (either as a string or as a file-like object). A maximum of five entries is allowed, and each file must be 10k or less. :param user_data: Optional user data to pass to be exposed by the metadata server this can be a file type object as well or a string :param server_group_id: Optional server group id(uuid) which is used for anti_affinity feature :param availability_zone: Name of the compute availability zone. :raises ComputeBuildException: if nova failed to build virtual machine :returns: UUID of amphora ''' volume_id = None try: network_ids = network_ids or [] port_ids = port_ids or [] nics = [] if network_ids: nics.extend([{"net-id": net_id} for net_id in network_ids]) if port_ids: nics.extend([{"port-id": port_id} for port_id in port_ids]) server_group = None if server_group_id is None else { "group": server_group_id } az_name = availability_zone or CONF.nova.availability_zone image_id = self.image_driver.get_image_id_by_tag( image_tag, image_owner) if CONF.nova.random_amphora_name_length: r = random.SystemRandom() name = "a{}".format("".join([ r.choice(string.ascii_uppercase + string.digits) for i in range(CONF.nova.random_amphora_name_length - 1) ])) block_device_mapping = {} if (CONF.controller_worker.volume_driver != constants.VOLUME_NOOP_DRIVER): # creating volume LOG.debug('Creating volume for amphora from image %s', image_id) volume_id = self.volume_driver.create_volume_from_image( image_id) LOG.debug('Created boot volume %s for amphora', volume_id) # If use volume based, does not require image ID anymore image_id = None # Boot from volume with parameters: target device name = vda, # device id = volume_id, device type and size unspecified, # delete-on-terminate = true (volume will be deleted by Nova # on instance termination) block_device_mapping = {'vda': '%s:::true' % volume_id} amphora = self.manager.create( name=name, image=image_id, flavor=amphora_flavor, block_device_mapping=block_device_mapping, key_name=key_name, security_groups=sec_groups, nics=nics, files=config_drive_files, userdata=user_data, config_drive=True, scheduler_hints=server_group, availability_zone=az_name) return amphora.id except Exception as e: if (CONF.controller_worker.volume_driver != constants.VOLUME_NOOP_DRIVER): self.volume_driver.delete_volume(volume_id) LOG.exception("Nova failed to build the instance due to: %s", str(e)) raise exceptions.ComputeBuildException(fault=e)