import sys
from datetime import datetime, timedelta
-import shade
+import openstack
+import openstack.config
+from openstack.cloud.exc import OpenStackCloudException
def _filter_servers(servers, days=0):
def list(os_cloud, days=0):
"""List servers found according to parameters."""
- cloud = shade.openstack_cloud(cloud=os_cloud)
+ cloud = openstack.connection.from_config(cloud=os_cloud)
servers = cloud.list_servers()
filtered_servers = _filter_servers(servers, days)
for server in servers:
try:
result = cloud.delete_server(server.name)
- except shade.exc.OpenStackCloudException as e:
+ except OpenStackCloudException as e:
if str(e).startswith("Multiple matches found for"):
print("WARNING: {}. Skipping server...".format(str(e)))
continue
else:
print('Removed "{}" from {}.'.format(server.name, cloud.cloud_config.name))
- cloud = shade.openstack_cloud(cloud=os_cloud)
+ cloud = openstack.connection.from_config(cloud=os_cloud)
servers = cloud.list_servers()
filtered_servers = _filter_servers(servers, days)
_remove_servers_from_cloud(filtered_servers, cloud)
:arg str os_cloud: Cloud name as defined in OpenStack clouds.yaml.
:arg int minutes: Only delete server if it is older than number of minutes.
"""
- cloud = shade.openstack_cloud(cloud=os_cloud)
+ cloud = openstack.connection.from_config(cloud=os_cloud)
server = cloud.get_server(server_name)
if not server:
from datetime import datetime
import openstack
-import shade
+import openstack.config
+from openstack.cloud.exc import OpenStackCloudHTTPError
from lftools.jenkins import Jenkins
def create(os_cloud, name, template_file, parameter_file, timeout=900, tries=2):
"""Create a heat stack from a template_file and a parameter_file."""
- cloud = shade.openstack_cloud(cloud=os_cloud)
+ cloud = openstack.connection.from_config(cloud=os_cloud)
stack_success = False
print("Creating stack {}".format(name))
stack = cloud.create_stack(
name, template_file=template_file, environment_files=[parameter_file], timeout=timeout, rollback=False
)
- except shade.exc.OpenStackCloudHTTPError as e:
+ except OpenStackCloudHTTPError as e:
if cloud.search_stacks(name):
print("Stack with name {} already exists.".format(name))
else:
time.sleep(10)
stack = cloud.get_stack(stack_id)
- if stack.stack_status == "CREATE_IN_PROGRESS":
+ if stack.status == "CREATE_IN_PROGRESS":
print("Waiting to initialize infrastructure...")
- elif stack.stack_status == "CREATE_COMPLETE":
+ elif stack.status == "CREATE_COMPLETE":
print("Stack initialization successful.")
stack_success = True
break
- elif stack.stack_status == "CREATE_FAILED":
- print("WARN: Failed to initialize stack. Reason: {}".format(stack.stack_status_reason))
+ elif stack.status == "CREATE_FAILED":
+ print("WARN: Failed to initialize stack. Reason: {}".format(stack.status_reason))
if delete(os_cloud, stack_id):
break
else:
- print("Unexpected status: {}".format(stack.stack_status))
+ print("Unexpected status: {}".format(stack.status))
if stack_success:
break
Return True if delete was successful.
"""
- cloud = shade.openstack_cloud(cloud=os_cloud)
+ cloud = openstack.connection.from_config(cloud=os_cloud)
print("Deleting stack {}".format(name_or_id))
cloud.delete_stack(name_or_id)
time.sleep(10)
stack = cloud.get_stack(name_or_id)
- if not stack or stack.stack_status == "DELETE_COMPLETE":
+ if not stack or stack.status == "DELETE_COMPLETE":
print("Successfully deleted stack {}".format(name_or_id))
return True
- elif stack.stack_status == "DELETE_IN_PROGRESS":
+ elif stack.status == "DELETE_IN_PROGRESS":
print("Waiting for stack to delete...")
- elif stack.stack_status == "DELETE_FAILED":
- print("WARN: Failed to delete $STACK_NAME. Reason: {}".format(stack.stack_status_reason))
+ elif stack.status == "DELETE_FAILED":
+ print("WARN: Failed to delete $STACK_NAME. Reason: {}".format(stack.status_reason))
print("Retrying delete...")
cloud.delete_stack(name_or_id)
else:
- print("WARN: Unexpected delete status: {}".format(stack.stack_status))
+ print("WARN: Unexpected delete status: {}".format(stack.status))
print("Retrying delete...")
cloud.delete_stack(name_or_id)
An orphaned stack is a stack that is not known in any of the Jenkins
servers passed into this function.
"""
- cloud = shade.openstack_cloud(cloud=os_cloud)
+ cloud = openstack.connection.from_config(cloud=os_cloud)
stacks = cloud.search_stacks()
if not stacks:
log.debug("No stacks to delete.")
log.debug("Active stacks")
for stack in stacks:
if (
- stack.stack_status == "CREATE_COMPLETE"
- or stack.stack_status == "CREATE_FAILED"
- or stack.stack_status == "DELETE_FAILED"
+ stack.status == "CREATE_COMPLETE"
+ or stack.status == "CREATE_FAILED"
+ or stack.status == "DELETE_FAILED"
):
log.debug(" {}".format(stack.stack_name))
- if stack.stack_status == "DELETE_FAILED":
+ if stack.status == "DELETE_FAILED":
cloud.pprint(stack)
if stack.stack_name not in builds:
import sys
from datetime import datetime, timedelta
-import shade
+import openstack
+import openstack.config
+from openstack.cloud.exc import OpenStackCloudException
def _filter_volumes(volumes, days=0):
def list(os_cloud, days=0):
"""List volumes found according to parameters."""
- cloud = shade.openstack_cloud(cloud=os_cloud)
+ cloud = openstack.connection.from_config(cloud=os_cloud)
volumes = cloud.list_volumes()
filtered_volumes = _filter_volumes(volumes, days)
for volume in volumes:
try:
result = cloud.delete_volume(volume.name)
- except shade.exc.OpenStackCloudException as e:
+ except OpenStackCloudException as e:
if str(e).startswith("Multiple matches found for"):
print("WARNING: {}. Skipping volume...".format(str(e)))
continue
else:
print('Removed "{}" from {}.'.format(volume.name, cloud.cloud_config.name))
- cloud = shade.openstack_cloud(cloud=os_cloud)
+ cloud = openstack.connection.from_config(cloud=os_cloud)
volumes = cloud.list_volumes()
filtered_volumes = _filter_volumes(volumes, days)
_remove_volumes_from_cloud(filtered_volumes, cloud)
:arg str volume_id: Volume ID to delete
:arg int minutes: Only delete volume if it is older than number of minutes.
"""
- cloud = shade.openstack_cloud(cloud=os_cloud)
+ cloud = openstack.connection.from_config(cloud=os_cloud)
volume = cloud.get_volume_by_id(volume_id)
if not volume: