Skip to content

Commit

Permalink
fix: add filter state to class and add example
Browse files Browse the repository at this point in the history
  • Loading branch information
Laure-di committed Dec 31, 2024
1 parent 78ba2cf commit b156e76
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions plugins/inventory/scaleway.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,11 @@
type: list
elements: str
default: []
state:
description:
- State of the instance server
type: str
default: running
hostnames:
description: List of preference about what to use as an hostname.
type: list
Expand Down Expand Up @@ -89,6 +94,8 @@
- nl-ams-1
tags:
- dev
state:
- stopped
variables:
ansible_host: public_ipv4
"""
Expand All @@ -104,7 +111,6 @@

try:
from scaleway_core.bridge import Zone

from scaleway import Client, ScalewayException
from scaleway.applesilicon.v1alpha1 import ApplesiliconV1Alpha1API
from scaleway.applesilicon.v1alpha1 import Server as ApplesiliconServer
Expand Down Expand Up @@ -135,6 +141,7 @@ class InstanceServerState:
STOPPING = "stopping"
LOCKED = "locked"


@dataclass
class _Filters:
zones: List[str] = field(default_factory=list)
Expand Down Expand Up @@ -258,7 +265,7 @@ def get_inventory(self):

return instances + elastic_metals + apple_silicon + dedibox_servers

def _get_instances(self, client: "Client", filters: _Filters, state: Optional[str] = InstanceServerState.RUNNING,) -> List[_Host]:
def _get_instances(self, client: "Client", filters: _Filters) -> List[_Host]:
api = InstanceV1API(client)

servers: List[InstanceServer] = []
Expand Down Expand Up @@ -451,6 +458,7 @@ def _get_client(self):
def _get_filters(self):
zones = self.get_option("zones")
tags = self.get_option("tags")
state = self.get_option("state")

filters = _Filters()

Expand All @@ -460,4 +468,7 @@ def _get_filters(self):
if tags:
filters.tags = tags

if state:
filters.state = state

return filters

0 comments on commit b156e76

Please sign in to comment.