Skip to content

Commit 75d4515

Browse files
authored
feat: add x-cli-lookup attribute to load-balancer and vpc (#69)
The following commands now support identifying a load-balancer by ID or name: - load-balancer get - load-balancer update - load-balancer delete - load-balancer rule create - load-balancer rule delete - load-balancer server create - load-balancer server delete The following commands now support identifying a VPC by ID or name: - server create - server action change-network - vpc get - vpc members - vpc patch - vpc update - vpc delete
1 parent 8d144c2 commit 75d4515

17 files changed

+128
-14
lines changed

src/binarylane/console/commands/api/delete_v2_load_balancers_load_balancer_id.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
if TYPE_CHECKING:
1010
from binarylane.client import Client
1111

12+
import binarylane.console.commands.api.get_v2_load_balancers as api_get_v2_load_balancers
1213
from binarylane.console.parser import Mapping, PrimitiveAttribute
1314
from binarylane.console.runners.command import CommandRunner
1415

@@ -28,13 +29,18 @@ def reference_url(self) -> str:
2829
def create_mapping(self) -> Mapping:
2930
mapping = Mapping(CommandRequest)
3031

32+
def lookup_load_balancer_id(ref: str) -> Union[None, int]:
33+
return api_get_v2_load_balancers.Command(self._context).lookup(ref)
34+
3135
mapping.add(
3236
PrimitiveAttribute(
3337
"load_balancer_id",
3438
int,
3539
required=True,
3640
option_name=None,
37-
description="""The ID of the load balancer to cancel.""",
41+
metavar="load_balancer",
42+
description="""The ID or name of the load balancer to cancel.""",
43+
lookup=lookup_load_balancer_id,
3844
)
3945
)
4046

src/binarylane/console/commands/api/delete_v2_load_balancers_load_balancer_id_forwarding_rules.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
if TYPE_CHECKING:
1414
from binarylane.client import Client
1515

16+
import binarylane.console.commands.api.get_v2_load_balancers as api_get_v2_load_balancers
1617
from binarylane.console.parser import ListAttribute, Mapping, PrimitiveAttribute
1718
from binarylane.console.runners.command import CommandRunner
1819

@@ -34,13 +35,18 @@ def reference_url(self) -> str:
3435
def create_mapping(self) -> Mapping:
3536
mapping = Mapping(CommandRequest)
3637

38+
def lookup_load_balancer_id(ref: str) -> Union[None, int]:
39+
return api_get_v2_load_balancers.Command(self._context).lookup(ref)
40+
3741
mapping.add(
3842
PrimitiveAttribute(
3943
"load_balancer_id",
4044
int,
4145
required=True,
4246
option_name=None,
43-
description="""The ID of the load balancer for which forwarding rules should be removed.""",
47+
metavar="load_balancer",
48+
description="""The ID or name of the load balancer for which forwarding rules should be removed.""",
49+
lookup=lookup_load_balancer_id,
4450
)
4551
)
4652

src/binarylane/console/commands/api/delete_v2_load_balancers_load_balancer_id_servers.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
if TYPE_CHECKING:
1212
from binarylane.client import Client
1313

14+
import binarylane.console.commands.api.get_v2_load_balancers as api_get_v2_load_balancers
1415
import binarylane.console.commands.api.get_v2_servers as api_get_v2_servers
1516
from binarylane.console.parser import Mapping, PrimitiveAttribute
1617
from binarylane.console.runners.command import CommandRunner
@@ -33,13 +34,18 @@ def reference_url(self) -> str:
3334
def create_mapping(self) -> Mapping:
3435
mapping = Mapping(CommandRequest)
3536

37+
def lookup_load_balancer_id(ref: str) -> Union[None, int]:
38+
return api_get_v2_load_balancers.Command(self._context).lookup(ref)
39+
3640
mapping.add(
3741
PrimitiveAttribute(
3842
"load_balancer_id",
3943
int,
4044
required=True,
4145
option_name=None,
42-
description="""The ID of the load balancer for which servers should be removed.""",
46+
metavar="load_balancer",
47+
description="""The ID or name of the load balancer for which servers should be removed.""",
48+
lookup=lookup_load_balancer_id,
4349
)
4450
)
4551

src/binarylane/console/commands/api/delete_v2_vpcs_vpc_id.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
if TYPE_CHECKING:
1010
from binarylane.client import Client
1111

12+
import binarylane.console.commands.api.get_v2_vpcs as api_get_v2_vpcs
1213
from binarylane.console.parser import Mapping, PrimitiveAttribute
1314
from binarylane.console.runners.command import CommandRunner
1415

@@ -28,13 +29,18 @@ def reference_url(self) -> str:
2829
def create_mapping(self) -> Mapping:
2930
mapping = Mapping(CommandRequest)
3031

32+
def lookup_vpc_id(ref: str) -> Union[None, int]:
33+
return api_get_v2_vpcs.Command(self._context).lookup(ref)
34+
3135
mapping.add(
3236
PrimitiveAttribute(
3337
"vpc_id",
3438
int,
3539
required=True,
3640
option_name=None,
37-
description="""The target vpc id.""",
41+
metavar="vpc",
42+
description="""The target vpc id or name.""",
43+
lookup=lookup_vpc_id,
3844
)
3945
)
4046

src/binarylane/console/commands/api/get_v2_load_balancers.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
from typing import TYPE_CHECKING, Any, Dict, List, Optional, Tuple, Union
55

66
from binarylane.api.load_balancers.get_v2_load_balancers import sync_detailed
7+
from binarylane.console.util import create_client
78
from binarylane.models.links import Links
89
from binarylane.models.load_balancers_response import LoadBalancersResponse
910

@@ -55,6 +56,18 @@ def fields(self) -> Dict[str, str]:
5556
"region": """The region the load balancer is located in. If this value is null the load balancer is an 'AnyCast' load balancer.""",
5657
}
5758

