Skip to content

Instantly share code, notes, and snippets.

@cloudnull
Created May 26, 2015 01:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cloudnull/0b4aae4e65d606b8e80f to your computer and use it in GitHub Desktop.
Save cloudnull/0b4aae4e65d606b8e80f to your computer and use it in GitHub Desktop.
Get the URL for the latest LXC image. Basic processor, uses the ";" separated characteristics to search for and find the path of the image rootfs. Presently the image search is hard coded to [ ubuntu;trusty;amd64;default ] .
#!/usr/bin/env python
import urlparse
import requests
LXC_IMAGE_INDEX = 'https://images.linuxcontainers.org:8443/meta/1.0/index-system'
INDEX_URL = urlparse.urlparse(LXC_IMAGE_INDEX)
def main(image='ubuntu;trusty;amd64;default'):
req = requests.get(LXC_IMAGE_INDEX)
image_entry = [i for i in req.content.split() if image in i][0].split(';')
image_path = urlparse.urljoin('%s://%s' %(INDEX_URL.scheme, INDEX_URL.netloc), image_entry[-1])
if not image_path.endswith('/'):
image_path = '%s/' % image_path
return urlparse.urljoin(image_path, 'rootfs.tar.xz')
if __name__ == '__main__':
print(main())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment