def attach_to_cloudshell_as(self, resource_name: Optional[str] = None, service_name: Optional[str] = None) -> None: """ Mock ES behaviour on local machine so the test can create local objects such as contexts, sandboxes etc. """ os.environ['DEVBOOTSTRAP'] = 'True' attach_to_cloudshell_as(server_address=self.session.host, user=self.session.username, password=self.session.password, reservation_id=self.reservation_id, domain=self.session.domain_name, resource_name=resource_name, service_name=service_name)
def test_test(self): dev_helpers.attach_to_cloudshell_as("admin", "admin", "Global", "8d36098c-6dd0-4d47-8ad8-b159191e3f63") details = helpers.get_reservation_context_details() py_vmomi_service = pyVmomiService(SmartConnect, Disconnect) cred = TestCredentials() si = py_vmomi_service.connect(cred.host, cred.username, cred.password, cred.port) vm = py_vmomi_service.find_by_uuid(si, '4222941e-a02d-dc78-80f6-44b88e0cb24f') network = py_vmomi_service.get_network_by_mac_address(vm, '00:50:56:a2:06:87') print network.name
def get_debug_session(): username = '******' password = '******' domain = 'Global' server = 'localhost' resId = '325e5105-47c9-4add-8e6c-8fd6a6f1fc8e' attach_to_cloudshell_as(user=username, password=password, domain=domain, server_address=server, reservation_id=resId, service_name='UptimeEnforcer')
def get_debug_session(): username = '******' password = '******' domain = 'Global' server = '40.113.155.10' resId = 'a3abeb7b-794f-485a-ab9a-9d82b97a8beb' dev_helpers.attach_to_cloudshell_as(user=username, password=password, domain=domain, server_address=server, reservation_id=resId, service_name='CheckpointMgmt')
def get_debug_session(): username = '******' password = '******' domain = 'Global' server = '40.113.155.10' resId = '5a1a7178-697a-4273-a99e-f85e4a734654' dev_helpers.attach_to_cloudshell_as(user=username, password=password, domain=domain, server_address=server, reservation_id=resId, service_name='FortiWeb')
def test_test(self): dev_helpers.attach_to_cloudshell_as( "admin", "admin", "Global", "8d36098c-6dd0-4d47-8ad8-b159191e3f63") details = helpers.get_reservation_context_details() py_vmomi_service = pyVmomiService(SmartConnect, Disconnect) cred = TestCredentials() si = py_vmomi_service.connect(cred.host, cred.username, cred.password, cred.port) vm = py_vmomi_service.find_by_uuid( si, '4222941e-a02d-dc78-80f6-44b88e0cb24f') network = py_vmomi_service.get_network_by_mac_address( vm, '00:50:56:a2:06:87') print network.name
def get_debug_session(): username = '******' password = '******' domain = 'Global' server = 'localhost' resource_name = 'IxVM 8.40 EA - Ixia Virtual Test Appliance_bd16-a85d' resId = 'd2a465f7-a75d-4fdb-8e5c-b97c5031a85d' dev_helpers.attach_to_cloudshell_as( user=username, password=password, domain=domain, server_address=server, reservation_id=resId, resource_name=resource_name )
def get_debug_session(): username = '******' password = '******' domain = 'Global' server = 'localhost' # resource_name = 'IxVM 8.40 EA - Ixia Virtual Test Appliance_bd16-a85d' resId = '30cfea93-6173-4404-8a09-211be471ff73' dev_helpers.attach_to_cloudshell_as( user=username, password=password, domain=domain, server_address=server, reservation_id=resId # resource_name=resource_name )
def create_cs_session(debug): if debug == 'yes': try: dev_helpers_71.attach_to_cloudshell_as("admin", "admin", "Global", reservation_id='59b547e3-6e9e-49d3-906f-2e28582ac98b', server_address='q1.cisco.com') except: dev_helpers_64.attach_to_cloudshell_as("admin", "admin", "Global", reservation_id='6376f07e-6d30-4b2b-811c-2eee0c77832b', server_address='q1.cisco.com') try: session = helpers_71.get_api_session() helpers = helpers_71 except: session = helpers_64.get_api_session() helpers = helpers_64 return session, helpers
def integration_test_update_vnics(self): dev_helpers.attach_to_cloudshell_as("admin", "admin", "Global", "1205e711-edf7-4b12-8a5e-e0ff53768ce7") details = helpers.get_reservation_context_details() py_vmomi_service = pyVmomiService(SmartConnect, Disconnect) cred = TestCredentials() si = py_vmomi_service.connect(cred.host, cred.username, cred.password, cred.port) vm = py_vmomi_service.find_vm_by_name(si, 'QualiSB/Alex', 'Ubuntu_a287f573') nics = [x for x in vm.config.hardware.device if isinstance(x, vim.vm.device.VirtualEthernetCard)] for nic in nics: network_name = nic.backing.network.name mac_address = nic.macAddress print network_name + mac_address
def attach_to_cs_wrapper(live_sandbox_id, resource_name=None, service_name=None): from cloudshell.helpers.scripts.cloudshell_dev_helpers import attach_to_cloudshell_as from credentials import credentials try: attach_to_cloudshell_as(user=credentials['user'], password=credentials['password'], domain=credentials['domain'], reservation_id=live_sandbox_id, server_address=credentials['server'], resource_name=resource_name, service_name=service_name) except CloudShellAPIError as e: print(error_red("error attaching to live sandbox:\n" + str(e)) + "\nTry checking user credentials, LIVE_SANDBOX_ID, TARGET_RESOURCE_NAME Spelling in control_flow.py") exit(1) except AttributeError as e: print(error_red("error attaching to live sandbox:\n" + str(e)) + "\nCheck spelling of TARGET_SERVICE_NAME set in control_flow.py") exit(1)
def integration_test_update_vnics(self): dev_helpers.attach_to_cloudshell_as("admin", "admin", "Global", "90738b16-cd33-4b24-ae43-7d76ad1e0e1e") details = helpers.get_reservation_context_details() py_vmomi_service = pyVmomiService(SmartConnect, Disconnect) cred = TestCredentials() si = py_vmomi_service.connect(cred.host, cred.username, cred.password, cred.port) vm = py_vmomi_service.find_by_uuid(si, '4222dd8d-0f01-29ca-0dce-f41561de1be9') nics = [x for x in vm.config.hardware.device if isinstance(x, vim.vm.device.VirtualEthernetCard) and hasattr(x, 'backing') and hasattr(x.backing, 'network')] for nic in nics: network_name = nic.backing.network.name mac_address = nic.macAddress print network_name + mac_address
def integration_test_update_vnics(self): dev_helpers.attach_to_cloudshell_as( "admin", "admin", "Global", "1205e711-edf7-4b12-8a5e-e0ff53768ce7") details = helpers.get_reservation_context_details() py_vmomi_service = pyVmomiService(SmartConnect, Disconnect) cred = TestCredentials() si = py_vmomi_service.connect(cred.host, cred.username, cred.password, cred.port) vm = py_vmomi_service.find_vm_by_name(si, 'QualiSB/Alex', 'Ubuntu_a287f573') nics = [ x for x in vm.config.hardware.device if isinstance(x, vim.vm.device.VirtualEthernetCard) ] for nic in nics: network_name = nic.backing.network.name mac_address = nic.macAddress print network_name + mac_address
def integration_test_update_vnics(self): dev_helpers.attach_to_cloudshell_as( "admin", "admin", "Global", "90738b16-cd33-4b24-ae43-7d76ad1e0e1e") details = helpers.get_reservation_context_details() py_vmomi_service = pyVmomiService(SmartConnect, Disconnect) cred = TestCredentials() si = py_vmomi_service.connect(cred.host, cred.username, cred.password, cred.port) vm = py_vmomi_service.find_by_uuid( si, '4222dd8d-0f01-29ca-0dce-f41561de1be9') nics = [ x for x in vm.config.hardware.device if isinstance(x, vim.vm.device.VirtualEthernetCard) and hasattr(x, 'backing') and hasattr(x.backing, 'network') ] for nic in nics: network_name = nic.backing.network.name mac_address = nic.macAddress print network_name + mac_address
"type": "actionTarget" }, "customActionAttributes": [], "type": "setVlan" }] } } ''' import cloudshell.helpers.scripts.cloudshell_scripts_helpers as qs_helper import cloudshell.helpers.scripts.cloudshell_dev_helpers as dev_help from cloudshell.shell.core.driver_context import * res_id = 'f7505eb3-b637-4795-9740-19a56244a33d' dev_help.attach_to_cloudshell_as('admin', 'admin', 'Global', res_id, 'localhost', '8029',resource_name='brocy') resource = qs_helper.get_resource_context_details() reservation = qs_helper.get_reservation_context_details() connectivity = qs_helper.get_connectivity_context_details() my_context = ResourceCommandContext(connectivity,resource,reservation,[]) my_context.reservation.reservation_id = '5695cf87-a4f3-4447-a08a-1a99a936010e' # cont = create_context() driv = BrocadeNOSDriver() driv.ApplyConnectivityChanges(my_context, request) # driv.get_inventory(cont) # driv.command(context=cont, command='conf t') # driv.command(context=cont, command='int fa 0/1') # driv.command(context=cont, command='speed 100')
import cloudshell.api.cloudshell_api as api import cloudshell.helpers.scripts.cloudshell_scripts_helpers as script_help import cloudshell.helpers.scripts.cloudshell_dev_helpers as dev_help resid = '0acc10c9-3056-4b3b-93e5-328aade2210a' username = '******' password = '******' server = '40.91.201.107' domain = 'Global' dev_help.attach_to_cloudshell_as(user=username, password=password, domain=domain, reservation_id=resid, server_address=server) session = script_help.get_api_session() reservation_details = session.GetReservationDetails( resid).ReservationDescription pass
from cloudshell.workflow.orchestration.sandbox import Sandbox # from cloudshell.workflow.orchestration.setup.default_setup_orchestrator import DefaultSetupWorkflow import image_changer from cloudshell.helpers.scripts.cloudshell_dev_helpers import attach_to_cloudshell_as DEBUG_MODE = True attach_to_cloudshell_as(user="******", password="******", domain="Global", reservation_id="3430d615-9d35-4ddb-9913-495fb38af50b", server_address="40.91.201.107") sandbox = Sandbox() BP_commands = image_changer.Blueprint_extra_commands(sandbox.id) if DEBUG_MODE: BP_commands.enforce_image_name(sandbox, components=None) exit(0)
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)
import cloudshell.helpers.scripts.cloudshell_dev_helpers as dev_help import cloudshell.helpers.scripts.cloudshell_scripts_helpers as sc_help import cloudshell.api.cloudshell_api as api resid = '9abac2bb-32cc-404f-8f1f-7c6d411683c2' dev_help.attach_to_cloudshell_as(user='******', password='******', reservation_id=resid, domain='Global') session = sc_help.get_api_session() res_det = session.GetResourceCommands('NxOS Simulator') session.ExecuteCommand( reservationId=resid, targetType='Resource', targetName='IOS emulator', commandName='run_custom_config_command', commandInputs=[api.InputNameValue('custom_command', '')]) session.SetResourceLiveStatus() pass
from cloudshell.workflow.orchestration.sandbox import Sandbox from cloudshell.helpers.scripts.cloudshell_dev_helpers import attach_to_cloudshell_as import credentials from dut_health_check import run_dut_health_check from start_traffic import start_traffic_flow LIVE_SANDBOX_ID = "361caea5-bf4e-419d-aadb-195f2ff33dce" attach_to_cloudshell_as(user=credentials.USER, password=credentials.PASSWORD, domain=credentials.DOMAIN, reservation_id=LIVE_SANDBOX_ID, server_address=credentials.SERVER) sandbox = Sandbox() run_dut_health_check(sandbox=sandbox, components=None) start_traffic_flow(sandbox)
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 DEBUG_PRINT = False LIVE_SANDBOX_ID = "dbb7119b-e1ee-47a7-95a0-425a5b89db29" TARGET_RESOURCE_NAME = None TARGET_SERVICE_NAME = None attach_to_cloudshell_as(user=credentials["user"], password=credentials["password"], domain=credentials["domain"], reservation_id=LIVE_SANDBOX_ID, server_address=credentials['server'], resource_name=TARGET_RESOURCE_NAME, service_name=TARGET_SERVICE_NAME) sandbox = Sandbox() first_module_flow(sandbox=sandbox, components=None)
from cloudshell.api.cloudshell_api import CloudShellAPISession from cloudshell.api.common_cloudshell_api import CloudShellAPIError from cloudshell.helpers.scripts import cloudshell_scripts_helpers as helpers from cloudshell.helpers.scripts import cloudshell_dev_helpers as dev_helpers dev_helpers.attach_to_cloudshell_as("admin","admin","Global","55aec269-792f-4ca9-8156-9967788d3a4f","10.211.55.4") reservation_id = helpers.get_reservation_context_details().id try: helpers.get_api_session().ExecuteCommand(reservation_id, "DriverDeepDive", "Resource", "failed_command") except CloudShellAPIError as err: print err.message raise
from cloudshell.api.cloudshell_api import CloudShellAPISession from cloudshell.api.common_cloudshell_api import CloudShellAPIError from cloudshell.helpers.scripts import cloudshell_scripts_helpers as helpers from cloudshell.helpers.scripts import cloudshell_dev_helpers as dev_helpers dev_helpers.attach_to_cloudshell_as("admin", "admin", "Global", "55aec269-792f-4ca9-8156-9967788d3a4f", "10.211.55.4") reservation_id = helpers.get_reservation_context_details().id try: helpers.get_api_session().ExecuteCommand(reservation_id, "DriverDeepDive", "Resource", "failed_command") except CloudShellAPIError as err: print err.message raise
# debug import cloudshell.helpers.scripts.cloudshell_dev_helpers as dev_helpers import vmwareConsole resid = 'cd43acfe-15a1-4503-91df-b9416ff43fd6' Resource_Name = 'ALinkedClone_d196-3fd6' dev_helpers.attach_to_cloudshell_as( user='******', password='******', domain='Global', reservation_id=resid, server_address='localhost', resource_name=Resource_Name, ) q = vmwareConsole.vmware_console() q.main() pass
from cloudshell.helpers.scripts.cloudshell_dev_helpers import attach_to_cloudshell_as from cloudshell.workflow.orchestration.sandbox import Sandbox from cloudshell.workflow.orchestration.setup.default_setup_orchestrator import DefaultSetupWorkflow from provisioning_override import custom_provisioning attach_to_cloudshell_as(user="******", password="******", domain="Global", reservation_id="be71319c-cf01-4adc-a560-bf41596d824f", server_address="localhost") sandbox = Sandbox() DefaultSetupWorkflow().register(sandbox, enable_provisioning=False) cpi = custom_provisioning() sandbox.workflow.add_to_provisioning(cpi.provisioning_overrider, None) sandbox.execute_setup()
import cloudshell.helpers.scripts.cloudshell_dev_helpers as dev_help import execute vm_name = 'azurevm-560e7e5c' # suffix = 'westeurope.cloudapp.azure.com' resource_group = 'c51fa7da-37ba-49d2-81e1-059cbbf7d4ac' username = '******' password = '******' server = 'localhost' domain = 'Global' dev_help.attach_to_cloudshell_as(user=username, password=password, domain=domain, server_address=server, resource_name=vm_name, reservation_id=resource_group) dns_script = execute.dns_altering_script() dns_script.get_cloud_provider() dns_script.execute() dns_script.set_dns_attribute() pass
from cloudshell.helpers.scripts.cloudshell_dev_helpers import attach_to_cloudshell_as import cloudshell.helpers.scripts.cloudshell_scripts_helpers as sh from cloudshell.shell.core.driver_context import InitCommandContext, ResourceCommandContext, ConnectivityContext, \ Connector, ReservationContextDetails, ResourceContextDetails import driver as my_driver LIVE_SANDBOX_ID = "97bf055e-dddc-46ed-a868-f2946bda9444" RESOURCE_NAME = "compute demo" CS_SERVER = "localhost" attach_to_cloudshell_as(user='******', password='******', domain='Global', server_address=CS_SERVER, reservation_id=LIVE_SANDBOX_ID, resource_name=RESOURCE_NAME) session = sh.get_api_session() token = session.token_id resource_context_details = sh.get_resource_context_details() reservation_context_details = sh.get_reservation_context_details() reservation_context = ReservationContextDetails( environment_name=reservation_context_details.environment_name, environment_path=reservation_context_details.environment_path, domain=reservation_context_details.domain, description=reservation_context_details.description, owner_user=reservation_context_details.owner_user, owner_email="*****@*****.**", reservation_id=reservation_context_details.id, saved_sandbox_name="",
#!/usr/bin/env python # -*- coding: utf-8 -*- import cloudshell.helpers.scripts.cloudshell_dev_helpers as dev_helpers from cloudshell.api.cloudshell_api import InputNameValue from cloudshell.workflow.orchestration.sandbox import Sandbox from cloudshell.workflow.orchestration.setup.default_setup_orchestrator import DefaultSetupWorkflow import cloudshell.api.cloudshell_api from datetime import datetime from ftplib import FTP # Update this with the current reservation ID reservation_id = "c6d79cc7-2ab9-4617-a615-3a27b66d02b6" ''' dev_helpers.attach_to_cloudshell_as('admin', 'admin', 'Global',reservation_id, server_address='localhost', cloudshell_api_port='8029') ''' DEBUG = False def restoreConfigs(Sandbox, components): # We are passing the resource_name into the function in the components parameter resource_name = components # Get the path to the FTP directory from the Configuration FTP Repo resource ftpServer = Sandbox.components.resources['Configuration FTP Repo'] # Get the path to the saved directory myServ = Sandbox.components.services['SnapshotName'] for item in myServ.Attributes :
import cloudshell.api.cloudshell_api as api from cloudshell.helpers.scripts.cloudshell_dev_helpers import attach_to_cloudshell_as import cloudshell.helpers.scripts.cloudshell_scripts_helpers username = '******' password = '******' server = 'localhost' domain = 'Global' session = api.CloudShellAPISession(username=username, password=password, domain=domain, host=server) import os def print_all_env_vars(): environ = os.environ.data for k in environ: print 'Key: {0} , Value:{1}'.format(k, environ.get(k)) if __name__ == "__main__": attach_to_cloudshell_as( user=username, password=password, domain=domain, server_address=server, reservation_id='4e7c8134-5689-4162-887c-01a3aef86fc8') print_all_env_vars()
import cloudshell.helpers.scripts.cloudshell_scripts_helpers as script_help import cloudshell.helpers.scripts.cloudshell_dev_helpers as dev dev.attach_to_cloudshell_as( ) script_help.get_api_session() script_help.get_resource_context_details().attributes
import cloudshell.api.cloudshell_api as api import cloudshell.helpers.scripts.cloudshell_scripts_helpers as script_help import attach_to_reservation from rdp_populator import rdp_populator import sys, string, os # DEBUG : remove before running live import cloudshell.helpers.scripts.cloudshell_dev_helpers as dh dh.attach_to_cloudshell_as( user='******', password='******', domain='Global', reservation_id='e03d8f4b-a233-490f-b3d4-5088b3aaf9be', server_address='localhost', resource_name='Centos VM_3432-f9be') def _decrypt(session, password): decypted = session.DecryptPassword(password).Value return decypted session = script_help.get_api_session() resid = script_help.get_reservation_context_details().id # resource_details = session address = script_help.get_resource_context_details().address username = script_help.get_resource_context_details().attributes.get('User') enc_cs_password = script_help.get_resource_context_details().attributes.get( 'Password') cleartext_password = session.DecryptPassword(enc_cs_password).Value
import os.path import string import random import zipfile import tempfile import cloudshell.helpers.scripts.cloudshell_scripts_helpers as helpers import cloudshell.helpers.scripts.cloudshell_dev_helpers as dev_helpers from cloudshell.api.common_cloudshell_api import CloudShellAPIError from cloudshell.api.cloudshell_api import ResourceInfoDto, PhysicalConnectionUpdateRequest from shell_installer import * from import_packages import * debug_res_id = 'dbdda917-71d0-4110-a50a-1b1cbc8dd96b' dev_helpers.attach_to_cloudshell_as('admin', 'admin', 'Global', debug_res_id) res_id = '' def execute(): api = helpers.get_api_session() inputs = helpers.get_reservation_context_details().parameters.global_inputs res_id = helpers.get_reservation_context_details().id connectivity = helpers.get_connectivity_context_details() tempdir = tempfile.gettempdir() # install mock shells try: with zipfile.ZipFile(os.path.dirname(__file__), "r") as z: z.extractall(tempdir) shells = [
from cloudshell.workflow.orchestration.sandbox import Sandbox from first_module import run_custom_command from debug_mode import debug_mode # ========== Debug helper ========== if debug_mode: sandbox_id = '5a7fc302-4777-4c6b-9cbe-91133c0feacf' cloud_shell_server = '137.117.197.55' from cloudshell.helpers.scripts.cloudshell_dev_helpers import attach_to_cloudshell_as attach_to_cloudshell_as(user='******', password='******', domain='Global', reservation_id=sandbox_id, server_address=cloud_shell_server) sandbox = Sandbox() run_custom_command(sandbox=sandbox, components=None)
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 from cloudshell.orch.training.teardown_orchestrator import TrainingTeardownWorkflow 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', '45d80326-72e0-4100-8337-6de156b20dae') sandbox = Sandbox() TrainingTeardownWorkflow(sandbox).register() sandbox.execute_teardown()