Class: OsCtld::NetInterface::Base

Inherits:
Object
  • Object
show all
Includes:
Lockable
Defined in:
lib/osctld/net_interface/base.rb

Direct Known Subclasses

Veth

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

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

#ctObject (readonly, protected)

Returns the value of attribute ct



141
142
143
# File 'lib/osctld/net_interface/base.rb', line 141

def ct
  @ct
end

#hwaddrObject (readonly)

Returns the value of attribute hwaddr



19
20
21
# File 'lib/osctld/net_interface/base.rb', line 19

def hwaddr
  @hwaddr
end

#indexObject (readonly)

Returns the value of attribute index



19
20
21
# File 'lib/osctld/net_interface/base.rb', line 19

def index
  @index
end

#nameObject (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

.setupObject



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

Parameters:

  • addr (IPAddress)

Raises:

  • (NotImplementedError)


124
125
126
# File 'lib/osctld/net_interface/base.rb', line 124

def add_ip(addr)
  raise NotImplementedError
end

#can_add_ip?(addr) ⇒ Boolean

Returns:

  • (Boolean)


118
119
120
# File 'lib/osctld/net_interface/base.rb', line 118

def can_add_ip?(addr)
  true
end

#can_run_distconfig?Boolean

Called to check if DistConfig for network can be run

Returns:

  • (Boolean)


103
104
105
# File 'lib/osctld/net_interface/base.rb', line 103

def can_run_distconfig?
  true
end

#create(opts) ⇒ Object

Setup a new interface

Parameters:

  • opts (Hash)

    options, different per interface type, symbol keys



33
34
35
36
# File 'lib/osctld/net_interface/base.rb', line 33

def create(opts)
  @name = opts[:name]
  @hwaddr = opts[:hwaddr]
end

#del_ip(addr) ⇒ Object

Delete IP address from this interface

Parameters:

  • addr (IPAddress)

Raises:

  • (NotImplementedError)


130
131
132
# File 'lib/osctld/net_interface/base.rb', line 130

def del_ip(addr)
  raise NotImplementedError
end

#down(*_args) ⇒ Object

Called when the interface goes down



97
98
99
# File 'lib/osctld/net_interface/base.rb', line 97

def down(*_args)

end

#dup(new_ct) ⇒ Object



134
135
136
137
138
# File 'lib/osctld/net_interface/base.rb', line 134

def dup(new_ct)
  ret = super()
  ret.instance_variable_set('@ct', new_ct)
  ret
end

#has_ip?(addr) ⇒ Boolean

Returns:

  • (Boolean)


114
115
116
# File 'lib/osctld/net_interface/base.rb', line 114

def has_ip?(addr)
  ips(addr.ipv4? ? 4 : 6).detect { |v| v == addr } ? true : false
end

#ips(v) ⇒ Array

List IP addresses

Returns:

  • (Array)

Raises:

  • (NotImplementedError)


109
110
111
# File 'lib/osctld/net_interface/base.rb', line 109

def ips(v)
  raise NotImplementedError
end

#load(cfg) ⇒ Object

Load configuration

Parameters:

  • cfg (Hash)

    configuration options, string keys



40
41
42
43
# File 'lib/osctld/net_interface/base.rb', line 40

def load(cfg)
  @name = cfg['name']
  @hwaddr = cfg['hwaddr']
end

#rename(new_name) ⇒ Object

Rename the interface within the container

Parameters:

  • new_name (String)


56
57
58
59
60
61
62
63
64
65
66
67
68
# File 'lib/osctld/net_interface/base.rb', line 56

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_optsHash

Return variables for template generating LXC configuration for this interface

Returns:

  • (Hash)

Raises:

  • (NotImplementedError)


87
88
89
# File 'lib/osctld/net_interface/base.rb', line 87

def render_opts
  raise NotImplementedError
end

#saveHash

Dump configuration

Returns:

  • (Hash)

    hash with string keys, given the has that `load` has then restores the state from



48
49
50
51
52
# File 'lib/osctld/net_interface/base.rb', line 48

def save
  inclusively do
    {'type' => type.to_s, 'name' => name, 'hwaddr' => hwaddr}
  end
end

#set(opts) ⇒ Object

Change interface properties

Parameters:

  • opts (Hash)

    options, see subclasses for more information

Options Hash (opts):

  • :hwaddr (String)


73
74
75
76
77
# File 'lib/osctld/net_interface/base.rb', line 73

def set(opts)
  exclusively do
    @hwaddr = opts[:hwaddr] if opts.has_key?(:hwaddr)
  end
end

#setupObject

Initialize the interface on creation / osctld restart



80
81
82
# File 'lib/osctld/net_interface/base.rb', line 80

def setup

end

#typeObject



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



92
93
94
# File 'lib/osctld/net_interface/base.rb', line 92

def up(*_args)

end