Skip to content

Commit

Permalink
update to flows. update to vpc handler
Browse files Browse the repository at this point in the history
  • Loading branch information
Costya-Y committed Sep 11, 2024
1 parent 9c41e80 commit 2dc8537
Show file tree
Hide file tree
Showing 7 changed files with 162 additions and 113 deletions.
2 changes: 1 addition & 1 deletion cloudshell/cp/gcp/actions/vm_details_actions.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ def _prepare_vm_network_data(self, instance_handler: InstanceHandler):

vm_network_interface = VmDetailsNetworkInterface(
interfaceId=index,
networkId=subnet_name.split('/')[-1],
networkId=subnet_name,
isPrimary=is_primary,
networkData=network_data,
privateIpAddress=private_ip,
Expand Down
24 changes: 21 additions & 3 deletions cloudshell/cp/gcp/flows/deploy_instance/base_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
from cloudshell.cp.core.flows import AbstractDeployFlow
from cloudshell.cp.core.request_actions import DeployVMRequestActions
from cloudshell.cp.core.rollback import RollbackCommandsManager

from cloudshell.cp.gcp.handlers.vpc import VPCHandler
from cloudshell.cp.gcp.helpers.name_generator import GCPNameGenerator
from cloudshell.cp.gcp.actions.vm_details_actions import VMDetailsActions
from cloudshell.cp.gcp.flows.deploy_instance.commands import DeployInstanceCommand
Expand All @@ -30,7 +32,7 @@ class AbstractGCPDeployFlow(AbstractDeployFlow):
instance_handler: InstanceHandler
resource_config: GCPResourceConfig
cs_api: CloudShellAPISession
reservation_info: ReservationInfo
# reservation_info: ReservationInfo
cancellation_manager: CancellationContextManager

def __attrs_post_init__(self):
Expand Down Expand Up @@ -78,17 +80,25 @@ def _prepare_deploy_app_result(
)

@abstractmethod
def _create_instance(self, deploy_app: BaseGCPDeployApp) -> Instance:
def _create_instance(self, deploy_app: BaseGCPDeployApp, subnet_list: list[str]) \
-> Instance:
""""""
pass

def _deploy(self, request_actions: DeployVMRequestActions) -> DeployAppResult:
"""Deploy Proxmox Instance."""
# noinspection PyTypeChecker

deploy_app: BaseGCPDeployApp = request_actions.deploy_app
subnet_list = [x.subnet_id for x in request_actions.connect_subnets]
if not subnet_list:
subnet_list = []

with self.cancellation_manager:
instance = self._create_instance(deploy_app=deploy_app)
instance = self._create_instance(
deploy_app=deploy_app,
subnet_list=subnet_list
)

with self._rollback_manager:
logger.info(f"Creating Instance {instance.name}")
Expand All @@ -104,3 +114,11 @@ def _deploy(self, request_actions: DeployVMRequestActions) -> DeployAppResult:
deploy_app=deploy_app,
instance_name=deployed_instance.name,
)

def _get_network(self) -> VPCHandler:
"""
Get Network.
"""

network_handler = VPCHandler.get_vpc_by_sandbox_id(self.resource_config.reservation_info.reservation_id)
return network_handler.get_vpc_by_name(network_name)
4 changes: 3 additions & 1 deletion cloudshell/cp/gcp/flows/deploy_instance/from_image.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,11 @@ class GCPDeployInstanceFromImageFlow(AbstractGCPDeployFlow):
def _create_instance(
self,
deploy_app: InstanceFromMachineImageDeployApp,
subnet_list: list[str],
) -> Instance:
"""Create Instance object based on Machine Image."""
return Instance(
deploy_app=deploy_app,
resource_config=self.resource_config
resource_config=self.resource_config,
subnet_list=subnet_list,
).from_machine_image()
4 changes: 3 additions & 1 deletion cloudshell/cp/gcp/flows/deploy_instance/from_scratch.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,11 @@ class GCPDeployInstanceFromScratchFlow(AbstractGCPDeployFlow):
def _create_instance(
self,
deploy_app: InstanceFromScratchDeployApp,
subnet_list: list[str]
) -> Instance:
"""Create Instance object based on provided attributes."""
return Instance(
deploy_app=deploy_app,
resource_config=self.resource_config
resource_config=self.resource_config,
subnet_list = subnet_list,
).from_scratch()
4 changes: 3 additions & 1 deletion cloudshell/cp/gcp/flows/deploy_instance/from_template.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,11 @@ class GCPDeployInstanceFromTemplateFlow(AbstractGCPDeployFlow):
def _create_instance(
self,
deploy_app: InstanceFromTemplateDeployApp,
subnet_list: list[str],
) -> Instance:
"""Create Instance object based on Template."""
return Instance(
deploy_app=deploy_app,
resource_config=self.resource_config
resource_config=self.resource_config,
subnet_list=subnet_list,
).from_template()
Loading

0 comments on commit 2dc8537

Please sign in to comment.