Exemple #1
0
def _build_gateway_device_body(tenant_id, display_name, neutron_id,
                               connector_type, connector_ip,
                               client_certificate, tz_uuid):

    connector_type_mappings = {
        utils.NetworkTypes.STT: "STTConnector",
        utils.NetworkTypes.GRE: "GREConnector",
        utils.NetworkTypes.BRIDGE: "BridgeConnector",
        'ipsec%s' % utils.NetworkTypes.STT: "IPsecSTT",
        'ipsec%s' % utils.NetworkTypes.GRE: "IPsecGRE"
    }
    nsx_connector_type = connector_type_mappings.get(connector_type)
    body = {
        "display_name": utils.check_and_truncate(display_name),
        "tags": utils.get_tags(os_tid=tenant_id, q_gw_dev_id=neutron_id),
        "admin_status_enabled": True
    }

    if connector_ip and nsx_connector_type:
        body["transport_connectors"] = [{
            "transport_zone_uuid": tz_uuid,
            "ip_address": connector_ip,
            "type": nsx_connector_type
        }]

    if client_certificate:
        body["credential"] = {
            "client_certificate": {
                "pem_encoded": client_certificate
            },
            "type": "SecurityCertificateCredential"
        }
    return body
Exemple #2
0
def update_router_lport(cluster, lrouter_uuid, lrouter_port_uuid,
                        tenant_id, neutron_port_id, display_name,
                        admin_status_enabled, ip_addresses):
    """Updates a logical port on the assigned logical router."""
    lport_obj = dict(
        admin_status_enabled=admin_status_enabled,
        display_name=display_name,
        tags=utils.get_tags(os_tid=tenant_id, q_port_id=neutron_port_id),
        ip_addresses=ip_addresses,
        type="LogicalRouterPortConfig"
    )
    # Do not pass null items to NSX
    for key in lport_obj.keys():
        if lport_obj[key] is None:
            del lport_obj[key]
    path = _build_uri_path(LROUTERPORT_RESOURCE,
                           lrouter_port_uuid,
                           parent_resource_id=lrouter_uuid)
    result = do_request(HTTP_PUT, path,
                        jsonutils.dumps(lport_obj),
                        cluster=cluster)
    LOG.debug(_("Updated logical port %(lport_uuid)s on "
                "logical router %(lrouter_uuid)s"),
              {'lport_uuid': lrouter_port_uuid, 'lrouter_uuid': lrouter_uuid})
    return result
Exemple #3
0
def create_lqueue(cluster, queue_data):
    params = {
        'name': 'display_name',
        'qos_marking': 'qos_marking',
        'min': 'min_bandwidth_rate',
        'max': 'max_bandwidth_rate',
        'dscp': 'dscp'
    }
    queue_obj = dict((nsx_name, queue_data.get(api_name))
                     for api_name, nsx_name in params.iteritems()
                     if attr.is_attr_set(queue_data.get(api_name)))
    if 'display_name' in queue_obj:
        queue_obj['display_name'] = utils.check_and_truncate(
            queue_obj['display_name'])

    queue_obj['tags'] = utils.get_tags()
    try:
        return nsxlib.do_request(HTTP_POST,
                                 nsxlib._build_uri_path(LQUEUE_RESOURCE),
                                 jsonutils.dumps(queue_obj),
                                 cluster=cluster)['uuid']
    except api_exc.NsxApiException:
        # FIXME(salv-orlando): This should not raise NeutronException
        with excutils.save_and_reraise_exception():
            raise exception.NeutronException()
Exemple #4
0
def create_lport(cluster, lswitch_uuid, tenant_id, neutron_port_id,
                 display_name, device_id, admin_status_enabled,
                 mac_address=None, fixed_ips=None, port_security_enabled=None,
                 security_profiles=None, queue_id=None,
                 mac_learning_enabled=None, allowed_address_pairs=None):
    """Creates a logical port on the assigned logical switch."""
    display_name = utils.check_and_truncate(display_name)
    lport_obj = dict(
        admin_status_enabled=admin_status_enabled,
        display_name=display_name,
        tags=utils.get_tags(os_tid=tenant_id,
                            q_port_id=neutron_port_id,
                            vm_id=utils.device_id_to_vm_id(device_id))
    )

    _configure_extensions(lport_obj, mac_address, fixed_ips,
                          port_security_enabled, security_profiles,
                          queue_id, mac_learning_enabled,
                          allowed_address_pairs)

    path = _build_uri_path(LSWITCHPORT_RESOURCE,
                           parent_resource_id=lswitch_uuid)
    result = do_request(HTTP_POST, path, json.dumps(lport_obj),
                        cluster=cluster)

    LOG.debug(_("Created logical port %(result)s on logical switch %(uuid)s"),
              {'result': result['uuid'], 'uuid': lswitch_uuid})
    return result
