def setUp(self):
     super(TestNetworkVIFModel, self).setUp()
     model = network_model.VIF('6c197bc7-820c-40d5-8aff-7116b993e793')
     primitive = jsonutils.dumps(model)
     self.field = fields.Field(fields.NetworkVIFModel())
     self.coerce_good_values = [(model, model), (primitive, model)]
     self.coerce_bad_values = [[], 'foo']
     self.to_primitive_values = [(model, primitive)]
     self.from_primitive_values = [(primitive, model)]
Exemple #2
0
class VIFMigrateData(obj_base.NovaObject):
    # Version 1.0: Initial version
    VERSION = '1.0'

    # The majority of the fields here represent a port binding on the
    # **destination** host during a live migration. The vif_type, among
    # other fields, could be different from the existing binding on the
    # source host, which is represented by the "source_vif" field.
    fields = {
        'port_id': fields.StringField(),
        'vnic_type': fields.StringField(),  # TODO(sean-k-mooney): make enum?
        'vif_type': fields.StringField(),
        # vif_details is a dict whose contents are dependent on the vif_type
        # and can be any number of types for the values, so we just store it
        # as a serialized dict
        'vif_details_json': fields.StringField(),
        # profile is in the same random dict of terrible boat as vif_details
        # so it's stored as a serialized json string
        'profile_json': fields.StringField(),
        'host': fields.StringField(),
        # The source_vif attribute is a copy of the VIF network model
        # representation of the port on the source host which can be used
        # for filling in blanks about the VIF (port) when building a
        # configuration reference for the destination host.
        # NOTE(mriedem): This might not be sufficient based on how the
        # destination host is configured for all vif types. See the note in
        # the libvirt driver here: https://review.opendev.org/#/c/551370/
        # 29/nova/virt/libvirt/driver.py@7036
        'source_vif': fields.Field(fields.NetworkVIFModel()),
    }

    @property
    def vif_details(self):
        if 'vif_details_json' not in self:
            return {}
        return jsonutils.loads(self.vif_details_json)

    @vif_details.setter
    def vif_details(self, vif_details_dict):
        self.vif_details_json = jsonutils.dumps(vif_details_dict)

    @property
    def profile(self):
        if 'profile_json' not in self:
            return {}
        return jsonutils.loads(self.profile_json)

    @profile.setter
    def profile(self, profile_dict):
        self.profile_json = jsonutils.dumps(profile_dict)

    @property
    def supports_os_vif_delegation(self):
        return self.profile.get(OS_VIF_DELEGATION, False)

    # TODO(stephenfin): add a proper delegation field instead of storing this
    # info in the profile catch-all blob
    @supports_os_vif_delegation.setter
    def supports_os_vif_delegation(self, supported):
        # we can't simply set the attribute using dict notation since the
        # getter returns a copy of the data, not the data itself
        self.profile = dict(self.profile or {},
                            **{OS_VIF_DELEGATION: supported})

    def get_dest_vif(self):
        """Get a destination VIF representation of this object.

        This method takes the source_vif and updates it to include the
        destination host port binding information using the other fields
        on this object.

        :return: nova.network.model.VIF object
        """
        if 'source_vif' not in self:
            raise exception.ObjectActionError(action='get_dest_vif',
                                              reason='source_vif is not set')
        vif = copy.deepcopy(self.source_vif)
        vif['type'] = self.vif_type
        vif['vnic_type'] = self.vnic_type
        vif['profile'] = self.profile
        vif['details'] = self.vif_details
        vif['delegate_create'] = self.supports_os_vif_delegation
        return vif

    @classmethod
    def create_skeleton_migrate_vifs(cls, vifs):
        """Create migrate vifs for live migration.

        :param vifs: a list of VIFs.
        :return: list of VIFMigrateData object corresponding to the provided
                 VIFs.
        """
        vif_mig_data = []

        for vif in vifs:
            mig_vif = cls(port_id=vif['id'], source_vif=vif)
            vif_mig_data.append(mig_vif)
        return vif_mig_data
class VIFMigrateData(obj_base.NovaObject):
    # Version 1.0: Initial version
    VERSION = '1.0'

    # The majority of the fields here represent a port binding on the
    # **destination** host during a live migration. The vif_type, among
    # other fields, could be different from the existing binding on the
    # source host, which is represented by the "source_vif" field.
    fields = {
        'port_id': fields.StringField(),
        'vnic_type': fields.StringField(),  # TODO(sean-k-mooney): make enum?
        'vif_type': fields.StringField(),
        # vif_details is a dict whose contents are dependent on the vif_type
        # and can be any number of types for the values, so we just store it
        # as a serialized dict
        'vif_details_json': fields.StringField(),
        # profile is in the same random dict of terrible boat as vif_details
        # so it's stored as a serialized json string
        'profile_json': fields.StringField(),
        'host': fields.StringField(),
        # The source_vif attribute is a copy of the VIF network model
        # representation of the port on the source host which can be used
        # for filling in blanks about the VIF (port) when building a
        # configuration reference for the destination host.
        # NOTE(mriedem): This might not be sufficient based on how the
        # destination host is configured for all vif types. See the note in
        # the libvirt driver here: https://review.openstack.org/#/c/551370/
        # 29/nova/virt/libvirt/driver.py@7036
        'source_vif': fields.Field(fields.NetworkVIFModel()),
    }

    @property
    def vif_details(self):
        return jsonutils.loads(self.vif_details_json)

    @vif_details.setter
    def vif_details(self, vif_details_dict):
        self.vif_details_json = jsonutils.dumps(vif_details_dict)

    @property
    def profile(self):
        return jsonutils.loads(self.profile_json)

    @profile.setter
    def profile(self, profile_dict):
        self.profile_json = jsonutils.dumps(profile_dict)

    def get_dest_vif(self):
        """Get a destination VIF representation of this object.

        This method takes the source_vif and updates it to include the
        destination host port binding information using the other fields
        on this object.

        :return: nova.network.model.VIF object
        """
        if 'source_vif' not in self:
            raise exception.ObjectActionError(action='get_dest_vif',
                                              reason='source_vif is not set')
        vif = copy.deepcopy(self.source_vif)
        vif['type'] = self.vif_type
        vif['vnic_type'] = self.vnic_type
        vif['profile'] = self.profile
        vif['details'] = self.vif_details
        return vif