Exemplo n.º 1
0
 def _check_ent_permission(self, gw_id, gw_port_id, netpart_id):
     gw = gw_helper.get_gateway(self.restproxy, gw_id)
     gw_perm = gw_helper.get_ent_permission_on_gateway(
         self.restproxy, gw_id, gw['redundant'])
     if gw_perm and gw_perm['permittedEntityID'] != netpart_id:
         msg = (_("Non default enterprise %(ent)s has permission for "
                  "gateway %(gw)s, so cannot create/delete vlan") % {
                      'ent': gw_perm['permittedEntityID'],
                      'gw': gw_id
                  })
         raise restproxy.RESTProxyError(msg)
     else:
         gw_port_perm = gw_helper.get_ent_permission_on_port(
             self.restproxy, gw_port_id,
             (gw['redundant']
              and gw['personality'] == constants.GW_TYPE['VSG']))
         if gw_port_perm and (gw_port_perm['permittedEntityID'] !=
                              netpart_id):
             msg = (_("Non default enterprise %(ent)s has permission for "
                      "gateway port %(port)s, so cannot create/delete "
                      "vlan") % {
                          'ent': gw_port_perm['permittedEntityID'],
                          'port': gw_port_id
                      })
             raise restproxy.RESTProxyError(msg)
Exemplo n.º 2
0
    def update_subnet(self, neutron_subnet, params):
        type = constants.NETWORK_TYPE_L3
        new_name = neutron_subnet.get('name')
        if params['type']:
            type = constants.NETWORK_TYPE_L2

        nuagedhcpoptions = dhcpoptions.NuageDhcpOptions(self.restproxy)
        nuagedhcpoptions.update_nuage_dhcp(neutron_subnet,
                                           parent_id=params['parent_id'],
                                           network_type=type)

        if type == constants.NETWORK_TYPE_L2 and 'dhcp_ip' in params:
            nuagel2domtemplate = nuagelib.NuageL2DomTemplate()
            if neutron_subnet.get('enable_dhcp'):
                # Enable dhcpmanaged on the l2domain template
                net = params['net']
                data = {
                    "DHCPManaged": neutron_subnet['enable_dhcp'],
                    "address": str(net.ip),
                    "netmask": str(net.netmask),
                    "gateway": params['dhcp_ip'],
                }
                response = self.restproxy.rest_call(
                    'PUT', nuagel2domtemplate.put_resource(params['type']),
                    data)
            else:
                # Disable dhcpmanaged on the l2domain template
                response = self.restproxy.rest_call(
                    'PUT', nuagel2domtemplate.put_resource(params['type']),
                    {'DHCPManaged': False})
            if not nuagel2domtemplate.validate(response):
                raise restproxy.RESTProxyError(nuagel2domtemplate.error_msg)
        if new_name:
            # update the description on the VSD for this subnet if required
            # If a subnet is updated from horizon, we get the name of the
            # subnet aswell in the subnet dict for update.
            if type == constants.NETWORK_TYPE_L2:
                nuagel2domain = nuagelib.NuageL2Domain()
                l2dom = self.restproxy.rest_call(
                    'GET', nuagel2domain.get_resource(params['parent_id']), '')
                if not nuagel2domain.validate(l2dom):
                    raise restproxy.RESTProxyError(nuagel2domain.error_msg)
                if nuagel2domain.get_description(l2dom) != new_name:
                    response = self.restproxy.rest_call(
                        'PUT', nuagel2domain.put_resource(params['parent_id']),
                        {'description': neutron_subnet['name']})
                    if not nuagel2domain.validate(response):
                        raise restproxy.RESTProxyError(nuagel2domain.error_msg)
            else:
                nuagesubn = nuagelib.NuageSubnet()
                l3dom = self.restproxy.rest_call(
                    'GET', nuagesubn.get_resource(params['parent_id']), '')
                if not nuagesubn.validate(l3dom):
                    raise restproxy.RESTProxyError(nuagesubn.error_msg)
                if nuagesubn.get_description(l3dom) != new_name:
                    response = self.restproxy.rest_call(
                        'PUT', nuagesubn.put_resource(params['parent_id']),
                        {'description': neutron_subnet['name']})
                    if not nuagesubn.validate(response):
                        raise restproxy.RESTProxyError(nuagesubn.error_msg)
