def list_instances(self): insts = self.handle.servers.list() # Update instance list in self.id2inst self.id2inst.clear() instances = [] for inst in insts: if not self.pattern.match(inst.name): continue instance = Instance(inst, self.ssh_info) self.id2inst[instance.get_id()] = instance instances.append(instance) return instances
def __init__(self, name, conf, os_auth_info): BaseClient.__init__(self, name, conf, os_auth_info) self.handle = client.Client( os_auth_info["username"], os_auth_info["password"], os_auth_info["tenant_name"], os_auth_info["auth_url"], insecure=True, service_type="compute") # Maybe the client doesn't prefer ssh route self.ssh_info = conf.get("ssh", None) servers = [] try: servers.extend(self.handle.servers.list()) except NotFound: logging.warn("No servers present for client %s" % name) self.pattern = re.compile("^" + os_auth_info["username"] + "-[0-9]{3}") for inst in servers: if not self.pattern.match(inst.name): continue instance = Instance(inst, self.ssh_info) instanceId = instance.get_id() self.id2inst[instanceId] = instance vols = [] try: vols.extend(self.handle.volumes.get_server_volumes(instanceId)) except NotFound: logging.warn("No volume attached for instance %s(%s)" % (instance.get_name(), instance.get_id())) volumes = self.id2vols[instanceId] = [] for vol in vols: volumes.append(Volume(instance, vol))