Exemple #5
0
def create_l2_gw_service(cluster, tenant_id, display_name, devices):
    """Create a NSX Layer-2 Network Gateway Service.

        :param cluster: The target NSX cluster
        :param tenant_id: Identifier of the Openstack tenant for which
        the gateway service.
        :param display_name: Descriptive name of this gateway service
        :param devices: List of transport node uuids (and network
        interfaces on them) to use for the network gateway service
        :raise NsxApiException: if there is a problem while communicating
        with the NSX controller
    """
    # NOTE(salvatore-orlando): This is a little confusing, but device_id in
    # NSX is actually the identifier a physical interface on the gateway
    # device, which in the Neutron API is referred as interface_name
    gateways = [{
        "transport_node_uuid": device['id'],
        "device_id": device['interface_name'],
        "type": "L2Gateway"
    } for device in devices]
    gwservice_obj = {
        "display_name": utils.check_and_truncate(display_name),
        "tags": utils.get_tags(os_tid=tenant_id),
        "gateways": gateways,
        "type": "L2GatewayServiceConfig"
    }
    return nsxlib.do_request(HTTP_POST,
                             nsxlib._build_uri_path(GWSERVICE_RESOURCE),
                             jsonutils.dumps(gwservice_obj),
                             cluster=cluster)
Exemple #6
0
def create_l2_gw_service(cluster, tenant_id, display_name, devices):
    """Create a NSX Layer-2 Network Gateway Service.

        :param cluster: The target NSX cluster
        :param tenant_id: Identifier of the Openstack tenant for which
        the gateway service.
        :param display_name: Descriptive name of this gateway service
        :param devices: List of transport node uuids (and network
        interfaces on them) to use for the network gateway service
        :raise NsxApiException: if there is a problem while communicating
        with the NSX controller
    """
    # NOTE(salvatore-orlando): This is a little confusing, but device_id in
    # NSX is actually the identifier a physical interface on the gateway
    # device, which in the Neutron API is referred as interface_name
    gateways = [{"transport_node_uuid": device['id'],
                 "device_id": device['interface_name'],
                 "type": "L2Gateway"} for device in devices]
    gwservice_obj = {
        "display_name": utils.check_and_truncate(display_name),
        "tags": utils.get_tags(os_tid=tenant_id),
        "gateways": gateways,
        "type": "L2GatewayServiceConfig"
    }
    return do_request(
        "POST", _build_uri_path(GWSERVICE_RESOURCE),
        json.dumps(gwservice_obj), cluster=cluster)
Exemple #7
0
def create_lport(cluster, lswitch_uuid, tenant_id, neutron_port_id,
                 display_name, device_id, admin_status_enabled,
                 mac_address=None, fixed_ips=None, port_security_enabled=None,
                 security_profiles=None, queue_id=None,
                 mac_learning_enabled=None, allowed_address_pairs=None):
    """Creates a logical port on the assigned logical switch."""
    display_name = utils.check_and_truncate(display_name)
    lport_obj = dict(
        admin_status_enabled=admin_status_enabled,
        display_name=display_name,
        tags=utils.get_tags(os_tid=tenant_id,
                            q_port_id=neutron_port_id,
                            vm_id=utils.device_id_to_vm_id(device_id))
    )

    _configure_extensions(lport_obj, mac_address, fixed_ips,
                          port_security_enabled, security_profiles,
                          queue_id, mac_learning_enabled,
                          allowed_address_pairs)

    path = nsxlib._build_uri_path(LSWITCHPORT_RESOURCE,
                                  parent_resource_id=lswitch_uuid)
    result = nsxlib.do_request(HTTP_POST, path, jsonutils.dumps(lport_obj),
                               cluster=cluster)

    LOG.debug("Created logical port %(result)s on logical switch %(uuid)s",
              {'result': result['uuid'], 'uuid': lswitch_uuid})
    return result
Exemple #8
0
def _build_gateway_device_body(
    tenant_id, display_name, neutron_id, connector_type, connector_ip, client_certificate, tz_uuid
):

    connector_type_mappings = {
        utils.NetworkTypes.STT: "STTConnector",
        utils.NetworkTypes.GRE: "GREConnector",
        utils.NetworkTypes.BRIDGE: "BridgeConnector",
        "ipsec%s" % utils.NetworkTypes.STT: "IPsecSTT",
        "ipsec%s" % utils.NetworkTypes.GRE: "IPsecGRE",
    }
    nsx_connector_type = connector_type_mappings.get(connector_type)
    body = {
        "display_name": utils.check_and_truncate(display_name),
        "tags": utils.get_tags(os_tid=tenant_id, q_gw_dev_id=neutron_id),
        "admin_status_enabled": True,
    }

    if connector_ip and nsx_connector_type:
        body["transport_connectors"] = [
            {"transport_zone_uuid": tz_uuid, "ip_address": connector_ip, "type": nsx_connector_type}
        ]

    if client_certificate:
        body["credential"] = {
            "client_certificate": {"pem_encoded": client_certificate},
            "type": "SecurityCertificateCredential",
        }
    return body
