コード例 #1
0
 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")
コード例 #2
0
ファイル: __main__.py プロジェクト: DYeag/Optiv
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()
コード例 #3
0
 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
コード例 #4
0
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()
コード例 #5
0
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()
コード例 #6
0
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()
コード例 #7
0
 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
コード例 #8
0
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")
コード例 #9
0
ファイル: __main__.py プロジェクト: qualidan/PriOrchSetup
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()
コード例 #10
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 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()
コード例 #12
0
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()
コード例 #13
0
    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')
コード例 #14
0
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()
コード例 #15
0
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")
コード例 #16
0
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()
コード例 #17
0
ファイル: __main__.py プロジェクト: ericrqs/Juniper-vMX
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')
コード例 #18
0
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))
コード例 #19
0
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()
コード例 #20
0
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()
コード例 #21
0
def sandbox(test_helpers: TestHelpers) -> Sandbox:
    """Yield Sandbox."""
    test_helpers.attach_to_cloudshell_as()
    return Sandbox()