Exemple #1
0
 def get_nuage_floatingip(self, context, id, fields=None):
     try:
         floatingip = self.nuageclient.get_nuage_floatingip(id,
                                                            externalID=None)
         if not floatingip:
             raise exceptions.NuageNotFound(resource="nuage-floatingip",
                                            resource_id=id)
         return self.map_vsd_to_os(floatingip, fields=fields)
     except ResourceNotFoundException:
         raise exceptions.NuageNotFound(resource="nuage_floatingip",
                                        resource_id=id)
 def get_nuage_policy_group(self, context, id, fields=None):
     try:
         policy_group = self.vsdclient.get_policygroup(id, externalID=None)
         if not policy_group:
             raise exceptions.NuageNotFound(resource="nuage-policy-group",
                                            resource_id=id)
         vports = self.vsdclient.get_vports_in_policygroup(id)
         port_ids = [vport['externalID'].split('@')[0] for vport in vports]
         policy_group['ports'] = port_ids
         return self.map_vsd_to_os(policy_group, fields=fields)
     except ResourceNotFoundException:
         raise exceptions.NuageNotFound(resource='nuage_policy_group',
                                        resource_id=id)
Exemple #3
0
 def get_nuage_gateway_vlan(self, context, id, fields=None):
     resp = self.nuageclient.get_gateway_port_vlan(context.tenant_id, id)
     if resp:
         return self._make_vlan_dict(resp, fields=fields, context=context)
     else:
         raise nuage_exc.NuageNotFound(resource='nuage_vlan',
                                       resource_id=id)
Exemple #4
0
    def get_nuage_redirect_target_rules(self, context, filters=None,
                                        fields=None):
        params = {}
        resource_id = None
        if filters.get('subnet'):
            subnet_mapping = nuagedb.get_subnet_l2dom_by_id(
                context.session, filters['subnet'][0])
            if subnet_mapping:
                if self._is_l3(subnet_mapping):
                    message = ("Subnet %s doesn't have mapping l2domain on "
                               "VSD " % filters['subnet'][0])
                    raise nuage_exc.NuageBadRequest(msg=message)
                params['subnet'] = filters.get('subnet')[0]
                params['subnet_mapping'] = subnet_mapping
            else:
                message = ("Subnet %s doesn't have mapping l2domain on "
                           "VSD " % filters['subnet'][0])
                raise nuage_exc.NuageBadRequest(msg=message)
        elif filters.get('router'):
            params['router'] = filters.get('router')[0]
        elif filters.get('id'):
            params['id'] = filters.get('id')[0]
            resource_id = params['id']

        try:
            rtarget_rules = self.vsdclient.get_nuage_redirect_target_rules(
                params)
        except Exception:
            raise nuage_exc.NuageNotFound(
                resource='nuage-redirect-target-rule',
                resource_id=resource_id)

        return [self._make_redirect_target_rule_dict(
            rtarget_rule, context, fields) for rtarget_rule in rtarget_rules]
    def get_nuage_external_security_group_rules(self, context, filters=None,
                                                fields=None):
        params = {}
        resource_id = None
        if filters.get('subnet'):
            subnet_mapping = nuagedb.get_subnet_l2dom_by_id(
                context.session, filters['subnet'][0])
            if subnet_mapping:
                if self._is_l3(subnet_mapping):
                    message = ("Subnet %s doesn't have mapping l2domain on "
                               "VSD " % filters['subnet'][0])
                    raise nuage_exc.NuageBadRequest(msg=message)
                params['subnet'] = filters.get('subnet')[0]
            else:
                message = ("Subnet %s doesn't have mapping l2domain on "
                           "VSD " % filters['subnet'][0])
                raise nuage_exc.NuageBadRequest(msg=message)
        elif filters.get('router'):
            params['router'] = filters.get('router')[0]
        elif filters.get('external_group'):
            params['external_group'] = filters.get('external_group')[0]
            resource_id = params['external_group']
        try:
            ext_rules = self.vsdclient.get_nuage_external_sg_rules(
                params)
        except Exception:
            raise nuage_exc.NuageNotFound(
                resource='nuage-external-security-group-rule',
                resource_id=resource_id)

        return [self._make_external_security_group_rule_dict(ext_rule, context,
                                                             fields) for
                ext_rule in ext_rules]
 def get_project_net_partition_mapping(self, context, id, fields=None):
     mapping = nuagedb.get_project_net_partition_mapping(
         context.session, id)
     if not mapping:
         raise nuage_exc.NuageNotFound(
             resource='project_net_partition_mapping', resource_id=id)
     return self._make_project_net_partition_mapping(
         context, mapping, fields)
 def get_net_partition(self, context, id, fields=None):
     net_partition = nuagedb.get_net_partition_by_id(context.session, id)
     if not net_partition:
         raise nuage_exc.NuageNotFound(resource='net_partition',
                                       resource_id=id)
     return self._make_net_partition_dict(net_partition,
                                          context=context,
                                          fields=fields)
 def delete_net_partition(self, context, id):
     net_partition = nuagedb.get_net_partition_by_id(context.session, id)
     if not net_partition:
         raise nuage_exc.NuageNotFound(resource='net_partition',
                                       resource_id=id)
     self._validate_delete_net_partition(context, id, net_partition['name'])
     self.vsdclient.delete_net_partition(net_partition['id'])
     with context.session.begin(subtransactions=True):
         nuagedb.delete_net_partition(context.session, net_partition)
