def get_host_info_specific_args(self, region, search_pattern, get_all=False, private_ip=None): filters = [ { "Name": "instance-state-name", "Values": ["running"] } ] # If no argument passed, assume full scan. if is_valid_ip_address(search_pattern): filters.append({ "Name": "private-ip-address", "Values": [search_pattern] }) elif search_pattern: filters.append({ "Name": "tag:Name", "Values": [search_pattern] }) instances = [] for _, client in self._get_clients(region=region).items(): instances.extend(list(client.instances.filter(Filters=filters))) results = [] for instance in instances: data = instance.meta.data if private_ip is not None and private_ip != data["PrivateIpAddress"]: logging.warn("Node name {} is not unique. Expected IP {}, got IP {}".format( search_pattern, private_ip, data["PrivateIpAddress"])) continue zone = data["Placement"]["AvailabilityZone"] name_tags = None server_tags = None launched_by_tags = None if data.get("Tags") is not None: # Server Type is an optinal flag only for cluster servers. server_tags = [t["Value"] for t in data["Tags"] if t["Key"] == "yb-server-type"] name_tags = [t["Value"] for t in data["Tags"] if t["Key"] == "Name"] launched_by_tags = [t["Value"] for t in data["Tags"] if t["Key"] == "launched-by"] result = dict( id=data.get("InstanceId", None), name=name_tags[0] if name_tags else None, public_ip=data.get("PublicIpAddress", None), private_ip=data["PrivateIpAddress"], public_dns=data["PublicDnsName"], private_dns=data["PrivateDnsName"], launch_time=data["LaunchTime"].isoformat(), zone=zone, subnet=data["SubnetId"], region=region if region is not None else zone[:-1], instance_type=data["InstanceType"], server_type=server_tags[0] if server_tags else None, launched_by=launched_by_tags[0] if launched_by_tags else None, vpc=data["VpcId"], ) if not get_all: return result results.append(result) return results
def get_host_info_specific_args(self, region, search_pattern, get_all=False, private_ip=None, filters=None, node_uuid=None): if not filters: filters = [{"Name": "instance-state-name", "Values": ["running"]}] # If no argument passed, assume full scan. if is_valid_ip_address(search_pattern): filters.append({ "Name": "private-ip-address", "Values": [search_pattern] }) elif search_pattern: filters.append({"Name": "tag:Name", "Values": [search_pattern]}) if node_uuid: filters.append({"Name": "tag:node-uuid", "Values": [node_uuid]}) instances = [] for _, client in self._get_clients(region=region).items(): instances.extend(list(client.instances.filter(Filters=filters))) results = [] for instance in instances: data = instance.meta.data if private_ip is not None and private_ip != data[ "PrivateIpAddress"]: logging.warn( "Node name {} is not unique. Expected IP {}, got IP {}". format(search_pattern, private_ip, data["PrivateIpAddress"])) continue zone = data["Placement"]["AvailabilityZone"] name_tags = None server_tags = None launched_by_tags = None if data.get("Tags") is not None: # Server Type is an optinal flag only for cluster servers. server_tags = [ t["Value"] for t in data["Tags"] if t["Key"] == "yb-server-type" ] name_tags = [ t["Value"] for t in data["Tags"] if t["Key"] == "Name" ] launched_by_tags = [ t["Value"] for t in data["Tags"] if t["Key"] == "launched-by" ] node_uuid_tags = [ t["Value"] for t in data["Tags"] if t["Key"] == "node-uuid" ] universe_uuid_tags = [ t["Value"] for t in data["Tags"] if t["Key"] == "universe-uuid" ] disks = data.get("BlockDeviceMappings") root_vol = next(disk for disk in disks if disk.get("DeviceName") == ROOT_VOLUME_LABEL) primary_private_ip = None secondary_private_ip = None primary_subnet = None secondary_subnet = None network_interfaces = data.get("NetworkInterfaces") for interface in network_interfaces: if interface.get("Attachment").get("DeviceIndex") == 0: primary_private_ip = interface.get("PrivateIpAddress") primary_subnet = interface.get("SubnetId") elif interface.get("Attachment").get("DeviceIndex") == 1: secondary_private_ip = interface.get("PrivateIpAddress") secondary_subnet = interface.get("SubnetId") result = dict( id=data.get("InstanceId", None), name=name_tags[0] if name_tags else None, public_ip=data.get("PublicIpAddress", None), private_ip=primary_private_ip, secondary_private_ip=secondary_private_ip, public_dns=data["PublicDnsName"], private_dns=data["PrivateDnsName"], launch_time=data["LaunchTime"].isoformat(), zone=zone, subnet=primary_subnet, secondary_subnet=secondary_subnet, region=region if region is not None else zone[:-1], instance_type=data["InstanceType"], server_type=server_tags[0] if server_tags else None, launched_by=launched_by_tags[0] if launched_by_tags else None, node_uuid=node_uuid_tags[0] if node_uuid_tags else None, universe_uuid=universe_uuid_tags[0] if universe_uuid_tags else None, vpc=data["VpcId"], root_volume=root_vol["Ebs"]["VolumeId"]) if not get_all: return result results.append(result) return results