Ejemplo n.º 1
0
 def create(self):
     if 'id' in self:
         raise exception.ObjectActionError(action='create',
                                           reason='already created')
     if 'uuid' not in self:
         raise exception.ObjectActionError(action='create',
                                           reason='uuid is required')
     updates = self.obj_get_changes()
     db_rp = self._create_in_db(self._context, updates)
     self._from_db_object(self._context, self, db_rp)
Ejemplo n.º 2
0
 def create(self):
     if self.obj_attr_is_set('id'):
         raise exception.ObjectActionError(action='create',
                                           reason='already created')
     updates = self.obj_get_changes()
     if 'migration_type' not in updates:
         raise exception.ObjectActionError(
             action="create",
             reason="cannot create a Migration object without a "
             "migration_type set")
     db_migration = db.migration_create(self._context, updates)
     self._from_db_object(self._context, self, db_migration)
Ejemplo n.º 3
0
 def _make_db(updates):
     try:
         resource_provider = updates.pop('resource_provider')
         updates['resource_provider_id'] = resource_provider.id
     except (KeyError, NotImplementedError):
         raise exception.ObjectActionError(
             action='create', reason='resource_provider required')
     try:
         resource_class = updates.pop('resource_class')
     except KeyError:
         raise exception.ObjectActionError(action='create',
                                           reason='resource_class required')
     updates['resource_class_id'] = fields.ResourceClass.index(
         resource_class)
     return updates
Ejemplo n.º 4
0
 def create(self):
     if self.obj_attr_is_set('id'):
         raise exception.ObjectActionError(action='create',
                                           reason='already created')
     updates = self.obj_get_changes()
     db_vif = db.virtual_interface_create(self._context, updates)
     self._from_db_object(self._context, self, db_vif)
Ejemplo n.º 5
0
    def save(self):
        updates = self.obj_get_changes()
        projects = updates.pop('projects', None)
        extra_specs = updates.pop('extra_specs', None)
        if updates:
            raise exception.ObjectActionError(
                action='save', reason='read-only fields were changed')

        if extra_specs is not None:
            deleted_keys = (set(self._orig_extra_specs.keys()) -
                            set(extra_specs.keys()))
            added_keys = self.extra_specs
        else:
            added_keys = deleted_keys = None

        if projects is not None:
            deleted_projects = set(self._orig_projects) - set(projects)
            added_projects = set(projects) - set(self._orig_projects)
        else:
            added_projects = deleted_projects = None

        # NOTE(danms): The first remotable method we call will reset
        # our of the original values for projects and extra_specs. Thus,
        # we collect the added/deleted lists for both above and /then/
        # call these methods to update them.

        if added_keys or deleted_keys:
            self.save_extra_specs(self.extra_specs, deleted_keys)

        if added_projects or deleted_projects:
            self.save_projects(added_projects, deleted_projects)
Ejemplo n.º 6
0
 def create(self):
     updates = self._get_primitive_changes()
     if 'id' in updates:
         raise exception.ObjectActionError(action='create',
                                           reason='already created')
     db_network = db.network_create_safe(self._context, updates)
     self._from_db_object(self._context, self, db_network)
Ejemplo n.º 7
0
 def create(self):
     updates = self.obj_get_changes()
     if 'id' in updates:
         raise exception.ObjectActionError(action='create',
                                           reason='Already Created')
     db_agent = db.agent_build_create(self._context, updates)
     self._from_db_object(self._context, self, db_agent)
Ejemplo n.º 8
0
 def save(self):
     if 'id' not in self:
         raise exception.ObjectActionError(action='save',
                                           reason='not created')
     updates = self.obj_get_changes()
     updates.pop('id', None)
     self._update_in_db(self._context, self.id, updates)
Ejemplo n.º 9
0
    def obj_make_compatible(self, primitive, target_version):
        super(ImageMetaProps,
              self).obj_make_compatible(primitive, target_version)
        target_version = versionutils.convert_version_to_tuple(target_version)
        if target_version < (1, 11):
            primitive.pop('hw_firmware_type', None)
        if target_version < (1, 9):
            primitive.pop('hw_cpu_thread_policy', None)
        if target_version < (1, 7):
            primitive.pop('img_config_drive', None)
        if target_version < (1, 5):
            primitive.pop('os_admin_user', None)
        if target_version < (1, 4):
            primitive.pop('hw_vif_multiqueue_enabled', None)
        if target_version < (1, 2):
            primitive.pop('img_hv_type', None)
            primitive.pop('img_hv_requested_version', None)
        if target_version < (1, 1):
            primitive.pop('os_require_quiesce', None)

        if target_version < (1, 6):
            bus = primitive.get('hw_disk_bus', None)
            if bus in ('lxc', 'uml'):
                raise exception.ObjectActionError(
                    action='obj_make_compatible',
                    reason='hw_disk_bus=%s not supported in version %s' %
                    (bus, target_version))
Ejemplo n.º 10
0
 def create(self):
     if 'id' in self:
         raise exception.ObjectActionError(action='create',
                                           reason='already created')
     updates = self._make_db(self.obj_get_changes())
     db_inventory = self._create_in_db(self._context, updates)
     self._from_db_object(self._context, self, db_inventory)
