qontract-reconcile 0.10.1rc613__py3-none-any.whl → 0.10.1rc614__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -2,6 +2,11 @@ import logging
2
2
  import tempfile
3
3
  from typing import Optional
4
4
 
5
+ from jinja2 import Environment, FileSystemLoader
6
+ from pydantic import BaseModel
7
+
8
+ from reconcile.ocm.types import OCMSpec
9
+ from reconcile.utils.constants import PROJ_ROOT
5
10
  from reconcile.utils.jobcontroller.controller import K8sJobController
6
11
  from reconcile.utils.jobcontroller.models import JobConcurrencyPolicy, JobStatus
7
12
  from reconcile.utils.ocm_base_client import OCMBaseClient
@@ -13,6 +18,27 @@ from reconcile.utils.rosa.rosa_cli import (
13
18
  )
14
19
 
15
20
 
21
+ class RosaSessionBuilder(BaseModel, arbitrary_types_allowed=True):
22
+ aws_iam_role: str
23
+ job_controller: K8sJobController
24
+ image: str
25
+ service_account: str
26
+
27
+ def build(
28
+ self, ocm_api: OCMBaseClient, aws_account_id: str, region: str, ocm_org_id: str
29
+ ) -> "RosaSession":
30
+ return RosaSession(
31
+ aws_account_id=aws_account_id,
32
+ aws_region=region,
33
+ aws_iam_role=self.aws_iam_role,
34
+ ocm_org_id=ocm_org_id,
35
+ ocm_api=ocm_api,
36
+ job_controller=self.job_controller,
37
+ image=self.image,
38
+ service_account=self.service_account,
39
+ )
40
+
41
+
16
42
  class RosaSession:
17
43
  """
18
44
  A ROSA session contains the required context to interact with OCM and AWS
@@ -86,6 +112,16 @@ class RosaSession:
86
112
  raise RosaCliException(status, cmd, LogHandle(log_file))
87
113
  return RosaCliResult(status, cmd, LogHandle(log_file))
88
114
 
115
+ def create_hcp_cluster(
116
+ self, cluster_name: str, spec: OCMSpec, dry_run: bool
117
+ ) -> RosaCliResult:
118
+ """
119
+ Create a ROSA HCP cluster in the OCM org and AWS account of this session.
120
+ If dry-run is provided, cluster creation is simulated and invalid configuration
121
+ data is highlighted as errors.
122
+ """
123
+ return self.cli_execute(rosa_hcp_creation_script(cluster_name, spec, dry_run))
124
+
89
125
  def upgrade_account_roles(
90
126
  self, role_prefix: str, minor_version: str, channel_group: str, dry_run: bool
91
127
  ) -> None:
@@ -116,3 +152,20 @@ class RosaSession:
116
152
  annotations={"qontract.rosa.cluster_id": cluster_id},
117
153
  )
118
154
  result.write_logs_to_logger(logging.info)
155
+
156
+
157
+ def rosa_hcp_creation_script(cluster_name: str, cluster: OCMSpec, dry_run: bool) -> str:
158
+ """
159
+ Builds a bash script to install a ROSA clusters.
160
+ """
161
+ # template_path = PROJ_ROOT / "templates" / "rosa-hcp-cluster-creation.sh.j2"
162
+ # with open(template_path, encoding="utf-8") as f:
163
+ env = Environment(loader=FileSystemLoader(PROJ_ROOT / "templates"))
164
+ env.filters["split"] = lambda value, sep: value.split(sep)
165
+ template = env.get_template("rosa-hcp-cluster-creation.sh.j2")
166
+ # template = Template(f.read(), keep_trailing_newline=True, trim_blocks=True)
167
+ return template.render(
168
+ cluster_name=cluster_name,
169
+ cluster=cluster,
170
+ dry_run=dry_run,
171
+ )