Class: Vagrant::Smartos::Zones::Util::ZoneUser

Inherits:
Object
  • Object
show all
Includes:
GlobalZone::Helper
Defined in:
lib/vagrant/smartos/zones/util/zone_user.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from GlobalZone::Helper

included, #sudo, #with_gz

Constructor Details

#initialize(machine, zone) ⇒ ZoneUser

Returns a new instance of ZoneUser.



14
15
16
17
# File 'lib/vagrant/smartos/zones/util/zone_user.rb', line 14

def initialize(machine, zone)
  @machine = machine
  @zone = zone
end

Instance Attribute Details

#machineObject (readonly)

Returns the value of attribute machine.



12
13
14
# File 'lib/vagrant/smartos/zones/util/zone_user.rb', line 12

def machine
  @machine
end

#zoneObject (readonly)

Returns the value of attribute zone.



12
13
14
# File 'lib/vagrant/smartos/zones/util/zone_user.rb', line 12

def zone
  @zone
end

Instance Method Details

#create(username, group, role = nil) ⇒ Object



32
33
34
35
36
37
# File 'lib/vagrant/smartos/zones/util/zone_user.rb', line 32

def create(username, group, role = nil)
  return if exists?(username)
  zone.zlogin("useradd #{flags(group)} #{username}")
  grant_role(username, role)
  install_public_key(group)
end

#exists?(username) ⇒ Boolean

Returns:

  • (Boolean)


28
29
30
# File 'lib/vagrant/smartos/zones/util/zone_user.rb', line 28

def exists?(username)
  machine.communicate.gz_test("#{sudo} zlogin #{zone.uuid} id -u #{username}")
end

#find(username) ⇒ Object



19
20
21
22
23
24
25
26
# File 'lib/vagrant/smartos/zones/util/zone_user.rb', line 19

def find(username)
  Models::ZoneUser.new.tap do |u|
    u.name = username
    with_gz("#{sudo} zlogin #{zone.uuid} id -u #{username}") do |output|
      u.uid = output.chomp if output
    end
  end
end