Method: Cisco::Client::GRPC#set
- Defined in:
- lib/cisco_node_utils/client/grpc/client.rb
#set(data_format: :cli, context: nil, values: nil, **kwargs) ⇒ Object
Configure the given CLI command(s) on the device.
92 93 94 95 96 97 98 99 100 101 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 |
# File 'lib/cisco_node_utils/client/grpc/client.rb', line 92 def set(data_format: :cli, context: nil, values: nil, **kwargs) context = munge_to_array(context) values = munge_to_array(values) super if data_format == :yang_json mode = kwargs[:mode] || :merge_config fail ArgumentError unless Cisco::YANG_SET_MODE.include? mode values.each do |yang| yang_req(@config, mode.to_s, ConfigArgs.new(yangjson: yang)) end else # IOS XR lets us concatenate submode commands together. # This makes it possible to guarantee we are in the correct context: # context: ['foo', 'bar'], values: ['baz', 'bat'] # ---> values: ['foo bar baz', 'foo bar bat'] # However, there's a special case for 'no' commands: # context: ['foo', 'bar'], values: ['no baz'] # ---> values: ['no foo bar baz'] ---- the 'no' goes at the start context = context.join(' ') unless context.empty? values.map! do |cmd| match = cmd[/^\s*no\s+(.*)/, 1] if match cmd = "no #{context} #{match}" else cmd = "#{context} #{cmd}" end cmd end end # CliConfigArgs wants a newline-separated string of commands args = CliConfigArgs.new(cli: values.join("\n")) req(@config, 'cli_config', args) end end |