コード例 #1
0
ファイル: vm.py プロジェクト: fmontserrat/kahuna
    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", help="The name of the virtual machine to deploy",
                action="store", dest="name")
        (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_context()
        try:
            cloud = context.getCloudService()
            monitor = context.getMonitoringService().getVirtualMachineMonitor()
            vm = cloud.findVirtualMachine(VirtualMachinePredicates.name(name))
            if vm:
                print "Deploying virtual machine %s... This may take some time." % name
                vm.deploy()
                monitor.awaitCompletionDeploy(vm)
            else:
                print "No virtual machine found with name: %s" % name
        except (AbiquoException, AuthorizationException), ex:
            print "Error: %s" % ex.getMessage()
コード例 #2
0
ファイル: vm.py プロジェクト: Marc-Morata-Fite/kahuna
    def find(self, args):
        """ Find a virtual machine given its name. """
        # Parse user input to get the name of the virtual machine
        parser = OptionParser(usage="vm find <options>")
        parser.add_option("-n", "--name", dest="name", help="The name of the virtual machine to find")
        parser.add_option(
            "-v", "--verbose", dest="verbose", action="store_true", help="Show virtual machine extended information"
        )
        (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:
                pprint_vms([vm], options.verbose)
            else:
                print "No virtual machine found with name: %s" % name
        except (AbiquoException, AuthorizationException), ex:
            print "Error: %s" % ex.getMessage()
コード例 #3
0
ファイル: vm.py プロジェクト: Marc-Morata-Fite/kahuna
    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()
コード例 #4
0
ファイル: volume.py プロジェクト: abelboldu/kahuna
    def attach(self, args):
        """ Attach a volume to the given virtual machine """
        parser = OptionParser(usage="volume attach <options>")
        parser.add_option("-n", "--name", dest="name", help="The name of the volume to attach")
        parser.add_option(
            "-v", "--vm", dest="vm", help=("The name of the virtual machine " "where the volume will be attached")
        )
        (options, args) = parser.parse_args(args)
        if not options.name or not options.vm:
            parser.print_help()
            return

        try:
            volume = helper.find_volume(self._context, options.name)
            if not volume:
                print "No volume found with name: %s" % options.name
                return
            cloud = self._context.getCloudService()
            vm = cloud.findVirtualMachine(VirtualMachinePredicates.name(options.vm))
            if not vm:
                print "No virtual machine found with name: %s" % options.vm
                return

            log.debug("Attaching volume %s to %s..." % (options.name, options.vm))
            if vm.getState().existsInHypervisor():
                print "Attaching volume to a running virtual machine.",
                print "This may take some time..."

            vm.attachVolumes(volume)
            pprint_volumes([helper.refresh_volume(self._context, volume)])
        except (AbiquoException, AuthorizationException), ex:
            print "Error: %s" % ex.getMessage()
コード例 #5
0
ファイル: helper.py プロジェクト: abelboldu/kahuna
def get_attached_vm(context, volume):
    """ Get the virtual machine where the volume is attached """
    # TODO: Add parent navigation in jclouds.abiquo
    link = volume.unwrap().searchLink("virtualmachine")
    if link:
        name = link.getTitle()
        cloud = context.getCloudService()
        return cloud.findVirtualMachine(VirtualMachinePredicates.name(name))
コード例 #6
0
ファイル: vm.py プロジェクト: abelboldu/kahuna
    def __change_state(self, state_name, new_state, args):
        """ Generic method to change the state of a virtual machine """
        parser = OptionParser(usage="vm %s <options>" % state_name)
        parser.add_option("-n", "--name", dest="name",
                help="The name of the virtual machine to %s" % state_name)
        (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.name(name))
            if vm:
                helper.change_state_vm(self._context, vm, new_state)
                pprint_vms([vm])
            else:
                print "No virtual machine found with name: %s" % name
        except (AbiquoException, AuthorizationException), ex:
            print "Error: %s" % ex.getMessage()
コード例 #7
0
ファイル: vm.py プロジェクト: Marc-Morata-Fite/kahuna
    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()
コード例 #8
0
ファイル: vm.py プロジェクト: fmontserrat/kahuna
    def find(self, args):
        """ Find a virtual machine given its name. """
        # Parse user input to get the name of the virtual machine
        parser = OptionParser(usage="vm find <options>")
        parser.add_option("-n", "--name", help="The name of the virtual machine to find",
                action="store", dest="name")
        parser.add_option("-v", "--verbose", help="Show virtual machine extended information",
                action="store_true", dest="verbose")
        (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_context()
        try:
            cloud = context.getCloudService()
            vm = cloud.findVirtualMachine(VirtualMachinePredicates.name(name))
            if vm:
                pprint_vms([vm])
                if options.verbose:
                    print "Found virtual machine in: "
                    print "  %s" % vm.getVirtualAppliance()
                    print "  %s" % vm.getVirtualDatacenter()
                    print "  %s" % vm.getEnterprise()
                    if vm.getState().existsInHypervisor():
                        admin = context.getAdministrationService()
                        machine = admin.findMachine(MachinePredicates.ip(vm.getVncAddress()))
                        print "  %s" % machine
                    else:
                        print "  Machine [None (VM not deployed)]"
            else:
                print "No virtual machine found with name: %s" % name
        except (AbiquoException, AuthorizationException), ex:
            print "Error: %s" % ex.getMessage()