Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_bound_image_init(self, image_response):
bound_image = BoundImage(
client=mock.MagicMock(),
data=image_response['image']
)
assert bound_image.id == 4711
assert bound_image.type == "snapshot"
assert bound_image.status == "available"
assert bound_image.name == "ubuntu-20.04"
assert bound_image.description == "Ubuntu 20.04 Standard 64 bit"
assert bound_image.image_size == 2.3
assert bound_image.disk_size == 10
assert bound_image.created == datetime.datetime(2016, 1, 30, 23, 50, tzinfo=tzoffset(None, 0))
assert bound_image.os_flavor == "ubuntu"
assert bound_image.os_version == "16.04"
assert bound_image.rapid_deploy is False
assert bound_image.deprecated == datetime.datetime(2018, 2, 28, 0, 0, tzinfo=tzoffset(None, 0))
@pytest.mark.parametrize("image", [Image(id=1), BoundImage(mock.MagicMock(), dict(id=1))])
def test_update(self, images_client, image, response_update_image):
images_client._client.request.return_value = response_update_image
image = images_client.update(image, description="My new Image description", type="snapshot", labels={})
images_client._client.request.assert_called_with(url="/images/1", method="PUT", json={"description": "My new Image description", "type": "snapshot", "labels": {}})
assert image.id == 4711
assert image.description == "My new Image description"
def bound_image(self, hetzner_client):
return BoundImage(client=hetzner_client.images, data=dict(id=14))
assert bound_server.server_type._client == bound_server._client._client.server_types
assert bound_server.server_type.id == 1
assert bound_server.server_type.complete is True
assert len(bound_server.volumes) == 2
assert isinstance(bound_server.volumes[0], BoundVolume)
assert bound_server.volumes[0]._client == bound_server._client._client.volumes
assert bound_server.volumes[0].id == 1
assert bound_server.volumes[0].complete is False
assert isinstance(bound_server.volumes[1], BoundVolume)
assert bound_server.volumes[1]._client == bound_server._client._client.volumes
assert bound_server.volumes[1].id == 2
assert bound_server.volumes[1].complete is False
assert isinstance(bound_server.image, BoundImage)
assert bound_server.image._client == bound_server._client._client.images
assert bound_server.image.id == 4711
assert bound_server.image.name == "ubuntu-20.04"
assert bound_server.image.complete is True
assert isinstance(bound_server.iso, BoundIso)
assert bound_server.iso._client == bound_server._client._client.isos
assert bound_server.iso.id == 4711
assert bound_server.iso.name == "FreeBSD-11.0-RELEASE-amd64-dvd1"
assert bound_server.iso.complete is True
assert len(bound_server.private_net) == 1
assert isinstance(bound_server.private_net[0], PrivateNet)
assert bound_server.private_net[0].network._client == bound_server._client._client.networks
assert bound_server.private_net[0].ip == "10.1.1.5"
assert bound_server.private_net[0].mac_address == "86:00:ff:2a:7d:e1"
def __init__(self, client, data):
from hcloud.servers.client import BoundServer
created_from = data.get("created_from")
if created_from is not None:
data['created_from'] = BoundServer(client._client.servers, created_from, complete=False)
bound_to = data.get("bound_to")
if bound_to is not None:
data['bound_to'] = BoundServer(client._client.servers, {"id": bound_to}, complete=False)
super(BoundImage, self).__init__(client, data)
:return: :class:`BoundAction `
"""
data = {}
if description is not None:
data.update({"description": description})
if type is not None:
data.update({"type": type})
if labels is not None:
data.update({"labels": labels})
response = self._client.request(url="/servers/{server_id}/actions/create_image".format(server_id=server.id),
method="POST", json=data)
return CreateImageResponse(action=BoundAction(self._client.actions, response['action']),
image=BoundImage(self._client.images, response['image']))
params['label_selector'] = label_selector
if bound_to is not None:
params['bound_to'] = bound_to
if type is not None:
params['type'] = type
if sort is not None:
params['sort'] = sort
if page is not None:
params['page'] = page
if per_page is not None:
params['per_page'] = per_page
if status is not None:
params['status'] = per_page
response = self._client.request(url="/images", method="GET", params=params)
images = [BoundImage(self, image_data) for image_data in response['images']]
return self._add_meta_to_result(images, response)
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)
iso = data.get("iso", None)
if iso is not None:
data['iso'] = BoundIso(client._client.isos, iso)
server_type = data.get("server_type")
if server_type is not None:
data['server_type'] = BoundServerType(client._client.server_types, server_type)
public_net = data.get("public_net")
if public_net:
ipv4_address = IPv4Address(**public_net['ipv4'])
ipv6_network = IPv6Network(**public_net['ipv6'])
floating_ips = [BoundFloatingIP(client._client.floating_ips, {"id": floating_ip}, complete=False) for
floating_ip in public_net['floating_ips']]
data['public_net'] = PublicNetwork(ipv4=ipv4_address, ipv6=ipv6_network, floating_ips=floating_ips)
def get_by_id(self, id):
# type: (int) -> BoundImage
"""Get a specific Image
:param id: int
:return: :class:`BoundImage
:param type: str (optional)
Destination image type to convert to
Choices: snapshot
:param labels: Dict[str, str] (optional)
User-defined labels (key-value pairs)
:return: :class:`BoundImage `
"""
data = {}
if description is not None:
data.update({"description": description})
if type is not None:
data.update({"type": type})
if labels is not None:
data.update({"labels": labels})
response = self._client.request(url="/images/{image_id}".format(image_id=image.id), method="PUT", json=data)
return BoundImage(self, response['image'])