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)
def check_gw_port_enterprise_permissions(restproxy_serv, params): nuage_gw_port = nuagelib.NuageGatewayPort(create_params=params) permissions = restproxy_serv.get(nuage_gw_port.get_ent_perm(), required=True) if not permissions: return False else: # check if gateway port has permissions for current net partition if permissions[0]['permittedEntityID'] != (params['np_id']): msg = ("Gateway port doesn't have enterprisepermisssions" " set for net_parttion %s") % params['np_id'] raise Exception(msg) return True
def validate_provider_phy_net(restproxy_serv, physical_network): req_params = { 'port_id': physical_network } nuage_gw_port = nuagelib.NuageGatewayPort(create_params=req_params) gw_port = restproxy_serv.rest_call('GET', nuage_gw_port.get_resource(), '') if not nuage_gw_port.validate(gw_port): raise restproxy.RESTProxyError(nuage_gw_port.error_msg) if gw_port[VSD_RESP_OBJ]: if gw_port[VSD_RESP_OBJ][0]['portType'] == "ACCESS": return True return False
def check_gw_port_enterprise_permissions(restproxy_serv, params): nuage_gw_port = nuagelib.NuageGatewayPort(create_params=params) gw_port_ent_perm_response = restproxy_serv.rest_call( 'GET', nuage_gw_port.get_ent_perm(), '') if not nuage_gw_port.validate(gw_port_ent_perm_response): raise restproxy.RESTProxyError(nuage_gw_port.error_msg) if not gw_port_ent_perm_response[VSD_RESP_OBJ]: return False else: # check if gateway port has permissions for current net partition if gw_port_ent_perm_response[VSD_RESP_OBJ][0]['permittedEntityID'] != ( params['np_id']): msg = ("Gateway port doesn't have enterprisepermisssions" " set for net_parttion %s") % params['np_id'] raise Exception(msg) return True
def validate_vlan_id(restproxy_serv, physical_network, vlan_id): req_params = { 'port_id': physical_network } 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) gw_port_vlans = restproxy_serv.rest_call('GET', nuage_gw_port.post_vlan(), '') if not nuage_gw_port.validate(gw_port_vlans): raise restproxy.RESTProxyError(nuage_gw_port.error_msg) if gw_port_vlans[3]: for vlan in gw_port_vlans[3]: if vlan['value'] == vlan_id: return False return True
def delete_vlan_for_gw_port(restproxy_serv, vport): # Delete vlan obj on gateway port nuage_gw_port = nuagelib.NuageGatewayPort() nuage_vlan = vport['VLANID'] restproxy_serv.delete(nuage_gw_port.delete_vlan(nuage_vlan))
def validate_provider_phy_net(restproxy_serv, physical_network): req_params = {'port_id': physical_network} nuage_gw_port = nuagelib.NuageGatewayPort(create_params=req_params) gw_port = restproxy_serv.get(nuage_gw_port.get_resource(), required=True)[0] return gw_port['portType'] == "ACCESS"