Skip to content

Commit

Permalink
feat(dedibox): add inventory (#19)
Browse files Browse the repository at this point in the history
* feat(dedibox): add inventory

* fix sanity

* fix sanity

* fix sanity

* fix sanity

* remove inventory
  • Loading branch information
Laure-di authored Dec 10, 2024
1 parent 9a02d25 commit b5c42c7
Showing 1 changed file with 39 additions and 1 deletion.
40 changes: 39 additions & 1 deletion plugins/inventory/scaleway.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,8 @@
from scaleway.instance.v1 import InstanceV1API
from scaleway.instance.v1 import Server as InstanceServer
from scaleway.instance.v1 import ServerState
from scaleway.dedibox.v1 import DediboxV1API
from scaleway.dedibox.v1 import ServerSummary as DediboxServer

HAS_SCALEWAY_SDK = True
except ImportError:
Expand Down Expand Up @@ -243,8 +245,9 @@ def get_inventory(self):
instances = self._get_instances(client, filters)
elastic_metals = self._get_elastic_metal(client, filters)
apple_silicon = self._get_apple_sillicon(client, filters)
dedibox_servers = self._get_dedibox(client, filters)

return instances + elastic_metals + apple_silicon
return instances + elastic_metals + apple_silicon + dedibox_servers

def _get_instances(self, client: "Client", filters: _Filters) -> List[_Host]:
api = InstanceV1API(client)
Expand Down Expand Up @@ -350,6 +353,41 @@ def _get_apple_sillicon(self, client: "Client", filters: _Filters) -> List[_Host

return results

def _get_dedibox(self, client: "Client", filters: _Filters) -> List[_Host]:
api = DediboxV1API(client)

servers: List[DediboxServer] = []

for zone in filters.zones:
try:
found = api.list_servers_all(
zone=zone,
)
servers.extend(found)
except ScalewayException:
pass

results: List[_Host] = []
for server in servers:
public_ipv4 = filter(lambda ip: ip.version == IPVersion.IPV4, server.interfaces.ips)
public_ipv6 = filter(lambda ip: ip.version == IPVersion.IPV6, server.interfaces.ips)
public_ipv4 = next(public_ipv4, None)
public_ipv6 = next(public_ipv6, None)

host = _Host(
id=server.id,
tags=["dedibox", *server.tags],
zone=server.zone,
state=str(server.status),
hostname=server.name,
public_ipv4=public_ipv4.address if public_ipv4 else None,
private_ipv4=None,
public_ipv6=public_ipv6.address if public_ipv6 else None,
)
results.append(host)

return results

def _get_hostname(self, host: _Host, hostnames: List[str]) -> str:
as_dict = host.__dict__

Expand Down

0 comments on commit b5c42c7

Please sign in to comment.