Commit a3bc4db2 authored by Christos Stavrakakis's avatar Christos Stavrakakis
Browse files

cyclades: Add --volume option to server-create cmd

Extend 'server-create' management command with the '--volume' option,
which can be used to specify which volumes to use or create for the new
server.
parent a183991f
......@@ -75,6 +75,11 @@ class Command(SynnefoCommand):
help="--port network:<network_id>(,address=<ip_address>),"
" --port id:<port_id>"
" --port floatingip:<floatingip_id>."),
make_option("--volume", dest="volumes", action="append",
help="--volume size=<size>, --volume id=<volume_id"
", --volume size=<size>,image=<image_id>"
", --volume size=<size>,snapshot=<snapshot_id>",
default=[]),
make_option("--floating-ips", dest="floating_ip_ids",
help="Comma separated list of port IDs to connect"),
make_option(
......@@ -118,8 +123,10 @@ class Command(SynnefoCommand):
backend = None
connection_list = parse_connections(options["connections"])
volumes_list = parse_volumes(options["volumes"])
server = servers.create(user_id, name, password, flavor, image["id"],
networks=connection_list,
volumes=volumes_list,
use_backend=backend)
pprint.pprint_server(server, stdout=self.stdout)
......@@ -127,6 +134,46 @@ class Command(SynnefoCommand):
common.wait_server_task(server, wait, self.stdout)
def parse_volumes(vol_list):
volumes = []
for vol in vol_list:
vol_dict = {}
kv_list = vol.split(",")
for kv_item in kv_list:
try:
k, v = kv_item.split("=")
except (TypeError, ValueError):
raise CommandError("Invalid syntax for volume: %s" % vol)
vol_dict[k] = v
size = vol_dict.get("size")
if size is not None:
try:
size = int(size)
except (TypeError, ValueError):
raise CommandError("Invalid size: %s" % size)
if len(vol_dict) == 1:
if size is not None:
volumes.append({"size": size, "source_type": "blank",
"source_uuid": None})
continue
vol_id = vol_dict.get("id")
if vol_id is not None:
volumes.append({"source_uuid": vol_id,
"source_type": "volume"})
continue
raise CommandError("Invalid syntax for volume %s" % vol)
image = vol_dict.get("image")
snapshot = vol_dict.get("snapshot")
if image and snapshot or not(image or snapshot) or size is None:
raise CommandError("Invalid syntax for volume %s" % vol)
source = image if image else snapshot
source_type = "image" if image else "snapshot"
volumes.append({"source_uuid": source,
"source_type": source_type,
"size": size})
return volumes
def parse_connections(con_list):
connections = []
if con_list:
......
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