code stringlengths 1 18.2k |
|---|
def get_dev_vlans(devid, auth, url): """Function takes input of devID to issue RESTUL call to HP IMC :param devid: requires devId as the only input parameter :return: dictionary of existing vlans on the devices. Device must be supported in HP IMC platform VLAN manager module """ # checks to see if the imc credentials a... |
= url + get_dev_vlans_url # creates the URL using the payload variable as the contents r = requests.get(f_url, auth=auth, headers=HEADERS) # r.status_code try: if r.status_code == 200: dev_vlans = (json.loads(r.text)) return dev_vlans['vlan'] elif r.status_code == 409: return {'vlan': 'no vlans'} except requests.except... |
def get_trunk_interfaces(devId, auth, url): """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 Example: auth = IMCAuth("http://", "10.101.0.203", "8080", "admin", "admin") get_d... |
= url + get_trunk_interfaces_url r = requests.get(f_url, auth=auth, headers=HEADERS) # r.status_code try: if r.status_code == 200: dev_trunk_interfaces = (json.loads(r.text)) if len(dev_trunk_interfaces) == 2: return dev_trunk_interfaces['trunkIf'] else: dev_trunk_interfaces['trunkIf'] = ["No trunk inteface"] return de... |
def get_device_access_interfaces(devId, auth, url): """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 availa... |
the URL using the payload variable as the contents r = requests.get(f_url, auth=auth, headers=HEADERS) # r.status_code try: if r.status_code == 200: dev_access_interfaces = (json.loads(r.text)) if len(dev_access_interfaces) == 2: return dev_access_interfaces['accessIf'] else: dev_access_interfaces['accessIf'] = ["No ac... |
def create_dev_vlan(devid, vlanid, vlan_name, auth, url): """ 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 ... |
value of the target 802.1q VLAN name. MUST be valid name on target device. :return:HTTP Status code of 201 with no values. """ create_dev_vlan_url = "/imcrs/vlan?devId=" + str(devid) f_url = url + create_dev_vlan_url payload = '''{ "vlanId": "''' + str(vlanid) + '''", "vlanName" : "''' + str(vlan_name) + '''"}''' r = r... |
the contents return r try: if r.status_code == 201: print ('Vlan Created') return r.status_code elif r.status_code == 409: return '''Unable to create VLAN.\nVLAN Already Exists\nDevice does not support VLAN function''' except requests.exceptions.RequestException as e: return "Error:\n" + str(e) + " create_dev_vlan: An ... |
def delete_dev_vlans(devid, vlanid, auth, url): """ 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. """... |
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 try: if r.status_code == 204: print ('Vlan deleted') return r.status_code elif r.status_code == 409: print ('Unable to delete VLAN.\nVLAN does not Exist\nDevice do... |
has occured" |
def create_operator(operator, auth, url): """ Function takes input of dictionary operator with the following keys operator = { "fullName" : "" , "sessionTimeout" : "", "password" : "", "operatorGroupId" : "", "name" : "", "desc" : "", "defaultAcl" : "", "authType" : ""} converts to json and issues a HTTP POST request t... |
auth.creds from auth pyhpeimc.auth.class :param url: base url of IMC RS interface #usually auth.url from pyhpeimc.auth.authclass :param operator: dictionary with the required operator key-value pairs as defined above. :return: :rtype: >>> from pyhpeimc.auth import * >>> from pyhpeimc.plat.operator import * >>> auth = I... |
"1", "name" : "testadmin", "desc" : "test admin account", "defaultAcl" : "", "authType" : "0"} >>> delete_if_exists = delete_plat_operator('testadmin', auth.creds, auth.url) >>> new_operator = create_operator(operator, auth.creds, auth.url) >>> assert type(new_operator) is int >>> assert new_operator == 201 >>> fail_op... |
= requests.post(f_url, data=payload, auth=auth, headers=HEADERS) try: if response.status_code == 409: return response.status_code elif response.status_code == 201: return response.status_code except requests.exceptions.RequestException as error: return "Error:\n" + str(error) + ' create_operator: An Error has occured' |
def set_operator_password(operator, password, auth, url): """ Function to set the password of an existing operator :param operator: str Name of the operator account :param password: str New password :param auth: requests auth object #usually auth.creds from auth pyhpeimc.auth.class :param url: base url of IMC RS interf... |
from pyhpeimc.plat.operator import * >>> auth = IMCAuth("http://", "10.101.0.203", "8080", "admin", "admin") >>> operator = { "fullName" : "test administrator", "sessionTimeout" : "30", "password" : "password","operatorGroupId" : "1", "name" : "testadmin","desc" : "test admin account", "defaultAcl" : "","authType" : "0... |
if operator is None: operator = input( '''\n What is the username you wish to change the password?''') oper_id = '' authtype = None plat_oper_list = get_plat_operator(auth, url) for i in plat_oper_list: if i['name'] == operator: oper_id = i['id'] authtype = i['authType'] if oper_id == '': return "User does not exist" c... |
None: password = input( '''\n ============ Please input the operators new password:\n ============ ''') payload = json.dumps({'password': password, 'authType': authtype}) response = requests.put(f_url, data=payload, auth=auth, headers=HEADERS) try: if response.status_code == 204: # print("Operator:" + operator + # " pa... |
def get_plat_operator(auth, url): """ Funtion takes no inputs and returns a list of dictionaties of all of the operators currently configured on the HPE IMC system :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... |
* >>> from pyhpeimc.plat.operator import * >>> auth = IMCAuth("http://", "10.101.0.203", "8080", "admin", "admin") >>> plat_operators = get_plat_operator(auth.creds, auth.url) >>> assert type(plat_operators) is list >>> assert 'name' in plat_operators[0] """ f_url = url + '/imcrs/plat/operator?start=0&size=1000&orderBy... |
An Error has occured') return "Error:\n" + str(error) + ' get_plat_operator: An Error has occured' |
def delete_plat_operator(operator, auth, url): """ Function to set the password of an existing operator :param operator: str Name of the operator account :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.auth... |
= IMCAuth("http://", "10.101.0.203", "8080", "admin", "admin") >>> success_delete_operator = delete_plat_operator('testadmin', auth.creds, auth.url) >>> assert type(success_delete_operator) is int >>> assert success_delete_operator == 204 >>> fail_delete_operator = delete_plat_operator('testadmin', auth.creds, auth.url... |
None: # print ("User does not exist") return 409 f_url = url + "/imcrs/plat/operator/" + str(oper_id) response = requests.delete(f_url, auth=auth, headers=HEADERS) try: if response.status_code == 204: # print("Operator: " + operator + # " was successfully deleted") return response.status_code except requests.exceptions... |
def execute_request(self, url, http_method, query_params, post_data): """Makes a request to the specified url endpoint with the specified http method, params and post data. Args: url (string): The url to the API without query params. Example: "https://api.housecanary.com/v2/property/value" http_method (string): The htt... |
the body of the request. Returns: The result of calling this instance's OutputGenerator process_response method on the requests.Response object. If no OutputGenerator is specified for this instance, returns the requests.Response. """ response = requests.request(http_method, url, params=query_params, auth=self._auth, js... |
return response |
def post(self, url, post_data, query_params=None): """Makes a POST request to the specified url endpoint. Args: url (string): The url to the API without query params. Example: "https://api.housecanary.com/v2/property/value" post_data: Json post data to send in the body of the request. query_params (dict): Optional. Dic... |
object. If no OutputGenerator is specified for this instance, returns the requests.Response. """ if query_params is None: query_params = {} return self.execute_request(url, "POST", query_params, post_data) |
def import_custom_views(filename): """ Function which takes in a csv files as input to the create_custom_views function from the pyhpeimc python module available at https://github.com/HPNetworking/HP-Intelligent-Management-Center :param filename: user-defined filename which contains two column named "name" and "uppervi... |
as csvfile: # decodes file as csv as a python dictionary reader = csv.DictReader(csvfile) for view in reader: # loads each row of the CSV as a JSON string name = view['name'] upperview = view['upperview'] if len(upperview) is 0: upperview = None create_custom_views(name,upperview,auth=auth.creds, url=auth.url) |
def get_real_time_locate(host_ipaddress, auth, url): """ 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. Note: Although intended to return a single location, Multiple locations may be returned for a single host due... |
IP address :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 :return: list of dictionaries where each element of the list represents the location of the target host :rtype: list >>> from pyhpeimc.au... |
get_real_time_locate('10.101.0.51', auth.creds, auth.url) >>> assert type(found_device) is list >>> assert 'deviceId' in found_device[0] >>> assert 'deviceId' in found_device[0] >>> assert 'deviceId' in found_device[0] >>> assert 'deviceId' in found_device[0] >>> no_device = get_real_time_locate('192.168.254.254', auth... |
200: response = json.loads(response.text) if 'realtimeLocation' in response: real_time_locate = response['realtimeLocation'] if isinstance(real_time_locate, dict): real_time_locate = [real_time_locate] return real_time_locate else: return json.loads(response)['realtimeLocation'] else: print("Host not found") return 403... |
def get_ip_mac_arp_list(auth, url, devid=None, devip=None): """ function takes devid of specific device and issues a RESTFUL call to get the IP/MAC/ARP list from the 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.... |
of the target device :return: list of dictionaries containing the IP/MAC/ARP list of the target device. :rtype: list >>> from pyhpeimc.auth import * >>> from pyhpeimc.plat.termaccess import * >>> auth = IMCAuth("http://", "10.101.0.203", "8080", "admin", "admin") >>> ip_mac_list = get_ip_mac_arp_list( auth.creds, auth.... |
not None: dev_details = get_dev_details(devip, auth, url) if isinstance(dev_details, str): print("Device not found") return 403 else: devid = get_dev_details(devip, auth, url)['id'] f_url = url + "/imcrs/res/access/ipMacArp/" + str(devid) response = requests.get(f_url, auth=auth, headers=HEADERS) try: if response.statu... |
An Error has occured" |
def get_ip_scope(auth, url, scopeid=None, ): """ function requires no inputs and returns all IP address scopes currently configured on the HPE IMC server. If the optional scopeid parameter is included, this will automatically return only the desired scope id. :param scopeid: integer of the desired scope id ( optional )... |
of IMC RS interface #usually auth.url from pyhpeimc.auth.authclass :return: list of dictionary objects where each element of the list represents one IP scope :rtype: list >>> from pyhpeimc.auth import * >>> from pyhpeimc.plat.termaccess import * >>> auth = IMCAuth("http://", "10.101.0.203", "8080", "admin", "admin") >>... |
= "/imcrs/res/access/assignedIpScope" else: get_ip_scope_url = "/imcrs/res/access/assignedIpScope/ip?ipScopeId=" + str(scopeid) f_url = url + get_ip_scope_url response = requests.get(f_url, auth=auth, headers=HEADERS) try: if response.status_code == 200: ipscopelist = (json.loads(response.text))['assignedIpScope'] if i... |
def add_ip_scope(name, description, auth, url, startip=None, endip=None, network_address=None): """ Function takes input of four strings Start Ip, endIp, name, and description to add new Ip Scope to terminal access in the HPE IMC base platform :param name: str Name of the owner of this IP scope ex. 'admin' :param descr... |
auth pyhpeimc.auth.class :param url: base url of IMC RS interface #usually auth.url from pyhpeimc.auth.authclass :param startip: str Start of IP address scope ex. '10.101.0.1' :param endip: str End of IP address scope ex. '10.101.0.254' :param network_address: ipv4 network address + subnet bits of target scope :return:... |
"10.101.0.203", "8080", "admin", "admin") >>> delete_ip_scope('10.50.0.0/24', auth.creds, auth.url) <Response [204]> >>> new_scope = add_ip_scope('10.50.0.1', '10.50.0.254', 'cyoung', 'test group', auth.creds, auth.url) >>> assert type(new_scope) is int >>> assert new_scope == 200 >>> existing_scope = add_ip_scope('10.... |
nw_address[-2] f_url = url + "/imcrs/res/access/assignedIpScope" payload = ('''{ "startIp": "%s", "endIp": "%s","name": "%s","description": "%s" }''' % (str(startip), str(endip), str(name), str(description))) response = requests.post(f_url, auth=auth, headers=HEADERS, data=payload) try: if response.status_code == 200: ... |
has occured" |
def delete_ip_scope(network_address, auth, url): """ Function to delete an entire IP segment from the IMC IP Address management under terminal access :param network_address :param auth :param url >>> from pyhpeimc.auth import * >>> from pyhpeimc.plat.termaccess import * >>> auth = IMCAuth("http://", "10.101.0.203", "80... |
get_scope_id(network_address, auth, url) if scope_id == "Scope Doesn't Exist": return scope_id f_url = url + '''/imcrs/res/access/assignedIpScope/''' + str(scope_id) response = requests.delete(f_url, auth=auth, headers=HEADERS) try: if response.status_code == 204: # print("IP Segment Successfully Deleted") return 204 e... |
def add_scope_ip(hostipaddress, name, description, auth, url, scopeid=None, network_address=None): """ Function to add new host IP address allocation to existing scope ID :param hostipaddress: ipv4 address of the target host to be added to the target scope :param name: name of the owner of this host :param description:... |
url of IMC RS interface #usually auth.url from pyhpeimc.auth.authclass :param scopeid: integer of the desired scope id ( optional ) :param network_address: ipv4 network address + subnet bits of target scope :return: :rtype: >>> from pyhpeimc.auth import * >>> from pyhpeimc.plat.termaccess import * >>> auth = IMCAuth("h... |
is not None: scopeid = get_scope_id(network_address, auth, url) if scopeid == "Scope Doesn't Exist": return scopeid new_ip = {"ip": hostipaddress, "name": name, "description": description} f_url = url + '/imcrs/res/access/assignedIpScope/ip?ipScopeId=' + str(scopeid) payload = json.dumps(new_ip) response = requests.pos... |
requests.exceptions.RequestException as error: return "Error:\n" + str(error) + " add_ip_scope: An Error has occured" |
def remove_scope_ip(hostid, auth, url): """ Function to add remove IP address allocation :param hostid: Host id of the host to be deleted :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 :return: S... |
pyhpeimc.plat.termaccess import * >>> auth = IMCAuth("http://", "10.101.0.203", "8080", "admin", "admin") >>> new_scope = add_ip_scope('10.50.0.1', '10.50.0.254', 'cyoung', 'test group', auth.creds, auth.url) >>> add_host_to_segment('10.50.0.5', 'cyoung', 'New Test Host', '10.50.0.0/24', auth.creds, auth.url) >>> host_... |
auth=auth, headers=HEADERS, ) try: if response.status_code == 204: # print("Host Successfully Deleted") return response.status_code elif response.status_code == 409: # print("IP Scope Already Exists") return response.status_code except requests.exceptions.RequestException as error: return "Error:\n" + str(error) + " ad... |
def get_ip_scope_hosts(auth, url, scopeid=None, network_address=None): """ Function requires input of scope ID and returns list of allocated IP address for the specified scope :param auth: requests auth object #usually auth.creds from auth pyhpeimc.auth.class :param url: base url of IMC RS interface #usually auth.url f... |
:return: list of dictionary objects where each element of the list represents a single host assigned to the IP scope :rtype: list >>> from pyhpeimc.auth import * >>> from pyhpeimc.plat.termaccess import * >>> auth = IMCAuth("http://", "10.101.0.203", "8080", "admin", "admin") >>> scope_id = get_scope_id('10.50.0.0/24',... |
'description' in ip_scope_hosts[0] >>> assert 'ip' in ip_scope_hosts[0] >>> assert 'id' in ip_scope_hosts[0] """ if network_address is not None: scopeid = get_scope_id(network_address, auth, url) if scopeid == "Scope Doesn't Exist": return scopeid f_url = url + "/imcrs/res/access/assignedIpScope/ip?size=10000&ipScopeId... |
dict): ipscope = [ipscopelist] return ipscope return ipscopelist except requests.exceptions.RequestException as error: return "Error:\n" + str(error) + " get_ip_scope: An Error has occured" |
def delete_host_from_segment(hostipaddress, networkaddress, auth, url): """ :param hostipaddress: str ipv4 address of the target host to be deleted :param networkaddress: ipv4 network address + subnet bits of target scope :param auth: requests auth object #usually auth.creds from auth pyhpeimc.auth.class :param url: ba... |
""" host_id = get_host_id(hostipaddress, networkaddress, auth, url) delete_host = remove_scope_ip(host_id, auth, url) return delete_host |
def allow_attribute_comments(chain, node): """ This augmentation is to allow comments on class attributes, for example: class SomeClass(object): some_attribute = 5 ''' This is a docstring for the above attribute ''' """ # TODO: find the relevant citation for why this is the correct way to comment attributes if isinstan... |
chain() |
def download(self, url, path, name_audio): """ Params: ::url = Comprises the url used to download the audio. ::path = Comprises the location where the file should be saved. ::name_audio = Is the name of the desired audio. Definition: Basically, we do a get with the requests module and after that we recorded in the desi... |
occasion. """ if path is not None: with open(str(path+name_audio), 'wb') as handle: response = requests.get(url, stream = True) if not response.ok: raise Exception("Error in audio download.") for block in response.iter_content(1024): if not block: break handle.write(block) |
def get_dev_asset_details(ipaddress, auth, url): """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 :param auth: requests auth object #usually auth.creds from auth pyhpeimc.auth.class :param url: base url ... |
details, with each asset contained in a dictionary :rtype: list >>> from pyhpeimc.auth import * >>> from pyhpeimc.plat.netassets import * >>> auth = IMCAuth("http://", "10.101.0.203", "8080", "admin", "admin") >>> single_asset = get_dev_asset_details('10.101.0.1', auth.creds, auth.url) >>> assert type(single_asset) is ... |
the contents r = requests.get(f_url, auth=auth, headers=HEADERS) # r.status_code try: if r.status_code == 200: dev_asset_info = (json.loads(r.text)) if len(dev_asset_info) > 0: dev_asset_info = dev_asset_info['netAsset'] if type(dev_asset_info) == dict: dev_asset_info = [dev_asset_info] if type(dev_asset_info) == list:... |
def get_dev_asset_details_all(auth, url): """Takes no input to fetch device assett details from HP IMC RESTFUL API :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 :return: list of dictionatires co... |
"8080", "admin", "admin") >>> all_assets = get_dev_asset_details_all( auth.creds, auth.url) >>> assert type(all_assets) is list >>> assert 'asset' in all_assets[0] """ get_dev_asset_details_all_url = "/imcrs/netasset/asset?start=0&size=15000" f_url = url + get_dev_asset_details_all_url # creates the URL using the paylo... |
+ ' get_dev_asset_details: An Error has occured' |
def check_database_connected(db): """ A built-in check to see if connecting to the configured default database backend succeeds. It's automatically added to the list of Dockerflow checks if a :class:`~flask_sqlalchemy.SQLAlchemy` object is passed to the :class:`~dockerflow.flask.app.Dockerflow` class during instantiati... |
""" from sqlalchemy.exc import DBAPIError, SQLAlchemyError errors = [] try: with db.engine.connect() as connection: connection.execute('SELECT 1;') except DBAPIError as e: msg = 'DB-API error: {!s}'.format(e) errors.append(Error(msg, id=health.ERROR_DB_API_EXCEPTION)) except SQLAlchemyError as e: msg = 'Database miscon... |
def check_migrations_applied(migrate): """ A built-in check to see if all migrations have been applied correctly. It's automatically added to the list of Dockerflow checks if a `flask_migrate.Migrate <https://flask-migrate.readthedocs.io/>`_ object is passed to the :class:`~dockerflow.flask.app.Dockerflow` class during... |
= Migrate(app, db) dockerflow = Dockerflow(app, db=db, migrate=migrate) """ errors = [] from alembic.migration import MigrationContext from alembic.script import ScriptDirectory from sqlalchemy.exc import DBAPIError, SQLAlchemyError # pass in Migrate.directory here explicitly to be compatible with # older versions of F... |
script_heads = set(script.get_heads()) except (DBAPIError, SQLAlchemyError) as e: msg = "Can't connect to database to check migrations: {!s}".format(e) return [Info(msg, id=health.INFO_CANT_CHECK_MIGRATIONS)] if db_heads != script_heads: msg = "Unapplied migrations found: {}".format(', '.join(script_heads)) errors.appe... |
def check_redis_connected(client): """ A built-in check to connect to Redis using the given client and see if it responds to the ``PING`` command. It's automatically added to the list of Dockerflow checks if a :class:`~redis.StrictRedis` instances is passed to the :class:`~dockerflow.flask.app.Dockerflow` class during ... |
= Dockerflow(app, redis=redis) An alternative approach to instantiating a Redis client directly would be using the `Flask-Redis <https://github.com/underyx/flask-redis>`_ Flask extension:: from flask import Flask from flask_redis import FlaskRedis from dockerflow.flask import Dockerflow app = Flask(__name__) app.config... |
to redis: {!s}'.format(e) errors.append(Error(msg, id=health.ERROR_CANNOT_CONNECT_REDIS)) except redis.RedisError as e: errors.append(Error('Redis error: "{!s}"'.format(e), id=health.ERROR_REDIS_EXCEPTION)) else: if not result: errors.append(Error('Redis ping failed', id=health.ERROR_REDIS_PING_FAILED)) return errors |
def get_custom_views(auth, url,name=None,headers=HEADERS): """ function requires no input and returns a list of dictionaries of custom views from an HPE IMC. Optional name argument will return only the specified view. :param name: str containing the name of the desired custom view :return: list of dictionaties containi... |
get_custom_view_url = '/imcrs/plat/res/view/custom?resPrivilegeFilter=false&name='+name+'&desc=false&total=false' f_url = url + get_custom_view_url r = requests.get(f_url, auth=auth, headers=headers) try: if r.status_code == 200: custom_view_list = (json.loads(r.text))["customView"] if type(custom_view_list) == dict: c... |
def create_custom_views(auth, url,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 containi... |
upperview is None: payload = '''{ "name": "''' + name + '''", "upLevelSymbolId" : ""}''' print (payload) else: parentviewid = get_custom_views(auth, url, upperview)[0]['symbolId'] payload = '''{ "name": "'''+name+ '''", "upLevelSymbolId" : "'''+str(parentviewid)+'''"}''' print (payload) r = requests.post(f_url, data = ... |
created successfully' except requests.exceptions.RequestException as e: return "Error:\n" + str(e) + ' get_custom_views: An Error has occured' |
def get_dev_run_config(devid, auth, url): """ 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 ent... |
the device 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 get_dev_run_url = "/imcrs/icc/deviceCfg/" + str(devid) + "/currentRun" f_url = url + get_dev_run_url... |
= requests.get(f_url, auth=auth, headers=HEADERS) # print (r.status_code) try: if r.status_code == 200: try: run_conf = (json.loads(r.text))['content'] return run_conf except: return "This features is no supported on this device" except requests.exceptions.RequestException as e: return "Error:\n" + str(e) + " get_dev_r... |
def get_dev_start_config(devId, auth, url): """ 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 e... |
the device 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 get_dev_run_url = "/imcrs/icc/deviceCfg/" + str(devId) + "/currentStart" f_url = url + get_dev_run_u... |
= requests.get(f_url, auth=auth, headers=HEADERS) try: if r.status_code == 200: try: start_conf = (json.loads(r.text))['content'] return start_conf except: return "Start Conf not supported on this device" except requests.exceptions.RequestException as e: return "Error:\n" + str(e) + " get_dev_run_config: An Error has o... |
def set_inteface_up(devid, ifindex, auth, url): """ function takest devid and ifindex of specific device and interface and issues a RESTFUL call to "undo shut" the spec ified interface on the target device. :param devid: int or str value of the target device :param ifindex: int or str value of the target interface :ret... |
+ str(devid) + "/interface/" + str(ifindex) + "/up" f_url = url + set_int_up_url try: r = requests.put(f_url, auth=auth, headers=HEADERS) # creates the URL using the payload variable as the contents if r.status_code == 204: return r.status_code except requests.exceptions.RequestException as e: return "Error:\n" + str(e... |
def vfolders(access_key): ''' List and manage virtual folders. ''' fields = [ ('Name', 'name'), ('Created At', 'created_at'), ('Last Used', 'last_used'), ('Max Files', 'max_files'), ('Max Size', 'max_size'), ] if access_key is None: q = 'query { vfolders { $fields } }' else: q = 'query($ak:String) { vfolders(access_key... |
Session() as session: try: resp = session.Admin.query(q, v) except Exception as e: print_error(e) sys.exit(1) print(tabulate((item.values() for item in resp['vfolders']), headers=(item[0] for item in fields))) |
def config(): ''' Shows the current configuration. ''' config = get_config() print('Client version: {0}'.format(click.style(__version__, bold=True))) print('API endpoint: {0}'.format(click.style(str(config.endpoint), bold=True))) print('API version: {0}'.format(click.style(config.version, bold=True))) print('Access key... |
def get_system_vendors(auth, url): """Takes string no input to issue RESTUL call to HP IMC\n :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 :return: list of dictionaries where each dictionary rep... |
"8080", "admin", "admin") >>> vendors = get_system_vendors(auth.creds, auth.url) >>> assert type(vendors) is list >>> assert 'name' in vendors[0] """ get_system_vendors_url = '/imcrs/plat/res/vendor?start=0&size=10000&orderBy=id&desc=false&total=false' f_url = url + get_system_vendors_url # creates the URL using the pa... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.