示例#1
0
    def delete(self, args):
        """ Delete a virtual machine given its name. """
        # Parse user input to get the name of the virtual machine
        parser = OptionParser(usage="vm delete <options>")
        parser.add_option("-n", "--name", dest="name", help="The name of the virtual machine to delete")
        parser.add_option(
            "-u",
            "--undeploy",
            dest="undeploy",
            action="store_true",
            help="undeploy the virtual machine before deleting it",
        )
        (options, args) = parser.parse_args(args)
        name = options.name
        if not name:
            parser.print_help()
            return

        context = ContextLoader().load()
        try:
            cloud = context.getCloudService()
            vm = cloud.findVirtualMachine(VirtualMachinePredicates.name(name))
            if vm:
                state = vm.getState()
                if not options.undeploy and state.existsInHypervisor():
                    print ("Virtual machine is deployed. " "Undeploy it before deleting.")
                elif options.undeploy and state.existsInHypervisor():
                    vm = helper.undeploy_vm(context, vm)
                    vm.delete()
                else:
                    vm.delete()
            else:
                print "No virtual machine found with name: %s" % name
        except (AbiquoException, AuthorizationException), ex:
            print "Error: %s" % ex.getMessage()
示例#2
0
    def undeploy(self, args):
        """ Undeploy an existing virtual machine given its name """
        # Parse user input to get the name of the virtual machine
        parser = OptionParser(usage="vm undeploy <options>")
        parser.add_option("-n",
                          "--name",
                          dest="name",
                          help="The name of the virtual machine to undeploy")
        (options, args) = parser.parse_args(args)
        name = options.name
        if not name:
            parser.print_help()
            return

        # Once user input has been read, find the virtual machine
        try:
            cloud = self._context.getCloudService()
            vm = cloud.findVirtualMachine(
                VirtualMachinePredicates.internalName(name))
            if vm:
                vm = helper.undeploy_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()
示例#3
0
    def delete(self, args):
        """ Delete a virtual machine given its name """
        # Parse user input to get the name of the virtual machine
        parser = OptionParser(usage="vm delete <options>")
        parser.add_option("-n", "--name", dest="name",
                help="The name of the virtual machine to delete")
        parser.add_option("-u", "--undeploy", dest="undeploy",
                action="store_true",
                help="undeploy the virtual machine before deleting it")
        (options, args) = parser.parse_args(args)
        name = options.name
        if not name:
            parser.print_help()
            return

        try:
            cloud = self._context.getCloudService()
            vm = cloud.findVirtualMachine(
                    VirtualMachinePredicates.internalName(name))
            if vm:
                state = vm.getState()
                if not options.undeploy and state.existsInHypervisor():
                    print ("Virtual machine is deployed. "
                            "Undeploy it before deleting.")
                elif options.undeploy and state.existsInHypervisor():
                    vm = helper.undeploy_vm(self._context, vm)
                    vm.delete()
                else:
                    vm.delete()
            else:
                print "No virtual machine found with name: %s" % name
        except (AbiquoException, AuthorizationException), ex:
            print "Error: %s" % ex.getMessage()
示例#4
0
    def undeploy(self, args):
        """ Undeploy an existing virtual machine given its name. """
        # Parse user input to get the name of the virtual machine
        parser = OptionParser(usage="vm undeploy <options>")
        parser.add_option("-n", "--name", dest="name", help="The name of the virtual machine to undeploy")
        (options, args) = parser.parse_args(args)
        name = options.name
        if not name:
            parser.print_help()
            return

        # Once user input has been read, find the virtual machine
        context = ContextLoader().load()
        try:
            cloud = context.getCloudService()
            vm = cloud.findVirtualMachine(VirtualMachinePredicates.name(name))
            if vm:
                vm = helper.undeploy_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()