|
2 | 2 | # :license: MIT, see LICENSE for more details. |
3 | 3 |
|
4 | 4 | import click |
| 5 | +import json |
5 | 6 |
|
6 | 7 | import SoftLayer |
7 | 8 | from SoftLayer.CLI import environment |
@@ -161,6 +162,39 @@ def _parse_create_args(client, args): |
161 | 162 | @click.option('--boot-mode', type=click.STRING, |
162 | 163 | help="Specify the mode to boot the OS in. Supported modes are HVM and PV.") |
163 | 164 | @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, |
164 | 198 | help="Billing rate") |
165 | 199 | @click.option('--dedicated/--public', is_flag=True, help="Create a Dedicated Virtual Server") |
166 | 200 | @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): |
203 | 237 | @click.option('--ipv6', is_flag=True, help="Adds an IPv6 address to this guest") |
204 | 238 | @click.option('--transient', is_flag=True, |
205 | 239 | 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) |
206 | 270 | @environment.pass_env |
207 | 271 | def cli(env, **args): |
208 | 272 | """Order/create virtual servers.""" |
@@ -239,7 +303,20 @@ def cli(env, **args): |
239 | 303 | if ready is False: |
240 | 304 | env.out(env.fmt(output)) |
241 | 305 | 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) |
243 | 320 |
|
244 | 321 | def _build_receipt_table(result, billing="hourly", test=False): |
245 | 322 | """Retrieve the total recurring fee of the items prices""" |
|
0 commit comments