Ejemplo n.º 1
0
    def _construct_ec2_params(self, lab_spec):
        """
        Returns a tuple of AWS VM parameters - the AMI id and the instance type
        based on the runtime parameters in the lab_spec
        """

        # get the availabe instance types from the config
        available_instance_types = config.available_instance_types

        # get the vm specs from the lab spec
        vm_spec = self._get_vm_spec(lab_spec)

        # derive hostname from the slug given in labspec
        if 'slug' in lab_spec['lab']['description']:
            slug = lab_spec['lab']['description']['slug']
            hostname = "%s.%s" % (slug, base_config.HOST_NAME)
        else:
            if vm_spec["lab_ID"] == "":
                lab_ID = base_adapter.get_test_lab_id()
            else:
                lab_ID = vm_spec["lab_ID"]
            hostname = "%s.%s" % (lab_ID, base_adapter.get_adapter_hostname())

        logger.debug("AWSAdapter: hostname of the lab: %s" % hostname)

        # pass OS and OS version and get a relavant AMI id for the corresponding
        # image
        ami_id = base_adapter.find_os_template(vm_spec["os"],
                                               vm_spec["os_version"],
                                               config.supported_amis)

        # use someone's super intelligent method to get RAM in megs- in a string
        # with 'M' appended at the end!! </sarcasm>
        (ram, swap) = vm_utils.get_ram_swap(vm_spec["ram"], vm_spec["swap"])

        # convert stupid RAM string in 'M' to an integer
        # no idea why would one deal with RAM values in strings!!
        ram = int(ram[:-1])
        if ram <= 1024:
            instance_type = available_instance_types[0]['instance_type']
        else:
            instance_type = available_instance_types[1]['instance_type']

        return (ami_id, instance_type)
Ejemplo n.º 2
0
    def _construct_ec2_params(self, lab_spec):
        """
        Returns a tuple of AWS VM parameters - the AMI id and the instance type
        based on the runtime parameters in the lab_spec
        """

        # get the availabe instance types from the config
        available_instance_types = config.available_instance_types

        # get the vm specs from the lab spec
        vm_spec = self._get_vm_spec(lab_spec)

        # derive hostname from the slug given in labspec
        if 'slug' in lab_spec['lab']['description']:
            slug = lab_spec['lab']['description']['slug']
            hostname = "%s.%s" % (slug, base_config.HOST_NAME)
        else:
            if vm_spec["lab_ID"] == "":
                lab_ID = base_adapter.get_test_lab_id()
            else:
                lab_ID = vm_spec["lab_ID"]
            hostname = "%s.%s" % (lab_ID, base_adapter.get_adapter_hostname())

        logger.debug("AWSAdapter: hostname of the lab: %s" % hostname)

        # pass OS and OS version and get a relavant AMI id for the corresponding
        # image
        ami_id = base_adapter.find_os_template(vm_spec["os"],
                                               vm_spec["os_version"],
                                               config.supported_amis)

        # use someone's super intelligent method to get RAM in megs- in a string
        # with 'M' appended at the end!! </sarcasm>
        (ram, swap) = vm_utils.get_ram_swap(vm_spec["ram"], vm_spec["swap"])

        # convert stupid RAM string in 'M' to an integer
        # no idea why would one deal with RAM values in strings!!
        ram = int(ram[:-1])
        if ram <= 1024:
            instance_type = available_instance_types[0]['instance_type']
        else:
            instance_type = available_instance_types[1]['instance_type']

        return (ami_id, instance_type)
Ejemplo n.º 3
0
    def construct_vzctl_args(self, lab_specz={}):
        """ Returns a tuple of vzctl create arguments and set arguments """

        def get_vm_spec():
            lab_spec = dict2default(lab_specz)
            vm_spec = {
                "lab_ID": lab_spec['lab']['description']['id'],
                "os": lab_spec['lab']['runtime_requirements']['platform']['os'],
                "os_version": lab_spec['lab']['runtime_requirements']
                ['platform']['osVersion'],
                "ram": lab_spec['lab']['runtime_requirements']['platform']
                ['memory']['min_required'],
                "diskspace": lab_spec['lab']['runtime_requirements']
                ['platform']['storage']['min_required'],
                "swap": lab_spec['lab']['runtime_requirements']['platform']
                ['memory']['swap']
            }
            return vm_spec

        vm_spec = get_vm_spec()
        lab_ID = None
        if vm_spec["lab_ID"] == "":
            lab_ID = base_adapter.get_test_lab_id()
        else:
            lab_ID = vm_spec["lab_ID"]
        host_name = lab_ID + "." + base_adapter.get_adapter_hostname()
        ip_address = base_adapter.find_available_ip()
        os_template = base_adapter.find_os_template(vm_spec["os"],
                                                    vm_spec["os_version"],
                                                    config.supported_template)
        (ram, swap) = vm_utils.get_ram_swap(vm_spec["ram"], vm_spec["swap"])
        (disk_soft, disk_hard) = vm_utils.get_disk_space(vm_spec["diskspace"])
        vm_create_args = " --ostemplate " + os_template + \
                         " --ipadd " + ip_address + \
                         " --diskspace " + disk_soft + ":" + disk_hard + \
                         " --hostname " + host_name
        # Note to self: check ram format "0:256M" vs "256M"
        vm_set_args = " --nameserver " + base_config.ADAPTER_NAME_SERVER + \
                      " --ram " + ram + \
                      " --swap " + swap + \
                      " --onboot yes" + \
                      " --save"
        return (vm_create_args, vm_set_args)