Package: arubafi
arubafiis a scalable and easy to use Python module capable of interfacing with some Aruba APIs (Mobility Master and AirWave for now).The module is intended for network reliability engineers that need to automate various tasks with regards to deployed, or soon to be deployed Aruba hardware or virtual appliances.(Documentation is still work in progress)Table Of ContentsInstallationUsage workflowMobility Master APICommunicating with the Mobility MasterUsing methods to get dataConfig levelFilteringDebuggingAirWave APIInstallationThe module can be pip installed withpip install arubafior probably usingpip3if having both Py2 and Py3 installed.The module is then imported withimportarubafibut it is suggested you import the module you need for a specific task.
For example if you need to work only with AirWave import just that, like sofromarubafiimportAirWaveUsage workflowThe usage workflow intended is:Create an object instance.Initiate communication with thecomms()method.Interface with the API with the provided methods.Mobility Master APIBelow is an explanation of to get up and running with the Mobility Master API (aka. Aruba OS8 for wireless)The minimum required for this option is to create an instance without any attributes like below.mmc=MMClient()In this case, after calling thecomms()method you are asked for the MM's FQDN, username and password.You can provide one or both when creating a new instance and be asked about the other once thecomms()method is run.You can also provide one or all required attributes at instantiation.mmc=MMClient(aw_username="theuser")There are various other parameters you can use with the instance object, like port, proxy, api version, etc. You can read more about them in the docstring.Communicating with the Mobility MasterYou must call thecomms()method on your instance, to setup the communication with your MM.aw=comms()Using methods to get dataFor getting the data from your MM, you use the resource methods or theresourcemethod itself. In either case you might need to pass in some arguments and for using theresourcemethod itself, you will definitely need to pass in at least the method and endpoint from which you want to retrieve data.The inbuilt resource methods begin their docsting withRMand are named as the endpoint as defined with Aruba API. For example, you use theap_group()method to get data about AP groups at a certainconfig_pathlevel from theconfiguration/object/ap_groupURI. These methods are pretty similar to theresourceone otherwise, but are here for easier (more human readable) interfacing with the API.Ex.: Comparison between resource methods and the resource method itselfThe below example shows that RMs use the resource() method with correct arguments passed in to GET or POST the data from an endpoint.>>>mm.ap_group()==mm.resource(method='GET',endpoint='configuration/object/ap_group')TrueEx: Basic getting of dataThe below will return all defined AP groups at the/mdconfig level.>>>mm.ap_group()"({'_data': {'ap_group': [{'profile-name': 'default', '_flags': ...."Config levelThe default config level (specified with theconfig_path) is/mdunless specified otherwise.mm.ap_group(config_path='/md/mylevel_A/mylevel_B')FilteringFilters are activated when passing in aprofile_nameargument. If specifying only that though the filter will default to$eq(equals), so theprofile_namemust match what you are looking for>>>mm.ap_group(profile_name='default')==mm.ap_group(profile_name='default',filter_oper='$eq')TrueYou can pass in afilter_operwith theprofile_nameif you wish to have a different search option or if passing in a partial search string.Ex. 1: partial search string with $inThis will return all profiles withdefin their profile-name.mm.ap_group(profile_name='def',filter_oper='$in')Ex. 2: partial search string with $ninThis will return all profiles thatdefis NOT in their profile-name.mm.ap_group(profile_name='def',filter_oper='$nin')You can even pass in the whole filter with thefilterargument if you so wish. If using that it will override whichever else you wanted to use as a filter, i.e. Theprofile_nameandfilter_operwill be ignored in this case, as in the end the previous examples construct the same string as the example below has passed into it, but whereas you can only look for profile names with theprofile_nameandfilter_oper, you can filter on anything else with thefilterparameter.Ex. 3: Passing in the whole filterThis will return all profiles thatdefis NOT in their profile-name.mm.ap_group(filter='[ {"ap_group.profile-name" : { "$eq" : ["default"] } } ]')For more information on how to use Aruba filters read the docstring and the associated Aruba API documentation.DebuggingThe default debug level isERROR, which can be changed per method call by preempting it withlogzero.loglevel(logging.LEVEL)whereLEVELis the logging level. Each method then resets logging toERROR, so you need to set logging level before each one.Ex. 1: DEBUG level>>>logzero.loglevel(logging.DEBUG)>>>mm.write_mem()[I20050321:38:12mmclient:506]Callingwrite_mem()[I20050321:38:12mmclient:237]Calling_params()[D20050321:38:12mmclient:281]Returnedparams:{'config_path':None,'UIDARUBA':'N2EyMDU5NGItZjRiYy00M2JhLWFjOTgtZWJk'}[I20050321:38:12mmclient:334]Calling_api_call()[I20050321:38:12mmclient:335]Methodis:POST[I20050321:38:12mmclient:336]SSLverify(Falseorcertpath):False[D20050321:38:12mmclient:340]FullURL:https://your_host:4343/v1/configuration/object/write_memory?UIDARUBA=N2EyMDU5NGItZjRiYy00M2JhLWFjOTgtZWJk[D20050321:38:12mmclient:346]ResponseJSON:{'write_memory':{'_result':{'status':0,'status_str':'Success'}},'_global_result':{'status':0,'status_str':'Success','_pending':False}}Ex. 2: INFO level>>>logzero.loglevel(logging.INFO)>>>mm.write_mem()[I20050321:39:22mmclient:506]Callingwrite_mem()[I20050321:39:22mmclient:237]Calling_params()[I20050321:39:22mmclient:334]Calling_api_call()[I20050321:39:22mmclient:335]Methodis:POST[I20050321:39:22mmclient:336]SSLverify(Falseorcertpath):FalseAirWave APIAirWaves API is quite different to what you could expect from a modern day one as it practically doesn't have any endpoints. There are about three available if not mistaken and only 2 of those are currently being used by this module, the/client_detail.xmland/ap_detail.xml.Note here that the returned data is in XML format, but that is handled by the module and for the resource methods data is retuned in JSON (dictionary) format. There is an option to get the data in the original XML format, with the use of the_full_raw_airwave_inventory()method with areturn_in_dictargument set toFalse, but it would be surprising if you'd need to use that at all.The very important thing to remember here is that once you want to access any of the resource methods that get you the required database from AW, likeget_controller_inventory(), which returns the database of the controller's id and it's FQDN mappings for example, ALL other databases are built as well. This is due to AW returning the whole DB of every element it holds when accessing the/ap_detail.xml, which can take tens of seconds to complete, depending on the number of elements in your AW and the hardware supporting it. Therefore it is much more efficient to build all DBs that the module returns at first call to any of theget_methods than for each one. Also due to this the AW class is made so that only one instance can be made in a script, so as to not overburden the AW with unnecessary calls.The minimum required for this option is to create an instance without any attributes like below.aw=AirWave()In this case, after calling thecomms()method you are asked for the AW's FQDN, username and password.You can provide one or both when creating a new instance and be asked about the other once thecomms()method is run.You can also provide one or all required attributes at instantiation.aw=AirWave(aw_username="theuser")Communicating with the Mobility MasterYou must call thecomms()method on your instance, to setup the communication with your MM.aw=comms()AdditionalThere are various other parameters you can use with the instance object, like port, proxy, api version, etc. You can read more about them in the docstring.##DebuggingThe default debug level isERROR, which can be changed per method call by preempting it withlogzero.loglevel(logging.LEVEL)whereLEVELis the logging level. Each method then resets logging toERROR, so you need to set logging level before each one.Ex. 1: DEBUG level>>>logzero.loglevel(logging.DEBUG)>>>mm._controller_inventory()Ex. 2: INFO level>>>logzero.loglevel(logging.INFO)>>>mm._controller_inventory()TODOThe general TODO list is:add more/all Aruba systemsadd mora/all API URIsContributingThank you for helping us developarubafi. We're happy to accept contribution of any kind. Feel free to submit feature requests and bug reports under Issues.Submitting a pull request guidelinesAll pull requests require a code review.Any merge conflicts need to be resolved.Include unit tests when you contribute new features and bugs, as they help to a) prove that your code works correctly, and b) guard against future breaking changes to lower the maintenance cost.All tests need to pass before we will review your PR.When you respond to changes based on comments from a code review, please reply with "Done." so that we get a notification.ContributorsBen CardyPrimoz Marinsek