def delete_port_postcommit(self, context):
        db_context = context._plugin_context
        core_plugin = context._plugin
        port = context.current

        subnet_mapping = self._validate_port(db_context, port)
        if not subnet_mapping:
            return

        if self._port_should_have_vm(port):
            np_name = self.nuageclient.get_net_partition_name_by_id(
                subnet_mapping['net_partition_id'])
            require(np_name, "netpartition",
                    subnet_mapping['net_partition_id'])
            self._delete_nuage_vm(core_plugin, db_context, port, np_name,
                                  subnet_mapping)
        nuage_vport = self._get_nuage_vport(port, subnet_mapping)
        if nuage_vport:
            try:
                self.nuageclient.delete_nuage_vport(
                    nuage_vport['nuage_vport_id'])
            except Exception as e:
                LOG.error("Failed to delete vport from vsd {vport id: %s}"
                          % nuage_vport['nuage_vport_id'])
                raise e
    def _process_port_redirect_target(self, port, nuage_vport):
        redirect_targets = port['nuage_redirect_targets']
        if redirect_targets is None:
            return
        if len(redirect_targets) == 0:
            self.nuageclient.update_nuage_vport_redirect_target(
                None, nuage_vport.get('nuage_vport_id'))
            return
        if len(redirect_targets) > 1:
            msg = _("Multiple redirect targets on a port not supported.")
            raise NuageBadRequest(msg=msg)

        rtarget = redirect_targets[0]
        uuid_match = re.match(UUID_PATTERN, rtarget)
        if not uuid_match:
            nuage_rtarget = self.nuageclient.get_nuage_redirect_targets(
                {'name': rtarget})
            require(nuage_rtarget, "redirect target", rtarget)
            nuage_rtarget_id = nuage_rtarget[0]['ID']
        else:
            nuage_rtarget_id = rtarget

        self.nuageclient.update_nuage_vport_redirect_target(
            nuage_rtarget_id, nuage_vport.get('nuage_vport_id'))

        port['nuage_redirect_targets'] = [nuage_rtarget_id]
 def _get_nuage_subnet(self, nuage_subnet_id):
     nuage_subnet = self.nuageclient.get_subnet_or_domain_subnet_by_id(
         nuage_subnet_id)
     require(nuage_subnet, 'subnet or domain', nuage_subnet_id)
     shared = nuage_subnet['subnet_shared_net_id']
     shared_subnet = None
     if shared:
         shared_subnet = self.nuageclient.get_nuage_sharedresource(shared)
         require(shared_subnet, 'sharednetworkresource', shared)
     return nuage_subnet, shared_subnet
    def update_port_precommit(self, context):
        db_context = context._plugin_context
        core_plugin = context._plugin
        port = context.current
        original = context.original
        if 'request_port' not in port:
            return
        request_port = port['request_port']
        del port['request_port']

        subnet_mapping = self._validate_port(db_context, port)
        if not subnet_mapping:
            return
        nuage_vport = self._get_nuage_vport(port, subnet_mapping)

        device_added = device_removed = False
        if not original['device_owner'] and port['device_owner']:
            device_added = True
        elif original['device_owner'] and not port['device_owner']:
            device_removed = True

        if device_added or device_removed:
            np_name = self.nuageclient.get_net_partition_name_by_id(
                subnet_mapping['net_partition_id'])
            require(np_name, "netpartition",
                    subnet_mapping['net_partition_id'])

            if device_removed:
                if self._port_should_have_vm(original):
                    self._delete_nuage_vm(core_plugin, db_context, original,
                                          np_name, subnet_mapping)
            elif device_added:
                if port['device_owner'].startswith(
                        constants.NOVA_PORT_OWNER_PREF):
                    nuage_subnet, _ = self._get_nuage_subnet(
                        subnet_mapping['nuage_subnet_id'])
                    self._create_nuage_vm(core_plugin, db_context, port,
                                          np_name, subnet_mapping, nuage_vport,
                                          nuage_subnet)
        rollbacks = []
        try:
            self.nuage_callbacks.notify(resources.PORT, constants.AFTER_UPDATE,
                                        core_plugin, context=db_context,
                                        updated_port=port,
                                        original_port=original,
                                        request_port=request_port,
                                        vport=nuage_vport, rollbacks=rollbacks)
        except Exception:
            with excutils.save_and_reraise_exception():
                for rollback in reversed(rollbacks):
                    rollback[0](*rollback[1], **rollback[2])
    def create_port_postcommit(self, context):
        db_context = context._plugin_context
        core_plugin = context._plugin
        port = context.current
        request_port = port['request_port']
        if 'request_port' not in port:
            return
        del port['request_port']

        subnet_mapping = self._validate_port(db_context, port)
        if not subnet_mapping:
            return

        nuage_vport = nuage_vm = np_name = None
        try:
            np_id = subnet_mapping['net_partition_id']
            nova_prefix = constants.NOVA_PORT_OWNER_PREF
            nuage_subnet, _ = self._get_nuage_subnet(
                subnet_mapping['nuage_subnet_id'])
            if port['device_owner'].startswith(nova_prefix):
                self._validate_vmports_same_netpartition(core_plugin,
                                                         db_context,
                                                         port, np_id)
                desc = ("device_owner:" + constants.NOVA_PORT_OWNER_PREF +
                        "(please do not edit)")
                nuage_vport = self._create_nuage_vport(port, nuage_subnet,
                                                       desc)
                np_name = self.nuageclient.get_net_partition_name_by_id(np_id)
                require(np_name, "netpartition", np_id)
                nuage_vm = self._create_nuage_vm(
                    core_plugin, db_context, port, np_name, subnet_mapping,
                    nuage_vport, nuage_subnet)
            else:
                nuage_vport = self._create_nuage_vport(port, nuage_subnet)
        except Exception:
            if nuage_vm:
                self._delete_nuage_vm(core_plugin, db_context, port, np_name,
                                      subnet_mapping)
            if nuage_vport:
                self.nuageclient.delete_nuage_vport(nuage_vport.get('ID'))
            raise
        rollbacks = []
        try:
            self.nuage_callbacks.notify(resources.PORT, constants.AFTER_CREATE,
                                        self, context=db_context, port=port,
                                        vport=nuage_vport, rollbacks=rollbacks,
                                        request_port=request_port)
        except Exception:
            with excutils.save_and_reraise_exception():
                    for rollback in reversed(rollbacks):
                        rollback[0](*rollback[1], **rollback[2])
 def _validate_net_partition(self, subnet, db_context):
     netpartition_db = nuagedb.get_net_partition_by_name(
         db_context.session, subnet['net_partition'])
     netpartition = self.nuageclient.get_netpartition_by_name(
         subnet['net_partition'])
     require(netpartition, "netpartition", subnet['net_partition'])
     if netpartition_db:
         if netpartition_db['id'] != netpartition['id']:
             net_partdb = nuagedb.get_net_partition_with_lock(
                 db_context.session, netpartition_db['id'])
             nuagedb.delete_net_partition(db_context.session, net_partdb)
             self._add_net_partition(db_context.session, netpartition)
     else:
         self._add_net_partition(db_context.session, netpartition)
     return netpartition['id']
    def update_port_postcommit(self, context):
        db_context = context._plugin_context
        core_plugin = context._plugin
        port = context.current
        original = context.original

        subnet_mapping = self._validate_port(db_context, port)
        if not subnet_mapping:
            return
        device_added = device_removed = rtargets = False
        if not original['device_owner'] and port['device_owner']:
            device_added = True
        elif original['device_owner'] and not port['device_owner']:
            device_removed = True
        if port.get('nuage_redirect_targets') is not None:
            rtargets = True

        if not (device_added or device_removed or rtargets):
            return

        np_name = self.nuageclient.get_net_partition_name_by_id(
            subnet_mapping['net_partition_id'])
        require(np_name, "netpartition", subnet_mapping['net_partition_id'])

        if device_removed:
            if self._port_should_have_vm(original):
                self._delete_nuage_vm(core_plugin, db_context, original,
                                      np_name, subnet_mapping)
        elif device_added:
            if port['device_owner'].startswith(constants.NOVA_PORT_OWNER_PREF):
                nuage_vport = self._get_nuage_vport(port, subnet_mapping)
                self._create_nuage_vm(core_plugin, db_context, port, np_name,
                                      subnet_mapping, nuage_vport)
        if rtargets:
            nuage_vport = self._get_nuage_vport(port, subnet_mapping)
            self._process_port_redirect_target({'nuage_redirect_targets': []},
                                               nuage_vport)
            if port['nuage_redirect_targets']:
                self._process_port_redirect_target(port, nuage_vport)
