class CloudShellAPILibrary(object): def __init__(self, cloudshell_address, cloudshell_api_port, user="******", auth_token='', domain="Global", sandbox_uuid: UUID =""): self.api_session = CloudShellAPISession(cloudshell_address, user, token_id=auth_token, domain=domain, port=cloudshell_api_port) if sandbox_uuid: self.sandbox_id = str(sandbox_uuid) def write_sandbox_message(self, message): self.api_session.WriteMessageToReservationOutput(self.sandbox_id, message) def execute_command(self, resource, resource_type, command_name, command_params: dict = {}): if command_params: api_params = [InputNameValue(param.name, param.value) for param in command_params.items()] output = self.api_session.ExecuteCommand(self.sandbox_id, resource, resource_type, command_name, api_params) else: output = self.api_session.ExecuteCommand(self.sandbox_id, resource, resource_type, command_name) return output.Output def execute_blueprint_command(self, command_name, command_params: dict = {}): if command_params: api_params = [InputNameValue(param.name, param.value) for param in command_params.items()] output = self.api_session.ExecuteEnvironmentCommand(self.sandbox_id, command_name, api_params, printOutput=True) else: output = self.api_session.ExecuteEnvironmentCommand(self.sandbox_id, command_name, printOutput=True) return output.Output def set_sandbox_status(self, status_name, status_reason): self.api_session.SetReservationLiveStatus(self.sandbox_id, status_name, status_reason)
from cloudshell.api.cloudshell_api import CloudShellAPISession, SandboxDataKeyValue user = "******" password = "******" server = "localhost" domain = "Global" SANDBOX_ID = "b8e1aea9-4d65-43c9-ac0d-227842fe5773" api = CloudShellAPISession(host=server, username=user, password=password, domain=domain) api.ExecuteEnvironmentCommand(reservationId=SANDBOX_ID, commandName="Setup") api # # SET DATA # data1 = SandboxDataKeyValue("Key1", "my info 1") # data2 = SandboxDataKeyValue("Key2", "my info 2") # data_list = [data1, data2] # api.SetSandboxData(reservationId=SANDBOX_ID, sandboxDataKeyValues=data_list) # # # GET DATA # sb_data = api.GetSandboxData(SANDBOX_ID).SandboxDataKeyValues # for item in sb_data: # print("Key: {}, Value: {}".format(item.Key, item.Value))