Class: OsCtld::NetInterface::Manager
- Inherits:
-
Object
- Object
- OsCtld::NetInterface::Manager
show all
- Includes:
- Enumerable, Lockable
- Defined in:
- lib/osctld/net_interface/manager.rb
Overview
Manages a list of interfaces
Instance Attribute Summary collapse
-
#ct ⇒ Object
readonly
protected
Returns the value of attribute ct.
-
#netifs ⇒ Object
readonly
protected
Returns the value of attribute netifs.
Class Method Summary
collapse
Instance Method Summary
collapse
Methods included from Lockable
#exclusively, included, #inclusively, #init_lock, #lock, #unlock
Constructor Details
#initialize(ct, entries: []) ⇒ Manager
Returns a new instance of Manager.
24
25
26
27
28
29
|
# File 'lib/osctld/net_interface/manager.rb', line 24
def initialize(ct, entries: [])
init_lock
@ct = ct
@netifs = entries
end
|
Instance Attribute Details
#ct ⇒ Object
Returns the value of attribute ct.
107
108
109
|
# File 'lib/osctld/net_interface/manager.rb', line 107
def ct
@ct
end
|
#netifs ⇒ Object
Returns the value of attribute netifs.
107
108
109
|
# File 'lib/osctld/net_interface/manager.rb', line 107
def netifs
@netifs
end
|
Class Method Details
.load(ct, cfg) ⇒ Object
Load interfaces from config
11
12
13
14
15
16
17
18
19
20
21
|
# File 'lib/osctld/net_interface/manager.rb', line 11
def self.load(ct, cfg)
new(
ct,
entries: cfg.each_with_index.map do |v, i|
netif = NetInterface.for(v['type'].to_sym).new(ct, i)
netif.load(v)
netif.setup
netif
end
)
end
|
Instance Method Details
#<<(netif) ⇒ Object
32
33
34
|
# File 'lib/osctld/net_interface/manager.rb', line 32
def <<(netif)
add(netif)
end
|
#[](name) ⇒ Object
78
79
80
|
# File 'lib/osctld/net_interface/manager.rb', line 78
def [](name)
inclusively { netifs.detect { |n| n.name == name } }
end
|
#add(netif) ⇒ Object
37
38
39
40
41
42
43
44
45
46
47
48
|
# File 'lib/osctld/net_interface/manager.rb', line 37
def add(netif)
exclusively { netifs << netif }
ct.save_config
Eventd.report(
:ct_netif,
action: :add,
pool: ct.pool.name,
id: ct.id,
name: netif.name
)
end
|
#contains?(name) ⇒ Boolean
73
74
75
|
# File 'lib/osctld/net_interface/manager.rb', line 73
def contains?(name)
inclusively { !(netifs.detect { |n| n.name == name }).nil? }
end
|
#delete(netif) ⇒ Object
51
52
53
54
55
56
57
58
59
60
61
62
|
# File 'lib/osctld/net_interface/manager.rb', line 51
def delete(netif)
exclusively { netifs.delete(netif) }
ct.save_config
Eventd.report(
:ct_netif,
action: :remove,
pool: ct.pool.name,
id: ct.id,
name: netif.name
)
end
|
#dump ⇒ Object
Dump interfaces to config
94
95
96
|
# File 'lib/osctld/net_interface/manager.rb', line 94
def dump
inclusively { netifs.map(&:save) }
end
|
#dup(new_ct) ⇒ Object
98
99
100
101
102
103
|
# File 'lib/osctld/net_interface/manager.rb', line 98
def dup(new_ct)
ret = super()
ret.instance_variable_set('@ct', new_ct)
ret.instance_variable_set('@netifs', netifs.map { |n| n.dup(new_ct) })
ret
end
|
#each ⇒ Object
87
88
89
|
# File 'lib/osctld/net_interface/manager.rb', line 87
def each(&)
get.each(&)
end
|
83
84
85
|
# File 'lib/osctld/net_interface/manager.rb', line 83
def get
inclusively { netifs.clone }
end
|
#take_down ⇒ Object
64
65
66
67
68
69
70
|
# File 'lib/osctld/net_interface/manager.rb', line 64
def take_down
inclusively do
netifs.each do |n|
n.down if n.is_up?
end
end
end
|