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.
30
31
32
33
34
35
|
# File 'lib/osctld/net_interface/manager.rb', line 30
def initialize(ct, entries: [])
init_lock
@ct = ct
@netifs = entries
end
|
Instance Attribute Details
#ct ⇒ Object
Returns the value of attribute ct.
144
145
146
|
# File 'lib/osctld/net_interface/manager.rb', line 144
def ct
@ct
end
|
#netifs ⇒ Object
Returns the value of attribute netifs.
144
145
146
|
# File 'lib/osctld/net_interface/manager.rb', line 144
def netifs
@netifs
end
|
Class Method Details
.load(ct, cfg, discover_host_links: true) ⇒ Object
Load interfaces from config
Instance Method Details
#<<(netif) ⇒ Object
38
39
40
|
# File 'lib/osctld/net_interface/manager.rb', line 38
def <<(netif)
add(netif)
end
|
#[](name) ⇒ Object
115
116
117
|
# File 'lib/osctld/net_interface/manager.rb', line 115
def [](name)
inclusively { netifs.detect { |n| n.name == name } }
end
|
#contains?(name) ⇒ Boolean
110
111
112
|
# File 'lib/osctld/net_interface/manager.rb', line 110
def contains?(name)
inclusively { !(netifs.detect { |n| n.name == name }).nil? }
end
|
#delete(netif) ⇒ Object
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
|
# File 'lib/osctld/net_interface/manager.rb', line 63
def delete(netif)
NetInterface.sync_host_link_registry do
if netif.respond_to?(:host_link_identity) &&
netif.host_link_identity.any?
raise NetInterface::HostLinkClaimError,
"network interface #{netif.name.inspect} still owns a host link; " \
'complete lifecycle cleanup before removing it'
end
exclusively { netifs.delete(netif) }
ct.save_config
Eventd.report(
:ct_netif,
action: :remove,
pool: ct.pool.name,
id: ct.id,
name: netif.name
)
end
end
|
#dump ⇒ Object
Dump interfaces to config
131
132
133
|
# File 'lib/osctld/net_interface/manager.rb', line 131
def dump
inclusively { netifs.map(&:save) }
end
|
#dup(new_ct) ⇒ Object
135
136
137
138
139
140
|
# File 'lib/osctld/net_interface/manager.rb', line 135
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
124
125
126
|
# File 'lib/osctld/net_interface/manager.rb', line 124
def each(&)
get.each(&)
end
|
120
121
122
|
# File 'lib/osctld/net_interface/manager.rb', line 120
def get
inclusively { netifs.clone }
end
|
#recovery_tainted? ⇒ Boolean
93
94
95
96
97
98
99
|
# File 'lib/osctld/net_interface/manager.rb', line 93
def recovery_tainted?
inclusively do
netifs.any? do |netif|
netif.respond_to?(:host_link_tainted?) && netif.host_link_tainted?
end
end
end
|
#setup_state_changed? ⇒ Boolean
101
102
103
104
105
106
107
|
# File 'lib/osctld/net_interface/manager.rb', line 101
def setup_state_changed?
inclusively do
netifs.any? do |netif|
netif.respond_to?(:setup_state_changed?) && netif.setup_state_changed?
end
end
end
|
#take_down ⇒ Object
85
86
87
88
89
90
91
|
# File 'lib/osctld/net_interface/manager.rb', line 85
def take_down
NetInterface.sync_host_link_registry do
get.each do |n|
n.down if n.is_created?
end
end
end
|