Skip to content

Commit

Permalink
Tidy up - add docstrings
Browse files Browse the repository at this point in the history
  • Loading branch information
lizsalmon committed Dec 19, 2024
1 parent c979265 commit 49820ff
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 67 deletions.
4 changes: 0 additions & 4 deletions lib/exceptions/migrate_error.py

This file was deleted.

12 changes: 6 additions & 6 deletions lib/openstack_api/openstack_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@
from openstack.connection import Connection
from openstack.compute.v2.image import Image

from exceptions.migrate_error import MigrateError


def snapshot_and_migrate_server(
conn: Connection,
Expand All @@ -13,19 +11,21 @@ def snapshot_and_migrate_server(
dest_host: Optional[str] = None,
) -> None:
"""
Migrate a server to a new host
Snapshot a server and then migrate it to a new host
:param conn: Openstack Connection
:param server_id: Server ID to migrate
:param dest_host: Optional host to migrate to, otherwise choosen by scheduler
:param live: True for live migration
:param server_status: Status of machine to migrate - must be ACTIVE or SHUTOFF
:param dest_host: Optional host to migrate to, otherwise chosen by scheduler
"""
snapshot_server(conn=conn, server_id=server_id)
if server_status == "ACTIVE":
live = True
elif server_status == "SHUTOFF":
live = False
else:
raise MigrateError("The VM is in the incorrect state to be migrated")
raise ValueError(
f"Server status: {server_status}. The server must be ACTIVE or SHUTOFF to be migrated"
)
if not live:
conn.compute.migrate_server(server=server_id, host=dest_host)
else:
Expand Down
51 changes: 0 additions & 51 deletions lib/workflows/migrate_server.py

This file was deleted.

9 changes: 3 additions & 6 deletions lib/workflows/search_by_property.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ def search_by_property(
group_by: Optional[str] = None,
sort_by: Optional[List[str]] = None,
webhook: Optional[str] = None,
**kwargs,
**kwargs
):
"""
method that builds and runs a query to find generic resource with a selected property
Expand All @@ -43,7 +43,7 @@ def search_by_property(
query = getattr(openstackquery, query_type)()
if not properties_to_select:
query.select_all()
elif webhook:
elif webhook == "migrate_server":
query.select(*properties_to_select, "server_id", "server_status")
else:
query.select(*properties_to_select)
Expand All @@ -58,15 +58,12 @@ def search_by_property(
query.sort_by(*[(p, "desc") for p in sort_by])
if group_by:
query.group_by(group_by)

query.run(cloud_account, **kwargs)
payload = query.to_props()
if webhook:
to_webhook(
webhook=webhook,
payload=payload,
payload=query.to_props(),
)

return {
"to_html": query.to_html(),
"to_string": query.to_string(),
Expand Down

0 comments on commit 49820ff

Please sign in to comment.