def delete_resources_created_for_l2dom_providernet(restproxy_serv, l2domid):
    nuagel2domain = nuagelib.NuageL2Domain()
    # Get bridge vport on given l2domain
    bridge_vports = restproxy_serv.rest_call(
        'GET', nuagel2domain.get_all_vports(l2domid), '',
        nuagel2domain.extra_headers_vport_get())
    if not nuagel2domain.validate(bridge_vports):
        raise restproxy.RESTProxyError(nuagel2domain.error_msg)

    # Delete bridge interface and bridge vport if it is subnet created for
    # provider net
    if bridge_vports and bridge_vports[VSD_RESP_OBJ]:
        nuage_vport = nuagelib.NuageVPort()
        bridge_vport = bridge_vports[VSD_RESP_OBJ][0]

        bridge_iface = restproxy_serv.rest_call(
            'GET', nuage_vport.post_bridge_interface(bridge_vport['ID']),
            '')
        if not nuage_vport.validate(bridge_iface):
            raise restproxy.RESTProxyError(nuage_vport.error_msg)

        if bridge_iface and bridge_iface[VSD_RESP_OBJ]:
            bridge_iface_id = bridge_iface[VSD_RESP_OBJ][0]['ID']
            restproxy_serv.rest_call(
                'DELETE',
                nuage_vport.del_bridge_interface(bridge_iface_id),
                '')

        # Delete bridge vport
        nuage_vport = nuagelib.NuageVPort({'vport_id': bridge_vport['ID']})
        restproxy_serv.delete(nuage_vport.delete_resource())

        # Delete vlan obj on gateway port
        delete_vlan_for_gw_port(restproxy_serv, bridge_vport)
Exemplo n.º 4
0
    def check_if_l2Dom_in_correct_ent(self, nuage_l2dom_id, nuage_netpart):
        nuagesubn = nuagelib.NuageSubnet()
        resp_subn = self.restproxy.rest_call(
            'GET', nuagesubn.get_resource(nuage_l2dom_id), '')
        if not nuagesubn.validate(resp_subn):
            nuagel2dom = nuagelib.NuageL2Domain()
            response = self.restproxy.rest_call(
                'GET', nuagel2dom.get_resource(nuage_l2dom_id), '')
            if not nuagel2dom.validate(response):
                raise restproxy.RESTProxyError(nuagel2dom.error_msg)
            else:
                if response[3][0]['parentID'] == nuage_netpart['id']:
                    return True
                return False
        else:
            req_params = {'zone_id': resp_subn[3][0]['parentID']}
            nuagezone = nuagelib.NuageZone(create_params=req_params)
            resp_zone = self.restproxy.rest_call('GET',
                                                 nuagezone.get_resource(), '')

            if not nuagezone.validate(resp_zone):
                raise restproxy.RESTProxyError(nuagezone.error_msg)

            req_params = {'domain_id': resp_zone[3][0]['parentID']}
            nuage_l3domain = nuagelib.NuageL3Domain(create_params=req_params)
            dom_resp = self.restproxy.rest_call('GET',
                                                nuage_l3domain.get_resource(),
                                                '')

            if not nuage_l3domain.validate(dom_resp):
                raise restproxy.RESTProxyError(nuage_l3domain.error_msg)
            if dom_resp[3][0]['parentID'] == nuage_netpart['id']:
                return True
            return False
Exemplo n.º 5
0
    def add_tenant_perm(self, vlan_id, user_tenant, netpart_id):
        req_params = {'vlan_id': vlan_id}
        # Check if the grp exists in VSD, if not create it
        nuage_user, nuage_group = helper.create_usergroup(
            self.restproxy, user_tenant, netpart_id)

        # Check if permission already exists
        perm = gw_helper.get_tenant_perm(self.restproxy, vlan_id)
        if perm:
            msg = _("Vlan %(vlan)s  already assigned to %(ten)s") % \
                {'vlan': vlan_id, 'ten': perm['permittedEntityName']}
            if perm['permittedEntityID'] != nuage_group:
                raise restproxy.RESTProxyError(msg)
            else:
                LOG.debug(msg)
                return

        nuage_perm = nuagelib.NuagePermission(create_params=req_params)
        data = nuage_perm.perm_update(nuage_group)
        data.update({'externalID': get_vsd_external_id(user_tenant)})
        response = self.restproxy.rest_call('POST',
                                            nuage_perm.get_resource_by_vlan(),
                                            data)
        if not nuage_perm.validate(response):
            raise restproxy.RESTProxyError(nuage_perm.error_msg)
