コード例 #1
0
ファイル: cli.py プロジェクト: zhouziqunzzq/conoha-cli
 def list_keys(cls, token, args):
     keylist = KeyList(token)
     # Header
     if args.verbose:
         yield ['Name', 'PublicKey', 'FingerPrint']
     else:
         yield ['Name', 'FingerPrint']
     # Body
     for key in keylist:
         if args.verbose:
             yield [key.name, key.publicKey, key.fingerprint]
         else:
             yield [key.name, key.fingerprint]
コード例 #2
0
ファイル: cli.py プロジェクト: zhouziqunzzq/conoha-cli
 def delete_key(cls, token, args):
     keylist = KeyList(token)
     keylist.delete(args.name)
コード例 #3
0
ファイル: cli.py プロジェクト: zhouziqunzzq/conoha-cli
 def add_key(cls, token, args):
     keylist = KeyList(token)
     keylist.add(name=args.name,
                 publicKey=args.key,
                 publicKeyFile=args.file)
コード例 #4
0
ファイル: cli.py プロジェクト: yuuki0xff/conoha-cli
    def add_vm(cls, token, args):
        if args.wizard:
            # name
            default_name = args.name
            prompt = 'Name [L to list exists VM names]: '
            if default_name:
                prompt = 'Name [default: {},  L to list exists VM names]: '.format(
                    default_name)
            while True:
                args.name = input(prompt)
                if args.name == 'L':
                    main(['compute', 'list-vms'])
                    continue
                if args.name == '':
                    args.name = default_name or None
                break

            # image
            images = VMImageList(token)
            default_image = args.imageid or args.image
            if not default_image:
                default_image = images[0].name
                for img in images:
                    if '-docker-' in img.name and img.name.endswith('-amd64'):
                        # The img.name will be match this pattern.
                        # 'vmi-docker-xx.xx-ubuntu-xx.xx-amd64'
                        default_image = img.name
                        break
            while True:
                args.image = input(
                    'Base Image [default: {},  L to list images]: '.format(
                        default_image))
                if args.image == 'L':
                    main(['compute', 'list-images'])
                    continue
                if args.image == '':
                    args.image = default_image
                try:
                    args.imageid = images[args.image].imageId
                    break
                except KeyError:
                    print('ERROR: Invalid image name. See the image list.')
                    continue

            # plans
            plans = VMPlanList(token)
            default_plan = args.planid or args.plan or 'g-2gb'
            while True:
                args.plan = input(
                    'Plan [default: {},  L to list plans]: '.format(
                        default_plan))
                if args.plan == 'L':
                    main(['compute', 'list-plans'])
                    continue
                if args.plan == '':
                    args.plan = default_plan
                try:
                    args.planid = plans[args.plan].planId
                    break
                except KeyError:
                    print('ERROR: Invalid plan name. See the plan list.')
                    continue

            # password
            if not args.passwd:
                while True:
                    passwd1 = getpass.getpass('Password: '******'Confirm Password: '******'ERROR: Password does not match. Please re-enter the password again.'
                        )
            else:
                print('Password: ***** (masked)')

            # SSH Public Key
            keys = KeyList(token)
            default_key = args.key
            if not args.key:
                if len(keys):
                    default_key = keys[0].name
            if default_key:
                while True:
                    args.key = input(
                        'SSH Public Key [default: {},  L to list keys, None to unspecified the key]: '
                        .format(default_key))
                    if args.key == 'L':
                        main(['compute', 'list-keys'])
                        continue
                    if args.key == 'None':
                        args.key = None
                        break
                    if args.key == '':
                        args.key = default_key
                    try:
                        _ = keys[args.key]
                        break
                    except KeyError:
                        print('ERROR: invalid key name. See the key list')
                        continue
            else:
                # 公開鍵が登録されていない
                args.key = None

            # Security Groups
            default_groups = args.group_names or 'default, gncs-ipv4-all, gncs-ipv6-all'
            while True:
                args.group_names = input(
                    'Security Groups [default: {},  L to list groups]: '.
                    format(default_groups))
                if args.group_names == 'L':
                    main(['network', 'list-security-groups'])
                    continue
                if args.group_names == '':
                    args.group_names = default_groups
                break
        else:
            if not any([args.imageid, args.image]):
                raise error.InvalidArgumentError(
                    'one of the arguments --image or --imageid is required.')
            if not any([args.planid, args.plan]):
                raise error.InvalidArgumentError(
                    'one on the arguments --plan or --planid is required.')

        groupNames = None
        if args.group_names.strip():
            groupNames = [
                group.strip() for group in args.group_names.strip().split(',')
            ]

        vmlist = VMList(token)
        vmid = vmlist.add(args.imageid
                          or VMImageList(token)[args.image].imageId,
                          args.planid or VMPlanList(token)[args.plan].planId,
                          adminPass=args.passwd,
                          keyName=args.key,
                          name=args.name,
                          securityGroupNames=groupNames)
        if not args.quiet:
            yield ['VMID']
            yield [vmid]
コード例 #5
0
ファイル: cli.py プロジェクト: yuuki0xff/conoha-cli
	def delete_key(cls, token, args):
		keylist = KeyList(token)
		keylist.delete(args.name)
コード例 #6
0
ファイル: cli.py プロジェクト: yuuki0xff/conoha-cli
	def add_key(cls, token, args):
		keylist = KeyList(token)
		keylist.add(name=args.name, publicKey=args.key, publicKeyFile=args.file)