def test_sandbox_inputs(self, automation_api, logger, details): # automation_api.return_value = 'test-val-1' # details.ReservationDescription.Id = 'be015364-9640-4ac5-b6ca-f26e1c6d44c8' # automation_api.GetReservationDetails.return_value = details sandbox = Sandbox() param = sandbox.get_user_param('MY_PARAM') self.assertEqual(param, "PARAM-VALUE")
def main(): sandbox = Sandbox() #session = script_helpers.get_api_session() #sandbox_id = script_helpers.get_reservation_context_details().id #sandbox_resources = session.GetReservationDetails(sandbox_id).ReservationDescription.Resources sandbox_resources = sandbox.automation_api.GetReservationDetails( sandbox.id).ReservationDescription.Resources static_vms = [ res for res in sandbox_resources if (res.ResourceModelName == 'vCenter Static VM' and sandbox. automation_api.GetAttributeValue(res.Name, 'Auto Power Off').Value) ] if static_vms.__len__() > 0: for static_vm in static_vms: #sandbox.automation_api.ExecuteResourceConnectedCommand( # reservationId=sandbox.id, # resourceFullPath=static_vm.Name, # commandName='remote_restore_snapshot', # commandTag='connectivity', # parameterValues=['default'], # printOutput=True #) sandbox.automation_api.ExecuteResourceConnectedCommand( reservationId=sandbox.id, resourceFullPath=static_vm.Name, commandName='PowerOff', commandTag='power', parameterValues=[], printOutput=True) else: sandbox.automation_api.WriteMessageToReservationOutput( reservationId=sandbox.id, message='No Static VMs to turn off!') #sandbox = Sandbox() DefaultTeardownWorkflow().register(sandbox) sandbox.execute_teardown()
def main(): sandbox = Sandbox() #session = script_helpers.get_api_session() #sandbox_id = script_helpers.get_reservation_context_details().id #sandbox_resources = session.GetReservationDetails(sandbox_id).ReservationDescription.Resources sandbox_resources = sandbox.automation_api.GetReservationDetails( sandbox.id).ReservationDescription.Resources static_vms = [ res for res in sandbox_resources if res.ResourceModelName == 'vCenter Static VM' ] if static_vms.__len__() > 0: for static_vm in static_vms: sandbox.automation_api.ExecuteResourceConnectedCommand( reservationId=sandbox.id, resourceFullPath=static_vm.Name, commandName='PowerOn', commandTag='power', parameterValues=[], printOutput=True) else: session.WriteMessageToReservationOutput( reservationId=sandbox.id, message='No Static VMs to turn on!') #sandbox = Sandbox() DefaultSetupWorkflow().register(sandbox) sandbox.execute_setup()
def main(): # Get list of vCenter Static VMs, with 'Auto Power Off' == True sandbox = Sandbox() sandbox_resources = sandbox.automation_api.GetReservationDetails( sandbox.id).ReservationDescription.Resources static_vms = [ res for res in sandbox_resources if res.ResourceModelName == 'vCenter Static VM' and sandbox.automation_api.GetAttributeValue( res.Name, 'Auto Power Off').Value is True ] # If any, iterate through if len(static_vms) > 0: for static_vm in static_vms: if static_vm.Shared: # Get number of reservations resource is currently in res_count = 0 for r in sandbox.automation_api.GetResourceAvailability( [static_vm.Name], True).Resources: for res in r.Reservations: res_count += 1 if res_count == 1: # If no other reservation, resource is unshared, powered off, then re shared # Unshared and re shared because shared resources cannot be powered on and off sandbox.automation_api.SetResourceSharedState( sandbox.id, [static_vm.Name], False) sandbox.automation_api.ExecuteResourceConnectedCommand( reservationId=sandbox.id, resourceFullPath=static_vm.Name, commandName='PowerOff', commandTag='power', parameterValues=[], printOutput=True) sandbox.automation_api.SetResourceSharedState( sandbox.id, [static_vm.Name], True) # If resource is in another reservation, it should stay on and be skipped here else: # Power off any non shared resource sandbox.automation_api.ExecuteResourceConnectedCommand( reservationId=sandbox.id, resourceFullPath=static_vm.Name, commandName='PowerOff', commandTag='power', parameterValues=[], printOutput=True) else: sandbox.automation_api.WriteMessageToReservationOutput( reservationId=sandbox.id, message='No Static VMs to turn off!') # Default sandbox teardown DefaultTeardownWorkflow().register(sandbox) sandbox.execute_teardown()
def main(): # Get list of vCenter Static VMs sandbox = Sandbox() sandbox_resources = sandbox.automation_api.GetReservationDetails( sandbox.id).ReservationDescription.Resources static_vms = [ res for res in sandbox_resources if res.ResourceModelName == 'vCenter Static VM' ] # If any, iterate through if len(static_vms) > 0: for static_vm in static_vms: if sandbox.automation_api.GetResourceLiveStatus( resourceFullPath=static_vm.Name ).liveStatusName != "Online": if static_vm.Shared: # Get number of reservations resource is currently in res_count = 0 for r in sandbox.automation_api.GetResourceAvailability( [static_vm.Name], True).Resources: for res in r.Reservations: res_count += 1 if res_count == 1: # If no other reservation, resource is unshared, powered on, then re shared # Unshared and re shared because shared resources cannot be powered on and off sandbox.automation_api.SetResourceSharedState( sandbox.id, [static_vm.Name], False) sandbox.automation_api.ExecuteResourceConnectedCommand( reservationId=sandbox.id, resourceFullPath=static_vm.Name, commandName='PowerOn', commandTag='power', parameterValues=[], printOutput=True) sandbox.automation_api.SetResourceSharedState( sandbox.id, [static_vm.Name], True) # If resource is in another reservation, it should already be powered on and can be skipped here else: # Power on any non shared resources sandbox.automation_api.ExecuteResourceConnectedCommand( reservationId=sandbox.id, resourceFullPath=static_vm.Name, commandName='PowerOn', commandTag='power', parameterValues=[], printOutput=True) else: sandbox.automation_api.WriteMessageToReservationOutput( reservationId=sandbox.id, message='No Static VMs to turn on!') # Default Sandbox Setup DefaultSetupWorkflow().register(sandbox) sandbox.execute_setup()
def main(): sandbox = Sandbox() sandbox.automation_api.WriteMessageToReservationOutput(reservationId=sandbox.id, message='Starting to execute the cool stuff!') DefaultSetupWorkflow().register(sandbox, enable_configuration=False) # Disable OOTB configuration sandbox.workflow.add_to_configuration(function=configure_apps, components=sandbox.components.apps) sandbox.execute_setup()
def main(): # Default Setup Process sandbox = Sandbox() DefaultTeardownWorkflow().register(sandbox) sandbox.execute_teardown() # Set Config # insert code here work_config = WorkConfig() work_config.input_config_all("Init Config Path")
def main(): sandbox = Sandbox() sandbox.logger.info('starting main') sandbox.automation_api.WriteMessageToReservationOutput(reservationId=sandbox.id, message='Starting apps based on their priority') DefaultSetupWorkflow().register(sandbox, enable_connectivity=False,enable_configuration=False) # Disable OOTB configuration sandbox.workflow.add_to_connectivity(function=start_apps, components=sandbox.components.apps) sandbox.execute_setup()
def main(): sandbox = Sandbox() sandbox.automation_api.WriteMessageToReservationOutput( reservationId=sandbox.id, message='Starting to execute the cool stuff!') DefaultSetupWorkflow().register( sandbox, enable_configuration=False) # Disable OOTB configuration sandbox.workflow.add_to_configuration(function=configure_apps, components=sandbox.components.apps) sandbox.execute_setup()
def main(): sandbox = Sandbox() DefaultSetupWorkflow().register(sandbox) route_details = sandbox.automation_api.GetReservationDetails( sandbox.id).ReservationDescription.TopologiesRouteInfo # stage hooks: sandbox.workflow.add_to_connectivity(function=do_route_connections, components=route_details) sandbox.execute_setup()
def main(): sandbox = Sandbox() DefaultSetupWorkflow().register(sandbox) w2output = sandbox.automation_api.WriteMessageToReservationOutput model_list = ['Arista EOS Router'] for model in model_list: route_helper = RouteCommandHelper(device_model=model) w2output(sandbox.id, 'Queueing Route Disconnection for {}'.format(model)) sandbox.workflow.add_to_teardown(function=SandboxOrchPlugins().disconnect_routes_by_device_type(), components=route_helper) sandbox.execute_setup()
def main(): # Default Setup Process sandbox = Sandbox() DefaultSetupWorkflow().register(sandbox) sandbox.execute_setup() # Additional Setup Process # Connect All L1 Routes L1CC = L1ConnectionController() L1CC.ChangeStateOfAllL1Routes("Connect") # Set Config # insert code here work_config = WorkConfig() work_config.input_config_all("Config Path")
def main(): sandbox = Sandbox() DefaultSetupWorkflow().register(sandbox) bark_inputs = OrderedDict() bark_inputs['Times'] = '3' cmd_helper = ResourceCommandHelper(command_name='bark', inputs=bark_inputs) # stage hooks: sandbox.workflow.add_to_configuration( function=SandboxOrchPlugins().run_resource_command_on_all, components=cmd_helper) sandbox.execute_setup()
def __init__(self): self.sandbox = Sandbox() self.automation_api = self.sandbox.automation_api self.reservation_id = self.sandbox.reservationContextDetails.id self.reservation_details = self.automation_api.GetReservationDetails( self.reservation_id) self.reservation_description = self.reservation_details.ReservationDescription
def __init__(self): self.sandbox = Sandbox() self.automation_api = self.sandbox.automation_api self.blueprint = self.automation_api.ActivateTopology self.reservation_id = self.sandbox.reservationContextDetails.id self.reservation_details = self.automation_api.GetReservationDetails(self.reservation_id) self.reservation_description = self.reservation_details.ReservationDescription self._FIRST_ONE = 0
def get_sandbox_wrapper(): from cloudshell.workflow.orchestration.sandbox import Sandbox try: sandbox = Sandbox() except KeyError as e: print(error_red('KeyError: ' + str(e)) + '\n' + 'Be sure "attach_to_cloudshell_as" is executed while developing.\n' 'Set DEBUG_MODE = True in control_flow.py.') exit(1) else: return sandbox
def __init__(self): self.cwd = os.getcwd() self.config_file = 'C:\ProgramData\QualiSystems\QBlueprintsBackup\config.json' self.configs = json.loads(open(self.config_file).read()) self.sandbox = Sandbox() self.FileDescription = namedtuple('FileDescription', 'path contents executable') self.logger = get_qs_logger( log_file_prefix="CloudShell Sandbox Backup", log_group=self.sandbox.id, log_category='BluePrintBackup')
from cloudshell.workflow.orchestration.sandbox import Sandbox from cloudshell.workflow.orchestration.setup.default_setup_orchestrator import DefaultSetupWorkflow sandbox = Sandbox() DefaultSetupWorkflow().register(sandbox) sandbox.execute_setup()
import threading import traceback from time import time from cloudshell.core.logger.qs_logger import get_qs_logger from cloudshell.workflow.orchestration.sandbox import Sandbox from cloudshell.workflow.orchestration.setup.default_setup_orchestrator import DefaultSetupWorkflow sandbox1 = Sandbox() DefaultSetupWorkflow().register(sandbox1) def f(sandbox2, hookpattern): api = sandbox2.automation_api resid = sandbox2.id logger = get_qs_logger(log_group=resid, log_file_prefix='setup_teardown_hooks') def notify(s): logger.info(s) api.WriteMessageToReservationOutput(resid, s) logger.info('enter f %s' % hookpattern) errors = [] already = set() while True: # recheck reservation every time hooks in this phase were run, in case a hook changed the reservation logger.info('get reservation details')
def main(): # Debugging Only: _d_user = '******' _d_pwrd = b64decode('') _d_host = 'localhost' _d_domain = 'Global' _d_id = '8cd7c1d7-b6ac-4b6e-a972-2cebb3a6a2a8' dev_helper.attach_to_cloudshell_as(_d_user, _d_pwrd, _d_domain, _d_id, server_address=_d_host) # end Debug section sandbox = Sandbox() cable_req = [] routes = sandbox.automation_api.GetReservationDetails( sandbox.id).ReservationDescription.RequestedRoutesInfo for route in routes: if route.RouteType == 'cable': cable_req.append(route) if len(cable_req) > 0: owner = sandbox.reservationContextDetails.owner_user email = sandbox.automation_api.GetUserDetails(username=owner).Email subj = 'CloudShell Cable Request from {}'.format(owner) count = 0 if HTTP_SECURE: wedge = 'https://{}'.format(HTTP_PREFIX) else: wedge = 'http://{}'.format(HTTP_PREFIX) wedge += sandbox.id link = '<a href="{}">{}</a>'.format(wedge, sandbox.id) msg = str() msg += 'CloudShell Request for Cabling\n' msg += '{}\n'.format(strftime('%Y-%m-%d %H:%M:%S')) msg += 'From User: {} ( {} )\n'.format(owner, email) msg += 'Sandbox Id: {}\n'.format(link) msg += 'Link: {}\n'.format(wedge) msg += '\n' msg += 'Requests:\n' for cable in cable_req: count += 1 r_txt = str() r_txt += ' Cable # {}\n'.format(count) r_txt += ' > From: {}\n'.format(cable.Source) r_txt += ' > To: {}\n'.format(cable.Target) r_txt += '\n' msg += r_txt msg += '-- End of Requests' # print msg send_email(subject=subj, message=msg) sandbox.automation_api.WriteMessageToReservationOutput( reservationId=sandbox.id, message='\nRequest for {} Cable(s) made'.format(count)) for each in cable_req: sandbox.automation_api.WriteMessageToReservationOutput( reservationId=sandbox.id, message=' {} <---> {}'.format(each.Source, each.Target))
def main(): sandbox = Sandbox() DefaultSetupWorkflow().register(sandbox, enable_configuration=False) sandbox.workflow.add_to_configuration(function=azure_app_extention, components=sandbox.components.apps) sandbox.execute_setup()
from cloudshell.workflow.orchestration.sandbox import Sandbox from cloudshell.workflow.orchestration.setup.default_setup_orchestrator import DefaultSetupWorkflow from custom_configuration import config_web_servers from cloudshelltrialutils.trial_utils import TrialUtils from cloudshelltrialutils import Hubspot_API_Helper import traceback hubspot_helper = Hubspot_API_Helper("cba66474-e4e4-4f5b-9b9b-35620577f343") sandbox = Sandbox() sandbox.suppress_exceptions = False if len(sandbox.components.apps) > 7: raise ValueError( "Cannot setup a Sandbox with more than 7 apps in Trial Version, please remove some apps from the Blueprint and try again" ) trial_utils = TrialUtils(sandbox.automation_api) trial_owner = trial_utils.get_quali_owner( sandbox.reservationContextDetails.domain) sandbox.automation_api.AddPermittedUsersToReservation(sandbox.id, [trial_owner]) DefaultSetupWorkflow().register(sandbox, enable_configuration=False) sandbox.workflow.add_to_configuration(config_web_servers, sandbox.components) if "@" in sandbox.reservationContextDetails.owner_user: hubspot_helper.increment_trial_sandbox_count( sandbox.reservationContextDetails.owner_user) hubspot_helper.update_contact_initial_login( sandbox.reservationContextDetails.owner_user, None) try:
from cloudshell.workflow.orchestration.sandbox import Sandbox from cloudshell.helpers.scripts.cloudshell_dev_helpers import attach_to_cloudshell_as from credentials import credentials from first_module import first_module_flow LIVE_SANDBOX_ID = "47f2b606-b335-4918-87e7-0297c06f1c01" attach_to_cloudshell_as(user=credentials["user"], password=credentials["password"], domain=credentials["domain"], reservation_id=LIVE_SANDBOX_ID, server_address=credentials['server']) sandbox = Sandbox() first_module_flow(sandbox=sandbox, components=None)
from cloudshell.workflow.orchestration.sandbox import Sandbox from cloudshell.workflow.orchestration.setup.default_setup_orchestrator import DefaultSetupWorkflow sandbox = Sandbox() DefaultSetupWorkflow().register(sandbox) sandbox.execute_restore()
try: response = Sandbox.automation_api.ExecuteCommand(reservationId=Sandbox.id, targetName=resource_name, targetType='Resource', commandName='restore_sandbox', commandInputs=myList) Sandbox.automation_api.WriteMessageToReservationOutput(reservationId=Sandbox.id,message='<div style="color: green; font-weight:bold">Successfully restored '+resource_name+'</div>') Sandbox.automation_api.SetResourceLiveStatus(resource_name, "Online" , "Active") except Exception as ex: template = "An exception of type {0} occurred. Arguments:\n{1!r}" message = template.format(type(ex).__name__, ex.args) Sandbox.automation_api.WriteMessageToReservationOutput(reservationId=Sandbox.id,message='<div style="color: red; font-weight:bold">'+message+'</div>') pass if __name__ == '__main__': sandbox = Sandbox() DefaultSetupWorkflow().register(sandbox) resources = sandbox.components.resources for resource_name, resource in sandbox.components.resources.iteritems(): if "/" in resource_name: continue if "FTP" in resource_name: continue sandbox.workflow.add_to_configuration(function=restoreConfigs, components=resource_name) sandbox.execute_restore()
from cloudshell.workflow.orchestration.sandbox import Sandbox from cloudshell.workflow.orchestration.teardown.default_teardown_orchestrator import DefaultTeardownWorkflow sandbox = Sandbox() DefaultTeardownWorkflow().register(sandbox) sandbox.execute_teardown()
import threading import traceback from time import time from cloudshell.core.logger.qs_logger import get_qs_logger from cloudshell.workflow.orchestration.sandbox import Sandbox from cloudshell.workflow.orchestration.teardown.default_teardown_orchestrator import DefaultTeardownWorkflow sandbox1 = Sandbox() DefaultTeardownWorkflow().register(sandbox1) def f(sandbox2, hookpattern): api = sandbox2.automation_api resid = sandbox2.id logger = get_qs_logger(log_group=resid, log_file_prefix='setup_teardown_hooks') def notify(s): logger.info(s) api.WriteMessageToReservationOutput(resid, s) logger.info('enter f %s' % hookpattern) already = set() while True: # recheck reservation every time hooks in this phase were run, in case a hook changed the reservation logger.info('get reservation details') rd = api.GetReservationDetails(sandbox2.id).ReservationDescription
from cloudshell.workflow.orchestration.sandbox import Sandbox from cloudshell.orch.training.setup_orchestrator import TrainingSetupWorkflow import cloudshell.helpers.scripts.cloudshell_dev_helpers as dev_helpers if dev_helpers.is_dev_mode(): dev_helpers.attach_to_cloudshell_as( 'admin', 'admin', 'Global', 'a563eb82-a81f-4ec7-b328-4abb427e0992') sandbox = Sandbox() workflow = TrainingSetupWorkflow(sandbox) workflow.register() workflow.initialize() sandbox.execute_setup()
from cloudshell.workflow.orchestration.sandbox import Sandbox sandbox = Sandbox() sandbox.execute_save()
from cloudshell.workflow.orchestration.sandbox import Sandbox from cloudshell.workflow.orchestration.teardown.default_teardown_orchestrator import DefaultTeardownWorkflow def custom_function(sandbox, components): """ :param Sandbox sandbox: """ for resource in components: if '/' in resource: continue sandbox.automation_api.SetResourceLiveStatus(resource, 'Offline') pass sandbox = Sandbox() DefaultTeardownWorkflow().register(sandbox) resources = sandbox.components.resources sandbox.workflow.add_to_teardown(custom_function, resources) sandbox.execute_teardown()
def sandbox(test_helpers: TestHelpers) -> Sandbox: """Yield Sandbox.""" test_helpers.attach_to_cloudshell_as() return Sandbox()