Exemplo n.º 6
0
def get_nuage_port_by_id(restproxy_serv, params):
    req_params = {'externalID': get_vsd_external_id(params['neutron_port_id'])}

    vport_type = params.get('nuage_vport_type')
    if vport_type == constants.HOST_VPORT_TYPE:
        req_params['vport_id'] = params['nuage_vport_id']
        nuage_intf = nuagelib.NuageHostInterface(create_params=req_params)
        nuage_extra_headers = nuage_intf.extra_headers_by_externalid()
    else:
        nuage_intf = nuagelib.NuageVMInterface(create_params=req_params)
        nuage_extra_headers = nuage_intf.extra_headers_for_all_vmifs()

    response = restproxy_serv.rest_call('GET',
                                        nuage_intf.get_all_resource(),
                                        '',
                                        extra_headers=nuage_extra_headers)

    if not nuage_intf.validate(response):
        raise restproxy.RESTProxyError(nuage_intf.error_msg,
                                       nuage_intf.vsd_error_code)

    if len(response[3]) > 0:
        port = response[3][0]
        req_params = {'vport_id': port['VPortID']}
        nuage_vport = nuagelib.NuageVPort(create_params=req_params)
        vport_resp = restproxy_serv.rest_call('GET',
                                              nuage_vport.get_resource(), '')
        if not nuage_vport.validate(vport_resp):
            raise restproxy.RESTProxyError(nuage_vport.error_msg,
                                           nuage_vport.vsd_error_code)
        vport = vport_resp[3][0]
        vport['nuage_vif_id'] = port['ID']
        return vport
Exemplo n.º 7
0
    def _create_default_l3template_for_netpart(self, np_id, name):
        req_params = {'net_partition_id': np_id, 'name': name}
        extra_params = {'externalID': np_id + '@openstack'}
        nuagel3domtemplate = \
            nuagelib.NuageL3DomTemplate(create_params=req_params,
                                        extra_params=extra_params)
        response = self.restproxy.rest_call('POST',
                                            nuagel3domtemplate.post_resource(),
                                            nuagel3domtemplate.post_data())
        if not nuagel3domtemplate.validate(response):
            raise restproxy.RESTProxyError(nuagel3domtemplate.error_msg)
        l3dom_tid = nuagel3domtemplate.get_templateid(response)
        isolated_zone_name = constants.DEF_NUAGE_ZONE_PREFIX + '-' + l3dom_tid
        params = {'name': isolated_zone_name, 'l3domain_id': l3dom_tid}
        nuagezonetemplate = nuagelib.NuageZoneTemplate(
            create_params=params, extra_params=extra_params)
        self.restproxy.rest_call('POST', nuagezonetemplate.post_resource(),
                                 nuagezonetemplate.post_data())
        if not nuagezonetemplate.validate(response):
            raise restproxy.RESTProxyError(nuagezonetemplate.error_msg)

        shared_zone_name = (constants.DEF_NUAGE_ZONE_PREFIX + '-pub-' +
                            l3dom_tid)
        nuagezonetemplate.create_params['name'] = shared_zone_name
        self.restproxy.rest_call('POST', nuagezonetemplate.post_resource(),
                                 nuagezonetemplate.post_data())
        if not nuagezonetemplate.validate(response):
            raise restproxy.RESTProxyError(nuagezonetemplate.error_msg)
        return l3dom_tid
Exemplo n.º 8
0
    def create_gateway_port_vlan(self, vlan_dict):
        gw_id = vlan_dict.get('gateway')
        gw_port_id = vlan_dict['gatewayport']
        vlan_value = vlan_dict['value']

        # Confirm that the gatewayport belongs to the gateway
        gw_port = gw_helper.get_gateway_port(self.restproxy, gw_port_id, gw_id)
        if not gw_port:
            msg = (_("Port %(port)s not found on gateway %(gw)s") % {
                'port': gw_port_id,
                'gw': gw_id
            })
            raise restproxy.RESTProxyError(msg)

        if not gw_id:
            gw_id = gw_port['parentID']
        gw = gw_helper.get_gateway(self.restproxy, gw_id)

        req_params = {'port_id': gw_port_id, 'personality': gw['personality']}

        nuage_gw_vlan = nuagelib.NuageVlanBase.factory(
            create_params=req_params,
            extra_params=None,
            redundant=gw['redundant'])
        response = self.restproxy.rest_call(
            'POST', nuage_gw_vlan.post_vlan(),
            nuage_gw_vlan.post_vlan_data(vlan_value))
        if not nuage_gw_vlan.validate(response):
            raise restproxy.RESTProxyError(nuage_gw_vlan.error_msg)

        return nuage_gw_vlan.get_response_objlist(response)
