def instances(self): instances = set() with open(self.data_file, 'r') as data_file: data = json.load(data_file) for results_dict in data[InstanceType.VM]['results']: for event_dict in results_dict['events']: hostname = event_dict['hostname'] address = event_dict['ipV4Address'].strip().split("/")[0] if hostname is None: hostname = address instances.add( Instance(hostname, address, None, self.name, None, InstanceType.VM)) for results_dict in data[InstanceType.ECS]['results']: for event_dict in results_dict['events']: container_name = event_dict['containerName'] container_id = event_dict['containerId'] hostname = event_dict['hostname'] address = parseIpFromHostname(hostname) instances.add( Instance(container_name, address, None, self.name, container_id, InstanceType.ECS)) return self.filter(list(instances))
def instances(self): data = self.__ec2_search(stub=True) instances = [] for reservation in data['Reservations']: for instance in reservation['Instances']: # try to find the best dns/ip address to reach this box address = None if instance.get('PublicDnsName'): address = instance['PublicDnsName'] elif instance.get('PrivateIpAddress'): address = instance['PrivateIpAddress'] # try to find the best field to match a name against aliases = list() if 'Tags' in list(instance.keys()): for tagDict in instance['Tags']: if tagDict['Key'] == 'Name': aliases.insert(0, tagDict['Value']) else: aliases.append(tagDict['Value']) if instance['PublicDnsName']: aliases.append(instance['PublicDnsName']) if instance['PrivateDnsName']: aliases.append(instance['PrivateDnsName']) if instance['InstanceId']: aliases.append(instance['InstanceId']) aliases[:] = [x for x in aliases if x != None] name = aliases.pop(0) # take note of this instance if name != None and address != None: if len(aliases) > 0: instances.append( Instance(name, address, tuple(aliases), self.name, None, InstanceType.VM)) else: instances.append( Instance(name, address, None, self.name, None, InstanceType.VM)) return self.filter(instances)
def instances(self): instances = set() with open(self.data_file, 'r') as data_file: data = json.load(data_file) for results_dict in data['results']: for event_dict in results_dict['events']: hostname = event_dict['hostname'] address = event_dict['ipV4Address'].strip().split("/")[0] if hostname == None: hostname = address instances.add(Instance(hostname, address, None, self.name)) return list(instances)
def instances(self): instances = set() try: with open(self.csv_path, 'r') as csv_file: reader = csv.DictReader(csv_file, fieldnames=self.fields, delimiter=self.delimiter) for row in reader: instances.add( Instance(row['name'].strip(), row['address'].strip(), None, self.name, None, InstanceType.VM)) except IOError as ex: logger.error("Unable to read inventory: %s" % ex) sys.exit(1) return list(instances)