Exemple #9
0
def create_router_lport(cluster, lrouter_uuid, tenant_id, neutron_port_id,
                        display_name, admin_status_enabled, ip_addresses,
                        mac_address=None):
    """Creates a logical port on the assigned logical router."""
    lport_obj = dict(
        admin_status_enabled=admin_status_enabled,
        display_name=display_name,
        tags=utils.get_tags(os_tid=tenant_id, q_port_id=neutron_port_id),
        ip_addresses=ip_addresses,
        type="LogicalRouterPortConfig"
    )
    # Only add the mac_address to lport_obj if present. This is because
    # when creating the fake_ext_gw there is no mac_address present.
    if mac_address:
        lport_obj['mac_address'] = mac_address
    path = _build_uri_path(LROUTERPORT_RESOURCE,
                           parent_resource_id=lrouter_uuid)
    result = do_request(HTTP_POST, path, jsonutils.dumps(lport_obj),
                        cluster=cluster)

    LOG.debug(_("Created logical port %(lport_uuid)s on "
                "logical router %(lrouter_uuid)s"),
              {'lport_uuid': result['uuid'],
               'lrouter_uuid': lrouter_uuid})
    return result
Exemple #10
0
def update_router_lport(cluster, lrouter_uuid, lrouter_port_uuid,
                        tenant_id, neutron_port_id, display_name,
                        admin_status_enabled, ip_addresses):
    """Updates a logical port on the assigned logical router."""
    lport_obj = dict(
        admin_status_enabled=admin_status_enabled,
        display_name=display_name,
        tags=utils.get_tags(os_tid=tenant_id, q_port_id=neutron_port_id),
        ip_addresses=ip_addresses,
        type="LogicalRouterPortConfig"
    )
    # Do not pass null items to NSX
    for key in lport_obj.keys():
        if lport_obj[key] is None:
            del lport_obj[key]
    path = nsxlib._build_uri_path(LROUTERPORT_RESOURCE,
                                  lrouter_port_uuid,
                                  parent_resource_id=lrouter_uuid)
    result = nsxlib.do_request(HTTP_PUT, path,
                               jsonutils.dumps(lport_obj),
                               cluster=cluster)
    LOG.debug("Updated logical port %(lport_uuid)s on "
              "logical router %(lrouter_uuid)s",
              {'lport_uuid': lrouter_port_uuid, 'lrouter_uuid': lrouter_uuid})
    return result
Exemple #11
0
def update_port(cluster, lswitch_uuid, lport_uuid, neutron_port_id, tenant_id,
                display_name, device_id, admin_status_enabled,
                mac_address=None, fixed_ips=None, port_security_enabled=None,
                security_profiles=None, queue_id=None,
                mac_learning_enabled=None, allowed_address_pairs=None):
    lport_obj = dict(
        admin_status_enabled=admin_status_enabled,
        display_name=utils.check_and_truncate(display_name),
        tags=utils.get_tags(os_tid=tenant_id,
                            q_port_id=neutron_port_id,
                            vm_id=utils.device_id_to_vm_id(device_id)))

    _configure_extensions(lport_obj, mac_address, fixed_ips,
                          port_security_enabled, security_profiles,
                          queue_id, mac_learning_enabled,
                          allowed_address_pairs)

    path = "/ws.v1/lswitch/" + lswitch_uuid + "/lport/" + lport_uuid
    try:
        result = nsxlib.do_request(HTTP_PUT, path, jsonutils.dumps(lport_obj),
                                   cluster=cluster)
        LOG.debug("Updated logical port %(result)s "
                  "on logical switch %(uuid)s",
                  {'result': result['uuid'], 'uuid': lswitch_uuid})
        return result
    except exception.NotFound as e:
        LOG.error(_LE("Port or Network not found, Error: %s"), str(e))
        raise exception.PortNotFoundOnNetwork(
            port_id=lport_uuid, net_id=lswitch_uuid)
Exemple #12
0
 def test_prepare_body_with_implicit_routing_config(self):
     router_name = 'fake_router_name'
     tenant_id = 'fake_tenant_id'
     neutron_router_id = 'pipita_higuain'
     router_type = 'SingleDefaultRouteImplicitRoutingConfig'
     route_config = {
         'default_route_next_hop': {
             'gateway_ip_address': 'fake_address',
             'type': 'RouterNextHop'
         },
     }
     body = routerlib._prepare_lrouter_body(router_name, neutron_router_id,
                                            tenant_id, router_type,
                                            **route_config)
     expected = {
         'display_name':
         'fake_router_name',
         'routing_config': {
             'default_route_next_hop': {
                 'gateway_ip_address': 'fake_address',
                 'type': 'RouterNextHop'
             },
             'type': 'SingleDefaultRouteImplicitRoutingConfig'
         },
         'tags':
         utils.get_tags(os_tid='fake_tenant_id',
                        q_router_id='pipita_higuain'),
         'type':
         'LogicalRouterConfig'
     }
     self.assertEqual(expected, body)
