Skip to content

Commit

Permalink
updated some imports and types
Browse files Browse the repository at this point in the history
  • Loading branch information
Costya-Y committed Sep 13, 2024
1 parent 3a70e0d commit 901ec03
Show file tree
Hide file tree
Showing 9 changed files with 23 additions and 18 deletions.
22 changes: 11 additions & 11 deletions cloudshell/cp/gcp/flows/deploy_instance/base_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,17 +21,14 @@
from cloudshell.cp.gcp.actions.vm_details_actions import VMDetailsActions
from cloudshell.cp.gcp.flows.deploy_instance.commands import DeployInstanceCommand
from cloudshell.cp.gcp.helpers.network_tag_helper import get_network_tags, InboundPort
from cloudshell.cp.core.request_actions.models import DeployAppResult, Attribute

if TYPE_CHECKING:
from cloudshell.cp.gcp.handlers.instance import Instance
from cloudshell.cp.gcp.models.deploy_app import BaseGCPDeployApp
from cloudshell.cp.gcp.resource_conf import GCPResourceConfig
from cloudshell.api.cloudshell_api import CloudShellAPISession, ReservationInfo
from cloudshell.cp.core.cancellation_manager import CancellationContextManager
from cloudshell.cp.core.request_actions.models import (
DeployAppResult,
VmDetailsData,
)
from cloudshell.cp.core.request_actions.models import VmDetailsData

logger = logging.getLogger(__name__)

