Beispiel #1
0
 def instance_operations(self,
                         instance_id: str,
                         page_size=1000) -> [Operation]:
     """Returns list of instance operations."""
     url = f'{self.compute_url}/compute/v1/instances/{instance_id}/operations?pageSize={page_size}'
     response = self._request.get(url).get('operations')
     return Operation.de_list(response, self)
Beispiel #2
0
 def cancel_operation(self, operation_id: str) -> Operation:
     url = f'{self.operation_url}/operations/{operation_id}:cancel'
     try:
         response = self._request.post(url)
         return Operation.de_json(response, self)
     except YandexCloudError:
         raise BadRequest("Operation can't be canceled.")
Beispiel #3
0
 def snapshot_operations(self,
                         snapshot_id: str,
                         page_size=1000) -> [Operation]:
     """Returns list of the snapshot operations."""
     url = f'{self.compute_url}/compute/v1/snapshots/{snapshot_id}/operations?pageSize={page_size}'
     response = self._request.get(url).get('operations')
     return Operation.de_list(response, self)
Beispiel #4
0
 def certificate_operations(self,
                            certificate_id: str,
                            page_size=1000) -> [Operation]:
     """Returns list of certificate operations."""
     url = f'{self.compute_url}/certificate-manager/v1/certificates{certificate_id}/operations?pageSize={page_size}'
     response = self._request.get(url).get('operations')
     return Operation.de_list(response, self)
Beispiel #5
0
 def _delete_resource(self, url, await_complete=None) -> Operation:
     """Wrapper for delete resources."""
     response = self._request.delete(url)
     operation = Operation.de_json(response, self)
     if not await_complete:
         return operation
     return OperationWait(operation,
                          timeout=self.operation_timeout).completed
Beispiel #6
0
    async def _async_resource_create(self, url, data=None) -> Operation:
        """Half async func for create resource.
        Returns coroutine.
        """
        response = self._request.post(url, json=data)
        operation = Operation.de_json(response, self)

        await OperationWait(
            operation, timeout=self.operation_timeout).await_complete_async()
Beispiel #7
0
    async def _async_delete_resource(self, url) -> CoroutineType:
        """Half async func for delete resource.
        Returns coroutine.
        """
        response = self._request.delete(url)
        operation = Operation.de_json(response, self)

        await OperationWait(
            operation, timeout=self.operation_timeout).await_complete_async()
Beispiel #8
0
    def _resource_create(self,
                         url,
                         data=None,
                         await_complete=True) -> Operation:
        response = self._request.post(url, json=data)
        operation = Operation.de_json(response, self)

        if not await_complete:
            return operation
        return OperationWait(operation).completed
Beispiel #9
0
    def _resource_create(self,
                         url,
                         data=None,
                         await_complete=True) -> Operation:
        """Wrapper for create resource."""
        response = self._request.post(url, json=data)
        operation = Operation.de_json(response, self)

        if not await_complete:
            return operation
        return OperationWait(operation,
                             timeout=self.operation_timeout).completed
Beispiel #10
0
    async def _async_instance_disk_management(self,
                                              instance_id: str,
                                              action=None,
                                              data=None) -> Operation:
        """Supported actions: detachDisk, attachDisk."""

        ACTIONS = ('detachDisk', 'attachDisk')
        if action not in ACTIONS:
            raise TypeError(f'Action {action} not supported')

        url = f'{self.compute_url}/compute/v1/instances/{instance_id}:{action}'
        response = self._request.post(url, json=data)
        operation = Operation.de_json(response, self)

        await OperationWait(operation).await_complete_async()
Beispiel #11
0
    async def _async_instance_state_management(self,
                                               action=None,
                                               instance_id=None
                                               ) -> CoroutineType:
        """Supported actions: start, restart, stop."""

        ACTIONS = ('start', 'restart', 'stop')
        if action not in ACTIONS:
            raise TypeError(f'Action {action} not supported')

        url = f'{self.compute_url}/compute/v1/instances/{instance_id}:{action}'
        response = self._request.post(url)
        operation = Operation.de_json(response, self)

        await OperationWait(operation).await_complete_async()
Beispiel #12
0
    async def _async_instance_disk_management(self,
                                              instance_id: str,
                                              action=None,
                                              data=None) -> Operation:
        """Half async helper func for managing the state of the disk.
        Supported actions: detachDisk, attachDisk.
        Returns coroutine.
        """

        ACTIONS = ('detachDisk', 'attachDisk')
        if action not in ACTIONS:
            raise TypeError(f'Action {action} not supported')

        url = f'{self.compute_url}/compute/v1/instances/{instance_id}:{action}'
        response = self._request.post(url, json=data)
        operation = Operation.de_json(response, self)

        await OperationWait(
            operation, timeout=self.operation_timeout).await_complete_async()
Beispiel #13
0
    def _instance_state_management(self,
                                   action=None,
                                   instance_id=None,
                                   await_complete=None) -> Operation:
        """Helper func for managing the state of the instance.
        Supported actions: start, restart, stop.
        """

        ACTIONS = ('start', 'restart', 'stop')
        if action not in ACTIONS:
            raise TypeError(f'Action {action} not supported')

        url = f'{self.compute_url}/compute/v1/instances/{instance_id}:{action}'
        response = self._request.post(url)
        operation = Operation.de_json(response, self)
        if not await_complete:
            return operation
        return OperationWait(operation,
                             timeout=self.operation_timeout).completed
Beispiel #14
0
 def _delete_resource(self, url, await_complete=None) -> Operation:
     response = self._request.delete(url)
     operation = Operation.de_json(response, self)
     if not await_complete:
         return operation
     return OperationWait(operation).completed
Beispiel #15
0
    async def _async_resource_create(self, url, data=None) -> Operation:
        response = self._request.post(url, json=data)
        operation = Operation.de_json(response, self)

        await OperationWait(operation).await_complete_async()
Beispiel #16
0
 def disk_operations(self, disk_id: str, page_size=1000) -> [Operation]:
     """Returns list of the disk operations."""
     url = f'{self.compute_url}/compute/v1/disks/{disk_id}/operations?pageSize={page_size}'
     response = self._request.get(url).get('operations')
     return Operation.de_list(response, self)
Beispiel #17
0
 def folder_operations(self, folder_id: str, page_size=1000) -> [Operation]:
     """Returns list of operations in the folder."""
     url = f'{self.resource_manager_url}/resource-manager/v1/folders/{folder_id}/operations?pageSize={page_size}'
     response = self._request.get(url).get('operations')
     return Operation.de_list(response, self)
Beispiel #18
0
 def operation(self, operation_id: str) -> Operation:
     """Returns operation as object."""
     url = f'{self.operation_url}/operations/{operation_id}'
     response = self._request.get(url)
     return Operation.de_json(response, self)
Beispiel #19
0
    async def _async_delete_resource(self, url) -> CoroutineType:
        response = self._request.delete(url)
        operation = Operation.de_json(response, self)

        await OperationWait(operation).await_complete_async()