def createInstance(self):
        try:
            if Environment.checkOrSet() == False:
                self.result = False
                logging.error("Failed to set environment credential")
            else:
                nr_available_vcpus = utils.get_nr_available_vcpus()

                if nr_available_vcpus < cvl_config.VM_CPU[self.cpu]:
                    message = "Required CPU " + cvl_config.VM_CPU[self.cpu] + " exceedes quota available CPU " + nr_available_vcpus
                    logging.error(message)
                    return False

                imageId = cvl_config.VM_IMAGE_ID[int(self.driver)]
                show = "nova boot " + "--flavor " + str(self.cpu) + " --image " + imageId + " --key_name " + cvl_config.VM_KEY_NAME + " --security_groups " + cvl_config.VM_SECURITY_GROUP + " \"" + self.serverName + "\""
                command = MultiOutputCommand(show)
                if command.run() == False:
                    self.result = False
                    logging.error("Failed to run command")
                else:
                    output = command.getOutput()
                    logging.debug('Output of nova boot command: ' + output)

                    for data in output:
                        dataList = data.split(":")
                        if dataList.__len__() > 0:
                            if dataList[0].strip() == "ERROR":
                                logging.error("Failed to launch an instance")
                                self.result = False
        except:
            self.result = False
            logging.error("Exception: " + traceback.format_exc())
        finally:
            logging.debug('Returning:', self.result)
            return self.result
import sys, traceback
import logging
import utils
import cvl_config

if len(sys.argv) < 2:
    logging.error("Missing argument: number of requested CPUs")
    sys.exit(1)

numberCpu = sys.argv[1]
try:
    if Environment.checkOrSet() == False:
        logging.error("Failed to set environment credential")
        sys.exit(1)
    else:
        availableCpu = utils.get_nr_available_vcpus()
        logging.debug("numberCpu index: " + str(numberCpu) + " number cpu: " + str(cvl_config.VM_CPU[int(numberCpu)]) + " available CPU: " + str(availableCpu));
        if availableCpu <= cvl_config.QUOTA_THRESHOLD:

            utils.send_email(cvl_config.CVL_HELP_EMAIL,
                             "CVL project resource warning",
                             "Warning: there are only " + str(availableCpu) + " CPUs available in the %s tenancy." % (utils.nova_client().project_id,))

        if availableCpu < cvl_config.VM_CPU[int(numberCpu)]:
            message = "Resources for " + str(cvl_config.VM_CPU[int(numberCpu)]) + " CPUs are not available"
            print message
            logging.error(message)
        print "OK"
except:
    logging.error("Exception:" + traceback.format_exc())
    sys.exit(1)