def create(self, num, os_type, os_version, arch, resources_hint): """ Create num OpenStack instances running os_type os_version and return their names. Each instance has at least the resources described in resources_hint. """ log.debug('ProvisionOpenStack:create') resources_hint = self.interpret_hints({ 'machine': config['openstack']['machine'], 'volumes': config['openstack']['volumes'], }, resources_hint) self.init_user_data(os_type, os_version) image = self.image(os_type, os_version) if 'network' in config['openstack']: net = "--nic net-id=" + str(self.net_id(config['openstack']['network'])) else: net = '' flavor = self.flavor(resources_hint['machine'], config['openstack'].get('flavor-select-regexp')) misc.sh("flock --close /tmp/teuthology-server-create.lock openstack server create" + " " + config['openstack'].get('server-create', '') + " -f json " + " --image '" + str(image) + "'" + " --flavor '" + str(flavor) + "'" + " --key-name teuthology " + " --user-data " + str(self.user_data) + " " + net + " --min " + str(num) + " --max " + str(num) + " --security-group teuthology" + " --property teuthology=" + self.property + " --property ownedby=" + config.openstack['ip'] + " --wait " + " " + self.basename) instances = filter( lambda instance: self.property in instance['Properties'], self.list_instances()) instances = [OpenStackInstance(i['ID'], i) for i in instances] fqdns = [] try: network = config['openstack'].get('network', '') for instance in instances: name = self.ip2name(self.basename, instance.get_ip(network)) misc.sh("openstack server set " + "--name " + name + " " + instance['ID']) fqdn = name + '.' + config.lab_domain if not misc.ssh_keyscan_wait(fqdn): raise ValueError('ssh_keyscan_wait failed for ' + fqdn) time.sleep(15) if not self.cloud_init_wait(fqdn): raise ValueError('clound_init_wait failed for ' + fqdn) self.attach_volumes(name, resources_hint['volumes']) fqdns.append(fqdn) except Exception as e: log.exception(str(e)) for id in [instance['ID'] for instance in instances]: self.destroy(id) raise e return fqdns
def create(self, num, os_type, os_version, arch, resources_hint): """ Create num OpenStack instances running os_type os_version and return their names. Each instance has at least the resources described in resources_hint. """ log.debug('ProvisionOpenStack:create') resources_hint = self.interpret_hints( { 'machine': config['openstack']['machine'], 'volumes': config['openstack']['volumes'], }, resources_hint) self.init_user_data(os_type, os_version) image = self.image(os_type, os_version) if 'network' in config['openstack']: net = "--nic net-id=" + str( self.net_id(config['openstack']['network'])) else: net = '' flavor = self.flavor(resources_hint['machine'], config['openstack'].get('flavor-select-regexp')) misc.sh( "flock --close /tmp/teuthology-server-create.lock openstack server create" + " " + config['openstack'].get('server-create', '') + " -f json " + " --image '" + str(image) + "'" + " --flavor '" + str(flavor) + "'" + " --key-name teuthology " + " --user-data " + str(self.user_data) + " " + net + " --min " + str(num) + " --max " + str(num) + " --security-group teuthology" + " --property teuthology=" + self.property + " --property ownedby=" + config.openstack['ip'] + " --wait " + " " + self.basename) all_instances = json.loads( misc.sh("openstack server list -f json --long")) instances = filter( lambda instance: self.property in instance['Properties'], all_instances) fqdns = [] try: network = config['openstack'].get('network', '') for instance in instances: name = self.ip2name(self.basename, self.get_ip(instance['ID'], network)) misc.sh("openstack server set " + "--name " + name + " " + instance['ID']) fqdn = name + '.' + config.lab_domain if not misc.ssh_keyscan_wait(fqdn): raise ValueError('ssh_keyscan_wait failed for ' + fqdn) import time time.sleep(15) if not self.cloud_init_wait(fqdn): raise ValueError('clound_init_wait failed for ' + fqdn) self.attach_volumes(name, resources_hint['volumes']) fqdns.append(fqdn) except Exception as e: log.exception(str(e)) for id in [instance['ID'] for instance in instances]: self.destroy(id) raise e return fqdns
def create(self, num, os_type, os_version, arch, resources_hint): """ Create num OpenStack instances running os_type os_version and return their names. Each instance has at least the resources described in resources_hint. """ log.debug("ProvisionOpenStack:create") resources_hint = self.interpret_hints( {"machine": config["openstack"]["machine"], "volumes": config["openstack"]["volumes"]}, resources_hint ) self.init_user_data(os_type, os_version) image = self.image(os_type, os_version) if "network" in config["openstack"]: net = "--nic net-id=" + str(self.net_id(config["openstack"]["network"])) else: net = "" flavor = self.flavor(resources_hint["machine"], config["openstack"].get("flavor-select-regexp")) misc.sh( "flock --close /tmp/teuthology-server-create.lock openstack server create" + " " + config["openstack"].get("server-create", "") + " -f json " + " --image '" + str(image) + "'" + " --flavor '" + str(flavor) + "'" + " --key-name teuthology " + " --user-data " + str(self.user_data) + " " + net + " --min " + str(num) + " --max " + str(num) + " --security-group teuthology" + " --property teuthology=" + self.property + " --property ownedby=" + config.openstack["ip"] + " --wait " + " " + self.basename ) all_instances = json.loads(misc.sh("openstack server list -f json --long")) instances = filter(lambda instance: self.property in instance["Properties"], all_instances) fqdns = [] try: network = config["openstack"].get("network", "") for instance in instances: name = self.ip2name(self.basename, self.get_ip(instance["ID"], network)) misc.sh("openstack server set " + "--name " + name + " " + instance["ID"]) fqdn = name + "." + config.lab_domain if not misc.ssh_keyscan_wait(fqdn): raise ValueError("ssh_keyscan_wait failed for " + fqdn) import time time.sleep(15) if not self.cloud_init_wait(fqdn): raise ValueError("clound_init_wait failed for " + fqdn) self.attach_volumes(name, resources_hint["volumes"]) fqdns.append(fqdn) except Exception as e: log.exception(str(e)) for id in [instance["ID"] for instance in instances]: self.destroy(id) raise e return fqdns