Exemple #9
0
 def get_nuage_redirect_target(self, context, rtarget_id, fields=None):
     rtarget_resp = self.vsdclient.get_nuage_redirect_target(rtarget_id)
     if not rtarget_resp:
         raise nuage_exc.NuageNotFound(resource='nuage_redirect_target',
                                       resource_id=rtarget_id)
     vports = self.vsdclient.get_redirect_target_vports(rtarget_id) or []
     port_ids = [vport['externalID'].split('@')[0] for vport in vports]
     rtarget_resp['ports'] = port_ids
     return self._make_redirect_target_dict(rtarget_resp, context=context,
                                            fields=fields)
 def get_nuage_external_security_group(self, context, ext_sg_id,
                                       fields=None):
     try:
         ext_sg_resp = self.vsdclient.get_nuage_external_security_group(
             ext_sg_id)
     except Exception:
         raise nuage_exc.NuageNotFound(
             resource='nuage-external-security-group',
             resource_id=ext_sg_id)
     return self._make_external_security_group_dict(ext_sg_resp,
                                                    context=context,
                                                    fields=fields)
Exemple #11
0
 def get_nuage_redirect_target_rule(self, context, rtarget_rule_id,
                                    fields=None):
     try:
         rtarget_rule_resp = (
             self.vsdclient.get_nuage_redirect_target_rule(
                 rtarget_rule_id))
     except Exception:
         raise nuage_exc.NuageNotFound(
             resource='nuage-redirect-target-rule',
             resource_id=rtarget_rule_id)
     return self._make_redirect_target_rule_dict(rtarget_rule_resp,
                                                 context=context,
                                                 fields=fields)
Exemple #12
0
    def get_nuage_external_security_groups(self,
                                           context,
                                           filters=None,
                                           fields=None):
        # get all redirect targets
        domain_type = None
        domain_id = None
        vsd_filters = {'external': 'true'}
        if filters.get('subnet'):
            subnet_mapping = nuagedb.get_subnet_l2dom_by_id(
                context.session, filters['subnet'][0])
            if subnet_mapping:
                if self._is_l3(subnet_mapping):
                    message = ("Subnet %s doesn't have mapping l2domain on "
                               "VSD " % filters['subnet'][0])
                    raise nuage_exc.NuageBadRequest(msg=message)
                domain_type = vsd_constants.L2DOMAIN
                domain_id = subnet_mapping['nuage_subnet_id']
            else:
                message = ("Subnet %s doesn't have mapping l2domain on "
                           "VSD " % filters['subnet'][0])
                raise nuage_exc.NuageBadRequest(msg=message)
        elif filters.get('router'):
            router_id = filters.get('router')[0]
            nuage_router = self.vsdclient.get_l3domain_by_external_id(
                router_id)
            if nuage_router:
                domain_type = vsd_constants.DOMAIN
                domain_id = nuage_router['ID']
            else:
                msg = _("VSD domain not found for router %s") % router_id
                raise n_exc.BadRequest(
                    resource='nuage_external_security_group', msg=msg)
        elif filters.get('id'):
            return self.get_nuage_external_security_group(
                context,
                filters.get('id')[0])
        elif filters.get('name'):
            vsd_filters['name'] = filters.get('name')[0]

        try:
            ext_sgs = self.vsdclient.get_policygroups(parent_type=domain_type,
                                                      parent_id=domain_id,
                                                      **vsd_filters)
        except Exception:
            raise nuage_exc.NuageNotFound(
                resource='nuage-external-security-group')
        return [
            self._make_external_security_group_dict(sg, context, fields)
            for sg in ext_sgs
        ]
