class TestMultipass: vm_name_prefix = "cloudmeshvm" #Note: multipass does not allow - or _ in vm name. def test_provider_init(self): HEADING() Benchmark.Start() self.provider = Provider() Benchmark.Stop() assert True Benchmark.Status(True) def test_provider_images(self): HEADING() self.provider = Provider() Benchmark.Start() result = self.provider.images() Benchmark.Stop() VERBOSE(result) result = str(result) assert "18.04" in result Benchmark.Status(True) def test_cms_images(self): HEADING() Benchmark.Start() result = Shell.execute("cms multipass images", shell=True) Benchmark.Stop() VERBOSE(result) result = str(result) assert "18.04" in result Benchmark.Status(True) def test_benchmark(self): HEADING() Benchmark.print(csv=True, tag=cloud)
def do_multipass(self, args, arguments): """ :: Usage: multipass deploy [--dryrun] multipass list [--output=OUTPUT] [--dryrun] multipass images [--output=OUTPUT] [--dryrun] multipass create NAMES [--image=IMAGE] [--size=SIZE] [--mem=MEMORY] [--cpus=CPUS] [--cloud-init=FILE] [--dryrun] multipass delete NAMES [--output=OUTPUT][--dryrun] multipass destroy NAMES [--output=OUTPUT][--dryrun] multipass shell NAMES [--dryrun] multipass run COMMAND NAMES [--output=OUTPUT] [--dryrun] multipass info NAMES [--output=OUTPUT] [--dryrun] multipass suspend NAMES [--output=OUTPUT] [--dryrun] multipass resume NAMES [--output=OUTPUT] [--dryrun] multipass start NAMES [--output=OUTPUT] [--dryrun] multipass stop NAMES [--output=OUTPUT] [--dryrun] multipass reboot NAMES [--output=OUTPUT] [--dryrun] multipass mount SOURCE DESTINATION [--dryrun] multipass umount SOURCE [--dryrun] multipass transfer SOURCE DESTINATION [--dryrun] multipass set key=VALUE [--dryrun] multipass get [key] [--dryrun] multipass deploy [--dryrun] multipass rename NAMES [--dryrun] multipass version Interface to multipass Options: --output=OUTPUT the output format [default: table]. Other values are yaml, csv and json. --image=IMAGE the image name to be used to create a VM. --cpus=CPUS Number of CPUs to allocate. Minimum: 1, default: 1. --size=SIZE Disk space to allocate. Positive integers, in bytes, or with K, M, G suffix. Minimum: 512M, default: 5G. --mem=MEMORY Amount of memory to allocate. Positive integers, in bytes, or with K, M, G suffix. Minimum: 128M, default: 1G. --cloud-init=FILE Path to a user-data cloud-init configuration Arguments: NAMES the names of the virtual machine Description: The NAMES can be a parameterized hostname such as red[0-1,5] = red0,red1,red5 Commands: First you can see the supported multipass images with cms multipass images Create and launch a new vm using cms multipass create NAMES Optionally you can provide image name, size, memory, number of cpus to create an instance. Start one or multiple multipass vms with cms multipass start NAMES Stop one or multiple vms with cms multipass stop NAMES Gets all multipass internal key values with cms multipass get Gets a specific internal key. cms multipass get KEY Known keys client.gui.autostart client.primary-name local.driver are there more? Reboot (stop and then start) vms with cms multipass reboot NAMES Delete one of multiple vms without purging with cms multipass delete NAMES Destory multipass vms (delete and purge) with cms multipass destroy NAMES Caution: Once destroyed everything in vm will be deleted and cannot be recovered. WHEN YOU IMPLEMENT A FUNCTION INCLUDE MINIMAL DOCUMENTATION HERE """ name = arguments.NAME map_parameters(arguments, "dryrun", "refresh", "cloud", "image", "size", "mem", "cpus", "cloud-init", "output") # so we can use arguments.cloudinit arguments["cloudinit"] = arguments["--cloud-init"] image = arguments.image variables = Variables() arguments.output = Parameter.find("output", arguments, variables, "table") names = Parameter.expand(arguments.NAMES) VERBOSE(arguments) if arguments.version: if arguments.dryrun: banner("dryrun list") else: provider = Provider() version = provider.version() del version["name"] print(Printer.attribute(version, header=["Program", "Version"])) return "" elif arguments.list: if arguments.dryrun: banner("dryrun list") else: provider = Provider() list = provider.list() print( provider.Print(list, kind='image', output=arguments.output)) return "" elif arguments.images: if arguments.dryrun: banner("dryrun images") else: provider = Provider() images = provider.images() print( provider.Print(images, kind='image', output=arguments.output)) return "" elif arguments.run: if arguments.dryrun: banner("dryrun run") for name in names: if arguments.dryrun: Console.ok(f"run {name} {arguments.COMMAND}") else: provider = Provider() provider.run(name, arguments.COMMAND) return "" elif arguments.create: result = "" if arguments.dryrun: banner("create") timeout = 360 group = None kwargs = { "cloud_init": arguments.cloud_init, "cpus": arguments.cpus, "memory": arguments.mem } for name in names: if arguments.dryrun: Console.ok(f"dryrun create {name} {image}") else: provider = Provider() result = provider.create(name, image, arguments.size, timeout, group, **kwargs) VERBOSE(result) return result elif arguments.start: result = "" if arguments.dryrun: banner("start") for name in names: if arguments.dryrun: Console.ok(f"dryrun start {name}") else: provider = Provider() result = provider.start(name) VERBOSE(result) return result elif arguments.stop: result = "" if arguments.dryrun: banner("stop") for name in names: if arguments.dryrun: Console.ok(f"dryrun stop {name}") else: provider = Provider(name=name) result = provider.stop(name) VERBOSE(result) return result elif arguments.delete: result = "" if arguments.dryrun: banner("delete") for name in names: if arguments.dryrun: Console.ok(f"dryrun delete {name}") else: provider = Provider() # Default purge is false. Is this ok? result = provider.delete(name) VERBOSE(result) return result elif arguments.info: result = "" if arguments.dryrun: banner(f"info {name}") for name in names: if arguments.dryrun: Console.ok(f"dryrun info {name}") else: provider = Provider() # Default purge is false. Is this ok? result = provider.info(name) VERBOSE(result) return result elif arguments.rename: result = "" if arguments.dryrun: banner(f"Current Name: {names[0]}" f"New Name: {names[1]}") if names.len() > 2: Console.error("You have entered too many names." "Only enter TWO names at a time.") else: old_name = names[0] new_name = names[1] provider = Provider() result = provider.rename(old_name, new_name) VERBOSE(result) return result elif arguments.suspend: result = "" if arguments.dryrun: banner("suspend") for name in names: if arguments.dryrun: Console.ok(f"dryrun suspend {name}") else: provider = Provider() result = provider.suspend(name) VERBOSE(result) return result elif arguments.resume: result = "" if arguments.dryrun: banner("resume") for name in names: if arguments.dryrun: Console.ok(f"dryrun resume {name}") else: provider = Provider() result = provider.resume(name) VERBOSE(result) return result elif arguments.destroy: result = "" if arguments.dryrun: banner("destroy") for name in names: if arguments.dryrun: Console.ok(f"dryrun destroy {name}") else: provider = Provider() result = provider.destroy(name) VERBOSE(result) return result elif arguments.reboot: result = "" if arguments.dryrun: banner("reboot") for name in names: if arguments.dryrun: Console.ok(f"dryrun reboot {name}") else: provider = Provider() result = provider.reboot(name) VERBOSE(result) return result elif arguments.shell: if len(names) > 1: Console.error("shell must only have one host") return "" name = names[0] if arguments.dryrun: banner("dryrun shell {name}") else: provider = Provider() provider.shell() return "" elif arguments.info: if arguments.dryrun: banner("dryrun info") else: provider = Provider() info = provider.info() print( provider.Print(info, kind='info', output=arguments.output)) return "" elif arguments.mount: if arguments.dryrun: banner( f"dryrun mount {arguments.SOURCE} {arguments.DESTINATION}") else: provider = Provider() provider.mount(arguments.SOURCE, arguments.DESTINATION) # list the mounts and display as table return "" elif arguments.deploy: provider = Deploy(dryrun=arguments.dryrun) provider.install() else: Console.error("Not yet implemented") return ""
class TestMultipass: vm_name_prefix = "cloudmeshvm" #Note: multipass does not allow - or _ in vm name. def test_cms_help(self): HEADING() Benchmark.Start() result = Shell.execute("cms help multipass", shell=True) Benchmark.Stop() VERBOSE(result) assert "quit" in result assert "clear" in result def test_cms_images(self): HEADING() Benchmark.Start() result = Shell.execute("cms multipass images", shell=True) Benchmark.Stop() VERBOSE(result) assert "18.04" in result def test_provider_init(self): HEADING() Benchmark.Start() self.provider = Provider() Benchmark.Stop() assert True def test_provider_images(self): HEADING() Benchmark.Start() result = self.provider.images() Benchmark.Stop() VERBOSE(result) assert "18.04" in result def test_provider_run_os(self): HEADING() Benchmark.Start() result = self.provider.run(command="uname -a", executor="os") Benchmark.Stop() VERBOSE(result) # find a good assertion assert "18.04" in result def test_provider_run_live(self): HEADING() Benchmark.Start() result = self.provider.run(command="uname -a", executor="live") Benchmark.Stop() VERBOSE(result) # find a good assertion assert "18.04" in result def test_provider_run_buffer(self): HEADING() Benchmark.Start() result = self.provider.run(command="uname -a", executor="buffer") Benchmark.Stop() VERBOSE(result) # find a good assertion assert "18.04" in result def test_cms_vm(self): HEADING() Benchmark.Start() result = Shell.execute("cms multipass vm", shell=True) Benchmark.Stop() VERBOSE(result) assert "18.04" in result def test_provider_vm(self): HEADING() Benchmark.Start() result = self.provider.vm() Benchmark.Stop() VERBOSE(result) assert "18.04" in result def test_cms_shell(self): HEADING() Benchmark.Start() Shell.execute(f"cms multipass launch --name={instance}", shell=True) result = Shell.execute(f"cms multipass shell {instance}", shell=True) Shell.execute(f"cms multipass delete {instance}", shell=True) Shell.execute(f"cms multipass purge", shell=True) Benchmark.Stop() VERBOSE(result) def test_provider_shell(self): HEADING() Benchmark.Start() Shell.execute(f"cms multipass launch --name={instance}", shell=True) result = self.provider.shell(name=instance) Shell.execute(f"cms multipass delete {instance}", shell=True) Shell.execute(f"cms multipass purge", shell=True) Benchmark.Stop() VERBOSE(result) def test_benchmark(self): HEADING() Benchmark.print(csv=True, tag=cloud) def test_info(self): HEADING() Benchmark.Start() result = Shell.execute("cms multipass info", shell=True) Benchmark.Stop() VERBOSE(result) assert result != None, "result cannot be null" def test_create(self): HEADING() vm_name = f"{self.vm_name_prefix}1" Benchmark.Start() result = Shell.execute(f"cms multipass create {vm_name}", shell=True) Benchmark.Stop() VERBOSE(result) assert f'Launched: {vm_name}' in result, "Error creating instance" def test_provider_create(self): HEADING() vm_name = f"{self.vm_name_prefix}2" provider = Provider(vm_name) Benchmark.Start() result = provider.create(vm_name) Benchmark.Stop() VERBOSE(result) assert 'Running' in result['status'], "Error creating instance" def test_create_with_options(self): HEADING() vm_name = f"{self.vm_name_prefix}3" Benchmark.Start() result = Shell.execute( f"cms multipass create {vm_name} --cpus=2 --size=3G --image=bionic --mem=1G", shell=True) Benchmark.Stop() VERBOSE(result) assert f'Launched: {vm_name}' in result, "Error creating instance" def test_stop(self): HEADING() #Using 2 VMs to test_created usingn test_create* methods. vm_names = f"{self.vm_name_prefix}1,{self.vm_name_prefix}3" Benchmark.Start() result = Shell.execute(f"cms multipass stop {vm_names}", shell=True) Benchmark.Stop() VERBOSE(result) assert 'Stopped' in result, "Error stopping instance" def test_provider_stop(self): HEADING() vm_name = f"{self.vm_name_prefix}2" provider = Provider(vm_name) Benchmark.Start() result = provider.stop(vm_name) Benchmark.Stop() VERBOSE(result) assert 'Stopped' in result['status'], "Error stopping instance" def test_start(self): HEADING() #Using 2 VMs to test_created usingn test_create* methods. vm_names = f"{self.vm_name_prefix}1,{self.vm_name_prefix}3" Benchmark.Start() result = Shell.execute(f"cms multipass start {vm_names}", shell=True) Benchmark.Stop() VERBOSE(result) assert 'Running' in result, "Error starting instance" def test_provider_start(self): HEADING() vm_name = f"{self.vm_name_prefix}2" provider = Provider(vm_name) Benchmark.Start() result = provider.start(vm_name) Benchmark.Stop() VERBOSE(result) assert 'Running' in result['status'], "Error starting instance" def test_reboot(self): HEADING() #Using 2 VMs to test_created usingn test_create* methods. vm_names = f"{self.vm_name_prefix}1,{self.vm_name_prefix}3" Benchmark.Start() result = Shell.execute(f"cms multipass reboot {vm_names}", shell=True) Benchmark.Stop() VERBOSE(result) assert 'Running' in result, "Error rebooting instance" def test_provider_reboot(self): HEADING() vm_name = f"{self.vm_name_prefix}2" provider = Provider(vm_name) Benchmark.Start() result = provider.reboot(vm_name) Benchmark.Stop() VERBOSE(result) assert 'Running' in result['status'], "Error rebooting instance" def test_delete(self): HEADING() #Using 2 VMs to test_created usingn test_create* methods. vm_names = f"{self.vm_name_prefix}1,{self.vm_name_prefix}3" Benchmark.Start() result = Shell.execute(f"cms multipass delete {vm_names}", shell=True) Benchmark.Stop() VERBOSE(result) assert 'deleted' in result, "Error deleting instance" def test_provider_delete(self): HEADING() vm_name = f"{self.vm_name_prefix}2" provider = Provider(vm_name) Benchmark.Start() result = provider.delete(vm_name) Benchmark.Stop() VERBOSE(result) assert 'deleted' in result['status'], "Error deleting instance" def test_destroy(self): HEADING() #Using 2 VMs to test_created usingn test_create* methods. vm_names = f"{self.vm_name_prefix}1,{self.vm_name_prefix}3" Benchmark.Start() result = Shell.execute(f"cms multipass destroy {vm_names}", shell=True) Benchmark.Stop() VERBOSE(result) assert 'destroyed' in result, "Error destroying instance" def test_provider_destroy(self): HEADING() vm_name = f"{self.vm_name_prefix}2" provider = Provider(vm_name) Benchmark.Start() result = provider.destroy(vm_name) Benchmark.Stop() VERBOSE(result) assert 'destroyed' in result['status'], "Error destroying instance"
class TestMultipass: def test_cms_help(self): HEADING() Benchmark.Start() result = Shell.execute("cms help multipass", shell=True) Benchmark.Stop() VERBOSE(result) assert "quit" in result assert "clear" in result def test_cms_images(self): HEADING() Benchmark.Start() result = Shell.execute("cms multipass images", shell=True) Benchmark.Stop() VERBOSE(result) assert "18.04" in result def test_provider_init(self): HEADING() Benchmark.Start() self.provider = Provider() Benchmark.Stop() assert True def test_provider_images(self): HEADING() Benchmark.Start() result = self.provider.images() Benchmark.Stop() VERBOSE(result) assert "18.04" in result def test_provider_run_os(self): HEADING() Benchmark.Start() result = self.provider.run(command="uname -a", executor="os") Benchmark.Stop() VERBOSE(result) # find a good assertion assert "18.04" in result def test_provider_run_live(self): HEADING() Benchmark.Start() result = self.provider.run(command="uname -a", executor="live") Benchmark.Stop() VERBOSE(result) # find a good assertion assert "18.04" in result def test_provider_run_buffer(self): HEADING() Benchmark.Start() result = self.provider.run(command="uname -a", executor="buffer") Benchmark.Stop() VERBOSE(result) # find a good assertion assert "18.04" in result def test_cms_vm(self): HEADING() Benchmark.Start() result = Shell.execute("cms multipass vm", shell=True) Benchmark.Stop() VERBOSE(result) assert "18.04" in result def test_provider_vm(self): HEADING() Benchmark.Start() result = self.provider.vm() Benchmark.Stop() VERBOSE(result) assert "18.04" in result def test_cms_shell(self): HEADING() Benchmark.Start() Shell.execute(f"cms multipass launch --name={instance}", shell=True) result = Shell.execute(f"cms multipass shell {instance}", shell=True) Shell.execute(f"cms multipass delete {instance}", shell=True) Shell.execute(f"cms multipass purge", shell=True) Benchmark.Stop() VERBOSE(result) def test_provider_shell(self): HEADING() Benchmark.Start() Shell.execute(f"cms multipass launch --name={instance}", shell=True) result = self.provider.shell(name=instance) Shell.execute(f"cms multipass delete {instance}", shell=True) Shell.execute(f"cms multipass purge", shell=True) Benchmark.Stop() VERBOSE(result) def test_benchmark(self): HEADING() Benchmark.print(csv=True, tag=cloud) def test_info(self): HEADING() Benchmark.Start() result = Shell.execute("cms multipass info", shell=True) Benchmark.Stop() VERBOSE(result) assert result != None, "result cannot be null"
def do_multipass(self, args, arguments): """ :: Usage: multipass list [--output=OUTPUT] [--dryrun] multipass images [--output=OUTPUT] [--dryrun] multipass start NAMES [--output=OUTPUT] [--dryrun] multipass stop NAMES [--output=OUTPUT] [--dryrun] multipass reboot NAMES [--output=OUTPUT] [--dryrun] multipass delete NAMES [--output=OUTPUT][--dryrun] multipass destroy NAMES [--output=OUTPUT][--dryrun] multipass shell NAMES [--dryrun] multipass run COMMAND NAMES [--output=OUTPUT] [--dryrun] multipass info NAMES [--output=OUTPUT] [--dryrun] multipass suspend NAMES [--output=OUTPUT] [--dryrun] multipass resume NAMES [--output=OUTPUT] [--dryrun] multipass destroy NAMES [--dryrun] multipass create NAMES [--image=IMAGE] [--size=SIZE] [--mem=MEMORY] [--cpus=CPUS] [--cloud-init=CLOUDINIT] [--dryrun] multipass reboot NAMES [--dryrun] multipass mount SOURCE DESTINATION [--dryrun] multipass umount SOURCE [--dryrun] multipass transfer SOURCE DESTINATION [--dryrun] multipass set key=VALUE [--dryrun] multipass get [key] [--dryrun] Interface to multipass Options: --output=OUTPUT the output format [default: table]. Other values are yaml, csv and json. --image=IMAGE the image name to be used to create a VM. Arguments: NAMES the names of the virtual machine Description: The NAMES can be a parameterized hostname such as red[0-1,5] = red0,red1,red5 Commands: First you can see the supported multipass images with cms multipass images Create and launch a new vm using cms multipass create NAMES Optionally you can provide image name, size, memory, # of cpus to create an instance. Start one or multiple multipass vms with cms multipass start NAMES Stop one or multiple vms with cms multipass stop NAMES Gets all multipass internal key values with cms multipass get Gets a specific internal key. cms multipass get KEY Known keys client.gui.autostart client.primary-name local.driver are there more? Reboot (stop and then start) vms with cms multipass reboot NAMES Delete one of multiple vms without purging with cms multipass delete NAMES Destory multipass vms (delete and purge) with cms multipass destroy NAMES Caution: Once destroyed everything in vm will be deleted and cannot be recovered. WHEN YOU IMPLEMENT A FUNCTION INCLUDE MINIMAL DOCUMENTATION HERE """ name = arguments.NAME map_parameters(arguments, "dryrun", "refresh", "cloud", "image", "size", "mem", "cpus", "output") # so we can use arguments.cloudinit arguments["cloudinit"] = arguments["--cloud-init"] image = arguments.image variables = Variables() arguments.output = Parameter.find("output", arguments, variables, "table") names = Parameter.expand(arguments.NAMES) VERBOSE(arguments) if arguments.list: if arguments.dryrun: banner("dryrun list") else: provider = Provider() provider.list() return "" elif arguments.images: if arguments.dryrun: banner("dryrun images") else: provider = Provider() images = provider.images() print( provider.Print(images, kind='image', output=arguments.output)) return "" elif arguments.run: if arguments.dryrun: banner("dryrun run") for name in names: if arguments.dryrun: Console.ok(f"run {name} {arguments.COMMAND}") else: provider = Provider() provider.run(name, arguments.COMMAND) return "" elif arguments.create: result = "" if arguments.dryrun: banner("create") for name in names: if arguments.dryrun: Console.ok(f"dryrun create {name} {image}") else: provider = Provider() result = provider.create(name, image) VERBOSE(result) return result elif arguments.start: result = "" if arguments.dryrun: banner("start") for name in names: if arguments.dryrun: Console.ok(f"dryrun start {name}") else: provider = Provider() result = provider.start(name) VERBOSE(result) return result elif arguments.stop: result = "" if arguments.dryrun: banner("stop") for name in names: if arguments.dryrun: Console.ok(f"dryrun stop {name}") else: provider = Provider(name=name) result = provider.stop(name) VERBOSE(result) return result elif arguments.delete: result = "" if arguments.dryrun: banner("delete") for name in names: if arguments.dryrun: Console.ok(f"dryrun delete {name}") else: provider = Provider() # Default purge is false. Is this ok? result = provider.delete(name) VERBOSE(result) return result elif arguments.info: result = "" if arguments.dryrun: banner(f"info {name}") for name in names: if arguments.dryrun: Console.ok(f"dryrun info {name}") else: provider = Provider() # Default purge is false. Is this ok? result = provider.info(name) VERBOSE(result) return result elif arguments.suspend: result = "" if arguments.dryrun: banner("suspend") for name in names: if arguments.dryrun: Console.ok(f"dryrun suspend {name}") else: provider = Provider() result = provider.suspend(name) VERBOSE(result) return result elif arguments.resume: result = "" if arguments.dryrun: banner("resume") for name in names: if arguments.dryrun: Console.ok(f"dryrun resume {name}") else: provider = Provider() result = provider.resume(name) VERBOSE(result) return result elif arguments.destroy: result = "" if arguments.dryrun: banner("destroy") for name in names: if arguments.dryrun: Console.ok(f"dryrun destroy {name}") else: provider = Provider() result = provider.destroy(name) VERBOSE(result) return result elif arguments.reboot: result = "" if arguments.dryrun: banner("reboot") for name in names: if arguments.dryrun: Console.ok(f"dryrun reboot {name}") else: provider = Provider() result = provider.reboot(name) VERBOSE(result) return result elif arguments.shell: if len(names) > 1: Console.error("shell must only have one host") return "" name = names[0] if arguments.dryrun: banner("dryrun shell {name}") else: provider = Provider() provider.shell() return "" elif arguments.info: if arguments.dryrun: banner("dryrun info") else: provider = Provider() info = provider.info() print( provider.Print(info, kind='info', output=arguments.output)) return "" elif arguments.mount: if arguments.dryrun: banner( f"dryrun mount {arguments.SOURCE} {arguments.DESTINATION}") else: provider = Provider() provider.mount(arguments.SOURCE, arguments.DESTINATION) # list the mounts and display as table return "" else: Console.error("Not yet implemented") return ""
def do_multipass(self, args, arguments): """ :: Usage: multipass list [--output=OUTPUT] [--dryrun] multipass images [--output=OUTPUT] [--dryrun] multipass start NAMES [--output=OUTPUT] [--dryrun] multipass stop NAMES [--output=OUTPUT] [--dryrun] multipass delete NAMES [--output=OUTPUT][--dryrun] multipass shell NAMES [--dryrun] multipass run COMMAND NAMES [--output=OUTPUT] [--dryrun] Interface to multipass Options: --output=OUTPUT the output format [default: table] Arguments: NAMES the names of the virtual machine Description: cms multipass start host[01-03] start multiple vms The NAMES can be a parameterized hostname """ name = arguments.NAME map_parameters(arguments, "dryrun", "refresh", "cloud", "output") variables = Variables() arguments.output = Parameter.find("output", arguments, variables, "table") names = Parameter.expand(arguments.NAMES) VERBOSE(arguments) if arguments.list: if arguments.dryrun: banner("dryrun list") else: provider = Provider() provider.list() return "" elif arguments.images: if arguments.dryrun: banner("dryrun images") else: provider = Provider() images = provider.images() print(provider.Print(images, kind='image', output=arguments.output)) return "" elif arguments.run: if arguments.dryrun: banner("dryrun run") for name in names: if arguments.dryrun: Console.ok(f"run {name} {arguments.COMMAND}") else: provider = Provider(name=name) provider.run(arguments.COMMAND) return "" elif arguments.start: if arguments.dryrun: banner("start") for name in names: if arguments.dryrun: Console.ok(f"dryrun start {name}") else: provider = Provider(name=name) provider.start() return "" elif arguments.stop: if arguments.dryrun: banner("stop") for name in names: if arguments.dryrun: Console.ok(f"dryrun stop {name}") else: provider = Provider(name=name) provider.stop() return "" elif arguments.delete: if arguments.dryrun: banner("delete") for name in names: if arguments.dryrun: Console.ok(f"dryrun delete {name}") else: provider = Provider(name=name) provider.delete() return "" elif arguments.shell: if len(names) > 1: Console.error("shell must only have one host") return "" name = names[0] if arguments.dryrun: banner("dryrun shell {name}") else: provider = Provider(name=name) provider.shell() return "" else: Console.error("Not yet implemented") return ""
def do_multipass(self, args, arguments): """ :: Usage: multipass list [--output=OUTPUT] [--dryrun] multipass images [--output=OUTPUT] [--dryrun] multipass start NAMES [--output=OUTPUT] [--dryrun] multipass stop NAMES [--output=OUTPUT] [--dryrun] multipass delete NAMES [--output=OUTPUT][--dryrun] multipass shell NAMES [--dryrun] multipass run COMMAND NAMES [--output=OUTPUT] [--dryrun] multipass info NAMES [--output=OUTPUT] [--dryrun] multipass suspend NAMES [--output=OUTPUT] [--dryrun] multipass resume NAMES [--output=OUTPUT] [--dryrun] multipass destroy NAMES [--dryrun] multipass create NAMES [--image=IMAGE] [--size=SIZE] [--mem=MEMORY] [--cpus=CPUS] [--cloud-init=CLOUDINIT] [--dryrun] multipass reboot NAMES [--dryrun] Interface to multipass Options: --output=OUTPUT the output format [default: table] Arguments: NAMES the names of the virtual machine Description: The NAMES can be a parameterized hostname such as red[0-1,5] = red0,red1,red5 cms multipass start vm1,vm2 start multiple vms WHEN YOU IMPLEMENT A FUNCTION INCLUDE MINIMAL DOCUMENTATION HERE """ name = arguments.NAME map_parameters(arguments, "dryrun", "refresh", "cloud", "image", "size", "mem", "cpus", "output") # so we can use arguments.cloudinit arguments["cloudinit"] = arguments["--cloud-init"] image = arguments.image variables = Variables() arguments.output = Parameter.find("output", arguments, variables, "table") names = Parameter.expand(arguments.NAMES) VERBOSE(arguments) if arguments.list: if arguments.dryrun: banner("dryrun list") else: provider = Provider() provider.list() return "" elif arguments.images: if arguments.dryrun: banner("dryrun images") else: provider = Provider() images = provider.images() print(provider.Print(images, kind='image', output=arguments.output)) return "" elif arguments.run: if arguments.dryrun: banner("dryrun run") for name in names: if arguments.dryrun: Console.ok(f"run {name} {arguments.COMMAND}") else: provider = Provider() provider.run(name, arguments.COMMAND) return "" elif arguments.create: result = "" if arguments.dryrun: banner("create") for name in names: if arguments.dryrun: Console.ok(f"dryrun create {name} {image}") else: provider = Provider() result = provider.create(name, image) VERBOSE(result) return result elif arguments.start: result = "" if arguments.dryrun: banner("start") for name in names: if arguments.dryrun: Console.ok(f"dryrun start {name}") else: provider = Provider() result = provider.start(name) VERBOSE(result) return result elif arguments.stop: result = "" if arguments.dryrun: banner("stop") for name in names: if arguments.dryrun: Console.ok(f"dryrun stop {name}") else: provider = Provider(name=name) result = provider.stop(name) VERBOSE(result) return result elif arguments.delete: result = "" if arguments.dryrun: banner("delete") for name in names: if arguments.dryrun: Console.ok(f"dryrun delete {name}") else: provider = Provider() # Default purge is false. Is this ok? result = provider.delete(name) VERBOSE(result) return result elif arguments.info: result = "" if arguments.dryrun: banner(f"info {name}") for name in names: if arguments.dryrun: Console.ok(f"dryrun info {name}") else: provider = Provider() # Default purge is false. Is this ok? result = provider.info(name) VERBOSE(result) return result elif arguments.suspend: result = "" if arguments.dryrun: banner("suspend") for name in names: if arguments.dryrun: Console.ok(f"dryrun suspend {name}") else: provider = Provider() result = provider.suspend(name) VERBOSE(result) return result elif arguments.resume: result = "" if arguments.dryrun: banner("resume") for name in names: if arguments.dryrun: Console.ok(f"dryrun resume {name}") else: provider = Provider() result = provider.resume(name) VERBOSE(result) return result elif arguments.destroy: result = "" if arguments.dryrun: banner("destroy") for name in names: if arguments.dryrun: Console.ok(f"dryrun destroy {name}") else: provider = Provider() result = provider.destroy(name) VERBOSE(result) return result elif arguments.reboot: result = "" if arguments.dryrun: banner("reboot") for name in names: if arguments.dryrun: Console.ok(f"dryrun reboot {name}") else: provider = Provider() result = provider.reboot(name) VERBOSE(result) return result elif arguments.shell: if len(names) > 1: Console.error("shell must only have one host") return "" name = names[0] if arguments.dryrun: banner("dryrun shell {name}") else: provider = Provider() provider.shell() return "" elif arguments.info: if arguments.dryrun: banner("dryrun info") else: provider = Provider() info = provider.info() print( provider.Print(info, kind='info', output=arguments.output)) return "" else: Console.error("Not yet implemented") return ""