def deleteImage(cls, token, args): images = ImageList(token) vms = VMList(token) for name in args.images: vmid = vms.toVmid(name) if vmid is None: raise error.ImageNotFound(name) images.delete(name)
def add_vm(cls, token, args): groupNames = args.group_names and args.group_names.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]
def add_vm(cls, token, args): groupNames = args.group_names and args.group_names.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]
def list_vms(cls, token, args): vmlist = VMList(token) # Header if args.verbose: yield [ 'VMID', 'FlavorID', 'HostID', 'ImageID', 'TenantID', 'Name', 'Status', 'Created', 'Updated', 'AddressList', 'SecuretyGroupList' ] else: yield [ 'VMID', 'Name', 'Status', 'AddressList', 'SecuretyGroupList' ] # Body for vm in vmlist: if args.verbose: yield [ vm.vmid, vm.flavorId, vm.hostId, vm.imageId, vm.tenantId, vm.name, vm.status, vm.created, vm.updated, vm.addressList, vm.securityGroupList ] else: yield [ vm.vmid, vm.name, vm.status, vm.addressList, vm.securityGroupList ]
def _vmlist(cls, token, args) -> typing.Iterable[conoha.compute.VM]: vmlist = VMList(token) if args.names: for name in args.names: vm = vmlist.getServer(vmid=name, name=name) if vm is None: raise error.VMNotFound(name) yield vm elif args.id or args.name: vm = vmlist.getServer(vmid=args.id, name=args.name) if vm is None: raise error.VMNotFound(args.id or args.name) yield vm else: raise error.InvalidArgumentError( 'argument is not specified: must specify the --name, --id or NAME positional argument' )
def create_image(cls, token, args): vmlist = VMList(token) vm = vmlist.getServer(vmid=args.id, name=args.name) if vm: vm.createImage(args.image_name)
def delete_vm(cls, token, args): vmlist = VMList(token) for vm in cls._vmlist(token, args): vmlist.delete(vm.vmid)
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]
def modify_vm(cls, token, args): vmlist = VMList(token) vm = vmlist.getServer(vmid=args.id, name=args.name) if vm: vm.resize(args.planid)
def delete_vm(cls, token, args): vmlist = VMList(token) vm = vmlist.getServer(vmid=args.id, name=args.name) if vm: vmlist.delete(vm.vmid)
def reboot_vm(cls, token, args): vmlist = VMList(token) vm = vmlist.getServer(vmid=args.id, name=args.name) if vm: vm.restart()
def stop_vm(cls, token, args): vmlist = VMList(token) vm = vmlist.getServer(vmid=args.id, name=args.name) if vm: vm.stop(args.force)