Last active
January 18, 2017 17:43
-
-
Save afgane/f9c0c729a36830125ed4 to your computer and use it in GitHub Desktop.
Set the variables at the top and connect to a desired cloud via `boto` library.
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
import boto | |
import boto.s3.connection | |
from boto.ec2.regioninfo import RegionInfo | |
# Provide access info for your cloud and your account | |
A_KEY = "" | |
S_KEY = "" | |
region_name = 'Chameleon' | |
region_endpoint = 'openstack.tacc.chameleoncloud.org' | |
ec2_conn_path = "/services/Cloud" | |
ec2_port = 8773 | |
is_secure = True | |
s3_host = 'openstack.tacc.chameleoncloud.org' | |
s3_port = 8888 | |
s3_conn_path = '/' | |
# Create a connection object for the EC2 service (i.e., VM instances) | |
r = RegionInfo(name=region_name, endpoint=region_endpoint) | |
ec2_conn = boto.connect_ec2(aws_access_key_id=A_KEY, | |
aws_secret_access_key=S_KEY, | |
is_secure=is_secure, | |
region=r, | |
port=ec2_port, | |
path=ec2_conn_path, | |
validate_certs=False) | |
# Create a connection object for the S3 service (i.e., object store) | |
calling_format = boto.s3.connection.OrdinaryCallingFormat() | |
s3_conn = boto.connect_s3(aws_access_key_id=A_KEY, | |
aws_secret_access_key=S_KEY, | |
is_secure=is_secure, | |
host=s3_host, | |
port=s3_port, | |
calling_format=calling_format, | |
path=s3_conn_path) | |
# Test your connection and get an image ID | |
img_list = ec2_conn.get_all_images() | |
for img in img_list: | |
print(img.id, img.name) | |
# Test the S3 connection as well | |
bl = s3_conn.get_all_buckets() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment