Skip to content

Commit

Permalink
Starting to add in checks for status
Browse files Browse the repository at this point in the history
  • Loading branch information
lizsalmon committed Dec 19, 2024
1 parent d93b5bd commit 3a28ed1
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 8 deletions.
9 changes: 4 additions & 5 deletions actions/server.migrate.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,8 @@ parameters:
type: string
required: true
description: ID of server to migrate
live:
type: boolean
required: true
default: true
description: True to use live migration
destination_host:
type: string
required: false
description: "Optional, host to migrate server to"
runner_type: python-script
31 changes: 28 additions & 3 deletions lib/workflows/migrate_server.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
from typing import Optional

import openstackquery
from openstack.connection import Connection
from openstack_api.openstack_server import migrate_server, snapshot_server


def server_migration(
conn: Connection,
cloud_account: str,
server_id: str,
destination_host: Optional[str] = None,
live: bool = True,
) -> None:
"""Docstring for migrate_server
Expand All @@ -21,6 +22,30 @@ def server_migration(
:param live: True to use live migration
:type live: bool
"""
snapshot_server(conn, server_id)

migrate_server(conn, server_id=server_id, dest_host=destination_host, live=live)
# Determine the status of the server
query = getattr(openstackquery, "ServerQuery")()
query.select("server_status")
query.where(
preset="any_in",
prop="server_id",
values=[server_id],
)
query.run(cloud_account, all_projects=True, as_admin=True)
status = query.to_props()[0].get("server_status")
if status == "ACTIVE":
live_migration = True
print(f"live migration: {live_migration}")
snapshot_server(conn, server_id)
migrate_server(
conn, server_id=server_id, dest_host=destination_host, live=live_migration
)
elif status == "SHUTOFF":
live_migration = False
print(f"live migration: {live_migration}")
snapshot_server(conn, server_id)
migrate_server(
conn, server_id=server_id, dest_host=destination_host, live=live_migration
)
else:
print("Status not SHUTOFF or ACTIVE - ERROR!")

0 comments on commit 3a28ed1

Please sign in to comment.