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(host, profile, id, toplevel, date, current: false, mc: nil) ⇒ Host

Returns a new instance of Host.

Parameters:

  • host (String)
  • profile (String)
  • id (Integer)
  • toplevel (String)
  • date (Time)
  • mc (MachineControl) (defaults to: nil)


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

def initialize(host, profile, id, toplevel, date, current: false, mc: nil)
  @host = host
  @profile = profile
  @id = id
  @toplevel = toplevel
  @date = date
  @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

#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



21
22
23
# File 'lib/confctl/generation/host.rb', line 21

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

#destroyObject



25
26
27
28
29
# File 'lib/confctl/generation/host.rb', line 25

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

  mc.execute('nix-env', '-p', profile, '--delete-generations', id.to_s)
end