Class: ConfCtl::Generation::Host

Inherits:
Object
  • Object
show all
Defined in:
lib/confctl/generation/host.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(machine, profile, id, toplevel, date, kernel_version, current: false, mc: nil) ⇒ Host

Returns a new instance of Host.

Parameters:

  • machine (Machine)
  • profile (String)
  • id (Integer)
  • toplevel (String)
  • date (Time)
  • kernel_version (String, nil)
  • mc (MachineControl) (defaults to: nil)


12
13
14
15
16
17
18
19
20
21
22
# File 'lib/confctl/generation/host.rb', line 12

def initialize(machine, profile, id, toplevel, date, kernel_version, current: false, mc: nil)
  @host = machine.name
  @machine = machine
  @profile = profile
  @id = id
  @toplevel = toplevel
  @date = date
  @kernel_version = kernel_version
  @current = current
  @mc = mc
end

Instance Attribute Details

#currentObject (readonly)

Returns the value of attribute current.



3
4
5
# File 'lib/confctl/generation/host.rb', line 3

def current
  @current
end

#dateObject (readonly)

Returns the value of attribute date.



3
4
5
# File 'lib/confctl/generation/host.rb', line 3

def date
  @date
end

#hostObject (readonly)

Returns the value of attribute host.



3
4
5
# File 'lib/confctl/generation/host.rb', line 3

def host
  @host
end

#idObject (readonly)

Returns the value of attribute id.



3
4
5
# File 'lib/confctl/generation/host.rb', line 3

def id
  @id
end

#kernel_versionObject (readonly)

Returns the value of attribute kernel_version.



3
4
5
# File 'lib/confctl/generation/host.rb', line 3

def kernel_version
  @kernel_version
end

#profileObject (readonly)

Returns the value of attribute profile.



3
4
5
# File 'lib/confctl/generation/host.rb', line 3

def profile
  @profile
end

#toplevelObject (readonly)

Returns the value of attribute toplevel.



3
4
5
# File 'lib/confctl/generation/host.rb', line 3

def toplevel
  @toplevel
end

Instance Method Details

#approx_nameObject



24
25
26
# File 'lib/confctl/generation/host.rb', line 24

def approx_name
  @approx_name ||= date.strftime('%Y-%m-%d--%H-%M-%S')
end

#destroyObject



28
29
30
31
32
33
# File 'lib/confctl/generation/host.rb', line 28

def destroy
  raise 'machine control not available' if mc.nil?

  env_cmd = @machine.carried? ? 'carrier-env' : 'nix-env'
  mc.execute(env_cmd, '-p', profile, '--delete-generations', id.to_s)
end