Fix hcloud_server and hcloud_server_info module when the image is None (#66234)

This commit is contained in:
Lukas Kämmerling 2020-01-07 11:20:40 +01:00 committed by ansibot
parent cb46e5f06b
commit 8743ff02c0
2 changed files with 4 additions and 2 deletions

View file

@ -272,12 +272,13 @@ class AnsibleHcloudServer(Hcloud):
self.hcloud_server = None self.hcloud_server = None
def _prepare_result(self): def _prepare_result(self):
image = None if self.hcloud_server.image is None else to_native(self.hcloud_server.image.name)
return { return {
"id": to_native(self.hcloud_server.id), "id": to_native(self.hcloud_server.id),
"name": to_native(self.hcloud_server.name), "name": to_native(self.hcloud_server.name),
"ipv4_address": to_native(self.hcloud_server.public_net.ipv4.ip), "ipv4_address": to_native(self.hcloud_server.public_net.ipv4.ip),
"ipv6": to_native(self.hcloud_server.public_net.ipv6.ip), "ipv6": to_native(self.hcloud_server.public_net.ipv6.ip),
"image": to_native(self.hcloud_server.image.name), "image": image,
"server_type": to_native(self.hcloud_server.server_type.name), "server_type": to_native(self.hcloud_server.server_type.name),
"datacenter": to_native(self.hcloud_server.datacenter.name), "datacenter": to_native(self.hcloud_server.datacenter.name),
"location": to_native(self.hcloud_server.datacenter.location.name), "location": to_native(self.hcloud_server.datacenter.location.name),

View file

@ -150,12 +150,13 @@ class AnsibleHcloudServerInfo(Hcloud):
for server in self.hcloud_server_info: for server in self.hcloud_server_info:
if server is not None: if server is not None:
image = None if server.image is None else to_native(server.image.name)
tmp.append({ tmp.append({
"id": to_native(server.id), "id": to_native(server.id),
"name": to_native(server.name), "name": to_native(server.name),
"ipv4_address": to_native(server.public_net.ipv4.ip), "ipv4_address": to_native(server.public_net.ipv4.ip),
"ipv6": to_native(server.public_net.ipv6.ip), "ipv6": to_native(server.public_net.ipv6.ip),
"image": to_native(server.image.name), "image": image,
"server_type": to_native(server.server_type.name), "server_type": to_native(server.server_type.name),
"datacenter": to_native(server.datacenter.name), "datacenter": to_native(server.datacenter.name),
"location": to_native(server.datacenter.location.name), "location": to_native(server.datacenter.location.name),