Commit 1796361e authored by Stavros Sachtouris's avatar Stavros Sachtouris
Browse files

Reverse server create --no-network/None http req

From now on, --no-network produces a "networks=[]" part,
while the absense of network-related arguments makes produces a
request without "networks" attributes.
parent 2a1e7072
......@@ -442,8 +442,8 @@ class server_create(_init_cyclades, _optional_json, _server_wait):
'Do not create any network NICs on the server. . '
'Mutually exclusive to --network . '
'If neither --network or --no-network are used, the default '
'network policy is applied. This policy is configured on the '
'cloud and kamaki is oblivious to it',
'network policy is applied. These policies are set on the cloud, '
'so kamaki is oblivious to them',
'--no-network')
)
required = ('server_name', 'flavor_id', 'image_id')
......@@ -451,7 +451,7 @@ class server_create(_init_cyclades, _optional_json, _server_wait):
@errors.cyclades.cluster_size
def _create_cluster(self, prefix, flavor_id, image_id, size):
networks = self['network_configuration'] or (
None if self['no_network'] else [])
[] if self['no_network'] else None)
servers = [dict(
name='%s%s' % (prefix, i if size > 1 else ''),
flavor_id=flavor_id,
......
......@@ -670,29 +670,29 @@ class ip_attach(_port_create):
@errors.generic.all
@errors.cyclades.connection
@errors.cyclades.server_id
def _run(self, ip_address, server_id):
def _run(self, ip_or_ip_id, server_id):
netid = None
for ip in self.client.list_floatingips():
if ip['floating_ip_address'] == ip_address:
if ip_or_ip_id in (ip['floating_ip_address'], ip['id']):
netid = ip['floating_network_id']
iparg = ValueArgument(parsed_name='--ip')
iparg.value = ip_address
iparg.value = ip['floating_ip_address']
self.arguments['ip_address'] = iparg
break
if netid:
self.error('Creating a port to attach IP %s to server %s' % (
ip_address, server_id))
ip_or_ip_id, server_id))
self.connect(netid, server_id)
else:
raiseCLIError(
'IP address %s does not match any reserved IPs' % ip_address,
'%s does not match any reserved IPs or IP ids' % ip_or_ip_id,
details=[
'To reserve an IP:', ' [kamaki] ip create',
'To see all reserved IPs:', ' [kamaki] ip list'])
def main(self, ip_address):
def main(self, ip_or_ip_id):
super(self.__class__, self)._run()
self._run(ip_address=ip_address, server_id=self['server_id'])
self._run(ip_or_ip_id=ip_or_ip_id, server_id=self['server_id'])
@command(ip_cmds)
......@@ -705,11 +705,11 @@ class ip_detach(_init_network, _port_wait, _optional_json):
@errors.generic.all
@errors.cyclades.connection
def _run(self, ip_address):
def _run(self, ip_or_ip_id):
for ip in self.client.list_floatingips():
if ip['floating_ip_address'] == ip_address:
if ip_or_ip_id in (ip['floating_ip_address'], ip['id']):
if not ip['port_id']:
raiseCLIError('IP %s is not attached' % ip_address)
raiseCLIError('IP %s is not attached' % ip_or_ip_id)
self.error('Deleting port %s:' % ip['port_id'])
self.client.delete_port(ip['port_id'])
if self['wait']:
......@@ -722,11 +722,11 @@ class ip_detach(_init_network, _port_wait, _optional_json):
raise
self.error('Port %s is deleted' % ip['port_id'])
return
raiseCLIError('IP %s not found' % ip_address)
raiseCLIError('IP or IP id %s not found' % ip_or_ip_id)
def main(self, ip_address):
def main(self, ip_or_ip_id):
super(self.__class__, self)._run()
self._run(ip_address)
self._run(ip_or_ip_id)
# Warn users for some importand changes
......
......@@ -133,8 +133,7 @@ class ComputeClient(ComputeRestClient):
{"uuid": <network_uuid>},
{"uuid": <network_uuid>, "fixed_ip": address},
{"port": <port_id>}, ...]
ATTENTION: Empty list is different to None. None means ' do not
mention it', empty list means 'automatically get an ip'
ATTENTION: Empty list is different to None.
:returns: a dict with the new virtual server details
......@@ -150,7 +149,7 @@ class ComputeClient(ComputeRestClient):
req['server']['personality'] = personality
if networks is not None:
req['server']['networks'] = networks or []
req['server']['networks'] = networks
r = self.servers_post(
json_data=req,
......
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