Created
May 17, 2010 20:30
-
-
Save chmouel/404193 to your computer and use it in GitHub Desktop.
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/jython | |
import sys | |
from org.apache.commons.httpclient.protocol import Protocol | |
from com.vmware.vcloud.sdk import VcloudClient, Organization, Vdc | |
from com.vmware.vcloud.sdk.samples import FakeSSLSocketFactory | |
class VcloudLogin(object): | |
""" | |
VcloudLogin: Login to vcloud class | |
""" | |
vcloudClient = None | |
api_version = None | |
vcloud_url = None | |
def __init__(self, vcloud_url, api_version): | |
# This is needed if you have a self certified certificate | |
# remove it if you have a proper SSL certs. | |
self.setup_fake_ssl() | |
self.vcloud_url = vcloud_url | |
self.api_version = api_version | |
def setup_fake_ssl(self): | |
https = Protocol("https", FakeSSLSocketFactory(), 443) | |
Protocol.registerProtocol("https", https) | |
def login(self, username, password): | |
versions = VcloudClient.getSupportedVersions(self.vcloud_url + "/api/versions") | |
self.vcloudClient = VcloudClient(versions.get(self.api_version)) | |
return self.vcloudClient.login(username, password) | |
if __name__ == '__main__': | |
URL="https://dev.hybridcloud.rackspace.co.uk:443" | |
API_VERSION="0.9" | |
USERNAME="user@organization" | |
PASSWORD="password" | |
vcl = VcloudLogin(URL, API_VERSION) | |
organizations_list = vcl.login(USERNAME, PASSWORD) | |
for org in organizations_list.values(): | |
for vdcLink in \ | |
Organization.getOrganizationByReference(vcl.vcloudClient, org).getVdcLinks(): | |
vdc = Vdc.getVdc(vcl.vcloudClient, vdcLink) | |
print "VDC Href: %s\n" % (vdcLink.getHref()) | |
for vapps in vdc.getVappRefs(): | |
print "Name: %s URL: %s" % (vapps.getName(), vapps.getHref()) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment