示例#1
0
    def instance_detach_disk(self,
                             instance_id: str,
                             disk_id=None,
                             disk_name=None,
                             await_complete=True,
                             run_async_await=False) -> Operation:
        """Detach disk from the instance."""
        if disk_id and disk_name:
            raise TooManyArguments(
                'disk_id and disk_name received, but you can use only one param'
            )

        if disk_id:
            data = {'diskId': disk_id}
        elif disk_name:
            data = {'diskName': disk_name}

        if run_async_await:
            return self._async_instance_disk_management(instance_id,
                                                        action='detachDisk',
                                                        data=data)

        return self._instance_disk_management(instance_id,
                                              action='detachDisk',
                                              data=data,
                                              await_complete=await_complete)
示例#2
0
    def __init__(self,
                 oauth_token: str = None,
                 iam_token: str = None,
                 service_account_key: dict = None,
                 request: object = None,
                 timeout: int = None,
                 operation_timeout: int = None,
                 base_url: str = None,
                 resource_manager_url: str = None,
                 compute_url: str = None,
                 certificate_url: str = None,
                 certificate_data_url: str = None,
                 iam_url: str = None,
                 operation_url: str = None):

        _cred_args = [
            x for x in (service_account_key, oauth_token, iam_token)
            if x is not None
        ]
        if len(_cred_args) > 1:
            message = f'Too many credentials({len(_cred_args)}) received, ' + \
                      'but only one credential type can be specified'
            raise TooManyArguments(message)
        elif len(_cred_args) < 1:
            raise InvalidToken(
                'IAM/OAuth token or service account key required!')

        if oauth_token:
            self.token = YandexCloudClient.get_iam_token(oauth_token)
        elif service_account_key:
            self.token = YandexCloudClient.get_token_for_sa(
                service_account_key)
        elif iam_token:
            self.token = iam_token
        else:
            raise InvalidToken(
                'IAM/OAuth token or service account key required!')

        self.timeout = int(timeout) if timeout is not None else DEFAULT_TIMEOUT
        self.operation_timeout = int(
            operation_timeout
        ) if operation_timeout is not None else DEFAULT_OP_TIMEOUT

        if request:
            self._request = request
            self._request.set_and_return_client(self)
        else:
            self._request = Request(self, timeout=self.timeout)

        self.base_url = base_url or BASE_URL
        self.iam_url = iam_url or IAM_URL
        self.resource_manager_url = resource_manager_url or RESOURCE_MANAGER_URL
        self.compute_url = compute_url or COMPUTE_URL
        self.certificate_url = certificate_url or CERTIFICATE_URL
        self.certificate_data_url = certificate_data_url or CERTIFICATE_DATA_URL
        self.operation_url = operation_url or OPERATION_URL
示例#3
0
文件: disk.py 项目: 113375/quiz
    def _validate(self):
        if self.imageId and self.snapshotId:
            raise TooManyArguments('snapshot_id and image_id received, but you can use only one param')

        if self.mode is not None and self.mode not in DISK_MODES:
            raise ValueError(f'Invalid disk mode: {self.mode}. Supported modes: {DISK_MODES}')

        if self.size is not None:
            if self.size < MIN_DISK_SIZE or self.size > MAX_DISK_SIZE:
                raise ValueError(f'The disk size must be between {MIN_DISK_SIZE} and {MAX_DISK_SIZE} bytes')
示例#4
0
    def _validate(self):
        if self.imageId and self.snapshotId:
            raise TooManyArguments(
                'snapshot_id and image_id received, but you can use only one param'
            )

        if self.size < MIN_DISK_SIZE or self.size > MAX_DISK_SIZE:
            raise ValueError(
                f'The disk size must be between {MIN_DISK_SIZE} and {MAX_DISK_SIZE} bytes'
            )