def main(self):
        auth = UserAuth(username=self.options.username,
                        password=self.options.password)
        sh = steelhead.SteelHead(host=self.options.host, auth=auth)

        print("\n********** Version **********\n")
        version_model = Model.get(sh, feature='common')
        pprint(version_model.show_version())

        print("\n********** Networking State **********\n")
        networking_model = Model.get(sh, feature='networking')
        pprint(networking_model.show_interfaces("aux"))

        print("\n********** All Current Flows **********\n")
        flows_model = Model.get(sh, feature='flows')
        pprint(flows_model.show_flows('all'))

        # Use the Action class
        flows_action = Action.get(sh, feature='flows')
        print("\n********** All Optimized Flows **********\n")
        pprint(flows_action.show_flows_optimized())
        print("\n********** All Passthrough Flows **********\n")
        pprint(flows_action.show_flows_passthrough())

        print ("\n********** Bandwidth Statistics **********\n")
        stats_model = Model.get(sh, feature='stats')
        pprint(stats_model.show_stats_bandwidth('all', 'bi-directional',
                                                '5min'))
def main():
    fields = {
        "host": {
            "required": True,
            "type": "str"
        },
        "username": {
            "required": True,
            "type": "str"
        },
        "password": {
            "required": True,
            "type": "str",
            "no_log": True
        },
        "hostgroup_file": {
            "required": True,
            "type": "str"
        }
    }

    module = AnsibleModule(argument_spec=fields)

    my_ar = AppResponse(
        module.params['host'],
        UserAuth(module.params['username'], module.params['password']))

    t = HostGroupApp(module.params['hostgroup_file'])
    t.appresponse = my_ar

    t.main(module)
def create_profiler():
    """ Create NetProfiler instance given configuration data
    """
    if 'profilerhost' not in config:
        raise unittest.SkipTest('no netprofiler hostname provided')
    try:
        username = config['username']
    except KeyError:
        username = '******'
    try:
        password = config['password']
    except KeyError:
        password = '******'
    auth = UserAuth(username, password)
    return NetProfiler(config['profilerhost'], auth=auth)
Exemple #4
0
    def validate_args(self):
        """ Hook for subclasses to add their own option/argument validation
        """
        super(Application, self).validate_args()

        if self.has_standard_options:
            if self.options.oauth and (self.options.username
                                       or self.options.password):
                self.parser.error('Username/Password are mutually exclusive '
                                  'from OAuth tokens, please choose only '
                                  'one method.')
            elif self.options.oauth:
                self.auth = OAuth(self.options.oauth)
            else:
                self.auth = UserAuth(self.options.username,
                                     self.options.password)

            steelscript.common.connection.Connection.HTTPLIB_DEBUGLEVEL = (
                self.options.httplib_debuglevel)

            steelscript.common.connection.Connection.DEBUG_MSG_BODY = (
                self.options.debug_msg_body)
    def main(self):
        auth = UserAuth(username=self.options.username,
                        password=self.options.password)
        sh = steelhead.SteelHead(host=self.options.host, auth=auth)

        print("\n********** Version **********\n")
        print(sh.cli.exec_command("show version"))

        print("\n********** Networking State **********\n")
        print(sh.cli.exec_command("show interfaces aux"))

        print("\n********** All Current Flows **********\n")
        print(sh.cli.exec_command("show flows all"))
        print("\n********** All Optimized Flows **********\n")
        print(sh.cli.exec_command("show flows optimized"))
        print("\n********** All Passthrough Flows **********\n")
        print(sh.cli.exec_command("show flows passthrough"))

        print("\n********** Bandwidth Statistics **********\n")
        print(
            sh.cli.exec_command("show stats bandwidth all "
                                "bi-directional 5min"))
Exemple #6
0
    def validate_args(self):
        """ Hook for subclasses to add their own option/argument validation
        """
        super(Application, self).validate_args()

        if self.has_conn_options:
            if self.options.oauth and (self.options.username
                                       or self.options.password):
                self.parser.error('Username/Password are mutually exclusive '
                                  'from OAuth tokens, please choose only '
                                  'one method.')
            elif self.options.oauth:
                self.auth = OAuth(self.options.oauth)
            else:
                self.auth = UserAuth(self.options.username,
                                     self.options.password)

        if self.has_log_options:
            steelscript.common.connection.Connection.REST_DEBUG = (
                self.options.rest_debug)
            steelscript.common.connection.Connection.REST_BODY_LINES = (
                self.options.rest_body_lines)
