Skip to content

Commit a15fb27

Browse files
authored
Merge pull request #1862 from rackerlabs/handle-vlangroup-name
fix(undersync-switch): ensure input is URL encoded
2 parents 3a60c95 + 4ec10f6 commit a15fb27

File tree

4 files changed

+65
-26
lines changed

4 files changed

+65
-26
lines changed

charts/site-workflows/templates/sensor-ironic-port-delete.yaml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,11 +60,11 @@ spec:
6060
# defines the parameters being replaced above
6161
arguments:
6262
parameters:
63-
- name: vlan_group_uuid
63+
- name: physical_network
6464
- name: force
65-
value: false
65+
value: "false"
6666
- name: dry_run
67-
value: false
67+
value: "false"
6868
# references the workflow
6969
workflowTemplateRef:
7070
name: undersync-switch

python/understack-workflows/understack_workflows/main/undersync_switch.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,12 @@ def call_undersync(args):
2020
try:
2121
logger.debug(
2222
"Syncing switches in vlan group %s args.dry_run=%s args.force=%s",
23-
args.vlan_group_uuid,
23+
args.physical_network,
2424
args.dry_run,
2525
args.force,
2626
)
2727
return undersync.sync_devices(
28-
args.vlan_group_uuid,
28+
args.physical_network,
2929
dry_run=args.dry_run,
3030
force=args.force,
3131
)
@@ -40,10 +40,10 @@ def argument_parser():
4040
description="Trigger undersync run for a set of switches.",
4141
)
4242
parser.add_argument(
43-
"--vlan_group_uuid",
43+
"--physical-network",
4444
type=str,
4545
required=True,
46-
help="UUID of Nautobot VlanGroup containing the switches to Undersync",
46+
help="Port physical_network / Nautobot VLANGroup",
4747
)
4848
parser.add_argument(
4949
"--force",
Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
from functools import cached_property
2+
from urllib.parse import quote
23

34
import requests
45

@@ -13,13 +14,13 @@ def __init__(
1314
self.token = auth_token
1415
self.api_url = api_url
1516

16-
def sync_devices(self, vlan_group_uuid: str, force=False, dry_run=False):
17+
def sync_devices(self, physical_network: str, force=False, dry_run=False):
1718
if dry_run:
18-
return self.dry_run(vlan_group_uuid)
19+
return self.dry_run(physical_network)
1920
elif force:
20-
return self.force(vlan_group_uuid)
21+
return self.force(physical_network)
2122
else:
22-
return self.sync(vlan_group_uuid)
23+
return self.sync(physical_network)
2324

2425
@cached_property
2526
def client(self):
@@ -30,17 +31,20 @@ def client(self):
3031
}
3132
return session
3233

33-
def sync(self, uuids: str) -> requests.Response:
34-
response = self.client.post(f"{self.api_url}/v1/vlan-group/{uuids}/sync")
34+
def sync(self, physical_network: str) -> requests.Response:
35+
physnet = quote(physical_network, safe="")
36+
response = self.client.post(f"{self.api_url}/v1/vlan-group/{physnet}/sync")
3537
response.raise_for_status()
3638
return response
3739

38-
def dry_run(self, uuids: str) -> requests.Response:
39-
response = self.client.post(f"{self.api_url}/v1/vlan-group/{uuids}/dry-run")
40+
def dry_run(self, physical_network: str) -> requests.Response:
41+
physnet = quote(physical_network, safe="")
42+
response = self.client.post(f"{self.api_url}/v1/vlan-group/{physnet}/dry-run")
4043
response.raise_for_status()
4144
return response
4245

43-
def force(self, uuids: str) -> requests.Response:
44-
response = self.client.post(f"{self.api_url}/v1/vlan-group/{uuids}/force")
46+
def force(self, physical_network: str) -> requests.Response:
47+
physnet = quote(physical_network, safe="")
48+
response = self.client.post(f"{self.api_url}/v1/vlan-group/{physnet}/force")
4549
response.raise_for_status()
4650
return response

workflows/argo-events/workflowtemplates/undersync-switch.yaml

Lines changed: 44 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,24 +4,64 @@ metadata:
44
annotations:
55
workflows.argoproj.io/title: Requests an Undersync run on a pair of switches
66
workflows.argoproj.io/description: |
7+
Requests an Undersync run for a switch pair identified by `physical_network`.
8+
9+
Parameters:
10+
11+
- `physical_network`: required switch pair / physical network identifier
12+
- `force`: push non-safe changes, without this config drift in non-safe areas won't apply
13+
- `dry_run`: show the intended changes without applying them
14+
15+
To test this workflow you can run it with the following:
16+
17+
```
18+
argo -n argo-events submit --from workflowtemplate/undersync-switch \
19+
-p physical_network=physnet1 -p force=false -p dry_run=false
20+
```
21+
722
Defined in `workflows/argo-events/workflowtemplates/undersync-switch.yaml`
823
kind: WorkflowTemplate
924
spec:
1025
entrypoint: undersync-switch
1126
serviceAccountName: workflow
27+
arguments:
28+
parameters:
29+
- name: physical_network
30+
description: Name of the physical_network (a.k.a. VLAN Group, e.g. "a1-1-network"), tells Undersync which switch pair to configure.
31+
- name: force
32+
description: |
33+
Override safety guardrails when "Change requires approval"
34+
When force=true it disables undersync safety features that would otherwise guard against taking the switch offline, guard against operating on the wrong switch (e.g. DNS snafu), allow the NOC to suspend operations, etc.
35+
When the guardrails are preventing a change from being pushed to the switch, undersync will respond with an error that includes a status like "Change requires approval".
36+
This parameter should never be needed in normal operations.
37+
default: "false"
38+
enum:
39+
- "true"
40+
- "false"
41+
- name: dry_run
42+
description: Preview the changes without making any updates.
43+
default: "false"
44+
enum:
45+
- "true"
46+
- "false"
1247
templates:
1348
- name: undersync-switch
49+
inputs:
50+
parameters:
51+
- name: physical_network
52+
- name: force
53+
- name: dry_run
1454
container:
1555
image: ghcr.io/rackerlabs/understack/ironic-nautobot-client:latest
1656
command:
1757
- undersync-switch
1858
args:
19-
- --vlan_group_uuid
20-
- "{{workflow.parameters.vlan_group_uuid}}"
59+
- --physical-network
60+
- "{{inputs.parameters.physical_network}}"
2161
- --dry-run
22-
- "{{workflow.parameters.dry_run}}"
62+
- "{{inputs.parameters.dry_run}}"
2363
- --force
24-
- "{{workflow.parameters.force}}"
64+
- "{{inputs.parameters.force}}"
2565
volumeMounts:
2666
- mountPath: /etc/nb-token/
2767
name: nb-token
@@ -35,11 +75,6 @@ spec:
3575
secretKeyRef:
3676
name: nautobot-token
3777
key: url
38-
inputs:
39-
parameters:
40-
- name: vlan_group_uuid
41-
- name: force
42-
- name: dry_run
4378
volumes:
4479
- name: nb-token
4580
secret:

0 commit comments

Comments
 (0)