def DisplayInstances(instances, compartmentName, instancetype): for instance in instances: privateips = "" publicips = "" instancetypename = "" tagtxt = "" OS = "" #print (instance) # Handle details for Compute Instances if instancetype == "Compute": OCPU, MEM, SSD = shapes.ComputeShape(instance.shape) response = ComputeClient.list_vnic_attachments( compartment_id=instance.compartment_id, instance_id=instance.id) vnics = response.data try: for vnic in vnics: responsenic = NetworkClient.get_vnic(vnic_id=vnic.vnic_id) nicinfo = responsenic.data privateips = privateips + nicinfo.private_ip + " " publicips = publicips + nicinfo.public_ip + " " except: privateips = NoValueString publicips = NoValueString instancetypename = "Compute" version = NoValueString namespaces = instance.defined_tags response = ComputeClient.get_image( instance.source_details.image_id) imagedetails = response.data OS = imagedetails.display_name for customertag in customertags: try: tagtxt = tagtxt + "," + namespaces[customertag[0]][ customertag[1]] except: tagtxt = tagtxt + "," + NoValueString # Handle details for Database Instances if instancetype == "DB": OCPU, MEM, SSD = shapes.ComputeShape(instance.shape) OCPU = instance.cpu_core_count # Overwrite Shape's CPU count, with DB enabled CPU count response = databaseClient.list_db_nodes( compartment_id=instance.compartment_id, db_system_id=instance.id) dbnodes = response.data try: for dbnode in dbnodes: responsenic = NetworkClient.get_vnic( vnic_id=dbnode.vnic_id) nicinfo = responsenic.data privateips = privateips + nicinfo.private_ip + " " publicips = publicips + nicinfo.public_ip + " " except: privateips = NoValueString publicips = NoValueString instancetypename = "DB " + instance.database_edition version = instance.version for customertag in customertags: tagtxt = tagtxt + "," + NoValueString OS = "Oracle Linux 6.8" # Remove prefix from AD Domain prefix, AD = instance.availability_domain.split(":") line = "{},{},{},{},{},{},{},{},{},{},{},{},{}{}".format( instance.display_name, instance.lifecycle_state, instancetypename, version, OS, instance.shape, OCPU, MEM, SSD, compartmentName, AD, privateips, publicips, tagtxt) print(line) report.write(line + EndLine)
def DisplayInstances(instances, compartmentName, instancetype, regionname): for instance in instances: # publicips = "" privateips = "" instancetypename = "" tagtxt = "" OS = "" LicenseIncluded = "" #print (instance) # Handle details for Compute Instances if instancetype == "Compute": OCPU, MEM, SSD = shapes.ComputeShape(instance.shape) response = ComputeClient.list_vnic_attachments( compartment_id=instance.compartment_id, instance_id=instance.id) vnics = response.data try: for vnic in vnics: responsenic = NetworkClient.get_vnic(vnic_id=vnic.vnic_id) nicinfo = responsenic.data # publicips = publicips + nicinfo.public_ip + " " privateips = privateips + nicinfo.private_ip + " " except: privateips = NoValueString # publicips = NoValueString instancetypename = "Compute" version = NoValueString namespaces = instance.defined_tags shape = instance.shape # Get OS Details try: response = ComputeClient.get_image( instance.source_details.image_id) imagedetails = response.data OS = imagedetails.display_name except: OS = NoValueString prefix, AD = instance.availability_domain.split(":") LicenseIncluded = "BYOL" # Handle details for Database Instances if instancetype == "DB": OCPU, MEM, SSD = shapes.ComputeShape(instance.shape) OCPU = instance.cpu_core_count # Overwrite Shape's CPU count, with DB enabled CPU count response = databaseClient.list_db_nodes( compartment_id=instance.compartment_id, db_system_id=instance.id) dbnodes = response.data try: for dbnode in dbnodes: responsenic = NetworkClient.get_vnic( vnic_id=dbnode.vnic_id) nicinfo = responsenic.data # publicips = publicips + nicinfo.public_ip + " " privateips = privateips + nicinfo.private_ip + " " except: # publicips = NoValueString privateips = NoValueString if instance.license_model == "LICENSE_INCLUDED": LicenseIncluded = "YES" else: LicenseIncluded = "BYOL" instancetypename = "DB " + instance.database_edition version = instance.version OS = "Oracle Linux 6.8" shape = instance.shape prefix, AD = instance.availability_domain.split(":") # Handle details for Autonomous Database (ATP) if instancetype == "ATP": OCPU = instance.cpu_core_count MEM = NoValueString SSD = instance.data_storage_size_in_tbs instancetypename = "ATP" version = NoValueString OS = NoValueString shape = "ATP" AD = regionname.upper() # publicips = NoValueString privateips = NoValueString if instance.license_model == "LICENSE_INCLUDED": LicenseIncluded = "YES" else: LicenseIncluded = "BYOL" # Handle details for Autonomous Database (ADW) if instancetype == "ADW": OCPU = instance.cpu_core_count MEM = NoValueString SSD = instance.data_storage_size_in_tbs instancetypename = "ADW" version = NoValueString OS = NoValueString shape = "ADW" AD = regionname.upper() # publicips = NoValueString privateips = NoValueString if instance.license_model == "LICENSE_INCLUDED": LicenseIncluded = "YES" else: LicenseIncluded = "BYOL" try: namespaces = instance.defined_tags for customertag in customertags: try: tagtxt = tagtxt + FieldSeperator + namespaces[ customertag[0]][customertag[1]] except: tagtxt = tagtxt + FieldSeperator + NoValueString except: tagtxt = "" # No Tags #line = "{},{},{},{},{},{},{},{},{},{},{},{},{},{}{}".format(instance.display_name, instance.lifecycle_state, instancetypename, LicenseIncluded, version, OS, shape, OCPU, MEM, SSD, compartmentName, AD, privateips, tagtxt) line = "{}{}".format(instance.display_name, FieldSeperator) line = "{}{}{}".format(line, instance.lifecycle_state, FieldSeperator) line = "{}{}{}".format(line, instancetypename, FieldSeperator) line = "{}{}{}".format(line, LicenseIncluded, FieldSeperator) line = "{}{}{}".format(line, version, FieldSeperator) line = "{}{}{}".format(line, OS, FieldSeperator) line = "{}{}{}".format(line, shape, FieldSeperator) line = "{}{}{}".format(line, OCPU, FieldSeperator) line = "{}{}{}".format(line, MEM, FieldSeperator) line = "{}{}{}".format(line, SSD, FieldSeperator) line = "{}{}{}".format(line, compartmentName, FieldSeperator) line = "{}{}{}".format(line, AD, FieldSeperator) line = "{}{}{}".format(line, privateips, FieldSeperator) line = "{}{}".format(line, tagtxt) print(line) report.write(line + EndLine)