Repository navigation
Expand file tree
/
Copy pathmodels.py
More file actions
193 lines (145 loc) · 6.16 KB
/
Copy pathmodels.py
File metadata and controls
193 lines (145 loc) · 6.16 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
"""Data models, configuration schemas, and exception hierarchy.
Defines core structures used across Phase 1 (Validation), Phase 2
(Password Reset), and Phase 3 (Deployment), along with structured error
classification for retry mechanics.
"""
import dataclasses
from typing import Any, Dict, List, Optional
# ==============================================================================
# Custom Error Classification
# ==============================================================================
class DeployerError(Exception):
"""Base error class for operational errors during Phase 2 and Phase 3."""
def __init__(self, message: str, details: Optional[Dict[str, Any]] = None):
super().__init__(message)
self.details = details or {}
class ValidationError(DeployerError):
"""Raised during Phase 1 pre-deployment validation on non-conformances.
Halts runtime immediately without retrying when external system states or
configuration inputs fail mandatory pre-flight checks.
"""
class RetryableError(DeployerError):
"""Raised for transient errors that should trigger exponential backoff.
Examples: Transient network faults, HTTP 429 Too Many Requests (rate
limits), HTTP 500/503 server errors, and socket connection timeouts.
"""
class NonRetryableError(DeployerError):
"""Raised for terminal errors where retrying will not resolve the issue.
Examples: HTTP 400 Bad Request (invalid config parameters), HTTP 401/403
Unauthorized/Forbidden (credential auth failures), and HTTP 404 Not Found.
"""
# ==============================================================================
# Input Configuration Schemas (from config.json)
# ==============================================================================
@dataclasses.dataclass
class VCFDeploymentConfig:
"""Optional configuration block for Phase 3 VCF Installer deployment.
If omitted from DeployerConfig, the deployment pipeline completes after
Phase 2 password rotation and skips Phase 3 mutations.
"""
target_gce_node: str
vcf_appliance_root_password_secret: str
vcf_appliance_local_user_password_secret: str
vcf_installer_fqdn: str
vcf_installer_ip_source: Any
offline_depot_subnet_cidr: str
vcf_appliance_local_user: str = "vcf"
dns_server: Optional[str] = None
@dataclasses.dataclass
class DeployerConfig:
"""Master config document parsed from config.json at runtime by main.py."""
project: str
zone: str
gce_nodes: Any
esxi_root_password_secret: str
vcf_deployment_config: Optional[VCFDeploymentConfig] = None
log_file: Optional[str] = None
log_dir: Optional[str] = None
log_level: Optional[str] = None
@property
def region(self) -> str:
"""Parses GCP region from zone string (e.g.
'us-central1-a' -> 'us-central1').
"""
if "-" in self.zone:
return "-".join(self.zone.split("-")[:-1])
return self.zone
def get_full_node_path(self, node_input: str) -> str:
"""Constructs full GCE node resource string if short name provided."""
if node_input.startswith("projects/"):
return node_input
return f"projects/{self.project}/zones/{self.zone}/instances/{node_input}"
def get_full_secret_path(self, secret_input: str) -> str:
"""Constructs full Secret Manager resource path if short secret name provided."""
if secret_input.startswith("projects/"):
if "/versions/" not in secret_input:
return f"{secret_input}/versions/latest"
return secret_input
return f"projects/{self.project}/secrets/{secret_input}/versions/latest"
# ==============================================================================
# Infrastructure Inspection Structures (Phase 1 Caching)
# ==============================================================================
@dataclasses.dataclass
class SubnetworkInfo:
"""Subnetwork metadata attached to a GCE primary or dynamic network interface."""
subnetwork_uri: str
vlan_id: int
network_uri: str
cidr: Optional[str] = None
@dataclasses.dataclass
class GCEInstanceDetails:
"""Complete compute instance attributes cached after initial GCE inspection."""
instance_resource_string: str
short_name: str
project: str
zone: str
primary_ip: str
boot_image_name: str
subnetworks: List[SubnetworkInfo]
tags: List[str]
tags_fingerprint: str
labels: Dict[str, str] = dataclasses.field(default_factory=dict)
label_fingerprint: str = ""
# ==============================================================================
# Phase 1 -> Phase 2 & 3 Context structures
# ==============================================================================
@dataclasses.dataclass(frozen=True)
class ValidationContext:
"""Immutable data context holding deduced variables and secrets.
Produced upon completion of Phase 1 pre-deployment validation and passed
sequentially to Phase 2 and Phase 3 modules.
"""
# Mapping of ESXi GCE node resource strings to cached GCEInstanceDetails
esxi_nodes: Dict[str, GCEInstanceDetails]
new_esxi_root_password: str
# Optional fields populated only if vcf_deployment_config was provided
target_esxi_ip: Optional[str] = None
vcf_installer_ip: Optional[str] = None
vcf_installer_ova_url: Optional[str] = None
vlan_id: Optional[int] = None
port_group_name: Optional[str] = None
sddc_manager_netmask: Optional[str] = None
sddc_manager_gateway: Optional[str] = None
vcf_vm_name: Optional[str] = None
vcf_domain: Optional[str] = None
vcf_searchpath: Optional[str] = None
ssl_thumbprint: Optional[str] = None
vcf_appliance_root_password: Optional[str] = None
vcf_appliance_local_password: Optional[str] = None
vcf_appliance_local_user: Optional[str] = "admin"
dns_server: Optional[str] = None
drift_manager_p4sa_email: Optional[str] = None
vcf_installer_ova_sha256: Optional[str] = None
# ==============================================================================
# Hardware Discovery Structures
# ==============================================================================
@dataclasses.dataclass
class VDQDiskInfo:
"""Representation of storage disk discovered via /sbin/vdq -q over SSH."""
name: str
device_path: str
state: str
eligible_for_use: bool
is_ssd: bool
capacity_bytes: int
details: Optional[Dict[str, Any]] = None