def process_provider_network(restproxy_serv, pg_obj, params):
    pnet_binding = params.get('pnet_binding')
    np_id = params['netpart_id']

    gw_port = pnet_binding['physical_network']
    req_params = {
        'port_id': gw_port,
        'np_id': params['netpart_id']
    }

    nuage_gw_port = nuagelib.NuageGatewayPort(create_params=req_params)
    response = restproxy_serv.rest_call('GET', nuage_gw_port.get_resource(),
                                        '')
    if not nuage_gw_port.validate(response):
        raise restproxy.RESTProxyError(nuage_gw_port.error_msg)
    nuage_gw_id = nuage_gw_port.get_gw(response)

    gw_params = {
        'gw_id': nuage_gw_id,
        'np_id': params['netpart_id']
    }

    gw_port_ent_perm = False
    gw_ent_perm = check_gw_enterprise_permissions(restproxy_serv, gw_params)
    if not gw_ent_perm:
        gw_port_ent_perm = check_gw_port_enterprise_permissions(
            restproxy_serv, req_params)
    # create vlan on gw port
    vlan_id = pnet_binding['vlan_id']
    response = restproxy_serv.rest_call('POST', nuage_gw_port.post_vlan(),
                                        nuage_gw_port.post_vlan_data(vlan_id))
    if not nuage_gw_port.validate(response):
        raise restproxy.RESTProxyError(nuage_gw_port.error_msg)
    nuage_vlan_id = nuage_gw_port.get_response_id(response)
    params['nuage_vlan_id'] = nuage_vlan_id

    # if the enterprise permission is not set for gateway
    # and gateway port,  set enterprise permission for vlan
    # for the current net partition
    if not gw_ent_perm and not gw_port_ent_perm:
        # Add permissions to extend the vlan on gateway port for this np
        req_params = {
            'vlan_id': nuage_vlan_id,
            'np_id': params['netpart_id']
        }
        nuage_vlan = nuagelib.NuageVlan(create_params=req_params)
        response = restproxy_serv.rest_call('POST',
                                            nuage_vlan.get_ent_perm(),
                                            nuage_vlan.ent_perm_update(np_id))
        if not nuage_vlan.validate(response):
            raise restproxy.RESTProxyError(nuage_vlan.error_msg)

    # Get gateway personality, as for gateway of type VSG, policygroup of
    # type hardware to be used
    gw_type = get_gw_personality(restproxy_serv, gw_params)

    params['gw_type'] = gw_type
    create_bridge_vport_iface_for_pnet(restproxy_serv, pg_obj, params)
Exemplo n.º 10
0
def delete_resources_created_for_domainsubnet_providernet(
        restproxy_serv, pg_obj, nuage_subn_id, neutron_subn_id):
    # Get vports on the given nuage domain subnet
    nuagel3domsub = nuagelib.NuageSubnet()
    bridge_vports = restproxy_serv.rest_call(
        'GET', nuagel3domsub.get_all_vports(nuage_subn_id), '',
        nuagel3domsub.extra_headers_vport_get())
    if not nuagel3domsub.validate(bridge_vports):
        raise restproxy.RESTProxyError(nuagel3domsub.error_msg)

    # Delete bridge interface and bridge vport if it is subnet created for
    # provider net
    if bridge_vports and bridge_vports[3]:
        nuage_vport = nuagelib.NuageVPort()
        vport = bridge_vports[VSD_RESP_OBJ][0]

        bridge_iface = restproxy_serv.rest_call(
            'GET', nuage_vport.post_bridge_interface(vport['ID']),
            '')

        if not nuage_vport.validate(bridge_iface):
            raise restproxy.RESTProxyError(nuage_vport.error_msg)

        if bridge_iface and bridge_iface[VSD_RESP_OBJ]:
            bridge_iface_id = \
                bridge_iface[constants.VSD_RESP_OBJ][0]['ID']
            restproxy_serv.rest_call(
                'DELETE',
                nuage_vport.del_bridge_interface(bridge_iface_id),
                '')

        # Delete bridge vport
        nuage_vport = nuagelib.NuageVPort({'vport_id': vport['ID']})
        restproxy_serv.rest_call(
            'DELETE', nuage_vport.get_resource(), '')

        # Delete vlan obj on gateway port
        delete_vlan_for_gw_port(restproxy_serv, vport)

    # Get defaultPG on nuage domain and delete if it is subnet created for
    # providernet
    if bridge_vports:
        nuage_dom_id = helper.get_domain_id_by_nuage_subnet_id(
            restproxy_serv, nuage_subn_id)
        params = {
            'domain_id': nuage_dom_id
        }
        nuage_policygroup = nuagelib.NuagePolicygroup(create_params=params)
        pg_name = 'defaultPG-' + neutron_subn_id
        nuage_policygroups = restproxy_serv.get(
            nuage_policygroup.post_resource(),
            extra_headers=nuage_policygroup.extra_headers_get_name(pg_name))

        if nuage_policygroups:
            nuage_policygroup_id = nuage_policygroups[0]['ID']
            if nuage_policygroup_id:
                pg_obj._delete_policy_group(nuage_policygroup_id)
