Commit ccdd1b82 authored by Stavros Sachtouris's avatar Stavros Sachtouris
Browse files

Create port_creates extention (cyclaes) and expose

Refs: #4563
parent 45cb7f88
......@@ -436,6 +436,24 @@ class port_set(_init_network, _optional_json):
self._run(port_id=port_id)
#@command(port_cmds)
#class port_create(_init_network, _optional_json):
#
@command(port_cmds)
class port_create(_init_network, _optional_json):
"""Create a new port"""
arguments = dict(
security_group_id=RepeatableArgument(
'Add a security group id (can be repeated)',
('-g', '--security-group'))
)
@errors.generic.all
@errors.cyclades.connection
@errors.cyclades.network_id
def _run(self, network_id, device_id):
r = self.client.create_port(
network_id, device_id, security_groups=self['security_group_id'])
self._print(r, self.print_dict)
def main(self, network_id, device_id):
super(self.__class__, self)._run()
self._run(network_id=network_id, device_id=device_id)
......@@ -525,3 +525,10 @@ class CycladesNetworkClient(NetworkClient):
req['network']['shared'] = bool(shared)
r = self.networks_post(json_data=req, success=201)
return r.json['network']
def create_port(self, network_id, device_id, security_groups=None):
port = dict(network_id=network_id, device_id=device_id)
if security_groups:
port['security_groups'] = security_groups
r = self.ports_post(json_data=dict(port=port), success=201)
return r.json['port']
......@@ -277,6 +277,22 @@ class CycladesNetworkClient(TestCase):
expargs = dict(json_data=dict(network=req), success=201)
self.assertEqual(networks_post.mock_calls[-1], call(**expargs))
@patch(
'kamaki.clients.network.rest_api.NetworkRestClient.ports_post',
return_value=FR)
def test_create_port(self, ports_post):
network_id, device_id, FR.json = 'netid', 'devid', dict(port='ret v')
for security_groups in ([1, 2, 3], None):
self.assertEqual(
self.client.create_port(
network_id, device_id, security_groups=security_groups),
'ret v')
req = dict(network_id=network_id, device_id=device_id)
if security_groups:
req['security_groups'] = security_groups
expargs = dict(json_data=dict(port=req), success=201)
self.assertEqual(ports_post.mock_calls[-1], call(**expargs))
class CycladesClient(TestCase):
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment