Created
May 1, 2013 15:31
-
-
Save tomellis/5496000 to your computer and use it in GitHub Desktop.
Get Rackspace Cloud Server Public IP Addresses
This file contains 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 characters
#!/usr/bin/env python | |
import os | |
import sys | |
import logging | |
import pyrax | |
import pyrax.exceptions as exc | |
# Set loglevel | |
logging.basicConfig(level=logging.DEBUG) | |
conf = os.path.expanduser("creds") | |
pyrax.set_credential_file(conf, "LON") | |
# Set pointers to cloud services | |
cs = pyrax.cloudservers | |
# Passed server id, returns public ipv4 address | |
def get_public_addr(): | |
servers = cs.servers.list() | |
for server in servers: | |
networks = server.networks["public"] | |
for public_ip in networks: | |
# Return ipv4 address only | |
if '.' in public_ip: | |
print "Name: %s\n ID: %s\n Public IP: %s\n" % (server.name, server.id, public_ip) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Awesome!