def test_5_get_host_VLUNs_no_query_support(self, mock_version): self.printHeader('get_host_VLUNs_no_query_support') # Mock the version number to a version that does not support # VLUN querying and then remake the client. version = ( client.HPE3ParClient.HPE3PAR_WS_MIN_BUILD_VERSION_VLUN_QUERY - 1) mock_version.return_value = {'build': version} self.cl = client.HPE3ParClient(self.flask_url) # Mock the HTTP GET function to track what the call to it was. self.cl.http.get = mock.Mock() self.cl.http.get.return_value = ({}, { 'members': [{ 'hostname': HOST_NAME1 }] }) self.cl.createVLUN(VOLUME_NAME1, LUN_1, HOST_NAME1) self.cl.getHostVLUNs(HOST_NAME1) # Check for the request that happens when VLUN querying is unsupported. self.cl.http.get.assert_has_calls([mock.call('/vluns')]) self.printFooter('get_host_VLUNs_no_query_support')
def test_5_get_host_VLUNs_query_support(self, mock_version): self.printHeader('get_host_VLUNs_query_support') # Mock the version number to a version that supports # VLUN querying and then remake the client. version = client.HPE3ParClient.HPE3PAR_WS_MIN_BUILD_VERSION_VLUN_QUERY mock_version.return_value = {'build': version} self.cl = client.HPE3ParClient(self.flask_url) # Mock the HTTP GET function to track what the call to it was. self.cl.http.get = mock.Mock() self.cl.http.get.return_value = ({}, { 'members': [{ 'hostname': HOST_NAME1, 'active': True }] }) self.cl.createVLUN(VOLUME_NAME1, LUN_1, HOST_NAME1) self.cl.getHostVLUNs(HOST_NAME1) # Check for the request that happens when VLUN querying is supported. query = '"hostname EQ %s"' % HOST_NAME1 expected_query = '/vluns?query=%s' % quote(query.encode("utf-8")) self.cl.http.get.assert_has_calls([mock.call(expected_query)]) self.printFooter('get_host_VLUNs_query_support')
def __init__(self, hostname, port, username, password): self.hostname = hostname self.port = port self.username = username self.password = password url = "https://" + self.hostname + ":" + str(self.port) + "/api/v1" print("connection to " + url) parser = argparse.ArgumentParser() parser.add_argument("-debug", help="Turn on http debugging", default=False, action="store_true") args = parser.parse_args() self.cl = client.HPE3ParClient(url, suppress_ssl_warnings=True) self.cl.login(self.username, self.password) if "debug" in args and args.debug == True: self.cl.debug_rest(True) #print(self.cl.getCPGs()); self.defaultCPG = self.cl.getCPGs()["members"][0]["name"] print("This array default CPG is " + self.defaultCPG) '''
def get_client(self, section_name, test, url=None): logger.info("hpe3par_wsapi_checks - get_client()") """Tries to create a client and verifies the api url :return: The client if url is valid, None if invalid/missing """ try: if not url: url = self.parser.get(section_name, 'hpe3par_api_url') logger.info("Attempting to connect to %s..." % url) if test: cl = testclient.HPE3ParClient(url) else: cl = hpeclient.HPE3ParClient(url) return cl except (hpe_exceptions.UnsupportedVersion, hpe_exceptions.HTTPBadRequest, TypeError) as e: logger.info("Failed to connect to hpe3par_api_url for node '%s' " "backend section '%s' --- %s" % (self.node, section_name, e)) return None except configparser.NoOptionError: logger.info("No hpe3par_api_url provided for node '%s' backend " "section '%s'" % (self.node, section_name)) return None
def storage3par_open_connection(self, storage_system, username, password, port=8080, optional=None): """ Open a connection to the 3PAR system Example: | Open Connection | 10.0.0.1 | user | password | """ self.client = client.HPE3ParClient('https://{}:{}/api/v1'.format( storage_system, port), suppress_ssl_warnings=True) self.client.login(username, password, optional)
def _create_client(self): cl = client.HPE3ParClient( self.config.hpe3par_api_url, suppress_ssl_warnings=CONF.suppress_requests_ssl_warnings) client_version = hpe3parclient.version if client_version < MIN_CLIENT_VERSION: ex_msg = (_('Invalid hpe3parclient version found (%(found)s). ' 'Version %(minimum)s or greater required. Run "pip' ' install --upgrade python-3parclient" to upgrade' ' the hpe3parclient.') % { 'found': client_version, 'minimum': MIN_CLIENT_VERSION }) LOG.error(ex_msg) raise exception.InvalidInput(reason=ex_msg) return cl
def setUp(self, withSSH=False, withFilePersona=False): self.withSSH = withSSH self.withFilePersona = withFilePersona cwd = os.path.dirname( os.path.abspath(inspect.getfile(inspect.currentframe()))) if self.unitTest: self.printHeader('Using flask ' + self.flask_url) parsed_url = urlparse(self.flask_url) userArg = '-user=%s' % self.user passwordArg = '-password=%s' % self.password portArg = '-port=%s' % parsed_url.port script = 'HPE3ParMockServer_flask.py' path = "%s/%s" % (cwd, script) try: self.mockServer = subprocess.Popen( [sys.executable, path, userArg, passwordArg, portArg], stdout=subprocess.PIPE, stderr=subprocess.PIPE, stdin=subprocess.PIPE) except Exception: pass time.sleep(1) if self.withFilePersona: self.cl = file_client.HPE3ParFilePersonaClient(self.flask_url) else: self.cl = client.HPE3ParClient(self.flask_url) if self.withSSH: self.printHeader('Using paramiko SSH server on port %s' % self.ssh_port) ssh_script = 'HPE3ParMockServer_ssh.py' ssh_path = "%s/%s" % (cwd, ssh_script) self.mockSshServer = subprocess.Popen( [sys.executable, ssh_path, str(self.ssh_port)], stdout=subprocess.PIPE, stderr=subprocess.PIPE, stdin=subprocess.PIPE) time.sleep(1) else: if withFilePersona: self.printHeader('Using 3PAR %s with File Persona' % self.url_3par) self.cl = file_client.HPE3ParFilePersonaClient(self.url_3par) else: self.printHeader('Using 3PAR ' + self.url_3par) self.cl = client.HPE3ParClient(self.url_3par) if self.withSSH: # This seems to slow down the test cases, so only use this when # requested if self.unitTest: # The mock SSH server can be accessed at 0.0.0.0. ip = '0.0.0.0' else: parsed_3par_url = urlparse(self.url_3par) ip = parsed_3par_url.hostname.split(':').pop() try: # Now that we don't do keep-alive, the conn_timeout needs to # be set high enough to avoid sometimes slow response in # the File Persona tests. self.cl.setSSHOptions( ip, self.user, self.password, port=self.ssh_port, conn_timeout=500, known_hosts_file=self.known_hosts_file, missing_key_policy=self.missing_key_policy) except Exception as ex: print(ex) self.fail("failed to start ssh client") # Setup remote copy target if self.run_remote_copy: parsed_3par_url = urlparse(self.secondary_url_3par) ip = parsed_3par_url.hostname.split(':').pop() self.secondary_cl = client.HPE3ParClient(self.secondary_url_3par) try: self.secondary_cl.setSSHOptions( ip, self.secondary_user, self.secondary_password, port=self.ssh_port, conn_timeout=500, known_hosts_file=self.known_hosts_file, missing_key_policy=self.missing_key_policy) except Exception as ex: print(ex) self.fail("failed to start ssh client") self.secondary_cl.login(self.secondary_user, self.secondary_password) if self.debug: self.cl.debug_rest(True) self.cl.login(self.user, self.password) if not self.port: ports = self.cl.getPorts() ports = [ p for p in ports['members'] if p['linkState'] == 4 and # Ready ('device' not in p or not p['device'] ) and p['mode'] == self.cl.PORT_MODE_TARGET ] self.port = ports[0]['portPos']
for item in items_list: vol_split = item[1].rsplit(".", 1)[0] vol_split = vol_split.rsplit("_", 1)[0] if vol_split not in vol_list: vol_list.append(vol_split) return vol_list username = "******" #password = input("password: "******"password: "******"KC3T2G222" array = "KC1T0G234" # this creates the client object and sets the url to the cl = client.HPE3ParClient("https://%s.cernerasp.com:8080/api/v1" % array, suppress_ssl_warnings=True) # Set the SSH authentication options for the SSH based calls. #cl.setSSHOptions("%s.cernerasp.com" % array, username, password) try: cl.login(username, password) print("Login worked!") except exceptions.HTTPUnauthorized as ex: print("Login failed.") quit = 'n' while quit != 'y': hosts = cl.getHosts() hosts_dict = {}
def get_arrayinfo(array_name): try: hparrayinfo = hp_client.getStorageSystemInfo() except Exception as e: print('Unable to get system info') print(e) sys.exit(1) #print(hparrayinfo['name'] + hparrayinfo['systemVersion'] + hparrayinfo['patches']) HPEARRAYINFO = {'name' : hparrayinfo['name'],'osversion' : hparrayinfo['systemVersion'], 'revision' : hparrayinfo['patches'] } HPEARRAYDATA.append(HPEARRAYINFO) # this creates the client object and sets the url to the 3PAR server try: hp_client = client.HPE3ParClient("http://" + ARRAYNAME + ":8008/api/v1") hp_client.login(USERNAME, PASSWORD) except Exception as e: print('Unable to connect to array (http)') sys.exit(1) # Set the SSH authentication options for the SSH based calls. hp_client.setSSHOptions(ARRAYNAME, USERNAME, PASSWORD) get_arrayinfo(ARRAYNAME) # kill session hp_client.logout()
# this is a hack to get the hpe driver module # and it's utils module on the search path. cmd_folder = os.path.realpath(os.path.abspath("..")) if cmd_folder not in sys.path: sys.path.insert(0, cmd_folder) from hpe3parclient import client, exceptions parser = argparse.ArgumentParser() parser.add_argument("-debug", help="Turn on http debugging", default=False, action="store_true") args = parser.parse_args() cl = client.HPE3ParClient("http://10.10.22.241:8008/api/v1") if "debug" in args and args.debug == True: cl.debug_rest(True) def test_login(): #this will fail print("Test Logout") try: cl.login("username", "hpe") pprint.pprint("Login worked") except exceptions.HTTPUnauthorized as ex: pprint.pprint("Login Failed") def test_logout():
def Connect3par(hpe3parip, username, password): cl = client.HPE3ParClient('https://%s:8080/api/v1' % hpe3parip) cl.setSSHOptions(ip=hpe3parip, login=username, password=password) cl.login(username, password) return cl
parser = argparse.ArgumentParser() parser.add_argument("-debug", help="Turn on http debugging", default=False, action="store_true") args = parser.parse_args() username = "******" password = "******" testVolName = "WALTTESTVOL6969" testSNAPName = testVolName + "SNAP" testCPGName = "WALTTESTCPG" TESTHOST = 'WALTOpenStackHost' DOMAIN = 'WALT_TEST' PORT = {'node': 1, 'slot': 8, 'cardPort': 1} #cl = client.HPE3ParClient("https://localhost:8080/api/v1") cl = client.HPE3ParClient("https://10.10.22.241:8080/api/v1") if "debug" in args and args.debug == True: cl.debug_rest(True) cl.login(username, password) ports = cl.getPorts() pprint.pprint(ports) ports = cl.getFCPorts() pprint.pprint(ports) ports = cl.getiSCSIPorts(cl.PORT_STATE_READY) pprint.pprint(ports)
return qosRules # ------------------------------------- # Parse args and proceed with execution # ------------------------------------- args = parser.parse_args() # ------------------ # Login and run task # ------------------ secure = False if args.secure == True: secure = True cl = client.HPE3ParClient(args.api, False, secure, None, True) cl.setSSHOptions(args.ip, args.username, args.password) try: cl.login(args.username, args.password) except exceptions.HTTPUnauthorized as ex: print "Login failed." try: globals()[args.task](cl, args) cl.logout() except Exception as ex: # something unexpected happened print ex cl.logout() exit(1)
#!/usr/bin/env python3 #Check HPE 3PAR volumes state import sys from optparse import OptionParser from hpe3parclient import client, exceptions usage = "usage: %prog --ip ip_address" parser = OptionParser(usage=usage) parser.add_option("--ip", action="store", type="string", dest="ip_address", help="IP address") (options, args) = parser.parse_args() ip_address = options.ip_address cl = client.HPE3ParClient('http://'+ip_address+':8008/api/v1') username = '******' password = '******' try: cl.login(username, password) except: print("Login failed.") sys.exit(3) volumes = cl.getVolumes() cl.logout() problem_bool = False message = ''