Exemple #13
0
def create_router_lport(cluster, lrouter_uuid, tenant_id, neutron_port_id,
                        display_name, admin_status_enabled, ip_addresses,
                        mac_address=None):
    """Creates a logical port on the assigned logical router."""
    lport_obj = dict(
        admin_status_enabled=admin_status_enabled,
        display_name=display_name,
        tags=utils.get_tags(os_tid=tenant_id, q_port_id=neutron_port_id),
        ip_addresses=ip_addresses,
        type="LogicalRouterPortConfig"
    )
    # Only add the mac_address to lport_obj if present. This is because
    # when creating the fake_ext_gw there is no mac_address present.
    if mac_address:
        lport_obj['mac_address'] = mac_address
    path = nsxlib._build_uri_path(LROUTERPORT_RESOURCE,
                                  parent_resource_id=lrouter_uuid)
    result = nsxlib.do_request(HTTP_POST, path, jsonutils.dumps(lport_obj),
                               cluster=cluster)

    LOG.debug("Created logical port %(lport_uuid)s on "
              "logical router %(lrouter_uuid)s",
              {'lport_uuid': result['uuid'],
               'lrouter_uuid': lrouter_uuid})
    return result
Exemple #14
0
def create_lqueue(cluster, queue_data):
    params = {
        'name': 'display_name',
        'qos_marking': 'qos_marking',
        'min': 'min_bandwidth_rate',
        'max': 'max_bandwidth_rate',
        'dscp': 'dscp'
    }
    queue_obj = dict(
        (nsx_name, queue_data.get(api_name))
        for api_name, nsx_name in params.iteritems()
        if attr.is_attr_set(queue_data.get(api_name))
    )
    if 'display_name' in queue_obj:
        queue_obj['display_name'] = utils.check_and_truncate(
            queue_obj['display_name'])

    queue_obj['tags'] = utils.get_tags()
    try:
        return do_request(HTTP_POST,
                          _build_uri_path(LQUEUE_RESOURCE),
                          jsonutils.dumps(queue_obj),
                          cluster=cluster)['uuid']
    except api_exc.NsxApiException:
        # FIXME(salv-orlando): This should not raise NeutronException
        with excutils.save_and_reraise_exception():
            raise exception.NeutronException()
Exemple #15
0
def create_lswitch(cluster,
                   neutron_net_id,
                   tenant_id,
                   display_name,
                   transport_zones_config,
                   shared=None,
                   **kwargs):
    # The tag scope adopts a slightly different naming convention for
    # historical reasons
    lswitch_obj = {
        "display_name": utils.check_and_truncate(display_name),
        "transport_zones": transport_zones_config,
        "tags": utils.get_tags(os_tid=tenant_id, quantum_net_id=neutron_net_id)
    }
    # TODO(salv-orlando): Now that we have async status synchronization
    # this tag is perhaps not needed anymore
    if shared:
        lswitch_obj["tags"].append({"tag": "true", "scope": "shared"})
    if "tags" in kwargs:
        lswitch_obj["tags"].extend(kwargs["tags"])
    uri = _build_uri_path(LSWITCH_RESOURCE)
    lswitch = do_request(HTTP_POST,
                         uri,
                         json.dumps(lswitch_obj),
                         cluster=cluster)
    LOG.debug(_("Created logical switch: %s"), lswitch['uuid'])
    return lswitch
Exemple #16
0
def update_port(cluster, lswitch_uuid, lport_uuid, neutron_port_id, tenant_id,
                display_name, device_id, admin_status_enabled,
                mac_address=None, fixed_ips=None, port_security_enabled=None,
                security_profiles=None, queue_id=None,
                mac_learning_enabled=None, allowed_address_pairs=None):
    lport_obj = dict(
        admin_status_enabled=admin_status_enabled,
        display_name=utils.check_and_truncate(display_name),
        tags=utils.get_tags(os_tid=tenant_id,
                            q_port_id=neutron_port_id,
                            vm_id=utils.device_id_to_vm_id(device_id)))

    _configure_extensions(lport_obj, mac_address, fixed_ips,
                          port_security_enabled, security_profiles,
                          queue_id, mac_learning_enabled,
                          allowed_address_pairs)

    path = "/ws.v1/lswitch/" + lswitch_uuid + "/lport/" + lport_uuid
    try:
        result = do_request(HTTP_PUT, path, json.dumps(lport_obj),
                            cluster=cluster)
        LOG.debug(_("Updated logical port %(result)s "
                    "on logical switch %(uuid)s"),
                  {'result': result['uuid'], 'uuid': lswitch_uuid})
        return result
    except exception.NotFound as e:
        LOG.error(_("Port or Network not found, Error: %s"), str(e))
        raise exception.PortNotFoundOnNetwork(
            port_id=lport_uuid, net_id=lswitch_uuid)
