1 # Copyright (c) 2016 Cable Television Laboratories, Inc. ("CableLabs")
2 # and others. All rights reserved.
4 # Licensed under the Apache License, Version 2.0 (the "License");
5 # you may not use this file except in compliance with the License.
6 # You may obtain a copy of the License at:
8 # http://www.apache.org/licenses/LICENSE-2.0
10 # Unless required by applicable law or agreed to in writing, software
11 # distributed under the License is distributed on an "AS IS" BASIS,
12 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 # See the License for the specific language governing permissions and
14 # limitations under the License.
15 __author__ = 'spisarski'
20 Represents the credentials required to connect with OpenStack servers
23 def __init__(self, username, password, auth_url, project_name, identity_api_version=2, image_api_version=1,
24 network_api_version=2, compute_api_version=2, user_domain_id='default', project_domain_id='default',
28 :param username: The user (required)
29 :param password: The user's password (required)
30 :param auth_url: The OpenStack cloud's authorization URL (required)
31 :param project_name: The project/tenant name
32 :param identity_api_version: The OpenStack's API version to use for Keystone clients
33 :param image_api_version: The OpenStack's API version to use for Glance clients
34 :param network_api_version: The OpenStack's API version to use for Neutron clients
35 :param compute_api_version: The OpenStack's API version to use for Nova clients
36 :param user_domain_id: Used for v3 APIs
37 :param project_domain_id: Used for v3 APIs
38 :param proxy_settings: instance of os_credentials.ProxySettings class
40 self.username = username
41 self.password = password
42 self.auth_url = auth_url
43 self.project_name = project_name
44 self.identity_api_version = identity_api_version
45 self.image_api_version = image_api_version
46 self.network_api_version = network_api_version
47 self.compute_api_version = compute_api_version
48 self.user_domain_id = user_domain_id
49 self.project_domain_id = project_domain_id
50 self.proxy_settings = proxy_settings
52 if self.proxy_settings and not isinstance(self.proxy_settings, ProxySettings):
53 raise Exception('proxy_settings must be an instance of the class ProxySettings')
56 auth_url_tokens = self.auth_url.split('/')
57 last_token = auth_url_tokens[len(auth_url_tokens) - 1]
58 if len(last_token) == 0:
59 last_token = auth_url_tokens[len(auth_url_tokens) - 2]
61 if not last_token.startswith('v'):
62 raise Exception('auth_url last toke must start with \'v\'')
65 """Converts object to a string"""
66 return 'OSCreds - username=' + str(self.username) + \
67 ', password=' + str(self.password) + \
68 ', auth_url=' + str(self.auth_url) + \
69 ', project_name=' + str(self.project_name) + \
70 ', identity_api_version=' + str(self.identity_api_version) + \
71 ', image_api_version=' + str(self.image_api_version) + \
72 ', network_api_version=' + str(self.network_api_version) + \
73 ', compute_api_version=' + str(self.compute_api_version) + \
74 ', user_domain_id=' + str(self.user_domain_id) + \
75 ', proxy_settings=' + str(self.proxy_settings)
80 Represents the information required for sending traffic (HTTP & SSH) through a proxy
83 def __init__(self, host, port, ssh_proxy_cmd=None):
86 :param host: the HTTP proxy host
87 :param port: the HTTP proxy port
88 :param ssh_proxy_cmd: the SSH proxy command string (optional)
90 # TODO - Add necessary fields here when adding support for secure proxies
94 self.ssh_proxy_cmd = ssh_proxy_cmd
96 if not self.host and not self.port:
97 raise Exception('host & port are required')
100 """Converts object to a string"""
101 return 'ProxySettings - host=' + str(self.host) + \
102 ', port=' + str(self.port) + \
103 ', ssh_proxy_cmd=' + str(self.ssh_proxy_cmd)