Esempio n. 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'])
Esempio n. 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
Esempio n. 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'])
Esempio n. 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"])
Esempio n. 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'])
Esempio n. 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'])
Esempio n. 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
Esempio n. 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'])
Esempio n. 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
Esempio n. 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
Esempio n. 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
Esempio n. 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
Esempio n. 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
Esempio n. 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)
Esempio n. 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()
Esempio n. 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'])
Esempio n. 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)
Esempio n. 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()
Esempio n. 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()
Esempio n. 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
Esempio n. 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()
Esempio n. 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)
Esempio n. 23
0
File: image.py Progetto: Cubx/pylxd
    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)
Esempio n. 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__[:]
Esempio n. 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__[:]
Esempio n. 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'])
Esempio n. 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)
Esempio n. 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)
Esempio n. 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'])