Ejemplo n.º 11
0
    def obj_load_attr(self, attrname):
        if not self._context:
            raise exception.OrphanedObjectError(method='obj_load_attr',
                                                objtype=self.obj_name())

        LOG.debug("Lazy-loading '%(attr)s' on %(name)s id %(id)s",
                  {'attr': attrname,
                   'name': self.obj_name(),
                   'id': self.id,
                   })
        if attrname != 'compute_node':
            raise exception.ObjectActionError(
                action='obj_load_attr',
                reason='attribute %s not lazy-loadable' % attrname)
        if self.binary == 'nova-compute':
            # Only n-cpu services have attached compute_node(s)
            compute_nodes = objects.ComputeNodeList.get_all_by_host(
                self._context, self.host)
        else:
            # NOTE(sbauza); Previous behaviour was raising a ServiceNotFound,
            # we keep it for backwards compatibility
            raise exception.ServiceNotFound(service_id=self.id)
        # NOTE(sbauza): Some drivers (VMware, Ironic) can have multiple nodes
        # for the same service, but for keeping same behaviour, returning only
        # the first elem of the list
        self.compute_node = compute_nodes[0]
Ejemplo n.º 12
0
    def save(self):
        updates = self.obj_get_changes()
        if 'address' in updates:
            raise exception.ObjectActionError(action='save',
                                              reason='address is not mutable')
        if 'fixed_ip_id' in updates:
            reason = 'fixed_ip_id is not mutable'
            raise exception.ObjectActionError(action='save', reason=reason)

        # NOTE(danms): Make sure we don't pass the calculated fixed_ip
        # relationship to the DB update method
        updates.pop('fixed_ip', None)

        db_floatingip = db.floating_ip_update(self._context, str(self.address),
                                              updates)
        self._from_db_object(self._context, self, db_floatingip)
Ejemplo n.º 13
0
 def save(self):
     updates = self.obj_get_changes()
     if 'address' in updates:
         raise exception.ObjectActionError(action='save',
                                           reason='address is not mutable')
     db.fixed_ip_update(self._context, str(self.address), updates)
     self.obj_reset_changes()
Ejemplo n.º 14
0
    def obj_load_attr(self, attrname):
        # NOTE(danms): Only projects could be lazy-loaded right now
        if attrname != 'projects':
            raise exception.ObjectActionError(action='obj_load_attr',
                                              reason='unable to load %s' %
                                              attrname)

        self._load_projects()
Ejemplo n.º 15
0
    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)
Ejemplo n.º 16
0
 def create(self):
     if self.obj_attr_is_set('id'):
         raise exception.ObjectActionError(action='create',
                                           reason='already created')
     self._check_minimum_version()
     updates = self.obj_get_changes()
     db_service = db.service_create(self._context, updates)
     self._from_db_object(self._context, self, db_service)
Ejemplo n.º 17
0
    def create(self):
        if self.obj_attr_is_set('id'):
            raise exception.ObjectActionError(action='create',
                                              reason='already created')

        updates = self._get_update_primitives()
        db_req = self._create_in_db(self._context, updates)
        self._from_db_object(self._context, self, db_req)
Ejemplo n.º 18
0
    def obj_load_attr(self, attrname):
        # NOTE(sbauza): Only hosts could be lazy-loaded right now
        if attrname != 'hosts':
            raise exception.ObjectActionError(
                action='obj_load_attr', reason='unable to load %s' % attrname)

        self.hosts = self.get_hosts()
        self.obj_reset_changes(['hosts'])
Ejemplo n.º 19
0
 def bulk_create(self, context, fixed_ips):
     ips = []
     for fixedip in fixed_ips:
         ip = obj_base.obj_to_primitive(fixedip)
         if 'id' in ip:
             raise exception.ObjectActionError(action='create',
                                               reason='already created')
         ips.append(ip)
     db.fixed_ip_bulk_create(context, ips)
Ejemplo n.º 20
0
 def create(self):
     updates = self.obj_get_changes()
     if 'id' in updates:
         raise exception.ObjectActionError(action='create',
                                           reason='already created')
     if 'address' in updates:
         updates['address'] = str(updates['address'])
     db_fixedip = db.fixed_ip_create(self._context, updates)
     self._from_db_object(self._context, self, db_fixedip)
Ejemplo n.º 21
0
 def obj_load_attr(self, attrname):
     if attrname not in FLOATING_IP_OPTIONAL_ATTRS:
         raise exception.ObjectActionError(
             action='obj_load_attr',
             reason='attribute %s is not lazy-loadable' % attrname)
     if not self._context:
         raise exception.OrphanedObjectError(method='obj_load_attr',
                                             objtype=self.obj_name())
     if self.fixed_ip_id is not None:
         self.fixed_ip = objects.FixedIP.get_by_id(
             self._context, self.fixed_ip_id, expected_attrs=['network'])
     else:
         self.fixed_ip = None
