Class: Mu::Command::Cmd_netconfig

Inherits:
Mu::Command show all
Defined in:
lib/mu/command/cmd_netconfig.rb

Constant Summary

Constants inherited from Mu::Command

Api

Constants included from Helper

Helper::ESCAPES

Instance Attribute Summary collapse

Attributes inherited from Mu::Command

#options, #opts

Instance Method Summary collapse

Methods inherited from Mu::Command

#initialize

Methods included from Helper

#ask, #bin2hex, #error, #escape, #format_float, #get_file_as_string_array, #make_xml, #msg, #shift, #to_boolean

Constructor Details

This class inherits a constructor from Mu::Command

Instance Attribute Details

#apiObject

Returns the value of attribute api.



7
8
9
# File 'lib/mu/command/cmd_netconfig.rb', line 7

def api
  @api
end

#hostObject

Returns the value of attribute host.



7
8
9
# File 'lib/mu/command/cmd_netconfig.rb', line 7

def host
  @host
end

#passwordObject

Returns the value of attribute password.



7
8
9
# File 'lib/mu/command/cmd_netconfig.rb', line 7

def password
  @password
end

#usernameObject

Returns the value of attribute username.



7
8
9
# File 'lib/mu/command/cmd_netconfig.rb', line 7

def username
  @username
end

Instance Method Details

#cmd_clear_hosts(argv) ⇒ Object

clears existing network configuration hosts

* argv = command-line arguments


70
71
72
73
74
75
# File 'lib/mu/command/cmd_netconfig.rb', line 70

def cmd_clear_hosts argv
  setup argv
  response = @api.clear_hosts
  msg JSON.pretty_generate(response)
  return response
end

#cmd_clear_interface(argv) ⇒ Object

clears existing network interfaces

* argv = command-line arguments, require the names of the interfaces to clear (-i name)


89
90
91
92
93
94
95
# File 'lib/mu/command/cmd_netconfig.rb', line 89

def cmd_clear_interface argv
  setup argv
  interface = @hash['interfaces']
  response = @api.clear_interface(interface)
  msg response
  return response
end

#cmd_clear_routes(argv) ⇒ Object

clears existing network routes

* argv = command-line arguments


108
109
110
111
112
113
# File 'lib/mu/command/cmd_netconfig.rb', line 108

def cmd_clear_routes argv
  setup argv
  response = @api.clear_routes
  msg response
  return response
end

#cmd_clear_vlans(argv) ⇒ Object

clears existing vlan configurations

* argv = command-line arguments


99
100
101
102
103
104
# File 'lib/mu/command/cmd_netconfig.rb', line 99

def cmd_clear_vlans argv
  setup argv
  response = @api.clear_vlans
  msg response
  return response
end

#cmd_create(argv) ⇒ Object

creates a new network element

* argv = command-line arguments, requires a json configuration (-j) and the element (-e) to modify, such as 'interfaces', 'hosts' or 'routes'


38
39
40
41
42
43
44
45
# File 'lib/mu/command/cmd_netconfig.rb', line 38

def cmd_create argv
  setup argv
  json = @hash['json']
  e = @hash['element']
  response = @api.create(json, e)
  msg response
  return response
end

#cmd_delete(argv) ⇒ Object

deletes an existing network element

* argv = command-line arguments, requires a json configuration (-j) and the element (-e) to modify, such as 'interfaces', 'hosts' or 'routes' or 'interfaces/a1' or 'hosts/dell-9'


49
50
51
52
53
54
55
# File 'lib/mu/command/cmd_netconfig.rb', line 49

def cmd_delete argv
  setup argv
  e = @hash['element']
  response = @api.delete(e)
  msg response
  return response
end

#cmd_get(argv) ⇒ Object

returns a json representation of the specified element

* argv = command-line arguments, requires an element (-e) argument, such as 'interfaces', 'hosts' or 'routes' or 'interfaces/a1' or 'hosts/dell-9'


16
17
18
19
20
21
22
# File 'lib/mu/command/cmd_netconfig.rb', line 16

def cmd_get argv
  setup argv
  e = @hash['element']
  response = @api.get(e)
  msg JSON.pretty_generate(response)
  return response
end

#cmd_help(argv) ⇒ Object

displays command-line help



10
11
12
# File 'lib/mu/command/cmd_netconfig.rb', line 10

def cmd_help argv
  help
end

#cmd_modify(argv) ⇒ Object

modifies a network element

* argv = command-line arguments, requires a json configuration (-j) and the element (-e) to modify, such as 'interfaces', 'hosts' or 'routes' or 'interfaces/a1' or 'hosts/dell-9'


26
27
28
29
30
31
32
33
# File 'lib/mu/command/cmd_netconfig.rb', line 26

def cmd_modify argv
  setup argv
  json = @hash['json']
  e = @hash['element']
  response = @api.modify(json, e)
  msg response
  return response
end

#cmd_resolve_hosts(argv) ⇒ Object

resolves network configuration hosts

* argv = command-line arguments, requires the name (-n) of the host to resolve (determines its ip address and adds it to the network configuration)


79
80
81
82
83
84
85
# File 'lib/mu/command/cmd_netconfig.rb', line 79

def cmd_resolve_hosts argv
  setup argv
  name = @hash['name']
  response = @api.resolve_hosts(name)
  msg response
  return response
end

#cmd_restore(argv) ⇒ Object

restores the network configuration from a file

* argv = command-line arguments, requires a path to a json configuration file (-f) , and a boolean (-b true|false) argument indicating whether or not existing elements should be cleared


59
60
61
62
63
64
65
66
# File 'lib/mu/command/cmd_netconfig.rb', line 59

def cmd_restore argv
  setup argv
  filepath = @hash['filepath']
  clear_existing = to_boolean(@hash['boolean'])
  response = @api.restore(filepath, clear_existing)
  msg response
  return response
end

#cmd_save(argv) ⇒ Object

saves the network configuration to a file

* argv = command-line arguments, requires the element (-e element, such as 'interfaces', or -e all) to save, and a file name (-f) to save the settings to


118
119
120
121
122
123
124
125
# File 'lib/mu/command/cmd_netconfig.rb', line 118

def cmd_save argv
  setup argv
  e = @hash['elements']
  filepath = @hash['filepath'] || "config.json"
  response = @api.save(e, filepath)
  msg response
  return response
end