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
# File 'lib/osctl/cli/top/container.rb', line 14

def initialize(ct)
  @id = ct[:id]
  @pool = ct[:pool]
  @group_path = ct[:group_path]
  @state = ct[:state].to_sym
  @netifs = []
  @measurements = []
  @initial = nil
end

Instance Attribute Details

#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

#initialObject (readonly, protected)

Returns the value of attribute initial



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

def initial
  @initial
end

#measurementsObject (readonly, protected)

Returns the value of attribute measurements



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

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

#container?Boolean

Returns:

  • (Boolean)


32
33
34
# File 'lib/osctl/cli/top/container.rb', line 32

def container?
  true
end

#find_netif(name) ⇒ Object (protected)



81
82
83
# File 'lib/osctl/cli/top/container.rb', line 81

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

#has_netif?(name) ⇒ Boolean

Returns:

  • (Boolean)


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

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

#measure(subsystems) ⇒ Object



36
37
38
39
40
41
42
# File 'lib/osctl/cli/top/container.rb', line 36

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

#netif_down(name) ⇒ Object



59
60
61
62
# File 'lib/osctl/cli/top/container.rb', line 59

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

#netif_rename(name, new_name) ⇒ Object



69
70
71
72
# File 'lib/osctl/cli/top/container.rb', line 69

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

#netif_rm(name) ⇒ Object



64
65
66
67
# File 'lib/osctl/cli/top/container.rb', line 64

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

#netif_up(name, veth) ⇒ Object



54
55
56
57
# File 'lib/osctl/cli/top/container.rb', line 54

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

#result(mode) ⇒ Object



44
45
46
47
48
49
50
51
52
# File 'lib/osctl/cli/top/container.rb', line 44

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)


28
29
30
# File 'lib/osctl/cli/top/container.rb', line 28

def running?
  @state == :running
end

#setup?Boolean

Returns:

  • (Boolean)


24
25
26
# File 'lib/osctl/cli/top/container.rb', line 24

def setup?
  measurements.count >= 2
end