Created
          October 29, 2024 19:10 
        
      - 
      
 - 
        
Save zacharygraber/ec88cd0b47c0753b3f0f7ded11cfa780 to your computer and use it in GitHub Desktop.  
Revisions
- 
        
zacharygraber created this gist
Oct 29, 2024 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,20 @@ #!/bin/python3 # Requires the openstacksdk pip package - openstacksdk==4.0.0 import openstack from urllib.request import urlopen import json # Initiate connection to the OpenStack API (get a token) # Expects credentials to be available in "OS_"-prefixed env vars conn = openstack.connect() # Query the OpenStack metadata service to find the UUID of the instance we're currently running on # see https://docs.openstack.org/nova/latest/user/metadata.html response = urlopen("http://169.254.169.254/openstack/latest/meta_data.json") json_data = json.loads(response.read()) # Here's where you could put other fun stuff, like an email/Slack notification to yourself conn.compute.shelve_server(json_data["uuid"])