Exemplo n.º 11
0
 def delete_nuage_extra_dhcp_option(self, dhcp_id, on_rollback):
     nuage_dhcpoptions = nuagelib.NuageDhcpOptions()
     resp = self.restproxy.rest_call('DELETE',
                                     nuage_dhcpoptions.
                                     dhcp_resource(dhcp_id), '')
     if not nuage_dhcpoptions.validate(resp):
         if on_rollback:
             raise restproxy.RESTProxyError("Rollback also failed due to "
                                            "the exception: " +
                                            nuage_dhcpoptions.error_msg)
         else:
             raise restproxy.RESTProxyError(nuage_dhcpoptions.error_msg)
Exemplo n.º 12
0
def validate_provider_network(restproxy_serv, network_type, physical_network,
                              vlan_id):
    match = re.match(UUID_PATTERN, physical_network)
    if not match:
        msg = ("provider:physical_network should be a valid uuid")
        raise restproxy.RESTProxyError(msg)

    if not validate_provider_phy_net(restproxy_serv, physical_network):
        msg = ("provider:physical_network is not of type ACCESS")
        raise restproxy.RESTProxyError(msg)

    if not validate_vlan_id(restproxy_serv, physical_network, vlan_id):
        msg = ("provider:vlan_id is in use")
        raise restproxy.RESTProxyError(msg)
Exemplo n.º 13
0
 def delete_nuage_floatingip(self, id):
     nuagefip = nuagelib.NuageFloatingIP()
     resp = self.restproxy.rest_call('DELETE', nuagefip.delete_resource(id),
                                     '')
     if not nuagefip.validate(resp):
         code = nuagefip.get_error_code(resp)
         raise restproxy.RESTProxyError(nuagefip.error_msg, error_code=code)
Exemplo n.º 14
0
 def get_cms(self, id):
     cms = nuagelib.NuageCms(create_params={'cms_id': id})
     response = self.restproxy.rest_call('GET', cms.get_resource(), '')
     if not cms.get_validate(response):
         LOG.error('CMS with id %s not found on vsd', id)
         raise restproxy.RESTProxyError(cms.error_msg)
     return cms.get_response_obj(response)
Exemplo n.º 15
0
def _get_nuage_domain_id_from_subnet(restproxy_serv, nuage_subnet_id):
    nuagesubn = nuagelib.NuageSubnet()
    nuage_subnet = restproxy_serv.rest_call(
        'GET', nuagesubn.get_resource(nuage_subnet_id), '')
    if not nuagesubn.validate(nuage_subnet):
        raise restproxy.RESTProxyError(nuagesubn.error_msg)
    nuage_zone_id = nuagesubn.get_parentzone(nuage_subnet)

    req_params = {'zone_id': nuage_zone_id}
    nuagezone = nuagelib.NuageZone(create_params=req_params)
    nuage_zone = restproxy_serv.rest_call('GET', nuagezone.get_resource(), '')
    if not nuagezone.validate(nuage_zone):
        raise restproxy.RESTProxyError(nuagezone.error_msg)
    nuage_domain_id = nuagezone.get_response_parentid(nuage_zone)

    return nuage_domain_id
Exemplo n.º 16
0
def get_nuage_fip(restproxy_serv, nuage_fip_id):
    req_params = {'fip_id': nuage_fip_id}
    nuage_fip = nuagelib.NuageFloatingIP(create_params=req_params)
    resp = restproxy_serv.rest_call('GET', nuage_fip.get_fip_resource(), '')
    if not nuage_fip.validate(resp):
        raise restproxy.RESTProxyError(nuage_fip.error_msg)
    return nuage_fip.get_response_obj(resp)
Exemplo n.º 17
0
    def create_nuage_sharedresource(self, params):
        subnet = params['neutron_subnet']
        req_params = {
            'name': subnet['id'],
            'gateway_ip': subnet['gateway_ip'],
            'net': params['net'],
            'type': params['type'],
            'net_id': params['net_id'],
            'externalID': get_vsd_external_id(subnet['id'])
        }
        desc_str = params['net_id'] + '_' + subnet['name']
        extra_params = {'description': desc_str}
        if params.get('underlay_config'):
            extra_params['underlay'] = True
        if params.get('underlay') is not None:
            extra_params['underlay'] = params['underlay']
        if params.get('nuage_uplink'):
            extra_params['sharedResourceParentID'] = params['nuage_uplink']

        nuage_sharedresource = nuagelib.NuageSharedResources(
            create_params=req_params, extra_params=extra_params)
        response = self.restproxy.rest_call(
            'POST', nuage_sharedresource.post_resource(),
            nuage_sharedresource.post_data())
        if not nuage_sharedresource.validate(response):
            code = nuage_sharedresource.get_error_code(response)
            raise restproxy.RESTProxyError(nuage_sharedresource.error_msg,
                                           code)
        return nuage_sharedresource.get_sharedresource_id(response)
