Example #1
0
def delete_nuage_interface(restproxy_serv, nuage_intf_id, type):
    req_params = {'interface_id': nuage_intf_id}
    if type == constants.BRIDGE_VPORT_TYPE:
        nuage_intf = nuagelib.NuageBridgeInterface(create_params=req_params)
    elif type == constants.HOST_VPORT_TYPE:
        nuage_intf = nuagelib.NuageHostInterface(create_params=req_params)
    restproxy_serv.delete(nuage_intf.delete_resource())
Example #2
0
def get_interface_by_vport(restproxy_serv, nuage_vport_id, type):
    req_params = {'vport_id': nuage_vport_id}
    if type == constants.BRIDGE_VPORT_TYPE:
        nuage_intf = nuagelib.NuageBridgeInterface(create_params=req_params)
    elif type == constants.HOST_VPORT_TYPE:
        nuage_intf = nuagelib.NuageHostInterface(create_params=req_params)
    host_interfaces = restproxy_serv.get(nuage_intf.get_resource_by_vport(),
                                         required=True)
    return host_interfaces[0] if host_interfaces else None
def delete_nuage_interface(restproxy_serv, nuage_intf_id, type):
    req_params = {
        'interface_id': nuage_intf_id
    }
    if type == constants.BRIDGE_VPORT_TYPE:
        nuage_intf = nuagelib.NuageBridgeInterface(create_params=req_params)
    elif type == constants.HOST_VPORT_TYPE:
        nuage_intf = nuagelib.NuageHostInterface(create_params=req_params)

    response = restproxy_serv.rest_call('DELETE',
                                        nuage_intf.delete_resource(), '')

    if not nuage_intf.validate(response):
        raise restproxy.RESTProxyError(nuage_intf.error_msg)
def get_interface_by_vport(restproxy_serv, nuage_vport_id, type):
    req_params = {
        'vport_id': nuage_vport_id
    }
    if type == constants.BRIDGE_VPORT_TYPE:
        nuage_intf = nuagelib.NuageBridgeInterface(create_params=req_params)
    elif type == constants.HOST_VPORT_TYPE:
        nuage_intf = nuagelib.NuageHostInterface(create_params=req_params)
    response = restproxy_serv.rest_call('GET',
                                        nuage_intf.get_resource_by_vport(),
                                        '')

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

    if nuage_intf.check_response_exist(response):
        return nuage_intf.get_response_obj(response)
def _create_vport_interface(subnet_id, pg_obj, restproxy_serv,
                            subn_type, vport_type, params):
    gw_type = params.get('gw_type')
    nuage_vlan_id = params.get('nuage_vlan_id')

    req_params = dict()
    extra_params = {
        'vlan': nuage_vlan_id,
        'externalID': get_vsd_external_id(params.get('externalid'))
    }

    if vport_type == constants.BRIDGE_VPORT_TYPE:
        extra_params['type'] = constants.BRIDGE_VPORT_TYPE
        extra_params['name'] = 'Bridge Vport ' + nuage_vlan_id
        extra_params['externalID'] = get_vsd_external_id(
            params['neutron_subnet_id'])
    else:
        extra_params['type'] = constants.HOST_VPORT_TYPE
        extra_params['name'] = 'Host Vport ' + nuage_vlan_id
        extra_params[constants.PORTSECURITY] = params[constants.PORTSECURITY]

    nuage_vport = nuagelib.NuageVPort(create_params=req_params,
                                      extra_params=extra_params)
    if subn_type == constants.SUBNET:
        req_params['subnet_id'] = subnet_id
        extra_params['net_type'] = constants.SUBNET.upper()
        resource_url = nuage_vport.post_vport_for_subnet()
    else:
        req_params['l2domain_id'] = subnet_id
        extra_params['net_type'] = constants.L2DOMAIN.upper()
        resource_url = nuage_vport.post_vport_for_l2domain()

    # create the vport
    vport = restproxy_serv.post(
        resource_url,
        nuage_vport.post_vport_data(),
        on_res_exists=restproxy_serv.retrieve_by_external_id,
        ignore_err_codes=[restproxy.REST_VLAN_IN_USE_ERR_CODE])[0]

    # create the interface
    nuage_vport_id = vport['ID']
    req_params['vport_id'] = nuage_vport_id

    if vport_type == constants.BRIDGE_VPORT_TYPE:
        # Setting the intf name as "BRIDGE INTERFACE(<vport_id>)"
        extra_params['name'] = "BRIDGE INTERFACE(" + nuage_vport_id + ")"
        nuage_interface = nuagelib.NuageBridgeInterface(
            create_params=req_params,
            extra_params=extra_params)
        resource_url = nuage_interface.post_resource_by_vport()
    else:
        extra_params['ipaddress'] = params['ipaddress']
        extra_params['mac'] = params['mac']
        extra_params['externalID'] = get_vsd_external_id(params['externalid'])

        nuage_interface = nuagelib.NuageHostInterface(
            create_params=req_params,
            extra_params=extra_params)
        resource_url = nuage_interface.post_resource_by_vport()

    vport_intf = restproxy_serv.post(
        resource_url,
        nuage_interface.post_iface_data(),
        on_res_exists=restproxy_serv.retrieve_by_external_id,
        ignore_err_codes=[restproxy.REST_IFACE_EXISTS_ERR_CODE])[0]

    if (not params.get('nuage_managed_subnet') and
            params.get('port_security_enabled')):
        if subn_type == constants.SUBNET:
            # Get rtr id from nuage_subnet_id
            nuage_rtr_id = helper._get_nuage_domain_id_from_subnet(
                restproxy_serv,
                subnet_id)
            _create_policygroup_for_vport(gw_type, None, nuage_rtr_id,
                                          params.get('neutron_subnet_id'),
                                          pg_obj, restproxy_serv, vport,
                                          subn_type)
        else:
            _create_policygroup_for_vport(gw_type, subnet_id, None,
                                          params.get('neutron_subnet_id'),
                                          pg_obj, restproxy_serv, vport,
                                          subn_type)
    if (not params.get('nuage_managed_subnet') and
            not params.get('port_security_enabled')):
        if subn_type == constants.SUBNET:
            nuage_rtr_id = helper._get_nuage_domain_id_from_subnet(
                restproxy_serv,
                subnet_id)
            _add_policy_group_for_port_sec(gw_type, None, nuage_rtr_id, pg_obj,
                                           nuage_vport_id)
        else:
            _add_policy_group_for_port_sec(gw_type, subnet_id, None, pg_obj,
                                           nuage_vport_id)

    ret = {
        'vport': vport,
        'interface': vport_intf
    }
    return ret
