72d72623a9
It wasn't working because of two reasons: 1. The packages filed in setup.cfg takes a directory name. so specifying tools.python_nsxadmin.admin didn't put the py files in /usr/local/lib/python2.7/dist-packages when we pip installed vmware-nsx package. (sudo pip install .). So changing it to tools installs all the code in tools including python_nsxadmin there. Read 2 to know why we need this. 2. To enable admin utility to dynamically pick up any hooks that users might add we use the importlib module. The bug was here, as the path was absolute tools/python_nsxadmin/.... So when we executed it from other diretory those modules were not imported. So I changed that to relative path. Though, over here there could be a case where the hooks location directory path contains a '-' / dash, which will cause it to fail. >>> import >>> home.gangil.t1-review.e_nsx.tools.python_nsxadmin.admin.plugins.nsxv.resources.edges File "<stdin>", line 1 import home.gangil.t1-review.vmware_nsx.tools.python_nsxadmin.admin.plugins.nsxv.resources.edges ^ SyntaxError: invalid syntax So we install the tools code using setup.cfg and then just import resources from there. Now it works from any directory. Change-Id: Idc414fabc769d0503974e8f77b84d32008b3c08a |
||
---|---|---|
.. | ||
admin | ||
README.rst | ||
__init__.py |
README.rst
Admin Utility
Introduction
Purpose of this script is to build a framework which can be leveraged to build utilities to help the on-field ops in system debugging.
Adding custom functions
Refer to the security groups example for reference implementation under, admin/plugins/nsx_v3/resources/securitygroups.py
Adding new functions is fairly straightforward:
- Define the function under appropriate package. We use neutron callbacks to provide hooks. So your function definition should be like,
- ::
-
def function(resource, event, trigger, **kwargs)
- Add the Resources and Operations enums if they don't exist.
- ::
-
- class Operations(object):
-
NEUTRON_CLEAN = 'neutron_clean'
- ::
-
- nsxv3_resources = {
-
constants.SECURITY_GROUPS: Resource(constants.SECURITY_GROUPS, ops)
}
- In resource.py, add the function to the callback registry.
- ::
-
- registry.subscribe(neutron_clean_security_groups,
-
Resources.SECURITY_GROUPS.value, Operations.NEUTRON_CLEAN.value)
- To test, do
- ::
-
cd python-nsxadmin/
sudo pip install -e .
nsxadmin -r <resource_name_you_added> -o <operation_you_added>
TODO
- Use Cliff
- Auto complete command line args.
Directory Structure
admin/
- plugins/
- common/
Contains code specific to different plugin versions.
- nsx_v3/
- resources/
Contains modules for various resources supported by the admin utility. These modules contains methods to perform operations on these resources.
Installation
- ::
-
sudo pip install -e .
Usage
- ::
-
nsxadmin -r <resource> -o <operation>
Example
- ::
-
$ nsxadmin -r security-groups -o list ==== [NSX] List Security Groups ==== Firewall Sections +------------------------------------------------+--------------------------------------+ | display_name | id | | default - 261343f8-4f35-4e57-9cc7-6c4fc7723b72 | 91a05fbd-054a-48b6-8e60-3b5d445be8c7 | | default - 823247b6-bdb3-47be-8bac-0d1114fc1ad7 | 78116d4a-de77-4a8f-b3e5-e76f458840ea | | OS default section for security-groups | 10a2fc6c-29c9-4d8d-ac2c-b24aafa15c79 | | Default Layer3 Section | e479e404-e712-4adb-879c-e432d510c056 | +------------------------------------------------+--------------------------------------+ Firewall NS Groups +------------------------------------------------+--------------------------------------+ | display_name | id | | NSGroup Container | c0b26e82-d49b-49f0-b68e-7449a59366e9 | | default - 261343f8-4f35-4e57-9cc7-6c4fc7723b72 | 2e5b5ca1-f687-4556-8130-9524b313474b | | default - 823247b6-bdb3-47be-8bac-0d1114fc1ad7 | b5cd9ae4-42b5-47a7-a1bf-9767ac62466e | +------------------------------------------------+--------------------------------------+ ==== [NEUTRON] List Security Groups ==== Security Groups +--------+------+ | name | id | +--------+------+
$ nsxadmin -r security-groups -o list -f json ==== [NSX] List Security Groups ==== { "Firewall Sections": [ { "display_name": "default - 261343f8-4f35-4e57-9cc7-6c4fc7723b72", "id": "91a05fbd-054a-48b6-8e60-3b5d445be8c7" }, { "display_name": "default - 823247b6-bdb3-47be-8bac-0d1114fc1ad7", "id": "78116d4a-de77-4a8f-b3e5-e76f458840ea" }, { "display_name": "OS default section for security-groups", "id": "10a2fc6c-29c9-4d8d-ac2c-b24aafa15c79" }, { "display_name": "Default Layer3 Section", "id": "e479e404-e712-4adb-879c-e432d510c056" } ] } { "Firewall NS Groups": [ { "display_name": "NSGroup Container", "id": "c0b26e82-d49b-49f0-b68e-7449a59366e9" }, { "display_name": "default - 261343f8-4f35-4e57-9cc7-6c4fc7723b72", "id": "2e5b5ca1-f687-4556-8130-9524b313474b" }, { "display_name": "default - 823247b6-bdb3-47be-8bac-0d1114fc1ad7", "id": "b5cd9ae4-42b5-47a7-a1bf-9767ac62466e" } ] } ==== [NEUTRON] List Security Groups ==== { "Security Groups": [] }
Help
- ::
-
$ nsxadmin --help