Exemple #17
0
 def setUp(self):
     super(TestProxyCreateLswitch, self).setUp()
     self.tenant_id = "foo_tenant"
     self.display_name = "foo_network"
     self.tz_config = [{'zone_uuid': 'foo_zone', 'transport_type': 'stt'}]
     self.tags = utils.get_tags(quantum_net_id='foo_id',
                                os_tid=self.tenant_id)
     self.cluster = None
Exemple #18
0
 def test_lsn_for_network_create(self):
     net_id = "foo_network_id"
     tags = utils.get_tags(n_network_id=net_id)
     obj = {"service_cluster_uuid": "foo", "tags": tags}
     lsnlib.lsn_for_network_create(self.cluster, net_id)
     self.mock_request.assert_called_once_with(
         "POST", "/ws.v1/lservices-node",
         json.dumps(obj), cluster=self.cluster)
Exemple #19
0
def lsn_for_network_create(cluster, network_id):
    lsn_obj = {
        "edge_cluster_uuid": cluster.default_service_cluster_uuid,
        "tags": utils.get_tags(n_network_id=network_id),
    }
    return nsxlib.do_request(
        HTTP_POST, nsxlib._build_uri_path(LSERVICESNODE_RESOURCE), jsonutils.dumps(lsn_obj), cluster=cluster
    )["uuid"]
Exemple #20
0
 def test_lsn_for_network_create(self):
     net_id = "foo_network_id"
     tags = utils.get_tags(n_network_id=net_id)
     obj = {"service_cluster_uuid": "foo", "tags": tags}
     lsnlib.lsn_for_network_create(self.cluster, net_id)
     self.mock_request.assert_called_once_with(
         "POST", "/ws.v1/lservices-node",
         json.dumps(obj), cluster=self.cluster)
Exemple #21
0
def create_security_profile(cluster, tenant_id, neutron_id, security_profile):
    """Create a security profile on the NSX backend.

    :param cluster: a NSX cluster object reference
    :param tenant_id: identifier of the Neutron tenant
    :param neutron_id: neutron security group identifier
    :param security_profile: dictionary with data for
    configuring the NSX security profile.
    """
    path = "/ws.v1/security-profile"
    # Allow all dhcp responses and all ingress traffic
    hidden_rules = {
        'logical_port_egress_rules': [{
            'ethertype': 'IPv4',
            'protocol': constants.PROTO_NUM_UDP,
            'port_range_min': constants.DHCP_RESPONSE_PORT,
            'port_range_max': constants.DHCP_RESPONSE_PORT,
            'ip_prefix': '0.0.0.0/0'
        }],
        'logical_port_ingress_rules': [{
            'ethertype': 'IPv4'
        }, {
            'ethertype': 'IPv6'
        }]
    }
    display_name = utils.check_and_truncate(security_profile.get('name'))
    # NOTE(salv-orlando): neutron-id tags are prepended with 'q' for
    # historical reasons
    body = mk_body(
        tags=utils.get_tags(os_tid=tenant_id, q_sec_group_id=neutron_id),
        display_name=display_name,
        logical_port_ingress_rules=(
            hidden_rules['logical_port_ingress_rules']),
        logical_port_egress_rules=hidden_rules['logical_port_egress_rules'])
    rsp = nsxlib.do_request(HTTP_POST, path, body, cluster=cluster)
    if security_profile.get('name') == 'default':
        # If security group is default allow ip traffic between
        # members of the same security profile is allowed and ingress traffic
        # from the switch
        rules = {
            'logical_port_egress_rules': [{
                'ethertype': 'IPv4',
                'profile_uuid': rsp['uuid']
            }, {
                'ethertype': 'IPv6',
                'profile_uuid': rsp['uuid']
            }],
            'logical_port_ingress_rules': [{
                'ethertype': 'IPv4'
            }, {
                'ethertype': 'IPv6'
            }]
        }

        update_security_group_rules(cluster, rsp['uuid'], rules)
    LOG.debug(_("Created Security Profile: %s"), rsp)
    return rsp
Exemple #22
0
def lsn_for_network_create(cluster, network_id):
    lsn_obj = {
        "service_cluster_uuid": cluster.default_service_cluster_uuid,
        "tags": utils.get_tags(n_network_id=network_id)
    }
    return do_request(HTTP_POST,
                      _build_uri_path(LSERVICESNODE_RESOURCE),
                      json.dumps(lsn_obj),
                      cluster=cluster)["uuid"]
Exemple #23
0
 def setUp(self):
     super(TestProxyCreateLswitch, self).setUp()
     self.tenant_id = "foo_tenant"
     self.display_name = "foo_network"
     self.tz_config = [
         {'zone_uuid': 'foo_zone',
          'transport_type': 'stt'}
     ]
     self.tags = utils.get_tags(quantum_net_id='foo_id',
                                os_tid=self.tenant_id)
     self.cluster = None
