Blackify everything else
Black used with the '-l 79 -S' flags. A future change will ignore this commit in git-blame history by adding a 'git-blame-ignore-revs' file. Change-Id: Ie106a5cec8831e113a2b764b62b712a205e3153b Signed-off-by: Stephen Finucane <stephenfin@redhat.com>
This commit is contained in:
parent
004c7352d0
commit
a36f514295
@ -77,10 +77,13 @@ htmlhelp_basename = 'openstacksdkdoc'
|
||||
# (source start file, target name, title, author, documentclass
|
||||
# [howto/manual]).
|
||||
latex_documents = [
|
||||
('index',
|
||||
'doc-openstacksdk.tex',
|
||||
'OpenStackSDK Documentation',
|
||||
'OpenStack Foundation', 'manual'),
|
||||
(
|
||||
'index',
|
||||
'doc-openstacksdk.tex',
|
||||
'OpenStackSDK Documentation',
|
||||
'OpenStack Foundation',
|
||||
'manual',
|
||||
),
|
||||
]
|
||||
|
||||
# Allow deeper levels of nesting for \begin...\end stanzas
|
||||
|
@ -16,11 +16,11 @@ from openstack import cloud as openstack
|
||||
openstack.enable_logging(debug=True)
|
||||
|
||||
for cloud_name, region_name in [
|
||||
('my-vexxhost', 'ca-ymq-1'),
|
||||
('my-citycloud', 'Buf1'),
|
||||
('my-internap', 'ams01')]:
|
||||
('my-vexxhost', 'ca-ymq-1'),
|
||||
('my-citycloud', 'Buf1'),
|
||||
('my-internap', 'ams01'),
|
||||
]:
|
||||
# Initialize cloud
|
||||
cloud = openstack.connect(
|
||||
cloud=cloud_name, region_name=region_name)
|
||||
cloud = openstack.connect(cloud=cloud_name, region_name=region_name)
|
||||
for server in cloud.search_servers('my-server'):
|
||||
cloud.delete_server(server, wait=True, delete_ips=True)
|
||||
|
@ -16,20 +16,31 @@ from openstack import cloud as openstack
|
||||
openstack.enable_logging(debug=True)
|
||||
|
||||
for cloud_name, region_name, image, flavor_id in [
|
||||
('my-vexxhost', 'ca-ymq-1', 'Ubuntu 16.04.1 LTS [2017-03-03]',
|
||||
'5cf64088-893b-46b5-9bb1-ee020277635d'),
|
||||
('my-citycloud', 'Buf1', 'Ubuntu 16.04 Xenial Xerus',
|
||||
'0dab10b5-42a2-438e-be7b-505741a7ffcc'),
|
||||
('my-internap', 'ams01', 'Ubuntu 16.04 LTS (Xenial Xerus)',
|
||||
'A1.4')]:
|
||||
(
|
||||
'my-vexxhost',
|
||||
'ca-ymq-1',
|
||||
'Ubuntu 16.04.1 LTS [2017-03-03]',
|
||||
'5cf64088-893b-46b5-9bb1-ee020277635d',
|
||||
),
|
||||
(
|
||||
'my-citycloud',
|
||||
'Buf1',
|
||||
'Ubuntu 16.04 Xenial Xerus',
|
||||
'0dab10b5-42a2-438e-be7b-505741a7ffcc',
|
||||
),
|
||||
('my-internap', 'ams01', 'Ubuntu 16.04 LTS (Xenial Xerus)', 'A1.4'),
|
||||
]:
|
||||
# Initialize cloud
|
||||
cloud = openstack.connect(
|
||||
cloud=cloud_name, region_name=region_name)
|
||||
cloud = openstack.connect(cloud=cloud_name, region_name=region_name)
|
||||
|
||||
# Boot a server, wait for it to boot, and then do whatever is needed
|
||||
# to get a public ip for it.
|
||||
server = cloud.create_server(
|
||||
'my-server', image=image, flavor=dict(id=flavor_id),
|
||||
wait=True, auto_ip=True)
|
||||
'my-server',
|
||||
image=image,
|
||||
flavor=dict(id=flavor_id),
|
||||
wait=True,
|
||||
auto_ip=True,
|
||||
)
|
||||
# Delete it - this is a demo
|
||||
cloud.delete_server(server, wait=True, delete_ips=True)
|
||||
|
@ -16,21 +16,24 @@ from openstack import cloud as openstack
|
||||
openstack.enable_logging(debug=True)
|
||||
|
||||
for cloud_name, region_name, image, flavor in [
|
||||
('my-vexxhost', 'ca-ymq-1',
|
||||
'Ubuntu 16.04.1 LTS [2017-03-03]', 'v1-standard-4'),
|
||||
('my-citycloud', 'Buf1',
|
||||
'Ubuntu 16.04 Xenial Xerus', '4C-4GB-100GB'),
|
||||
('my-internap', 'ams01',
|
||||
'Ubuntu 16.04 LTS (Xenial Xerus)', 'A1.4')]:
|
||||
(
|
||||
'my-vexxhost',
|
||||
'ca-ymq-1',
|
||||
'Ubuntu 16.04.1 LTS [2017-03-03]',
|
||||
'v1-standard-4',
|
||||
),
|
||||
('my-citycloud', 'Buf1', 'Ubuntu 16.04 Xenial Xerus', '4C-4GB-100GB'),
|
||||
('my-internap', 'ams01', 'Ubuntu 16.04 LTS (Xenial Xerus)', 'A1.4'),
|
||||
]:
|
||||
# Initialize cloud
|
||||
cloud = openstack.connect(
|
||||
cloud=cloud_name, region_name=region_name)
|
||||
cloud = openstack.connect(cloud=cloud_name, region_name=region_name)
|
||||
cloud.delete_server('my-server', wait=True, delete_ips=True)
|
||||
|
||||
# Boot a server, wait for it to boot, and then do whatever is needed
|
||||
# to get a public ip for it.
|
||||
server = cloud.create_server(
|
||||
'my-server', image=image, flavor=flavor, wait=True, auto_ip=True)
|
||||
'my-server', image=image, flavor=flavor, wait=True, auto_ip=True
|
||||
)
|
||||
print(server.name)
|
||||
print(server['name'])
|
||||
cloud.pprint(server)
|
||||
|
@ -11,8 +11,8 @@
|
||||
# under the License.
|
||||
|
||||
from openstack import cloud as openstack
|
||||
|
||||
openstack.enable_logging(debug=True)
|
||||
|
||||
cloud = openstack.connect(
|
||||
cloud='my-vexxhost', region_name='ca-ymq-1')
|
||||
cloud = openstack.connect(cloud='my-vexxhost', region_name='ca-ymq-1')
|
||||
cloud.get_image('Ubuntu 16.04.1 LTS [2017-03-03]')
|
||||
|
@ -11,9 +11,10 @@
|
||||
# under the License.
|
||||
|
||||
from openstack import cloud as openstack
|
||||
|
||||
openstack.enable_logging()
|
||||
|
||||
cloud = openstack.connect(cloud='fuga', region_name='cystack')
|
||||
cloud.pprint([
|
||||
image for image in cloud.list_images()
|
||||
if 'ubuntu' in image.name.lower()])
|
||||
cloud.pprint(
|
||||
[image for image in cloud.list_images() if 'ubuntu' in image.name.lower()]
|
||||
)
|
||||
|
@ -11,8 +11,8 @@
|
||||
# under the License.
|
||||
|
||||
from openstack import cloud as openstack
|
||||
|
||||
openstack.enable_logging(http_debug=True)
|
||||
|
||||
cloud = openstack.connect(
|
||||
cloud='my-vexxhost', region_name='ca-ymq-1')
|
||||
cloud = openstack.connect(cloud='my-vexxhost', region_name='ca-ymq-1')
|
||||
cloud.get_image('Ubuntu 16.04.1 LTS [2017-03-03]')
|
||||
|
@ -11,6 +11,7 @@
|
||||
# under the License.
|
||||
|
||||
from openstack import cloud as openstack
|
||||
|
||||
openstack.enable_logging(debug=True)
|
||||
|
||||
cloud = openstack.connect(cloud='ovh', region_name='SBG1')
|
||||
|
@ -11,9 +11,11 @@
|
||||
# under the License.
|
||||
|
||||
from openstack import cloud as openstack
|
||||
|
||||
openstack.enable_logging()
|
||||
|
||||
cloud = openstack.connect(cloud='fuga', region_name='cystack')
|
||||
image = cloud.get_image(
|
||||
'Ubuntu 16.04 LTS - Xenial Xerus - 64-bit - Fuga Cloud Based Image')
|
||||
'Ubuntu 16.04 LTS - Xenial Xerus - 64-bit - Fuga Cloud Based Image'
|
||||
)
|
||||
cloud.pprint(image)
|
||||
|
@ -11,14 +11,18 @@
|
||||
# under the License.
|
||||
|
||||
import openstack
|
||||
|
||||
openstack.enable_logging(debug=True)
|
||||
|
||||
cloud = openstack.connect(cloud='my-citycloud', region_name='Buf1')
|
||||
try:
|
||||
server = cloud.create_server(
|
||||
'my-server', image='Ubuntu 16.04 Xenial Xerus',
|
||||
'my-server',
|
||||
image='Ubuntu 16.04 Xenial Xerus',
|
||||
flavor=dict(id='0dab10b5-42a2-438e-be7b-505741a7ffcc'),
|
||||
wait=True, auto_ip=True)
|
||||
wait=True,
|
||||
auto_ip=True,
|
||||
)
|
||||
|
||||
print("\n\nFull Server\n\n")
|
||||
cloud.pprint(server)
|
||||
|
@ -11,6 +11,7 @@
|
||||
# under the License.
|
||||
|
||||
import openstack
|
||||
|
||||
openstack.enable_logging(debug=True)
|
||||
|
||||
cloud = openstack.connect(cloud='rax', region_name='DFW')
|
||||
|
@ -11,6 +11,7 @@
|
||||
# under the License.
|
||||
|
||||
import openstack
|
||||
|
||||
openstack.enable_logging(debug=True)
|
||||
|
||||
cloud = openstack.connect(cloud='kiss', region_name='region1')
|
||||
|
@ -11,10 +11,11 @@
|
||||
# under the License.
|
||||
|
||||
import openstack
|
||||
|
||||
openstack.enable_logging()
|
||||
|
||||
cloud = openstack.connect(
|
||||
cloud='fuga', region_name='cystack', strict=True)
|
||||
cloud = openstack.connect(cloud='fuga', region_name='cystack', strict=True)
|
||||
image = cloud.get_image(
|
||||
'Ubuntu 16.04 LTS - Xenial Xerus - 64-bit - Fuga Cloud Based Image')
|
||||
'Ubuntu 16.04 LTS - Xenial Xerus - 64-bit - Fuga Cloud Based Image'
|
||||
)
|
||||
cloud.pprint(image)
|
||||
|
@ -11,12 +11,15 @@
|
||||
# under the License.
|
||||
|
||||
import openstack
|
||||
|
||||
openstack.enable_logging(debug=True)
|
||||
|
||||
cloud = openstack.connect(cloud='ovh', region_name='SBG1')
|
||||
cloud.create_object(
|
||||
container='my-container', name='my-object',
|
||||
container='my-container',
|
||||
name='my-object',
|
||||
filename='/home/mordred/briarcliff.sh3d',
|
||||
segment_size=1000000)
|
||||
segment_size=1000000,
|
||||
)
|
||||
cloud.delete_object('my-container', 'my-object')
|
||||
cloud.delete_container('my-container')
|
||||
|
@ -11,12 +11,15 @@
|
||||
# under the License.
|
||||
|
||||
import openstack
|
||||
|
||||
openstack.enable_logging(debug=True)
|
||||
|
||||
cloud = openstack.connect(cloud='ovh', region_name='SBG1')
|
||||
cloud.create_object(
|
||||
container='my-container', name='my-object',
|
||||
container='my-container',
|
||||
name='my-object',
|
||||
filename='/home/mordred/briarcliff.sh3d',
|
||||
segment_size=1000000)
|
||||
segment_size=1000000,
|
||||
)
|
||||
cloud.delete_object('my-container', 'my-object')
|
||||
cloud.delete_container('my-container')
|
||||
|
@ -11,8 +11,10 @@
|
||||
# under the License.
|
||||
|
||||
import openstack
|
||||
|
||||
openstack.enable_logging(http_debug=True)
|
||||
|
||||
cloud = openstack.connect(
|
||||
cloud='datacentred', app_name='AmazingApp', app_version='1.0')
|
||||
cloud='datacentred', app_name='AmazingApp', app_version='1.0'
|
||||
)
|
||||
cloud.list_networks()
|
||||
|
@ -107,9 +107,7 @@ def replace_nodes_in_cluster(conn):
|
||||
|
||||
old_node = NODE_ID
|
||||
new_node = "cd803d4a-015d-4223-b15f-db29bad3146c"
|
||||
spec = {
|
||||
old_node: new_node
|
||||
}
|
||||
spec = {old_node: new_node}
|
||||
res = conn.clustering.replace_nodes_in_cluster(CLUSTER_ID, **spec)
|
||||
print(res)
|
||||
|
||||
@ -135,7 +133,7 @@ def resize_cluster(conn):
|
||||
'min_size': 1,
|
||||
'max_size': 6,
|
||||
'adjustment_type': 'EXACT_CAPACITY',
|
||||
'number': 2
|
||||
'number': 2,
|
||||
}
|
||||
res = conn.clustering.resize_cluster(CLUSTER_ID, **spec)
|
||||
print(res)
|
||||
@ -146,7 +144,8 @@ def attach_policy_to_cluster(conn):
|
||||
|
||||
spec = {'enabled': True}
|
||||
res = conn.clustering.attach_policy_to_cluster(
|
||||
CLUSTER_ID, POLICY_ID, **spec)
|
||||
CLUSTER_ID, POLICY_ID, **spec
|
||||
)
|
||||
print(res)
|
||||
|
||||
|
||||
|
@ -38,8 +38,8 @@ def create_policy(conn):
|
||||
'properties': {
|
||||
'criteria': 'oldest_first',
|
||||
'destroy_after_deletion': True,
|
||||
}
|
||||
}
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
policy = conn.clustering.create_policy(attrs)
|
||||
|
@ -44,10 +44,8 @@ def create_profile(conn):
|
||||
'name': SERVER_NAME,
|
||||
'flavor': FLAVOR_NAME,
|
||||
'image': IMAGE_NAME,
|
||||
'networks': {
|
||||
'network': NETWORK_NAME
|
||||
}
|
||||
}
|
||||
'networks': {'network': NETWORK_NAME},
|
||||
},
|
||||
}
|
||||
|
||||
profile = conn.clustering.create_profile(spec)
|
||||
|
@ -39,10 +39,8 @@ def create_receiver(conn):
|
||||
"action": "CLUSTER_SCALE_OUT",
|
||||
"cluster_id": CLUSTER_ID,
|
||||
"name": FAKE_NAME,
|
||||
"params": {
|
||||
"count": "1"
|
||||
},
|
||||
"type": "webhook"
|
||||
"params": {"count": "1"},
|
||||
"type": "webhook",
|
||||
}
|
||||
|
||||
receiver = conn.clustering.create_receiver(**spec)
|
||||
@ -66,12 +64,7 @@ def find_receiver(conn):
|
||||
def update_receiver(conn):
|
||||
print("Update Receiver:")
|
||||
|
||||
spec = {
|
||||
"name": "test_receiver2",
|
||||
"params": {
|
||||
"count": "2"
|
||||
}
|
||||
}
|
||||
spec = {"name": "test_receiver2", "params": {"count": "2"}}
|
||||
receiver = conn.clustering.update_receiver(FAKE_NAME, **spec)
|
||||
print(receiver.to_dict())
|
||||
|
||||
|
@ -62,11 +62,17 @@ def create_server(conn):
|
||||
keypair = create_keypair(conn)
|
||||
|
||||
server = conn.compute.create_server(
|
||||
name=SERVER_NAME, image_id=image.id, flavor_id=flavor.id,
|
||||
networks=[{"uuid": network.id}], key_name=keypair.name)
|
||||
name=SERVER_NAME,
|
||||
image_id=image.id,
|
||||
flavor_id=flavor.id,
|
||||
networks=[{"uuid": network.id}],
|
||||
key_name=keypair.name,
|
||||
)
|
||||
|
||||
server = conn.compute.wait_for_server(server)
|
||||
|
||||
print("ssh -i {key} root@{ip}".format(
|
||||
key=PRIVATE_KEYPAIR_FILE,
|
||||
ip=server.access_ipv4))
|
||||
print(
|
||||
"ssh -i {key} root@{ip}".format(
|
||||
key=PRIVATE_KEYPAIR_FILE, ip=server.access_ipv4
|
||||
)
|
||||
)
|
||||
|
@ -45,8 +45,9 @@ class Opts:
|
||||
|
||||
|
||||
def _get_resource_value(resource_key, default):
|
||||
return config.get_extra_config(
|
||||
EXAMPLE_CONFIG_KEY).get(resource_key, default)
|
||||
return config.get_extra_config(EXAMPLE_CONFIG_KEY).get(
|
||||
resource_key, default
|
||||
)
|
||||
|
||||
|
||||
SERVER_NAME = 'openstacksdk-example'
|
||||
@ -55,10 +56,12 @@ FLAVOR_NAME = _get_resource_value('flavor_name', 'm1.small')
|
||||
NETWORK_NAME = _get_resource_value('network_name', 'private')
|
||||
KEYPAIR_NAME = _get_resource_value('keypair_name', 'openstacksdk-example')
|
||||
SSH_DIR = _get_resource_value(
|
||||
'ssh_dir', '{home}/.ssh'.format(home=os.path.expanduser("~")))
|
||||
'ssh_dir', '{home}/.ssh'.format(home=os.path.expanduser("~"))
|
||||
)
|
||||
PRIVATE_KEYPAIR_FILE = _get_resource_value(
|
||||
'private_keypair_file', '{ssh_dir}/id_rsa.{key}'.format(
|
||||
ssh_dir=SSH_DIR, key=KEYPAIR_NAME))
|
||||
'private_keypair_file',
|
||||
'{ssh_dir}/id_rsa.{key}'.format(ssh_dir=SSH_DIR, key=KEYPAIR_NAME),
|
||||
)
|
||||
|
||||
EXAMPLE_IMAGE_NAME = 'openstacksdk-example-public-image'
|
||||
|
||||
@ -72,8 +75,15 @@ def create_connection_from_args():
|
||||
return openstack.connect(options=parser)
|
||||
|
||||
|
||||
def create_connection(auth_url, region, project_name, username, password,
|
||||
user_domain, project_domain):
|
||||
def create_connection(
|
||||
auth_url,
|
||||
region,
|
||||
project_name,
|
||||
username,
|
||||
password,
|
||||
user_domain,
|
||||
project_domain,
|
||||
):
|
||||
return openstack.connect(
|
||||
auth_url=auth_url,
|
||||
project_name=project_name,
|
||||
|
@ -24,8 +24,10 @@ def import_image(conn):
|
||||
print("Import Image:")
|
||||
|
||||
# Url where glance can download the image
|
||||
uri = 'https://download.cirros-cloud.net/0.4.0/' \
|
||||
'cirros-0.4.0-x86_64-disk.img'
|
||||
uri = (
|
||||
'https://download.cirros-cloud.net/0.4.0/'
|
||||
'cirros-0.4.0-x86_64-disk.img'
|
||||
)
|
||||
|
||||
# Build the image attributes and import the image.
|
||||
image_attrs = {
|
||||
|
@ -18,8 +18,10 @@ List resources from the Key Manager service.
|
||||
def create_secret(conn):
|
||||
print("Create a secret:")
|
||||
|
||||
conn.key_manager.create_secret(name="My public key",
|
||||
secret_type="public",
|
||||
expiration="2020-02-28T23:59:59",
|
||||
payload="ssh rsa...",
|
||||
payload_content_type="text/plain")
|
||||
conn.key_manager.create_secret(
|
||||
name="My public key",
|
||||
secret_type="public",
|
||||
expiration="2020-02-28T23:59:59",
|
||||
payload="ssh rsa...",
|
||||
payload_content_type="text/plain",
|
||||
)
|
||||
|
@ -26,6 +26,6 @@ def list_secrets_query(conn):
|
||||
print("List Secrets:")
|
||||
|
||||
for secret in conn.key_manager.secrets(
|
||||
secret_type="symmetric",
|
||||
expiration="gte:2020-01-01T00:00:00"):
|
||||
secret_type="symmetric", expiration="gte:2020-01-01T00:00:00"
|
||||
):
|
||||
print(secret)
|
||||
|
@ -22,7 +22,8 @@ def create_network(conn):
|
||||
print("Create Network:")
|
||||
|
||||
example_network = conn.network.create_network(
|
||||
name='openstacksdk-example-project-network')
|
||||
name='openstacksdk-example-project-network'
|
||||
)
|
||||
|
||||
print(example_network)
|
||||
|
||||
@ -31,6 +32,7 @@ def create_network(conn):
|
||||
network_id=example_network.id,
|
||||
ip_version='4',
|
||||
cidr='10.0.2.0/24',
|
||||
gateway_ip='10.0.2.1')
|
||||
gateway_ip='10.0.2.1',
|
||||
)
|
||||
|
||||
print(example_subnet)
|
||||
|
@ -22,7 +22,8 @@ def delete_network(conn):
|
||||
print("Delete Network:")
|
||||
|
||||
example_network = conn.network.find_network(
|
||||
'openstacksdk-example-project-network')
|
||||
'openstacksdk-example-project-network'
|
||||
)
|
||||
|
||||
for example_subnet in example_network.subnet_ids:
|
||||
conn.network.delete_subnet(example_subnet, ignore_missing=False)
|
||||
|
@ -22,7 +22,8 @@ def open_port(conn):
|
||||
print("Open a port:")
|
||||
|
||||
example_sec_group = conn.network.create_security_group(
|
||||
name='openstacksdk-example-security-group')
|
||||
name='openstacksdk-example-security-group'
|
||||
)
|
||||
|
||||
print(example_sec_group)
|
||||
|
||||
@ -33,7 +34,8 @@ def open_port(conn):
|
||||
protocol='HTTPS',
|
||||
port_range_max='443',
|
||||
port_range_min='443',
|
||||
ethertype='IPv4')
|
||||
ethertype='IPv4',
|
||||
)
|
||||
|
||||
print(example_rule)
|
||||
|
||||
@ -42,7 +44,8 @@ def allow_ping(conn):
|
||||
print("Allow pings:")
|
||||
|
||||
example_sec_group = conn.network.create_security_group(
|
||||
name='openstacksdk-example-security-group2')
|
||||
name='openstacksdk-example-security-group2'
|
||||
)
|
||||
|
||||
print(example_sec_group)
|
||||
|
||||
@ -53,6 +56,7 @@ def allow_ping(conn):
|
||||
protocol='icmp',
|
||||
port_range_max=None,
|
||||
port_range_min=None,
|
||||
ethertype='IPv4')
|
||||
ethertype='IPv4',
|
||||
)
|
||||
|
||||
print(example_rule)
|
||||
|
@ -31,8 +31,10 @@ def get_share_instance(conn, share_instance_id):
|
||||
|
||||
|
||||
def reset_share_instance_status(conn, share_instance_id, status):
|
||||
print('Reset the status of the share instance with the given '
|
||||
'share_instance_id to the given status')
|
||||
print(
|
||||
'Reset the status of the share instance with the given '
|
||||
'share_instance_id to the given status'
|
||||
)
|
||||
conn.share.reset_share_instance_status(share_instance_id, status)
|
||||
|
||||
|
||||
|
@ -19,16 +19,18 @@ import pbr.version
|
||||
|
||||
|
||||
def show_version(args):
|
||||
print("OpenstackSDK Version %s" %
|
||||
pbr.version.VersionInfo('openstacksdk').version_string_with_vcs())
|
||||
print(
|
||||
"OpenstackSDK Version %s"
|
||||
% pbr.version.VersionInfo('openstacksdk').version_string_with_vcs()
|
||||
)
|
||||
|
||||
|
||||
parser = argparse.ArgumentParser(description="Openstack SDK")
|
||||
subparsers = parser.add_subparsers(title='commands',
|
||||
dest='command')
|
||||
subparsers = parser.add_subparsers(title='commands', dest='command')
|
||||
|
||||
cmd_version = subparsers.add_parser('version',
|
||||
help='show Openstack SDK version')
|
||||
cmd_version = subparsers.add_parser(
|
||||
'version', help='show Openstack SDK version'
|
||||
)
|
||||
cmd_version.set_defaults(func=show_version)
|
||||
|
||||
args = parser.parse_args()
|
||||
|
@ -44,7 +44,10 @@ def setup_logging(name, handlers=None, level=None):
|
||||
|
||||
|
||||
def enable_logging(
|
||||
debug=False, http_debug=False, path=None, stream=None,
|
||||
debug=False,
|
||||
http_debug=False,
|
||||
path=None,
|
||||
stream=None,
|
||||
format_stream=False,
|
||||
format_template='%(asctime)s %(levelname)s: %(name)s %(message)s',
|
||||
handlers=None,
|
||||
@ -121,9 +124,11 @@ def enable_logging(
|
||||
# enable_logging should not be used and instead python logging should
|
||||
# be configured directly.
|
||||
setup_logging(
|
||||
'urllib3', handlers=[logging.NullHandler()], level=logging.INFO)
|
||||
'urllib3', handlers=[logging.NullHandler()], level=logging.INFO
|
||||
)
|
||||
setup_logging(
|
||||
'stevedore', handlers=[logging.NullHandler()], level=logging.INFO)
|
||||
'stevedore', handlers=[logging.NullHandler()], level=logging.INFO
|
||||
)
|
||||
# Suppress warning about keystoneauth loggers
|
||||
setup_logging('keystoneauth.discovery')
|
||||
setup_logging('keystoneauth.identity.base')
|
||||
|
@ -6,7 +6,9 @@ from openstack.baremetal_introspection import baremetal_introspection_service
|
||||
from openstack.block_storage import block_storage_service
|
||||
from openstack.clustering import clustering_service
|
||||
from openstack.compute import compute_service
|
||||
from openstack.container_infrastructure_management import container_infrastructure_management_service
|
||||
from openstack.container_infrastructure_management import (
|
||||
container_infrastructure_management_service,
|
||||
)
|
||||
from openstack.database import database_service
|
||||
from openstack.dns import dns_service
|
||||
from openstack.identity import identity_service
|
||||
@ -31,32 +33,52 @@ class ServicesMixin:
|
||||
|
||||
image = image_service.ImageService(service_type='image')
|
||||
|
||||
load_balancer = load_balancer_service.LoadBalancerService(service_type='load-balancer')
|
||||
load_balancer = load_balancer_service.LoadBalancerService(
|
||||
service_type='load-balancer'
|
||||
)
|
||||
|
||||
object_store = object_store_service.ObjectStoreService(service_type='object-store')
|
||||
object_store = object_store_service.ObjectStoreService(
|
||||
service_type='object-store'
|
||||
)
|
||||
|
||||
clustering = clustering_service.ClusteringService(service_type='clustering')
|
||||
clustering = clustering_service.ClusteringService(
|
||||
service_type='clustering'
|
||||
)
|
||||
resource_cluster = clustering
|
||||
cluster = clustering
|
||||
|
||||
data_processing = service_description.ServiceDescription(service_type='data-processing')
|
||||
data_processing = service_description.ServiceDescription(
|
||||
service_type='data-processing'
|
||||
)
|
||||
|
||||
baremetal = baremetal_service.BaremetalService(service_type='baremetal')
|
||||
bare_metal = baremetal
|
||||
|
||||
baremetal_introspection = baremetal_introspection_service.BaremetalIntrospectionService(service_type='baremetal-introspection')
|
||||
baremetal_introspection = (
|
||||
baremetal_introspection_service.BaremetalIntrospectionService(
|
||||
service_type='baremetal-introspection'
|
||||
)
|
||||
)
|
||||
|
||||
key_manager = key_manager_service.KeyManagerService(service_type='key-manager')
|
||||
key_manager = key_manager_service.KeyManagerService(
|
||||
service_type='key-manager'
|
||||
)
|
||||
|
||||
resource_optimization = service_description.ServiceDescription(service_type='resource-optimization')
|
||||
resource_optimization = service_description.ServiceDescription(
|
||||
service_type='resource-optimization'
|
||||
)
|
||||
infra_optim = resource_optimization
|
||||
|
||||
message = message_service.MessageService(service_type='message')
|
||||
messaging = message
|
||||
|
||||
application_catalog = service_description.ServiceDescription(service_type='application-catalog')
|
||||
application_catalog = service_description.ServiceDescription(
|
||||
service_type='application-catalog'
|
||||
)
|
||||
|
||||
container_infrastructure_management = container_infrastructure_management_service.ContainerInfrastructureManagementService(service_type='container-infrastructure-management')
|
||||
container_infrastructure_management = container_infrastructure_management_service.ContainerInfrastructureManagementService(
|
||||
service_type='container-infrastructure-management'
|
||||
)
|
||||
container_infra = container_infrastructure_management
|
||||
container_infrastructure = container_infrastructure_management
|
||||
|
||||
@ -68,17 +90,27 @@ class ServicesMixin:
|
||||
|
||||
rating = service_description.ServiceDescription(service_type='rating')
|
||||
|
||||
operator_policy = service_description.ServiceDescription(service_type='operator-policy')
|
||||
operator_policy = service_description.ServiceDescription(
|
||||
service_type='operator-policy'
|
||||
)
|
||||
policy = operator_policy
|
||||
|
||||
shared_file_system = shared_file_system_service.SharedFilesystemService(service_type='shared-file-system')
|
||||
shared_file_system = shared_file_system_service.SharedFilesystemService(
|
||||
service_type='shared-file-system'
|
||||
)
|
||||
share = shared_file_system
|
||||
|
||||
data_protection_orchestration = service_description.ServiceDescription(service_type='data-protection-orchestration')
|
||||
data_protection_orchestration = service_description.ServiceDescription(
|
||||
service_type='data-protection-orchestration'
|
||||
)
|
||||
|
||||
orchestration = orchestration_service.OrchestrationService(service_type='orchestration')
|
||||
orchestration = orchestration_service.OrchestrationService(
|
||||
service_type='orchestration'
|
||||
)
|
||||
|
||||
block_storage = block_storage_service.BlockStorageService(service_type='block-storage')
|
||||
block_storage = block_storage_service.BlockStorageService(
|
||||
service_type='block-storage'
|
||||
)
|
||||
block_store = block_storage
|
||||
volume = block_storage
|
||||
|
||||
@ -92,44 +124,69 @@ class ServicesMixin:
|
||||
event = service_description.ServiceDescription(service_type='event')
|
||||
events = event
|
||||
|
||||
application_deployment = service_description.ServiceDescription(service_type='application-deployment')
|
||||
application_deployment = service_description.ServiceDescription(
|
||||
service_type='application-deployment'
|
||||
)
|
||||
application_deployment = application_deployment
|
||||
|
||||
multi_region_network_automation = service_description.ServiceDescription(service_type='multi-region-network-automation')
|
||||
multi_region_network_automation = service_description.ServiceDescription(
|
||||
service_type='multi-region-network-automation'
|
||||
)
|
||||
tricircle = multi_region_network_automation
|
||||
|
||||
database = database_service.DatabaseService(service_type='database')
|
||||
|
||||
application_container = service_description.ServiceDescription(service_type='application-container')
|
||||
application_container = service_description.ServiceDescription(
|
||||
service_type='application-container'
|
||||
)
|
||||
container = application_container
|
||||
|
||||
root_cause_analysis = service_description.ServiceDescription(service_type='root-cause-analysis')
|
||||
root_cause_analysis = service_description.ServiceDescription(
|
||||
service_type='root-cause-analysis'
|
||||
)
|
||||
rca = root_cause_analysis
|
||||
|
||||
nfv_orchestration = service_description.ServiceDescription(service_type='nfv-orchestration')
|
||||
nfv_orchestration = service_description.ServiceDescription(
|
||||
service_type='nfv-orchestration'
|
||||
)
|
||||
|
||||
network = network_service.NetworkService(service_type='network')
|
||||
|
||||
backup = service_description.ServiceDescription(service_type='backup')
|
||||
|
||||
monitoring_logging = service_description.ServiceDescription(service_type='monitoring-logging')
|
||||
monitoring_logging = service_description.ServiceDescription(
|
||||
service_type='monitoring-logging'
|
||||
)
|
||||
monitoring_log_api = monitoring_logging
|
||||
|
||||
monitoring = service_description.ServiceDescription(service_type='monitoring')
|
||||
monitoring = service_description.ServiceDescription(
|
||||
service_type='monitoring'
|
||||
)
|
||||
|
||||
monitoring_events = service_description.ServiceDescription(service_type='monitoring-events')
|
||||
monitoring_events = service_description.ServiceDescription(
|
||||
service_type='monitoring-events'
|
||||
)
|
||||
|
||||
placement = placement_service.PlacementService(service_type='placement')
|
||||
|
||||
instance_ha = instance_ha_service.InstanceHaService(service_type='instance-ha')
|
||||
instance_ha = instance_ha_service.InstanceHaService(
|
||||
service_type='instance-ha'
|
||||
)
|
||||
ha = instance_ha
|
||||
|
||||
reservation = service_description.ServiceDescription(service_type='reservation')
|
||||
reservation = service_description.ServiceDescription(
|
||||
service_type='reservation'
|
||||
)
|
||||
|
||||
function_engine = service_description.ServiceDescription(service_type='function-engine')
|
||||
function_engine = service_description.ServiceDescription(
|
||||
service_type='function-engine'
|
||||
)
|
||||
|
||||
accelerator = accelerator_service.AcceleratorService(service_type='accelerator')
|
||||
accelerator = accelerator_service.AcceleratorService(
|
||||
service_type='accelerator'
|
||||
)
|
||||
|
||||
admin_logic = service_description.ServiceDescription(service_type='admin-logic')
|
||||
admin_logic = service_description.ServiceDescription(
|
||||
service_type='admin-logic'
|
||||
)
|
||||
registration = admin_logic
|
||||
|
||||
|
@ -82,14 +82,13 @@ class MetadataMixin:
|
||||
url = utils.urljoin(self.base_path, self.id, 'metadata', key)
|
||||
response = session.get(url)
|
||||
exceptions.raise_from_response(
|
||||
response, error_message='Metadata item does not exist')
|
||||
response, error_message='Metadata item does not exist'
|
||||
)
|
||||
meta = response.json().get('meta', {})
|
||||
# Here we need to potentially init metadata
|
||||
metadata = self.metadata or {}
|
||||
metadata[key] = meta.get(key)
|
||||
self._body.attributes.update({
|
||||
'metadata': metadata
|
||||
})
|
||||
self._body.attributes.update({'metadata': metadata})
|
||||
|
||||
return self
|
||||
|
||||
@ -101,17 +100,12 @@ class MetadataMixin:
|
||||
:param str value: The value.
|
||||
"""
|
||||
url = utils.urljoin(self.base_path, self.id, 'metadata', key)
|
||||
response = session.put(
|
||||
url,
|
||||
json={'meta': {key: value}}
|
||||
)
|
||||
response = session.put(url, json={'meta': {key: value}})
|
||||
exceptions.raise_from_response(response)
|
||||
# we do not want to update tags directly
|
||||
metadata = self.metadata
|
||||
metadata[key] = value
|
||||
self._body.attributes.update({
|
||||
'metadata': metadata
|
||||
})
|
||||
self._body.attributes.update({'metadata': metadata})
|
||||
return self
|
||||
|
||||
def delete_metadata_item(self, session, key):
|
||||
@ -132,7 +126,5 @@ class MetadataMixin:
|
||||
metadata = {}
|
||||
except ValueError:
|
||||
pass # do nothing!
|
||||
self._body.attributes.update({
|
||||
'metadata': metadata
|
||||
})
|
||||
self._body.attributes.update({'metadata': metadata})
|
||||
return self
|
||||
|
@ -26,8 +26,7 @@ class QuotaSet(resource.Resource):
|
||||
allow_delete = True
|
||||
allow_commit = True
|
||||
|
||||
_query_mapping = resource.QueryParameters(
|
||||
"usage")
|
||||
_query_mapping = resource.QueryParameters("usage")
|
||||
|
||||
# NOTE(gtema) Sadly this attribute is useless in all the methods, but keep
|
||||
# it here extra as a reminder
|
||||
@ -47,8 +46,14 @@ class QuotaSet(resource.Resource):
|
||||
|
||||
project_id = resource.URI('project_id')
|
||||
|
||||
def fetch(self, session, requires_id=False,
|
||||
base_path=None, error_message=None, **params):
|
||||
def fetch(
|
||||
self,
|
||||
session,
|
||||
requires_id=False,
|
||||
base_path=None,
|
||||
error_message=None,
|
||||
**params
|
||||
):
|
||||
return super(QuotaSet, self).fetch(
|
||||
session,
|
||||
requires_id=False,
|
||||
@ -93,8 +98,9 @@ class QuotaSet(resource.Resource):
|
||||
if 'in_use' in val:
|
||||
normalized_attrs['usage'][key] = val['in_use']
|
||||
if 'reserved' in val:
|
||||
normalized_attrs['reservation'][key] = \
|
||||
val['reserved']
|
||||
normalized_attrs['reservation'][key] = val[
|
||||
'reserved'
|
||||
]
|
||||
if 'limit' in val:
|
||||
normalized_attrs[key] = val['limit']
|
||||
else:
|
||||
|
@ -81,8 +81,9 @@ class TagMixin:
|
||||
url = utils.urljoin(self.base_path, self.id, 'tags', tag)
|
||||
session = self._get_session(session)
|
||||
response = session.get(url)
|
||||
exceptions.raise_from_response(response,
|
||||
error_message='Tag does not exist')
|
||||
exceptions.raise_from_response(
|
||||
response, error_message='Tag does not exist'
|
||||
)
|
||||
return self
|
||||
|
||||
def add_tag(self, session, tag):
|
||||
@ -98,9 +99,7 @@ class TagMixin:
|
||||
# we do not want to update tags directly
|
||||
tags = self.tags
|
||||
tags.append(tag)
|
||||
self._body.attributes.update({
|
||||
'tags': tags
|
||||
})
|
||||
self._body.attributes.update({'tags': tags})
|
||||
return self
|
||||
|
||||
def remove_tag(self, session, tag):
|
||||
@ -121,7 +120,5 @@ class TagMixin:
|
||||
tags.remove(tag)
|
||||
except ValueError:
|
||||
pass # do nothing!
|
||||
self._body.attributes.update({
|
||||
'tags': tags
|
||||
})
|
||||
self._body.attributes.update({'tags': tags})
|
||||
return self
|
||||
|
@ -18,15 +18,20 @@ from openstack.config.loader import OpenStackConfig # noqa
|
||||
|
||||
|
||||
def get_cloud_region(
|
||||
service_key=None, options=None,
|
||||
app_name=None, app_version=None,
|
||||
load_yaml_config=True,
|
||||
load_envvars=True,
|
||||
**kwargs):
|
||||
service_key=None,
|
||||
options=None,
|
||||
app_name=None,
|
||||
app_version=None,
|
||||
load_yaml_config=True,
|
||||
load_envvars=True,
|
||||
**kwargs
|
||||
):
|
||||
config = OpenStackConfig(
|
||||
load_yaml_config=load_yaml_config,
|
||||
load_envvars=load_envvars,
|
||||
app_name=app_name, app_version=app_version)
|
||||
app_name=app_name,
|
||||
app_version=app_version,
|
||||
)
|
||||
if options:
|
||||
config.register_argparse_arguments(options, sys.argv, service_key)
|
||||
parsed_options = options.parse_known_args(sys.argv)
|
||||
|
@ -22,7 +22,9 @@ def normalize_keys(config):
|
||||
elif isinstance(value, bool):
|
||||
new_config[key] = value
|
||||
elif isinstance(value, int) and key not in (
|
||||
'verbose_level', 'api_timeout'):
|
||||
'verbose_level',
|
||||
'api_timeout',
|
||||
):
|
||||
new_config[key] = str(value)
|
||||
elif isinstance(value, float):
|
||||
new_config[key] = str(value)
|
||||
|
@ -18,7 +18,6 @@ from openstack.config import cloud_region
|
||||
|
||||
|
||||
class CloudConfig(cloud_region.CloudRegion):
|
||||
|
||||
def __init__(self, name, region, config, **kwargs):
|
||||
super(CloudConfig, self).__init__(name, region, config, **kwargs)
|
||||
self.region = region
|
||||
|
@ -28,6 +28,7 @@ from keystoneauth1.loading import adapter as ks_load_adap
|
||||
from keystoneauth1 import session as ks_session
|
||||
import os_service_types
|
||||
import requestsexceptions
|
||||
|
||||
try:
|
||||
import statsd
|
||||
except ImportError:
|
||||
@ -52,9 +53,11 @@ from openstack import version as openstack_version
|
||||
_logger = _log.setup_logging('openstack')
|
||||
|
||||
SCOPE_KEYS = {
|
||||
'domain_id', 'domain_name',
|
||||
'project_id', 'project_name',
|
||||
'system_scope'
|
||||
'domain_id',
|
||||
'domain_name',
|
||||
'project_id',
|
||||
'project_name',
|
||||
'system_scope',
|
||||
}
|
||||
|
||||
# Sentinel for nonexistence
|
||||
@ -90,9 +93,15 @@ def _get_implied_microversion(version):
|
||||
return version
|
||||
|
||||
|
||||
def from_session(session, name=None, region_name=None,
|
||||
force_ipv4=False,
|
||||
app_name=None, app_version=None, **kwargs):
|
||||
def from_session(
|
||||
session,
|
||||
name=None,
|
||||
region_name=None,
|
||||
force_ipv4=False,
|
||||
app_name=None,
|
||||
app_version=None,
|
||||
**kwargs
|
||||
):
|
||||
"""Construct a CloudRegion from an existing `keystoneauth1.session.Session`
|
||||
|
||||
When a Session already exists, we don't actually even need to go through
|
||||
@ -118,9 +127,14 @@ def from_session(session, name=None, region_name=None,
|
||||
config_dict = config_defaults.get_defaults()
|
||||
config_dict.update(**kwargs)
|
||||
return CloudRegion(
|
||||
name=name, session=session, config=config_dict,
|
||||
region_name=region_name, force_ipv4=force_ipv4,
|
||||
app_name=app_name, app_version=app_version)
|
||||
name=name,
|
||||
session=session,
|
||||
config=config_dict,
|
||||
region_name=region_name,
|
||||
force_ipv4=force_ipv4,
|
||||
app_name=app_name,
|
||||
app_version=app_version,
|
||||
)
|
||||
|
||||
|
||||
def from_conf(conf, session=None, service_types=None, **kwargs):
|
||||
@ -160,8 +174,10 @@ def from_conf(conf, session=None, service_types=None, **kwargs):
|
||||
for st in stm.all_types_by_service_type:
|
||||
if service_types is not None and st not in service_types:
|
||||
_disable_service(
|
||||
config_dict, st,
|
||||
reason="Not in the list of requested service_types.")
|
||||
config_dict,
|
||||
st,
|
||||
reason="Not in the list of requested service_types.",
|
||||
)
|
||||
continue
|
||||
project_name = stm.get_project_name(st)
|
||||
if project_name not in conf:
|
||||
@ -170,10 +186,13 @@ def from_conf(conf, session=None, service_types=None, **kwargs):
|
||||
|
||||
if project_name not in conf:
|
||||
_disable_service(
|
||||
config_dict, st,
|
||||
config_dict,
|
||||
st,
|
||||
reason="No section for project '{project}' (service type "
|
||||
"'{service_type}') was present in the config."
|
||||
.format(project=project_name, service_type=st))
|
||||
"'{service_type}') was present in the config.".format(
|
||||
project=project_name, service_type=st
|
||||
),
|
||||
)
|
||||
continue
|
||||
opt_dict = {}
|
||||
# Populate opt_dict with (appropriately processed) Adapter conf opts
|
||||
@ -189,20 +208,24 @@ def from_conf(conf, session=None, service_types=None, **kwargs):
|
||||
# option of) blowing up right away for (2) rather than letting them
|
||||
# get all the way to the point of trying the service and having
|
||||
# *that* blow up.
|
||||
reason = ("Encountered an exception attempting to process config "
|
||||
"for project '{project}' (service type "
|
||||
"'{service_type}'): {exception}".format(
|
||||
project=project_name, service_type=st, exception=e))
|
||||
_logger.warning("Disabling service '{service_type}': "
|
||||
"{reason}".format(service_type=st, reason=reason))
|
||||
reason = (
|
||||
"Encountered an exception attempting to process config "
|
||||
"for project '{project}' (service type "
|
||||
"'{service_type}'): {exception}".format(
|
||||
project=project_name, service_type=st, exception=e
|
||||
)
|
||||
)
|
||||
_logger.warning(
|
||||
"Disabling service '{service_type}': "
|
||||
"{reason}".format(service_type=st, reason=reason)
|
||||
)
|
||||
_disable_service(config_dict, st, reason=reason)
|
||||
continue
|
||||
# Load them into config_dict under keys prefixed by ${service_type}_
|
||||
for raw_name, opt_val in opt_dict.items():
|
||||
config_name = _make_key(raw_name, st)
|
||||
config_dict[config_name] = opt_val
|
||||
return CloudRegion(
|
||||
session=session, config=config_dict, **kwargs)
|
||||
return CloudRegion(session=session, config=config_dict, **kwargs)
|
||||
|
||||
|
||||
class CloudRegion:
|
||||
@ -232,18 +255,34 @@ class CloudRegion:
|
||||
|
||||
'interface': 'public'
|
||||
"""
|
||||
def __init__(self, name=None, region_name=None, config=None,
|
||||
force_ipv4=False, auth_plugin=None,
|
||||
openstack_config=None, session_constructor=None,
|
||||
app_name=None, app_version=None, session=None,
|
||||
discovery_cache=None, extra_config=None,
|
||||
cache_expiration_time=0, cache_expirations=None,
|
||||
cache_path=None, cache_class='dogpile.cache.null',
|
||||
cache_arguments=None, password_callback=None,
|
||||
statsd_host=None, statsd_port=None, statsd_prefix=None,
|
||||
influxdb_config=None,
|
||||
collector_registry=None,
|
||||
cache_auth=False):
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
name=None,
|
||||
region_name=None,
|
||||
config=None,
|
||||
force_ipv4=False,
|
||||
auth_plugin=None,
|
||||
openstack_config=None,
|
||||
session_constructor=None,
|
||||
app_name=None,
|
||||
app_version=None,
|
||||
session=None,
|
||||
discovery_cache=None,
|
||||
extra_config=None,
|
||||
cache_expiration_time=0,
|
||||
cache_expirations=None,
|
||||
cache_path=None,
|
||||
cache_class='dogpile.cache.null',
|
||||
cache_arguments=None,
|
||||
password_callback=None,
|
||||
statsd_host=None,
|
||||
statsd_port=None,
|
||||
statsd_prefix=None,
|
||||
influxdb_config=None,
|
||||
collector_registry=None,
|
||||
cache_auth=False,
|
||||
):
|
||||
self._name = name
|
||||
self.config = _util.normalize_keys(config)
|
||||
# NOTE(efried): For backward compatibility: a) continue to accept the
|
||||
@ -294,9 +333,7 @@ class CloudRegion:
|
||||
return self.config.__iter__()
|
||||
|
||||
def __eq__(self, other):
|
||||
return (
|
||||
self.name == other.name
|
||||
and self.config == other.config)
|
||||
return self.name == other.name and self.config == other.config
|
||||
|
||||
def __ne__(self, other):
|
||||
return not self == other
|
||||
@ -306,7 +343,8 @@ class CloudRegion:
|
||||
if self._name is None:
|
||||
try:
|
||||
self._name = urllib.parse.urlparse(
|
||||
self.get_session().auth.auth_url).hostname
|
||||
self.get_session().auth.auth_url
|
||||
).hostname
|
||||
except Exception:
|
||||
self._name = self._app_name or ''
|
||||
return self._name
|
||||