def setUp(self, withSSH=False): 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 = 'test_HP3ParMockServer_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 as e: pass time.sleep(1) self.cl = client.HP3ParClient(self.flask_url) # SSH is not supported in flask, so not initializing # those tests are expected to fail else: self.printHeader('Using 3PAR ' + self.url_3par) self.cl = client.HP3ParClient(self.url_3par) if withSSH: # This seems to slow down the test cases, so only use this when # requested parsed_3par_url = urlparse(self.url_3par) ip = parsed_3par_url.hostname.split(':').pop() try: # Set the conn_timeout to None so that the ssh connections will # use the default transport values which will allow the test # case process to terminate after completing self.cl.setSSHOptions(ip, self.user, self.password, conn_timeout=None) except Exception as ex: print ex self.fail("failed to start ssh client") if self.debug: self.cl.debug_rest(True) self.cl.login(self.user, self.password)
def _create_client(self): cl = client.HP3ParClient(self.config.hp3par_api_url) client_version = hp3parclient.version if (client_version < MIN_CLIENT_VERSION): ex_msg = (_('Invalid hp3parclient version. Version %s or greater ' 'required.') % MIN_CLIENT_VERSION) raise hpexceptions.UnsupportedVersion(ex_msg) return cl
def _create_client(self): cl = client.HP3ParClient(self.config.hp3par_api_url) client_version = hp3parclient.version if (client_version < MIN_CLIENT_VERSION): ex_msg = (_('Invalid hp3parclient version. Version %s or greater ' 'required.') % MIN_CLIENT_VERSION) LOG.error(ex_msg) raise exception.InvalidInput(reason=ex_msg) return cl
def wwn(): ip_address = '192.168.92.101' username = '******' password = '******' cl = client.HP3ParClient("https://%s:8080/api/v1" % ip_address, suppress_ssl_warnings=True) cl.setSSHOptions(ip_address, username, password) try: cl.login(username, password) port = cl.getFCPorts() volumes = cl.getVolumes() luns = [] lun = {} # On parcourt le nombre total de lun et on ressort le nom de la lun for i in range(int(volumes['total'])): # print(volumes['members'][i]['name']) # luns.append(volumes['members'][i]['name']) lun = { 'nom': volumes['members'][i]['name'], 'taille': int(int(volumes['members'][i]['sizeMiB']) / 1024) } luns.append(lun) except exceptions.HTTPUnauthorized as ex: pprint.pprint("You must login first") except Exception as ex: print(ex) print(luns) cl.logout() print("logout worked") # print(volumes) lun = volumes['members'][74]['name'] return render_template('wwn.html', luns=luns)
def _create_client(self): cl = client.HP3ParClient(self.config.hp3par_api_url) client_version = hp3parclient.version if (client_version < MIN_CLIENT_VERSION): ex_msg = (_('Invalid hp3parclient version found (%(found)s). ' 'Version %(minimum)s or greater required.') % {'found': client_version, 'minimum': MIN_CLIENT_VERSION}) LOG.error(ex_msg) raise exception.InvalidInput(reason=ex_msg) cl.setSSHOptions(self.config.san_ip, self.config.san_login, self.config.san_password, port=self.config.san_ssh_port, conn_timeout=self.config.ssh_conn_timeout, privatekey=self.config.san_private_key) return cl
def _create_client(self): return client.HP3ParClient(self.configuration.hp3par_api_url)
# this is a hack to get the hp 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 hp3parclient 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.HP3ParClient("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", "hp") pprint.pprint("Login worked") except exceptions.HTTPUnauthorized as ex: pprint.pprint("Login Failed") def test_logout():
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.HP3ParClient("https://localhost:8080/api/v1") cl = client.HP3ParClient("https://10.10.22.241:8080/api/v1") if "debug" in args and args.debug == True: cl.debug_rest(True) def create_test_volume(): try: cl.createVolume(testVolName, testCPGName, 1000) except exceptions.HTTPUnauthorized as ex: print "You must login" except Exception as ex: print ex def create_test_vlun(): try:
# Create snap to replay mapping database rdb = script_db.SnapToReplayDB(options.work_dir + r'\replay_db') rdb.setup() # Setup server/lun info conn = options.array array = options.array serial = options.serial.upper() # Connect to 3Par array. # Get credentials for the proxy host username, password = cdb.get_enc_info(array) #this creates the client object and sets the url to the array. cl = client.HP3ParClient("http://" + array + ":8008/api/v1") # Set the SSH authentication options for the SSH based calls. #cl.setSSHOptions(array, username, password) try: cl.login(username, password) script_log("Logged into the array.") except exceptions.HTTPUnauthorized as ex: script_log("Login failed.") if options.operation == 'HELLO': check_lun(conn, serial) elif options.operation == 'CREATE_SNAP': create_snap(cdb, sdb, rdb, conn, serial, options.snap_name, options.access_group, options.proxy_host, options.datacenter, options.include_hosts,