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.
-
#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_down? ⇒ Boolean
- #is_up? ⇒ Boolean
-
#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.
21 22 23 24 25 |
# File 'lib/osctld/net_interface/base.rb', line 21 def initialize(ct, index) @ct = ct @index = index init_lock end |
Instance Attribute Details
#ct ⇒ Object (readonly, protected)
Returns the value of attribute ct.
163 164 165 |
# File 'lib/osctld/net_interface/base.rb', line 163 def ct @ct end |
#hwaddr ⇒ Object (readonly)
Returns the value of attribute hwaddr.
19 20 21 |
# File 'lib/osctld/net_interface/base.rb', line 19 def hwaddr @hwaddr end |
#index ⇒ Object (readonly)
Returns the value of attribute index.
19 20 21 |
# File 'lib/osctld/net_interface/base.rb', line 19 def index @index end |
#max_rx ⇒ Object (readonly)
Returns the value of attribute max_rx.
19 20 21 |
# File 'lib/osctld/net_interface/base.rb', line 19 def max_rx @max_rx end |
#max_tx ⇒ Object (readonly)
Returns the value of attribute max_tx.
19 20 21 |
# File 'lib/osctld/net_interface/base.rb', line 19 def max_tx @max_tx end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
19 20 21 |
# File 'lib/osctld/net_interface/base.rb', line 19 def name @name end |
Class Method Details
.setup ⇒ Object
13 14 15 |
# 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
146 147 148 |
# File 'lib/osctld/net_interface/base.rb', line 146 def add_ip(addr) raise NotImplementedError end |
#can_add_ip?(addr) ⇒ Boolean
140 141 142 |
# File 'lib/osctld/net_interface/base.rb', line 140 def can_add_ip?(addr) true end |
#can_run_distconfig? ⇒ Boolean
Called to check if DistConfig for network can be run
125 126 127 |
# File 'lib/osctld/net_interface/base.rb', line 125 def can_run_distconfig? true end |
#create(opts) ⇒ Object
Setup a new interface
33 34 35 36 37 38 |
# File 'lib/osctld/net_interface/base.rb', line 33 def create(opts) @name = opts[:name] @hwaddr = opts[:hwaddr] @max_tx = opts.fetch(:max_tx, 0) @max_rx = opts.fetch(:max_rx, 0) end |
#del_ip(addr) ⇒ Object
Delete IP address from this interface
152 153 154 |
# File 'lib/osctld/net_interface/base.rb', line 152 def del_ip(addr) raise NotImplementedError end |
#down(*_args) ⇒ Object
Called when the interface goes down
111 112 113 |
# File 'lib/osctld/net_interface/base.rb', line 111 def down(*_args) end |
#dup(new_ct) ⇒ Object
156 157 158 159 160 |
# File 'lib/osctld/net_interface/base.rb', line 156 def dup(new_ct) ret = super() ret.instance_variable_set('@ct', new_ct) ret end |
#has_ip?(addr) ⇒ Boolean
136 137 138 |
# File 'lib/osctld/net_interface/base.rb', line 136 def has_ip?(addr) ips(addr.ipv4? ? 4 : 6).detect { |v| v == addr } ? true : false end |
#ips(v) ⇒ Array
List IP addresses
131 132 133 |
# File 'lib/osctld/net_interface/base.rb', line 131 def ips(v) raise NotImplementedError end |
#is_down? ⇒ Boolean
119 120 121 |
# File 'lib/osctld/net_interface/base.rb', line 119 def is_down? !is_up? end |
#is_up? ⇒ Boolean
115 116 117 |
# File 'lib/osctld/net_interface/base.rb', line 115 def is_up? raise NotImplementedError end |
#load(cfg) ⇒ Object
Load configuration
42 43 44 45 46 47 |
# File 'lib/osctld/net_interface/base.rb', line 42 def load(cfg) @name = cfg['name'] @hwaddr = cfg['hwaddr'] @max_tx = cfg.fetch('max_tx', 0) @max_rx = cfg.fetch('max_rx', 0) end |
#rename(new_name) ⇒ Object
Rename the interface within the container
66 67 68 69 70 71 72 73 74 75 76 77 78 |
# File 'lib/osctld/net_interface/base.rb', line 66 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: new_name, ) end |
#render_opts ⇒ Hash
Return variables for template generating LXC configuration for this interface
101 102 103 |
# File 'lib/osctld/net_interface/base.rb', line 101 def render_opts raise NotImplementedError end |
#save ⇒ Hash
Dump configuration
52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/osctld/net_interface/base.rb', line 52 def save inclusively do { 'type' => type.to_s, 'name' => name, 'hwaddr' => hwaddr, 'max_tx' => max_tx, 'max_rx' => max_rx, } end end |
#set(opts) ⇒ Object
Change interface properties
85 86 87 88 89 90 91 |
# File 'lib/osctld/net_interface/base.rb', line 85 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) end end |
#setup ⇒ Object
Initialize the interface on creation / osctld restart
94 95 96 |
# File 'lib/osctld/net_interface/base.rb', line 94 def setup end |
#type ⇒ Object
27 28 29 |
# File 'lib/osctld/net_interface/base.rb', line 27 def type self.class.type end |
#up(*_args) ⇒ Object
Called when the interface goes up
106 107 108 |
# File 'lib/osctld/net_interface/base.rb', line 106 def up(*_args) end |