Exemplo n.º 18
0
def get_nuage_vport_by_name(restproxy_serv, nuage_subnet_id,
                            nuage_vport_name, subnet_type):
    req_params = dict()
    extra_params = {
        'vport_name': nuage_vport_name
    }

    nuage_vport = nuagelib.NuageVPort(create_params=req_params,
                                      extra_params=extra_params)

    if subnet_type == constants.L2DOMAIN:
        req_params['l2domain_id'] = nuage_subnet_id
        res_url = nuage_vport.get_vports_for_l2domain()
    else:
        req_params['subnet_id'] = nuage_subnet_id
        res_url = nuage_vport.get_vports_for_subnet()

    response = restproxy_serv.rest_call(
        'GET', res_url, '',
        nuage_vport.extra_headers_get_by_name())

    if not nuage_vport.validate(response):
        raise restproxy.RESTProxyError(nuage_vport.error_msg)

    if nuage_vport.check_response_exist(response):
        return nuage_vport.get_response_obj(response)

    return []
Exemplo n.º 19
0
    def get_nuage_static_route(self, params):
        req_params = {
            'address': params['address'],
            'nexthop': params['nexthop'],
            'domain_id': params['nuage_domain_id']
        }

        static_route = nuagelib.NuageStaticRoute(create_params=req_params)
        nuage_extra_headers = static_route.extra_headers_get()

        response = self.restproxy.rest_call(
            'GET',
            static_route.get_resources_of_domain(),
            '',
            extra_headers=nuage_extra_headers)

        if not static_route.validate(response):
            raise restproxy.RESTProxyError(static_route.error_msg)

        if len(response[3]) > 0:
            ret = {
                'nuage_zone_id': response[3][0]['ID'],
                'nuage_static_route_id': response[3][0]['ID'],
                'rd': response[3][0]['routeDistinguisher']
            }

            return ret
Exemplo n.º 20
0
    def _get_gateway_ports(self, req_params, extra_params=None):
        extra_headers = dict()
        if not req_params.get('personality'):
            gw = gw_helper.get_gateway(self.restproxy, req_params['gw_id'])
            req_params['personality'] = gw['personality']
            redundant = 'redundantGatewayStatus' in gw
        else:
            redundant = req_params['redundant']
        nuage_gw_port = nuagelib.NuageGatewayPortBase.factory(
            create_params=req_params,
            extra_params=extra_params,
            redundant=redundant)
        if extra_params:
            if 'gw_port_name' in extra_params:
                extra_headers = nuage_gw_port.extra_headers_by_name()

        response = self.restproxy.rest_call(
            'GET',
            nuage_gw_port.get_resource_by_gateway(),
            '',
            extra_headers=extra_headers)

        if not nuage_gw_port.validate(response):
            raise restproxy.RESTProxyError(nuage_gw_port.error_msg)
        return nuage_gw_port.get_response_objlist(response)
Exemplo n.º 21
0
    def _get_gateway_port_vlans(self,
                                tenant_id,
                                req_params,
                                extra_params=None):
        if not req_params.get('personality'):
            gw_port = gw_helper.get_gateway_port(self.restproxy,
                                                 req_params['port_id'])
            gw = gw_helper.get_gateway(self.restproxy, gw_port['parentID'])
            req_params['personality'] = gw['personality']
            redundant = 'redundantGatewayStatus' in gw
        else:
            redundant = req_params['redundant']
        nuage_gw_vlan = nuagelib.NuageVlanBase.factory(
            create_params=req_params,
            extra_params=extra_params,
            redundant=redundant)

        resource_url = nuage_gw_vlan.get_resource_by_port()

        extra_headers = dict()
        if extra_params and 'vlan_value' in extra_params:
            vlan_val = extra_params['vlan_value']
            if not helper.is_vlan_valid(vlan_val):
                return []
            extra_headers = nuage_gw_vlan.extra_headers_by_value()

        response = self.restproxy.rest_call('GET',
                                            resource_url,
                                            '',
                                            extra_headers=extra_headers)
        if not nuage_gw_vlan.validate(response):
            raise restproxy.RESTProxyError(nuage_gw_vlan.error_msg)

        return nuage_gw_vlan.get_response_objlist(response)
