Skip to content

Commit 8217715

Browse files
twarnockMark Beacom
authored andcommitted
Fix #85 generic migration state (#86)
1 parent 89c2aa8 commit 8217715

File tree

10 files changed

+26
-26
lines changed

10 files changed

+26
-26
lines changed

step/lambdas/copy_image.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
from typing import Any, Dict
99

1010
import boto3
11-
from servicenowstate import ServiceNowState, ServiceNowStateHandler
11+
from migrationstate import MigrationState, MigrationStateHandler
1212

1313
print("Loading function copy_image")
1414

@@ -59,7 +59,7 @@ def lambda_handler(event: Dict[str, Any], context: Any) -> str:
5959
print(e)
6060
return ""
6161

62-
ServiceNowStateHandler().update_state(
62+
MigrationStateHandler().update_state(
6363
state="IMAGE_COPYING", machine_name=instance_name
6464
)
6565
return new_image.get("ImageId", "")

step/lambdas/create_image.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
from typing import Any, Dict
99

1010
import boto3
11-
from servicenowstate import ServiceNowStateHandler
11+
from migrationstate import MigrationStateHandler
1212

1313
print("Loading function create_image")
1414

@@ -42,6 +42,6 @@ def lambda_handler(event: Dict[str, Any], context: Any) -> str:
4242

4343
instance.create_tags(Tags=[{"Key": "CloneStatus", "Value": "IMAGE_CREATED"}])
4444

45-
ServiceNowStateHandler().update_state(state="IMAGE_CREATING", machine_name=name)
45+
MigrationStateHandler().update_state(state="IMAGE_CREATING", machine_name=name)
4646

4747
return ec2_image.image_id

step/lambdas/find_instance.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
from typing import Any, Dict
99

1010
import boto3
11-
from servicenowstate import ServiceNowStateHandler
11+
from migrationstate import MigrationStateHandler
1212

1313
print("Loading function find_instance")
1414

@@ -72,7 +72,7 @@ def lambda_handler(event: Dict[str, Any], context: Any) -> str:
7272
print(e)
7373
event_dict["instance_id"] = "not-found"
7474

75-
ServiceNowStateHandler().update_state(
75+
MigrationStateHandler().update_state(
7676
state="INSTANCE_LAUNCHED", machine_name=event_dict.get("name")
7777
)
7878
return event_dict

step/lambdas/get_copy_status.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
from typing import Any, Dict
99

1010
import boto3
11-
from servicenowstate import ServiceNowStateHandler
11+
from migrationstate import MigrationStateHandler
1212

1313
print("Loading function get_copy_status")
1414

@@ -39,7 +39,7 @@ def lambda_handler(event: Dict[str, Any], context: Any) -> str:
3939

4040
state = ami_state["Images"][0]["State"]
4141
if state == "available":
42-
ServiceNowStateHandler().update_state(
42+
MigrationStateHandler().update_state(
4343
state="IMAGE_COPIED", machine_name=instance_name
4444
)
4545

step/lambdas/get_image_status.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
from typing import Any, Dict
88

99
import boto3
10-
from servicenowstate import ServiceNowStateHandler
10+
from migrationstate import MigrationStateHandler
1111

1212
print("Loading function get_image_status")
1313

@@ -33,7 +33,7 @@ def lambda_handler(event: Dict[str, Any], context: Any) -> str:
3333

3434
state = ami_state["Images"][0]["State"]
3535
if state == "available":
36-
ServiceNowStateHandler().update_state(
36+
MigrationStateHandler().update_state(
3737
state="IMAGE_CREATED", machine_name=instance_name
3838
)
3939

step/lambdas/get_instance_status.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
from typing import Any, Dict
88

99
import boto3
10-
from servicenowstate import ServiceNowStateHandler
10+
from migrationstate import MigrationStateHandler
1111

1212
print("Loading function get_instance_status")
1313

@@ -43,7 +43,7 @@ def lambda_handler(event: Dict[str, Any], context: Any) -> str:
4343
state = "system_failed"
4444

4545
if state == "running":
46-
ServiceNowStateHandler().update_state(
46+
MigrationStateHandler().update_state(
4747
state="INSTANCE_READY", machine_name=instance_name
4848
)
4949

step/lambdas/image_cleanup.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
from typing import Any, Dict, List
99

1010
import boto3
11-
from servicenowstate import ServiceNowStateHandler
11+
from migrationstate import MigrationStateHandler
1212

1313
print("Loading function image_cleanup")
1414

@@ -46,7 +46,7 @@ def lambda_handler(event: Dict[str, Any], context: Any) -> bool:
4646
print(f"Failed. AMI may not exist.\n{str(e)}")
4747
return False
4848

49-
ServiceNowStateHandler().update_state(
49+
MigrationStateHandler().update_state(
5050
state="IMAGE_READY", machine_name=instance_name
5151
)
5252

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# -*- coding: utf-8 -*-
2-
"""Define ServiceNow events."""
2+
"""Define Migration events."""
33
from __future__ import annotations
44

55
import json
@@ -10,7 +10,7 @@
1010
import boto3
1111

1212

13-
class ServiceNowStateHandler:
13+
class MigrationStateHandler:
1414
sqs = None
1515

1616
def update_state(self, state: str, machine_name: str, **kwargs) -> bool:
@@ -19,22 +19,22 @@ def update_state(self, state: str, machine_name: str, **kwargs) -> bool:
1919

2020
print("Event queue: " + os.environ.get("event_queue"))
2121
queue_url = os.environ.get("event_queue")
22-
state_obj = ServiceNowState(state, machine_name, **kwargs)
22+
state_obj = MigrationState(state, machine_name, **kwargs)
2323
print(
2424
sqs.send_message(
2525
QueueUrl=queue_url, MessageBody=json.dumps(state_obj.state_dict)
2626
)
2727
)
2828

2929

30-
class ServiceNowException(Exception):
31-
"""Define the structure of a ServiceNow exception."""
30+
class MigrationException(Exception):
31+
"""Define the structure of a Migration exception."""
3232

3333
pass
3434

3535

36-
class ServiceNowState:
37-
"""Define the structure of a ServiceNow state."""
36+
class MigrationState:
37+
"""Define the structure of a Migration state."""
3838

3939
state_dict = {}
4040

@@ -66,7 +66,7 @@ class ServiceNowState:
6666
def __init__(self, state: str, machine_name: str = "NA", **kwargs) -> None:
6767
"""Initialize the State."""
6868
if state not in self.STATES:
69-
raise ServiceNowException(f"State: {state} is unrecognized!")
69+
raise MigrationException(f"State: {state} is unrecognized!")
7070

7171
self.machine_name: str = machine_name.upper()
7272
self.state: str = state

step/lambdas/share_image.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
from typing import Any, Dict
88

99
import boto3
10-
from servicenowstate import ServiceNowStateHandler
10+
from migrationstate import MigrationStateHandler
1111

1212
print("Loading function share_image")
1313

@@ -59,7 +59,7 @@ def lambda_handler(event: Dict[str, Any], context: Any) -> bool:
5959
print(e)
6060
return False
6161

62-
ServiceNowStateHandler().update_state(
62+
MigrationStateHandler().update_state(
6363
state="IMAGE_SHARED", machine_name=instance_name
6464
)
6565
return True

step/lambdas/split_image.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
from typing import Any, Dict, List
99

1010
import boto3
11-
from servicenowstate import ServiceNowStateHandler
11+
from migrationstate import MigrationStateHandler
1212

1313
print("Loading function split_image")
1414

@@ -90,7 +90,7 @@ def lambda_handler(event: Dict[str, Any], context: Any) -> str:
9090
print(e)
9191
return ""
9292

93-
ServiceNowStateHandler().update_state(
93+
MigrationStateHandler().update_state(
9494
state="IMAGE_SPLIT", machine_name=instance_name
9595
)
9696

0 commit comments

Comments
 (0)