Example #1
0
    def test_create_resource(self):
        api = self.new_mocked_client(client.NSX3Client)
        client.create_resource('ports', {'resource-name': 'port1'}, client=api)

        assert_json_call('post',
                         api,
                         'https://1.2.3.4/api/v1/ports',
                         data=jsonutils.dumps({'resource-name': 'port1'}))
Example #2
0
    def test_create_resource(self):
        api = self.new_mocked_client(client.NSX3Client)
        client.create_resource(
            'ports', {'resource-name': 'port1'},
            client=api)

        assert_json_call(
            'post', api,
            'https://1.2.3.4/api/v1/ports',
            data=jsonutils.dumps({'resource-name': 'port1'}))
Example #3
0
def create_empty_section(display_name, description, applied_tos, tags,
                         operation=INSERT_BOTTOM, other_section=None):
    resource = 'firewall/sections?operation=%s' % operation
    body = _build_section(display_name, description, applied_tos, tags)
    if other_section:
        resource += '&id=%s' % other_section
    return nsxclient.create_resource(resource, body)
Example #4
0
def add_static_route(logical_router_id, dest_cidr, nexthop):
    resource = 'logical-routers/%s/routing/static-routes' % logical_router_id
    body = {}
    if dest_cidr:
        body['network'] = dest_cidr
    if nexthop:
        body['next_hops'] = [{"ip_address": nexthop}]
    return client.create_resource(resource, body)
Example #5
0
def create_nsgroup(display_name, description, tags):
    body = {
        'display_name': display_name,
        'description': description,
        'tags': tags,
        'members': []
    }
    return nsxclient.create_resource('ns-groups', body)
Example #6
0
def create_empty_section(display_name,
                         description,
                         applied_tos,
                         tags,
                         operation=INSERT_BOTTOM,
                         other_section=None):
    resource = 'firewall/sections?operation=%s' % operation
    body = _build_section(display_name, description, applied_tos, tags)
    if other_section:
        resource += '&id=%s' % other_section
    return nsxclient.create_resource(resource, body)
Example #7
0
def add_nat_rule(logical_router_id, action, translated_network,
                 source_net=None, dest_net=None,
                 enabled=True, rule_priority=None):
    resource = 'logical-routers/%s/nat/rules' % logical_router_id
    body = {'action': action,
            'enabled': enabled,
            'translated_network': translated_network}
    if source_net:
        body['match_source_network'] = source_net
    if dest_net:
        body['match_destination_network'] = dest_net
    if rule_priority:
        body['rule_priority'] = rule_priority
    return client.create_resource(resource, body)
Example #8
0
def create_bridge_endpoint(device_name, seg_id, tags):
    """Create a bridge endpoint on the backend.

    Create a bridge endpoint resource on a bridge cluster for the L2 gateway
    network connection.
    :param device_name: device_name actually refers to the bridge cluster's
                        UUID.
    :param seg_id: integer representing the VLAN segmentation ID.
    :param tags: nsx backend specific tags.
    """
    resource = 'bridge-endpoints'
    body = {'bridge_cluster_id': device_name,
            'tags': tags,
            'vlan': seg_id}
    return client.create_resource(resource, body)
Example #9
0
def update_section(section_id, display_name=None, description=None,
                   applied_tos=None, rules=None):
    resource = 'firewall/sections/%s' % section_id
    section = read_section(section_id)

    if rules is not None:
        resource += '?action=update_with_rules'
        section.update({'rules': rules})
    if display_name is not None:
        section['display_name'] = display_name
    if description is not None:
        section['description'] = description
    if applied_tos is not None:
        section['applied_tos'] = [get_nsgroup_reference(nsg_id)
                                  for nsg_id in applied_tos]
    if rules is not None:
        return nsxclient.create_resource(resource, section)
    elif any(p is not None for p in (display_name, description, applied_tos)):
        return nsxclient.update_resource(resource, section)
Example #10
0
    def update_section(self, section_id, display_name=None, description=None,
                       applied_tos=None, rules=None):
        resource = 'firewall/sections/%s' % section_id
        section = self.read_section(section_id)

        if rules is not None:
            resource += '?action=update_with_rules'
            section.update({'rules': rules})
        if display_name is not None:
            section['display_name'] = display_name
        if description is not None:
            section['description'] = description
        if applied_tos is not None:
            section['applied_tos'] = [self.get_nsgroup_reference(nsg_id)
                                      for nsg_id in applied_tos]
        if rules is not None:
            return nsxclient.create_resource(resource, section)
        elif any(p is not None for p in (display_name, description,
                                         applied_tos)):
            return self.client.update(resource, section)
Example #11
0
def create_logical_switch(display_name, transport_zone_id, tags,
                          replication_mode=nsx_constants.MTEP,
                          admin_state=True, vlan_id=None):
    # TODO(salv-orlando): Validate Replication mode and admin_state
    # NOTE: These checks might be moved to the API client library if one that
    # performs such checks in the client is available

    resource = 'logical-switches'
    body = {'transport_zone_id': transport_zone_id,
            'replication_mode': replication_mode,
            'display_name': display_name,
            'tags': tags}

    if admin_state:
        body['admin_state'] = nsx_constants.ADMIN_STATE_UP
    else:
        body['admin_state'] = nsx_constants.ADMIN_STATE_DOWN

    if vlan_id:
        body['vlan'] = vlan_id

    return client.create_resource(resource, body)
Example #12
0
def add_rule_in_section(rule, section_id):
    resource = 'firewall/sections/%s/rules' % section_id
    params = '?operation=insert_bottom'
    return nsxclient.create_resource(resource + params, rule)
Example #13
0
def add_rules_in_section(rules, section_id):
    resource = 'firewall/sections/%s/rules' % section_id
    params = '?action=create_multiple&operation=insert_bottom'
    return nsxclient.create_resource(resource + params, {'rules': rules})
Example #14
0
def add_rule_in_section(rule, section_id):
    resource = 'firewall/sections/%s/rules' % section_id
    params = '?operation=insert_bottom'
    return nsxclient.create_resource(resource + params, rule)
Example #15
0
def _update_nsgroup_with_members(nsgroup_id, members, action):
    members_update = 'ns-groups/%s?action=%s' % (nsgroup_id, action)
    return nsxclient.create_resource(members_update, members)
Example #16
0
def create_qos_switching_profile(tags, name=None,
                                 description=None):
    resource = 'switching-profiles'
    body = _build_qos_switching_profile_args(tags, name, description)
    return client.create_resource(resource, body)
Example #17
0
 def create_resource(self, resource, data):
     return nsx_client.create_resource(
         resource, data, client=self._client)
Example #18
0
def create_nsgroup(display_name, description, tags):
    body = {'display_name': display_name,
            'description': description,
            'tags': tags,
            'members': []}
    return nsxclient.create_resource('ns-groups', body)
Example #19
0
def add_rules_in_section(rules, section_id):
    resource = 'firewall/sections/%s/rules' % section_id
    params = '?action=create_multiple&operation=insert_bottom'
    return nsxclient.create_resource(resource + params, {'rules': rules})
Example #20
0
def _update_nsgroup_with_members(nsgroup_id, members, action):
    members_update = 'ns-groups/%s?action=%s' % (nsgroup_id, action)
    return nsxclient.create_resource(members_update, members)
 def create_resource(self, resource, data):
     return nsx_client.create_resource(
         resource, data, client=self._client)