Class: Bixby::Provision::Base

Inherits:
Object
  • Object
show all
Extended by:
Log
Includes:
Log, Util::File, ScriptUtil
Defined in:
lib/bixby/provision/dsl/base.rb

Constant Summary collapse

PATH =
"/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Util::File

#chmod, #chown, #sha256sum, #which

Constructor Details

#initialize(obj = nil) ⇒ Base

Returns a new instance of Base.



20
21
22
23
24
25
# File 'lib/bixby/provision/dsl/base.rb', line 20

def initialize(obj=nil)
  if obj.kind_of? Base then
    @manifest = obj.manifest
    @proxy    = obj.proxy
  end
end

Instance Attribute Details

#manifestObject

Returns the value of attribute manifest.



18
19
20
# File 'lib/bixby/provision/dsl/base.rb', line 18

def manifest
  @manifest
end

#proxyObject

Returns the value of attribute proxy.



18
19
20
# File 'lib/bixby/provision/dsl/base.rb', line 18

def proxy
  @proxy
end

Instance Method Details

#get_gid(group) ⇒ Object



53
54
55
56
57
58
59
60
61
62
63
# File 'lib/bixby/provision/dsl/base.rb', line 53

def get_gid(group)
  return group if group.nil? or group.kind_of? Fixnum
  return group.to_i if group =~ /^[0-9]+$/ # convert to int, e.g. "500"
  begin
    return Etc.getgrnam(group).gid
  rescue ArgumentError => ex
    # TODO raise
    logger.warn("Group '#{group}' was invalid: #{ex.message}")
  end
  nil
end

#get_group(gid) ⇒ Object



65
66
67
68
69
70
71
72
73
# File 'lib/bixby/provision/dsl/base.rb', line 65

def get_group(gid)
  begin
    return Etc.getgrgid(gid).name
  rescue ArgumentError => ex
    # TODO raise
    logger.warn("Group '#{group}' was invalid: #{ex.message}")
  end
  nil
end

#get_uid(user) ⇒ Object



31
32
33
34
35
36
37
38
39
40
41
# File 'lib/bixby/provision/dsl/base.rb', line 31

def get_uid(user)
  return user if user.nil? or user.kind_of? Fixnum
  return user.to_i if user =~ /^[0-9]+$/ # convert to int, e.g. "500"
  begin
    return Etc.getpwnam(user).uid
  rescue ArgumentError => ex
    # TODO raise
    logger.warn("Username '#{user}' was invalid: #{ex.message}")
  end
  nil
end

#get_user(uid) ⇒ Object



43
44
45
46
47
48
49
50
51
# File 'lib/bixby/provision/dsl/base.rb', line 43

def get_user(uid)
  begin
    return Etc.getpwuid(uid).name
  rescue ArgumentError => ex
    # TODO raise
    logger.warn("Username '#{user}' was invalid: #{ex.message}")
  end
  nil
end

#tap(&block) ⇒ Object



27
28
29
# File 'lib/bixby/provision/dsl/base.rb', line 27

def tap(&block)
  self.instance_eval(&block)
end

#tempfile(close = false) ⇒ Tempfile

Create a temporary file

Parameters:

  • close (Boolean) (defaults to: false)

    If true, close the file handle before returning it (default: false)

Returns:

  • (Tempfile)


80
81
82
83
84
# File 'lib/bixby/provision/dsl/base.rb', line 80

def tempfile(close=false)
  t = Tempfile.new("bixby-provision-")
  t.close if close
  t
end