def _create_vport_interface(subnet_id, restproxy_serv, subn_type, vport_type,
                            params):
    nuage_vlan_id = params.get('nuage_vlan_id')

    req_params = dict()
    extra_params = {
        'vlan': nuage_vlan_id,
        'externalID': get_vsd_external_id(params.get('externalid'))
    }

    if vport_type == constants.BRIDGE_VPORT_TYPE:
        extra_params['type'] = constants.BRIDGE_VPORT_TYPE
        extra_params['name'] = 'Bridge Vport ' + nuage_vlan_id
    else:
        extra_params['type'] = constants.HOST_VPORT_TYPE
        extra_params['name'] = 'Host Vport ' + nuage_vlan_id
        extra_params[constants.PORTSECURITY] = params[constants.PORTSECURITY]

    nuage_vport = nuagelib.NuageVPort(create_params=req_params,
                                      extra_params=extra_params)
    if subn_type == constants.SUBNET:
        req_params['subnet_id'] = subnet_id
        extra_params['net_type'] = constants.SUBNET.upper()
        resource_url = nuage_vport.post_vport_for_subnet()
    else:
        req_params['l2domain_id'] = subnet_id
        extra_params['net_type'] = constants.L2DOMAIN.upper()
        resource_url = nuage_vport.post_vport_for_l2domain()

    # create the vport
    vport = restproxy_serv.post(
        resource_url,
        nuage_vport.post_vport_data(),
        on_res_exists=restproxy_serv.vport_retrieve_by_ext_id_and_vlan,
        ignore_err_codes=[restproxy.REST_VLAN_IN_USE_ERR_CODE])[0]

    # create the interface
    nuage_vport_id = vport['ID']
    req_params['vport_id'] = nuage_vport_id

    if vport_type == constants.BRIDGE_VPORT_TYPE:
        # Setting the intf name as "BRIDGE INTERFACE(<vport_id>)"
        extra_params['name'] = "BRIDGE INTERFACE(" + nuage_vport_id + ")"
        nuage_interface = nuagelib.NuageBridgeInterface(
            create_params=req_params, extra_params=extra_params)
        resource_url = nuage_interface.post_resource_by_vport()
    else:
        extra_params['ipaddress'] = params['ipaddress']
        extra_params['ipaddress_v6'] = params.get('ipaddress_v6')
        extra_params['mac'] = params['mac']
        extra_params['externalID'] = get_vsd_external_id(params['externalid'])

        nuage_interface = nuagelib.NuageHostInterface(
            create_params=req_params, extra_params=extra_params)
        resource_url = nuage_interface.post_resource_by_vport()

    vport_intf = restproxy_serv.post(
        resource_url,
        nuage_interface.post_iface_data(),
        on_res_exists=restproxy_serv.retrieve_by_external_id,
        ignore_err_codes=[restproxy.REST_IFACE_EXISTS_ERR_CODE])[0]

    return {'vport': vport, 'interface': vport_intf}