59+
def lookup(self, ref: str) -> Optional[int]:
60+
status_code, received = self.request(create_client(self._context), CommandRequest())
61+
if status_code != 200:
62+
super().response(status_code, received)
63+
64+
assert isinstance(received, LoadBalancersResponse)
65+
for item in received.load_balancers:
66+
if item.name == ref:
67+
return item.id
68+
else:
69+
return None
70+
5871
@property
5972
def reference_url(self) -> str:
6073
return "https://api.binarylane.com.au/reference/#tag/LoadBalancers/paths/~1v2~1load_balancers/get"

src/binarylane/console/commands/api/get_v2_load_balancers_load_balancer_id.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
if TYPE_CHECKING:
1111
from binarylane.client import Client
1212

13+
import binarylane.console.commands.api.get_v2_load_balancers as api_get_v2_load_balancers
1314
from binarylane.console.parser import Mapping, PrimitiveAttribute
1415
from binarylane.console.runners.command import CommandRunner
1516

@@ -29,13 +30,18 @@ def reference_url(self) -> str:
2930
def create_mapping(self) -> Mapping:
3031
mapping = Mapping(CommandRequest)
3132

33+
def lookup_load_balancer_id(ref: str) -> Union[None, int]:
34+
return api_get_v2_load_balancers.Command(self._context).lookup(ref)
35+
3236
mapping.add(
3337
PrimitiveAttribute(
3438
"load_balancer_id",
3539
int,
3640
required=True,
3741
option_name=None,
38-
description="""The ID of the load balancer to fetch.""",
42+
metavar="load_balancer",
43+
description="""The ID or name of the load balancer to fetch.""",
44+
lookup=lookup_load_balancer_id,
3945
)
4046
)
4147

src/binarylane/console/commands/api/get_v2_vpcs.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
from typing import TYPE_CHECKING, Any, Dict, List, Optional, Tuple, Union
55

66
from binarylane.api.vpcs.get_v2_vpcs import sync_detailed
7+
from binarylane.console.util import create_client
78
from binarylane.models.links import Links
89
from binarylane.models.vpcs_response import VpcsResponse
910