Exemple #24
0
 def test_prepare_body_without_routing_config(self):
     router_name = 'fake_router_name'
     tenant_id = 'fake_tenant_id'
     neutron_router_id = 'marekiaro_hamsik'
     router_type = 'RoutingTableRoutingConfig'
     body = routerlib._prepare_lrouter_body(router_name, neutron_router_id,
                                            tenant_id, router_type)
     expected = {'display_name': 'fake_router_name',
                 'routing_config': {'type': 'RoutingTableRoutingConfig'},
                 'tags': utils.get_tags(os_tid='fake_tenant_id',
                                        q_router_id='marekiaro_hamsik'),
                 'type': 'LogicalRouterConfig'}
     self.assertEqual(expected, body)
Exemple #25
0
 def test_prepare_body_without_routing_config(self):
     router_name = 'fake_router_name'
     tenant_id = 'fake_tenant_id'
     neutron_router_id = 'marekiaro_hamsik'
     router_type = 'RoutingTableRoutingConfig'
     body = routerlib._prepare_lrouter_body(router_name, neutron_router_id,
                                            tenant_id, router_type)
     expected = {'display_name': 'fake_router_name',
                 'routing_config': {'type': 'RoutingTableRoutingConfig'},
                 'tags': utils.get_tags(os_tid='fake_tenant_id',
                                        q_router_id='marekiaro_hamsik'),
                 'type': 'LogicalRouterConfig'}
     self.assertEqual(expected, body)
Exemple #26
0
def update_lswitch(cluster, lswitch_id, display_name,
                   tenant_id=None, **kwargs):
    uri = nsxlib._build_uri_path(LSWITCH_RESOURCE, resource_id=lswitch_id)
    lswitch_obj = {"display_name": utils.check_and_truncate(display_name),
                   "tags": utils.get_tags(os_tid=tenant_id)}
    if "tags" in kwargs:
        lswitch_obj["tags"].extend(kwargs["tags"])
    try:
        return nsxlib.do_request(HTTP_PUT, uri, json.dumps(lswitch_obj),
                                 cluster=cluster)
    except exception.NotFound as e:
        LOG.error(_("Network not found, Error: %s"), str(e))
        raise exception.NetworkNotFound(net_id=lswitch_id)
Exemple #27
0
def update_lswitch(cluster, lswitch_id, display_name,
                   tenant_id=None, **kwargs):
    uri = _build_uri_path(LSWITCH_RESOURCE, resource_id=lswitch_id)
    lswitch_obj = {"display_name": utils.check_and_truncate(display_name),
                   "tags": utils.get_tags(os_tid=tenant_id)}
    if "tags" in kwargs:
        lswitch_obj["tags"].extend(kwargs["tags"])
    try:
        return do_request(HTTP_PUT, uri, json.dumps(lswitch_obj),
                          cluster=cluster)
    except exception.NotFound as e:
        LOG.error(_("Network not found, Error: %s"), str(e))
        raise exception.NetworkNotFound(net_id=lswitch_id)
Exemple #28
0
def lsn_port_create(cluster, lsn_id, port_data):
    port_obj = {
        "ip_address": port_data["ip_address"],
        "mac_address": port_data["mac_address"],
        "tags": utils.get_tags(n_mac_address=port_data["mac_address"], n_subnet_id=port_data["subnet_id"]),
        "type": "LogicalServicesNodePortConfig",
    }
    return nsxlib.do_request(
        HTTP_POST,
        nsxlib._build_uri_path(LSERVICESNODEPORT_RESOURCE, parent_resource_id=lsn_id),
        jsonutils.dumps(port_obj),
        cluster=cluster,
    )["uuid"]
Exemple #29
0
def _prepare_lrouter_body(name, neutron_router_id, tenant_id, router_type, distributed=None, **kwargs):
    body = {
        "display_name": utils.check_and_truncate(name),
        "tags": utils.get_tags(os_tid=tenant_id, q_router_id=neutron_router_id),
        "routing_config": {"type": router_type},
        "type": "LogicalRouterConfig",
        "replication_mode": cfg.CONF.NSX.replication_mode,
    }
    # add the distributed key only if not None (ie: True or False)
    if distributed is not None:
        body["distributed"] = distributed
    if kwargs:
        body["routing_config"].update(kwargs)
    return body
Exemple #30
0
    def _get_lrouter(self, tenant_id, router_name, router_id, relations=None):
        schema = '/ws.v1/schema/RoutingTableRoutingConfig'

        router = {'display_name': router_name,
                  'uuid': router_id,
                  'tags': utils.get_tags(os_tid=tenant_id),
                  'distributed': False,
                  'routing_config': {'type': 'RoutingTableRoutingConfig',
                                     '_schema': schema},
                  '_schema': schema,
                  'nat_synchronization_enabled': True,
                  'replication_mode': 'service',
                  'type': 'LogicalRouterConfig',
                  '_href': '/ws.v1/lrouter/%s' % router_id, }
        if relations:
            router['_relations'] = relations
        return router
