def get_system(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_PURESTORAGE: if array_name and api: system = purestorage.FlashArray(array_name, api_token=api, user_agent=user_agent) elif environ.get('PUREFA_URL') and environ.get('PUREFA_API'): system = purestorage.FlashArray( 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() except Exception: module.fail_json( msg= "Pure Storage FlashArray authentication failed. Check your credentials" ) else: module.fail_json(msg="purestorage SDK is not installed.") return system
def get_session(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'] username = module.params['name'] password = module.params['password'] if HAS_PURESTORAGE: if array_name and username and password: system = purestorage.FlashArray(array_name, username=username, password=password, user_agent=user_agent) elif environ.get('PUREFA_URL'): if environ.get('PUREFA_USERNAME') and environ.get( 'PUREFA_PASSWORD'): url = environ.get('PUREFA_URL') username = environ.get('PUREFA_USERNAME') password = environ.get('PUREFA_PASSWORD') system = purestorage.FlashArray(url, username=username, password=password, user_agent=user_agent) else: module.fail_json( msg= "You must set PUREFA_URL and PUREFA_USERNAME, PUREFA_PASSWORD " "environment variables or the fa_url, username and password " "module arguments") try: system.get() except Exception: module.fail_json( msg= "Pure Storage FlashArray authentication failed. Check your credentials" ) else: module.fail_json(msg="purestorage SDK is not installed.") return system
def fa_connect(flasharray, api_token): global array try: array = purestorage.FlashArray(flasharray, api_token=api_token) print('Successfully connected to ', flasharray) except Exception as e: print(e) sys.exit('Exiting: Unable to establish session')
def do_setup(self, context): """Performs driver initialization steps that could raise exceptions.""" if purestorage is None: msg = _("Missing 'purestorage' python module, ensure the library" " is installed and available.") raise exception.PureDriverException(msg) # Raises PureDriverException if unable to connect and PureHTTPError # if unable to authenticate. purestorage.FlashArray.supported_rest_versions = \ self.SUPPORTED_REST_API_VERSIONS self._array = purestorage.FlashArray( self.configuration.san_ip, api_token=self.configuration.pure_api_token)
def get_system(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_PURESTORAGE: if array_name and api: system = purestorage.FlashArray(array_name, api_token=api, user_agent=user_agent) elif environ.get("PUREFA_URL") and environ.get("PUREFA_API"): system = purestorage.FlashArray( 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() except Exception: module.fail_json( msg= "Pure Storage FlashArray authentication failed. Check your credentials" ) else: module.fail_json(msg="purestorage SDK is not installed.") return system