Esempio n. 1
0
    def _send_command(self, context, command):
        """
        :param ResourceCommandContext context:
        :return:
        """
        session = CloudShellAPISession(
            host=context.connectivity.server_address,
            token_id=context.connectivity.admin_auth_token,
            domain=context.reservation.domain)

        username = context.resource.attributes.get(
            '{Model}.User'.format(Model=context.resource.model))
        password_enc = context.resource.attributes.get(
            '{Model}.Password'.format(Model=context.resource.model))
        password = session.DecryptPassword(password_enc).Value
        my_session = cloudshell_cli_handler.CreateSession(
            host=context.resource.address,
            username=username,
            password=password,
            logger=self.logger)
        if not isinstance(command, list):
            commands = [command]
        else:
            commands = command
        outp = my_session.send_terminal_command(commands, password=password)
        self.logger.info(outp)
        return outp
def decrypt(password):
    decypted = session.DecryptPassword(password).Value
    return decypted


debug.get_debug_session()
res_id = script_helpers.get_reservation_context_details().id
session = script_helpers.get_api_session()
resources = session.GetReservationDetails(
    res_id).ReservationDescription.Resources

password = script_helpers.get_resource_context_details().attributes.get(
    '{0}.Admin Password'.format(
        script_helpers.get_resource_context_details().model))

i = 0
while i < 5:
    try:
        password = decrypt(password)
    except:
        i = 1000
    i = i + 1

CS_Cli = cloudshell_cli_handler.CreateSession(
    host=script_helpers.get_resource_context_details().address,
    username=script_helpers.get_resource_context_details().attributes.get(
        '{0}.Admin Username'.format(
            script_helpers.get_resource_context_details().model)),
    password=password)
pass
Esempio n. 3
0
    return decypted


debug.get_debug_session()
res_id = script_helpers.get_reservation_context_details().id
session = script_helpers.get_api_session()
resources = session.GetReservationDetails(res_id).ReservationDescription.Resources

password = script_helpers.get_resource_context_details().attributes.get('{0}.Admin Password'.format(script_helpers.get_resource_context_details().model))
username = script_helpers.get_resource_context_details().attributes.get('{0}.Admin Username'.format(script_helpers.get_resource_context_details().model))
host = script_helpers.get_resource_context_details().attributes.get('{0}.Address'.format(script_helpers.get_resource_context_details().model))

i = 0
while i < 5:
    try:
        password = decrypt(password)
    except:
        i = 1000
    i = i + 1

CS_Cli = cloudshell_cli_handler.CreateSession(
    host=host,
    username=username,
    password=password
)
outp = CS_Cli.send_terminal_command('\r\n')
outp = CS_Cli.send_terminal_command('show log setting\r\n')
print outp
pass

import cloudshell_cli_handler

cs_cli = cloudshell_cli_handler.CreateSession(username='******',
                                              password='******',
                                              host='13.69.60.5')
outp = cs_cli.send_clish_terminal_command('show version')
pass
    res for res in resources if res.Name.lower().__contains__(FIREWALL)
]

qqq = cloudshell_cli_handler.CreateSessionSimpleCase()
qqq.create_my_session()

if splunk_resources.__len__() > 0 and fortigate_resources.__len__() > 0:
    splunk_resource = session.GetResourceDetails(splunk_resources[0].Name)
    fortigate_resource = session.GetResourceDetails(
        fortigate_resources[0].Name)
    f_ssh = cloudshell_cli_handler.CreateSession(
        host=fortigate_resource.Address,
        username=[
            attr.Value for attr in fortigate_resource.ResourceAttributes
            if attr.Name == 'User'
        ][0],
        password=session.DecryptPassword([
            attr.Value for attr in fortigate_resource.ResourceAttributes
            if attr.Name == 'Password'
        ][0]).Value
        # splunk_address=splunk_resource.Address
    )

    # f_ssh = firewall_ssh_handler.configure_firewall(
    #     hostname=fortigate_resource.Address,
    #     user=[attr.Value for attr in fortigate_resource.ResourceAttributes if attr.Name == 'User'][0],
    #     password=session.DecryptPassword(
    #         [attr.Value for attr in fortigate_resource.ResourceAttributes if attr.Name == 'Password'][0]).Value,
    #     splunk_address=splunk_resource.Address
    # )
    # outp = f_ssh.config_license()