Exemplo n.º 1
0
 def get_app_instance_resources(self):
     """
     Gets resources allocated to app-instance
     :param slot: slot id
     :param app: app name
     :param identifier: identifier or logical device name
     :return: resources
     """
     if self.get_app_instance_detail():
         scope(self.handle,
               'app-instance {} {}'.format(self.app_name, self.identifier))
         resources = create_dict(
             self.handle.execute('show resource detail'))
         resources['cpu'] = resources.pop('Allocated Core NR')
         resources['ram'] = resources.pop('Allocated RAM (MB)')
         resources['data_disk'] = resources.pop('Allocated Data Disk (MB)')
         resources['binary_disk'] = resources.pop(
             'Allocated Binary Disk (MB)')
         resources['secondary_disk'] = resources.pop(
             'Allocated Secondary Disk (MB)')
         return resources
     else:
         raise Exception(
             "The app is not present. Cannot get resource profile information!"
         )
 def get_ld_detail(self, move_to_scope=True):
     """
     Get logical device detail
     """
     if move_to_scope:
         self.scope_to_ld()
     return create_dict(self.handle.execute('show detail', timeout=30))
Exemplo n.º 3
0
 def assign_resource_profile(self, resource_profile_name):
     """
     Assigns Resource Profile
     :param resource_profile_name: resource profile name
     :return:
     """
     if self.get_app_instance_detail():
         scope(self.handle,
               'app-instance {} {}'.format(self.app_name, self.identifier))
         self.handle.execute(
             "set resource-profile-name {}".format(resource_profile_name))
         output = self.handle.execute("commit")
         if 'Error' in output:
             logger.info(
                 "Failed while trying to assign resource profile with error: {}"
                 .format(output))
             raise Exception(
                 "Failed while trying to assign resource profile")
         self.handle.execute("discard-buffer")
         output = create_dict(self.handle.execute("show detail"))
         assert output[
             'Profile Name'] == resource_profile_name, "Mismatch in Profile Name! Expected: {}, Saw: {}".format(
                 resource_profile_name, output['Profile Name'])
     else:
         raise Exception(
             "The app is not present. Cannot add resource profile!")
 def get_details(self):
     """
     gets the attributes associated with the interface in a dict
     """
     self.handle.execute('top')
     assert self.verify_interface_present(), 'Interface {} not present'.format(self.hardware)
     self.handle.execute('scope port-channel {}'.format(self.port_channel_id))
     output = create_dict(self.handle.execute('show detail'))
     return output
Exemplo n.º 5
0
    def configure(self, port_type=None, enabled=None, commit=True):
        """
        Configure Interface
        :param port_type: port type; e.g. 'data', 'data-sharing', 'mgmt', 'firepower-eventing'
        :param enabled: admin state True=Enabled, False=Disabled; None - do nothing
        :param commit: commits buffer 'True|False'
        """
        logger.info('Configuring Interface {}'.format(self.hardware))
        self.handle.execute('top')
        assert self.verify_interface_present(
        ), 'Interface {} not present'.format(self.hardware)
        self.handle.execute('scope interface {}'.format(self.hardware))

        if port_type:
            self.handle.execute('set port-type {}'.format(port_type))
        if enabled is not None:
            if enabled:
                self.handle.execute('enable')
                admin_state = 'Enabled'
            else:
                self.handle.execute('disable')
                admin_state = 'Disabled'

        if commit:
            output = self.handle.execute('commit-buffer')
            if 'Error' in output:
                logger.info(
                    "Failed while trying to configure physical interface {} with error: {}"
                    .format(self.hardware, output))
                raise Exception(
                    "Failed while trying to configure physical interface")
            output = create_dict(self.handle.execute('show detail'))
            if port_type:
                if port_type.lower() == 'firepower-eventing':
                    port_type = 'Firepower Eventing'
                elif port_type.lower() == 'data':
                    port_type = 'Data'
                elif port_type.lower() == 'cluster':
                    port_type = 'Cluster'
                elif port_type.lower() == 'mgmt':
                    port_type = 'Mgmt'
                elif port_type.lower() == 'data-sharing':
                    port_type = 'Data Sharing'
                assert output['Port Type'] == port_type, \
                    "Mismatch in Port Type! Expected: '{}', Saw: '{}'".format(port_type, output['Port Type'])
            if enabled is not None:
                assert output['Admin State'] == admin_state, \
                    "Mismatch in Admin State! Expected: '{}', Saw: '{}'".format(admin_state, output['Admin State'])
            logger.info('Successfully Configured Interface {}'.format(
                self.hardware))
        else:
            logger.info('No commit - Didn\'t configure Interface {}'.format(
                self.hardware))
Exemplo n.º 6
0
    def show_monitor_detail(self):
        self.handle.execute("top")
        scope(self.handle, 'ssa/slot {}'.format(self.slot))
        out = self.handle.execute('show monitor detail')
        if 'Error' in out:
            logger.info(
                "Failed while trying to show monitor detail with error: {}".
                format(out))
            raise Exception("Failed while trying to show app-instance")
        resources = create_dict(out)
        resources['available_cores'] = resources.pop('CPU Cores Available')

        return resources