Exemple #31
0
    def _get_lrouter(self, tenant_id, router_name, router_id, relations=None):
        schema = '/ws.v1/schema/RoutingTableRoutingConfig'

        router = {'display_name': router_name,
                  'uuid': router_id,
                  'tags': utils.get_tags(os_tid=tenant_id),
                  'distributed': False,
                  'routing_config': {'type': 'RoutingTableRoutingConfig',
                                     '_schema': schema},
                  '_schema': schema,
                  'nat_synchronization_enabled': True,
                  'replication_mode': 'service',
                  'type': 'LogicalRouterConfig',
                  '_href': '/ws.v1/lrouter/%s' % router_id, }
        if relations:
            router['_relations'] = relations
        return router
Exemple #32
0
def lsn_port_create(cluster, lsn_id, port_data):
    port_obj = {
        "ip_address":
        port_data["ip_address"],
        "mac_address":
        port_data["mac_address"],
        "tags":
        utils.get_tags(n_mac_address=port_data["mac_address"],
                       n_subnet_id=port_data["subnet_id"]),
        "type":
        "LogicalServicesNodePortConfig",
    }
    return do_request(HTTP_POST,
                      _build_uri_path(LSERVICESNODEPORT_RESOURCE,
                                      parent_resource_id=lsn_id),
                      json.dumps(port_obj),
                      cluster=cluster)["uuid"]
Exemple #33
0
def create_security_profile(cluster, tenant_id, neutron_id, security_profile):
    """Create a security profile on the NSX backend.

    :param cluster: a NSX cluster object reference
    :param tenant_id: identifier of the Neutron tenant
    :param neutron_id: neutron security group identifier
    :param security_profile: dictionary with data for
    configuring the NSX security profile.
    """
    path = "/ws.v1/security-profile"
    # Allow all dhcp responses and all ingress traffic
    hidden_rules = {'logical_port_egress_rules':
                    [{'ethertype': 'IPv4',
                      'protocol': constants.PROTO_NUM_UDP,
                      'port_range_min': constants.DHCP_RESPONSE_PORT,
                      'port_range_max': constants.DHCP_RESPONSE_PORT,
                      'ip_prefix': '0.0.0.0/0'}],
                    'logical_port_ingress_rules':
                    [{'ethertype': 'IPv4'},
                     {'ethertype': 'IPv6'}]}
    display_name = utils.check_and_truncate(security_profile.get('name'))
    # NOTE(salv-orlando): neutron-id tags are prepended with 'q' for
    # historical reasons
    body = mk_body(
        tags=utils.get_tags(os_tid=tenant_id, q_sec_group_id=neutron_id),
        display_name=display_name,
        logical_port_ingress_rules=(
            hidden_rules['logical_port_ingress_rules']),
        logical_port_egress_rules=hidden_rules['logical_port_egress_rules']
    )
    rsp = nsxlib.do_request(HTTP_POST, path, body, cluster=cluster)
    if security_profile.get('name') == 'default':
        # If security group is default allow ip traffic between
        # members of the same security profile is allowed and ingress traffic
        # from the switch
        rules = {'logical_port_egress_rules': [{'ethertype': 'IPv4',
                                                'profile_uuid': rsp['uuid']},
                                               {'ethertype': 'IPv6',
                                                'profile_uuid': rsp['uuid']}],
                 'logical_port_ingress_rules': [{'ethertype': 'IPv4'},
                                                {'ethertype': 'IPv6'}]}

        update_security_group_rules(cluster, rsp['uuid'], rules)
    LOG.debug(_("Created Security Profile: %s"), rsp)
    return rsp
Exemple #34
0
def _prepare_lrouter_body(name, neutron_router_id, tenant_id,
                          router_type, distributed=None, **kwargs):
    body = {
        "display_name": utils.check_and_truncate(name),
        "tags": utils.get_tags(os_tid=tenant_id,
                               q_router_id=neutron_router_id),
        "routing_config": {
            "type": router_type
        },
        "type": "LogicalRouterConfig",
        "replication_mode": cfg.CONF.NSX.replication_mode,
    }
    # add the distributed key only if not None (ie: True or False)
    if distributed is not None:
        body['distributed'] = distributed
    if kwargs:
        body["routing_config"].update(kwargs)
    return body
