Class: Squall::User

Inherits:
Base
  • Object
show all
Defined in:
lib/squall/user.rb

Overview

OnApp User

Instance Attribute Summary

Attributes inherited from Base

#result, #success

Instance Method Summary (collapse)

Methods inherited from Base

#check_config, #default_params, #key_for_class, #request

Instance Method Details

- (Object) activate(id) Also known as: unsuspend

Activate a user.

Parameters:

  • id

    ID of user

Returns:

  • Return a Hash.



97
98
99
100
# File 'lib/squall/user.rb', line 97

def activate(id)
  response = request(:get, "/users/#{id}/activate_user.json")
  response["user"]
end

- (Object) create(options = {})

Create a new User

Examples:

create login:                 'bob',
       email:                 'something@example.com',
       password:              'secret',
       password_confirmation: 'secret'
       first_name:            'Bob',
       last_name:             'Smith'

Parameters:

  • options (defaults to: {})

    Params for creating the User:

Options Hash (options):

  • :login (Object)

    Login name

  • :email (Object)

    Email address

  • :first_name (Object)

    First name

  • :last_name (Object)

    Last name

  • :password (Object)

    Password

  • :passwor_confirmation (Object)

    Password

  • :role (Object)

    Role to be assigned to user

  • :time_zone (Object)

    Time zone for user. If not provided it will be set automatically.

  • :locale (Object)

    Locale for user. If not provided it will be set automatically.

  • :status (Object)

    User's status: `active`, `suspended`, `deleted`

  • :billing_plan_id (Object)

    ID of billing plan to be applied to user's account

  • :role_ids (Object)

    Array of IDs of roles to be assigned to the user

  • :suspend_after_hours (Object)

    Number of hours after which the account will be automatically suspended

  • :suspend_at (Object)

    Time after which the account will automatically be suspended, formatted

Returns:

  • a Hash.



48
49
50
# File 'lib/squall/user.rb', line 48

def create(options = {})
  request(:post, '/users.json', default_params(options))
end

- (Object) data_store_zones(id)

List data store zones associated with user.

Parameters:

  • id

    ID of user

Returns:

  • Return a Hash.



159
160
161
162
# File 'lib/squall/user.rb', line 159

def data_store_zones(id)
  response = request(:get, "/users/#{id}/data_store_zones.json")
  response.collect { |vm| vm['data-store-group']}
end

- (Object) delete(id)

Note:

this does not delete remove a user from the database. First, their status will be set to “Deleted.” If you call this method again, the user will be completely removed.

Delete a user.

Parameters:

  • id

    ID of user

Returns:

  • Return a Hash.



112
113
114
# File 'lib/squall/user.rb', line 112

def delete(id)
  request(:delete, "/users/#{id}.json")
end

- (Object) edit(id, options = {})

Edit a user

Parameters:

  • id

    ID of user

  • options (defaults to: {})

    Params for creating the user, see `#create`

Returns:

  • a Hash.



58
59
60
# File 'lib/squall/user.rb', line 58

def edit(id, options = {})
  request(:put, "/users/#{id}.json", default_params(options))
end

- (Object) generate_api_key(id)

Create a new API Key for a user.

Parameters:

  • id

    ID of user

Returns:

  • Return a Hash.



77
78
79
80
# File 'lib/squall/user.rb', line 77

def generate_api_key(id)
  response = request(:post, "/users/#{id}/make_new_api_key.json")
  response["user"]
end

- (Object) hypervisors(id)

List Hypervisors for a User's VirtualMachines.

Parameters:

  • id

    ID of user

Returns:

  • Return a Hash.



149
150
151
152
# File 'lib/squall/user.rb', line 149

def hypervisors(id)
  response = request(:get, "/users/#{id}/hypervisors.json")
  response.collect { |vm| vm['hypervisor']}
end

- (Object) limits(id)

Show resources available to a user for creating a virtual machine.

Parameters:

  • id

    ID of user

Returns:

  • a Hash.



179
180
181
182
# File 'lib/squall/user.rb', line 179

def limits(id)
  response = request(:get, "/users/#{id}/limits.json")
  response["limits"]
end

- (Object) list

Lists all users.

Returns:

  • an Array.



7
8
9
10
# File 'lib/squall/user.rb', line 7

def list
  response = request(:get, '/users.json')
  response.collect { |user| user['user'] }
end

- (Object) monthly_bills(id)

List a User's bills.

Parameters:

  • id

    ID of user

Returns:

  • Return a Hash.



130
131
132
# File 'lib/squall/user.rb', line 130

def monthly_bills(id)
  request(:get, "/users/#{id}/monthly_bills.json")
end

- (Object) network_zones(id)

List network zones associated with user.

Parameters:

  • id

    ID of user

Returns:

  • Return a Hash.



169
170
171
172
# File 'lib/squall/user.rb', line 169

def network_zones(id)
  response = request(:get, "/users/#{id}/network_zones.json")
  response.collect { |vm| vm['network_group']}
end

- (Object) show(id)

Get info for a user.

Parameters:

  • id

    ID of user

Returns:

  • a Hash.



67
68
69
70
# File 'lib/squall/user.rb', line 67

def show(id)
  response = request(:get, "/users/#{id}.json")
  response["user"]
end

- (Object) stats(id)

Get the stats for each of a User's VirtualMachines

Parameters:

  • id

    ID of user

Returns:

  • Return a Hash.



121
122
123
# File 'lib/squall/user.rb', line 121

def stats(id)
  request(:get, "/users/#{id}/vm_stats.json")
end

- (Object) suspend(id)

Suspend a user.

Parameters:

  • id

    ID of user

Returns:

  • Return a Hash.



87
88
89
90
# File 'lib/squall/user.rb', line 87

def suspend(id)
  response = request(:get, "/users/#{id}/suspend.json")
  response["user"]
end

- (Object) virtual_machines(id)

List User's VirtualMachines.

Parameters:

  • id

    ID of user

Returns:

  • Return a Hash.



139
140
141
142
# File 'lib/squall/user.rb', line 139

def virtual_machines(id)
  response = request(:get, "/users/#{id}/virtual_machines.json")
  response.collect { |vm| vm['virtual_machine']}
end