Skip to content

Commit a691ab5

Browse files
Add new Compute Engine Operators and fix system tests (#25608)
1 parent f304df7 commit a691ab5

File tree

18 files changed

+4466
-1034
lines changed

18 files changed

+4466
-1034
lines changed

airflow/providers/google/cloud/hooks/compute.py

Lines changed: 486 additions & 56 deletions
Large diffs are not rendered by default.

airflow/providers/google/cloud/hooks/compute_ssh.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -257,7 +257,7 @@ def _connect_to_instance(self, user, hostname, pkey, proxy_command) -> paramiko.
257257
raise
258258
self.log.info("Failed to connect. Waiting %ds to retry", time_to_wait)
259259
time.sleep(time_to_wait)
260-
raise AirflowException("Caa not connect to instance")
260+
raise AirflowException("Can not connect to instance")
261261

262262
def _authorize_compute_engine_instance_metadata(self, pubkey):
263263
self.log.info("Appending SSH public key to instance metadata")
Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
1+
#
2+
# Licensed to the Apache Software Foundation (ASF) under one
3+
# or more contributor license agreements. See the NOTICE file
4+
# distributed with this work for additional information
5+
# regarding copyright ownership. The ASF licenses this file
6+
# to you under the Apache License, Version 2.0 (the
7+
# "License"); you may not use this file except in compliance
8+
# with the License. You may obtain a copy of the License at
9+
#
10+
# http://www.apache.org/licenses/LICENSE-2.0
11+
#
12+
# Unless required by applicable law or agreed to in writing,
13+
# software distributed under the License is distributed on an
14+
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
# KIND, either express or implied. See the License for the
16+
# specific language governing permissions and limitations
17+
# under the License.
18+
"""This module contains Google Compute Engine links."""
19+
from __future__ import annotations
20+
21+
from typing import TYPE_CHECKING
22+
23+
from airflow.models import BaseOperator
24+
from airflow.providers.google.cloud.links.base import BaseGoogleLink
25+
26+
if TYPE_CHECKING:
27+
from airflow.utils.context import Context
28+
29+
COMPUTE_BASE_LINK = "https://console.cloud.google.com/compute"
30+
COMPUTE_LINK = (
31+
COMPUTE_BASE_LINK + "/instancesDetail/zones/{location_id}/instances/{resource_id}?project={project_id}"
32+
)
33+
COMPUTE_TEMPLATE_LINK = COMPUTE_BASE_LINK + "/instanceTemplates/details/{resource_id}?project={project_id}"
34+
COMPUTE_GROUP_MANAGER_LINK = (
35+
COMPUTE_BASE_LINK + "/instanceGroups/details/{location_id}/{resource_id}?project={project_id}"
36+
)
37+
38+
39+
class ComputeInstanceDetailsLink(BaseGoogleLink):
40+
"""Helper class for constructing Compute Instance details Link"""
41+
42+
name = "Compute Instance details"
43+
key = "compute_instance_details"
44+
format_str = COMPUTE_LINK
45+
46+
@staticmethod
47+
def persist(
48+
context: Context,
49+
task_instance: BaseOperator,
50+
location_id: str,
51+
resource_id: str,
52+
project_id: str | None,
53+
):
54+
task_instance.xcom_push(
55+
context,
56+
key=ComputeInstanceDetailsLink.key,
57+
value={
58+
"location_id": location_id,
59+
"resource_id": resource_id,
60+
"project_id": project_id,
61+
},
62+
)
63+
64+
65+
class ComputeInstanceTemplateDetailsLink(BaseGoogleLink):
66+
"""Helper class for constructing Compute Instance Template details Link"""
67+
68+
name = "Compute Instance Template details"
69+
key = "compute_instance_template_details"
70+
format_str = COMPUTE_TEMPLATE_LINK
71+
72+
@staticmethod
73+
def persist(
74+
context: Context,
75+
task_instance: BaseOperator,
76+
resource_id: str,
77+
project_id: str | None,
78+
):
79+
task_instance.xcom_push(
80+
context,
81+
key=ComputeInstanceTemplateDetailsLink.key,
82+
value={
83+
"resource_id": resource_id,
84+
"project_id": project_id,
85+
},
86+
)
87+
88+
89+
class ComputeInstanceGroupManagerDetailsLink(BaseGoogleLink):
90+
"""Helper class for constructing Compute Instance Group Manager details Link"""
91+
92+
name = "Compute Instance Group Manager"
93+
key = "compute_instance_group_manager_details"
94+
format_str = COMPUTE_GROUP_MANAGER_LINK
95+
96+
@staticmethod
97+
def persist(
98+
context: Context,
99+
task_instance: BaseOperator,
100+
location_id: str,
101+
resource_id: str,
102+
project_id: str | None,
103+
):
104+
task_instance.xcom_push(
105+
context,
106+
key=ComputeInstanceGroupManagerDetailsLink.key,
107+
value={
108+
"location_id": location_id,
109+
"resource_id": resource_id,
110+
"project_id": project_id,
111+
},
112+
)

0 commit comments

Comments
 (0)