Class: OsCtl::Cli::Top::Container

Inherits:
Object
  • Object
show all
Defined in:
lib/osctl/cli/top/container.rb

Direct Known Subclasses

Host

Defined Under Namespace

Classes: NetIf

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(ct) ⇒ Container

Returns a new instance of Container.

Parameters:

  • ct (Hash)

    container from ct_show



14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/osctl/cli/top/container.rb', line 14

def initialize(ct)
  @id = ct[:id]
  @pool = ct[:pool]
  @ident = "#{@pool}:#{@id}"
  @dataset = ct[:dataset]
  @group_path = ct[:group_path]
  @state = ct[:state].to_sym
  @cpu_package_inuse = ct[:cpu_package_inuse]
  @lxcfs_mountpoint = ct[:lxcfs_mountpoint]
  @init_pid = ct[:init_pid]
  @netifs = []
  @measurements = []
  @initial = nil
end

Instance Attribute Details

#cpu_package_inuseObject

Returns the value of attribute cpu_package_inuse.



11
12
13
# File 'lib/osctl/cli/top/container.rb', line 11

def cpu_package_inuse
  @cpu_package_inuse
end

#datasetObject (readonly)

Returns the value of attribute dataset.



10
11
12
# File 'lib/osctl/cli/top/container.rb', line 10

def dataset
  @dataset
end

#group_pathObject (readonly)

Returns the value of attribute group_path.



10
11
12
# File 'lib/osctl/cli/top/container.rb', line 10

def group_path
  @group_path
end

#idObject (readonly)

Returns the value of attribute id.



10
11
12
# File 'lib/osctl/cli/top/container.rb', line 10

def id
  @id
end

#identObject (readonly)

Returns the value of attribute ident.



10
11
12
# File 'lib/osctl/cli/top/container.rb', line 10

def ident
  @ident
end

#init_pidObject

Returns the value of attribute init_pid.



11
12
13
# File 'lib/osctl/cli/top/container.rb', line 11

def init_pid
  @init_pid
end

#initialObject (readonly, protected)

Returns the value of attribute initial.



98
99
100
# File 'lib/osctl/cli/top/container.rb', line 98

def initial
  @initial
end

#measurementsObject (readonly, protected)

Returns the value of attribute measurements.



98
99
100
# File 'lib/osctl/cli/top/container.rb', line 98

def measurements
  @measurements
end

#netifsObject

Returns the value of attribute netifs.



11
12
13
# File 'lib/osctl/cli/top/container.rb', line 11

def netifs
  @netifs
end

#poolObject (readonly)

Returns the value of attribute pool.



10
11
12
# File 'lib/osctl/cli/top/container.rb', line 10

def pool
  @pool
end

#stateObject

Returns the value of attribute state.



11
12
13
# File 'lib/osctl/cli/top/container.rb', line 11

def state
  @state
end

Instance Method Details

#[](k) ⇒ Object



29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/osctl/cli/top/container.rb', line 29

def [](k)
  # Used by OsCtl::Lib::LoadAvgReader
  case k
  when :id
    @id
  when :pool
    @pool
  when :lxcfs_mountpoint
    @lxcfs_mountpoint
  else
    raise ArgumentError, "key #{k.inspect} is not supported"
  end
end

#container?Boolean

Returns:

  • (Boolean)


51
52
53
# File 'lib/osctl/cli/top/container.rb', line 51

def container?
  true
end

#find_netif(name) ⇒ Object (protected)



100
101
102
# File 'lib/osctl/cli/top/container.rb', line 100

def find_netif(name)
  netifs.detect { |netif| netif.name == name }
end

#has_netif?(name) ⇒ Boolean

Returns:

  • (Boolean)


93
94
95
# File 'lib/osctl/cli/top/container.rb', line 93

def has_netif?(name)
  !find_netif(name).nil?
end

#measure(host, subsystems) ⇒ Object



55
56
57
58
59
60
61
# File 'lib/osctl/cli/top/container.rb', line 55

def measure(host, subsystems)
  m = Top::Measurement.new(host, subsystems, group_path, dataset, netifs)
  m.measure
  @initial = m if measurements.empty?
  measurements << m
  measurements.shift if measurements.size > 2
end

#netif_down(name) ⇒ Object



78
79
80
81
# File 'lib/osctl/cli/top/container.rb', line 78

def netif_down(name)
  netif = find_netif(name)
  netif.veth = nil
end

#netif_rename(name, new_name) ⇒ Object



88
89
90
91
# File 'lib/osctl/cli/top/container.rb', line 88

def netif_rename(name, new_name)
  netif = find_netif(name)
  netif.name = new_name
end

#netif_rm(name) ⇒ Object



83
84
85
86
# File 'lib/osctl/cli/top/container.rb', line 83

def netif_rm(name)
  netif = find_netif(name)
  netifs.delete(netif)
end

#netif_up(name, veth) ⇒ Object



73
74
75
76
# File 'lib/osctl/cli/top/container.rb', line 73

def netif_up(name, veth)
  netif = find_netif(name)
  netif.veth = veth
end

#result(mode) ⇒ Object



63
64
65
66
67
68
69
70
71
# File 'lib/osctl/cli/top/container.rb', line 63

def result(mode)
  case mode
  when :realtime
    measurements[1].diff_from(measurements[0], mode)

  when :cumulative
    measurements[1].diff_from(initial, mode)
  end
end

#running?Boolean

Returns:

  • (Boolean)


47
48
49
# File 'lib/osctl/cli/top/container.rb', line 47

def running?
  @state == :running
end

#setup?Boolean

Returns:

  • (Boolean)


43
44
45
# File 'lib/osctl/cli/top/container.rb', line 43

def setup?
  measurements.count >= 2
end