Revision c6fe2f41
b/snf-cyclades-app/synnefo/api/management/commands/server-create.py | ||
---|---|---|
69 | 69 |
" available flavors."), |
70 | 70 |
make_option("--password", dest="password", |
71 | 71 |
help="Password for the new server"), |
72 |
make_option("--networks", dest="network_ids",
|
|
73 |
help="Comma separated list of network IDs to connect"),
|
|
74 |
make_option("--ports", dest="port_ids",
|
|
75 |
help="Comma separated list of port IDs to connect"),
|
|
72 |
make_option("--port", dest="connections", action="append",
|
|
73 |
help="--port network:<network_id>(,address=<ip_address>),"
|
|
74 |
" --port id:<port_id>"
|
|
75 |
" --port floatingip:<floatingip_id>."),
|
|
76 | 76 |
make_option("--floating-ips", dest="floating_ip_ids", |
77 | 77 |
help="Comma separated list of port IDs to connect"), |
78 | 78 |
make_option( |
... | ... | |
115 | 115 |
else: |
116 | 116 |
backend = None |
117 | 117 |
|
118 |
network_ids = parse_list(options["network_ids"]) |
|
119 |
port_ids = parse_list(options["port_ids"]) |
|
120 |
floating_ip_ids = parse_list(options["floating_ip_ids"]) |
|
121 |
floating_ips = \ |
|
122 |
map(lambda x: common.get_floating_ip_by_id(x, for_update=True), |
|
123 |
floating_ip_ids) |
|
124 |
|
|
125 |
floating_ips = map(lambda fp: {"uuid": fp.network_id, |
|
126 |
"fixed_ip": fp.address}, |
|
127 |
floating_ips) |
|
128 |
networks = map(lambda x: {"uuid": x}, network_ids) |
|
129 |
ports = map(lambda x: {"port": x}, port_ids) |
|
130 |
|
|
118 |
connection_list = parse_connections(options["connections"]) |
|
131 | 119 |
server = servers.create(user_id, name, password, flavor, image, |
132 |
networks=(floating_ips+ports+networks),
|
|
120 |
networks=connection_list,
|
|
133 | 121 |
use_backend=backend) |
134 | 122 |
pprint.pprint_server(server, stdout=self.stdout) |
135 | 123 |
|
... | ... | |
137 | 125 |
common.wait_server_task(server, wait, self.stdout) |
138 | 126 |
|
139 | 127 |
|
140 |
def parse_list(_list): |
|
141 |
if _list is None: |
|
142 |
return [] |
|
143 |
else: |
|
144 |
return _list.split(",") |
|
128 |
def parse_connections(con_list): |
|
129 |
connections = [] |
|
130 |
if con_list: |
|
131 |
for opt in con_list: |
|
132 |
try: |
|
133 |
con_kind = opt.split(":")[0] |
|
134 |
if con_kind == "network": |
|
135 |
info = opt.split(",") |
|
136 |
network_id = info[0].split(":")[1] |
|
137 |
try: |
|
138 |
address = info[1].split(":")[1] |
|
139 |
except: |
|
140 |
address = None |
|
141 |
if address: |
|
142 |
val = {"uuid": network_id, "fixed_ip": address} |
|
143 |
else: |
|
144 |
val = {"uuid": network_id} |
|
145 |
elif con_kind == "id": |
|
146 |
port_id = opt.split(":")[1] |
|
147 |
val = {"port": port_id} |
|
148 |
elif con_kind == "floatingip": |
|
149 |
fip_id = opt.split(":")[1] |
|
150 |
fip = common.get_floating_ip_by_id(fip_id, for_update=True) |
|
151 |
val = {"uuid": fip.network_id, "fixed_ip": fip.address} |
|
152 |
else: |
|
153 |
raise CommandError("Unknown argument for option --port") |
|
154 |
|
|
155 |
connections.append(val) |
|
156 |
except: |
|
157 |
raise CommandError("Malformed information for option --port") |
|
158 |
return connections |
Also available in: Unified diff