code stringlengths 1 18.2k |
|---|
def delete_custom_view(auth, url, name): """ function takes input of auth, url, and name and issues a RESTFUL call to delete a specific of custom views from HPE IMC. :param name: string containg the name of the desired custom view :param auth: requests auth object #usually auth.creds from auth pyhpeimc.auth.class :para... |
creation results ( "view " + name + "created successfully" :rtype: str >>> from pyhpeimc.auth import * >>> from pyhpeimc.plat.groups import * >>> auth = IMCAuth("http://", "10.101.0.203", "8080", "admin", "admin") >>> delete_custom_view(auth.creds, auth.url, name = "L1 View") 'View L1 View deleted successfully' >>> vie... |
L2 View deleted successfully' >>> view_2 =get_custom_views( auth.creds, auth.url, name = 'L2 View') >>> assert view_2 == None """ view_id = get_custom_views(auth, url,name )[0]['symbolId'] delete_custom_view_url = '/imcrs/plat/res/view/custom/'+str(view_id) f_url = url + delete_custom_view_url r = requests.delete(f_url... |
e: return "Error:\n" + str(e) + ' delete_custom_view: An Error has occured' |
def multisplit(string, # type: unicode *separators, # type: unicode **kwargs # type: Union[unicode, C[..., I[unicode]]] ): # type: (...) -> I """ Like unicode.split, but accept several separators and regexes Args: string: the string to split. separators: strings you can split on. Each string can be a regex. maxsplit: m... |
flags: flags you wish to pass if you use regexes. You should pass them as a string containing a combination of: - 'm' for re.MULTILINE - 'x' for re.VERBOSE - 'v' for re.VERBOSE - 's' for re.DOTALL - '.' for re.DOTALL - 'd' for re.DEBUG - 'i' for re.IGNORECASE - 'u' for re.UNICODE - 'l' for re.LOCALE cast: what to cast ... |
Returns: An iterable of substrings. Raises: ValueError: if you pass a flag without separators. TypeError: if you pass something else than unicode strings. Example: >>> for word in multisplit(u'fat black cat, big'): print(word) fat black cat, big >>> string = u'a,b;c/d=a,b;c/d' >>> chunks = multisplit(string, u',', u';'... |
list) flags = parse_re_flags(kwargs.get('flags', 0)) # 0 means "no limit" for re.split maxsplit = require_positive_number(kwargs.get('maxsplit', 0), 'maxsplit') # no separator means we use the default unicode.split behavior if not separators: if flags: raise ValueError(ww.s >> """ You can't pass flags without passing a... |
limit" for unicode.split return unicode.split(string, None, maxsplit) # Check that all separators are strings for i, sep in enumerate(separators): if not isinstance(sep, unicode): raise TypeError(ww.s >> """ '{!r}', the separator at index '{}', is of type '{}'. multisplit() only accepts unicode strings. """.format(sep,... |
so we can slice it # simple code for when you need to split the whole string if maxsplit == 0: return cast(_split(string, seps, flags)) # slow implementation with checks for recursive maxsplit return cast(_split_with_max(string, seps, maxsplit, flags)) |
def multireplace(string, # type: unicode patterns, # type: str_or_str_iterable substitutions, # type: str_istr_icallable maxreplace=0, # type: int flags=0 # type: unicode ): # type: (...) -> bool """ Like unicode.replace() but accept several substitutions and regexes Args: string: the string to split on. patterns: a st... |
as a replacement. You can pass either one string, or an iterable containing the same number of sustitutions that you passed as patterns. You can also pass a callable instead of a string. It should expact a match object as a parameter. maxreplace: the max number of replacement to make. 0 is no limit, which is the defaul... |
if you use regexes. You should pass them as a string containing a combination of: - 'm' for re.MULTILINE - 'x' for re.VERBOSE - 'v' for re.VERBOSE - 's' for re.DOTALL - '.' for re.DOTALL - 'd' for re.DEBUG - 'i' for re.IGNORECASE - 'u' for re.UNICODE - 'l' for re.LOCALE Returns: The string with replaced bits. Raises: V... |
number of substitution. Example: >>> print(multireplace(u'a,b;c/d', (u',', u';', u'/'), u',')) a,b,c,d >>> print(multireplace(u'a1b33c-d', u'\d+', u',')) a,b,c-d >>> print(multireplace(u'a-1,b-3,3c-d', u',|-', u'', maxreplace=3)) a1b3,3c-d >>> def upper(match): ... return match.group().upper() ... >>> print(multireplac... |
# - many patterns, exactly as many substitutions # anything else is an error num_of_subs = len(substitutions) num_of_patterns = len(patterns) if num_of_subs == 1 and num_of_patterns > 0: substitutions *= num_of_patterns elif len(patterns) != num_of_subs: raise ValueError("You must have exactly one substitution " "for e... |
maxreplace: for pattern, sub in zip(patterns, substitutions): string, count = re.subn(pattern, sub, string, flags=flags) return string # ensure we respect the max number of replace accross substitutions for pattern, sub in zip(patterns, substitutions): string, count = re.subn(pattern, sub, string, count=maxreplace, fla... |
def status(): '''Show the manager's current status.''' with Session() as session: resp = session.Manager.status() print(tabulate([('Status', 'Active Sessions'), (resp['status'], resp['active_sessions'])], headers='firstrow')) |
def freeze(wait, force_kill): '''Freeze manager.''' if wait and force_kill: print('You cannot use both --wait and --force-kill options ' 'at the same time.', file=sys.stderr) return with Session() as session: if wait: while True: resp = session.Manager.status() active_sessions_num = resp['active_sessions'] if active_se... |
print_done('All sessions are killed.') print('Manager is successfully frozen.') |
def get_dev_vlans(auth, url, devid=None, devip=None): """Function takes input of devID to issue RESTUL call to HP IMC :param auth: requests auth object #usually auth.creds from auth pyhpeimc.auth.class :param url: base url of IMC RS interface #usually auth.url from pyhpeimc.auth.authclass :param devid: str requires dev... |
each element of the list represents one vlan on the target device :rtype: list >>> from pyhpeimc.auth import * >>> from pyhpeimc.plat.vlanm import * >>> auth = IMCAuth("http://", "10.101.0.203", "8080", "admin", "admin") >>> vlans = get_dev_vlans('350', auth.creds, auth.url) >>> assert type(vlans) is list >>> assert 'v... |
+ "&start=0&size=5000&total=false" f_url = url + get_dev_vlans_url response = requests.get(f_url, auth=auth, headers=HEADERS) try: if response.status_code == 200: dev_vlans = (json.loads(response.text)) return dev_vlans['vlan'] elif response.status_code == 409: return {'vlan': 'no vlans'} except requests.exceptions.Req... |
def get_trunk_interfaces(auth, url, devid=None, devip=None): """Function takes devId as input to RESTFULL call to HP IMC platform :param auth: requests auth object #usually auth.creds from auth pyhpeimc.auth.class :param url: base url of IMC RS interface #usually auth.url from pyhpeimc.auth.authclass :param devid: str ... |
element of the list represents an interface which has been configured as a VLAN trunk port :rtype: list >>> from pyhpeimc.auth import * >>> from pyhpeimc.plat.vlanm import * >>> auth = IMCAuth("http://", "10.101.0.203", "8080", "admin", "admin") >>> trunk_interfaces = get_trunk_interfaces('10', auth.creds, auth.url) >>... |
'pvid' in trunk_interfaces[0] >>> get_trunk_interfaces('350', auth.creds, auth.url) ['No trunk inteface'] """ if devip is not None: devid = get_dev_details(devip, auth, url)['id'] get_trunk_interfaces_url = "/imcrs/vlan/trunk?devId=" + str(devid) + \ "&start=1&size=5000&total=false" f_url = url + get_trunk_interfaces_u... |
["No trunk inteface"] return dev_trunk_interfaces['trunkIf'] except requests.exceptions.RequestException as error: return "Error:\n" + str(error) + ' get_trunk_interfaces: An Error has occured' |
def get_device_access_interfaces(auth, url, devid=None, devip=None): """ Function takes devid pr devip as input to RESTFUL call to HP IMC platform :param auth: requests auth object #usually auth.creds from auth pyhpeimc.auth.class :param url: base url of IMC RS interface #usually auth.url from pyhpeimc.auth.authclass :... |
dictionaries where each element of the list represents an interface which has been configured as a VLAN access port :rtype: list >>> from pyhpeimc.auth import * >>> from pyhpeimc.plat.vlanm import * >>> auth = IMCAuth("http://", "10.101.0.203", "8080", "admin", "admin") >>> access_interfaces = get_device_access_interfa... |
access_interfaces[0] """ if devip is not None: devid = get_dev_details(devip, auth, url)['id'] get_access_interface_vlan_url = "/imcrs/vlan/access?devId=" + str(devid) + \ "&start=1&size=500&total=false" f_url = url + get_access_interface_vlan_url response = requests.get(f_url, auth=auth, headers=HEADERS) try: if respo... |
+ str(error) + " get_device_access_interfaces: An Error has occured" |
def get_device_hybrid_interfaces(auth, url, devid=None, devip=None): """ Function takes devId as input to RESTFUL call to HP IMC platform :param auth: requests auth object #usually auth.creds from auth pyhpeimc.auth.class :param url: base url of IMC RS interface #usually auth.url from pyhpeimc.auth.authclass :param dev... |
each element of the list represents an interface which has been configured as a VLAN access port :rtype: list >>> from pyhpeimc.auth import * >>> from pyhpeimc.plat.vlanm import * >>> auth = IMCAuth("http://", "10.101.0.203", "8080", "admin", "admin") >>> hybrid_interfaces = get_device_hybrid_interfaces('10', auth.cred... |
if devip is not None: devid = get_dev_details(devip, auth, url)['id'] get_hybrid_interface_vlan_url = "/imcrs/vlan/hybrid?devId=" + str(devid) + \ "&start=1&size=500&total=false" f_url = url + get_hybrid_interface_vlan_url response = requests.get(f_url, auth=auth, headers=HEADERS) try: if response.status_code == 200: d... |
"Error:\n" + str(error) + " get_device_hybrid_interfaces: An Error has occured" |
def add_hybrid_interface(ifindex, pvid, taggedvlans, untaggedvlans, auth, url, devip=None, devid=None): """ Function takes ifindex, pvid, tagged vlans untagged vlans as input values to add a hybrid port to a HPE Comware based switch. These functions only apply to HPE Comware based devices. :param ifindex: str ifIndex v... |
by commas, of target tagged VLANs :param untaggedvlans: str 802.1q value, seperated by commas, of target untagged VLANs :param auth: requests auth object #usually auth.creds from auth pyhpeimc.auth.class :param url: base url of IMC RS interface #usually auth.url from pyhpeimc.auth.authclass :param devid: str requires d... |
code :rtype int """ if devip is not None: devid = get_dev_details(devip, auth, url)['id'] add_hybrid_interface_url = "/imcrs/vlan/hybrid?devId=" + str(devid) + \ "&start=1&size=500&total=false" f_url = url + add_hybrid_interface_url payload = '''{"ifIndex": "''' + ifindex + '''", "pvid": "''' + pvid + '''", "taggedVlan... |
response.status_code == 201: return 201 if response.status_code == 409: return 409 except requests.exceptions.RequestException as error: return "Error:\n" + str(error) + " get_device_hybrid_interfaces: An Error has occured" |
def delete_hybrid_interface(ifindex, auth, url, devip=None, devid=None): """ Function takes devip ( ipv4 address ), ifIndex and pvid (vlanid) of specific device and 802.1q VLAN tag and issues a RESTFUL call to remove the specified VLAN from the target device. :param ifindex: str value of ifIndex for a specific interfac... |
base url of IMC RS interface #usually auth.url from pyhpeimc.auth.authclass :param devid: str requires devid of the target device :param devip: str of ipv4 address of the target device :return: int of 204 if successful or 409 if not succesful :rtype: int >>> from pyhpeimc.auth import * >>> from pyhpeimc.plat.vlanm impo... |
devip='10.101.0.221') 409 >>> add_hybrid = add_hybrid_interface('9', '1', '10', '1', auth.creds, auth.url, devip='10.101.0.221') >>> delete_hybrid = delete_hybrid_interface('9', auth.creds, auth.url, devip='10.101.0.221') >>> assert type(delete_hybrid) is int >>> assert delete_hybrid == 204 """ if devip is not None: de... |
response.status_code == 409: return 409 except requests.exceptions.RequestException as error: return "Error:\n" + str(error) + " get_device_hybrid_interfaces: An Error has occured" |
def set_access_interface_pvid(ifindex, pvid, auth, url, devip=None, devid=None): """ Function takes devip ( ipv4 address ), ifIndex and pvid (vlanid) of specific device and 802.1q VLAN tag and issues a RESTFUL call to remove the specified VLAN from the target device. :param ifindex: str value of ifIndex for a specific ... |
the device :param auth: requests auth object #usually auth.creds from auth pyhpeimc.auth.class :param url: base url of IMC RS interface #usually auth.url from pyhpeimc.auth.authclass :param devid: str requires devid of the target device :param devip: str of ipv4 address of the target device :return: int of 204 if succe... |
import * >>> auth = IMCAuth("http://", "10.101.0.203", "8080", "admin", "admin") >>> set_access_int_vlan = set_access_interface_pvid('9', '1', auth.creds, auth.url, devip='10.101.0.221') >>> set_access_int_vlan = set_access_interface_pvid('9', '10', auth.creds, auth.url, devip='10.101.0.221') >>> assert type(set_access... |
\ + "&ifIndex=" + str(ifindex) f_url = url + set_access_interface_pvid_url response = requests.put(f_url, auth=auth, headers=HEADERS) try: if response.status_code == 204: return 204 if response.status_code == 409: return 409 except requests.exceptions.RequestException as error: return "Error:\n" + str(error) + " set_ac... |
def create_dev_vlan(vlanid, vlan_name, auth, url, devid=None, devip=None): """ function takes devid and vlanid vlan_name of specific device and 802.1q VLAN tag and issues a RESTFUL call to add the specified VLAN from the target device. VLAN Name MUST be valid on target device. :param vlanid:int or str value of target 8... |
valid name on target device. :param auth: requests auth object #usually auth.creds from auth pyhpeimc.auth.class :param url: base url of IMC RS interface #usually auth.url from pyhpeimc.auth.authclass :param devid: str requires devid of the target device :param devip: str of ipv4 address of the target device :return: s... |
>>> from pyhpeimc.plat.vlanm import * >>> auth = IMCAuth("http://", "10.101.0.203", "8080", "admin", "admin") >>> create_dev_vlan = create_dev_vlan('350', '200', 'test vlan', auth.creds, auth.url) """ if devip is not None: devid = get_dev_details(devip, auth, url)['id'] create_dev_vlan_url = "/imcrs/vlan?devId=" + str(... |
201 elif response.status_code == 409: print('''Unable to create VLAN.\nVLAN Already Exists\nDevice does not support VLAN function''') return 409 except requests.exceptions.RequestException as error: return "Error:\n" + str(error) + " create_dev_vlan: An Error has occured" |
def delete_dev_vlans(vlanid, auth, url, devid=None, devip=None): """ function takes devid and vlanid of specific device and 802.1q VLAN tag and issues a RESTFUL call to remove the specified VLAN from the target device. :param vlanid:int or str value of target 802.1q VLAN :param auth: requests auth object #usually auth.... |
:return: HTTP response object from requests library. Status code should be 204 if Successful :param devid: str requires devid of the target device :param devip: str of ipv4 address of the target device :rtype: requests.models.Response >>> from pyhpeimc.auth import * >>> from pyhpeimc.plat.vlanm import * >>> auth = IMCA... |
devip is not None: devid = get_dev_details(devip, auth, url)['id'] remove_dev_vlan_url = "/imcrs/vlan/delvlan?devId=" + str(devid) + "&vlanId=" + str(vlanid) f_url = url + remove_dev_vlan_url response = requests.delete(f_url, auth=auth, headers=HEADERS) try: if response.status_code == 204: print('Vlan deleted') return ... |
+ " delete_dev_vlans: An Error has occured" |
def _get_results_from_api(identifiers, endpoints, api_key, api_secret): """Use the HouseCanary API Python Client to access the API""" if api_key is not None and api_secret is not None: client = housecanary.ApiClient(api_key, api_secret) else: client = housecanary.ApiClient() wrapper = getattr(client, endpoints[0].split... |
def images(): ''' Show the list of registered images in this cluster. ''' fields = [ ('Name', 'name'), ('Registry', 'registry'), ('Tag', 'tag'), ('Digest', 'digest'), ('Size', 'size_bytes'), ('Aliases', 'aliases'), ] with Session() as session: try: items = session.Image.list(fields=(item[1] for item in fields)) except ... |
item in fields), floatfmt=',.0f')) |
def rescan_images(registry): '''Update the kernel image metadata from all configured docker registries.''' with Session() as session: try: result = session.Image.rescanImages(registry) except Exception as e: print_error(e) sys.exit(1) if result['ok']: print("kernel image metadata updated") else: print("rescanning faile... |
def alias_image(alias, target): '''Add an image alias.''' with Session() as session: try: result = session.Image.aliasImage(alias, target) except Exception as e: print_error(e) sys.exit(1) if result['ok']: print("alias {0} created for target {1}".format(alias, target)) else: print(result['msg']) |
def dealias_image(alias): '''Remove an image alias.''' with Session() as session: try: result = session.Image.dealiasImage(alias) except Exception as e: print_error(e) sys.exit(1) if result['ok']: print("alias {0} removed.".format(alias)) else: print(result['msg']) |
def run_alias(): """ Quick aliases for run command. """ mode = Path(sys.argv[0]).stem help = True if len(sys.argv) <= 1 else False if mode == 'lcc': sys.argv.insert(1, 'c') elif mode == 'lpython': sys.argv.insert(1, 'python') sys.argv.insert(1, 'run') if help: sys.argv.append('--help') main.main(prog_name='backend.ai') |
def get_dev_asset_details(ipaddress): """Takes in ipaddress as input to fetch device assett details from HP IMC RESTFUL API :param ipaddress: IP address of the device you wish to gather the asset details :return: object of type list containing the device asset details """ # checks to see if the imc credentials are alre... |
get_dev_asset_url = "/imcrs/netasset/asset?assetDevice.ip=" + str(ipaddress) f_url = url + get_dev_asset_url payload = None # creates the URL using the payload variable as the contents r = requests.get(f_url, auth=auth, headers=headers) # r.status_code if r.status_code == 200: dev_asset_info = (json.loads(r.text)) if l... |
dev.get('deviceIp') == ipaddress] return dev_asset_info else: print("get_dev_asset_details: An Error has occured") |
def get_serial_numbers(assetList): """ Helper function: Uses return of get_dev_asset_details function to evaluate to evaluate for multipe serial objects. :param assetList: output of get_dev_asset_details function :return: the serial_list object of list type which contains one or more dictionaries of the asset details "... |
def get_trunk_interfaces(devId): """Function takes devId as input to RESTFULL call to HP IMC platform :param devId: output of get_dev_details :return: list of dictionaries containing of interfaces configured as an 802.1q trunk """ # checks to see if the imc credentials are already available if auth is None or url is No... |
+ get_trunk_interfaces_url payload = None # creates the URL using the payload variable as the contents r = requests.get(f_url, auth=auth, headers=headers) # r.status_code if r.status_code == 200: dev_trunk_interfaces = (json.loads(r.text)) if len(dev_trunk_interfaces) == 2: return dev_trunk_interfaces['trunkIf'] else: ... |
def get_device_access_interfaces(devId): """Function takes devId as input to RESTFUL call to HP IMC platform :param devId: requires deviceID as the only input parameter :return: list of dictionaries containing interfaces configured as access ports """ # checks to see if the imc credentials are already available if auth... |
= url + get_access_interface_vlan_url payload = None # creates the URL using the payload variable as the contents r = requests.get(f_url, auth=auth, headers=headers) # r.status_code if r.status_code == 200: dev_access_interfaces = (json.loads(r.text)) if len(dev_access_interfaces) == 2: return dev_access_interfaces['ac... |
def get_dev_details(ip_address): """Takes string input of IP address to issue RESTUL call to HP IMC :param ip_address: string object of dotted decimal notation of IPv4 address :return: dictionary of device details >>> get_dev_details('10.101.0.1') {'symbolLevel': '2', 'typeName': 'Cisco 2811', 'location': 'changed this... |
'contact': 'changed this too', 'statusDesc': 'Normal', 'parentId': '1', 'categoryId': '0', 'topoIconName': 'iconroute', 'mac': '00:1b:d4:47:1e:68', 'devCategoryImgSrc': 'router', 'link': {'@rel': 'self', '@href': 'http://10.101.0.202:8080/imcrs/plat/res/device/30', '@op': 'GET'}, 'ip': '10.101.0.1'} >>> get_dev_details... |
f_url = url + get_dev_details_url payload = None # creates the URL using the payload variable as the contents r = requests.get(f_url, auth=auth, headers=headers) # r.status_code if r.status_code == 200: dev_details = (json.loads(r.text)) if len(dev_details) == 0: print("Device not found") return "Device not found" elif... |
dict: return dev_details['device'] else: print("dev_details: An Error has occured") |
def get_dev_vlans(devId): """Function takes input of devID to issue RESTUL call to HP IMC :param devId: requires devId as the only input parameter :return: list dictionaries of existing vlans on the devices. Device must be supported in HP IMC platform VLAN manager module """ # checks to see if the imc credentials are a... |
global r get_dev_vlans_url = "/imcrs/vlan?devId=" + str(devId) + "&start=0&size=5000&total=false" f_url = url + get_dev_vlans_url payload = None # creates the URL using the payload variable as the contents r = requests.get(f_url, auth=auth, headers=headers) # r.status_code if r.status_code == 200: dev_details = (json.l... |
def get_dev_interface(devid): """ Function takes devid as input to RESTFUL call to HP IMC platform :param devid: requires devid as the only input :return: list object which contains a dictionary per interface """ # checks to see if the imc credentials are already available if auth is None or url is None: set_imc_creds(... |
= url + get_dev_interface_url payload = None # creates the URL using the payload variable as the contents r = requests.get(f_url, auth=auth, headers=headers) # r.status_code if r.status_code == 200: int_list = (json.loads(r.text))['interface'] return int_list else: print("An Error has occured") |
def get_dev_run_config(devId): """ function takes the devId of a specific device and issues a RESTFUL call to get the most current running config file as known by the HP IMC Base Platform ICC module for the target device. :param devId: int or str value of the target device :return: str which contains the entire content... |
is not currently supported in the HP IMC Base Platform ICC module, this call returns a string of "This feature is not supported on this device" """ # checks to see if the imc credentials are already available if auth is None or url is None: set_imc_creds() global r get_dev_run_url = "/imcrs/icc/deviceCfg/" + str(devId)... |
# creates the URL using the payload variable as the contents r = requests.get(f_url, auth=auth, headers=headers) # print (r.status_code) if r.status_code == 200: run_conf = (json.loads(r.text))['content'] type(run_conf) if run_conf is None: return "This features is no supported on this device" else: return run_conf els... |
def get_dev_start_config(devId): """ function takes the devId of a specific device and issues a RESTFUL call to get the most current startup config file as known by the HP IMC Base Platform ICC module for the target device. :param devId: int or str value of the target device :return: str which contains the entire conte... |
is not currently supported in the HP IMC Base Platform ICC module, this call returns a string of "This feature is not supported on this device" """ # checks to see if the imc credentials are already available if auth is None or url is None: set_imc_creds() global r get_dev_run_url = "/imcrs/icc/deviceCfg/" + str(devId)... |
# creates the URL using the payload variable as the contents r = requests.get(f_url, auth=auth, headers=headers) if r.status_code == 200: start_conf = (json.loads(r.text))['content'] return start_conf else: # print (r.status_code) return "This feature is not supported on this device" |
def get_dev_alarms(devId): """ function takes the devId of a specific device and issues a RESTFUL call to get the current alarms for the target device. :param devId: int or str value of the target device :return:list of dictionaries containing the alarms for this device """ # checks to see if the imc credentials are al... |
set_imc_creds() global r get_dev_alarm_url = "/imcrs/fault/alarm?operatorName=admin&deviceId=" + \ str(devId) + "&desc=false" f_url = url + get_dev_alarm_url payload = None # creates the URL using the payload variable as the contents r = requests.get(f_url, auth=auth, headers=headers) if r.status_code == 200: dev_alarm... |
def get_real_time_locate(ipAddress): """ function takes the ipAddress of a specific host and issues a RESTFUL call to get the device and interface that the target host is currently connected to. :param ipAddress: str value valid IPv4 IP address :return: dictionary containing hostIp, devId, deviceIP, ifDesc, ifIndex """... |
already available set_imc_creds() real_time_locate_url = "/imcrs/res/access/realtimeLocate?type=2&value=" + str(ipAddress) + "&total=false" f_url = url + real_time_locate_url r = requests.get(f_url, auth=auth, headers=headers) # creates the URL using the payload variable as the contents if r.status_code == 200: return ... |
def get_ip_mac_arp_list(devId): """ function takes devid of specific device and issues a RESTFUL call to get the IP/MAC/ARP list from the target device. :param devId: int or str value of the target device. :return: list of dictionaries containing the IP/MAC/ARP list of the target device. """ if auth is None or url is N... |
available set_imc_creds() ip_mac_arp_list_url = "/imcrs/res/access/ipMacArp/" + str(devId) f_url = url + ip_mac_arp_list_url r = requests.get(f_url, auth=auth, headers=headers) # creates the URL using the payload variable as the contents if r.status_code == 200: macarplist = (json.loads(r.text)) if len(macarplist) > 1:... |
def get_custom_views(name=None): """ function takes no input and issues a RESTFUL call to get a list of custom views from HPE IMC. Optioanl Name input will return only the specified view. :param name: string containg the name of the desired custom view :return: list of dictionaries containing attributes of the custom v... |
see if the imc credentials are already available set_imc_creds() if name is None: get_custom_views_url = '/imcrs/plat/res/view/custom?resPrivilegeFilter=false&desc=false&total=false' elif name is not None: get_custom_views_url = '/imcrs/plat/res/view/custom?resPrivilegeFilter=false&name='+ name + '&desc=false&total=fal... |
else: return customviewlist else: print(r.status_code) print("An Error has occured") |
def create_custom_views(name=None, upperview=None): """ function takes no input and issues a RESTFUL call to get a list of custom views from HPE IMC. Optioanl Name input will return only the specified view. :param name: string containg the name of the desired custom view :return: list of dictionaries containing attribu... |
to see if the imc credentials are already available set_imc_creds() create_custom_views_url = '/imcrs/plat/res/view/custom?resPrivilegeFilter=false&desc=false&total=falsee' f_url = url + create_custom_views_url if upperview is None: payload = '''{ "name": "''' + name + '''", "upLevelSymbolId" : ""}''' else: parentviewi... |
as the contents if r.status_code == 201: return 'View ' + name +' created successfully' else: print(r.status_code) print("An Error has occured") |
def create_dev_vlan(devid, vlanid, vlan_name): """ function takes devid and vlanid vlan_name of specific device and 802.1q VLAN tag and issues a RESTFUL call to add the specified VLAN from the target device. VLAN Name MUST be valid on target device. :param devid: int or str value of the target device :param vlanid:int ... |
the target 802.1q VLAN name. MUST be valid name on target device. :return:HTTP Status code of 201 with no values. """ if auth is None or url is None: # checks to see if the imc credentials are already available set_imc_creds() create_dev_vlan_url = "/imcrs/vlan?devId=" + str(devid) f_url = url + create_dev_vlan_url pay... |
str(vlan_name) + '''"}''' r = requests.post(f_url, data=payload, auth=auth, headers=headers) # creates the URL using the payload variable as the contents print (r.status_code) if r.status_code == 201: print ('Vlan Created') return r.status_code elif r.status_code == 409: return '''Unable to create VLAN.\nVLAN Already E... |
def delete_dev_vlans(devid, vlanid): """ function takes devid and vlanid of specific device and 802.1q VLAN tag and issues a RESTFUL call to remove the specified VLAN from the target device. :param devid: int or str value of the target device :param vlanid: :return:HTTP Status code of 204 with no values. """ if auth is... |
the imc credentials are already available set_imc_creds() remove_dev_vlan_url = "/imcrs/vlan/delvlan?devId=" + str(devid) + "&vlanId=" + str(vlanid) f_url = url + remove_dev_vlan_url payload = None r = requests.delete(f_url, auth=auth, headers=headers) # creates the URL using the payload variable as the contents print ... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.