Skip to content

Commit 21a7c95

Browse files
authored
fix: get instance ips (#97)
1 parent d67cd18 commit 21a7c95

2 files changed

Lines changed: 8 additions & 13 deletions

File tree

galaxy.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
namespace: scaleway
44
name: scaleway
5-
version: 2.7.1
5+
version: 2.7.2
66
readme: README.md
77
authors:
88
- Ansible (https://github.com/ansible)

plugins/module_utils/instance.py

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,39 +5,34 @@
55
from scaleway import Client
66
from scaleway.instance.v1 import Server as InstanceServer
77
from scaleway.ipam.v1 import IpamV1API
8-
from scaleway.vpc.v2 import VpcV2API
98
except ImportError:
109
HAS_SCALEWAY_SDK = False
1110

1211

1312
@dataclass
14-
class VpcIps:
13+
class VpcIp:
1514
ipv4: Optional[str] = None
1615
ipv6: Optional[str] = None
1716

1817

1918
def get_instance_private_ips(
2019
client: "Client", servers: list["InstanceServer"]
21-
) -> Dict[str, VpcIps]:
20+
) -> Dict[str, VpcIp]:
2221
"""
2322
return a mapping of first found vpc IPs with the instance
2423
"""
25-
vpc_api = VpcV2API(client)
2624
ipam_api = IpamV1API(client)
2725

2826
vpc_ips = {}
2927

3028
for server in servers:
29+
vpc_ip = VpcIp()
30+
vpc_ips[server.id] = vpc_ip
3131
for pnic in server.private_nics:
32-
server_pn = vpc_api.get_private_network(
33-
private_network_id=pnic.private_network_id
34-
)
35-
vpc_ips[server.id] = VpcIps
36-
37-
for ip in ipam_api.list_i_ps(vpc_id=server_pn.vpc_id).ips:
32+
for ip in ipam_api.list_i_ps_all(resource_id=pnic.id):
3833
if ip.is_ipv6:
39-
vpc_ips[server.id].ipv6 = ip.address.split("/")[0]
34+
vpc_ip.ipv6 = ip.address.split("/")[0]
4035
else:
41-
vpc_ips[server.id].ipv4 = ip.address.split("/")[0]
36+
vpc_ip.ipv4 = ip.address.split("/")[0]
4237

4338
return vpc_ips

0 commit comments

Comments
 (0)