Skip to content

Commit

Permalink
🐛 IF-7068 fix existing api (#91)
Browse files Browse the repository at this point in the history
Co-authored-by: yamazaki.tomoka <tomoka.yamazaki@w.ntt.com>
  • Loading branch information
yamazaki-x and yamazaki.tomoka authored Feb 10, 2022
1 parent b8ca37e commit 9e70943
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 19 deletions.
6 changes: 5 additions & 1 deletion ecl/network/v2/_proxy.py
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ def get_extension(self, extension):
def create_port(self, admin_state_up=None, allowed_address_pairs=None,
mac_address=None, description=None, device_id=None,
device_owner=None, fixed_ips=None, name=None,
network_id=None, segmentation_id=None,
network_id=None, security_groups=None, segmentation_id=None,
segmentation_type=None, tags=None):
"""Create a new port from attributes
Expand All @@ -203,6 +203,7 @@ def create_port(self, admin_state_up=None, allowed_address_pairs=None,
e.g. [{"ip_address":<ipv4> , "subnet_id": <uuid> }, ]
:param string name: The name of port to create
:param string network_id: The network id of port to create
:param array security_groups: The security groups ids of port to create
:param int segmentation_id: The segmentation id of port to create
:param string segmentation_type: The segmentation type of port to create
:param dict tags: tags of port
Expand All @@ -229,6 +230,8 @@ def create_port(self, admin_state_up=None, allowed_address_pairs=None,
body["name"] = name
if network_id:
body["network_id"] = network_id
if security_groups:
body["security_groups"] = security_groups
if segmentation_id:
body["segmentation_id"] = segmentation_id
if segmentation_type:
Expand Down Expand Up @@ -305,6 +308,7 @@ def update_port(self, port, **params):
* array fixed_ips: The fixed ips of port to update
e.g. [{"ip_address":<ipv4> , "subnet_id": <uuid> }, ]
* string name: The name of port to update
* array security_groups: The security groups ids of port to update
* int segmentation_id: The segmentation id of port to update
* string segmentation_type: The segmentation type of port to update
* dict tags: tags of port
Expand Down
3 changes: 3 additions & 0 deletions ecl/network/v2/port.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,9 @@ class Port(base.NetworkBaseResource):
#: users can specify a project ID other than their own.
project_id = resource2.Body('tenant_id')

#: The IDs of security groups applied to the port.
security_groups = resource2.Body('security_groups')

#: The segmentation ID of ports.
segmentation_id = resource2.Body('segmentation_id', type=int)

Expand Down
2 changes: 2 additions & 0 deletions ecl/network/v2/quota.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ class Quota(resource2.Resource):
vpn_gateway = resource2.Body('vpn_gateway', type=int)
#: The maximum amount of public ip you can create. *Type: int*
public_ip = resource2.Body('public_ip', type=int)
#: The maximum amount of security group you can create. *Type: int*
security_group = resource2.Body('security_group', type=int)


class QuotaDefault(Quota):
Expand Down
12 changes: 8 additions & 4 deletions ecl/tests/unit/network/v2/test_port.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

import testtools

from ecl.network.v2 import port
from ecl.network.v2.port import Port

IDENTIFIER = 'IDENTIFIER'
EXAMPLE = {
Expand All @@ -30,6 +30,9 @@
"mac_address": "test-mac",
"name": "Example port 1",
"network_id": IDENTIFIER,
"security_groups": [
IDENTIFIER
],
"segmentation_id": 0,
"segmentation_type": "flat",
"tags": {
Expand All @@ -44,10 +47,10 @@
class TestPort(testtools.TestCase):

def test_basic(self):
sot = port.Port()
sot = Port()
self.assertEqual('port', sot.resource_key)
self.assertEqual('ports', sot.resources_key)
self.assertEqual('/ports', sot.base_path)
self.assertEqual('/v2.0/ports', sot.base_path)
self.assertEqual('network', sot.service.service_type)
self.assertTrue(sot.allow_create)
self.assertTrue(sot.allow_get)
Expand All @@ -56,7 +59,7 @@ def test_basic(self):
self.assertTrue(sot.allow_list)

def test_make_it(self):
sot = port.Port(**EXAMPLE)
sot = Port(**EXAMPLE)
self.assertTrue(sot.admin_state_up)
self.assertEqual('UP', sot.admin_state)
self.assertEqual(EXAMPLE['allowed_address_pairs'],
Expand All @@ -68,6 +71,7 @@ def test_make_it(self):
self.assertEqual(EXAMPLE['mac_address'], sot.mac_address)
self.assertEqual(EXAMPLE['name'], sot.name)
self.assertEqual(EXAMPLE['network_id'], sot.network_id)
self.assertEqual(EXAMPLE['security_groups'], sot.security_groups)
self.assertEqual(EXAMPLE['segmentation_id'], sot.segmentation_id)
self.assertEqual(EXAMPLE['segmentation_type'], sot.segmentation_type)
self.assertEqual(EXAMPLE['tags'], sot.tags)
Expand Down
30 changes: 16 additions & 14 deletions ecl/tests/unit/network/v2/test_quota.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

import testtools

from ecl.network.v2 import quota
from ecl.network.v2.quota import Quota, QuotaDefault

IDENTIFIER = 'IDENTIFIER'
EXAMPLE = {
Expand All @@ -27,18 +27,18 @@
"port": 30,
"subnet": 5,
"tenant_id": IDENTIFIER,
"vpn_gateway": 1
"vpn_gateway": 1,
"security_group": 1
}



class TestQuota(testtools.TestCase):

def test_basic(self):
sot = quota.Quota()
sot = Quota()
self.assertEqual('quota', sot.resource_key)
self.assertEqual('quotas', sot.resources_key)
self.assertEqual('/quotas', sot.base_path)
self.assertEqual('/v2.0/quotas', sot.base_path)
self.assertEqual('network', sot.service.service_type)
self.assertFalse(sot.allow_create)
self.assertTrue(sot.allow_get)
Expand All @@ -47,24 +47,25 @@ def test_basic(self):
self.assertTrue(sot.allow_list)

def test_make_it(self):
sot = quota.Quota(**EXAMPLE)
sot = Quota(**EXAMPLE)
self.assertEqual(EXAMPLE['colocation_logical_link'], sot.colocation_logical_link)
self.assertEqual(EXAMPLE['common_function_gateway'], sot.common_function_gateway)
self.assertEqual(EXAMPLE['firewall'], sot.firewall)
self.assertEqual(EXAMPLE['id'], sot.id)
self.assertEqual(EXAMPLE['interdc_gateway'], sot.interdc_gateway)
self.assertEqual(EXAMPLE['interdc_gateway'], sot.internet_gateway)
self.assertEqual(EXAMPLE['load_balancer'], sot.load_balancer)
self.assertEqual(EXAMPLE['network'], sot.networks)
self.assertEqual(EXAMPLE['port'], sot.ports)
self.assertEqual(EXAMPLE['subnet'], sot.subnets)
self.assertEqual(EXAMPLE['network'], sot.network)
self.assertEqual(EXAMPLE['port'], sot.port)
self.assertEqual(EXAMPLE['subnet'], sot.subnet)
self.assertEqual(EXAMPLE['tenant_id'], sot.project_id)
self.assertEqual(EXAMPLE['vpn_gateway'], sot.vpn_gateway)
self.assertEqual(EXAMPLE['security_group'], sot.security_group)

class TestQuotaDefault(testtools.TestCase):

def test_basic(self):
default = quota.QuotaDefault()
default = QuotaDefault()
self.assertEqual('quota', default.resource_key)
self.assertEqual('quotas', default.resources_key)
self.assertEqual('/quotas/%(project)s/default', default.base_path)
Expand All @@ -76,16 +77,17 @@ def test_basic(self):
self.assertFalse(default.allow_list)

def test_make_it(self):
default = quota.QuotaDefault(**EXAMPLE)
default = QuotaDefault(**EXAMPLE)
self.assertEqual(EXAMPLE['colocation_logical_link'], default.colocation_logical_link)
self.assertEqual(EXAMPLE['common_function_gateway'], default.common_function_gateway)
self.assertEqual(EXAMPLE['firewall'], default.firewall)
self.assertEqual(EXAMPLE['id'], default.id)
self.assertEqual(EXAMPLE['interdc_gateway'], default.interdc_gateway)
self.assertEqual(EXAMPLE['interdc_gateway'], default.internet_gateway)
self.assertEqual(EXAMPLE['load_balancer'], default.load_balancer)
self.assertEqual(EXAMPLE['network'], default.networks)
self.assertEqual(EXAMPLE['port'], default.ports)
self.assertEqual(EXAMPLE['subnet'], default.subnets)
self.assertEqual(EXAMPLE['network'], default.network)
self.assertEqual(EXAMPLE['port'], default.port)
self.assertEqual(EXAMPLE['subnet'], default.subnet)
self.assertEqual(EXAMPLE['tenant_id'], default.project_id)
self.assertEqual(EXAMPLE['vpn_gateway'], default.vpn_gateway)
self.assertEqual(EXAMPLE['security_group'], default.security_group)

0 comments on commit 9e70943

Please sign in to comment.