def on_put(self, req, resp, tenant_id, host_id): host = find_host(self.db, host_id, when_not_found=_host_not_found) body = load_body(req) profile_id = body['profile_id'] profile = find_host_profile(self.db, id=profile_id, when_not_found=_profile_not_found) host.profile = profile self.db.commit() resp.status = falcon.HTTP_200
def on_get(self, req, resp, tenant_id, host_id): #verify the tenant exists tenant = find_tenant(self.db, tenant_id=tenant_id, when_not_found=_tenant_not_found) #verify the hosts exists host = find_host(self.db, host_id, when_not_found=_host_not_found) #verify the host belongs to the tenant if not host in tenant.hosts: _host_not_found() resp.status = falcon.HTTP_200 resp.body = json.dumps(host.format())
def on_delete(self, req, resp, tenant_id, host_id): #verify the tenant exists tenant = find_tenant(self.db, tenant_id=tenant_id, when_not_found=_tenant_not_found) #verify the hosts exists host = find_host(self.db, host_id, when_not_found=_host_not_found) #verify the host belongs to the tenant if not host in tenant.hosts: _host_not_found() self.db.delete(host) self.db().commit() resp.status = falcon.HTTP_200
def on_put(self, req, resp, tenant_id, host_id): #verify the tenant exists tenant = find_tenant(self.db, tenant_id=tenant_id, when_not_found=_tenant_not_found) #verify the hosts exists host = find_host(self.db, host_id, when_not_found=_host_not_found) #verify the host belongs to the tenant if not host in tenant.hosts: _host_not_found() body = load_body(req) if 'hostname' in body.keys(): host.hostname = body['hostname'] if 'ip_address' in body.keys(): host.ip_address = body['ip_address'] if 'profile_id' in body.keys(): profile_id = body['profile_id'] #if profile_id has a new value, # find the profile and assign it to the host if profile_id: profile = find_host_profile(self.db, id=profile_id, when_not_found=_profile_not_found) host.profile = profile #if the profile id key passed an empty value, # then remove the profile form the host else: host.profile = None self.db.commit() resp.status = falcon.HTTP_200
def on_get(self, req, resp, tenant_id, host_id): host = find_host(self.db, host_id, when_not_found=_host_not_found) resp.status = falcon.HTTP_200 resp.body = json.dumps(format_host(host))