Skip to content

Commit 7cd40f7

Browse files
authored
Merge pull request #93 from 2ndWatch/add-instance-sizing
Update CE to handle instance type updates
2 parents d67add3 + 4639fc3 commit 7cd40f7

File tree

9 files changed

+50
-10
lines changed

9 files changed

+50
-10
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: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,23 @@ 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(
86+
"instance_types", ""
87+
).split(",")
88+
if len(self.target_machines) == len(self.target_instance_types):
89+
self.target_instances: Dict[str, str] = dict(
90+
zip(self.target_machines, self.target_instance_types)
91+
)
92+
else:
93+
print(
94+
"WARNING: Misconfiguration of CLOUDENDURE_INSTANCE_TYPES and CLOUDENDURE_MACHINES. These should be the same length!"
95+
)
96+
self.target_instances = {}
97+
98+
self.lagging_machines: List[str] = []
99+
self.ready_machines: List[str] = []
100+
self.nonexistent_machines: List[str] = []
101+
self.launched_machines: List[str] = []
85102
self.migration_wave: str = self.config.active_config.get("migration_wave", "0")
86103
self.max_lag_ttl: int = self.config.active_config.get("max_lag_ttl", 90)
87104

@@ -504,6 +521,10 @@ def update_blueprint(self) -> bool:
504521
if self.security_group_id:
505522
blueprint["securityGroupIDs"] = [self.security_group_id]
506523

524+
instance_type = self.target_instances.get(machine_name, "")
525+
if instance_type:
526+
blueprint["instanceType"] = instance_type
527+
507528
# Update machine tags
508529
blueprint["tags"] = [
509530
{
@@ -680,8 +701,8 @@ def status(self) -> bool:
680701
)
681702
return False
682703
if not machine_exist:
683-
print("ERROR: Machine: " + _machine + " does not exist!")
684-
return False
704+
print(f"ERROR: Machine: {_machine} does not exist!")
705+
self.nonexistent_machines.append(_machine)
685706

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

cloudendure/cloudendure_api/configuration.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -222,9 +222,7 @@ def get_api_key_with_prefix(self, identifier: str) -> str:
222222
223223
"""
224224
if self.api_key.get(identifier) and self.api_key_prefix.get(identifier):
225-
return (
226-
f"{self.api_key_prefix[identifier]} {self.api_key[identifier]}"
227-
) # noqa: E501
225+
return f"{self.api_key_prefix[identifier]} {self.api_key[identifier]}" # noqa: E501
228226
if self.api_key.get(identifier):
229227
return self.api_key[identifier]
230228
return ""

cloudendure/cloudendure_api/test/test_replication_api.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ def test_projects_project_id_replication_configurations_post(self):
7171
pass
7272

7373
def test_projects_project_id_replication_configurations_replication_configuration_id_patch(
74-
self
74+
self,
7575
):
7676
"""Test case for projects_project_id_replication_configurations_replication_configuration_id_patch
7777

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)