-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
feat: update nautobot with minimal chassis info
- Loading branch information
Showing
5 changed files
with
120 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
49 changes: 49 additions & 0 deletions
49
python/understack-workflows/understack_workflows/main/sync_nautobot_system_info.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
import argparse | ||
import os | ||
from uuid import UUID | ||
|
||
from understack_workflows.helpers import credential | ||
from understack_workflows.helpers import oob_sushy_session | ||
from understack_workflows.helpers import parser_nautobot_args | ||
from understack_workflows.helpers import setup_logger | ||
from understack_workflows.models import Chassis | ||
from understack_workflows.nautobot import Nautobot | ||
|
||
logger = setup_logger(__name__) | ||
|
||
|
||
def argument_parser(name): | ||
parser = argparse.ArgumentParser( | ||
prog=os.path.basename(name), description="Nautobot Interface sync" | ||
) | ||
parser.add_argument( | ||
"--device-id", type=UUID, required=True, help="Nautobot device ID" | ||
) | ||
parser.add_argument("--bmc_username", required=False, help="BMC username") | ||
parser.add_argument("--bmc_password", required=False, help="BMC password") | ||
parser = parser_nautobot_args(parser) | ||
return parser | ||
|
||
|
||
def do_sync(device_id: UUID, nautobot: Nautobot, bmc_user: str, bmc_pass: str): | ||
bmc_ip = nautobot.device_oob_ip(device_id) | ||
bmc_obj = oob_sushy_session(bmc_ip, bmc_user, bmc_pass) | ||
|
||
chassis = Chassis.from_redfish(bmc_obj) | ||
nautobot.update_system_info(device_id, chassis.system_info) | ||
|
||
|
||
def main(): | ||
parser = argument_parser(__file__) | ||
args = parser.parse_args() | ||
|
||
nb_token = args.nautobot_token or credential("nb-token", "token") | ||
bmc_user = args.oob_username or credential("bmc-secrets", "username") | ||
bmc_pass = args.oob_password or credential("bmc-secrets", "password") | ||
nautobot = Nautobot(args.nautobot_url, nb_token, logger=logger) | ||
|
||
do_sync(args.device_id, nautobot, bmc_user, bmc_pass) | ||
|
||
|
||
if __name__ == "__main__": | ||
main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
39 changes: 39 additions & 0 deletions
39
workflows/argo-events/workflowtemplates/sync-system-info-to-nautobot.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
apiVersion: argoproj.io/v1alpha1 | ||
metadata: | ||
name: sync-system-info-to-nautobot | ||
annotations: | ||
workflows.argoproj.io/title: Sync Redfish system info (serial number, service tag, model name) data to Nautobot | ||
workflows.argoproj.io/description: | | ||
Defined in `workflows/argo-events/workflowtemplates/sync-system-info-to-nautobot.yaml` | ||
kind: WorkflowTemplate | ||
spec: | ||
arguments: | ||
parameters: | ||
- name: device_id | ||
value: "{}" | ||
- name: bmc_secret | ||
value: "{}" | ||
templates: | ||
- name: sync-system-info | ||
container: | ||
image: ghcr.io/rackerlabs/understack/ironic-nautobot-client:latest | ||
command: | ||
- sync-nautobot-system-info | ||
args: ["--device-id", "{{workflow.parameters.device_id}}"] | ||
volumeMounts: | ||
- mountPath: /etc/nb-token/ | ||
name: nb-token | ||
readOnly: true | ||
- mountPath: /etc/bmc-secrets/ | ||
name: bmc-secrets | ||
readOnly: true | ||
inputs: | ||
parameters: | ||
- name: bmc_secret | ||
volumes: | ||
- name: nb-token | ||
secret: | ||
secretName: nautobot-token | ||
- name: bmc-secrets | ||
secret: | ||
secretName: "{{inputs.parameters.bmc_secret}}" |