Example #1
0
    def detach(self, args):
        """ Detach a volume from the given virtual machine """
        parser = OptionParser(usage="volume detach <options>")
        parser.add_option("-n", "--name", dest="name",
                help="The name of the volume to detach")
        (options, args) = parser.parse_args(args)
        if not options.name:
            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

            vm = helper.get_attached_vm(self._context, volume)
            if not vm:
                print ("Volume %s is not attached "
                        "to any virtual machine") % options.name
                return

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

            disks = [disk for disk in vm.listVirtualDisks()
                    if disk.getId() != volume.getId()]
            vm.setVirtualDisks(disks)

            pprint_volumes([helper.refresh_volume(self._context, volume)])
        except (AbiquoException, AuthorizationException), ex:
            print "Error: %s" % ex.getMessage()
Example #2
0
    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.internalName(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()
Example #3
0
    def detach(self, args):
        """ Detach a volume from the given virtual machine """
        parser = OptionParser(usage="volume detach <options>")
        parser.add_option("-n",
                          "--name",
                          dest="name",
                          help="The name of the volume to detach")
        (options, args) = parser.parse_args(args)
        if not options.name:
            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

            vm = helper.get_attached_vm(self._context, volume)
            if not vm:
                print("Volume %s is not attached "
                      "to any virtual machine") % options.name
                return

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

            vm.detachVolumes(volume)
            pprint_volumes([helper.refresh_volume(self._context, volume)])
        except (AbiquoException, AuthorizationException), ex:
            print "Error: %s" % ex.getMessage()
Example #4
0
    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.internalName(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..."

            disks = list(vm.listVirtualDisks())
            disks.append(volume)
            vm.setVirtualDisks(disks)

            pprint_volumes([helper.refresh_volume(self._context, volume)])
        except (AbiquoException, AuthorizationException), ex:
            print "Error: %s" % ex.getMessage()