Skip to content

Commit

Permalink
added add public ip and wait for IP attributes
Browse files Browse the repository at this point in the history
  • Loading branch information
Costya-Y committed Sep 8, 2024
1 parent 3abba6a commit 36326d6
Show file tree
Hide file tree
Showing 3 changed files with 163 additions and 35 deletions.
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -61,4 +61,3 @@ cloudshell_config.yml

.idea/
src/run_driver.py

30 changes: 30 additions & 0 deletions deployments/deployment-path.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,16 @@ node_types:
separation. The default source cidr, if not specified, is any (0.0.0.0/0).
For example: 80;443:tcp:10.0.0.0/24;200-220:udp;icmp;icmp:10.0.0.0/24"
tags: [ user_input ]
Wait for IP:
type: boolean
default: false
description: "If set to False the deployment will not wait for the VM to get an IP."
tags: [ user_input ]
Add Public IP:
type: boolean
default: false
description: "Use a public IP address to communicate with the virtual machine from outside the virtual network. In most cases the public IP address is associated with the VM until it's stopped or terminated, after which it's no longer available for you to use. It's possible to reserve a public IP in Azure to ensure that the IP is available to your subscription at any time."
tags: [ user_input ]
Autoload:
type: boolean
description: "Enables the automatic execution of the Autoload command during reservation Setup."
Expand Down Expand Up @@ -262,6 +272,16 @@ node_types:
separation. The default source cidr, if not specified, is any (0.0.0.0/0).
For example: 80;443:tcp:10.0.0.0/24;200-220:udp;icmp;icmp:10.0.0.0/24"
tags: [ user_input ]
Wait for IP:
type: boolean
default: false
description: "If set to False the deployment will not wait for the VM to get an IP."
tags: [ user_input ]
Add Public IP:
type: boolean
default: false
description: "Use a public IP address to communicate with the virtual machine from outside the virtual network. In most cases the public IP address is associated with the VM until it's stopped or terminated, after which it's no longer available for you to use. It's possible to reserve a public IP in Azure to ensure that the IP is available to your subscription at any time."
tags: [ user_input ]
Autoload:
type: boolean
description: "Enables the automatic execution of the Autoload command during reservation Setup."
Expand Down Expand Up @@ -302,6 +322,16 @@ node_types:
separation. The default source cidr, if not specified, is any (0.0.0.0/0).
For example: 80;443:tcp:10.0.0.0/24;200-220:udp;icmp;icmp:10.0.0.0/24"
tags: [ user_input ]
Wait for IP:
type: boolean
default: false
description: "If set to False the deployment will not wait for the VM to get an IP."
tags: [ user_input ]
Add Public IP:
type: boolean
default: false
description: "Use a public IP address to communicate with the virtual machine from outside the virtual network. In most cases the public IP address is associated with the VM until it's stopped or terminated, after which it's no longer available for you to use. It's possible to reserve a public IP in Azure to ensure that the IP is available to your subscription at any time."
tags: [ user_input ]
Autoload:
type: boolean
description: "Enables the automatic execution of the Autoload command during reservation Setup."
Expand Down
167 changes: 133 additions & 34 deletions src/driver.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,38 +3,22 @@
from typing import TYPE_CHECKING

from cloudshell.cp.core.cancellation_manager import CancellationContextManager
from cloudshell.cp.core.request_actions import GetVMDetailsRequestActions, \
PrepareSandboxInfraRequestActions, CleanupSandboxInfraRequestActions

from cloudshell.cp.core.reservation_info import ReservationInfo
from cloudshell.shell.core.resource_driver_interface import ResourceDriverInterface
from cloudshell.shell.core.session.cloudshell_session import CloudShellSessionContext
from cloudshell.shell.core.session.logging_session import LoggingSessionContext

from cloudshell.cp.proxmox.flows import (
ProxmoxDeleteFlow as DeleteFlow,
ProxmoxSnapshotFlow as SnapshotFlow,
ProxmoxAutoloadFlow,
ProxmoxPowerFlow,
ProxmoxGetVMDetailsFlow,
)
from cloudshell.cp.gcp.flows.deploy_flow import get_deploy_params
from cloudshell.cp.proxmox.flows.refresh_ip import refresh_ip

from cloudshell.cp.proxmox.handlers.proxmox_handler import ProxmoxHandler

from cloudshell.cp.proxmox.models.deploy_app import (
ProxmoxDeployVMRequestActions,
InstanceFromTemplateDeployApp,
InstanceFromVMDeployApp,
)
from cloudshell.cp.proxmox.models.deployed_app import (
ProxmoxDeployedVMActions,
ProxmoxGetVMDetailsRequestActions,
InstanceFromTemplateDeployedApp,
InstanceFromVMDeployedApp,
)
from cloudshell.cp.proxmox.resource_config import ProxmoxResourceConfig

from cloudshell.cp.gcp.flows.cleanup_infra_flow import CleanUpGCPInfraFlow
from cloudshell.cp.gcp.flows.power_flow import GCPPowerFlow
from cloudshell.cp.gcp.flows.prepare_infra_flow import PrepareGCPInfraFlow
from cloudshell.cp.gcp.flows.vm_details_flow import GCPGetVMDetailsFlow
from cloudshell.cp.gcp.helpers import constants
from cloudshell.cp.gcp.models.deployed_app import InstanceFromScratchDeployApp, \
GCPDeployedVMRequestActions
from cloudshell.cp.gcp.resource_conf import GCPResourceConfig

