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

Implement port wait

Refs: #4583
parent 6f2b87c1
......@@ -68,6 +68,22 @@ class _network_wait(_service_wait):
class _port_wait(_service_wait):
def _wait(self, port_id, current_status, timeout=60):
super(_port_wait, self)._wait(
'Port', port_id, self.client.wait_port, current_status,
class _port_wait(_service_wait):
def _wait(self, net_id, current_status, timeout=60):
super(_network_wait, self)._wait(
'Network', net_id, self.client.wait_network, current_status,
class _init_network(_command_init):
......@@ -472,7 +488,7 @@ class port_modify(_init_network, _optional_json):
class port_create(_init_network, _optional_json):
class port_create(_init_network, _optional_json, _port_wait):
"""Create a new port (== connect server to network)"""
arguments = dict(
......@@ -488,7 +504,8 @@ class port_create(_init_network, _optional_json):
network_id=ValueArgument('Set the network ID', '--network-id'),
'The device is either a virtual server or a virtual router',
wait=FlagArgument('Wait port to be established', ('-w', '--wait')),
required = ('network_id', 'device_id')
......@@ -504,6 +521,8 @@ class port_create(_init_network, _optional_json):
if self['wait']:
self._wait(r['id'], r['status'])
self._print(r, self.print_dict)
def main(self):
......@@ -511,6 +530,32 @@ class port_create(_init_network, _optional_json):
self._run(network_id=self['network_id'], device_id=self['device_id'])
class port_wait(_init_network, _port_wait):
"""Wait for port to finish [PENDING, ACTIVE, DELETED]"""
arguments = dict(
'Wait limit in seconds (default: 60)', '--timeout', default=60)
def _run(self, port_id, current_status):
port = self.client.get_port_details(port_id)
if port['status'].lower() == current_status.lower():
self._wait(port_id, current_status, timeout=self['timeout'])
'Port %s: Cannot wait for status %s, '
'status is already %s' % (
port_id, current_status, port['status']))
def main(self, port_id, current_status='PENDING'):
super(self.__class__, self)._run()
self._run(port_id=port_id, current_status=current_status)
class ip_list(_init_network, _optional_json):
"""List reserved floating IPs"""
......@@ -399,24 +399,21 @@ class CycladesNetworkClient(NetworkClient, Waiter):
def wait_network(
self, net_id,
current_status='PENDING', delay=1, max_wait=100, wait_cb=None):
"""Wait for network while its status is current_status
:param net_id: integer (str or int)
:param current_status: (str) PENDING | ACTIVE | DELETED
:param delay: time interval between retries
:max_wait: (int) timeout in secconds
def get_status(self, net_id):
r = self.get_network_details(net_id)
return r['status'], None
:param wait_cb: if set a progressbar is used to show progress
return self._wait(
net_id, current_status, get_status, delay, max_wait, wait_cb)
:returns: (str) the new mode if succesfull, (bool) False if timed out
def wait_port(
self, port_id,
current_status='PENDING', delay=1, max_wait=100, wait_cb=None):
def get_status(self, net_id):
r = self.get_network_details(net_id)
r = self.get_port_details(port_id)
return r['status'], None
return self._wait(
net_id, current_status, get_status, delay, max_wait, wait_cb)
port_id, current_status, get_status, delay, max_wait, wait_cb)
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