Ejemplo n.º 1
0
 def executePlaybookScript(self):
     session = scripthelpers.get_api_session()
     Ansible_services = [
         service for service in session.GetReservationDetails(
             reservation_details.id).ReservationDescription.Services
         if service.ServiceName == 'AnsibleServer'
     ]
     if Ansible_services == []:
         raise Exception('Ansible Server not found!')
     elif Ansible_services.__len__() > 1:
         raise Exception('Multiple Ansible Servers found!')
     else:
         Ansible_service = Ansible_services[0]
     # Build Inputs:
     command_inputs = [
         api.InputNameValue('Host_IP', resource_context.address),
         api.InputNameValue(
             'URL', resource_context.attributes['Ansible Playbook URL']),
         api.InputNameValue(
             'Ansible_Parameters',
             resource_context.attributes['Ansible Parameters']),
         api.InputNameValue('Username',
                            resource_context.attributes['User']),
         api.InputNameValue('Password',
                            resource_context.attributes['Password'])
     ]
     session.ExecuteCommand(reservationId=reservation_details.id,
                            targetName=Ansible_service.Alias,
                            targetType='Service',
                            commandName='AnsibleExecutePlaybook',
                            commandInputs=command_inputs)
Ejemplo n.º 2
0
def save():
    return session.ExecuteCommand(
        reservationId=resid,
        targetType='Resource',
        targetName='NxOS Simulator',
        commandName='save',
        commandInputs=[
            api.InputNameValue('folder_path', 'tftp://172.16.1.20'),
            api.InputNameValue('configuration_type', 'Startup'),
            api.InputNameValue('vrf_management_name', 'management')
        ]).Output
Ejemplo n.º 3
0
def restore(filename):
    session.ExecuteCommand(
        reservationId=resid,
        targetType='Resource',
        targetName='NxOS Simulator',
        commandName='restore',
        commandInputs=[
            api.InputNameValue('path',
                               'tftp://172.16.1.21/{0}'.format(filename)),
            api.InputNameValue('configuration_type', 'Running'),
            api.InputNameValue('restore_method', 'Append'),
            api.InputNameValue('vrf_management_name', 'management')
        ])
    def _run_ansible_playbook(self, session, resid, JsonDetails, service_Name):
        command_inputs = [
            api.InputNameValue(
                Name='ansible_configuration_json',
                Value=JsonDetails
            )
        ]

        session.ExecuteCommand(
            reservationId=resid,
            targetName=service_Name,
            targetType='Service',
            commandName='execute_playbook',
            commandInputs=command_inputs
        )
Ejemplo n.º 5
0
def run():
    session = sh.get_api_session()
    resources = session.GetReservationDetails(sh.get_reservation_context_details().id).ReservationDescription.Resources
    pcs = []
    switch = sh.get_resource_context_details().name
    for res in resources:
        if res.ResourceModelName.__contains__('GenericPortChannel'):
            # pcs.append(res.Name)
            command = 'show interfaces {}'.format(res.Name.split('/')[-1])
            session.ExecuteCommand(
                reservationId=sh.get_reservation_context_details().id,
                targetType='Resource',
                targetName=switch,
                commandName='run_custom_command',
                commandInputs=[api.InputNameValue('custom_command', command)],
                printOutput=True
            )
Ejemplo n.º 6
0
            service.Attributes)[0].Value
        print '{}:\n'.format(vm_name)
        username = filter(lambda x: x.Name == 'User',
                          service.Attributes)[0].Value
        password = filter(lambda x: x.Name == 'Password',
                          service.Attributes)[0].Value
        i = 0
        while i < 5:
            try:
                password = _decrypt(session, password)
            except:
                i = 1000
            i = i + 1

        print '     Username : {}'.format(username)
        print '     Password : {}'.format(password)
        nic_data = json.loads(
            session.ExecuteCommand(reservationId=resid,
                                   targetType='Service',
                                   targetName='Azuresupplementcommands',
                                   commandName='print_vm_nic_information',
                                   commandInputs=[
                                       api.InputNameValue(Name='alias',
                                                          Value=service.Alias)
                                   ]).Output)
        for nic in nic_data:
            print('        Private IP : {}'.format(nic['Private IP']))
            print('        Public IP : {}'.format(nic['Public IP']))
            print('        Subnet CIDR : {}'.format(nic['subnet CIDR']))
            print '\n'
Ejemplo n.º 7
0
def get_alias_clean_name(alias):
    alias_list = alias.split('-')
    return ''.join(alias_list[:-2]).strip()


reservation_details = session.GetReservationDetails(
    resid).ReservationDescription
resources = reservation_details.Resources
services = reservation_details.Services
subnets = filter(lambda x: x.ServiceName == 'Subnet', services)
ARM_services = filter(lambda x: x.ServiceName in ARMMODELS, services)
for subnet in subnets:
    subnet_ip = get_service_attribute_by_name(subnet,
                                              'Allocated CIDR').split('/')[0]
    command_inputs = [
        api.InputNameValue(Name='object_type', Value='network'),
        api.InputNameValue(Name='ip', Value=subnet_ip),
        api.InputNameValue(Name='name',
                           Value='{}'.format(get_alias_clean_name(
                               subnet.Alias))),
        api.InputNameValue(Name='subnet_mask', Value='255.255.255.240')
    ]
    session.ExecuteCommand(reservationId=resid,
                           targetName='CheckpointMgmt',
                           targetType='Service',
                           commandName='create_single_object',
                           commandInputs=command_inputs)
for resource in resources:
    if resource.VmDetails:
        command_inputs = [
            api.InputNameValue(Name='object_type', Value='host'),
Ejemplo n.º 8
0
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
import time
import cloudshell.api.cloudshell_api as api

session = api.CloudShellAPISession('localhost', 'admin', 'admin', 'Global')

res_id = '69b58834-2f2e-40ac-8ce6-a09e809f37a3'

for x in range(1000):
    print("sending 1000 requests")
    for y in range(1000):
        cmdInput1 = api.InputNameValue("batch", str(x))
        cmdInput2 = api.InputNameValue("number", str(y))
        session.EnqueueCommand(res_id, "my service model", "Service",
                               "cmd_run_cleanup_command",
                               [cmdInput1, cmdInput2], True)
    print("1000 requests sent. waiting 1 minute")
    time.sleep(60)

print("done!!!")
import cloudshell.api.cloudshell_api as api
import cloudshell.helpers.scripts.cloudshell_scripts_helpers as SH
import cloudshell.helpers.scripts.cloudshell_dev_helpers as DH

username = '******'
password = '******'
server = 'localhost'
domain = 'Global'

session = api.CloudShellAPISession(username=username,
                                   password=password,
                                   domain=domain,
                                   host=server)

resid = 'a1b04dc4-f037-402e-839c-6d4298d97b1d'

res_det = session.GetReservationDetails(resid)
resources = res_det.ReservationDescription.Resources
for resource in resources:
    session.ExecuteCommand(
        reservationId=resid,
        targetName=resource.Name,
        targetType='resource',
        commandName='refresh',
        commandInputs=[api.InputNameValue(Name='myinput', Value='myvalue')])

pass