Class: OsCtld::NetInterface::Base
- Inherits:
-
Object
- Object
- OsCtld::NetInterface::Base
- Includes:
- Lockable
- Defined in:
- lib/osctld/net_interface/base.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#ct ⇒ Object
readonly
protected
Returns the value of attribute ct.
- #enable ⇒ Boolean readonly
-
#hwaddr ⇒ Object
readonly
Returns the value of attribute hwaddr.
-
#index ⇒ Object
readonly
Returns the value of attribute index.
-
#max_rx ⇒ Object
readonly
Returns the value of attribute max_rx.
-
#max_tx ⇒ Object
readonly
Returns the value of attribute max_tx.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
Class Method Summary collapse
Instance Method Summary collapse
-
#add_ip(addr) ⇒ Object
Add IP address to this interface.
- #can_add_ip?(_addr) ⇒ Boolean
-
#can_run_distconfig? ⇒ Boolean
Called to check if DistConfig for network can be run.
-
#create(opts) ⇒ Object
Setup a new interface.
-
#del_ip(addr) ⇒ Object
Delete IP address from this interface.
-
#down(*_args) ⇒ Object
Called when the interface goes down.
- #dup(new_ct) ⇒ Object
- #has_ip?(addr) ⇒ Boolean
-
#initialize(ct, index) ⇒ Base
constructor
A new instance of Base.
-
#ips(v) ⇒ Array
List IP addresses.
-
#is_created? ⇒ Boolean
True if the interface is created on the host system.
-
#is_up? ⇒ Boolean
True if the interface is created and up.
-
#load(cfg) ⇒ Object
Load configuration.
-
#rename(new_name) ⇒ Object
Rename the interface within the container.
-
#render_opts ⇒ Hash
Return variables for template generating LXC configuration for this interface.
-
#save ⇒ Hash
Dump configuration.
-
#set(opts) ⇒ Object
Change interface properties.
-
#setup ⇒ Object
Initialize the interface on creation / osctld restart.
- #type ⇒ Object
-
#up(*_args) ⇒ Object
Called when the interface goes up.
Methods included from Lockable
#exclusively, included, #inclusively, #init_lock, #lock, #unlock
Constructor Details
#initialize(ct, index) ⇒ Base
Returns a new instance of Base.
22 23 24 25 26 |
# File 'lib/osctld/net_interface/base.rb', line 22 def initialize(ct, index) @ct = ct @index = index init_lock end |
Instance Attribute Details
#ct ⇒ Object (readonly, protected)
Returns the value of attribute ct.
171 172 173 |
# File 'lib/osctld/net_interface/base.rb', line 171 def ct @ct end |
#enable ⇒ Boolean (readonly)
20 21 22 |
# File 'lib/osctld/net_interface/base.rb', line 20 def enable @enable end |
#hwaddr ⇒ Object (readonly)
Returns the value of attribute hwaddr.
17 18 19 |
# File 'lib/osctld/net_interface/base.rb', line 17 def hwaddr @hwaddr end |
#index ⇒ Object (readonly)
Returns the value of attribute index.
17 18 19 |
# File 'lib/osctld/net_interface/base.rb', line 17 def index @index end |
#max_rx ⇒ Object (readonly)
Returns the value of attribute max_rx.
17 18 19 |
# File 'lib/osctld/net_interface/base.rb', line 17 def max_rx @max_rx end |
#max_tx ⇒ Object (readonly)
Returns the value of attribute max_tx.
17 18 19 |
# File 'lib/osctld/net_interface/base.rb', line 17 def max_tx @max_tx end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
17 18 19 |
# File 'lib/osctld/net_interface/base.rb', line 17 def name @name end |
Class Method Details
.setup ⇒ Object
13 |
# File 'lib/osctld/net_interface/base.rb', line 13 def self.setup; end |
.type(name = nil) ⇒ Object
3 4 5 6 7 8 9 10 11 |
# File 'lib/osctld/net_interface/base.rb', line 3 def self.type(name = nil) if name NetInterface.register(name, self) @type = name else @type end end |
Instance Method Details
#add_ip(addr) ⇒ Object
Add IP address to this interface
153 154 155 |
# File 'lib/osctld/net_interface/base.rb', line 153 def add_ip(addr) raise NotImplementedError end |
#can_add_ip?(_addr) ⇒ Boolean
147 148 149 |
# File 'lib/osctld/net_interface/base.rb', line 147 def can_add_ip?(_addr) true end |
#can_run_distconfig? ⇒ Boolean
Called to check if DistConfig for network can be run
128 129 130 |
# File 'lib/osctld/net_interface/base.rb', line 128 def can_run_distconfig? true end |
#create(opts) ⇒ Object
Setup a new interface
34 35 36 37 38 39 40 |
# File 'lib/osctld/net_interface/base.rb', line 34 def create(opts) @name = opts[:name] @hwaddr = opts[:hwaddr] @max_tx = opts.fetch(:max_tx, 0) @max_rx = opts.fetch(:max_rx, 0) @enable = opts.fetch(:enable, true) end |
#del_ip(addr) ⇒ Object
Delete IP address from this interface
159 160 161 |
# File 'lib/osctld/net_interface/base.rb', line 159 def del_ip(addr) raise NotImplementedError end |
#down(*_args) ⇒ Object
Called when the interface goes down
112 |
# File 'lib/osctld/net_interface/base.rb', line 112 def down(*_args); end |
#dup(new_ct) ⇒ Object
163 164 165 166 167 |
# File 'lib/osctld/net_interface/base.rb', line 163 def dup(new_ct) ret = super() ret.instance_variable_set('@ct', new_ct) ret end |
#has_ip?(addr) ⇒ Boolean
139 140 141 142 143 144 145 |
# File 'lib/osctld/net_interface/base.rb', line 139 def has_ip?(addr) if ips(addr.ipv4? ? 4 : 6).detect { |v| v == addr } true else false end end |
#ips(v) ⇒ Array
List IP addresses
134 135 136 |
# File 'lib/osctld/net_interface/base.rb', line 134 def ips(v) raise NotImplementedError end |
#is_created? ⇒ Boolean
True if the interface is created on the host system
116 117 118 |
# File 'lib/osctld/net_interface/base.rb', line 116 def is_created? raise NotImplementedError end |
#is_up? ⇒ Boolean
True if the interface is created and up
122 123 124 |
# File 'lib/osctld/net_interface/base.rb', line 122 def is_up? inclusively { is_created? && enable } end |
#load(cfg) ⇒ Object
Load configuration
44 45 46 47 48 49 50 |
# File 'lib/osctld/net_interface/base.rb', line 44 def load(cfg) @name = cfg['name'] @hwaddr = cfg['hwaddr'] @max_tx = cfg.fetch('max_tx', 0) @max_rx = cfg.fetch('max_rx', 0) @enable = cfg.fetch('enable', true) end |
#rename(new_name) ⇒ Object
Rename the interface within the container
70 71 72 73 74 75 76 77 78 79 80 81 82 |
# File 'lib/osctld/net_interface/base.rb', line 70 def rename(new_name) old_name = inclusively { @name } exclusively { @name = new_name } Eventd.report( :ct_netif, action: :rename, pool: ct.pool.name, id: ct.id, name: old_name, new_name: ) end |
#render_opts ⇒ Hash
Return variables for template generating LXC configuration for this interface
104 105 106 |
# File 'lib/osctld/net_interface/base.rb', line 104 def render_opts raise NotImplementedError end |
#save ⇒ Hash
Dump configuration
55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/osctld/net_interface/base.rb', line 55 def save inclusively do { 'type' => type.to_s, 'name' => name, 'hwaddr' => hwaddr, 'max_tx' => max_tx, 'max_rx' => max_rx, 'enable' => enable } end end |
#set(opts) ⇒ Object
Change interface properties
89 90 91 92 93 94 95 96 |
# File 'lib/osctld/net_interface/base.rb', line 89 def set(opts) exclusively do @hwaddr = opts[:hwaddr] if opts.has_key?(:hwaddr) @max_tx = opts[:max_tx] if opts.has_key?(:max_tx) @max_rx = opts[:max_rx] if opts.has_key?(:max_rx) @enable = opts[:enable] if opts.has_key?(:enable) end end |
#setup ⇒ Object
Initialize the interface on creation / osctld restart
99 |
# File 'lib/osctld/net_interface/base.rb', line 99 def setup; end |
#type ⇒ Object
28 29 30 |
# File 'lib/osctld/net_interface/base.rb', line 28 def type self.class.type end |
#up(*_args) ⇒ Object
Called when the interface goes up
109 |
# File 'lib/osctld/net_interface/base.rb', line 109 def up(*_args); end |