Пример #1
0
    def ntp(self, row_num, wr_file, **kwargs):
        # Dicts for required and optional args
        required_args = {
            'NTP_Server_IPv4': '',
            'Preferred': '',
            'Mgmt_Domain': ''
        }
        optional_args = {}

        # Validate inputs, return dict of template vars
        templateVars = process_kwargs(required_args, optional_args, **kwargs)

        try:
            # Validate DNS IPv4 Address
            validating.ipv4(row_num, templateVars['NTP_Server_IPv4'])
            templateVars['Mgmt_Domain'] = validating.mgmt_domain(
                row_num, templateVars['Mgmt_Domain'])
        except Exception as err:
            Error_Return = '%s\nError on Row %s.  Please verify Input Information.' % (
                SystemExit(err), row_num)
            raise ErrException(Error_Return)

        templateVars['NTP_Server_IPv4_'] = templateVars[
            'NTP_Server_IPv4'].replace('.', '_')

        # Locate template for method
        template_file = "ntp.template"
        template = self.templateEnv.get_template(template_file)

        # Render template w/ values from dicts
        payload = template.render(templateVars)
        wr_file.write(payload)
        wr_file.write('\n\n')
Пример #2
0
    def dns_mgmt(self, row_num, wr_file, **kwargs):
        # Dicts for required and optional args
        required_args = {'Mgmt_Domain': ''}
        optional_args = {}

        # Validate inputs, return dict of template vars
        templateVars = process_kwargs(required_args, optional_args, **kwargs)

        try:
            # Validate Management Domain
            templateVars['Mgmt_Domain'] = validating.mgmt_domain(
                row_num, templateVars['Mgmt_Domain'])
        except Exception as err:
            Error_Return = '%s\nError on Row %s.  Please verify Input Information.' % (
                SystemExit(err), row_num)
            raise ErrException(Error_Return)

        # Locate template for method
        template_file = "dns_mgmt.template"
        template = self.templateEnv.get_template(template_file)

        # Render template w/ values from dicts
        payload = template.render(templateVars)
        wr_file.write(payload)
        wr_file.write('\n\n')
Пример #3
0
    def backup(self, row_num, wr_file, **kwargs):
        # Dicts for required and optional args
        required_args = {
            'Encryption_Key': '',
            'Backup_Hour': '',
            'Backup_Minute': '',
            'Remote_Host': '',
            'Mgmt_Domain': '',
            'Protocol': '',
            'Remote_Path': '',
            'Port': '',
            'Auth_Type': '',
            'Passwd_or_SSH_Pass': ''
        }
        optional_args = {'Username': '', 'SSH_Key': '', 'Description': ''}

        # Validate inputs, return dict of template vars
        templateVars = process_kwargs(required_args, optional_args, **kwargs)

        try:
            # Validate Encryption Key Length & Management Domain
            validating.encryption_key(row_num, templateVars['Encryption_Key'])
            templateVars['Mgmt_Domain'] = validating.mgmt_domain(
                row_num, templateVars['Mgmt_Domain'])
        except Exception as err:
            Error_Return = '%s\nError on Row %s.  Please verify Input Information.' % (
                SystemExit(err), row_num)
            raise ErrException(Error_Return)

        templateVars['Remote_Host_'] = templateVars['Remote_Host'].replace(
            '.', '_')

        # Locate template for method
        if templateVars['Auth_Type'] == 'password':
            templateVars['Auth_Type'] = 'usePassword'
            template_file = "backup_passwd.template"
        elif templateVars['Auth_Type'] == 'ssh-key':
            templateVars['Auth_Type'] = 'useSshKeyContents'
            template_file = "backup_ssh_key.template"
        else:
            print(
                f'\n-----------------------------------------------------------------------------\n'
            )
            print(
                f'   Error on Row {row_num}.  Authentication type should be password or ssh-key.'
            )
            print(f'   Exiting....')
            print(
                f'\n-----------------------------------------------------------------------------\n'
            )
            exit()

        template = self.templateEnv.get_template(template_file)

        # Render template w/ values from dicts
        payload = template.render(templateVars)
        wr_file.write(payload)
        wr_file.write('\n\n')
Пример #4
0
    def snmp_trap(self, row_num, wr_file, **kwargs):
        # Dicts for required and optional args
        required_args = {
            'Trap_Server_IPv4': '',
            'Destination_Port': '',
            'Version': '',
            'Community_or_Username': '',
            'Security_Level': '',
            'Mgmt_Domain': ''
        }
        optional_args = {}

        # Validate inputs, return dict of template vars
        templateVars = process_kwargs(required_args, optional_args, **kwargs)

        # Set noauth if v1 or v2c
        if re.search('(v1|v2c)', templateVars['Version']):
            templateVars['Security_Level'] = 'noauth'

        try:
            # Validate SNMP Trap Server IPv4 Address, SNMP Port, Check SNMP Version
            # Check SNMP Community/Username and Validate Management Domain
            validating.ipv4(row_num, templateVars['Trap_Server_IPv4'])
            validating.port(row_num, templateVars['Destination_Port'])
            validating.snmp_ver(row_num, templateVars['Version'])
            validating.snmp_string(row_num,
                                   templateVars['Community_or_Username'])
            templateVars['Mgmt_Domain'] = validating.mgmt_domain(
                row_num, templateVars['Mgmt_Domain'])
        except Exception as err:
            Error_Return = '%s\nError on Row %s.  Please verify Input Information.' % (
                SystemExit(err), row_num)
            raise ErrException(Error_Return)

        templateVars['Trap_Server_IPv4_'] = templateVars[
            'Trap_Server_IPv4'].replace('.', '_')

        # Locate template for method
        template_file = "snmp_trap.template"
        template = self.templateEnv.get_template(template_file)

        # Render template w/ values from dicts
        payload = template.render(templateVars)
        # print(payload)
        wr_file.write(payload)
        wr_file.write('\n\n')
