Beispiel #1
0
    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'])
Beispiel #2
0
 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
Beispiel #3
0
    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'])
Beispiel #4
0
    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"])
Beispiel #5
0
    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'])
Beispiel #6
0
    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'])
Beispiel #7
0
 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
Beispiel #8
0
    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'])
Beispiel #9
0
    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
Beispiel #10
0
    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
Beispiel #11
0
    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
Beispiel #12
0
    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
Beispiel #13
0
    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
Beispiel #14
0
    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)
Beispiel #15
0
 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()
Beispiel #16
0
    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'])
Beispiel #17
0
    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)
Beispiel #18
0
 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()
Beispiel #19
0
 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()
Beispiel #20
0
    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
Beispiel #21
0
 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()
Beispiel #22
0
    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)
Beispiel #23
0
    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)
Beispiel #24
0
    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__[:]
Beispiel #25
0
    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__[:]
Beispiel #26
0
    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'])
Beispiel #27
0
    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)
Beispiel #28
0
    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)
Beispiel #29
0
    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'])