Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
from binarylane.models.change_offsite_backup_location import ChangeOffsiteBackupLocation
from binarylane.models.change_partner import ChangePartner
from binarylane.models.change_port_blocking import ChangePortBlocking
from binarylane.models.change_region import ChangeRegion
from binarylane.models.change_reverse_name import ChangeReverseName
from binarylane.models.change_separate_private_network_interface import ChangeSeparatePrivateNetworkInterface
from binarylane.models.change_source_and_destination_check import ChangeSourceAndDestinationCheck
Expand Down Expand Up @@ -72,6 +73,7 @@ def _get_kwargs(
"ChangeOffsiteBackupLocation",
"ChangePartner",
"ChangePortBlocking",
"ChangeRegion",
"ChangeReverseName",
"ChangeSeparatePrivateNetworkInterface",
"ChangeSourceAndDestinationCheck",
Expand Down Expand Up @@ -148,6 +150,9 @@ def _get_kwargs(
elif isinstance(json_body, ChangePortBlocking):
json_json_body = json_body.to_dict()

elif isinstance(json_body, ChangeRegion):
json_json_body = json_body.to_dict()

elif isinstance(json_body, ChangeReverseName):
json_json_body = json_body.to_dict()

Expand Down Expand Up @@ -298,6 +303,7 @@ def sync_detailed(
"ChangeOffsiteBackupLocation",
"ChangePartner",
"ChangePortBlocking",
"ChangeRegion",
"ChangeReverseName",
"ChangeSeparatePrivateNetworkInterface",
"ChangeSourceAndDestinationCheck",
Expand Down Expand Up @@ -342,7 +348,7 @@ def sync_detailed(
'ChangeAdvancedFirewallRules', 'ChangeBackupSchedule', 'ChangeIpv6',
'ChangeIpv6ReverseNameservers', 'ChangeKernel', 'ChangeManageOffsiteBackupCopies',
'ChangeNetwork', 'ChangeOffsiteBackupLocation', 'ChangePartner', 'ChangePortBlocking',
'ChangeReverseName', 'ChangeSeparatePrivateNetworkInterface',
'ChangeRegion', 'ChangeReverseName', 'ChangeSeparatePrivateNetworkInterface',
'ChangeSourceAndDestinationCheck', 'ChangeThresholdAlerts', 'ChangeVpcIpv4',
'CloneUsingBackup', 'DeleteDisk', 'DetachBackup', 'DisableBackups', 'DisableSelinux',
'EnableBackups', 'EnableIpv6', 'IsRunning', 'PasswordReset', 'Ping', 'PowerCycle',
Expand Down Expand Up @@ -389,6 +395,7 @@ def sync(
"ChangeOffsiteBackupLocation",
"ChangePartner",
"ChangePortBlocking",
"ChangeRegion",
"ChangeReverseName",
"ChangeSeparatePrivateNetworkInterface",
"ChangeSourceAndDestinationCheck",
Expand Down Expand Up @@ -433,7 +440,7 @@ def sync(
'ChangeAdvancedFirewallRules', 'ChangeBackupSchedule', 'ChangeIpv6',
'ChangeIpv6ReverseNameservers', 'ChangeKernel', 'ChangeManageOffsiteBackupCopies',
'ChangeNetwork', 'ChangeOffsiteBackupLocation', 'ChangePartner', 'ChangePortBlocking',
'ChangeReverseName', 'ChangeSeparatePrivateNetworkInterface',
'ChangeRegion', 'ChangeReverseName', 'ChangeSeparatePrivateNetworkInterface',
'ChangeSourceAndDestinationCheck', 'ChangeThresholdAlerts', 'ChangeVpcIpv4',
'CloneUsingBackup', 'DeleteDisk', 'DetachBackup', 'DisableBackups', 'DisableSelinux',
'EnableBackups', 'EnableIpv6', 'IsRunning', 'PasswordReset', 'Ping', 'PowerCycle',
Expand Down Expand Up @@ -473,6 +480,7 @@ async def asyncio_detailed(
"ChangeOffsiteBackupLocation",
"ChangePartner",
"ChangePortBlocking",
"ChangeRegion",
"ChangeReverseName",
"ChangeSeparatePrivateNetworkInterface",
"ChangeSourceAndDestinationCheck",
Expand Down Expand Up @@ -517,7 +525,7 @@ async def asyncio_detailed(
'ChangeAdvancedFirewallRules', 'ChangeBackupSchedule', 'ChangeIpv6',
'ChangeIpv6ReverseNameservers', 'ChangeKernel', 'ChangeManageOffsiteBackupCopies',
'ChangeNetwork', 'ChangeOffsiteBackupLocation', 'ChangePartner', 'ChangePortBlocking',
'ChangeReverseName', 'ChangeSeparatePrivateNetworkInterface',
'ChangeRegion', 'ChangeReverseName', 'ChangeSeparatePrivateNetworkInterface',
'ChangeSourceAndDestinationCheck', 'ChangeThresholdAlerts', 'ChangeVpcIpv4',
'CloneUsingBackup', 'DeleteDisk', 'DetachBackup', 'DisableBackups', 'DisableSelinux',
'EnableBackups', 'EnableIpv6', 'IsRunning', 'PasswordReset', 'Ping', 'PowerCycle',
Expand Down Expand Up @@ -562,6 +570,7 @@ async def asyncio(
"ChangeOffsiteBackupLocation",
"ChangePartner",
"ChangePortBlocking",
"ChangeRegion",
"ChangeReverseName",
"ChangeSeparatePrivateNetworkInterface",
"ChangeSourceAndDestinationCheck",
Expand Down Expand Up @@ -606,7 +615,7 @@ async def asyncio(
'ChangeAdvancedFirewallRules', 'ChangeBackupSchedule', 'ChangeIpv6',
'ChangeIpv6ReverseNameservers', 'ChangeKernel', 'ChangeManageOffsiteBackupCopies',
'ChangeNetwork', 'ChangeOffsiteBackupLocation', 'ChangePartner', 'ChangePortBlocking',
'ChangeReverseName', 'ChangeSeparatePrivateNetworkInterface',
'ChangeRegion', 'ChangeReverseName', 'ChangeSeparatePrivateNetworkInterface',
'ChangeSourceAndDestinationCheck', 'ChangeThresholdAlerts', 'ChangeVpcIpv4',
'CloneUsingBackup', 'DeleteDisk', 'DetachBackup', 'DisableBackups', 'DisableSelinux',
'EnableBackups', 'EnableIpv6', 'IsRunning', 'PasswordReset', 'Ping', 'PowerCycle',
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,217 @@
from __future__ import annotations

from http import HTTPStatus
from typing import Any, Dict, Optional, Union, cast

import httpx

from binarylane import errors
from binarylane.client import Client
from binarylane.models.action_response import ActionResponse
from binarylane.models.change_region import ChangeRegion
from binarylane.models.problem_details import ProblemDetails
from binarylane.models.validation_problem_details import ValidationProblemDetails
from binarylane.types import Response


def _get_kwargs(
server_id: int,
*,
client: Client,
json_body: ChangeRegion,
) -> Dict[str, Any]:
url = "{}/v2/servers/{server_id}/actions#ChangeRegion".format(client.base_url, server_id=server_id)

headers: Dict[str, str] = client.get_headers()
cookies: Dict[str, Any] = client.get_cookies()

json_json_body = json_body.to_dict()

return {
"method": "post",
"url": url,
"headers": headers,
"cookies": cookies,
"timeout": client.get_timeout(),
"json": json_json_body,
}


def _parse_response(
*, client: Client, response: httpx.Response
) -> Optional[Union[ActionResponse, Any, ProblemDetails, ValidationProblemDetails]]:
if response.status_code == HTTPStatus.OK:
response_200 = ActionResponse.from_dict(response.json())

return response_200
if response.status_code == HTTPStatus.ACCEPTED:
response_202 = cast(Any, None)
return response_202
if response.status_code == HTTPStatus.BAD_REQUEST:
response_400 = ValidationProblemDetails.from_dict(response.json())

return response_400
if response.status_code == HTTPStatus.NOT_FOUND:
response_404 = ProblemDetails.from_dict(response.json())

return response_404
if response.status_code == HTTPStatus.UNAUTHORIZED:
response_401 = cast(Any, None)
return response_401
if client.raise_on_unexpected_status:
raise errors.UnexpectedStatus(f"Unexpected status code: {response.status_code}")
else:
return None


def _build_response(
*, client: Client, response: httpx.Response
) -> Response[Union[ActionResponse, Any, ProblemDetails, ValidationProblemDetails]]:
return Response(
status_code=HTTPStatus(response.status_code),
content=response.content,
headers=response.headers,
parsed=_parse_response(client=client, response=response),
)


def sync_detailed(
server_id: int,
*,
client: Client,
json_body: ChangeRegion,
) -> Response[Union[ActionResponse, Any, ProblemDetails, ValidationProblemDetails]]:
"""Change the Region of a Server

This is used to move a server to a different region.
Please check our knowledge base article for the current requirements for servers to be able to move
between regions.


Args:
server_id (int): The ID of the server on which the action should be performed.
json_body (ChangeRegion): Change the Region of a Server

Raises:
errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True.
httpx.TimeoutException: If the request takes longer than Client.timeout.

Returns:
Response[Union[ActionResponse, Any, ProblemDetails, ValidationProblemDetails]]
"""

kwargs = _get_kwargs(
server_id=server_id,
client=client,
json_body=json_body,
)

response = httpx.request(
verify=client.verify_ssl,
**kwargs,
)

return _build_response(client=client, response=response)


def sync(
server_id: int,
*,
client: Client,
json_body: ChangeRegion,
) -> Optional[Union[ActionResponse, Any, ProblemDetails, ValidationProblemDetails]]:
"""Change the Region of a Server

This is used to move a server to a different region.
Please check our knowledge base article for the current requirements for servers to be able to move
between regions.


Args:
server_id (int): The ID of the server on which the action should be performed.
json_body (ChangeRegion): Change the Region of a Server

Raises:
errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True.
httpx.TimeoutException: If the request takes longer than Client.timeout.

Returns:
Response[Union[ActionResponse, Any, ProblemDetails, ValidationProblemDetails]]
"""

return sync_detailed(
server_id=server_id,
client=client,
json_body=json_body,
).parsed


async def asyncio_detailed(
server_id: int,
*,
client: Client,
json_body: ChangeRegion,
) -> Response[Union[ActionResponse, Any, ProblemDetails, ValidationProblemDetails]]:
"""Change the Region of a Server

This is used to move a server to a different region.
Please check our knowledge base article for the current requirements for servers to be able to move
between regions.


Args:
server_id (int): The ID of the server on which the action should be performed.
json_body (ChangeRegion): Change the Region of a Server

Raises:
errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True.
httpx.TimeoutException: If the request takes longer than Client.timeout.

Returns:
Response[Union[ActionResponse, Any, ProblemDetails, ValidationProblemDetails]]
"""

kwargs = _get_kwargs(
server_id=server_id,
client=client,
json_body=json_body,
)

async with httpx.AsyncClient(verify=client.verify_ssl) as _client:
response = await _client.request(**kwargs)

return _build_response(client=client, response=response)


async def asyncio(
server_id: int,
*,
client: Client,
json_body: ChangeRegion,
) -> Optional[Union[ActionResponse, Any, ProblemDetails, ValidationProblemDetails]]:
"""Change the Region of a Server

This is used to move a server to a different region.
Please check our knowledge base article for the current requirements for servers to be able to move
between regions.


Args:
server_id (int): The ID of the server on which the action should be performed.
json_body (ChangeRegion): Change the Region of a Server

Raises:
errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True.
httpx.TimeoutException: If the request takes longer than Client.timeout.

Returns:
Response[Union[ActionResponse, Any, ProblemDetails, ValidationProblemDetails]]
"""

return (
await asyncio_detailed(
server_id=server_id,
client=client,
json_body=json_body,
)
).parsed
70 changes: 70 additions & 0 deletions lib/binarylane/models/change_region.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
from __future__ import annotations

from typing import Any, Dict, List, Type, TypeVar

import attr

from binarylane.models.change_region_type import ChangeRegionType

T = TypeVar("T", bound="ChangeRegion")


@attr.s(auto_attribs=True)
class ChangeRegion:
"""Change the Region of a Server

Attributes:
type (ChangeRegionType):
region (str): The slug of the selected region.
"""

type: ChangeRegionType
region: str
additional_properties: Dict[str, Any] = attr.ib(init=False, factory=dict)

def to_dict(self) -> Dict[str, Any]:
type = self.type.value

region = self.region

field_dict: Dict[str, Any] = {}
field_dict.update(self.additional_properties)
field_dict.update(
{
"type": type,
"region": region,
}
)

return field_dict

@classmethod
def from_dict(cls: Type[T], src_dict: Dict[str, Any]) -> T:
d = src_dict.copy()
type = ChangeRegionType(d.pop("type"))

region = d.pop("region")

change_region = cls(
type=type,
region=region,
)

change_region.additional_properties = d
return change_region

@property
def additional_keys(self) -> List[str]:
return list(self.additional_properties.keys())

def __getitem__(self, key: str) -> Any:
return self.additional_properties[key]

def __setitem__(self, key: str, value: Any) -> None:
self.additional_properties[key] = value

def __delitem__(self, key: str) -> None:
del self.additional_properties[key]

def __contains__(self, key: str) -> bool:
return key in self.additional_properties
10 changes: 10 additions & 0 deletions lib/binarylane/models/change_region_type.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
from __future__ import annotations

from enum import Enum


class ChangeRegionType(str, Enum):
CHANGE_REGION = "change_region"

def __str__(self) -> str:
return str(self.value)
Loading
Loading