Пример #5
0
    def tacacs(self, row_num, wr_file, **kwargs):
        # Dicts for required and optional args
        required_args = {
            'Login_Domain': '',
            'TACACS_IPv4': '',
            'Port': '',
            'Shared_Secret': '',
            'Auth_Proto': '',
            'Timeout': '',
            'Retry_Interval': '',
            'Mgmt_Domain': '',
            'Domain_Order': ''
        }
        optional_args = {}

        # Validate inputs, return dict of template vars
        templateVars = process_kwargs(required_args, optional_args, **kwargs)

        try:
            # Validate RADIUS IPv4 Address, Login Domain, Authentication Protocol,
            # secret, Timeout, Retry Limit and Management Domain
            validating.login_domain(row_num, templateVars['Login_Domain'])
            validating.ipv4(row_num, templateVars['TACACS_IPv4'])
            validating.auth_proto(row_num, templateVars['Auth_Proto'])
            validating.secret(row_num, templateVars['Shared_Secret'])
            validating.timeout(row_num, templateVars['Timeout'])
            validating.retry(row_num, templateVars['Retry_Interval'])
            templateVars['Mgmt_Domain'] = validating.mgmt_domain(
                row_num, templateVars['Mgmt_Domain'])
        except Exception as err:
            Error_Return = '%s\nError on Row %s.  Please verify Input Information.' % (
                SystemExit(err), row_num)
            raise ErrException(Error_Return)

        templateVars['TACACS_IPv4_'] = templateVars['TACACS_IPv4'].replace(
            '.', '_')

        # Locate template for method
        template_file = "tacacs.template"
        template = self.templateEnv.get_template(template_file)

        # Render template w/ values from dicts
        payload = template.render(templateVars)
        wr_file.write(payload)
        wr_file.write('\n\n')
Пример #6
0
    def smartcallhome(self, row_num, wr_file, **kwargs):
        # Dicts for required and optional args
        required_args = {
            'SMTP_Port': '',
            'SMTP_Relay': '',
            'Mgmt_Domain': '',
            'From_Email': '',
            'Reply_Email': '',
            'To_Email': '',
            'Phone_Number': '',
            'Contact_Info': '',
            'Street_Address': '',
            'Contract_ID': '',
            'Customer_Identifier': '',
            'Site_Identifier': ''
        }
        optional_args = {}

        # Validate inputs, return dict of template vars
        templateVars = process_kwargs(required_args, optional_args, **kwargs)

        try:
            # Validate All the Email Addresses, Phone Number, and Management Domain
            validating.email(row_num, templateVars['From_Email'])
            validating.email(row_num, templateVars['Reply_Email'])
            validating.email(row_num, templateVars['To_Email'])
            validating.phone(row_num, templateVars['Phone_Number'])
            templateVars['Mgmt_Domain'] = validating.mgmt_domain(
                row_num, templateVars['Mgmt_Domain'])
        except Exception as err:
            Error_Return = '%s\nError on Row %s.  Please verify Input Information.' % (
                SystemExit(err), row_num)
            raise ErrException(Error_Return)

        # Locate template for method
        template_file = "smartcallhome.template"
        template = self.templateEnv.get_template(template_file)

        # Render template w/ values from dicts
        payload = template.render(templateVars)
        wr_file.write(payload)
        wr_file.write('\n\n')
Пример #7
0
    def syslog_rmt(self, row_num, wr_file, **kwargs):
        # Dicts for required and optional args
        required_args = {
            'Dest_Group_Name': '',
            'Syslog_Server_IPv4': '',
            'Port': '',
            'Mgmt_Domain': '',
            'Severity': '',
            'Facility': ''
        }
        optional_args = {}

        # Validate inputs, return dict of template vars
        templateVars = process_kwargs(required_args, optional_args, **kwargs)

        try:
            # Validate Syslog Server IPv4 Address, Port, Facility, Logging Levels and Management Domain
            validating.ipv4(row_num, templateVars['Syslog_Server_IPv4'])
            validating.port(row_num, templateVars['Port'])
            validating.syslog_fac(row_num, templateVars['Facility'])
            validating.log_level(row_num, 'remote', templateVars['Severity'])
            templateVars['Mgmt_Domain'] = validating.mgmt_domain(
                row_num, templateVars['Mgmt_Domain'])
        except Exception as err:
            Error_Return = '%s\nError on Row %s.  Please verify Input Information.' % (
                SystemExit(err), row_num)
            raise ErrException(Error_Return)

        templateVars['Syslog_Server_IPv4_'] = templateVars[
            'Syslog_Server_IPv4'].replace('.', '_')

        # Locate template for method
        template_file = "syslog_rmt.template"
        template = self.templateEnv.get_template(template_file)

        # Render template w/ values from dicts
        payload = template.render(templateVars)
        wr_file.write(payload)
        wr_file.write('\n\n')