Created
May 26, 2015 01:44
-
-
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 ] .
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 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