Exemple #35
0
def update_lswitch(cluster, lswitch_id, display_name,
                   tenant_id=None, **kwargs):
    uri = nsxlib._build_uri_path(LSWITCH_RESOURCE, resource_id=lswitch_id)
    lswitch_obj = {"display_name": utils.check_and_truncate(display_name)}
    # NOTE: tag update will not 'merge' existing tags with new ones.
    tags = []
    if tenant_id:
        tags = utils.get_tags(os_tid=tenant_id)
    # The 'tags' kwarg might existing and be None
    tags.extend(kwargs.get('tags') or [])
    if tags:
        lswitch_obj['tags'] = tags
    try:
        return nsxlib.do_request(HTTP_PUT, uri, jsonutils.dumps(lswitch_obj),
                                 cluster=cluster)
    except exception.NotFound as e:
        LOG.error(_LE("Network not found, Error: %s"), str(e))
        raise exception.NetworkNotFound(net_id=lswitch_id)
Exemple #36
0
 def test_prepare_body_with_implicit_routing_config(self):
     router_name = 'fake_router_name'
     tenant_id = 'fake_tenant_id'
     neutron_router_id = 'pipita_higuain'
     router_type = 'SingleDefaultRouteImplicitRoutingConfig'
     route_config = {
         'default_route_next_hop': {'gateway_ip_address': 'fake_address',
                                    'type': 'RouterNextHop'}, }
     body = routerlib._prepare_lrouter_body(router_name, neutron_router_id,
                                            tenant_id, router_type,
                                            **route_config)
     expected = {'display_name': 'fake_router_name',
                 'routing_config': {
                     'default_route_next_hop':
                     {'gateway_ip_address': 'fake_address',
                      'type': 'RouterNextHop'},
                     'type': 'SingleDefaultRouteImplicitRoutingConfig'},
                 'tags': utils.get_tags(os_tid='fake_tenant_id',
                                        q_router_id='pipita_higuain'),
                 'type': 'LogicalRouterConfig'}
     self.assertEqual(expected, body)
Exemple #37
0
 def test_lsn_port_create(self):
     port_data = {
         "ip_address": "1.2.3.0/24",
         "mac_address": "aa:bb:cc:dd:ee:ff",
         "subnet_id": "foo_subnet_id"
     }
     port_id = "foo_port_id"
     self.mock_request.return_value = {"uuid": port_id}
     lsn_id = "foo_lsn_id"
     result = lsnlib.lsn_port_create(self.cluster, lsn_id, port_data)
     self.assertEqual(result, port_id)
     tags = utils.get_tags(n_subnet_id=port_data["subnet_id"],
                           n_mac_address=port_data["mac_address"])
     port_obj = {
         "ip_address": port_data["ip_address"],
         "mac_address": port_data["mac_address"],
         "type": "LogicalServicesNodePortConfig",
         "tags": tags
     }
     self.mock_request.assert_called_once_with(
         "POST", "/ws.v1/lservices-node/%s/lport" % lsn_id,
         json.dumps(port_obj), cluster=self.cluster)
Exemple #38
0
 def test_lsn_port_create(self):
     port_data = {
         "ip_address": "1.2.3.0/24",
         "mac_address": "aa:bb:cc:dd:ee:ff",
         "subnet_id": "foo_subnet_id"
     }
     port_id = "foo_port_id"
     self.mock_request.return_value = {"uuid": port_id}
     lsn_id = "foo_lsn_id"
     result = lsnlib.lsn_port_create(self.cluster, lsn_id, port_data)
     self.assertEqual(result, port_id)
     tags = utils.get_tags(n_subnet_id=port_data["subnet_id"],
                           n_mac_address=port_data["mac_address"])
     port_obj = {
         "ip_address": port_data["ip_address"],
         "mac_address": port_data["mac_address"],
         "type": "LogicalServicesNodePortConfig",
         "tags": tags
     }
     self.mock_request.assert_called_once_with(
         "POST", "/ws.v1/lservices-node/%s/lport" % lsn_id,
         json.dumps(port_obj), cluster=self.cluster)
Exemple #39
0
def create_lswitch(cluster, neutron_net_id, tenant_id, display_name,
                   transport_zones_config,
                   shared=None,
                   **kwargs):
    # The tag scope adopts a slightly different naming convention for
    # historical reasons
    lswitch_obj = {"display_name": utils.check_and_truncate(display_name),
                   "transport_zones": transport_zones_config,
                   "tags": utils.get_tags(os_tid=tenant_id,
                                          quantum_net_id=neutron_net_id)}
    # TODO(salv-orlando): Now that we have async status synchronization
    # this tag is perhaps not needed anymore
    if shared:
        lswitch_obj["tags"].append({"tag": "true",
                                    "scope": "shared"})
    if "tags" in kwargs:
        lswitch_obj["tags"].extend(kwargs["tags"])
    uri = _build_uri_path(LSWITCH_RESOURCE)
    lswitch = do_request(HTTP_POST, uri, json.dumps(lswitch_obj),
                         cluster=cluster)
    LOG.debug(_("Created logical switch: %s"), lswitch['uuid'])
    return lswitch