def _get_system(): """ Get Pure Storage FlashArray configuration 1) From the minion config pure_tags: fa: san_ip: management vip or hostname for the FlashArray api_token: A valid api token for the FlashArray being managed 2) From environment (PUREFA_IP and PUREFA_API) 3) From the pillar (PUREFA_IP and PUREFA_API) """ agent = { "base": USER_AGENT_BASE, "class": __name__, "version": VERSION, "platform": platform.platform(), } user_agent = "{base} {class}/{version} ({platform})".format(**agent) try: array = __opts__["pure_tags"]["fa"].get("san_ip") api = __opts__["pure_tags"]["fa"].get("api_token") if array and api: system = purestorage.FlashArray(array, api_token=api, user_agent=user_agent) except (KeyError, NameError, TypeError): try: san_ip = os.environ.get("PUREFA_IP") api_token = os.environ.get("PUREFA_API") system = purestorage.FlashArray(san_ip, api_token=api_token, user_agent=user_agent) except (ValueError, KeyError, NameError): try: system = purestorage.FlashArray( __pillar__["PUREFA_IP"], api_token=__pillar__["PUREFA_API"], user_agent=user_agent, ) except (KeyError, NameError): raise CommandExecutionError( "No Pure Storage FlashArray credentials found.") try: system.get() except Exception: # pylint: disable=broad-except raise CommandExecutionError( "Pure Storage FlashArray authentication failed.") return system
def _get_system(): ''' Get Pure Storage FlashArray configuration 1) From the minion config pure_tags: fa: san_ip: management vip or hostname for the FlashArray api_token: A valid api token for the FlashArray being managed 2) From environment (PUREFA_IP and PUREFA_API) 3) From the pillar (PUREFA_IP and PUREFA_API) ''' agent = { 'base': USER_AGENT_BASE, 'class': __name__, 'version': VERSION, 'platform': platform.platform() } user_agent = '{base} {class}/{version} ({platform})'.format(**agent) try: array = __opts__['pure_tags']['fa'].get('san_ip') api = __opts__['pure_tags']['fa'].get('api_token') if array and api: system = purestorage.FlashArray(array, api_token=api, user_agent=user_agent) except (KeyError, NameError, TypeError): try: san_ip = os.environ.get('PUREFA_IP') api_token = os.environ.get('PUREFA_API') system = purestorage.FlashArray(san_ip, api_token=api_token, user_agent=user_agent) except (ValueError, KeyError, NameError): try: system = purestorage.FlashArray( __pillar__['PUREFA_IP'], api_token=__pillar__['PUREFA_API'], user_agent=user_agent) except (KeyError, NameError): raise CommandExecutionError( 'No Pure Storage FlashArray credentials found.') try: system.get() except Exception: raise CommandExecutionError( 'Pure Storage FlashArray authentication failed.') return system
def getFAinfo(flash_array, apitoken): # Retrieves the basic statistics of the given flash_array urllib3.disable_warnings() fa = purestorage.FlashArray(flash_array, api_token=apitoken) fainfo = fa.get(action='monitor') fa.invalidate_cookie() return (fainfo)
def restore_overwrite_volume(snapshot, mount_point, backupid, serialno): array = purestorage.FlashArray(flasharray, flasharrayuser, flasharraypassword, verify_https=False) volumes = array.list_volumes() for key in volumes: volname = key.get("name") volserial = str(key.get("serial")).lower() found = volserial in serialno if (found): new_volume = array.copy_volume(snapshot.get("name"), volname, overwrite=True) #operating system rescan for new device sshclient = prepare_ssh_connection() rescan_scsi_bus_add_string = "rescan-scsi-bus.sh -a" stdin, stdout, stderr = sshclient.exec_command( rescan_scsi_bus_add_string) time.sleep(30) opt = stdout.readlines() #mount new volume device_mount_string = "mount /dev/mapper/3624a9370" + new_volume.get( "serial").lower() + " " + mount_point stdin, stdout, stderr = sshclient.exec_command(device_mount_string) time.sleep(30) sshclient.close() returned_serial_number = get_volume_serialno(mount_point) foundfinal = str(new_volume.get("serial")).lower() in serialno if (foundfinal): return True else: return False
def getArrayInfo(): for array in PUREARRAYS: ARRAY = array['name'] API_TOKEN = array['apitoken'] # Connect to the Array try: array = purestorage.FlashArray(ARRAY, api_token=API_TOKEN) except purestorage.PureError: print(e) print("PureError Unable to connect to the pure array: " + ARRAY) sys.exit(1) except Exception as e: print(e) print('Exception - Unable to connect to the pure array: ', ARRAY) sys.exit(1) arrayInfo = array.get() arrayName = arrayInfo['array_name'] arrayOSVersion = arrayInfo['version'] arrayRevision = arrayInfo['revision'] PUREINFO = {'name':arrayName,'osversion':arrayOSVersion,'revision':arrayRevision} PUREARRAYDATA.append(PUREINFO) # close the REST session array.invalidate_cookie()
def list_volume_connections(target, api_token, volume): # disable ceritificate warnings urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning) conn = purestorage.FlashArray( target, api_token=api_token, user_agent='Purity_FA_Prometheus_exporter/1.0') array = conn.get() p_hosts = conn.list_volume_private_connections(volume) s_hosts = conn.list_volume_shared_connections(volume) v_info = conn.get_volume(volume) hosts = [] for h in s_hosts: hosts.append({ 'host': h['host'], 'lun': h['lun'], 'hgroup': h['hgroup'] }) for h in p_hosts: hosts.append({'host': h['host'], 'lun': h['lun'], 'hgroup': ''}) vol = {} vol['serial'] = v_info['serial'] vol['hosts'] = hosts vol['array_name'] = array['array_name'] return vol
def pull_fa_objects(self, host: str, object_type: str) -> list: fa = purestorage.FlashArray( target=self.flasharrays[host]['ip'], api_token=self.flasharrays[host]['auth_token'], verify_https=False) if object_type == 'vol': try: fa_items = fa.list_volumes() except rest.ApiException as e: print("Exception: %s\n" % e) elif object_type == 'hgroup': try: fa_items = fa.list_hgroups() except rest.ApiException as e: print("Exception: %s\n" % e) else: raise Exception( "Wrong object type specified. Object type should be 'vol' or 'hgroup'." ) names = [] for item in fa_items: names.append(item['name']) return names
def pure_disk_monitoring(): try: '''Get the argument from Zabbix''' ip = str(sys.argv[2]) #IP of the Pure Storage Array token = str(sys.argv[3]) #API Token host = str(sys.argv[4]) #Host name (for the sender) zabbixIP = str( sys.argv[5]) #Zabbix Proxy or Server IP (for the sender) '''Get data''' arrayConnect = purestorage.FlashArray(ip, api_token=token, verify_https=False) diskList = arrayConnect.list_drives() metrics = [] for i in diskList: disk = i["name"] diskMonitoring = arrayConnect.get_drive(drive=disk) '''Sending data''' if "status" in diskMonitoring: diskStatus = str(diskMonitoring["status"]) m = ZabbixMetric(host, "pure.disk.status[" + disk + "]", diskStatus) metrics.append(m) if "capacity" in diskMonitoring: diskCapacity = str(diskMonitoring["capacity"]) m = ZabbixMetric(host, "pure.disk.capacity[" + disk + "]", diskCapacity) metrics.append(m) if "protocol" in diskMonitoring: diskProtocol = str(diskMonitoring["protocol"]) m = ZabbixMetric(host, "pure.disk.protocol[" + disk + "]", diskProtocol) metrics.append(m) if "type" in diskMonitoring: diskType = str(diskMonitoring["type"]) m = ZabbixMetric(host, "pure.disk.type[" + disk + "]", diskType) metrics.append(m) if "last_failure" in diskMonitoring: diskLastFailure = str(diskMonitoring["last_failure"]) m = ZabbixMetric(host, "pure.disk.last.failure[" + disk + "]", diskLastFailure) metrics.append(m) data = ZabbixSender(zabbixIP) data.send(metrics) '''Send 1 to give a result to Zabbix''' print(1) except Exception as e: ''' Sending 0 to Zabbix instead of a Python error. Like that the items won't be considered as "unsupported" ''' metrics = [ ZabbixMetric(host, "pure.disk.monitoring.launcher.error", str(e)) ] data = ZabbixSender(zabbixIP) data.send(metrics) print(0)
def pure_host_lld(): try: '''Get the argument from Zabbix''' ip = str(sys.argv[2]) #IP of the Pure Storage Array token = str(sys.argv[3]) #API Token ''' Disable the SSL Warning from the output ''' urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning) '''Get data''' arrayConnect = purestorage.FlashArray(ip, api_token=token) hostList = arrayConnect.list_hosts() '''Print data to console for Zabbix discovery''' json_data = '{\t"data":[' temp = 1 for i in hostList: data = '{"{#HOSTNAME}":' + '"' + i["name"] + '"}' if temp == 0: json_data = json_data + ',\n' else: temp = 0 json_data = json_data + data json_data = json_data + '\t ]}' print(json_data) except purestorage.PureHTTPError as err: print("Error while getting hosts information : {0}".format(err.reason)) except purestorage.PureError as err: print("Error while getting hosts information : {0}".format(err.reason)) except ValueError: print( "Error while getting hosts information due to an error with the arguments (Token,IP)" ) except: print("Unknow error while getting hosts information")
def __init__(self, array_info): self.host = array_info['host'] self.api_token = array_info['api_token'] self.array = purestorage.FlashArray(self.host, api_token=self.api_token) self.name = self.array.get()['array_name'] self.gather_metrics() self.volumes = self._get_volumes()
def pure_disk_lld(): try: '''Get the argument from Zabbix''' ip = str(sys.argv[2]) #IP of the Pure Storage Array token = str(sys.argv[3]) #API Token '''Get data''' arrayConnect = purestorage.FlashArray(ip, api_token=token, verify_https=False) diskList = arrayConnect.list_drives() '''Print data to console for Zabbix discovery''' json_data = '{\t"data":[' temp = 1 for i in diskList: data = '{"{#DISKNAME}":' + '"' + i["name"] + '"}' if temp == 0: json_data = json_data + ',\n' else: temp = 0 json_data = json_data + data json_data = json_data + '\t ]}' print(json_data) except purestorage.PureHTTPError as err: print("Error while getting disks information : {0}".format(err.reason)) except purestorage.PureError as err: print("Error while getting disks information : {0}".format(err.reason)) except ValueError: print( "Error while getting disks information due to an error with the arguments (Token,IP)" ) except Exception as e: print("Unknow error while getting disks information : " + str(e))
def get_status(self): """Gets hardware element status from flasharray.""" urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning) fa = purestorage.FlashArray(self.endpoint, api_token=self.apitoken) fainfo = fa.get_hardware(component=self.component) fa.invalidate_cookie() return (fainfo)
def get_alerts(self): """Gets active alerts from FlashArray.""" urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning) fa = purestorage.FlashArray(self.endpoint, api_token=self.apitoken) fainfo = fa.list_messages(open=True) fa.invalidate_cookie() return (fainfo)
def __init__(self, configuration, cluster_id): """ :param configuration: FlashArrayconfiguration :param cluster_id: Flocker cluster id :param hostname: Current hostname :param allocation_unit: allocation_unit """ self._cluster_id = cluster_id self._hostname = unicode(socket.gethostname()) self._conf = configuration eliot.Message.new(info='Initializing FlashArrayBlockDeviceAPI', cluster_id=self._cluster_id, hostname=self._hostname, config='PureFlashArrayConfiguration = {0}'.format( self._conf)).write(_logger) self._validate_config() # Will raise exception if something is missing self._full_vol_prefix = '{0}-{1}'.format(PURE_BASE_PREFIX, self._cluster_id) # TODO(patrickeast): remove this hack... we trim to allow for # '-<vol id>' postfix in the name without going over the 63 char # limit on volumes. We need to have the full dataset_id in them, but # can skimp on the cluster_id and hope we don't get two with the same # starting uuid. Ideally we store metadata somewhere so we have both # full paths available so we can correctly list_volumes later. self._vol_prefix = self._full_vol_prefix[:26] + '-' ua = '{cls}/{version} (flocker; {protocol}; {sys} {sys_version};)'.format( cls=self.__class__.__name__, version=self.VERSION, protocol=self._conf.storage_protocol, sys=platform.system(), sys_version=platform.version()) self._array = purestorage.FlashArray( self._conf.ip, api_token=self._conf.api_token, verify_https=self._conf.verify_https, ssl_cert=self._conf.ssl_cert, user_agent=ua) self._connector = connector.InitiatorConnector.factory( self._conf.storage_protocol, None, use_multipath=True, ) self._initiator_info = self._get_initiator_info() eliot.Message.new(info='Found initiator info: ' + str(self._initiator_info)).write(_logger) self._purity_hostname = self._ensure_purity_host() eliot.Message.new(info='Using Purity host: ' + str(self._purity_hostname)).write(_logger) self._volume_path_cache = {}
def pure_snap(vol_name): array = ps.FlashArray(fa_ip, api_token=fa_api_token) make_snap = array.create_snapshot(vol_name) temp_name = make_snap temp_name = str(temp_name) list_name = temp_name.split(",") list_name = list_name[3].strip("'name': ") make_snap = list_name return make_snap
def get_perf(self): """Gets performance counters from flasharray.""" urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning) fa = purestorage.FlashArray(self.endpoint, api_token=self.apitoken) if (self.volname is None): fainfo = fa.get(action='monitor')[0] else: fainfo = fa.get_volume(self.volname, action='monitor')[0] fa.invalidate_cookie() return(fainfo)
def __init__(self, endpoint, api_token): self.flasharray = purestorage.FlashArray( endpoint, api_token=api_token, user_agent='Purity_FA_Prometheus_exporter/1.0') self.array = None self.hosts = None self.volumes = None self.pods = None
def __init__(self, target, api_token, request='all'): self.connection = purestorage.FlashArray( target, api_token=api_token, user_agent='Purity_FA_Prometheus_exporter/1.0') vols = self.connection.list_volumes() self.serials = {} for v in vols: self.serials[v['name']] = v['serial'] self.request = request
def get_status(self): """Gets hardware element status from flasharray.""" urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning) fainfo = {} try: fa = purestorage.FlashArray(self.endpoint, api_token=self.apitoken) fainfo = fa.get_hardware(component=self.component) fa.invalidate_cookie() except Exception as e: self.logger.error('FA REST call returned "%s" ', e) return (fainfo)
def array_collect(array_context): logger.info("Collecting info for array '{}'".format(array_context.name)) # Create PureStorage client and Elasticsearch client ps_client = purestorage.FlashArray(array_context.host, api_token=array_context.api_token) # "elasticsearch" is the internal link to PureELK ES server es_client = Elasticsearch(hosts="elasticsearch:9200", retry_on_timeout=True) pure_collector = PureCollector(ps_client, es_client, array_context) pure_collector.collect()
def get_alerts(self): """Gets active alerts from FlashArray.""" urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning) fainfo = {} try: fa = purestorage.FlashArray(self.endpoint, api_token=self.apitoken) fainfo = fa.list_messages(open=True) fa.invalidate_cookie() except Exception as e: self.logger.error('FA REST call returned "%s" ', e) return (fainfo)
def get_volume_name(serialno): array = purestorage.FlashArray(flasharray, flasharrayuser, flasharraypassword, verify_https=False) volumes = array.list_volumes() for key in volumes: volname = key.get("name") volserial = str(key.get("serial")).lower() found = volserial in serialno if found: return volname return False
def check_storage_snapshot(backupid): array = purestorage.FlashArray(flasharray, flasharrayuser, flasharraypassword, verify_https=False) volumes = array.list_volumes() for key in volumes: volname = key.get("name") snaps = array.get_volume(volname, snap=True) for snap in snaps: found = str(backupid) in snap.get("name") if found: return snap
def pure_gather(vmw_in): array = ps.FlashArray(fa_ip, api_token=fa_api_token) get_info = array.list_volumes(tags=True) get_info_str = str(get_info) temp_str = get_info_str.replace('"', "") temp_list = temp_str.split('}') match_list = [s for s in temp_list if vmw_in in s] temp_name = match_list temp_name = str(temp_name[0]) list_name = temp_name.split(",") list_name = list_name[2].strip("'name': ") vvol_name = list_name return vvol_name
def pure_vol_info(): array = ps.FlashArray(fa_ip, api_token=fa_api_token) get_info = array.list_volumes(tags=True) get_info_str = str(get_info) temp_str = get_info_str.replace('"', "") temp_list = temp_str.split('}') print(temp_list) match_list = [s for s in temp_list if vol_name in s] temp_name = match_list temp_name = str(temp_name) list_name = temp_name.split(",") list_name = get_info_str return list_name
def create_protection_group_snap(volumes): pgname = "SAPHANA-" + databasename + "-CrashConsistency" array = purestorage.FlashArray(flasharray, flasharrayuser, flasharraypassword, verify_https=False) try: pgroup = array.get_pgroup(pgname) except Exception: array.create_pgroup(pgname) for vol in volumes: protectiongroups = array.add_volume(vol.get('volumename'), pgname) pgsnap = array.create_pgroup_snapshot(pgname) return pgsnap
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_space(self): """Gets performance counters from flasharray.""" urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning) fainfo = {} try: fa = purestorage.FlashArray(self.endpoint, api_token=self.apitoken) if (self.volname is None): fainfo = fa.get(space=True)[0] else: fainfo = fa.get_volume(self.volname, space=True) fa.invalidate_cookie() except Exception as e: self.logger.error('FA REST call returned "%s" ', e) return (fainfo)
def clean(self): """Custom clean method to test a connection attempt to the API for validation.""" super(FlashArray, self).clean() self.hostname = self.hostname.lower() try: connection = purestorage.FlashArray(self.ip_address, api_token=self.api_token) api_version = connection.get_rest_version() if LooseVersion(api_version) < LooseVersion('1.6'): message = 'Found API Version {} (1.6+ is required). Consider upgrading Purity.' raise ValidationError(message.format(api_version)) except purestorage.PureError: message = 'Failed to connect to {}. Please verify IP Address and API Token.' raise ValidationError(message.format(self.ip_address))
def create_flasharray_volume_snapshot(serialnumber, snapshot_suffix): array = purestorage.FlashArray(flasharray, flasharrayuser, flasharraypassword, verify_https=False) volumes = array.list_volumes() for key in volumes: volname = key.get("name") volserial = str(key.get("serial")).lower() found = volserial in serialnumber if found: snapshot_id = array.create_snapshot(volname, suffix=snapshot_suffix) snapserial = str(snapshot_id.get("serial")) return snapserial