Exemplo n.º 22
0
    def _delete_nuage_vm(self, params):
        nuage_vm_id = self._get_nuage_vm(params, isdelete=True)
        if not nuage_vm_id:
            # It might already be deleted from the VSD
            return
        req_params = {
            'id': nuage_vm_id,
        }

        extra_params = {
            'tenant': params['tenant'],
            'net_partition_name': params['netpart_name']
        }

        nuagevm = nuagelib.NuageVM(create_params=req_params,
                                   extra_params=extra_params)
        resp = self.restproxy.rest_call(
            'DELETE',
            nuagevm.delete_resource(), '',
            extra_headers=nuagevm.extra_headers_delete())
        if not nuagevm.delete_validate(resp):
            raise restproxy.RESTProxyError(nuagevm.error_msg,
                                           nuagevm.vsd_error_code)
        if (not params['portOnSharedSubn'] and
                (params['subn_tenant'] != params['tenant'])):
            self._delete_extra_perm_attached(params['tenant'],
                                             params.get('l2dom_id'),
                                             params.get('l3dom_id'))
Exemplo n.º 23
0
    def _attach_reqd_perm_for_vm_boot(self, params, id, on_l2=True):
        if on_l2:
            # if the vm is to be attached on a non-shared n/w and the request
            # is from an admin tenant, then add the permissions to the l2domain
            # so that the admin tenant can boot a VM on a l2domain that was
            # not created by admin himself.
            l2dom_id = id
            nuage_grp_id_list = self._make_grp_id_list(params)
            self._attach_permissions_to_groups(nuage_grp_id_list, l2dom_id,
                                               params['tenant'],
                                               target='l2domains')
        else:
            # if the vm is to be attached on a non-shared n/w and the request
            # is from an admin tenant, then add the permissions to the zone
            # so that the admin tenant can boot a VM on a domain-subnet
            # that was not created by him.
            zone_id = id
            nuage_perm = nuagelib.NuagePermission(
                create_params={'zone_id': zone_id})
            response = self.restproxy.rest_call(
                'GET', nuage_perm.get_resource_by_zone_id(), '')
            if not nuage_perm.validate(response):
                raise restproxy.RESTProxyError(nuage_perm.error_msg)
            for resp in nuage_perm.get_response_objlist(response):
                if resp['permittedEntityName'] == params['tenant']:
                    return

            nuage_grp_id_list = self._make_grp_id_list(params)
            self._attach_permissions_to_groups(nuage_grp_id_list, id,
                                               params['tenant'])
Exemplo n.º 24
0
    def attach_nuage_group_to_nuagenet(self, tenant, nuage_npid,
                                       nuage_subnetid, shared):
        nuage_uid, nuage_gid = helper.create_usergroup(self.restproxy, tenant,
                                                       nuage_npid)
        nuagesubn = nuagelib.NuageSubnet()
        nuagegroup = nuagelib.NuageGroup()

        if shared:
            # Get the id for grp 'everybody'
            params = {'net_partition_id': nuage_npid}
            nuagegroup = nuagelib.NuageGroup(create_params=params)
            response = self.restproxy.rest_call(
                'GET', nuagegroup.list_resource(), '',
                nuagegroup.extra_headers_get_for_everybody())
            if not nuagegroup.validate(response):
                raise restproxy.RESTProxyError(nuagegroup.error_msg)
            nuage_all_groupid = nuagegroup.get_groupid(response)

        response = self.restproxy. \
            rest_call('GET', nuagesubn.get_resource(nuage_subnetid),
                      '')
        if not nuagesubn.validate(response):
            nuagel2dom = nuagelib.NuageL2Domain()
            response = self.restproxy. \
                rest_call('GET', nuagel2dom.get_resource(nuage_subnetid),
                          '')
            if not nuagel2dom.validate(response):
                raise restproxy.RESTProxyError(nuagel2dom.error_msg)
            if shared:
                self.create_permission(nuage_subnetid,
                                       nuage_all_groupid,
                                       tenant,
                                       perm_on='l2domains')
            else:
                self.create_permission(nuage_subnetid,
                                       nuage_gid,
                                       tenant,
                                       perm_on='l2domains')
            return nuage_uid, nuage_gid
        else:
            if shared:
                self.create_permission(nuagesubn.get_parentzone(response),
                                       nuage_all_groupid, tenant)
            else:
                self.create_permission(nuagesubn.get_parentzone(response),
                                       nuage_gid, tenant)
            return nuage_uid, nuage_gid