Exemple #13
0
    def get_nuage_gateway_vport(self, context, id, fields=None):
        fetch_tenant = self._check_for_permissions(context, None)
        def_netpart = cfg.CONF.RESTPROXY.default_net_partition_name
        netpart = nuagedb.get_default_net_partition(context, def_netpart)

        resp = self.nuageclient.get_gateway_vport(fetch_tenant, netpart['id'],
                                                  id)
        if resp:
            if not resp.get('subnet_id'):
                subnet_mapping = nuagedb.get_subnet_l2dom_by_nuage_id(
                    context.session, resp['nuage_subnet_id'])
                resp['subnet_id'] = subnet_mapping['subnet_id']
            return self._make_vport_dict(resp, fields=fields, context=context)
        else:
            raise nuage_exc.NuageNotFound(resource='nuage_vport',
                                          resource_id=id)
Exemple #14
0
 def get_nuage_external_security_group(self,
                                       context,
                                       ext_sg_id,
                                       fields=None):
     try:
         filters = {'external': 'true'}
         ext_pg = self.vsdclient.get_policygroup(ext_sg_id,
                                                 required=True,
                                                 **filters)
     except Exception:
         raise nuage_exc.NuageNotFound(
             resource='nuage-external-security-group',
             resource_id=ext_sg_id)
     return self._make_external_security_group_dict(ext_pg,
                                                    context=context,
                                                    fields=fields)
Exemple #15
0
 def get_nuage_l2bridge(self, context, nuage_l2bridge_id, fields=None):
     bridge = nuagedb.get_nuage_l2bridge(context.session,
                                         l2bridge_id=nuage_l2bridge_id)
     if not bridge:
         raise exceptions.NuageNotFound(resource='nuage_l2bridge',
                                        resource_id=nuage_l2bridge_id)
     bridge = self._make_l2bridges_dict(bridge, fields)
     if not fields or 'physnets' in fields:
         physnets = nuagedb.get_nuage_l2bridge_physnet_mappings(
             context.session, l2bridge_id=bridge['id'])
         bridge['physnets'] = self._make_physnet_mapping_dict(physnets)
     if not fields or 'networks' in fields:
         networks = nuagedb.get_networks_for_nuage_l2bridge(
             context.session, nuage_l2bridge_id)
         networks = [n['id'] for n in networks]
         bridge['networks'] = networks
     return bridge
    def get_nuage_gateway_vport(self, context, id, fields=None):
        fetch_tenant = self._check_for_permissions(context, None)
        def_netpart = cfg.CONF.RESTPROXY.default_net_partition_name
        netpart = nuagedb.get_default_net_partition(context, def_netpart)

        resp = self.vsdclient.get_gateway_vport(context,
                                                fetch_tenant,
                                                netpart['id'],
                                                id)
        if not resp:
            raise nuage_exc.NuageNotFound(resource='nuage_vport',
                                          resource_id=id)
        if not resp.get('subnet_id'):
            nuage_subnet_id = resp['nuage_subnet_id']
            subnet_info = nuagedb.get_subnet_info_by_nuage_id(
                context.session, nuage_subnet_id)
            if subnet_info:
                if 'subnet_id' in subnet_info:
                    resp['subnet_id'] = subnet_info['subnet_id']
                    LOG.debug('get_nuage_gateway_vport: subnet_id '
                              'could be retrieved via subnet_info')
                elif resp.get('port_id'):
                    subnet_mapping = nuagedb.\
                        get_subnet_l2dom_by_nuage_id_and_port(
                            context.session, nuage_subnet_id, resp['vport_id'])
                    if subnet_mapping:
                        resp['subnet_id'] = subnet_mapping['subnet_id']
                        LOG.debug('get_nuage_gateway_vport: subnet_id '
                                  'could be retrieved via port')
                    else:
                        LOG.debug('get_nuage_gateway_vport: subnet_id '
                                  'could not be retrieved via port')
                else:
                    LOG.debug('get_nuage_gateway_vport: subnet_id could '
                              'not be retrieved')
            else:
                LOG.debug('get_nuage_gateway_vport: subnet_id could not '
                          'be retrieved as no subnet_info is present for '
                          'nuage_subnet_id={}'.format(nuage_subnet_id))
        else:
            LOG.debug('get_nuage_gateway_vport: subnet_id already '
                      'contained')
        return self._make_vport_dict(resp, fields=fields, context=context)
