Class: Construqt::Vlans

Inherits:
Object
  • Object
show all
Defined in:
lib/construqt/vlans.rb

Defined Under Namespace

Classes: Vlan

Instance Method Summary collapse

Constructor Details

#initialize(region) ⇒ Vlans

Returns a new instance of Vlans.



4
5
6
7
8
# File 'lib/construqt/vlans.rb', line 4

def initialize(region)
  @region = region
  @vlans_id = {}
  @vlans_description = {}
end

Instance Method Details

#add(vlan, cfg) ⇒ Object



34
35
36
37
38
39
40
41
42
43
44
# File 'lib/construqt/vlans.rb', line 34

def add(vlan, cfg)
  throw "vlan has to be a fixnum #{vlan}" unless vlan.kind_of?(Fixnum)
  throw "vlan need #{vlan} description" unless cfg['description']
  throw "vlan with id #{vlan} exists" if @vlans_id[vlan]
  throw "vlan with description #{vlan} exists" if @vlans_description[cfg['description']]
  cfg['vlan_id'] = vlan
  ret = Vlan.new(cfg)
  @vlans_id[vlan] = ret
  @vlans_description[cfg['description']] = ret
  ret
end

#clone(key) ⇒ Object



46
47
48
49
# File 'lib/construqt/vlans.rb', line 46

def clone(key)
  throw "vlan clone key not found #{key}" unless @vlans_id[key] || @vlans_description[key]
  (@vlans_id[key] || @vlans_description[key]).clone
end