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)
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.")
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)
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)
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
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()
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()
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
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
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()
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()
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()
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
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
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()
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)
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)
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)
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()