From 3ca08afd93067037705efcde2ac9318c29f07105 Mon Sep 17 00:00:00 2001 From: Mark Goddard Date: Thu, 16 Mar 2017 11:02:53 +0000 Subject: [PATCH] Add kayobe CLI command to configure the physical network Currently this can configure interfaces on DellOS6 switches only but can be extended to support other makes and models. --- ansible/group_vars/switches/dell | 15 +++++++++++++++ ansible/group_vars/switches/type | 7 +++++++ ansible/mgmt-switch-config.yml | 23 ----------------------- ansible/physical-network.yml | 26 ++++++++++++++++++++++++++ kayobe/cli/commands.py | 17 +++++++++++++++++ setup.py | 1 + 6 files changed, 66 insertions(+), 23 deletions(-) create mode 100644 ansible/group_vars/switches/dell create mode 100644 ansible/group_vars/switches/type delete mode 100644 ansible/mgmt-switch-config.yml create mode 100644 ansible/physical-network.yml diff --git a/ansible/group_vars/switches/dell b/ansible/group_vars/switches/dell new file mode 100644 index 000000000..760412acf --- /dev/null +++ b/ansible/group_vars/switches/dell @@ -0,0 +1,15 @@ +--- +# Switch configuration. + +############################################################################### +# Authentication configuration. + +# For DellOS6 switches, this defines a 'provider' argument to the dellos6_* +# modules. +switch_dellos6_provider: + host: "{{ ansible_host }}" + username: "{{ ansible_user }}" + password: "{{ ansible_ssh_pass }}" + transport: cli + authorize: yes + auth_pass: "{{ switch_auth_pass }}" diff --git a/ansible/group_vars/switches/type b/ansible/group_vars/switches/type new file mode 100644 index 000000000..5f0ea8d1d --- /dev/null +++ b/ansible/group_vars/switches/type @@ -0,0 +1,7 @@ +--- +############################################################################### +# Switch type configuration. + +# This configures the type of switch, which is used to determine how the switch +# will be configured. +switch_type: diff --git a/ansible/mgmt-switch-config.yml b/ansible/mgmt-switch-config.yml deleted file mode 100644 index a2fbe186e..000000000 --- a/ansible/mgmt-switch-config.yml +++ /dev/null @@ -1,23 +0,0 @@ ---- -- name: Ensure the power and management network switches are configured - hosts: mgmt-switches - gather_facts: no - vars: - provider: - host: "{{ ansible_host }}" - username: "{{ ansible_user }}" - password: "{{ ansible_ssh_pass }}" - transport: cli - authorize: yes - auth_pass: "{{ switch_auth_pass }}" - tasks: - - name: Ensure switch interfaces are configured - local_action: - module: dellos6_config - provider: "{{ provider }}" - lines: > - {{ ['description ' ~ item.value.description] + - item.value.config | default([]) }} - parents: - - "interface {{ item.key }}" - with_dict: "{{ switch_interface_config }}" diff --git a/ansible/physical-network.yml b/ansible/physical-network.yml new file mode 100644 index 000000000..1104515f3 --- /dev/null +++ b/ansible/physical-network.yml @@ -0,0 +1,26 @@ +--- +# Switch configuration depends on the type of switch, so groups hosts by their +# switch type and apply tasks/roles to the relevant groups. + +- name: Group hosts by their switch type + hosts: switches + gather_facts: no + tasks: + - name: Group hosts by their switch type + group_by: + key: "switches_of_type_{{ switch_type }}" + +- name: Ensure DellOS6 physical network devices are configured + hosts: switches_of_type_dellos6 + gather_facts: no + tasks: + - name: Ensure DellOS6 switch interfaces are configured + local_action: + module: dellos6_config + provider: "{{ switch_dellos6_provider }}" + lines: > + {{ ['description ' ~ item.value.description] + + item.value.config | default([]) }} + parents: + - "interface {{ item.key }}" + with_dict: "{{ switch_interface_config }}" diff --git a/kayobe/cli/commands.py b/kayobe/cli/commands.py index e41e18956..5148615b4 100644 --- a/kayobe/cli/commands.py +++ b/kayobe/cli/commands.py @@ -127,6 +127,23 @@ class KollaAnsibleRun(KollaAnsibleMixin, Command): parsed_args.kolla_inventory_filename) +class PhysicalNetworkConfigure(KayobeAnsibleMixin, Command): + """Configure a set of physical network devices.""" + + def get_parser(self, prog_name): + parser = super(PhysicalNetworkConfigure, self).get_parser( + prog_name) + group = parser.add_argument_group("Physical Networking") + group.add_argument("--group", required=True, + help="the Ansible group to apply configuration to") + return parser + + def take_action(self, parsed_args): + self.app.LOG.debug("Configuring a physical network") + ansible.run_playbook(parsed_args, "ansible/physical-network.yml", + limit=parsed_args.group) + + class SeedVMProvision(KollaAnsibleMixin, KayobeAnsibleMixin, Command): """Provision the seed VM.""" diff --git a/setup.py b/setup.py index f62b8b882..ed407c19c 100644 --- a/setup.py +++ b/setup.py @@ -44,6 +44,7 @@ setup( 'overcloud_inventory_discover = kayobe.cli.commands:OvercloudInventoryDiscover', 'overcloud_service_deploy = kayobe.cli.commands:OvercloudServiceDeploy', 'overcloud_provision = kayobe.cli.commands:OvercloudProvision', + 'physical_network_configure = kayobe.cli.commands:PhysicalNetworkConfigure', 'playbook_run = kayobe.cli.commands:PlaybookRun', 'seed_container_image_build = kayobe.cli.commands:SeedContainerImageBuild', 'seed_host_configure = kayobe.cli.commands:SeedHostConfigure',