def create_connection(module, array): """Create connection between arrays""" changed = True if not module.check_mode: remote_array = module.params["target_url"] user_agent = "%(base)s %(class)s/%(version)s (%(platform)s)" % { "base": "Ansible", "class": __name__, "version": 1.2, "platform": platform.platform(), } try: remote_system = FlashArray( module.params["target_url"], api_token=module.params["target_api"], user_agent=user_agent, ) connection_key = remote_system.get( connection_key=True)["connection_key"] remote_array = remote_system.get()["array_name"] api_version = array._list_available_rest_versions() # TODO: Refactor when FC async is supported if (FC_REPL_VERSION in api_version and module.params["transport"].lower() == "fc"): if module.params["connection"].lower() == "async": module.fail_json( msg= "Asynchronous replication not supported using FC transport" ) array_connection = flasharray.ArrayConnectionPost( type="sync-replication", management_address=module.params["target_url"], replication_transport="fc", connection_key=connection_key, ) array = get_array(module) res = array.post_array_connections( array_connection=array_connection) if res.status_code != 200: module.fail_json(msg="Array Connection failed. Error: {0}". format(res.errors[0].message)) else: array.connect_array( module.params["target_url"], connection_key, [module.params["connection"]], ) except Exception: module.fail_json(msg="Failed to connect to remote array {0}.". format(remote_array)) module.exit_json(changed=changed)
def create_connection(module, array): """Create connection between arrays""" changed = True if not module.check_mode: remote_array = module.params['target_url'] user_agent = '%(base)s %(class)s/%(version)s (%(platform)s)' % { 'base': 'Ansible', 'class': __name__, 'version': 1.2, 'platform': platform.platform() } try: remote_system = FlashArray(module.params['target_url'], api_token=module.params['target_api'], user_agent=user_agent) connection_key = remote_system.get(connection_key=True)['connection_key'] remote_array = remote_system.get()['array_name'] array.connect_array(module.params['target_url'], connection_key, [module.params['connection']]) except Exception: module.fail_json(msg="Failed to connect to remote array {0}.".format(remote_array)) module.exit_json(changed=changed)
class ArrayReport: def __init__(self, address, token, name): self.client = FlashArray(address, api_token=token) self.name = name def return_array_space(self, time): return self.client.get(space=True, historical=time) def return_host_groups(self): return self.client.list_hgroups(connect=True) def set_volumes(self): logger.info("Grouping Volumes by Host Group") data = self.return_host_groups() self.groups = {} for each in data: try: self.groups[each['name']].append(each['vol']) except: self.groups[each['name']] = [] self.groups[each['name']].append(each['vol']) return self.groups def ret_volumes(self): return self.set_volumes() def get_historical(self): self.set_volumes() self.vol_history = {} self.hostg_vol = {} for group in self.groups: self.hostg_vol[group] = {} for vol_name in self.groups[group]: try: vol_hist = self.client.get_volume(vol_name, space=True, historical='1y') logger.info("Getting Volume History for volume: " + vol_name) tmphist = {} for vol_entry in vol_hist: if vol_entry['total'] == None: vol_entry['total'] = 0 if vol_entry['snapshots'] == None: vol_entry['snapshots'] = 0 if vol_entry['size'] == None: vol_entry['size'] = 0 tmphist[vol_entry['time']] = vol_entry self.vol_history[vol_name] = tmphist self.hostg_vol[group][vol_name] = vol_hist # self.hostg_vol[group][vol['name']] = tmphist except Exception as e: pass return self.vol_history def calc_volumes(self): for group in self.groups: for volume in self.groups[group]: pass def calc_hgroups(self): logger.info("Calculating Host Group Data from Volume History") self.get_historical() self.all_gps = {} for group in self.groups: logger.info("Calculating for Group: " + group) # Find all the sample times # First get a set of all times that exist for volumes # in this host group times = set() for volume in self.groups[group]: try: for htime in self.vol_history[volume]: # print(htime) times.add(htime) except: pass self.all_gps[group] = {} for time in times: total = 0 snapshots = 0 size = 0 try: for volume in self.groups[group]: total += self.vol_history[volume][time]['total'] snapshots += self.vol_history[volume][time][ 'snapshots'] size += self.vol_history[volume][time]['size'] except: pass try: self.all_gps[group][time]['total'] = total self.all_gps[group][time]['snapshots'] = snapshots self.all_gps[group][time]['size'] = size self.all_gps[group][time]['date'] = time except: self.all_gps[group][time] = {} self.all_gps[group][time]['total'] = total self.all_gps[group][time]['snapshots'] = snapshots self.all_gps[group][time]['size'] = size self.all_gps[group][time]['date'] = time self.oput = {} for each in self.all_gps: self.oput[each] = {} for gp in self.all_gps[each]: dto = datetime.strptime(gp, '%Y-%m-%dT%H:%M:%SZ') out = dto.timestamp() self.oput[each][out] = self.all_gps[each][gp] ret_out = {} for group in self.oput: ret_out[group] = [] for tstamp in sorted(self.oput[group].keys()): ret_out[group].append(self.oput[group][tstamp]) self.calculated_hgroups = ret_out def build_series_data(self, group): volumes = self.groups[group] ret_data = {} for volume in volumes: try: ret_data[volume] = self.hostg_vol[group][volume] except: pass return ret_data
pass while not password: try: password = getpass.getpass() except EOFError: PrintWarning('Password may not be empty... try again...') if not options.array: parser.error("Array not provided") else: array = FlashArray(options.array, username, password) ### Verify Array ### try: array_info = array.get() print "FlashArray {} (version {}) REST session established!".format( array_info['array_name'], array_info['version']) except: print "Array not connected" sys.exit(1) with open(properties) as json_data_file: vols = json.load(json_data_file) ### Create the Volumes ### vols = createAsmVols(array,oracleServer,vols) ### Attach Volumes to Array Hostgroup #### connectVols(array, vols, hostgroup)