@@ -42,6 +43,18 @@ def fields(self) -> Dict[str, str]:
4243
"route_entries": """The route entries that control how network traffic is directed through the VPC environment.""",
4344
}
4445

46+
def lookup(self, ref: str) -> Optional[int]:
47+
status_code, received = self.request(create_client(self._context), CommandRequest())
48+
if status_code != 200:
49+
super().response(status_code, received)
50+
51+
assert isinstance(received, VpcsResponse)
52+
for item in received.vpcs:
53+
if item.name == ref:
54+
return item.id
55+
else:
56+
return None
57+
4558
@property
4659
def reference_url(self) -> str:
4760
return "https://api.binarylane.com.au/reference/#tag/Vpcs/paths/~1v2~1vpcs/get"

src/binarylane/console/commands/api/get_v2_vpcs_vpc_id.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
if TYPE_CHECKING:
1111
from binarylane.client import Client
1212

13+
import binarylane.console.commands.api.get_v2_vpcs as api_get_v2_vpcs
1314
from binarylane.console.parser import Mapping, PrimitiveAttribute
1415
from binarylane.console.runners.command import CommandRunner
1516

@@ -29,13 +30,18 @@ def reference_url(self) -> str:
2930
def create_mapping(self) -> Mapping:
3031
mapping = Mapping(CommandRequest)
3132

33+
def lookup_vpc_id(ref: str) -> Union[None, int]:
34+
return api_get_v2_vpcs.Command(self._context).lookup(ref)
35+
3236
mapping.add(
3337
PrimitiveAttribute(
3438
"vpc_id",
3539
int,
3640
required=True,
3741
option_name=None,
38-
description="""The target vpc id.""",
42+
metavar="vpc",
43+
description="""The target vpc id or name.""",
44+
lookup=lookup_vpc_id,
3945
)
4046
)
4147

src/binarylane/console/commands/api/get_v2_vpcs_vpc_id_members.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
if TYPE_CHECKING:
1414
from binarylane.client import Client
1515

16+
import binarylane.console.commands.api.get_v2_vpcs as api_get_v2_vpcs
1617
from binarylane.console.parser import Mapping, PrimitiveAttribute
1718
from binarylane.console.runners.list import ListRunner
1819

@@ -66,13 +67,18 @@ def reference_url(self) -> str:
6667
def create_mapping(self) -> Mapping:
6768
mapping = Mapping(CommandRequest)
6869

70+
def lookup_vpc_id(ref: str) -> Union[None, int]:
71+
return api_get_v2_vpcs.Command(self._context).lookup(ref)
72+
6973
mapping.add(
7074
PrimitiveAttribute(
7175
"vpc_id",
7276
int,
7377
required=True,
7478
option_name=None,
75-
description="""The target vpc id.""",
79+
metavar="vpc",
80+
description="""The target vpc id or name.""",
81+
lookup=lookup_vpc_id,
7682
)
7783
)
7884

src/binarylane/console/commands/api/patch_v2_vpcs_vpc_id.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
if TYPE_CHECKING:
1515
from binarylane.client import Client
1616

17+
import binarylane.console.commands.api.get_v2_vpcs as api_get_v2_vpcs
1718
from binarylane.console.parser import ListAttribute, Mapping, PrimitiveAttribute
1819
from binarylane.console.runners.command import CommandRunner
1920

@@ -35,13 +36,18 @@ def reference_url(self) -> str:
3536
def create_mapping(self) -> Mapping:
3637
mapping = Mapping(CommandRequest)
3738

39+
def lookup_vpc_id(ref: str) -> Union[None, int]:
40+
return api_get_v2_vpcs.Command(self._context).lookup(ref)
41+
3842
mapping.add(
3943
PrimitiveAttribute(
4044
"vpc_id",
4145
int,
4246
required=True,
4347
option_name=None,
44-
description="""The target vpc id.""",
48+
metavar="vpc",
49+
description="""The target vpc id or name.""",
50+
lookup=lookup_vpc_id,
4551
)
4652
)
4753

0 commit comments

Comments
 (0)