Skip to content

Commit d5c6b5c

Browse files
Irwen SongYingchao Huang
authored andcommitted
Enable the cli to create multiple vm instances in one request.
1 parent dec3516 commit d5c6b5c

1 file changed

Lines changed: 78 additions & 1 deletion

File tree

SoftLayer/CLI/virt/create.py

Lines changed: 78 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
# :license: MIT, see LICENSE for more details.
33

44
import click
5+
import json
56

67
import SoftLayer
78
from SoftLayer.CLI import environment
@@ -161,6 +162,39 @@ def _parse_create_args(client, args):
161162
@click.option('--boot-mode', type=click.STRING,
162163
help="Specify the mode to boot the OS in. Supported modes are HVM and PV.")
163164
@click.option('--billing', type=click.Choice(['hourly', 'monthly']), default='hourly', show_default=True,
165+
@click.command(epilog="See 'slcli vs create-options' for valid options")
166+
@click.option('--hostnames', '-H',
167+
help="Hosts portion of the FQDN",
168+
required=True,
169+
prompt=True)
170+
@click.option('--domain', '-D',
171+
help="Domain portion of the FQDN",
172+
required=True,
173+
prompt=True)
174+
@click.option('--cpu', '-c',
175+
help="Number of CPU cores (not available with flavors)",
176+
type=click.INT)
177+
@click.option('--memory', '-m',
178+
help="Memory in mebibytes (not available with flavors)",
179+
type=virt.MEM_TYPE)
180+
@click.option('--flavor', '-f',
181+
help="Public Virtual Server flavor key name",
182+
type=click.STRING)
183+
@click.option('--datacenter', '-d',
184+
help="Datacenter shortname",
185+
required=True,
186+
prompt=True)
187+
@click.option('--os', '-o',
188+
help="OS install code. Tip: you can specify <OS>_LATEST")
189+
@click.option('--image',
190+
help="Image ID. See: 'slcli image list' for reference")
191+
@click.option('--boot-mode',
192+
help="Specify the mode to boot the OS in. Supported modes are HVM and PV.",
193+
type=click.STRING)
194+
@click.option('--billing',
195+
type=click.Choice(['hourly', 'monthly']),
196+
default='hourly',
197+
show_default=True,
164198
help="Billing rate")
165199
@click.option('--dedicated/--public', is_flag=True, help="Create a Dedicated Virtual Server")
166200
@click.option('--host-id', type=click.INT, help="Host Id to provision a Dedicated Host Virtual Server onto")
@@ -203,6 +237,36 @@ def _parse_create_args(client, args):
203237
@click.option('--ipv6', is_flag=True, help="Adds an IPv6 address to this guest")
204238
@click.option('--transient', is_flag=True,
205239
help="Create a transient virtual server")
240+
@click.option('--userfile', '-F',
241+
help="Read userdata from file",
242+
type=click.Path(exists=True, readable=True, resolve_path=True))
243+
@click.option('--vlan-public',
244+
help="The ID of the public VLAN on which you want the virtual "
245+
"server placed",
246+
type=click.INT)
247+
@click.option('--vlan-private',
248+
help="The ID of the private VLAN on which you want the virtual "
249+
"server placed",
250+
type=click.INT)
251+
@click.option('--subnet-public',
252+
help="The ID of the public SUBNET on which you want the virtual server placed",
253+
type=click.INT)
254+
@click.option('--subnet-private',
255+
help="The ID of the private SUBNET on which you want the virtual server placed",
256+
type=click.INT)
257+
@helpers.multi_option('--public-security-group',
258+
'-S',
259+
help=('Security group ID to associate with '
260+
'the public interface'))
261+
@helpers.multi_option('--private-security-group',
262+
'-s',
263+
help=('Security group ID to associate with '
264+
'the private interface'))
265+
@click.option('--wait',
266+
type=click.INT,
267+
help="Wait until VS is finished provisioning for up to X "
268+
"seconds before returning")
269+
@click.option('--output-json', is_flag=True)
206270
@environment.pass_env
207271
def cli(env, **args):
208272
"""Order/create virtual servers."""
@@ -239,7 +303,20 @@ def cli(env, **args):
239303
if ready is False:
240304
env.out(env.fmt(output))
241305
raise exceptions.CLIHalt(code=1)
242-
306+
if args['output_json']:
307+
env.fout(json.dumps(result))
308+
else:
309+
for instance_data in result:
310+
table = formatting.KeyValueTable(['name', 'value'])
311+
table.align['name'] = 'r'
312+
table.align['value'] = 'l'
313+
table.add_row(['id', instance_data['id']])
314+
table.add_row(['hostname', instance_data['hostname']])
315+
table.add_row(['created', instance_data['createDate']])
316+
table.add_row(['uuid', instance_data['uuid']])
317+
output.append(table)
318+
319+
env.fout(output)
243320

244321
def _build_receipt_table(result, billing="hourly", test=False):
245322
"""Retrieve the total recurring fee of the items prices"""

0 commit comments

Comments
 (0)