def create(cls, client, config, wait=False): """Create a new container config.""" response = client.api.containers.post(json=config) if wait: Operation.wait_for_operation(client, response.json()['operation']) return cls(name=config['name'])
def rename(self, new_name, wait=False): """Rename a snapshot.""" response = self.api.post(json={'name': new_name}) if wait: Operation.wait_for_operation(self.client, response.json()['operation']) self.name = new_name
def delete(self, wait=False): """Delete the container.""" response = self._client.api.containers[self.name].delete() if wait: Operation.wait_for_operation( self._client, response.json()['operation'])
def create(cls, client, config, wait=False): """Create a new container config.""" response = client.api.containers.post(json=config) if wait: Operation.wait_for_operation(client, response.json()["operation"]) return cls(name=config["name"])
def delete(self, wait=False): """Delete the container.""" response = self._client.api.containers[self.name].delete() if wait: Operation.wait_for_operation(self._client, response.json()['operation'])
def delete(self, wait=False): """Delete the image.""" response = self._client.api.images[self.fingerprint].delete() if wait: Operation.wait_for_operation( self._client, response.json()['operation'])
def rename(self, new_name, wait=False): """Rename a snapshot.""" response = self.api.post(json={'name': new_name}) if wait: Operation.wait_for_operation( self.client, response.json()['operation']) self.name = new_name
def delete(self, wait=False): """Delete the image.""" response = self._client.api.images[self.fingerprint].delete() if wait: Operation.wait_for_operation(self._client, response.json()['operation'])
def rename(self, name, wait=False): """Rename a container.""" response = self.api.post(json={'name': name}) if wait: Operation.wait_for_operation(self.client, response.json()['operation']) self.name = name
def create(cls, client, container, name, stateful=False, wait=False): response = client.api.containers[container.name].snapshots.post(json={ 'name': name, 'stateful': stateful}) snapshot = cls(client, container=container, name=name) if wait: Operation.wait_for_operation(client, response.json()['operation']) return snapshot
def rename(self, name, wait=False): """Rename a container.""" response = self.api.post(json={'name': name}) if wait: Operation.wait_for_operation( self.client, response.json()['operation']) self.name = name
def delete(self, wait=False): """Delete an object from the server.""" response = self.api.delete() if response.json()['type'] == 'async' and wait: Operation.wait_for_operation( self.client, response.json()['operation']) self.client = None
def delete(self, wait=False): """Delete an object from the server.""" response = self.api.delete() if response.json()['type'] == 'async' and wait: Operation.wait_for_operation(self.client, response.json()['operation']) self.client = None
def create(cls, client, config, wait=False): """Create a new container config.""" response = client.api.containers.post(json=config) if response.status_code != 202: raise exceptions.CreateFailed(response.json()) if wait: Operation.wait_for_operation(client, response.json()['operation']) return cls(name=config['name'], _client=client)
def _set_state(self, state, timeout=30, force=True, wait=False): response = self.api.state.put(json={ 'action': state, 'timeout': timeout, 'force': force }) if wait: Operation.wait_for_operation( self.client, response.json()['operation']) self.sync()
def create(cls, client, config, wait=False): """Create a new container config.""" try: response = client.api.containers.post(json=config) except exceptions.LXDAPIException as e: raise exceptions.CreateFailed(e.response) if wait: Operation.wait_for_operation(client, response.json()['operation']) return cls(client, name=config['name'])
def create(cls, client, config, wait=False): """Create a new container config.""" try: response = client.api.containers.post(json=config) except exceptions.LXDAPIException as e: raise exceptions.CreateFailed(e.response) if wait: Operation.wait_for_operation(client, response.json()['operation']) return cls(name=config['name'], _client=client)
def _set_state(self, state, timeout=30, force=True, wait=False): response = self.api.state.put(json={ 'action': state, 'timeout': timeout, 'force': force }) if wait: Operation.wait_for_operation(self.client, response.json()['operation']) self.sync()
def _set_state(self, state, timeout=30, force=True, wait=False): response = self._client.api.containers[self.name].state.put(json={ 'action': state, 'timeout': timeout, 'force': force }) if wait: Operation.wait_for_operation( self._client, response.json()['operation']) self.fetch()
def create(cls, client, container, name, stateful=False, wait=False): response = client.api.containers[container.name].snapshots.post( json={ 'name': name, 'stateful': stateful }) snapshot = cls(client, container=container, name=name) if wait: Operation.wait_for_operation(client, response.json()['operation']) return snapshot
def _set_state(self, state, timeout=30, force=True, wait=False): response = self._client.api.containers[self.name].state.put( json={ 'action': state, 'timeout': timeout, 'force': force }) if wait: Operation.wait_for_operation(self._client, response.json()['operation']) self.fetch()
def create(cls, client, image_data, public=False, wait=False): """Create an image.""" fingerprint = hashlib.sha256(image_data).hexdigest() headers = {} if public: headers['X-LXD-Public'] = '1' response = client.api.images.post(data=image_data, headers=headers) if wait: Operation.wait_for_operation(client, response.json()['operation']) return cls.get(client, fingerprint)
def create(cls, client, image_data, public=False, wait=False): """Create an image.""" fingerprint = hashlib.sha256(image_data).hexdigest() headers = {} if public: headers['X-LXD-Public'] = '1' response = client.api.images.post( data=image_data, headers=headers) if wait: Operation.wait_for_operation(client, response.json()['operation']) return cls.get(client, fingerprint)
def save(self, wait=False): """Save data to the server. This method should write the new data to the server via marshalling. It should be a no-op when the object is not dirty, to prevent needless I/O. """ marshalled = self.marshall() response = self.api.put(json=marshalled) if response.json()['type'] == 'async' and wait: Operation.wait_for_operation( self.client, response.json()['operation']) del self.__dirty__[:]
def save(self, wait=False): """Save data to the server. This method should write the new data to the server via marshalling. It should be a no-op when the object is not dirty, to prevent needless I/O. """ marshalled = self.marshall() response = self.api.put(json=marshalled) if response.json()['type'] == 'async' and wait: Operation.wait_for_operation(self.client, response.json()['operation']) del self.__dirty__[:]
def update(self, wait=False): """Update the container in lxd from local changes.""" try: marshalled = self.marshall() except AttributeError: raise exceptions.ObjectIncomplete() # These two properties are explicitly not allowed. del marshalled['name'] del marshalled['status'] response = self._client.api.containers[self.name].put(json=marshalled) if wait: Operation.wait_for_operation(self._client, response.json()['operation'])
def create(cls, client, image_data, public=False, wait=False): """Create an image.""" fingerprint = hashlib.sha256(image_data).hexdigest() headers = {} if public: headers['X-LXD-Public'] = '1' try: response = client.api.images.post(data=image_data, headers=headers) except exceptions.LXDAPIException as e: raise exceptions.CreateFailed(e.response.json()) if wait: Operation.wait_for_operation(client, response.json()['operation']) return cls(_client=client, fingerprint=fingerprint)
def create(cls, client, image_data, public=False, wait=False): """Create an image.""" fingerprint = hashlib.sha256(image_data).hexdigest() headers = {} if public: headers['X-LXD-Public'] = '1' try: response = client.api.images.post( data=image_data, headers=headers) except exceptions.LXDAPIException as e: raise exceptions.CreateFailed(e.response.json()) if wait: Operation.wait_for_operation(client, response.json()['operation']) return cls(_client=client, fingerprint=fingerprint)
def update(self, wait=False): """Update the container in lxd from local changes.""" try: marshalled = self.marshall() except AttributeError: raise exceptions.ObjectIncomplete() # These two properties are explicitly not allowed. del marshalled['name'] del marshalled['status'] response = self._client.api.containers[self.name].put( json=marshalled) if wait: Operation.wait_for_operation( self._client, response.json()['operation'])