ec2reporter.py
def create_objects(instances):
    """
    Create and object for each of the instances in the provided list and return a list of instance objects
    populated with the corresponding AWS and custom tag metadata.
    """
    objects = []
    for instance in instances:
        i  = Instance()
        i.AvailabilityZone = instance["Placement"]["AvailabilityZone"]
        i.InstanceId = instance["InstanceId"]
        i.InstanceType = instance["InstanceType"]
        i.State = instance["State"]["Name"]
        i.ImageId = instance["ImageId"]
        i.LaunchTime = str(instance["LaunchTime"]) 
        i.Region = i.AvailabilityZone[0:-1] 
        try:
            i.PrivateIpAddress = instance["PrivateIpAddress"]
        except:
            i.PrivateIpAddress = ""
        try:
            i.KeyName = instance["KeyName"].lower().replace(' ', '')
        except:
            i.KeyName = ""
        try:
            i.PublicIpAddress = instance["PublicIpAddress"]
        except:
            i.PublicIpAddress = ""
        try:
            i.SubnetId = instance["SubnetId"]
        except:
            i.SubnetId = ""
        try:
            i.VpcId = instance["VpcId"]
        except:
            i.VpcId = ""

        for tag in instance["Tags"]:
            if tag['Key'].lower() == 'owner':
                i.Owner = removebadchars(tag['Value'].lower()) 
            elif tag['Key'].lower() == 'name':
                i.Name = removebadchars(tag['Value'].lower())
            elif tag['Key'].lower() == 'technical_contact':
                i.TechnicalContact = removebadchars(tag['Value'].lower())
         
        if not "TechnicalContact" in i.__dict__:
            i.TechnicalContact = ''
        if not "Owner" in i.__dict__:
            i.Owner = ''
        if not "Name" in i.__dict__:
            i.Name = ''
        
        objects.append(i)

    return(objects)

    Create and object for each of the instances in the provided list and return a list of instance objects
    populated with the corresponding AWS and custom tag metadata.
    
Create and object for each of the instances in the provided list and return a list of instance objects
populated with the corresponding AWS and custom tag metadata.
Create and object for each of the instances in the provided list and return a list of instance objects populated with the corresponding AWS and custom tag metadata .
def create_objects(instances):
    objects = []
    for instance in instances:
        i  = Instance()
        i.AvailabilityZone = instance["Placement"]["AvailabilityZone"]
        i.InstanceId = instance["InstanceId"]
        i.InstanceType = instance["InstanceType"]
        i.State = instance["State"]["Name"]
        i.ImageId = instance["ImageId"]
        i.LaunchTime = str(instance["LaunchTime"]) 
        i.Region = i.AvailabilityZone[0:-1] 
        try:
            i.PrivateIpAddress = instance["PrivateIpAddress"]
        except:
            i.PrivateIpAddress = ""
        try:
            i.KeyName = instance["KeyName"].lower().replace(' ', '')
        except:
            i.KeyName = ""
        try:
            i.PublicIpAddress = instance["PublicIpAddress"]
        except:
            i.PublicIpAddress = ""
        try:
            i.SubnetId = instance["SubnetId"]
        except:
            i.SubnetId = ""
        try:
            i.VpcId = instance["VpcId"]
        except:
            i.VpcId = ""
        for tag in instance["Tags"]:
            if tag['Key'].lower() == 'owner':
                i.Owner = removebadchars(tag['Value'].lower()) 
            elif tag['Key'].lower() == 'name':
                i.Name = removebadchars(tag['Value'].lower())
            elif tag['Key'].lower() == 'technical_contact':
                i.TechnicalContact = removebadchars(tag['Value'].lower())
        if not "TechnicalContact" in i.__dict__:
            i.TechnicalContact = ''
        if not "Owner" in i.__dict__:
            i.Owner = ''
        if not "Name" in i.__dict__:
            i.Name = ''
        objects.append(i)
    return(objects)
def create_objects ( instances ) : objects = [ ] for instance in instances : i = Instance ( ) i . AvailabilityZone = instance [ "Placement" ] [ "AvailabilityZone" ] i . InstanceId = instance [ "InstanceId" ] i . InstanceType = instance [ "InstanceType" ] i . State = instance [ "State" ] [ "Name" ] i . ImageId = instance [ "ImageId" ] i . LaunchTime = str ( instance [ "LaunchTime" ] ) i . Region = i . AvailabilityZone [ 0 : - 1 ] try : i . PrivateIpAddress = instance [ "PrivateIpAddress" ] except : i . PrivateIpAddress = "" try : i . KeyName = instance [ "KeyName" ] . lower ( ) . replace ( ' ' , '' ) except : i . KeyName = "" try : i . PublicIpAddress = instance [ "PublicIpAddress" ] except : i . PublicIpAddress = "" try : i . SubnetId = instance [ "SubnetId" ] except : i . SubnetId = "" try : i . VpcId = instance [ "VpcId" ] except : i . VpcId = "" for tag in instance [ "Tags" ] : if tag [ 'Key' ] . lower ( ) == 'owner' : i . Owner = removebadchars ( tag [ 'Value' ] . lower ( ) ) elif tag [ 'Key' ] . lower ( ) == 'name' : i . Name = removebadchars ( tag [ 'Value' ] . lower ( ) ) elif tag [ 'Key' ] . lower ( ) == 'technical_contact' : i . TechnicalContact = removebadchars ( tag [ 'Value' ] . lower ( ) ) if not "TechnicalContact" in i . __dict__ : i . TechnicalContact = '' if not "Owner" in i . __dict__ : i . Owner = '' if not "Name" in i . __dict__ : i . Name = '' objects . append ( i ) return ( objects )
Create and object for each of the instances in the provided list and return a list of instance objects
populated with the corresponding AWS and custom tag metadata.
Create and object for each of the instances in the provided list and return a list of instance objects populated with the corresponding AWS and custom tag metadata .
"""
    Create and object for each of the instances in the provided list and return a list of instance objects
    populated with the corresponding AWS and custom tag metadata.
    """
instances