Skip to content

Commit

Permalink
Make --cloud be optional and alert on mismatch
Browse files Browse the repository at this point in the history
1.  make the use if --cloud not be mandatory.
    However if --cloud is omitted on place of --host,
    we should be able to calculate the cloud object
    based on the hostname provided.

2.  if BOTH --host and --cloud are specified, we should
    do some checking to make sure the target host is actually
    a member of the target cloud.

Under rare circumstances the user may want to reconfigure the
switch ports associated with host and place the host into the
vlans associated with an arbitrary cloud. However this is a rare
corner case. In the case where the user specifies both cloud and
host, and the cloud does not match the associated cloud of the
target host, the user should be alerted with output on the screen
to alert them that there is a possible unintentional mismatch.

Fixes: #378
Change-Id: I9aa804ebcdeaec97b31d7b0de000d8101c7d225d
  • Loading branch information
kambiz-aghaiepour committed May 18, 2021
1 parent 6fb0513 commit ec973d6
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 2 deletions.
24 changes: 24 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -887,6 +887,30 @@ Resource properly removed
/opt/quads/quads/tools/verify_switchconf.py --host host01.example.com
```

* To validate and fix a single hosts network config use `--change`

```
/opt/quads/quads/tools/verify_switchconf.py --host host01.example.com --change
```

* To straddle clouds and place a single host into a cloud it does not belong in (rare use case):
```
/opt/quads/quads/tools/verify_switchconf.py --host host01.example.com --cloud cloud10
```

Note, if host01.example.com is not in cloud10, but rather cloud20, you will see the following output:
```
WARNING - Both --cloud and --host have been specified.
WARNING -
WARNING - Host: host01.example.com
WARNING - Cloud: cloud10
WARNING -
WARNING - However, host01.example.com is a member of cloud20
WARNING -
WARNING - !!!!! Be certain this is what you want to do. !!!!!
WARNING -
```

### Modify or check a specific Host Network Switch Settings
* With the `modify_switch_conf.py` tool you can set up each individual network interface to a specific vlan id.
* Passing the `--change` argument will make the changes effective in the switch. Not passing this will only verify the configuration is set to the desired.
Expand Down
27 changes: 25 additions & 2 deletions quads/tools/verify_switchconf.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,35 @@


def verify(_cloud_name, _host_name, change=False):
_cloud_obj = Cloud.objects(name=_cloud_name).first()
if _cloud_name == None and _host_name == None:
logger.warning(f"At least one of --cloud or --host should be specified.")
return

if _cloud_name:
_cloud_obj = Cloud.objects(name=_cloud_name).first()
else:
_cloud_obj = None

if _host_name:
hosts = Host.objects(name=_host_name)
_host_cloud_obj = hosts.first().cloud
else:
hosts = Host.objects(cloud=_cloud_obj)
_host_cloud_obj = None

if _cloud_obj == None:
_cloud_obj = _host_cloud_obj

if _cloud_obj != _host_cloud_obj:
logger.warning(f"Both --cloud and --host have been specified.")
logger.warning(f"")
logger.warning(f"Host: {hosts.first().name}")
logger.warning(f"Cloud: {_cloud_obj.name}")
logger.warning(f"")
logger.warning(f"However, {hosts.first().name} is a member of {_host_cloud_obj.name}")
logger.warning(f"")
logger.warning(f"!!!!! Be certain this is what you want to do. !!!!!")
logger.warning(f"")

for _host_obj in hosts:
logger.info(f"Host: {_host_obj.name}")
Expand Down Expand Up @@ -117,7 +141,6 @@ def verify(_cloud_name, _host_name, change=False):
dest="cloud",
type=str,
default=None,
required=True,
help="Cloud name to verify switch configuration for.",
)
parser.add_argument(
Expand Down

0 comments on commit ec973d6

Please sign in to comment.