Exemple #17
0
    def create_nuage_redirect_target_rule(self, context,
                                          nuage_redirect_target_rule):
        remote_sg = None
        origin_sg = None
        rtarget_rule = nuage_redirect_target_rule['nuage_redirect_target_rule']
        if rtarget_rule.get('remote_group_id'):
            remote_sg = self.core_plugin.get_security_group(
                context, rtarget_rule.get('remote_group_id'))
        if (rtarget_rule.get('origin_group_id')
                and rtarget_rule.get('origin_group_id') !=
                rtarget_rule.get('remote_group_id')):
            origin_sg = self.core_plugin.get_security_group(
                context, rtarget_rule.get('origin_group_id'))
        self._validate_nuage_redirect_target_rule(rtarget_rule)
        rtarget = self.vsdclient.get_nuage_redirect_target(
            rtarget_rule['redirect_target_id'])
        if not rtarget:
            raise nuage_exc.NuageNotFound(
                resource='nuage_redirect_target',
                resource_id=rtarget_rule['redirect_target_id'])
        if rtarget['parentType'] == constants.L2DOMAIN:
            domain = self.vsdclient.get_l2domain_by_id(rtarget['parentID'])
        else:
            domain = self.vsdclient.get_l3domain_by_id(rtarget['parentID'],
                                                       True)
        vsd_managed = False if domain['externalID'] else True
        if remote_sg:
            rtarget_rule['remote_group_name'] = remote_sg['name']
            remote_pg = self._find_or_create_policygroup_using_rt(
                context, remote_sg['id'], rtarget, vsd_managed)
            rtarget_rule['remote_policygroup_id'] = remote_pg['ID']
            rtarget_rule['origin_policygroup_id'] = remote_pg['ID']
        if origin_sg:
            rtarget_rule['origin_group_name'] = origin_sg['name']
            origin_pg = self._find_or_create_policygroup_using_rt(
                context, origin_sg['id'], rtarget, vsd_managed)
            rtarget_rule['origin_policygroup_id'] = origin_pg['ID']
        rtarget_rule_resp = self.vsdclient.create_nuage_redirect_target_rule(
            rtarget_rule, rtarget)

        return self._make_redirect_target_rule_dict(rtarget_rule_resp,
                                                    context=context)
