Has anyone found an easy way to identify instances that have no server or container attached

I still have a pocket of users that will remove servers from our VMware based clouds with out using Morpheus. This is causing some issues where I have instances without a server attached. I am searching for a way to identify these. I have well over 150 tenants and going through each one is a little tedious. I think I can key on the power status in the compute dataset for unknowns, that will be a rough report as I did have two this morning that were live and showing unknown.

A couple of options. The api instances response includes status. Normally ‘running’ it changes to unknown when the server is deleted in the cloud, not Morpheus. You can apply a querystring filter on status to retrieve only unknown status

Another option would be a custom report. In the instance table, the status column changes from running to unknown, in line with what the API returns. This may be a better way obtain info about all 150 tenants, as all instances for all tenants in Morpheus are in the table and can be identified by the account id

Below is a Python script that will assist you in gathering server information from your environment and presenting it in a CSV file to allow you to investigate further. The script will find any server in the “unknown” power status and tell you the server ID, server name, and what tenant it is located in. Make sure to enter your Morpheus URL and token into the script to give it access to the API.

During my testing, I noticed that the status at the instance level occasionally toggles between “unknown” and “stopped.” We found leveraging the server’s power status is a good workaround for now.

import requests
import json
import csv

url = 'yourURL'

endpoint = 'api/servers?powerState=unknown&vm=true'

token = 'yourtoken'

payload = {}
headers = {
                    'Authorization': f'Bearer {token}'
                                    }
 
 
response = requests.request("GET", url + endpoint, headers=headers, data=payload)
data = json.loads(response.text)
 
 
# Extract relevant data from the JSON response
servers = data['servers']

if servers:
    with open('server_info.csv', 'w', newline='') as csvfile:
        csv_writer = csv.writer(csvfile)
        csv_writer.writerow(['Server ID', 'Server name', 'Tenant', 'Power State'])
        for server in servers:
            server_id = server['id']
            hostname = server['hostname']
            power_state = server['powerState']
            account_name = server['account']['name']
            csv_writer.writerow([server_id, hostname, account_name, power_state])
        print("Server information has been written to server_info.csv successfully.")
else:
    print("No servers found.")

2 Likes

Perfect @Tyler_Boyd :+1: