def get_array(module): """Return System Object or Fail""" user_agent = '%(base)s %(class)s/%(version)s (%(platform)s)' % { 'base': USER_AGENT_BASE, 'class': __name__, 'version': VERSION, 'platform': platform.platform() } array_name = module.params['fa_url'] api = module.params['api_token'] if HAS_PYPURECLIENT: if array_name and api: system = flasharray.Client(target=array_name, api_token=api, user_agent=user_agent) elif environ.get('PUREFA_URL') and environ.get('PUREFA_API'): system = flasharray.Client(target=(environ.get('PUREFA_URL')), api_token=(environ.get('PUREFA_API')), user_agent=user_agent) else: module.fail_json( msg= "You must set PUREFA_URL and PUREFA_API environment variables " "or the fa_url and api_token module arguments") try: system.get_hardware() except Exception: module.fail_json( msg= "Pure Storage FlashArray authentication failed. Check your credentials" ) else: module.fail_json(msg="py-pure-client SDK is not installed.") return system
def get_array(module): """Return System Object or Fail""" user_agent = "%(base)s %(class)s/%(version)s (%(platform)s)" % { "base": USER_AGENT_BASE, "class": __name__, "version": VERSION, "platform": platform.platform(), } array_name = module.params["fa_url"] api = module.params["api_token"] if HAS_PYPURECLIENT and HAS_REQUESTS: versions = requests.get("https://" + array_name + "/api/api_version", verify=False) api_version = versions.json()["version"][-1] if array_name and api: system = flasharray.Client( target=array_name, api_token=api, user_agent=user_agent, version=api_version, ) elif environ.get("PUREFA_URL") and environ.get("PUREFA_API"): system = flasharray.Client( target=(environ.get("PUREFA_URL")), api_token=(environ.get("PUREFA_API")), user_agent=user_agent, ) else: module.fail_json( msg= "You must set PUREFA_URL and PUREFA_API environment variables " "or the fa_url and api_token module arguments") try: system.get_hardware() except Exception: module.fail_json( msg= "Pure Storage FlashArray authentication failed. Check your credentials" ) else: module.fail_json( msg="py-pure-client and/or requests are not installed.") return system
clone_new_volumes(target_client, source, source_snapshot_name, source_volumes, clone_suffix) if __name__ == "__main__": parser = argparse.ArgumentParser( description= 'Get all volumes in a pgroup, then snap/clone them to a remote target.' ) parser.add_argument('--source', help='Source array. PG Snapshot will be taken here.', required=True) parser.add_argument( '--target', help='Target array. Clone volumes will be created here.', required=True) parser.add_argument('--source-api-token', help='1.X API token for source array', required=True) parser.add_argument('--target-id-token', help='OAuth2 identity token for target array', required=True) args = parser.parse_args() source_1x_client = purestorage.FlashArray(args.source, api_token=args.source_api_token) target_2x_client = flasharray.Client(target=args.target, id_token=args.target_id_token) main(args.source, args.target, source_1x_client, target_2x_client)
############ # Add number of days to sample and desired output file name. # You should start with < 30 days and go from there ############ num_days = 30 # <- Enter number of days here file_name = 'Volume_Capacity_snaps_2.xlsx' # <- Enter your file name here in quotes # Suppress error warnings urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning) client = flasharray.Client('192.168.0.NN', version='2.2', private_key_file='rest-key.pem', private_key_password='', username='******', client_id='XXX', key_id='XXX', issuer='issuerid') # Set and format our sample period start_date = datetime.now() - timedelta(days=num_days) my_time = round(start_date.timestamp()) * 1000 # Set up placeholders for volume names and our dicts volname = [] tcap = [] scap = [] # Get our volume information from the FlashArray cvol = client.get_volumes_space(names=["*"], start_time=my_time, resolution=86400000).items