Class: MistApi::CaptureSwitch

Inherits:
BaseModel
  • Object
show all
Defined in:
lib/mist_api/models/capture_switch.rb

Overview

Initiate a Switch (Junos) Packet Capture

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from BaseModel

#check_for_conflict, #process_additional_properties, #process_array, #process_basic_value, #process_hash, #to_hash, #to_json

Constructor Details

#initialize(switches = nil, duration = 600, format = CaptureSwitchFormatEnum::STREAM, max_pkt_len = 512, num_packets = 1024, ports = SKIP, tcpdump_expression = SKIP, additional_properties = nil) ⇒ CaptureSwitch

Returns a new instance of CaptureSwitch.



83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
# File 'lib/mist_api/models/capture_switch.rb', line 83

def initialize(switches = nil, duration = 600,
               format = CaptureSwitchFormatEnum::STREAM, max_pkt_len = 512,
               num_packets = 1024, ports = SKIP, tcpdump_expression = SKIP,
               additional_properties = nil)
  # Add additional model properties to the instance
  additional_properties = {} if additional_properties.nil?

  @duration = duration unless duration == SKIP
  @format = format unless format == SKIP
  @max_pkt_len = max_pkt_len unless max_pkt_len == SKIP
  @num_packets = num_packets unless num_packets == SKIP
  @ports = ports unless ports == SKIP
  @switches = switches
  @tcpdump_expression = tcpdump_expression unless tcpdump_expression == SKIP
  @type = 'switch'
  @additional_properties = additional_properties
end

Instance Attribute Details

#durationInteger

Duration of the capture, in seconds

Returns:

  • (Integer)


14
15
16
# File 'lib/mist_api/models/capture_switch.rb', line 14

def duration
  @duration
end

#formatCaptureSwitchFormatEnum

enum: ‘stream`



18
19
20
# File 'lib/mist_api/models/capture_switch.rb', line 18

def format
  @format
end

#max_pkt_lenInteger

enum: ‘stream`

Returns:

  • (Integer)


22
23
24
# File 'lib/mist_api/models/capture_switch.rb', line 22

def max_pkt_len
  @max_pkt_len
end

#num_packetsInteger

number of packets to capture, 0 for unlimited, default is 1024, maximum is 10000

Returns:

  • (Integer)


27
28
29
# File 'lib/mist_api/models/capture_switch.rb', line 27

def num_packets
  @num_packets
end

#portsHash[String, CaptureSwitchPortsTcpdumpExpression]

Property key is the port name. 6 ports max per switch supported, or 5 max with irb port auto-included into capture request

Returns:



32
33
34
# File 'lib/mist_api/models/capture_switch.rb', line 32

def ports
  @ports
end

#switchesHash[String, CaptureSwitchSwitches]

Property key is the switch mac

Returns:



36
37
38
# File 'lib/mist_api/models/capture_switch.rb', line 36

def switches
  @switches
end

#tcpdump_expressionString

tcpdump expression, port specific if specified under ports dict, otherwise applicable across ports if specified at top level of payload. Port specific value overrides top level value when both exist.

Returns:

  • (String)


42
43
44
# File 'lib/mist_api/models/capture_switch.rb', line 42

def tcpdump_expression
  @tcpdump_expression
end

#typeString (readonly)

enum: ‘switch`

Returns:

  • (String)


46
47
48
# File 'lib/mist_api/models/capture_switch.rb', line 46

def type
  @type
end

Class Method Details

.from_hash(hash) ⇒ Object

Creates an instance of the object from a hash.



102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
# File 'lib/mist_api/models/capture_switch.rb', line 102

def self.from_hash(hash)
  return nil unless hash

  # Extract variables from the hash.
  switches = CaptureSwitchSwitches.from_hash(hash['switches']) if hash['switches']

  switches = nil unless hash.key?('switches')
  duration = hash['duration'] ||= 600
  format = hash['format'] ||= CaptureSwitchFormatEnum::STREAM
  max_pkt_len = hash['max_pkt_len'] ||= 512
  num_packets = hash['num_packets'] ||= 1024
  ports = CaptureSwitchPortsTcpdumpExpression.from_hash(hash['ports']) if hash['ports']

  ports = SKIP unless hash.key?('ports')
  tcpdump_expression =
    hash.key?('tcpdump_expression') ? hash['tcpdump_expression'] : SKIP

  # Create a new hash for additional properties, removing known properties.
  new_hash = hash.reject { |k, _| names.value?(k) }

  additional_properties = APIHelper.get_additional_properties(
    new_hash, proc { |value| value }
  )

  # Create object from extracted values.
  CaptureSwitch.new(switches,
                    duration,
                    format,
                    max_pkt_len,
                    num_packets,
                    ports,
                    tcpdump_expression,
                    additional_properties)
end

.namesObject

A mapping from model property names to API property names.



49
50
51
52
53
54
55
56
57
58
59
60
# File 'lib/mist_api/models/capture_switch.rb', line 49

def self.names
  @_hash = {} if @_hash.nil?
  @_hash['duration'] = 'duration'
  @_hash['format'] = 'format'
  @_hash['max_pkt_len'] = 'max_pkt_len'
  @_hash['num_packets'] = 'num_packets'
  @_hash['ports'] = 'ports'
  @_hash['switches'] = 'switches'
  @_hash['tcpdump_expression'] = 'tcpdump_expression'
  @_hash['type'] = 'type'
  @_hash
end

.nullablesObject

An array for nullable fields



75
76
77
78
79
80
81
# File 'lib/mist_api/models/capture_switch.rb', line 75

def self.nullables
  %w[
    duration
    max_pkt_len
    num_packets
  ]
end

.optionalsObject

An array for optional fields



63
64
65
66
67
68
69
70
71
72
# File 'lib/mist_api/models/capture_switch.rb', line 63

def self.optionals
  %w[
    duration
    format
    max_pkt_len
    num_packets
    ports
    tcpdump_expression
  ]
end

Instance Method Details

#inspectObject

Provides a debugging-friendly string with detailed object information.



147
148
149
150
151
152
153
# File 'lib/mist_api/models/capture_switch.rb', line 147

def inspect
  class_name = self.class.name.split('::').last
  "<#{class_name} duration: #{@duration.inspect}, format: #{@format.inspect}, max_pkt_len:"\
  " #{@max_pkt_len.inspect}, num_packets: #{@num_packets.inspect}, ports: #{@ports.inspect},"\
  " switches: #{@switches.inspect}, tcpdump_expression: #{@tcpdump_expression.inspect}, type:"\
  " #{@type.inspect}, additional_properties: #{@additional_properties}>"
end

#to_sObject

Provides a human-readable string representation of the object.



138
139
140
141
142
143
144
# File 'lib/mist_api/models/capture_switch.rb', line 138

def to_s
  class_name = self.class.name.split('::').last
  "<#{class_name} duration: #{@duration}, format: #{@format}, max_pkt_len: #{@max_pkt_len},"\
  " num_packets: #{@num_packets}, ports: #{@ports}, switches: #{@switches},"\
  " tcpdump_expression: #{@tcpdump_expression}, type: #{@type}, additional_properties:"\
  " #{@additional_properties}>"
end