Ejemplo n.º 22
0
    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)
Ejemplo n.º 23
0
 def create(self):
     if self.obj_attr_is_set('id'):
         raise exception.ObjectActionError(action='create',
                                           reason='already created')
     updates = self.obj_get_changes()
     parent_group = updates.pop('parent_group', None)
     if parent_group:
         updates['parent_group_id'] = parent_group.id
     grantee_group = updates.pop('grantee_group', None)
     if grantee_group:
         updates['group_id'] = grantee_group.id
     db_rule = db.security_group_rule_create(self._context, updates)
     self._from_db_object(self._context, self, db_rule)
Ejemplo n.º 24
0
 def create(self):
     if self.obj_attr_is_set('id'):
         raise exception.ObjectActionError(action='create',
                                           reason='already created')
     updates = self.obj_get_changes()
     expected_attrs = []
     for attr in OPTIONAL_FIELDS:
         if attr in updates:
             expected_attrs.append(attr)
     projects = updates.pop('projects', [])
     db_flavor = db.flavor_create(self._context, updates, projects=projects)
     self._from_db_object(self._context,
                          self,
                          db_flavor,
                          expected_attrs=expected_attrs)
Ejemplo n.º 25
0
    def __init__(self, *args, **kwargs):
        # NOTE(danms): We're going against the rules here and overriding
        # init. The reason is that we want to *ensure* that we're always
        # setting the current service version on our objects, overriding
        # whatever else might be set in the database, or otherwise (which
        # is the normal reason not to override init).
        #
        # We also need to do this here so that it's set on the client side
        # all the time, such that create() and save() operations will
        # include the current service version.
        if 'version' in kwargs:
            raise exception.ObjectActionError(
                action='init',
                reason='Version field is immutable')

        super(Service, self).__init__(*args, **kwargs)
        self.version = SERVICE_VERSION
Ejemplo n.º 26
0
    def obj_load_attr(self, attrname):
        if attrname not in BLOCK_DEVICE_OPTIONAL_ATTRS:
            raise exception.ObjectActionError(
                action='obj_load_attr',
                reason='attribute %s not lazy-loadable' % attrname)
        if not self._context:
            raise exception.OrphanedObjectError(method='obj_load_attr',
                                                objtype=self.obj_name())

        LOG.debug("Lazy-loading '%(attr)s' on %(name)s uuid %(uuid)s",
                  {'attr': attrname,
                   'name': self.obj_name(),
                   'uuid': self.uuid,
                   })
        self.instance = objects.Instance.get_by_uuid(self._context,
                                                     self.instance_uuid)
        self.obj_reset_changes(fields=['instance'])
Ejemplo n.º 27
0
    def create(self):
        if self.obj_attr_is_set('id'):
            raise exception.ObjectActionError(action='create',
                                              reason='already created')
        updates = self.obj_get_changes()
        payload = dict(updates)
        updates.pop('id', None)
        policies = updates.pop('policies', None)
        members = updates.pop('members', None)

        db_inst = db.instance_group_create(self._context, updates,
                                           policies=policies,
                                           members=members)
        self._from_db_object(self._context, self, db_inst)
        payload['server_group_id'] = self.uuid
        compute_utils.notify_about_server_group_update(self._context,
                                                       "create", payload)
Ejemplo n.º 28
0
 def obj_make_compatible(self, primitive, target_version):
     target_version = versionutils.convert_version_to_tuple(target_version)
     if target_version < (1, 2) and 'request_id' in primitive:
         del primitive['request_id']
     if target_version < (1, 4) and 'parent_addr' in primitive:
         if primitive['parent_addr'] is not None:
             extra_info = primitive.get('extra_info', {})
             extra_info['phys_function'] = primitive['parent_addr']
         del primitive['parent_addr']
     if target_version < (1, 5) and 'parent_addr' in primitive:
         added_statuses = (fields.PciDeviceStatus.UNCLAIMABLE,
                           fields.PciDeviceStatus.UNAVAILABLE)
         status = primitive['status']
         if status in added_statuses:
             raise exception.ObjectActionError(
                 action='obj_make_compatible',
                 reason='status=%s not supported in version %s' %
                 (status, target_version))
Ejemplo n.º 29
0
    def get_minimum_version(cls, context, binary, use_slave=False):
        if not binary.startswith('nova-') and not binary.startswith('jacket-'):
            LOG.warning(_LW('get_minimum_version called with likely-incorrect '
                            'binary `%s\''), binary)
            raise exception.ObjectActionError(action='get_minimum_version',
                                              reason='Invalid binary prefix')

        if cls._SERVICE_VERSION_CACHING:
            cached_version = cls._MIN_VERSION_CACHE.get(binary)
            if cached_version:
                return cached_version
        version = cls._db_service_get_minimum_version(context, binary,
                                                      use_slave=use_slave)
        if version is None:
            return 0
        # NOTE(danms): Since our return value is not controlled by object
        # schema, be explicit here.
        version = int(version)
        cls._MIN_VERSION_CACHE[binary] = version

        return version
Ejemplo n.º 30
0
 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)