Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def bound_model_class(self):
class Model(BaseDomain):
__slots__ = ("id", "name", "description")
def __init__(self, id, name="", description=""):
self.id = id
self.name = name
self.description = description
class BoundModel(BoundModelBase):
model = Model
return BoundModel
# -*- coding: utf-8 -*-
from hcloud.core.client import BoundModelBase, ClientEntityBase, GetEntityByNameMixin
from hcloud.isos.domain import Iso
class BoundIso(BoundModelBase):
model = Iso
class IsosClient(ClientEntityBase, GetEntityByNameMixin):
results_list_attribute_name = 'isos'
def get_by_id(self, id):
# type: (int) -> BoundIso
"""Get a specific ISO by its id
:param id: int
:return: :class:`BoundIso `
"""
response = self._client.request(url="/isos/{iso_id}".format(iso_id=id), method="GET")
return BoundIso(self, response['iso'])
# -*- coding: utf-8 -*-
from hcloud.core.client import ClientEntityBase, BoundModelBase, GetEntityByNameMixin
from hcloud.ssh_keys.domain import SSHKey
class BoundSSHKey(BoundModelBase):
model = SSHKey
def update(self, name=None, labels=None):
# type: (Optional[str], Optional[Dict[str, str]]) -> BoundSSHKey
"""Updates an SSH key. You can update an SSH key name and an SSH key labels.
:param description: str (optional)
New Description to set
:param labels: Dict[str, str] (optional)
User-defined labels (key-value pairs)
:return: :class:`BoundSSHKey
"""
return self._client.update(self, name, labels)
def delete(self):
# type: () -> bool
# -*- coding: utf-8 -*-
from hcloud.actions.client import BoundAction
from hcloud.core.client import BoundModelBase, ClientEntityBase, GetEntityByNameMixin
from hcloud.core.domain import add_meta_to_result
from hcloud.floating_ips.domain import FloatingIP, CreateFloatingIPResponse
from hcloud.locations.client import BoundLocation
class BoundFloatingIP(BoundModelBase):
model = FloatingIP
def __init__(self, client, data, complete=True):
from hcloud.servers.client import BoundServer
server = data.get("server")
if server is not None:
data['server'] = BoundServer(client._client.servers, {"id": server}, complete=False)
home_location = data.get("home_location")
if home_location is not None:
data['home_location'] = BoundLocation(client._client.locations, home_location)
super(BoundFloatingIP, self).__init__(client, data, complete)
def get_actions_list(self, status=None, sort=None, page=None, per_page=None):
# type: (Optional[List[str]], Optional[List[str]], Optional[int], Optional[int]) -> PageResult[BoundAction, Meta]
# -*- coding: utf-8 -*-
import time
from hcloud.core.client import ClientEntityBase, BoundModelBase
from hcloud.actions.domain import Action, ActionFailedException, ActionTimeoutException
class BoundAction(BoundModelBase):
model = Action
def wait_until_finished(self, max_retries=100):
"""Wait until the specific action has status="finished" (set Client.poll_interval to specify a delay between checks)
:param max_retries: int
Specify how many retries will be performed before an ActionTimeoutException will be raised
:raises: ActionFailedException when action is finished with status=="error"
:raises: ActionTimeoutException when Action is still in "running" state after max_retries reloads.
"""
while self.status == Action.STATUS_RUNNING:
if max_retries > 0:
self.reload()
time.sleep(self._client._client.poll_interval)
max_retries = max_retries - 1
else:
# -*- coding: utf-8 -*-
from hcloud.core.client import ClientEntityBase, BoundModelBase, GetEntityByNameMixin
from hcloud.locations.domain import Location
class BoundLocation(BoundModelBase):
model = Location
class LocationsClient(ClientEntityBase, GetEntityByNameMixin):
results_list_attribute_name = 'locations'
def get_by_id(self, id):
# type: (int) -> locations.client.BoundLocation
"""Get a specific location by its ID.
:param id: int
:return: :class:`BoundLocation `
"""
response = self._client.request(url="/locations/{location_id}".format(location_id=id), method="GET")
return BoundLocation(self, response['location'])
from hcloud.core.client import ClientEntityBase, BoundModelBase, GetEntityByNameMixin
from hcloud.server_types.domain import ServerType
class BoundServerType(BoundModelBase):
model = ServerType
class ServerTypesClient(ClientEntityBase, GetEntityByNameMixin):
results_list_attribute_name = 'server_types'
def get_by_id(self, id):
# type: (int) -> server_types.client.BoundServerType
"""Returns a specific Server Type.
:param id: int
:return: :class:`BoundServerType `
"""
response = self._client.request(url="/server_types/{server_type_id}".format(server_type_id=id), method="GET")
return BoundServerType(self, response['server_type'])
from hcloud.actions.client import BoundAction
from hcloud.core.domain import add_meta_to_result
from hcloud.floating_ips.client import BoundFloatingIP
from hcloud.isos.client import BoundIso
from hcloud.servers.domain import Server, CreateServerResponse, ResetPasswordResponse, EnableRescueResponse, \
RequestConsoleResponse, PublicNetwork, IPv4Address, IPv6Network, PrivateNet
from hcloud.volumes.client import BoundVolume
from hcloud.images.domain import CreateImageResponse
from hcloud.images.client import BoundImage
from hcloud.server_types.client import BoundServerType
from hcloud.datacenters.client import BoundDatacenter
from hcloud.networks.client import BoundNetwork # noqa
from hcloud.networks.domain import Network # noqa
class BoundServer(BoundModelBase):
model = Server
def __init__(self, client, data, complete=True):
datacenter = data.get('datacenter')
if datacenter is not None:
data['datacenter'] = BoundDatacenter(client._client.datacenters, datacenter)
volumes = data.get('volumes', [])
if volumes:
volumes = [BoundVolume(client._client.volumes, {"id": volume}, complete=False) for volume in volumes]
data['volumes'] = volumes
image = data.get("image", None)
if image is not None:
data['image'] = BoundImage(client._client.images, image)
from hcloud.servers.client import BoundServer
from hcloud.load_balancer_types.client import BoundLoadBalancerType
from hcloud.locations.client import BoundLocation
from hcloud.networks.client import BoundNetwork
from hcloud.core.client import ClientEntityBase, BoundModelBase, GetEntityByNameMixin
from hcloud.core.domain import add_meta_to_result
from hcloud.actions.client import BoundAction
from hcloud.load_balancers.domain import LoadBalancer, IPv4Address, IPv6Network, PublicNetwork, PrivateNet, \
CreateLoadBalancerResponse, LoadBalancerTarget, LoadBalancerService, LoadBalancerServiceHttp, \
LoadBalancerHealthCheck, LoadBalancerHealtCheckHttp, LoadBalancerAlgorithm
class BoundLoadBalancer(BoundModelBase):
model = LoadBalancer
def __init__(self, client, data, complete=True):
algorithm = data.get("algorithm")
if algorithm:
data['algorithm'] = LoadBalancerAlgorithm(type=algorithm['type'])
public_net = data.get("public_net")
if public_net:
ipv4_address = IPv4Address(**public_net['ipv4'])
ipv6_network = IPv6Network(**public_net['ipv6'])
data['public_net'] = PublicNetwork(ipv4=ipv4_address, ipv6=ipv6_network, enabled=public_net['enabled'])
private_nets = data.get("private_net")
if private_nets:
private_nets = [PrivateNet(
# -*- coding: utf-8 -*-
from hcloud.core.client import ClientEntityBase, BoundModelBase, GetEntityByNameMixin
from hcloud.certificates.domain import Certificate
class BoundCertificate(BoundModelBase):
model = Certificate
def update(self, name=None, labels=None):
# type: (Optional[str], Optional[Dict[str, str]]) -> BoundCertificate
"""Updates an certificate. You can update an certificate name and the certificate labels.
:param name: str (optional)
New name to set
:param labels: Dict[str, str] (optional)
User-defined labels (key-value pairs)
:return: :class:`BoundCertificate
"""
return self._client.update(self, name, labels)
def delete(self):
# type: () -> bool