forked from uncloud/uncloud
uncloud cli converted to argparse, code isn't beautiful yet. Would make it soom
This commit is contained in:
parent
cd2f0aaa0d
commit
50fb135726
14 changed files with 278 additions and 264 deletions
45
uncloud/cli/host.py
Normal file
45
uncloud/cli/host.py
Normal file
|
|
@ -0,0 +1,45 @@
|
|||
import requests
|
||||
|
||||
from uncloud.cli.helper import make_request, get_otp_parser
|
||||
from uncloud.common.parser import BaseParser
|
||||
|
||||
|
||||
class HostParser(BaseParser):
|
||||
def __init__(self):
|
||||
super().__init__('host')
|
||||
|
||||
def create(self, **kwargs):
|
||||
p = self.subparser.add_parser('create', parents=[get_otp_parser()], **kwargs)
|
||||
p.add_argument('--hostname', required=True)
|
||||
p.add_argument('--cpu', required=True, type=int)
|
||||
p.add_argument('--ram', required=True)
|
||||
p.add_argument('--os-ssd', required=True)
|
||||
p.add_argument('--hdd', default=list())
|
||||
|
||||
def list(self, **kwargs):
|
||||
self.subparser.add_parser('list', **kwargs)
|
||||
|
||||
|
||||
parser = HostParser()
|
||||
arg_parser = parser.arg_parser
|
||||
|
||||
|
||||
def main(**kwargs):
|
||||
subcommand = kwargs.pop('host_subcommand')
|
||||
if not subcommand:
|
||||
arg_parser.print_help()
|
||||
else:
|
||||
request_method = requests.post
|
||||
data = None
|
||||
if subcommand == 'create':
|
||||
kwargs['specs'] = {
|
||||
'cpu': kwargs.pop('cpu'),
|
||||
'ram': kwargs.pop('ram'),
|
||||
'os-ssd': kwargs.pop('os_ssd'),
|
||||
'hdd': kwargs.pop('hdd')
|
||||
}
|
||||
data = kwargs
|
||||
elif subcommand == 'list':
|
||||
request_method = requests.get
|
||||
|
||||
make_request('host', subcommand, data=data, request_method=request_method)
|
||||
Loading…
Add table
Add a link
Reference in a new issue