Beispiel #1
0
    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()
Beispiel #2
0
    def start(self, args):
        """ Deploys and undeploys the first virtual appliance N times. """
        # Parse user input to get the number of deployments and undeployments
        parser = OptionParser(usage="deployer start <options>")
        parser.add_option("-n", "--num", dest="num",
                help="The number of deployments to execute")
        (options, args) = parser.parse_args(args)
        if not options.num:
            parser.print_help()
            return

        # Once user input has been read, find the VM
        max = int(options.num)
        context = ContextLoader().load()
        try:
            cloud = context.getCloudService()
            monitor = context.getMonitoringService() \
                    .getVirtualApplianceMonitor()

            vdc = cloud.listVirtualDatacenters()[0]
            vapp = vdc.listVirtualAppliances()[0]
            num_vms = len(vapp.listVirtualMachines())

            print "Starting %s deployment iterations for %s (%s vms)" % (max,
                    vapp.getName(), num_vms)

            for i in range(0, max):
                print "Iteration #%s" % (i + 1)
                print "  Deploying %s (%s vms)" % (vapp.getName(), num_vms)
                vapp.deploy()
                monitor.awaitCompletionDeploy(vapp)

                # Bypass current issues with state by waiting a bit
                # before undeploying
                time.sleep(5)

                print "  Undeploying %s (%s vms)" % (vapp.getName(), num_vms)
                vapp.undeploy()
                monitor.awaitCompletionUndeploy(vapp)

                # Currently there is a minor issue when undeploying that puts
                # the vm in state UNKNOWN. Wait a bit so it gets in
                # NOT_ALLOCATED state before deploying again
                time.sleep(5)
        except (AbiquoException, AuthorizationException), ex:
            print "Error: %s" % ex.getMessage()