Class: Fog::Identity::OpenStack::V2::User

Inherits:
Model
  • Object
show all
Defined in:
lib/fog/openstack/models/identity_v2/user.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(attributes) ⇒ User

Returns a new instance of User.



18
19
20
21
22
# File 'lib/fog/openstack/models/identity_v2/user.rb', line 18

def initialize(attributes)
  # Old 'connection' is renamed as service and should be used instead
  prepare_service_value(attributes)
  super
end

Instance Attribute Details

#emailObject

Returns the value of attribute email.



16
17
18
# File 'lib/fog/openstack/models/identity_v2/user.rb', line 16

def email
  @email
end

#enabledObject

Returns the value of attribute enabled.



16
17
18
# File 'lib/fog/openstack/models/identity_v2/user.rb', line 16

def enabled
  @enabled
end

#nameObject

Returns the value of attribute name.



16
17
18
# File 'lib/fog/openstack/models/identity_v2/user.rb', line 16

def name
  @name
end

#passwordObject

Returns the value of attribute password.



16
17
18
# File 'lib/fog/openstack/models/identity_v2/user.rb', line 16

def password
  @password
end

#tenant_idObject

Returns the value of attribute tenant_id.



16
17
18
# File 'lib/fog/openstack/models/identity_v2/user.rb', line 16

def tenant_id
  @tenant_id
end

Instance Method Details

#destroyObject



58
59
60
61
62
# File 'lib/fog/openstack/models/identity_v2/user.rb', line 58

def destroy
  requires :id
  service.delete_user(id)
  true
end

#ec2_credentialsObject



24
25
26
27
# File 'lib/fog/openstack/models/identity_v2/user.rb', line 24

def ec2_credentials
  requires :id
  service.ec2_credentials(:user => self)
end

#roles(tenant_id = self.tenant_id) ⇒ Object



64
65
66
# File 'lib/fog/openstack/models/identity_v2/user.rb', line 64

def roles(tenant_id = self.tenant_id)
  service.list_roles_for_user_on_tenant(tenant_id, self.id).body['roles']
end

#saveObject

Raises:

  • (Fog::Errors::Error)


29
30
31
32
33
34
35
36
# File 'lib/fog/openstack/models/identity_v2/user.rb', line 29

def save
  raise Fog::Errors::Error.new('Resaving an existing object may create a duplicate') if persisted?
  requires :name, :tenant_id, :password
  enabled = true if enabled.nil?
  data = service.create_user(name, password, email, tenant_id, enabled)
  merge_attributes(data.body['user'])
  true
end

#update(options = {}) ⇒ Object



38
39
40
41
42
43
# File 'lib/fog/openstack/models/identity_v2/user.rb', line 38

def update(options = {})
  requires :id
  options.merge('id' => id)
  response = service.update_user(id, options)
  true
end

#update_enabled(enabled) ⇒ Object



54
55
56
# File 'lib/fog/openstack/models/identity_v2/user.rb', line 54

def update_enabled(enabled)
  update({:enabled => enabled, 'url' => "/users/#{id}/OS-KSADM/enabled"})
end

#update_password(password) ⇒ Object



45
46
47
# File 'lib/fog/openstack/models/identity_v2/user.rb', line 45

def update_password(password)
  update({'password' => password, 'url' => "/users/#{id}/OS-KSADM/password"})
end

#update_tenant(tenant) ⇒ Object



49
50
51
52
# File 'lib/fog/openstack/models/identity_v2/user.rb', line 49

def update_tenant(tenant)
  tenant = tenant.id if tenant.class != String
  update({:tenantId => tenant, 'url' => "/users/#{id}/OS-KSADM/tenant"})
end