def get_flavor_id(nova_client, flavor): ''' Get the id for the specified flavor name. :param nova_client: the nova client to use :param flavor: the name of the flavor to find :returns: the id of :flavor: :raises: exception.FlavorMissing ''' flavor_id = None flavor_list = nova_client.flavors.list() for o in flavor_list: if o.name == flavor: flavor_id = o.id break if flavor_id is None: raise exception.FlavorMissing(flavor_id=flavor) return flavor_id
def get_flavor_id(self, flavor): """Get the id for the specified flavor name. If the specified value is flavor id, just return it. :param flavor: the name of the flavor to find :returns: the id of :flavor: :raises: exception.FlavorMissing """ try: flavor_list = self.client().flavors.list() except LavaError as exc: LOG.info("Unable to read CBD flavor list", exc_info=exc) raise for bigdata_flavor in flavor_list: if bigdata_flavor.name == flavor: return bigdata_flavor.id LOG.info("Unable to find CBD flavor %s", flavor) raise exception.FlavorMissing(flavor_id=flavor)
def get_flavor_id(self, flavor): ''' Get the id for the specified flavor name. If the specified value is flavor id, just return it. :param flavor: the name of the flavor to find :returns: the id of :flavor: :raises: exception.FlavorMissing ''' flavor_id = None flavor_list = self.client().flavors.list() for o in flavor_list: if o.name == flavor: flavor_id = o.id break if o.id == flavor: flavor_id = o.id break if flavor_id is None: raise exception.FlavorMissing(flavor_id=flavor) return flavor_id
def get_flavor_id(nova_client, flavor): warnings.warn('nova_utils.get_flavor_id is deprecated. ' 'Use self.client_plugin("nova").get_flavor_id') ''' Get the id for the specified flavor name. If the specified value is flavor id, just return it. :param nova_client: the nova client to use :param flavor: the name of the flavor to find :returns: the id of :flavor: :raises: exception.FlavorMissing ''' flavor_id = None flavor_list = nova_client.flavors.list() for o in flavor_list: if o.name == flavor: flavor_id = o.id break if o.id == flavor: flavor_id = o.id break if flavor_id is None: raise exception.FlavorMissing(flavor_id=flavor) return flavor_id
def handle_create(self): if self.properties.get('SecurityGroups') is None: security_groups = None else: security_groups = [ self.physical_resource_name_find(sg) for sg in self.properties.get('SecurityGroups') ] userdata = self.properties['UserData'] or '' flavor = self.properties['InstanceType'] key_name = self.properties['KeyName'] availability_zone = self.properties['AvailabilityZone'] keypairs = [k.name for k in self.nova().keypairs.list()] if key_name not in keypairs and key_name is not None: raise exception.UserKeyPairMissing(key_name=key_name) image_name = self.properties['ImageId'] image_id = None image_list = self.nova().images.list() for o in image_list: if o.name == image_name: image_id = o.id break if image_id is None: logger.info("Image %s was not found in glance" % image_name) raise exception.ImageNotFound(image_name=image_name) flavor_id = None flavor_list = self.nova().flavors.list() for o in flavor_list: if o.name == flavor: flavor_id = o.id break if flavor_id is None: raise exception.FlavorMissing(flavor_id=flavor) tags = {} if self.properties['Tags']: for tm in self.properties['Tags']: tags[tm['Key']] = tm['Value'] else: tags = None scheduler_hints = {} if self.properties['NovaSchedulerHints']: for tm in self.properties['NovaSchedulerHints']: scheduler_hints[tm['Key']] = tm['Value'] else: scheduler_hints = None nics = self._build_nics(self.properties['NetworkInterfaces'], subnet_id=self.properties['SubnetId']) server_userdata = self._build_userdata(userdata) server = None try: server = self.nova().servers.create( name=self.physical_resource_name(), image=image_id, flavor=flavor_id, key_name=key_name, security_groups=security_groups, userdata=server_userdata, meta=tags, scheduler_hints=scheduler_hints, nics=nics, availability_zone=availability_zone) finally: # Avoid a race condition where the thread could be cancelled # before the ID is stored if server is not None: self.resource_id_set(server.id) return server