Exemplo n.º 25
0
def change_perm_of_subns(restproxy_serv,
                         nuage_npid,
                         nuage_subnetid,
                         shared,
                         tenant_id,
                         remove_everybody=False):
    if shared:
        params = {'net_partition_id': nuage_npid}
        nuagegroup = nuagelib.NuageGroup(create_params=params)
        response = restproxy_serv.rest_call(
            'GET', nuagegroup.list_resource(), '',
            nuagegroup.extra_headers_get_for_everybody())
        if not nuagegroup.validate(response):
            raise restproxy.RESTProxyError(nuagegroup.error_msg)
        nuage_groupid = nuagegroup.get_groupid(response)
    else:
        nuage_userid, nuage_groupid = \
            create_usergroup(restproxy_serv, tenant_id, nuage_npid)
        if remove_everybody:
            params = {'l2dom_id': nuage_subnetid}
            nuagepermission = nuagelib.NuagePermission(create_params=params)
            resource = nuagepermission.get_resource_by_l2dom_id()
            response = restproxy_serv.rest_call('GET', resource, '')
            if not nuagepermission.validate(response):
                if response[0] == constants.RES_NOT_FOUND:
                    return
                raise restproxy.RESTProxyError(nuagepermission.error_msg,
                                               nuagepermission.vsd_error_code)
            permissions = response[3]
            for permission in permissions:
                if permission['permittedEntityName'] == "Everybody":
                    restproxy_serv.delete(
                        nuagepermission.delete_resource(permission['ID']))
                    break

    nuage_permission = nuagelib.NuagePermission()
    post_data = nuage_permission.perm_create_data(
        nuage_groupid, constants.NUAGE_PERMISSION_USE, tenant_id)
    resp = restproxy_serv.rest_call(
        'POST',
        nuage_permission.post_resource_by_parent_id('l2domains',
                                                    nuage_subnetid), post_data)
    if not nuage_permission.validate(resp):
        if (nuage_permission.get_error_code(resp) !=
                constants.CONFLICT_ERR_CODE):
            raise restproxy.RESTProxyError(nuage_permission.error_msg)
Exemplo n.º 26
0
 def delete_gateway_port_vlan(self, vlan_id):
     req_params = {'vlan_id': vlan_id}
     nuage_gw_vlan = nuagelib.NuageVlan(create_params=req_params)
     response = self.restproxy.rest_call(
         'DELETE',
         nuage_gw_vlan.get_resource() + '?responseChoice=1', '')
     if not nuage_gw_vlan.validate(response):
         raise restproxy.RESTProxyError(nuage_gw_vlan.error_msg)
Exemplo n.º 27
0
 def get_nuage_sharedresource(self, id):
     nuage_sharedresource = nuagelib.NuageSharedResources()
     response = self.restproxy.rest_call(
         'GET', nuage_sharedresource.get_resource_by_id(id), '')
     if not nuage_sharedresource.get_validate(response):
         raise restproxy.RESTProxyError(nuage_sharedresource.error_msg,
                                        nuage_sharedresource.vsd_error_code)
     return nuage_sharedresource.get_response_obj(response)
Exemplo n.º 28
0
 def _delete_nuage_sharedresource(self, id):
     nuage_sharedresource = nuagelib.NuageSharedResources()
     resp = self.restproxy.rest_call(
         'DELETE', nuage_sharedresource.delete_resource(id), '')
     if not nuage_sharedresource.validate(resp):
         code = nuage_sharedresource.get_error_code(resp)
         raise restproxy.RESTProxyError(nuage_sharedresource.error_msg,
                                        error_code=code)
Exemplo n.º 29
0
 def create_cms(self, name):
     cms = nuagelib.NuageCms(create_params={'name': name})
     response = self.restproxy.rest_call('POST', cms.post_resource(),
                                         cms.post_data())
     if not cms.validate(response):
         LOG.error('Error creating cms %s', name)
         raise restproxy.RESTProxyError(cms.error_msg)
     return cms.get_response_obj(response)
Exemplo n.º 30
0
def get_gw_personality(restproxy_serv, params):
    nuage_gw = nuagelib.NuageGateway(create_params=params)
    gw_resp = restproxy_serv.rest_call('GET', nuage_gw.get_resource_by_id(),
                                       '')
    if not nuage_gw.validate(gw_resp):
        raise restproxy.RESTProxyError(nuage_gw.error_msg)
    if gw_resp[VSD_RESP_OBJ]:
        return gw_resp[VSD_RESP_OBJ][0]['personality']