2019-11-11 18:49:35 +00:00
|
|
|
import click
|
2019-07-17 14:58:39 +00:00
|
|
|
|
2019-12-31 14:54:08 +00:00
|
|
|
from uncloud_cli.commands.helper import add_otp_options, make_request, add_vm_options
|
2019-07-17 14:58:39 +00:00
|
|
|
|
|
|
|
|
|
|
|
@click.group()
|
|
|
|
def vm():
|
|
|
|
pass
|
|
|
|
|
|
|
|
|
2019-12-31 14:54:08 +00:00
|
|
|
@vm.command('create')
|
|
|
|
@add_otp_options
|
|
|
|
@add_vm_options
|
|
|
|
@click.option('--cpu', required=True, type=int)
|
|
|
|
@click.option('--ram', required=True)
|
|
|
|
@click.option('--os-ssd', required=True)
|
|
|
|
@click.option('--hdd', default=list(), multiple=True)
|
|
|
|
@click.option('--image', required=True)
|
|
|
|
@click.option('--network', default=list(), multiple=True)
|
|
|
|
def create(**kwargs):
|
|
|
|
kwargs['specs'] = {
|
|
|
|
'cpu': kwargs.pop('cpu'),
|
|
|
|
'ram': kwargs.pop('ram'),
|
|
|
|
'os-ssd': kwargs.pop('os_ssd'),
|
|
|
|
'hdd': kwargs.pop('hdd')
|
2019-11-11 18:49:35 +00:00
|
|
|
}
|
2019-12-31 14:54:08 +00:00
|
|
|
make_request('vm', kwargs.pop('action'), data=kwargs)
|
2019-07-17 14:58:39 +00:00
|
|
|
|
|
|
|
|
2019-12-31 14:54:08 +00:00
|
|
|
@vm.command('start')
|
|
|
|
@add_otp_options
|
|
|
|
@add_vm_options
|
|
|
|
def start(**kwargs):
|
|
|
|
make_request('vm', 'action', data=kwargs)
|
2019-09-01 17:09:08 +00:00
|
|
|
|
|
|
|
|
2019-12-31 14:54:08 +00:00
|
|
|
@vm.command('stop')
|
|
|
|
@add_otp_options
|
|
|
|
@add_vm_options
|
|
|
|
def stop(**kwargs):
|
|
|
|
make_request('vm', 'action', data=kwargs)
|
2019-07-17 14:58:39 +00:00
|
|
|
|
|
|
|
|
2019-12-31 14:54:08 +00:00
|
|
|
@vm.command('delete')
|
|
|
|
@add_otp_options
|
|
|
|
@add_vm_options
|
|
|
|
def delete(**kwargs):
|
|
|
|
make_request('vm', 'action', data=kwargs)
|
2019-09-04 13:21:28 +00:00
|
|
|
|
|
|
|
|
2019-12-31 14:54:08 +00:00
|
|
|
@vm.command('status')
|
|
|
|
@add_otp_options
|
|
|
|
@click.option('--vm-name', required=True)
|
|
|
|
def status(**kwargs):
|
|
|
|
make_request('vm', 'status', data=kwargs)
|
2019-08-12 12:56:19 +00:00
|
|
|
|
2019-11-11 18:49:35 +00:00
|
|
|
|
2019-12-31 15:18:14 +00:00
|
|
|
@vm.command('migrate')
|
2019-12-31 14:54:08 +00:00
|
|
|
@add_otp_options
|
2019-12-31 15:18:14 +00:00
|
|
|
@click.option('--vm-name', required=True)
|
|
|
|
@click.option('--destination', required=True)
|
2019-12-31 14:54:08 +00:00
|
|
|
def vm_migration(**kwargs):
|
|
|
|
make_request('vm', 'migrate', data=kwargs)
|