Created
November 20, 2013 09:57
-
-
Save sebgoa/7560629 to your computer and use it in GitHub Desktop.
libcloudshell
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 characters
#!/usr/bin/env python | |
import code | |
import sys | |
import os | |
import urlparse | |
from libcloud.compute.types import Provider | |
from libcloud.compute.providers import get_driver | |
import libcloud.security as sec | |
from libcloud.compute.deployment import ScriptDeployment | |
from libcloud.compute.deployment import MultiStepDeployment | |
from IPython.terminal.embed import InteractiveShellEmbed | |
Driver = get_driver(Provider.CLOUDSTACK) | |
apikey=os.getenv('EXOSCALE_API_KEY') | |
secretkey=os.getenv('EXOSCALE_SECRET_KEY') | |
endpoint=os.getenv('EXOSCALE_ENDPOINT') | |
host=urlparse.urlparse(endpoint).netloc | |
path=urlparse.urlparse(endpoint).path | |
conn=Driver(key=apikey,secret=secretkey,secure=True,host=host,path=path) | |
def listimages(): | |
for i in conn.list_images(): | |
print i.id, i.extra['displaytext'] | |
def listsizes(): | |
for i in conn.list_sizes(): | |
print i.id, i.name | |
def getimage(id): | |
return [i for i in conn.list_images() if i.id == id][0] | |
def getsize(id): | |
return [i for i in conn.list_sizes() if i.id == id][0] | |
script=ScriptDeployment("touch /tmp/linuxcon") | |
image=getimage('a17b40d6-83e4-4f2a-9ef0-dce6af575789') | |
size=getsize('71004023-bb72-4a97-b1e9-bc66dfce9470') | |
msd = MultiStepDeployment([script]) | |
class shell(code.InteractiveConsole): | |
def __init__(self,locals=None): | |
code.InteractiveConsole.__init__(self,locals=locals) | |
return | |
#console = shell(locals()) | |
#console.interact("Hello LibCloud Shell !!"+ "\n"+"You are running at: %s" % endpoint) | |
ipshell = InteractiveShellEmbed(banner1="Hello LibCloud Shell !!"+ "\n"+"You are running at: %s" % endpoint) | |
ipshell() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment