def __init__(self, scheduler_driver=None, *args, **kwargs): super(ConsoleAuthManager, self).__init__(service_name='consoleauth', *args, **kwargs) self._mc = None self._mc_instance = None self.compute_rpcapi = compute_rpcapi.ComputeAPI() self.cells_rpcapi = cells_rpcapi.CellsAPI()
def __init__(self, *args, **kwargs): super(ComputeCellsAPI, self).__init__(*args, **kwargs) self.cells_rpcapi = cells_rpcapi.CellsAPI() # Avoid casts/calls directly to compute self.compute_rpcapi = ComputeRPCAPIRedirect(self.cells_rpcapi) # Redirect conductor build_instances to cells self.compute_task_api = ConductorTaskRPCAPIRedirect(self.cells_rpcapi) self._cell_type = 'api'
def _metadata_as_json(self, version, path): metadata = {'uuid': self.uuid} if self.launch_metadata: metadata['meta'] = self.launch_metadata if self.files: metadata['files'] = self.files if self.extra_md: metadata.update(self.extra_md) if self.network_config: metadata['network_config'] = self.network_config if self.instance.key_name: metadata['public_keys'] = { self.instance.key_name: self.instance.key_data } if cells_opts.get_cell_type() == 'compute': cells_api = cells_rpcapi.CellsAPI() keypair = cells_api.get_keypair_at_top( context.get_admin_context(), self.instance.user_id, self.instance.key_name) else: try: keypair = keypair_obj.KeyPair.get_by_name( context.get_admin_context(), self.instance.user_id, self.instance.key_name) except exception.KeypairNotFound: # NOTE(mriedem): If the keypair was deleted from under us # don't totally fail the request, just treat it as if the # instance.key_name wasn't set. keypair = None if keypair: metadata['keys'] = [{ 'name': keypair.name, 'type': keypair.type, 'data': keypair.public_key }] else: LOG.debug( "Unable to find keypair for instance with " "key name '%s'.", self.instance.key_name, instance=self.instance) metadata['hostname'] = self._get_hostname() metadata['name'] = self.instance.display_name metadata['launch_index'] = self.instance.launch_index metadata['availability_zone'] = self.availability_zone if self._check_os_version(GRIZZLY, version): metadata['random_seed'] = base64.b64encode(os.urandom(512)) if self._check_os_version(LIBERTY, version): metadata['project_id'] = self.instance.project_id self.set_mimetype(MIME_TYPE_APPLICATION_JSON) return jsonutils.dump_as_bytes(metadata)
def __init__(self, target, version_cap): super(RPCClientCellsProxy, self).__init__() self.target = target self.version_cap = version_cap self._server = None self._version = None self.cells_rpcapi = cells_rpcapi.CellsAPI()
def _info_cache_cells_update(ctxt, info_cache): cell_type = cells_opts.get_cell_type() if cell_type != 'compute': return cells_api = cells_rpcapi.CellsAPI() try: cells_api.instance_info_cache_update_at_top(ctxt, info_cache) except Exception: LOG.exception( _LE("Failed to notify cells of instance info " "cache update"))
def destroy(self): if not self.obj_attr_is_set('id'): raise exception.ObjectActionError(action='destroy', reason='already destroyed') db.block_device_mapping_destroy(self._context, self.id) delattr(self, base.get_attrname('id')) cell_type = cells_opts.get_cell_type() if cell_type == 'compute': cells_api = cells_rpcapi.CellsAPI() cells_api.bdm_destroy_at_top(self._context, self.instance_uuid, device_name=self.device_name, volume_id=self.volume_id)
def _create(self, context, update_or_create=False): """Create the block device record in the database. In case the id field is set on the object, and if the instance is set raise an ObjectActionError. Resets all the changes on the object. Returns None :param context: security context used for database calls :param update_or_create: consider existing block devices for the instance based on the device name and swap, and only update the ones that match. Normally only used when creating the instance for the first time. """ cell_type = cells_opts.get_cell_type() if cell_type == 'api': raise exception.ObjectActionError( action='create', reason='BlockDeviceMapping cannot be ' 'created in the API cell.') if self.obj_attr_is_set('id'): raise exception.ObjectActionError(action='create', reason='already created') updates = self.obj_get_changes() if 'instance' in updates: raise exception.ObjectActionError(action='create', reason='instance assigned') cells_create = update_or_create or None if update_or_create: db_bdm = db.block_device_mapping_update_or_create( context, updates, legacy=False) else: db_bdm = db.block_device_mapping_create( context, updates, legacy=False) self._from_db_object(context, self, db_bdm) # NOTE(alaski): bdms are looked up by instance uuid and device_name # so if we sync up with no device_name an entry will be created that # will not be found on a later update_or_create call and a second bdm # create will occur. if cell_type == 'compute' and db_bdm.get('device_name') is not None: cells_api = cells_rpcapi.CellsAPI() cells_api.bdm_update_or_create_at_top( context, self, create=cells_create)
def save(self): updates = self.obj_get_changes() if 'instance' in updates: raise exception.ObjectActionError(action='save', reason='instance changed') updates.pop('id', None) updated = db.block_device_mapping_update(self._context, self.id, updates, legacy=False) if not updated: raise exception.BDMNotFound(id=self.id) self._from_db_object(self._context, self, updated) cell_type = cells_opts.get_cell_type() if cell_type == 'compute': create = False # NOTE(alaski): If the device name has just been set this bdm # likely does not exist in the parent cell and we should create it. # If this is a modification of the device name we should update # rather than create which is why None is used here instead of True if 'device_name' in updates: create = None cells_api = cells_rpcapi.CellsAPI() cells_api.bdm_update_or_create_at_top(self._context, self, create=create)
def create(self): if self.obj_attr_is_set('id'): raise exception.ObjectActionError(action='create', reason='already created') values = { 'instance_uuid': self.instance_uuid, 'code': self.code, 'message': self.message, 'details': self.details, 'host': self.host, } db_fault = db.instance_fault_create(self._context, values) self._from_db_object(self._context, self, db_fault) self.obj_reset_changes() # Cells should only try sending a message over to compute-cells # if cells is enabled and we're not the API cell. Otherwise, # if the API cell is calling this, we could end up with # infinite recursion. if cells_opts.get_cell_type() == 'compute': try: cells_rpcapi.CellsAPI().instance_fault_create_at_top( self._context, db_fault) except Exception: LOG.exception(_LE("Failed to notify cells of instance fault"))
def __init__(self, ext_mgr): self.cells_rpcapi = cells_rpcapi.CellsAPI() self.ext_mgr = ext_mgr
def __init__(self): self.cells_rpcapi = cells_rpcapi.CellsAPI()
def __init__(self): super(InstanceActionAPI, self).__init__() self.cells_rpcapi = cells_rpcapi.CellsAPI()
def __init__(self): super(HostAPI, self).__init__(rpcapi=ComputeRPCProxyAPI()) self.cells_rpcapi = cells_rpcapi.CellsAPI()