Skip to content

Commit 85c5e7d

Browse files
committed
Update CE to handle instance type updates
1 parent d67add3 commit 85c5e7d

File tree

7 files changed

+44
-6
lines changed

7 files changed

+44
-6
lines changed

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ SHA1 := $$(git log -1 --pretty=%h)
88
CURRENT_BRANCH := $$(git symbolic-ref -q --short HEAD)
99
LATEST_TAG := ${REPO_NAME}:latest
1010
GIT_TAG := ${REPO_NAME}:${SHA1}
11-
VERSION := v0.1.7
11+
VERSION := v0.1.8
1212

1313
info: ## Show information about the current git state.
1414
@echo "Github Project: https://github.com/${REPO_NAME}\nCurrent Branch: ${CURRENT_BRANCH}\nSHA1: ${SHA1}\n"

cloudendure/__version__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
__version__ = "0.1.8"

cloudendure/api.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,9 @@
2121
from requests.models import Response
2222
from requests.sessions import Session
2323

24-
from .config import CloudEndureConfig
25-
from .exceptions import CloudEndureException
24+
from cloudendure.config import CloudEndureConfig
25+
from cloudendure.exceptions import CloudEndureException
26+
from cloudendure.utils import get_user_agent
2627

2728
HOST: str = os.environ.get("CLOUDENDURE_HOST", "https://console.cloudendure.com")
2829
API_VERSION: str = os.environ.get("CLOUDENDURE_API_VERSION", "latest").lower()
@@ -65,6 +66,7 @@ def __init__(self, config: CloudEndureConfig, *args, **kwargs) -> None:
6566
self.session.headers: Dict[str, str] = {
6667
"Content-Type": "application/json",
6768
"Accept": "text/plain",
69+
"User-Agent": get_user_agent(),
6870
}
6971
self.timestamps: Dict[str, Any] = {
7072
"created": time_now,

cloudendure/cloudendure.py

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,19 @@ def __init__(
8282
self.target_machines: List[str] = self.config.active_config.get(
8383
"machines", ""
8484
).split(",")
85+
self.target_instance_types: List[str] = self.config.active_config.get("instance_types", "").split(",")
86+
if len(self.target_machines) == len(self.target_instance_types):
87+
self.target_instances: Dict[str, str] = dict(zip(self.target_machines, self.target_instance_types))
88+
else:
89+
print(
90+
"WARNING: Misconfiguration of CLOUDENDURE_INSTANCE_TYPES and CLOUDENDURE_MACHINES. These should be the same length!"
91+
)
92+
self.target_instances = {}
93+
94+
self.lagging_machines: List[str] = []
95+
self.ready_machines: List[str] = []
96+
self.nonexistent_machines: List[str] = []
97+
self.launched_machines: List[str] = []
8598
self.migration_wave: str = self.config.active_config.get("migration_wave", "0")
8699
self.max_lag_ttl: int = self.config.active_config.get("max_lag_ttl", 90)
87100

@@ -504,6 +517,10 @@ def update_blueprint(self) -> bool:
504517
if self.security_group_id:
505518
blueprint["securityGroupIDs"] = [self.security_group_id]
506519

520+
instance_type = self.target_instances.get(machine_name, "")
521+
if instance_type:
522+
blueprint["instanceType"] = instance_type
523+
507524
# Update machine tags
508525
blueprint["tags"] = [
509526
{
@@ -680,8 +697,8 @@ def status(self) -> bool:
680697
)
681698
return False
682699
if not machine_exist:
683-
print("ERROR: Machine: " + _machine + " does not exist!")
684-
return False
700+
print(f"ERROR: Machine: {_machine} does not exist!")
701+
self.nonexistent_machines.append(_machine)
685702

686703
if machine_status == len(self.target_machines):
687704
print("All Machines in the targeted pool are ready!")

cloudendure/config.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ class CloudEndureConfig:
4040
"private_ip_action": "",
4141
"disk_type": "SSD",
4242
"public_ip": "DONT_ALLOCATE",
43+
"instance_types": "",
4344
}
4445

4546
def __init__(

cloudendure/utils.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,27 @@
1515
from datetime import datetime
1616
from typing import Any, Dict
1717

18+
from cloudendure.__version__ import __version__ as cloudendure_version
19+
1820
first_cap_re: re.Pattern = re.compile("(.)([A-Z][a-z]+)")
1921
all_cap_re: re.Pattern = re.compile("([a-z0-9])([A-Z])")
2022

2123

24+
def get_user_agent(user_agent: str = "cloudendure-python") -> str:
25+
"""Get the current module version.
26+
27+
Args:
28+
user_agent (str): The user agent client designation.
29+
Defaults to: cloudendure-python
30+
31+
Returns:
32+
str: The user agent string representation for the client.
33+
34+
"""
35+
user_agent_str: str = f"{user_agent}/{cloudendure_version}"
36+
return user_agent_str
37+
38+
2239
def get_time_now() -> Dict[str, Any]:
2340
"""Get the current time in UTC as milliseconds.
2441

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
2424
AUTHOR: str = "Mark Beacom, Tom Warnock"
2525
REQUIRES_PYTHON: str = ">=3.7.0"
26-
VERSION: str = "0.1.7"
26+
VERSION: str = os.environ.get("CLOUDENDURE_CLIENT_VERSION", "")
2727

2828
REQUIRED: List[str] = ["requests", "boto3", "fire"]
2929
EXTRAS: Dict[str, List[str]] = {

0 commit comments

Comments
 (0)