When writing python modules it is useful to ensure the help function in Python can add some value
For exmaple if you go to the Python interperator and issue the help function on the module you will get usful output;
β robedwa@ROBEDWA-M-800R:~ python:βΉsystem: 2.7.10βΊ
β° β€ python
Python 2.7.10 (default, Sep 23 2015, 04:34:21)
[GCC 4.2.1 Compatible Apple LLVM 7.0.0 (clang-700.0.72)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import cecs
>>> help(cecs)
Help on package cecs:
NAME
cecs
FILE
/Users/robedwa/Documents/Development/Projects/UCSD/Python/cecs/cecs/__init__.py
DESCRIPTION
Python module of different functions for manipulating UCS Director
via the API.
PACKAGE CONTENTS
command_line
icfDevelopment
menu stuff
obtain_credentials
tests (package)
FUNCTIONS
CreateVDC(env, APIVDCDetails)
Creates a vDC defined by the provided data.
:param: APIVDCDetails
:return: boolean
ExportVDC(env, vdcName)
Exports a vDC.
:param vdcName: Name of the vDC that you want to export
:return: String
GetAllVDCs(env)
Returns all VDCs for the logged-in user group
:param None
:return: APITabularReport
GetCatalog(env, group='all')
Returns the catalogs for the specified user group or all groups.
:param: GroupName
:return: APITabularReport
GetCatalogDetail(env, catalog)
GetCloudSummary(env, icfCloudId)
Returns the details of the Cisco Intercloud Fabric clouds that match the specified cloud identifier.
:param icfCloudId: Cisco Intercloud Fabric cloud identifier.
:return: APITabularReport
GetClouds(env)
Returns a list of all Cisco Intercloud Fabric clouds.
:param: None
:return: APITabularReport
GetIconURL(imageId)
Returns the icon image URL of the specified icon identifier. Only ICF API!
:param: imageId
:return: FormLOVPair[]
GetMgmtPortProfiles(env, vmManager, dataCenter)
Returns a list of all management port profiles for the specified VM Manager and data center.
:param vmManager: VM Manager identifier.
:param dataCenter: Data center identifier.
:return: APITabularReport
GetResIP(env)
Returns a list of all reserved IP addresses.
:param None
:return: APITabularReport
GetStaticIPPool(env)
Returns a list of all static IP address pools.
:param id
:return: APITabularReport
GetStaticIPPoolPolicies(env)
Returns a list of all static IP address pool policies.
:param None
:return: APITabularReport
GetTunnelProfiles(env)
Returns a list of all tunnel profiles.
:param: None
:return: APITabularReport
GetVMvNics(env, vmId)
Returns a list of the vNICs configured on the specified VM.
:param vmId: VM identifier available from the VM report screen.
:return: APITabularReport
GetWorkflowInput(env, name)
GetWorkflowInputDetail(env, name)
GetvCenter(env, vCenterAccountName)
Returns a list of all VMware vCenter servers or of all data centers that match the VMware vCenter account name.
:param: None or vCenterAccountName
:return: APITabularReport
ImportVDC(env, vdcName)
Imports a vDC.
:param vdcName: Name of the vDC that you want to import
:return: VDC
VMNameToID(env, vm_name)
Will return the 'vmid' when the VM Name is passed. Currently on UCSD but will be expanded to ICF
:param api: The specific API call required
:param: VM_Name
:return: vmid
apiCall(env, api, param0=None, param1=None, param2=None, param3=None, param4=None)
Craetes the URL format to make the call to UCS Director or Intercloud Fabric
Rest API. This is a hacked way to achieve overloading
:param env: Specify if the API call should be against UCSD or ICFB
:param api: The specific API call required
:param param0: The initial parameter required to create the request structure
:param param1: The 2nd if required
:param param2: The 3rd if required
:return: JSON response from API call
getAllVMs(env)
group_name(name)
obtain_apikey(env, username, password)
Return the API Key
:param :
:return:
report_tabular(group, report)
#################### Reports ###################################################
Help on package cecs:
NAME
cecs
FILE
/Users/robedwa/Documents/Development/Projects/UCSD/Python/cecs/cecs/__init__.py
DESCRIPTION
Python module of different functions for manipulating UCS Director
via the API.
PACKAGE CONTENTS
command_line
icfDevelopment
menu stuff
obtain_credentials
tests (package)
FUNCTIONS
CreateVDC(env, APIVDCDetails)
Creates a vDC defined by the provided data.
:param: APIVDCDetails
:return: boolean
ExportVDC(env, vdcName)
Exports a vDC.
:param vdcName: Name of the vDC that you want to export
:return: String
GetAllVDCs(env)
Returns all VDCs for the logged-in user group
:param None
:return: APITabularReport
GetCatalog(env, group='all')
Returns the catalogs for the specified user group or all groups.
:param: GroupName
:return: APITabularReport
GetCatalogDetail(env, catalog)
GetCloudSummary(env, icfCloudId)
Returns the details of the Cisco Intercloud Fabric clouds that match the specified cloud identifier.
:param icfCloudId: Cisco Intercloud Fabric cloud identifier.
:return: APITabularReport
GetClouds(env)
Returns a list of all Cisco Intercloud Fabric clouds.
:param: None
:return: APITabularReport
GetIconURL(imageId)
Returns the icon image URL of the specified icon identifier. Only ICF API!
:param: imageId
:return: FormLOVPair[]
GetMgmtPortProfiles(env, vmManager, dataCenter)
Returns a list of all management port profiles for the specified VM Manager and data center.
:param vmManager: VM Manager identifier.
:param dataCenter: Data center identifier.
:return: APITabularReport
GetResIP(env)
Returns a list of all reserved IP addresses.
:param None
:return: APITabularReport
GetStaticIPPool(env)
Returns a list of all static IP address pools.
:param id
:return: APITabularReport
GetStaticIPPoolPolicies(env)
Returns a list of all static IP address pool policies.
:param None
:return: APITabularReport
GetTunnelProfiles(env)
Returns a list of all tunnel profiles.
:param: None
:return: APITabularReport
GetVMvNics(env, vmId)
Returns a list of the vNICs configured on the specified VM.
:param vmId: VM identifier available from the VM report screen.
:return: APITabularReport
GetWorkflowInput(env, name)
GetWorkflowInputDetail(env, name)
GetvCenter(env, vCenterAccountName)
Returns a list of all VMware vCenter servers or of all data centers that match the VMware vCenter account name.
:param: None or vCenterAccountName
:return: APITabularReport
ImportVDC(env, vdcName)
Imports a vDC.
:param vdcName: Name of the vDC that you want to import
:return: VDC
VMNameToID(env, vm_name)
Will return the 'vmid' when the VM Name is passed. Currently on UCSD but will be expanded to ICF
:param api: The specific API call required
:param: VM_Name
:return: vmid
apiCall(env, api, param0=None, param1=None, param2=None, param3=None, param4=None)
Craetes the URL format to make the call to UCS Director or Intercloud Fabric
Rest API. This is a hacked way to achieve overloading
:param env: Specify if the API call should be against UCSD or ICFB
:param api: The specific API call required
:param param0: The initial parameter required to create the request structure
:param param1: The 2nd if required
:param param2: The 3rd if required
:return: JSON response from API call
getAllVMs(env)
group_name(name)
obtain_apikey(env, username, password)
Return the API Key
:param :
:return:
report_tabular(group, report)
#################### Reports ###################################################
sr_details(srnumber)
Return the details of the Service Request Specified - Workflow Based Only
:param srnumber: The Service Request ID
:return: JSON of the SR Status
sr_get(env)
Return the service request for the logged in user (Both UCSD & ICFB)
:return: APITabularReport (JSON)
sr_log(srnumber, severity)
Return the logs from the specified Service Request
:param srnumber: The Service Request ID
:param severity: Log severity (debug, info, warning, error)
:return: JSON of the logs
ucsdCall(api, param0=None, param1=None, param2=None, param3=None, param4=None)
NOTE: This is deprecated and will be removed once all functions have been migrated!
Craetes the URL format to make the call to UCS Director Rest API.
This is a hacked version of overloading (not sure how else to achieve)
:param api: The specific API call required
:param param0: The initial parameter required to create the request structure
:return: JSON response (in Python dictionary) from API call
version(env)
Return the version of the application
:param env: The server that requires querying (ucsd or icfb)
:return: FQDN: <version number>
vm_action(env, vm_name, action, comment)
This will alter the status (on, off etc.) of a VM. It has to work out the
vmid based on the VM name that is passed.
DATA
Version = '0.1.12'
__version__ = '0.1.12'
config = ConfigObj({'UCSD': {'apikey': 'B01BB65B70EB481C9...A98033922'...
filename = '/Users/robedwa/.cecs.cfg'
getstring = 'formatType=json&opName=%s'
headers = {'X-Cloupia-Request-Key': ' '}
home = '/Users/robedwa'
icfb_key = '6B75494C86E041CDA4AA390A98033922'
icfb_section = {'apikey': '6B75494C86E041CDA4AA390A98033922', 'hostnam...
icfbserver = 'sandboxicf.cisco.com'
parameter_lead = '&opData='
ucsd_key = 'B01BB65B70EB481C9D8184055FD59B58'
ucsd_section = {'apikey': 'B01BB65B70EB481C9D8184055FD59B58', 'hostnam...
ucsdserver = 'infrastructure.ukidcv.cisco.com'
url = 'https://%s/app/api/rest?'
VERSION
0.1.12
>>> dir(cecs)
['ConfigObj', 'CreateVDC', 'ExportVDC', 'GetAllVDCs', 'GetCatalog', 'GetCatalogDetail', 'GetCloudSummary', 'GetClouds', 'GetIconURL', 'GetMgmtPortProfiles', 'GetResIP', 'GetStaticIPPool', 'GetStaticIPPoolPolicies', 'GetTunnelProfiles', 'GetVMvNics', 'GetWorkflowInput', 'GetWorkflowInputDetail', 'GetvCenter', 'ImportVDC', 'VMNameToID', 'Version', '__builtins__', '__doc__', '__file__', '__name__', '__package__', '__path__', '__version__', 'apiCall', 'config', 'expanduser', 'filename', 'getAllVMs', 'getstring', 'group_name', 'headers', 'home', 'icfb_key', 'icfb_section', 'icfbserver', 'json', 'obtain_apikey', 'parameter_lead', 'report_tabular', 'requests', 'sr_details', 'sr_get', 'sr_log', 'ucsdCall', 'ucsd_key', 'ucsd_section', 'ucsdserver', 'url', 'version', 'vm_action']
>>>