Expand Down Expand Up @@ -74,16 +71,16 @@ def _prepare_deploy_app_result(
vmUuid=json.dumps(
{
"instance_name": instance_handler.instance.name,
"zone": instance_handler.instance.zone
"zone": instance_handler.instance.zone.rsplit("/", 1)[-1],
}
),
vmName=instance_handler.instance.name,
vmDetailsData=vm_details_data,
deployedAppAdditionalData={
"ip_regex": deploy_app.ip_regex,
"refresh_ip_timeout": deploy_app.refresh_ip_timeout,
"auto_power_off": deploy_app.auto_power_off,
"auto_delete": deploy_app.auto_delete,
# "auto_power_off": deploy_app.auto_power_off,
# "auto_delete": deploy_app.auto_delete,
},
deployedAppAttributes=self._prepare_app_attrs(
deploy_app,
Expand Down Expand Up @@ -146,7 +143,7 @@ def _deploy(self, request_actions: DeployVMRequestActions) -> DeployAppResult:
cancellation_manager=self.cancellation_manager,
).execute()

logger.info(f"Instance {deployed_instance.name} created")
logger.info(f"Instance {deployed_instance.instance.name} created")

firewall_actions = FirewallPolicyActions(
credentials=self.resource_config.credentials
Expand All @@ -158,7 +155,8 @@ def _deploy(self, request_actions: DeployVMRequestActions) -> DeployAppResult:
inbound_port=inbound_port,
)

logger.info(f"Preparing Deploy App result for the {deployed_instance.name}")
logger.info(f"Preparing Deploy App result for the "
f"{deployed_instance.instance.name}")
return self._prepare_deploy_app_result(
deploy_app=deploy_app,
instance_handler=deployed_instance,
Expand All @@ -173,7 +171,9 @@ def _prepare_app_attrs(
) -> list[Attribute]:
deployed_app_attrs = [
Attribute("User", deploy_app.user),
Attribute("Public IP", InterfaceHelper.get_public_ip(instance_handler)),
Attribute("Public IP", InterfaceHelper(
instance_handler.instance
).get_public_ip()),
]
if password:
deployed_app_attrs.append(Attribute("Password", password))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ def _execute(self) -> compute.Instance:
except Exception as e:
raise

return self._instance_handler.instance
return self._instance_handler

def rollback(self):
with suppress(NotFound):
Expand Down
3 changes: 2 additions & 1 deletion cloudshell/cp/gcp/flows/power_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,10 @@
from attr import define
from typing import TYPE_CHECKING

from cloudshell.cp.gcp.handlers.instance import InstanceHandler

if TYPE_CHECKING:
from cloudshell.cp.gcp.handlers.instance import InstanceHandler

from cloudshell.cp.gcp.models.deployed_app import BaseGCPDeployApp
from cloudshell.cp.gcp.resource_conf import GCPResourceConfig

Expand Down
2 changes: 1 addition & 1 deletion cloudshell/cp/gcp/handlers/instance.py
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ def _add_interfaces(self, instance):

@define
class InstanceHandler(BaseGCPHandler):
instance: Instance
instance: compute.Instance

@cached_property
def instance_client(self):
Expand Down
2 changes: 1 addition & 1 deletion cloudshell/cp/gcp/handlers/vpc.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ def create(cls, sandbox_id: str, credentials: compute.Credentials) -> Self:
operation_client.wait(operation=operation.name, project=credentials.project_id)

logger.info(f"VPC network '{network.name}' created successfully.")
return cls(credentials, network)
return cls.get_vpc_by_name(credentials=credentials, network_name=network)

def delete(self) -> None:
operation = self.network_client.delete(
Expand Down
2 changes: 2 additions & 0 deletions cloudshell/cp/gcp/models/attributes.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ class BaseGCPDeploymentAppAttributeNames:
add_public_ip = "Add Public IP"
autoload = "Autoload"
autogenerated_name = "Autogenerated Name"
ip_regex = "IP Regex"
refresh_ip_timeout = "Refresh IP Timeout"


class GCPFromScratchDeploymentAppAttributeNames(BaseGCPDeploymentAppAttributeNames):
Expand Down
2 changes: 2 additions & 0 deletions cloudshell/cp/gcp/models/deploy_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,8 @@ class BaseGCPDeployApp(DeployApp):
zone = ResourceAttrRODeploymentPath(ATTR_NAMES.zone)
machine_type = ResourceAttrRODeploymentPath(ATTR_NAMES.machine_type)
maintenance = ResourceAttrRODeploymentPath(ATTR_NAMES.maintenance)
ip_regex = ResourceAttrRODeploymentPath(ATTR_NAMES.ip_regex)
refresh_ip_timeout = ResourceIntAttrRODeploymentPath(ATTR_NAMES.refresh_ip_timeout)
auto_restart = OnOffBoolAttrRO(ATTR_NAMES.auto_restart)
ip_forwarding = ResourceBoolAttrRODeploymentPath(ATTR_NAMES.ip_forwarding)
inbound_ports = InboundPortsAttrRO(ATTR_NAMES.inbound_ports)
Expand Down
4 changes: 2 additions & 2 deletions cloudshell/cp/gcp/models/deployed_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ class BaseGCPDeployedApp(DeployedApp):
maintenance = ResourceAttrRODeploymentPath(ATTR_NAMES.maintenance)
auto_restart = ResourceBoolAttrRODeploymentPath(ATTR_NAMES.auto_restart)
ip_forwarding = ResourceBoolAttrRODeploymentPath(ATTR_NAMES.ip_forwarding)
# network = ResourceAttrRODeploymentPath(ATTR_NAMES.network)
# sub_network = ResourceAttrRODeploymentPath(ATTR_NAMES.sub_network)
ip_regex = ResourceAttrRODeploymentPath(ATTR_NAMES.ip_regex)
refresh_ip_timeout = ResourceIntAttrRODeploymentPath(ATTR_NAMES.refresh_ip_timeout)
inbound_ports = ResourceAttrRODeploymentPath(ATTR_NAMES.inbound_ports)
custom_tags = CustomTagsAttrRO(ATTR_NAMES.custom_tags)
wait_for_ip = ResourceBoolAttrRODeploymentPath(ATTR_NAMES.wait_for_ip)
Expand Down
2 changes: 1 addition & 1 deletion version.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.1.32
0.1.40

0 comments on commit 901ec03

Please sign in to comment.