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

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

Instance Attribute Summary collapse

Attributes inherited from Model

#collection, #connection

Instance Method Summary collapse

Methods inherited from Model

#inspect, #reload, #symbolize_keys, #to_json, #wait_for

Methods included from Attributes::ClassMethods

#_load, #aliases, #attribute, #attributes, #identity, #ignore_attributes, #ignored_attributes

Methods included from Attributes::InstanceMethods

#_dump, #attributes, #dup, #identity, #identity=, #merge_attributes, #new_record?, #requires, #requires_one

Constructor Details

#initialize(attributes) ⇒ User

Returns a new instance of User.



17
18
19
20
# File 'lib/fog/openstack/models/identity/user.rb', line 17

def initialize(attributes)
  @connection = attributes[:connection]
  super
end

Instance Attribute Details

#emailObject

Returns the value of attribute email.



15
16
17
# File 'lib/fog/openstack/models/identity/user.rb', line 15

def email
  @email
end

#enabledObject

Returns the value of attribute enabled.



15
16
17
# File 'lib/fog/openstack/models/identity/user.rb', line 15

def enabled
  @enabled
end

#nameObject

Returns the value of attribute name.



15
16
17
# File 'lib/fog/openstack/models/identity/user.rb', line 15

def name
  @name
end

#passwordObject

Returns the value of attribute password.



15
16
17
# File 'lib/fog/openstack/models/identity/user.rb', line 15

def password
  @password
end

#tenant_idObject

Returns the value of attribute tenant_id.



15
16
17
# File 'lib/fog/openstack/models/identity/user.rb', line 15

def tenant_id
  @tenant_id
end

Instance Method Details

#destroyObject



51
52
53
54
55
# File 'lib/fog/openstack/models/identity/user.rb', line 51

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

#roles(tenant_id = self.tenant_id) ⇒ Object



57
58
59
# File 'lib/fog/openstack/models/identity/user.rb', line 57

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

#saveObject

Raises:



22
23
24
25
26
27
28
29
# File 'lib/fog/openstack/models/identity/user.rb', line 22

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

#update(options = {}) ⇒ Object



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

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

#update_enabled(enabled) ⇒ Object



47
48
49
# File 'lib/fog/openstack/models/identity/user.rb', line 47

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

#update_password(password) ⇒ Object



38
39
40
# File 'lib/fog/openstack/models/identity/user.rb', line 38

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

#update_tenant(tenant) ⇒ Object



42
43
44
45
# File 'lib/fog/openstack/models/identity/user.rb', line 42

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