Exemple #7
0
    def validate_args(self):
        """ Hook for subclasses to add their own option/argument validation
        """
        super(Application, self).validate_args()

        if self.has_conn_options:

            # check to see if we've added credentials to the class
            # itself, and use those as defaults if nothing passed in via
            # the command line options
            if self.username and not self.options.username:
                self.options.username = self.username
            if self.password and not self.options.password:
                self.options.password = self.password
            if self.oauth and not self.options.oauth:
                self.options.oauth = self.oauth

            if self.options.oauth and (self.options.username
                                       or self.options.password):
                self.parser.error('Username/Password are mutually exclusive '
                                  'from OAuth tokens, please choose only '
                                  'one method.')
            elif self.options.oauth:
                self.auth = OAuth(self.options.oauth)
            elif not self.options.username or not self.options.password:
                self.parser.error('Authentication credentials required: '
                                  'either username/password or OAuth token.')
            else:
                self.auth = UserAuth(self.options.username,
                                     self.options.password)

        if self.has_log_options:
            steelscript.common.connection.Connection.REST_DEBUG = (
                self.options.rest_debug)
            steelscript.common.connection.Connection.REST_BODY_LINES = (
                self.options.rest_body_lines)
def create_profiler(request):
    """ Create default NetProfiler lab instance. """
    auth = UserAuth('admin', 'admin')
    profiler = NetProfiler('10.38.131.150', auth=auth)
    request.cls.profiler = profiler
Exemple #9
0
# Create a clip from a job

from steelscript.common.service import Service, UserAuth

host = '<hostname>'

username = '******'

password = '******'

auth = UserAuth(username=username, password=password)

service = Service('AppResponse', host=host, auth=auth)

# Get a list of packet capture jobs

uri = '/api/npm.packet_capture/1.0/jobs'
jobs = service.conn.json_request('GET', uri)

# Create a clip from a job

uri = '/api/npm.clips/1.0/clips'

config = dict(job_id='<job_id>',
              start_time='<start_epoch_time>',
              end_time='<end_epoch_time>')

data = dict(config=config)
resp = service.conn.json_request('POST', uri, body=data)
    def main(self):
        if self.options.timerange is not None:
            try:
                timefilter = TimeFilter.parse_range(self.options.timerange)
            except ValueError:
                print "Could not parse time filter expression."
                return
        elif (self.options.starttime is not None or
              self.options.endtime is not None):
            timeparser = TimeParser()

            if self.options.starttime is None:
                start_time = datetime.min
            else:
                try:
                    start_time = timeparser.parse(self.options.starttime)
                except ValueError:
                    print "Could not parse start timestamp"
                    return

            if self.options.endtime is None:
                end_time = datetime.now()
            else:
                try:
                    end_time = timeparser.parse(self.options.endtime)
                except ValueError:
                    print "Could not parse end timestamp"
                    return
            timefilter = TimeFilter(start_time, end_time)
        else:
            timefilter = None

        filters = [NetSharkFilter(f) for f in self.options.filters]
        if timefilter is not None:
            filters.append(timefilter)

        if self.options.file is None:
            sharks_info = [[self.options.host, self.options.username,
                            self.options.password]]
        else:
            sharks_info = self.get_csv_sharks_info(self.options.file)

        out_table = []
        for host, username, password in sharks_info:
            shark = NetShark(host, auth=UserAuth(username, password))

            jobs_bytes = self.get_jobs_bytes(shark, filters)
            if not jobs_bytes:
                print "(No data returned from NetShark {0}.)".format(host)
            else:
                for job_name, job_bytes in self.get_jobs_bytes(shark, filters):
                    out_table.append([host, job_name, job_bytes])

        if not out_table:
            print "No data found by any NetShark."
        else:
            out_table_sorted = sorted(out_table, reverse=True,
                                      key=operator.itemgetter(2))

            heads = ["NetShark", "Job", "Total bytes"]
            Formatter.print_table(out_table_sorted, heads)
Exemple #11
0
def user_auth():
    return UserAuth(USERNAME, PASSWORD)