45 lines
1.3 KiB
Python
Raw Normal View History

# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
"""
Connect to an OpenStack cloud.
For a full guide see TODO(etoews):link to docs on developer.openstack.org
"""
from openstack import connection
from openstack import profile
class Opts(object):
def __init__(self, cloud='hp', debug=False):
self.cloud = cloud
self.debug = debug
def create_connection_from_config():
return connection.from_config(Opts(cloud='test_cloud'))
def create_connection(auth_url, region, project_name, username, password):
prof = profile.Profile()
prof.set_region(profile.Profile.ALL, region)
return connection.Connection(
profile=prof,
user_agent='examples',
auth_url=auth_url,
project_name=project_name,
username=username,
password=password
)