def create_host(self, infra, offering, name, team_name, zone=None, database_name=''): url = "{}/{}/{}/host/new".format( self.credential.endpoint, self.provider, self.environment ) data = { "engine": self.engine, "name": name, "cpu": offering.cpus, "memory": offering.memory_size_mb, "group": infra.name, "team_name": team_name, "database_name": database_name } if zone: data['zone'] = zone response = self._request(post, url, json=data, timeout=600) if response.status_code != 201: raise HostProviderCreateVMException(response.content, response) content = response.json() host = Host() host.address = content["address"] host.hostname = host.address host.user = self.vm_credential.user host.password = self.vm_credential.password host.provider = self.provider host.identifier = content["id"] host.offering = offering host.save() return host
def create_host(self, infra, offering, name): url = "{}/{}/{}/host/new".format(self.credential.endpoint, self.provider, self.environment) data = { "engine": self.engine, "name": name, "cpu": offering.cpus, "memory": offering.memory_size_mb, "group": infra.name } response = post(url, json=data) if response.status_code != 201: raise IndexError(response.content, response) content = response.json() host = Host() host.address = content["address"] host.hostname = host.address host.user = self.vm_credential.user host.password = self.vm_credential.password host.provider = self.provider host.identifier = content["id"] host.offering = offering host.save() return host
def do(self): host = Host() host.address = self.instance.vm_name host.hostname = self.instance.vm_name host.user = '******' host.password = '******' host.provider = 'k8s' host.save() self.instance.hostname = host self.instance.save()
def create_host(self, infra, offering, name, team_name, zone=None, database_name='', host_obj=None, port=None, volume_name=None, init_user=None, init_password=None, static_ip=None): url = "{}/{}/{}/host/new".format(self.credential.endpoint, self.provider, self.environment) data = { "engine": self.engine, "name": name, "cpu": offering.cpus, "memory": offering.memory_size_mb, "group": infra.name, "team_name": team_name, "database_name": database_name, "static_ip_id": static_ip and static_ip.identifier } if zone: data['zone'] = zone if port: data['port'] = port if volume_name: data['volume_name'] = volume_name if init_user: data['init_user'] = init_user if init_password: data['init_password'] = init_password response = self._request(post, url, json=data, timeout=600) if response.status_code != 201: raise HostProviderCreateVMException(response.content, response) content = response.json() if host_obj is None: host = Host() host.hostname = content["address"] else: host = host_obj host.address = content["address"] host.user = self.vm_credential.user host.password = self.vm_credential.password host.private_key = self.vm_credential.private_key host.provider = self.provider host.identifier = content["id"] host.offering = offering host.save() return host