def deploy(self, args): """ Deploy an existing virtual machine given its name """ # Parse user input to get the name of the virtual machine parser = OptionParser(usage="vm deploy <options>") parser.add_option("-n", "--name", dest="name", help="The name of the virtual machine to deploy") (options, args) = parser.parse_args(args) name = options.name if not name: parser.print_help() return # Once user input has been read, find the VM try: cloud = self._context.getCloudService() vm = cloud.findVirtualMachine( VirtualMachinePredicates.internalName(name)) if vm: vm = helper.deploy_vm(self._context, vm) pprint_vms([vm]) else: print "No virtual machine found with name: %s" % name except (AbiquoException, AuthorizationException), ex: print "Error: %s" % ex.getMessage()
def create(self, args): """ Creates a virtual machine based on a given template """ # Parse user input to get the name of the virtual machine parser = OptionParser(usage="vm create <options>") parser.add_option("-t", "--template-id", dest="template", type="int", help="The id of the template to use") parser.add_option("-c", "--cpu", dest="cpu", type="int", help="The number of cores") parser.add_option("-r", "--ram", dest="ram", type="int", help="The RAM in MB") parser.add_option("-d", "--deploy", dest="deploy", action="store_true", help="Deploy the virtual machine after creating it") (options, args) = parser.parse_args(args) if not options.template: parser.print_help() return try: api_context = self._context.getApiContext() template = helper.find_template_by_id(self._context, options.template) if not template: print "No template was found with id %s" % options.template return log.debug("Using template: %s" % template.getName()) vdc = helper.get_virtual_datacenter_for_template(self._context, template) if not vdc: print ("Could not create a compatible virtual datacenter " "for %s") % template.getName() return log.debug("Using virtual datacenter: %s" % vdc.getName()) name = "Kahuna-" + api_context.getIdentity() vapp = vdc.findVirtualAppliance( VirtualAppliancePredicates.name(name)) if not vapp: log.debug(("Virtual appliance %s not found. " "Creating it...") % name) vapp = VirtualAppliance.builder(api_context, vdc) \ .name(name) \ .build() vapp.save() builder = VirtualMachine.builder(api_context, vapp, template) if options.cpu: builder.cpu(options.cpu) if options.ram: builder.ram(options.ram) vm = builder.build() vm.save() if options.deploy: vm = helper.deploy_vm(self._context, vm) pprint_vms([vm]) except (AbiquoException, AuthorizationException), ex: print "Error: %s" % ex.getMessage()
def deploy(self, args): """ Deploy an existing virtual machine given its name. """ # Parse user input to get the name of the virtual machine parser = OptionParser(usage="vm deploy <options>") parser.add_option("-n", "--name", dest="name", help="The name of the virtual machine to deploy") (options, args) = parser.parse_args(args) name = options.name if not name: parser.print_help() return # Once user input has been read, find the VM context = ContextLoader().load() try: cloud = context.getCloudService() vm = cloud.findVirtualMachine(VirtualMachinePredicates.name(name)) if vm: vm = helper.deploy_vm(context, vm) pprint_vms([vm]) else: print "No virtual machine found with name: %s" % name except (AbiquoException, AuthorizationException), ex: print "Error: %s" % ex.getMessage()
def create(self, args): """ Creates a virtual machine based on a given template """ # Parse user input to get the name of the virtual machine parser = OptionParser(usage="vm create <options>") parser.add_option("-t", "--template-id", dest="template", type="int", help="The id of the template to use") parser.add_option("-c", "--cpu", dest="cpu", type="int", help="The number of cores") parser.add_option("-r", "--ram", dest="ram", type="int", help="The RAM in MB") parser.add_option("-d", "--deploy", dest="deploy", action="store_true", help="Deploy the virtual machine after creating it") (options, args) = parser.parse_args(args) if not options.template: parser.print_help() return try: api_context = self._context.getApiContext() template = helper.find_template_by_id(self._context, options.template) if not template: print "No template was found with id %s" % options.template return log.debug("Using template: %s" % template.getName()) vdc = helper.get_virtual_datacenter_for_template( self._context, template) if not vdc: print( "Could not create a compatible virtual datacenter " "for %s") % template.getName() return log.debug("Using virtual datacenter: %s" % vdc.getName()) name = "Kahuna-" + api_context.getIdentity() vapp = vdc.findVirtualAppliance( VirtualAppliancePredicates.name(name)) if not vapp: log.debug(("Virtual appliance %s not found. " "Creating it...") % name) vapp = VirtualAppliance.builder(api_context, vdc) \ .name(name) \ .build() vapp.save() builder = VirtualMachine.builder(api_context, vapp, template) if options.cpu: builder.cpu(options.cpu) if options.ram: builder.ram(options.ram) vm = builder.build() vm.save() if options.deploy: vm = helper.deploy_vm(self._context, vm) pprint_vms([vm]) except (AbiquoException, AuthorizationException), ex: print "Error: %s" % ex.getMessage()