if TYPE_CHECKING:
from cloudshell.shell.core.driver_context import (
Expand Down Expand Up @@ -99,10 +83,34 @@ def Deploy(self, context, request=None, cancellation_context=None):
return deploy_flow.deploy(request_actions=request_actions)

def PowerOn(self, context, ports):
pass
"""Called during sandbox's teardown.

Can also be run manually by the sandbox end-user from the deployed
App's commands pane. Method shuts down (or powers off) the VM instance.
If the operation fails, method should raise an exception.
"""
with LoggingSessionContext(context) as logger:
logger.info("Starting Power Off command")
api = CloudShellSessionContext(context).get_api()
resource_config = GCPResourceConfig.from_context(context, api=api)
resource = context.remote_endpoints[0]
actions = GCPDeployedVMRequestActions.from_remote_resource(resource, api)
GCPPowerFlow(actions.deployed_app, resource_config).power_on()

def PowerOff(self, context, ports):
pass
"""Called during sandbox's teardown.

Can also be run manually by the sandbox end-user from the deployed
App's commands pane. Method shuts down (or powers off) the VM instance.
If the operation fails, method should raise an exception.
"""
with LoggingSessionContext(context) as logger:
logger.info("Starting Power Off command")
api = CloudShellSessionContext(context).get_api()
resource_config = GCPResourceConfig.from_context(context, api=api)
resource = context.remote_endpoints[0]
actions = GCPDeployedVMRequestActions.from_remote_resource(resource, api)
GCPPowerFlow(actions.deployed_app, resource_config).power_off()

def orchestration_power_on(self, context, ports):
pass
Expand All @@ -114,16 +122,79 @@ def PowerCycle(self, context, ports, delay):
pass

def remote_refresh_ip(self, context, ports, cancellation_context):
pass
"""Called when reserving a sandbox during setup.

Call for each app in the sandbox can also be run manually by the sandbox
end-user from the deployed App's commands pane. Method retrieves the VM's
updated IP address from the cloud provider and sets it on the deployed App
resource. Both private and public IPs are retrieved, as appropriate. If the
operation fails, method should raise an exception.
"""
with LoggingSessionContext(context) as logger:
logger.info("Starting Remote Refresh IP command")
api = CloudShellSessionContext(context).get_api()
resource_config = GCPResourceConfig.from_context(context, api=api)
resource = context.remote_endpoints[0]
actions = GCPDeployedVMRequestActions.from_remote_resource(resource, api)
cancellation_manager = CancellationContextManager(cancellation_context)
with ProxmoxHandler.from_config(resource_config) as si:
return refresh_ip(
si, actions.deployed_app, resource_config, cancellation_manager
)

def DeleteInstance(self, context, ports):
pass

def PrepareSandboxInfra(self, context, request, cancellation_context):
pass
"""

:param ResourceCommandContext context:
:param str request:
:param CancellationContext cancellation_context:
:return:
:rtype: str
"""
with LoggingSessionContext(context) as logger:
logger.info("Starting Prepare Sandbox Infra command...")
logger.debug(f"Request: {request}")
api = CloudShellSessionContext(context).get_api()
resource_config = GCPResourceConfig.from_context(
context=context, api=api
)

request_actions = PrepareSandboxInfraRequestActions.from_request(request)
cancellation_manager = CancellationContextManager(cancellation_context)

prepare_sandbox_flow = PrepareGCPInfraFlow(
logger=logger,
config=resource_config,
)

return prepare_sandbox_flow.prepare(request_actions=request_actions)

def CleanupSandboxInfra(self, context, request):
pass
"""

:param ResourceCommandContext context:
:param str request:
:return:
:rtype: str
"""
with LoggingSessionContext(context) as logger:
logger.info("Starting Cleanup Sandbox Infra command...")
api = CloudShellSessionContext(context).get_api()
resource_config = GCPResourceConfig.from_context(
context=context, api=api
)

request_actions = CleanupSandboxInfraRequestActions.from_request(request)

cleanup_flow = CleanUpGCPInfraFlow(
config=resource_config,
logger=logger,
)

return cleanup_flow.cleanup(request_actions=request_actions)

def get_inventory(self, context):
pass
Expand All @@ -134,11 +205,39 @@ def GetAccessKey(self, context, ports):
def SetAppSecurityGroups(self, context, request):
pass

def GetVmDetails(self, context, cancellation_context, requests):
pass
def GetVmDetails(self, context, requests, cancellation_context):
"""

def AddCustomTags(self, context, request, ports):
pass
:param ResourceCommandContext context:
:param str requests:
:param CancellationContext cancellation_context:
:return:
"""
with LoggingSessionContext(context) as logger:
logger.info("Starting Get VM Details command...")
logger.debug(f"Requests: {requests}")
api = CloudShellSessionContext(context).get_api()
resource_config = GCPResourceConfig.from_context(
context=context, api=api
)

for deploy_app_cls in (
InstanceFromScratchDeployApp,
):
GetVMDetailsRequestActions.register_deployment_path(deploy_app_cls)

request_actions = GetVMDetailsRequestActions.from_request(
request=requests, cs_api=api
)

# cancellation_manager = CancellationContextManager(cancellation_context)

vm_details_flow = GCPGetVMDetailsFlow(
logger=logger,
config=resource_config,
)

return vm_details_flow.get_vm_details(request_actions=request_actions)

def cleanup(self):
pass

0 comments on commit 36326d6

Please sign in to comment.