Exemple #18
0
    def get_nuage_external_security_groups(self,
                                           context,
                                           filters=None,
                                           fields=None):
        # get all redirect targets
        resource_id = None
        params = {}
        if filters.get('subnet'):
            subnet_mapping = nuagedb.get_subnet_l2dom_by_id(
                context.session, filters['subnet'][0])
            if subnet_mapping:
                if self._is_l3(subnet_mapping):
                    message = ("Subnet %s doesn't have mapping l2domain on "
                               "VSD " % filters['subnet'][0])
                    raise nuage_exc.NuageBadRequest(msg=message)
                params['subnet'] = filters.get('subnet')[0]
                params['subnet_mapping'] = subnet_mapping
            else:
                message = ("Subnet %s doesn't have mapping l2domain on "
                           "VSD " % filters['subnet'][0])
                raise nuage_exc.NuageBadRequest(msg=message)
        elif filters.get('router'):
            params['router'] = filters.get('router')[0]
        elif filters.get('id'):
            params['id'] = filters.get('id')[0]
            resource_id = params['id']
        elif filters.get('name'):
            params['name'] = filters.get('name')[0]
            resource_id = params['name']

        try:
            ext_sgs = self.vsdclient.get_nuage_external_security_groups(params)
        except Exception:
            raise nuage_exc.NuageNotFound(
                resource='nuage-external-security-group',
                resource_id=resource_id)
        return [
            self._make_external_security_group_dict(sg, context, fields)
            for sg in ext_sgs
        ]
Exemple #19
0
    def update_nuage_l2bridge(self, context, l2bridge_id, nuage_l2bridge):
        nuage_l2bridge = nuage_l2bridge['nuage_l2bridge']
        with context.session.begin(subtransactions=True):
            current = nuagedb.get_nuage_l2bridge_blocking(
                context.session, l2bridge_id)
            if not current:
                raise exceptions.NuageNotFound(resource='nuage_l2bridge',
                                               resource_id=l2bridge_id)
            physnets = nuagedb.get_nuage_l2bridge_physnet_mappings(
                context.session, l2bridge_id=current['id'])
            if nuage_l2bridge.get('physnets') is not None:
                current_keyset = {(p['physnet'], p['segmentation_id'],
                                   p['segmentation_type'])
                                  for p in physnets}
                future_keyset = {(p['physnet_name'], p['segmentation_id'],
                                  p['segmentation_type'])
                                 for p in nuage_l2bridge['physnets']}
                # Check deleted physnets
                deleted = current_keyset - future_keyset
                for to_delete in deleted:
                    db_physnet = nuagedb.get_nuage_l2bridge_physnet_mappings(
                        context.session,
                        l2bridge_id=current['id'],
                        physnet=to_delete[0],
                        segmentation_id=to_delete[1],
                        segmentation_type=to_delete[2])[0]
                    msg = _("Physical network {} with segmentation_id {} and "
                            "segmentation_type {} is currently in use. It is "
                            "not allowed to remove a physical network that is "
                            "in use from a nuage_l2bridge.")
                    self._check_physnet_not_in_use_by_network(
                        context.session,
                        db_physnet['physnet'],
                        db_physnet['segmentation_id'],
                        db_physnet['segmentation_type'],
                        msg=msg)
                    context.session.delete(db_physnet)
                # Check added subnets
                added = future_keyset - current_keyset
                for to_add in added:
                    self._validate_physnet(context, to_add[0], to_add[1],
                                           to_add[2])
                    db_physnet = nuage_models.NuageL2bridgePhysnetMapping(
                        l2bridge_id=current['id'],
                        physnet=to_add[0],
                        segmentation_id=to_add[1],
                        segmentation_type=to_add[2])
                    context.session.add(db_physnet)
                physnets = nuagedb.get_nuage_l2bridge_physnet_mappings(
                    context.session, l2bridge_id=current['id'])

            if (nuage_l2bridge.get('name')
                    and current['name'] != nuage_l2bridge['name']):
                current['name'] = nuage_l2bridge['name']
                if current['nuage_subnet_id']:
                    subnet_mapping = nuagedb.get_subnet_l2doms_by_nuage_id(
                        context.session, current['nuage_subnet_id'])[0]
                    self.vsdclient.update_l2domain_template(
                        nuage_l2dom_tmplt_id=(
                            subnet_mapping["nuage_l2dom_tmplt_id"]),
                        description=nuage_l2bridge['name'])
                    self.vsdclient.update_l2domain(
                        nuage_l2dom_id=current['nuage_subnet_id'],
                        description=nuage_l2bridge['name'])
        current['physnets'] = self._make_physnet_mapping_dict(physnets)
        return current