Exemplo n.º 8
0
    def _validate_net_partition(self, np_id_or_name, context):
        # check db first
        netpartition_db = self._get_netpartition_from_db(
            context.session, np_id_or_name)

        # check vsd by the net-partition in db if found, else try np_id_or_name
        # - note that np_id_or_name only makes sense when a name is given -
        netpartition = self.vsdclient.get_netpartition_by_name(
            netpartition_db['name'] if netpartition_db else np_id_or_name)
        require(netpartition, "netpartition", np_id_or_name)
        if netpartition_db:
            if netpartition_db['id'] == netpartition['id']:
                return netpartition_db
            else:
                # fix neutron with enterprise id (it seems changed?)
                # ... not sure how this would ever happen (legacy code) ...
                net_part_db = nuagedb.get_net_partition_with_lock(
                    context.session, netpartition_db['id'])
                nuagedb.delete_net_partition(context.session, net_part_db)
                return self._add_net_partition(context.session, netpartition)
        else:
            # enterprise exists on VSD but not yet in neutron; add it
            return self._add_net_partition(context.session, netpartition)
    def create_port_postcommit(self, context):
        db_context = context._plugin_context
        core_plugin = context._plugin
        port = context.current

        subnet_mapping = self._validate_port(db_context, port)
        if not subnet_mapping:
            return

        nuage_vport = nuage_vm = np_name = None
        try:
            np_id = subnet_mapping['net_partition_id']
            nova_prefix = constants.NOVA_PORT_OWNER_PREF
            if port['device_owner'].startswith(nova_prefix):
                self._validate_vmports_same_netpartition(core_plugin,
                                                         db_context,
                                                         port, np_id)
                desc = ("device_owner:" + constants.NOVA_PORT_OWNER_PREF +
                        "(please do not edit)")
                nuage_vport = self._create_nuage_vport(port, subnet_mapping,
                                                       desc)
                np_name = self.nuageclient.get_net_partition_name_by_id(np_id)
                require(np_name, "netpartition", np_id)
                nuage_vm = self._create_nuage_vm(
                    core_plugin, db_context, port, np_name, subnet_mapping,
                    nuage_vport)
            else:
                nuage_vport = self._create_nuage_vport(port, subnet_mapping)
            self._process_port_redirect_target(port, nuage_vport)
        except Exception:
            if nuage_vm:
                self._delete_nuage_vm(core_plugin, db_context, port, np_name,
                                      subnet_mapping)
            if nuage_vport:
                self.nuageclient.delete_nuage_vport(
                    nuage_vport.get('nuage_vport_id'))
            raise
Exemplo n.º 10
0
 def get_subnet_available_nuage_floatingips(self, context, filters=None):
     subnet_id = filters.pop('for_subnet')[0]
     vsd_mapping = nuagedb.get_subnet_l2dom_by_id(context.session,
                                                  subnet_id)
     require(vsd_mapping, 'vsd subnet mapping for subnet', subnet_id)
     return self._get_available_nuage_floatingips(vsd_mapping, filters)
 def get_subnet_available_nuage_floatingips(self, context, filters=None):
     subnet_id = filters.pop('for_subnet')[0]
     vsd_mapping = nuagedb.get_subnet_l2dom_by_id(context.session,
                                                  subnet_id)
     require(vsd_mapping, 'vsd subnet mapping for subnet', subnet_id)
     return self._get_available_nuage_floatingips(vsd_mapping, filters)