Exemplo n.º 7
0
 def get_app_instances_in_slot(self):
     """
     Get app-instance in slot as munch dictionary
     :return: Dictionary structure with apps
     """
     apps = []
     scope(self.handle, 'ssa/slot {}'.format(self.slot))
     for i in list(
             map(
                 lambda x: create_dict(x),
                 self.handle.execute('show app-instance detail').split(
                     '\r\n\r\n'))):
         if hasattr(i, 'App Name'):
             apps.append(i)
     return apps
Exemplo n.º 8
0
 def configure_ntp_server(self, steps):
     if NTP_SERVER:
         with steps.start("Change NTP server - if necessary"):
             self.chassis_line.execute('top')
             self.chassis_line.execute('scope system')
             self.chassis_line.execute('scope services')
             output = create_dict(self.chassis_line.execute('show ntp-server detail'))
             if not hasattr(output, 'Name') or output['Name'] != NTP_SERVER:
                 log.info("Changing NTP server")
                 self.chassis_line.execute('create ntp-server {}'.format(NTP_SERVER))
                 output = self.chassis_line.execute('commit-buffer')
                 if 'Error' in output:
                     raise Exception("Failed to change NTP server")
                 self.chassis_line.execute('up')
                 self.chassis_line.execute('show ntp-server detail')
Exemplo n.º 9
0
 def get_online_app_instances_in_slot(self):
     """
     Get the list of online app-instance in slot
     :return: List of app identifiers
     """
     apps = []
     scope(self.handle, 'ssa/slot {}'.format(self.slot))
     for i in list(
             map(
                 lambda x: create_dict(x),
                 self.handle.execute('show app-instance detail').split(
                     '\r\n\r\n'))):
         if hasattr(i, 'App Name'):
             if hasattr(i, 'Oper State') and i['Oper State'] == 'Online':
                 apps.append(i['Identifier'])
     return apps
Exemplo n.º 10
0
    def get_all_ld(self):
        """
        Get all logical device details
        :return:
        """
        scope(self.handle, 'ssa')
        lds = []
        output = self.handle.execute('show logical-device detail', timeout=30)
        if "Logical Device" not in output:
            logger.info("Retrying command")
            output = self.handle.execute('show logical-device detail',
                                         timeout=30)
        if "Oper State" not in output:
            logger.info("Retrying command again")
            output = self.handle.execute('show logical-device detail',
                                         timeout=30)
        for i in list(map(lambda x: create_dict(x), output.split('\r\n\r\n'))):
            if hasattr(i, 'Name'):
                lds.append(i)

        return lds
    def configure(self, port_type=None, member_ports=None, enabled=None, commit=True):
        """
        Configure Port Channel
        :param port_type: port type; e.g. 'Data', 'Mgmt', 'firepower-eventing', 'Cluster'
        :param member_ports: list of member ports data structures
        :param enabled: admin state True=Enabled, False=Disabled
        :param commit: commits buffer 'True|False'
        """
        logger.info('Configuring Port-Channel {}'.format(self.hardware))
        if member_ports:
            for member_port_interface in member_ports:
                assert member_port_interface.verify_interface_present(), \
                    'Interface {} not present'.format(member_port_interface.hardware)

        scope(self.handle, 'eth-uplink/fabric')
        self.handle.execute('enter port-channel {}'.format(self.port_channel_id))
        if port_type:
            self.handle.execute('set port-type {}'.format(port_type))
        if member_ports:
            for member_port_interface in member_ports:
                output = self.handle.execute('create member-port {}'.format(member_port_interface.hardware))
                if 'Error' in output:
                    logger.info("Failed while trying to create member port with error: {}".format(output))
                    raise Exception("Failed while trying to create member port channel")
                self.handle.execute('up')
        if enabled is not None:
            if enabled:
                self.handle.execute('enable')
                admin_state = 'Enabled'
            else:
                self.handle.execute('disable')
                admin_state = 'Disabled'

        if commit:
            output = self.handle.execute('commit-buffer')
            if 'Error' in output:
                logger.info("Failed while trying to create port channel with error: {}".format(output))
                raise Exception("Failed while trying to create port channel")
            output = create_dict(self.handle.execute('show detail'))
            if port_type:
                if port_type.lower() == 'firepower-eventing':
                    port_type = 'Firepower Eventing'
                elif port_type.lower() == 'data':
                    port_type = 'Data'
                elif port_type.lower() == 'cluster':
                    port_type = 'Cluster'
                elif port_type.lower() == 'mgmt':
                    port_type = 'Mgmt'
                elif port_type.lower() == 'data-sharing':
                    port_type = 'Data Sharing'
                assert output['Port Type'] == port_type, \
                    "Mismatch in Port Type! Expected: {}, Saw: {}".format(port_type, output['Port Type'])
            if enabled is not None:
                assert output['Admin State'] == admin_state, \
                    "Mismatch in Admin State! Expected: {}, Saw: {}".format(admin_state, output['Admin State'])
            if member_ports:
                output = self.handle.execute("show member-port")
                for member_port_interface in member_ports:
                    assert member_port_interface.hardware in output, "Could Not Find Member Port {}".format(
                        member_port_interface.hardware)
            logger.info('Successfully Configured Port-Channel {}'.format(self.hardware))
        else:
            logger.info('No commit - Didn\'t configure Interface {}'.format(self.hardware))