squall 1.0.2 → 1.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +3 -0
- data/.rbenv-version +1 -0
- data/.rspec +1 -1
- data/.rvmrc +41 -1
- data/.travis.yml +13 -3
- data/README.md +122 -27
- data/Rakefile +5 -34
- data/lib/squall/data_store_zone.rb +58 -0
- data/lib/squall/firewall_rule.rb +66 -0
- data/lib/squall/hypervisor.rb +63 -11
- data/lib/squall/hypervisor_zone.rb +135 -0
- data/lib/squall/ip_address.rb +50 -3
- data/lib/squall/ip_address_join.rb +46 -0
- data/lib/squall/network.rb +21 -4
- data/lib/squall/network_zone.rb +73 -0
- data/lib/squall/payment.rb +59 -0
- data/lib/squall/role.rb +28 -11
- data/lib/squall/statistic.rb +3 -3
- data/lib/squall/{base.rb → support/base.rb} +8 -4
- data/lib/squall/{config.rb → support/config.rb} +4 -0
- data/lib/squall/{exception.rb → support/exception.rb} +0 -0
- data/lib/squall/{params.rb → support/params.rb} +0 -0
- data/lib/squall/support/version.rb +3 -0
- data/lib/squall/support/yaml.rb +5 -0
- data/lib/squall/template.rb +4 -0
- data/lib/squall/transaction.rb +4 -0
- data/lib/squall/user.rb +126 -30
- data/lib/squall/user_group.rb +56 -0
- data/lib/squall/virtual_machine.rb +176 -52
- data/lib/squall/whitelist.rb +74 -0
- data/lib/squall.rb +21 -12
- data/spec/spec_helper.rb +21 -16
- data/spec/squall/data_store_zone_spec.rb +97 -0
- data/spec/squall/firewall_rule_spec.rb +112 -0
- data/spec/squall/hypervisor_spec.rb +101 -48
- data/spec/squall/hypervisor_zone_spec.rb +190 -0
- data/spec/squall/ip_address_join_spec.rb +67 -0
- data/spec/squall/ip_address_spec.rb +68 -6
- data/spec/squall/network_spec.rb +0 -1
- data/spec/squall/network_zone_spec.rb +147 -0
- data/spec/squall/payment_spec.rb +98 -0
- data/spec/squall/role_spec.rb +31 -46
- data/spec/squall/statistic_spec.rb +7 -9
- data/spec/squall/{base_spec.rb → support/base_spec.rb} +5 -7
- data/spec/squall/{config_spec.rb → support/config_spec.rb} +0 -0
- data/spec/{params_spec.rb → squall/support/params_spec.rb} +0 -0
- data/spec/squall/template_spec.rb +0 -1
- data/spec/squall/transaction_spec.rb +0 -1
- data/spec/squall/user_group_spec.rb +74 -0
- data/spec/squall/user_spec.rb +142 -59
- data/spec/squall/virtual_machine_spec.rb +179 -67
- data/spec/squall/whitelist_spec.rb +113 -0
- data/spec/squall_spec.rb +4 -8
- data/spec/vcr_cassettes/data_store_zone/create.yml +40 -0
- data/spec/vcr_cassettes/data_store_zone/delete.yml +77 -0
- data/spec/vcr_cassettes/data_store_zone/edit.yml +77 -0
- data/spec/vcr_cassettes/data_store_zone/list.yml +40 -0
- data/spec/vcr_cassettes/data_store_zone/show.yml +77 -0
- data/spec/vcr_cassettes/firewall_rule/create.yml +75 -0
- data/spec/vcr_cassettes/firewall_rule/delete.yml +75 -0
- data/spec/vcr_cassettes/firewall_rule/edit.yml +75 -0
- data/spec/vcr_cassettes/firewall_rule/list.yml +40 -0
- data/spec/vcr_cassettes/hypervisor/add_data_store_join.yml +40 -0
- data/spec/vcr_cassettes/hypervisor/add_network_join.yml +40 -0
- data/spec/vcr_cassettes/hypervisor/create.yml +7 -44
- data/spec/vcr_cassettes/hypervisor/data_store_joins.yml +40 -0
- data/spec/vcr_cassettes/hypervisor/delete.yml +11 -11
- data/spec/vcr_cassettes/hypervisor/edit.yml +7 -46
- data/spec/vcr_cassettes/hypervisor/list.yml +7 -7
- data/spec/vcr_cassettes/hypervisor/network_joins.yml +40 -0
- data/spec/vcr_cassettes/hypervisor/reboot.yml +13 -13
- data/spec/vcr_cassettes/hypervisor/remove_data_store_join.yml +40 -0
- data/spec/vcr_cassettes/hypervisor/remove_network_join.yml +40 -0
- data/spec/vcr_cassettes/hypervisor/show.yml +13 -13
- data/spec/vcr_cassettes/hypervisor_zones/add_data_store_join.yml +40 -0
- data/spec/vcr_cassettes/hypervisor_zones/add_network_join.yml +40 -0
- data/spec/vcr_cassettes/hypervisor_zones/create.yml +40 -0
- data/spec/vcr_cassettes/hypervisor_zones/data_store_joins.yml +40 -0
- data/spec/vcr_cassettes/hypervisor_zones/delete.yml +77 -0
- data/spec/vcr_cassettes/hypervisor_zones/edit.yml +77 -0
- data/spec/vcr_cassettes/hypervisor_zones/hypervisors.yml +40 -0
- data/spec/vcr_cassettes/hypervisor_zones/list.yml +40 -0
- data/spec/vcr_cassettes/hypervisor_zones/network_joins.yml +40 -0
- data/spec/vcr_cassettes/hypervisor_zones/remove_data_store_join.yml +40 -0
- data/spec/vcr_cassettes/hypervisor_zones/remove_network_join.yml +40 -0
- data/spec/vcr_cassettes/hypervisor_zones/show.yml +77 -0
- data/spec/vcr_cassettes/ipaddress/create.yml +40 -0
- data/spec/vcr_cassettes/ipaddress/delete.yml +40 -0
- data/spec/vcr_cassettes/ipaddress/edit.yml +40 -0
- data/spec/vcr_cassettes/ipaddress/list.yml +17 -17
- data/spec/vcr_cassettes/ipaddress_join/assign.yml +77 -0
- data/spec/vcr_cassettes/ipaddress_join/delete.yml +77 -0
- data/spec/vcr_cassettes/ipaddress_join/list.yml +77 -0
- data/spec/vcr_cassettes/network/create.yml +15 -15
- data/spec/vcr_cassettes/network/delete.yml +6 -6
- data/spec/vcr_cassettes/network/edit.yml +18 -18
- data/spec/vcr_cassettes/network/list.yml +3 -3
- data/spec/vcr_cassettes/network_zones/attach.yml +114 -0
- data/spec/vcr_cassettes/network_zones/create.yml +40 -0
- data/spec/vcr_cassettes/network_zones/delete.yml +77 -0
- data/spec/vcr_cassettes/network_zones/detach.yml +114 -0
- data/spec/vcr_cassettes/network_zones/edit.yml +77 -0
- data/spec/vcr_cassettes/network_zones/list.yml +40 -0
- data/spec/vcr_cassettes/network_zones/show.yml +77 -0
- data/spec/vcr_cassettes/payment/create.yml +78 -0
- data/spec/vcr_cassettes/payment/delete.yml +77 -0
- data/spec/vcr_cassettes/payment/edit.yml +77 -0
- data/spec/vcr_cassettes/payment/list.yml +41 -0
- data/spec/vcr_cassettes/role/create.yml +7 -44
- data/spec/vcr_cassettes/role/delete.yml +6 -6
- data/spec/vcr_cassettes/role/edit.yml +13 -75
- data/spec/vcr_cassettes/role/list.yml +7 -7
- data/spec/vcr_cassettes/role/permissions.yml +7 -7
- data/spec/vcr_cassettes/role/show.yml +13 -13
- data/spec/vcr_cassettes/statistic/usage_statistics.yml +7 -7
- data/spec/vcr_cassettes/template/list.yml +3 -3
- data/spec/vcr_cassettes/template/make_public.yml +6 -6
- data/spec/vcr_cassettes/transaction/list.yml +3 -3
- data/spec/vcr_cassettes/transaction/show.yml +6 -6
- data/spec/vcr_cassettes/user/activate.yml +7 -7
- data/spec/vcr_cassettes/user/create.yml +7 -83
- data/spec/vcr_cassettes/user/data_store_zones.yml +79 -0
- data/spec/vcr_cassettes/user/delete.yml +11 -11
- data/spec/vcr_cassettes/user/edit.yml +40 -0
- data/spec/vcr_cassettes/user/edit_role.yml +9 -9
- data/spec/vcr_cassettes/user/generate_api_key.yml +7 -7
- data/spec/vcr_cassettes/user/hypervisors.yml +77 -0
- data/spec/vcr_cassettes/user/limits.yml +77 -0
- data/spec/vcr_cassettes/user/list.yml +8 -8
- data/spec/vcr_cassettes/user/monthly_bills.yml +40 -0
- data/spec/vcr_cassettes/user/network_zones.yml +79 -0
- data/spec/vcr_cassettes/user/show.yml +29 -29
- data/spec/vcr_cassettes/user/stats.yml +6 -6
- data/spec/vcr_cassettes/user/suspend.yml +7 -7
- data/spec/vcr_cassettes/user/virtual_machines.yml +18 -20
- data/spec/vcr_cassettes/user_group/create.yml +40 -0
- data/spec/vcr_cassettes/user_group/delete.yml +77 -0
- data/spec/vcr_cassettes/user_group/edit.yml +77 -0
- data/spec/vcr_cassettes/user_group/list.yml +40 -0
- data/spec/vcr_cassettes/virtual_machine/build.yml +7 -7
- data/spec/vcr_cassettes/virtual_machine/change_owner.yml +8 -8
- data/spec/vcr_cassettes/virtual_machine/change_password.yml +13 -13
- data/spec/vcr_cassettes/virtual_machine/console.yml +63 -0
- data/spec/vcr_cassettes/virtual_machine/create.yml +9 -11
- data/spec/vcr_cassettes/virtual_machine/delete.yml +11 -11
- data/spec/vcr_cassettes/virtual_machine/edit.yml +16 -18
- data/spec/vcr_cassettes/virtual_machine/list.yml +3 -3
- data/spec/vcr_cassettes/virtual_machine/migrate.yml +22 -24
- data/spec/vcr_cassettes/virtual_machine/reboot.yml +22 -22
- data/spec/vcr_cassettes/virtual_machine/resize.yml +13 -13
- data/spec/vcr_cassettes/virtual_machine/segregate.yml +114 -0
- data/spec/vcr_cassettes/virtual_machine/set_ssh_keys.yml +77 -0
- data/spec/vcr_cassettes/virtual_machine/set_vip.yml +77 -0
- data/spec/vcr_cassettes/virtual_machine/show.yml +6 -6
- data/spec/vcr_cassettes/virtual_machine/shutdown.yml +6 -6
- data/spec/vcr_cassettes/virtual_machine/startup.yml +6 -6
- data/spec/vcr_cassettes/virtual_machine/stats.yml +63 -0
- data/spec/vcr_cassettes/virtual_machine/stop.yml +22 -22
- data/spec/vcr_cassettes/virtual_machine/suspend.yml +13 -13
- data/spec/vcr_cassettes/virtual_machine/unlock.yml +13 -13
- data/spec/vcr_cassettes/virtual_machine/unsuspend.yml +6 -6
- data/spec/vcr_cassettes/whitelist/create.yml +77 -0
- data/spec/vcr_cassettes/whitelist/delete.yml +77 -0
- data/spec/vcr_cassettes/whitelist/edit.yml +77 -0
- data/spec/vcr_cassettes/whitelist/list.yml +40 -0
- data/spec/vcr_cassettes/whitelist/show.yml +77 -0
- data/squall.gemspec +3 -2
- metadata +247 -131
- data/Gemfile.lock +0 -100
- data/lib/squall/version.rb +0 -3
data/lib/squall/user.rb
CHANGED
@@ -4,84 +4,180 @@ module Squall
|
|
4
4
|
# Return a list of all users
|
5
5
|
def list
|
6
6
|
response = request(:get, '/users.json')
|
7
|
-
response.collect { |user| user['user']}
|
7
|
+
response.collect { |user| user['user'] }
|
8
8
|
end
|
9
9
|
|
10
10
|
|
11
11
|
# Create a new User
|
12
12
|
#
|
13
|
-
# ====
|
13
|
+
# ==== Params
|
14
14
|
#
|
15
15
|
# * +options+ - Params for creating the User
|
16
16
|
#
|
17
|
+
# ==== Options
|
18
|
+
#
|
19
|
+
# * +login*+ - Login name
|
20
|
+
# * +email*+ - Email address
|
21
|
+
# * +first_name*+ - First name
|
22
|
+
# * +last_name*+ - Last name
|
23
|
+
# * +password*+ - Password
|
24
|
+
# * +passwor_confirmation*+ - Password
|
25
|
+
# * +role+ - Role to be assigned to user
|
26
|
+
# * +time_zone+ - Time zone for user. If not provided it will be set automatically.
|
27
|
+
# * +locale+ - Locale for user. If not provided it will be set automatically.
|
28
|
+
# * +status+ - User's status: +active+, +suspended+, +deleted+
|
29
|
+
# * +billing_plan_id+ - ID of billing plan to be applied to user's account
|
30
|
+
# * +role_ids+ - Array of IDs of roles to be assigned to the user
|
31
|
+
# * +suspend_after_hours+ - Number of hours after which the account will be automatically suspended
|
32
|
+
# * +suspend_at+ - Time after which the account will automatically be suspended, formatted as +YYYYMMDD ThhmmssZ+
|
33
|
+
#
|
17
34
|
# ==== Example
|
18
35
|
#
|
19
|
-
# create :login
|
20
|
-
# :email
|
21
|
-
# :password
|
22
|
-
# :
|
23
|
-
# :
|
24
|
-
# :
|
36
|
+
# create :login => 'bob',
|
37
|
+
# :email => 'something@example.com',
|
38
|
+
# :password => 'secret',
|
39
|
+
# :password_confirmation => 'secret'
|
40
|
+
# :first_name => 'Bob',
|
41
|
+
# :last_name => 'Smith'
|
25
42
|
def create(options = {})
|
26
|
-
params.required(:login, :email, :password).accepts(:
|
43
|
+
params.required(:login, :email,:first_name, :last_name, :password, :password_confirmation).accepts(:role, :time_zone, :locale, :status, :billing_plan_id, :role_ids, :suspend_after_hours, :suspend_at).validate!(options)
|
27
44
|
request(:post, '/users.json', default_params(options))
|
28
45
|
end
|
29
46
|
|
30
|
-
#
|
47
|
+
# Edit a user
|
48
|
+
#
|
49
|
+
# ==== Params
|
50
|
+
#
|
51
|
+
# * +id*+ - ID of user
|
52
|
+
# * +options+ - Params for creating the user
|
53
|
+
#
|
54
|
+
# ==== Options
|
55
|
+
#
|
56
|
+
# See #create
|
57
|
+
def edit(id, options={})
|
58
|
+
params.accepts(:email, :password, :password_confirmation, :first_name, :last_name, :user_group_id, :billing_plan_id, :role_ids, :suspend_at).validate!(options)
|
59
|
+
request(:put, "/users/#{id}.json", default_params(options))
|
60
|
+
end
|
61
|
+
|
62
|
+
# Return a Hash of the given user
|
63
|
+
#
|
64
|
+
# ==== Params
|
65
|
+
#
|
66
|
+
# * +id*+ - ID of user
|
31
67
|
def show(id)
|
32
68
|
response = request(:get, "/users/#{id}.json")
|
33
|
-
response
|
69
|
+
response["user"]
|
34
70
|
end
|
35
71
|
|
36
|
-
# Create a new API Key for a
|
72
|
+
# Create a new API Key for a user
|
73
|
+
#
|
74
|
+
# ==== Params
|
75
|
+
#
|
76
|
+
# * +id*+ - ID of user
|
37
77
|
def generate_api_key(id)
|
38
|
-
request(:post, "/users/#{id}/make_new_api_key.json")
|
78
|
+
response = request(:post, "/users/#{id}/make_new_api_key.json")
|
79
|
+
response["user"]
|
39
80
|
end
|
40
81
|
|
41
|
-
# Suspend a
|
82
|
+
# Suspend a user
|
83
|
+
#
|
84
|
+
# ==== Params
|
85
|
+
#
|
86
|
+
# * +id*+ - ID of user
|
42
87
|
def suspend(id)
|
43
88
|
response = request(:get, "/users/#{id}/suspend.json")
|
44
|
-
response
|
89
|
+
response["user"]
|
45
90
|
end
|
46
91
|
|
47
92
|
# Activate a user
|
93
|
+
#
|
94
|
+
# ==== Params
|
95
|
+
#
|
96
|
+
# * +id*+ - ID of user
|
48
97
|
def activate(id)
|
49
98
|
response = request(:get, "/users/#{id}/activate_user.json")
|
50
|
-
response
|
99
|
+
response["user"]
|
51
100
|
end
|
52
101
|
alias_method :unsuspend, :activate
|
53
102
|
|
54
103
|
# Delete a user
|
104
|
+
#
|
105
|
+
# ==== Params
|
106
|
+
#
|
107
|
+
# * +id*+ - ID of user
|
108
|
+
#
|
109
|
+
# 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.
|
55
110
|
def delete(id)
|
56
|
-
|
57
|
-
success
|
111
|
+
request(:delete, "/users/#{id}.json")
|
58
112
|
end
|
59
113
|
|
60
|
-
# Get the stats for a User
|
114
|
+
# Get the stats for each of a User's VirtualMachines
|
115
|
+
#
|
116
|
+
# ==== Params
|
117
|
+
#
|
118
|
+
# * +id*+ - ID of user
|
61
119
|
def stats(id)
|
62
|
-
|
63
|
-
|
120
|
+
request(:get, "/users/#{id}/vm_stats.json")
|
121
|
+
end
|
122
|
+
|
123
|
+
# Get a list of bills for the User
|
124
|
+
#
|
125
|
+
# ==== Params
|
126
|
+
#
|
127
|
+
# * +id*+ - ID of user
|
128
|
+
def monthly_bills(id)
|
129
|
+
response = request(:get, "/users/#{id}/monthly_bills.json")
|
64
130
|
end
|
65
131
|
|
66
132
|
# Return a list of VirtualMachines for a User
|
133
|
+
#
|
134
|
+
# ==== Params
|
135
|
+
#
|
136
|
+
# * +id*+ - ID of user
|
67
137
|
def virtual_machines(id)
|
68
138
|
response = request(:get, "/users/#{id}/virtual_machines.json")
|
69
139
|
response.collect { |vm| vm['virtual_machine']}
|
70
140
|
end
|
71
141
|
|
72
|
-
#
|
142
|
+
# Return a list of Hypervisors for a User's VirtualMachines
|
73
143
|
#
|
74
|
-
# ====
|
144
|
+
# ==== Params
|
75
145
|
#
|
76
|
-
# * +id
|
77
|
-
|
146
|
+
# * +id*+ - ID of user
|
147
|
+
def hypervisors(id)
|
148
|
+
response = request(:get, "/users/#{id}/hypervisors.json")
|
149
|
+
response.collect { |vm| vm['hypervisor']}
|
150
|
+
end
|
151
|
+
|
152
|
+
# Return a list of data store zones associated with user
|
78
153
|
#
|
79
|
-
# ====
|
154
|
+
# ==== Params
|
155
|
+
#
|
156
|
+
# * +id*+ - ID of user
|
157
|
+
def data_store_zones(id)
|
158
|
+
response = request(:get, "/users/#{id}/data_store_zones.json")
|
159
|
+
response.collect { |vm| vm['data-store-group']}
|
160
|
+
end
|
161
|
+
|
162
|
+
# Return a list of network zones associated with user
|
163
|
+
#
|
164
|
+
# ==== Params
|
80
165
|
#
|
81
|
-
#
|
82
|
-
|
83
|
-
|
84
|
-
|
166
|
+
# * +id*+ - ID of user
|
167
|
+
def network_zones(id)
|
168
|
+
response = request(:get, "/users/#{id}/network_zones.json")
|
169
|
+
response.collect { |vm| vm['network_group']}
|
85
170
|
end
|
171
|
+
|
172
|
+
# Return a description of resources available to a user for creating a virtual machine
|
173
|
+
#
|
174
|
+
# ==== Params
|
175
|
+
#
|
176
|
+
# * +id*+ - ID of user
|
177
|
+
def limits(id)
|
178
|
+
response = request(:get, "/users/#{id}/limits.json")
|
179
|
+
response["limits"]
|
180
|
+
end
|
181
|
+
|
86
182
|
end
|
87
183
|
end
|
@@ -0,0 +1,56 @@
|
|
1
|
+
module Squall
|
2
|
+
# OnApp UserGroup
|
3
|
+
class UserGroup < Base
|
4
|
+
|
5
|
+
# Return a list of all user groups
|
6
|
+
def list
|
7
|
+
response = request(:get, "/user_groups.json")
|
8
|
+
response.collect { |user_group| user_group['user_group'] }
|
9
|
+
end
|
10
|
+
|
11
|
+
# Create a user group
|
12
|
+
#
|
13
|
+
# ==== Params
|
14
|
+
#
|
15
|
+
# * +options+ - Params for creating the user groups
|
16
|
+
#
|
17
|
+
# ==== Options
|
18
|
+
#
|
19
|
+
# * +label*+ - Label for the user group
|
20
|
+
#
|
21
|
+
# ==== Example
|
22
|
+
#
|
23
|
+
# create :label => "My new user group"
|
24
|
+
def create(options={})
|
25
|
+
params.required(:label).validate!(options)
|
26
|
+
request(:post, "/user_groups.json", default_params(options))
|
27
|
+
end
|
28
|
+
|
29
|
+
# Edit a user group
|
30
|
+
#
|
31
|
+
# ==== Params
|
32
|
+
#
|
33
|
+
# * +id*+ - ID of the user group
|
34
|
+
# * +options+ - Params for creating the user groups
|
35
|
+
#
|
36
|
+
# ==== Options
|
37
|
+
#
|
38
|
+
# See #create
|
39
|
+
#
|
40
|
+
# * +options+ - Params for editing the user group.
|
41
|
+
def edit(id, options={})
|
42
|
+
params.accepts(:label).validate!(options)
|
43
|
+
request(:put, "/user_groups/#{id}.json", default_params(options))
|
44
|
+
end
|
45
|
+
|
46
|
+
# Delete a user group
|
47
|
+
#
|
48
|
+
# ==== Params
|
49
|
+
#
|
50
|
+
# * +id*+ - ID of the user group
|
51
|
+
def delete(id)
|
52
|
+
request(:delete, "/user_groups/#{id}.json")
|
53
|
+
end
|
54
|
+
|
55
|
+
end
|
56
|
+
end
|
@@ -1,40 +1,66 @@
|
|
1
1
|
module Squall
|
2
2
|
# OnApp VirtualMachine
|
3
3
|
class VirtualMachine < Base
|
4
|
-
# Return a list of
|
4
|
+
# Return a list of virtual machines
|
5
5
|
def list
|
6
6
|
response = request(:get, '/virtual_machines.json')
|
7
7
|
response.collect { |v| v['virtual_machine'] }
|
8
8
|
end
|
9
9
|
|
10
|
-
# Return a Hash for the given
|
10
|
+
# Return a Hash for the given virtual machines
|
11
|
+
#
|
12
|
+
# ==== Params
|
13
|
+
#
|
14
|
+
# * +id*+ - ID of the virtual machine
|
11
15
|
def show(id)
|
12
16
|
response = request(:get, "/virtual_machines/#{id}.json")
|
13
17
|
response.first[1]
|
14
18
|
end
|
15
19
|
|
16
|
-
# Create a new
|
20
|
+
# Create a new virtual machine
|
21
|
+
#
|
22
|
+
# ==== Params
|
23
|
+
#
|
24
|
+
# * +options+ - Params for creating the virtual machine
|
17
25
|
#
|
18
26
|
# ==== Options
|
19
27
|
#
|
20
|
-
# * +
|
28
|
+
# * +label*+ - Label for the virtual machine
|
29
|
+
# * +hostname*+ - Hostname for the virtual machine
|
30
|
+
# * +memory*+ - Amount of RAM assigned to this virtual machine
|
31
|
+
# * +cpus*+ - Number of CPUs assigned to the virtual machine
|
32
|
+
# * +cpu_shares*+ - CPU priority for this virtual machine
|
33
|
+
# * +primary_disk_size*+ - Disk space for this virtual machine
|
34
|
+
# * +template_id*+ - ID for a template from which the virtual machine will be built
|
35
|
+
# * +hypervisor_id+ - ID for a hypervisor where virtual machine will be built. If not provided the virtual machine will be assigned to the first available hypervisor
|
36
|
+
# * +swap_disk_size+ - Swap space (does not apply to Windows virtual machines)
|
37
|
+
# * +primary_network_id+ - ID of the primary network
|
38
|
+
# * +required_automatic_backup+ - Set to '1' if automatic backups are required
|
39
|
+
# * +rate_limit+ - Max port speed
|
40
|
+
# * +required_ip_address_assignment+ - Set to '1' if you wish to assign an IP address automatically
|
41
|
+
# * +required_virtual_machine_build+ - Set to '1' to build virtual machine automatically
|
42
|
+
# * +admin_note+ - Comment that can only be set by admin of virtual machine
|
43
|
+
# * +note+ - Comment that can be set by the user of the virtual machine
|
44
|
+
# * +allowed_hot_migrate+ - Set to '1' to allow hot migration
|
45
|
+
# * +initial_root_password+ - Root password for the virtual machine. 6-31 characters consisting of letters, numbers, '-' and '_'
|
21
46
|
#
|
22
47
|
# ==== Example
|
23
48
|
#
|
24
49
|
# params = {
|
25
|
-
# :label => 'testmachine',
|
50
|
+
# :label => 'testmachine',
|
26
51
|
# :hypervisor_id => 5,
|
27
|
-
# :hostname => 'testmachine',
|
28
|
-
# :memory => 512,
|
52
|
+
# :hostname => 'testmachine',
|
53
|
+
# :memory => 512,
|
29
54
|
# :cpus => 1,
|
30
|
-
# :cpu_shares => 10,
|
31
|
-
# :primary_disk_size => 10
|
55
|
+
# :cpu_shares => 10,
|
56
|
+
# :primary_disk_size => 10,
|
57
|
+
# :template_id => 1
|
32
58
|
# }
|
33
59
|
#
|
34
60
|
# create params
|
35
61
|
def create(options = {})
|
36
|
-
required = [:label, :
|
37
|
-
optional = [:
|
62
|
+
required = [:label, :hostname, :memory, :cpus, :cpu_shares, :primary_disk_size, :template_id]
|
63
|
+
optional = [:hypervisor_id,
|
38
64
|
:swap_disk_size,
|
39
65
|
:primary_network_id,
|
40
66
|
:required_automatic_backup,
|
@@ -44,7 +70,6 @@ module Squall
|
|
44
70
|
:admin_note,
|
45
71
|
:note,
|
46
72
|
:allowed_hot_migrate,
|
47
|
-
:template_id,
|
48
73
|
:initial_root_password
|
49
74
|
]
|
50
75
|
params.required(required).accepts(optional).validate! options
|
@@ -52,37 +77,33 @@ module Squall
|
|
52
77
|
response['virtual_machine']
|
53
78
|
end
|
54
79
|
|
55
|
-
# Build a
|
80
|
+
# Build a virtual machine
|
81
|
+
#
|
82
|
+
# ==== Params
|
83
|
+
#
|
84
|
+
# * +id*+ - ID of the virtual machine
|
85
|
+
# * +options+ - Params for creating the virtual machine
|
56
86
|
#
|
57
87
|
# ==== Options
|
58
88
|
#
|
59
|
-
# * +
|
60
|
-
# * +
|
89
|
+
# * +template_id*+ - ID of the template to be used to build the virtual machine
|
90
|
+
# * +required_startup+ - Set to '1' to startup virtual machine after building
|
61
91
|
def build(id, options = {})
|
62
|
-
params.
|
92
|
+
params.required(:template_id).accepts(:required_startup).validate! options
|
63
93
|
response = request(:post, "/virtual_machines/#{id}/build.json", default_params(options))
|
64
94
|
response.first[1]
|
65
95
|
end
|
66
96
|
|
67
|
-
# Edit a
|
97
|
+
# Edit a virtual machine
|
68
98
|
#
|
69
|
-
# ====
|
99
|
+
# ==== Params
|
70
100
|
#
|
71
|
-
# * +
|
101
|
+
# * +id*+ - ID of the virtual machine
|
102
|
+
# * +options+ - Params for creating the virtual machine
|
72
103
|
#
|
73
|
-
# ====
|
74
|
-
#
|
75
|
-
# params = {
|
76
|
-
# :label => 'testmachine',
|
77
|
-
# :hypervisor_id => 5,
|
78
|
-
# :hostname => 'testmachine',
|
79
|
-
# :memory => 512,
|
80
|
-
# :cpus => 1,
|
81
|
-
# :cpu_shares => 10,
|
82
|
-
# :primary_disk_size => 10
|
83
|
-
# }
|
104
|
+
# ==== Options
|
84
105
|
#
|
85
|
-
#
|
106
|
+
# See #create
|
86
107
|
def edit(id, options = {})
|
87
108
|
optional = [:label,
|
88
109
|
:hypervisor_id,
|
@@ -108,79 +129,182 @@ module Squall
|
|
108
129
|
request(:put, "/virtual_machines/#{id}.json", default_params(options))
|
109
130
|
end
|
110
131
|
|
111
|
-
# Change the owner of a
|
132
|
+
# Change the owner of a virtual machine
|
112
133
|
#
|
113
|
-
# ====
|
114
|
-
#
|
115
|
-
# * +
|
134
|
+
# ==== Params
|
135
|
+
#
|
136
|
+
# * +id*+ - ID of the virtual machine
|
137
|
+
# * +user_id*+ - ID of the target User
|
116
138
|
def change_owner(id, user_id)
|
117
139
|
response = request(:post, "/virtual_machines/#{id}/change_owner.json", :query => { :user_id => user_id })
|
118
140
|
response['virtual_machine']
|
119
141
|
end
|
120
142
|
|
121
143
|
# Change the password
|
144
|
+
#
|
145
|
+
# ==== Params
|
146
|
+
#
|
147
|
+
# * +id*+ - ID of the virtual machine
|
148
|
+
# * +password*+ - New password
|
122
149
|
def change_password(id, password)
|
123
150
|
response = request(:post, "/virtual_machines/#{id}/reset_password.json", :query => { :new_password => password })
|
124
151
|
response['virtual_machine']
|
125
152
|
end
|
126
153
|
|
127
|
-
#
|
154
|
+
# Assigns SSH keys of all administrators and a owner to a virtual machine
|
128
155
|
#
|
129
|
-
# ====
|
156
|
+
# ==== Params
|
157
|
+
#
|
158
|
+
# * +id*+ - ID of the virtual machine
|
159
|
+
def set_ssh_keys(id)
|
160
|
+
response = request(:post, "/virtual_machines/#{id}/set_ssh_keys.json")
|
161
|
+
response['virtual_machine']
|
162
|
+
end
|
163
|
+
|
164
|
+
# Migrate a virtual machine to a new hypervisor
|
165
|
+
#
|
166
|
+
# ==== Params
|
130
167
|
#
|
131
|
-
# * +id
|
168
|
+
# * +id*+ - ID of the virtual machine
|
132
169
|
# * +options+ - :destination, :cold_migrate_on_rollback
|
170
|
+
#
|
171
|
+
# ==== Options
|
172
|
+
#
|
173
|
+
# * +destination*+ - ID of a hypervisor to which to migrate the virtual machine
|
174
|
+
# * +cold_migrate_on_rollback+ - Set to '1' to switch to cold migration if migration fails
|
133
175
|
def migrate(id, options = {})
|
134
|
-
params.required(:destination).accepts(:cold_migrate_on_rollback).validate! options
|
135
|
-
response = request(:post, "/virtual_machines/#{id}/migrate.json", :query => options )
|
176
|
+
params.required(:destination).accepts(:cold_migrate_on_rollback).validate! options
|
177
|
+
response = request(:post, "/virtual_machines/#{id}/migrate.json", :query => {:virtual_machine => options} )
|
178
|
+
end
|
179
|
+
|
180
|
+
# Toggle the VIP status of the virtual machine
|
181
|
+
#
|
182
|
+
# ==== Params
|
183
|
+
#
|
184
|
+
# * +id*+ - ID of the virtual machine
|
185
|
+
def set_vip(id)
|
186
|
+
response = request(:post, "/virtual_machines/#{id}/set_vip.json")
|
187
|
+
response['virtual_machine']
|
136
188
|
end
|
137
189
|
|
138
|
-
# Delete a
|
190
|
+
# Delete a virtual machine
|
191
|
+
#
|
192
|
+
# ==== Params
|
193
|
+
#
|
194
|
+
# * +id*+ - ID of the virtual machine
|
139
195
|
def delete(id)
|
140
196
|
request(:delete, "/virtual_machines/#{id}.json")
|
141
197
|
end
|
142
198
|
|
143
|
-
# Resize a
|
199
|
+
# Resize a virtual machine's memory
|
200
|
+
#
|
201
|
+
# ==== Params
|
202
|
+
#
|
203
|
+
# * +id*+ - ID of the virtual machine
|
204
|
+
# * +options+ - Options for resizing
|
205
|
+
#
|
206
|
+
# * ==== Options
|
207
|
+
#
|
208
|
+
# * +memory*+ - Amount of RAM assigned to this virtual machine
|
209
|
+
# * +cpus*+ - Number of CPUs assigned to the virtual machine
|
210
|
+
# * +cpu_shares*+ - CPU priority for this virtual machine
|
211
|
+
# * +allow_cold_resize*+ - Set to '1' to allow cold resize
|
144
212
|
def resize(id, options = {})
|
145
|
-
|
213
|
+
raise ArgumentError, "You must specify at least one of the following attributes to resize: :memory, :cpus, :cpu_shares, :allow_cold_resize" if options.empty?
|
214
|
+
params.accepts(:memory, :cpus, :cpu_shares, :allow_cold_resize).validate! options
|
146
215
|
response = request(:post, "/virtual_machines/#{id}/resize.json", default_params(options))
|
147
216
|
response['virtual_machine']
|
148
217
|
end
|
149
218
|
|
150
|
-
# Suspend/Unsuspend a
|
219
|
+
# Suspend/Unsuspend a virtual machine
|
220
|
+
#
|
221
|
+
# ==== Params
|
222
|
+
#
|
223
|
+
# * +id*+ - ID of the virtual machine
|
151
224
|
def suspend(id)
|
152
225
|
response = request(:post, "/virtual_machines/#{id}/suspend.json")
|
153
226
|
response['virtual_machine']
|
154
227
|
end
|
155
|
-
alias_method :unsuspend, :suspend
|
156
228
|
|
157
|
-
# Unlock a
|
229
|
+
# Unlock a virtual machine
|
230
|
+
#
|
231
|
+
# ==== Params
|
232
|
+
#
|
233
|
+
# * +id*+ - ID of the virtual machine
|
158
234
|
def unlock(id)
|
159
235
|
response = request(:post, "/virtual_machines/#{id}/unlock.json")
|
160
236
|
response['virtual_machine']
|
161
237
|
end
|
162
238
|
|
163
|
-
# Boot a
|
239
|
+
# Boot a virtual machine
|
240
|
+
#
|
241
|
+
# ==== Params
|
242
|
+
#
|
243
|
+
# * +id*+ - ID of the virtual machine
|
164
244
|
def startup(id)
|
165
245
|
response = request(:post, "/virtual_machines/#{id}/startup.json")
|
166
246
|
response['virtual_machine']
|
167
247
|
end
|
168
248
|
|
169
|
-
# Shutdown a
|
249
|
+
# Shutdown a virtual machine
|
250
|
+
#
|
251
|
+
# ==== Params
|
252
|
+
#
|
253
|
+
# * +id*+ - ID of the virtual machine
|
170
254
|
def shutdown(id)
|
171
255
|
response = request(:post, "/virtual_machines/#{id}/shutdown.json")
|
172
256
|
response['virtual_machine']
|
173
257
|
end
|
174
258
|
|
175
|
-
# Stop a
|
259
|
+
# Stop a virtual machine
|
260
|
+
#
|
261
|
+
# ==== Params
|
262
|
+
#
|
263
|
+
# * +id*+ - ID of the virtual machine
|
176
264
|
def stop(id)
|
177
265
|
response = request(:post, "/virtual_machines/#{id}/stop.json")
|
178
266
|
response['virtual_machine']
|
179
267
|
end
|
180
268
|
|
181
|
-
# Reboot a
|
182
|
-
|
183
|
-
|
269
|
+
# Reboot a virtual machine
|
270
|
+
#
|
271
|
+
# ==== Params
|
272
|
+
#
|
273
|
+
# * +id*+ - ID of the virtual machine
|
274
|
+
# * +recovery+ - Set to true to reboot in recovery, defaults to false
|
275
|
+
def reboot(id, recovery=false)
|
276
|
+
response = request(:post, "/virtual_machines/#{id}/reboot.json", {:query => recovery ? {:mode => :recovery} : nil})
|
277
|
+
response['virtual_machine']
|
278
|
+
end
|
279
|
+
|
280
|
+
# Segregate a virtual machine from another virtual machine
|
281
|
+
#
|
282
|
+
# ==== Params
|
283
|
+
#
|
284
|
+
# * +id*+ - ID of the virtual machine
|
285
|
+
# * +target_vm_id+* - ID of another virtual machine from which it should be segregated
|
286
|
+
def segregate(id, target_vm_id)
|
287
|
+
response = request(:post, "/virtual_machines/#{id}/strict_vm.json", default_params(:strict_virtual_machine_id => target_vm_id))
|
288
|
+
response['virtual_machine']
|
289
|
+
end
|
290
|
+
|
291
|
+
# Open a console for a virtual machine
|
292
|
+
#
|
293
|
+
# ==== Params
|
294
|
+
#
|
295
|
+
# * +id*+ - ID of the virtual machine
|
296
|
+
def console(id)
|
297
|
+
response = request(:post, "/virtual_machines/#{id}/console.json")
|
298
|
+
response['virtual_machine']
|
299
|
+
end
|
300
|
+
|
301
|
+
# Get billing statistics for a virtual machine
|
302
|
+
#
|
303
|
+
# ==== Params
|
304
|
+
#
|
305
|
+
# * +id*+ - ID of the virtual machine
|
306
|
+
def stats(id)
|
307
|
+
response = request(:post, "/virtual_machines/#{id}/vm_stats.json")
|
184
308
|
response['virtual_machine']
|
185
309
|
end
|
186
310
|
end
|
@@ -0,0 +1,74 @@
|
|
1
|
+
module Squall
|
2
|
+
# OnApp Whitelist
|
3
|
+
class Whitelist < Base
|
4
|
+
|
5
|
+
# Return a list of all whitelists
|
6
|
+
#
|
7
|
+
# ==== Params
|
8
|
+
#
|
9
|
+
# * +user_id*+ - ID of the user to display whitelists for
|
10
|
+
def list(user_id)
|
11
|
+
response = request(:get, "/users/#{user_id}/user_white_lists.json")
|
12
|
+
response.collect { |user| user['user_white_list'] }
|
13
|
+
end
|
14
|
+
|
15
|
+
# Get the details for a whitelist
|
16
|
+
#
|
17
|
+
# ==== Params
|
18
|
+
#
|
19
|
+
# * +user_id*+ - ID of the user
|
20
|
+
# * +id*+ - ID of the whitelist
|
21
|
+
def show(user_id, id)
|
22
|
+
response = request(:get, "/users/#{user_id}/user_white_lists/#{id}.json")
|
23
|
+
response['user_white_list']
|
24
|
+
end
|
25
|
+
|
26
|
+
# Create a whitelist for a user
|
27
|
+
#
|
28
|
+
# ==== Params
|
29
|
+
#
|
30
|
+
# * +user_id*+ - ID of the user
|
31
|
+
# * +options+ - Params for creating the whitelist
|
32
|
+
#
|
33
|
+
# ==== Options
|
34
|
+
#
|
35
|
+
# * +ip*+ - IP to be whitelisted
|
36
|
+
# * +description+ - Description of the whitelist
|
37
|
+
#
|
38
|
+
# ==== Example
|
39
|
+
#
|
40
|
+
# create :ip => 192.168.1.1,
|
41
|
+
# :description => "Computer that someone I trust uses"
|
42
|
+
def create(user_id, options={})
|
43
|
+
params.required(:ip).accepts(:description).validate!(options)
|
44
|
+
request(:post, "/users/#{user_id}/user_white_lists.json", :query => {:user_white_list => options})
|
45
|
+
end
|
46
|
+
|
47
|
+
# Edit a whitelist
|
48
|
+
#
|
49
|
+
# ==== Params
|
50
|
+
#
|
51
|
+
# * +user_id*+ - ID of the user
|
52
|
+
# * +id*+ - ID of whitelist
|
53
|
+
# * +options+ - Params for editing the whitelist
|
54
|
+
#
|
55
|
+
# ==== Options
|
56
|
+
#
|
57
|
+
# See #create
|
58
|
+
def edit(user_id, id, options={})
|
59
|
+
params.accepts(:ip, :description).validate!(options)
|
60
|
+
request(:put, "/users/#{user_id}/user_white_lists/#{id}.json", :query => {:user_white_list => options})
|
61
|
+
end
|
62
|
+
|
63
|
+
# Delete a whitelist
|
64
|
+
#
|
65
|
+
# ==== Params
|
66
|
+
#
|
67
|
+
# * +user_id*+ - ID of the user
|
68
|
+
# * +id*+ - ID of whitelist
|
69
|
+
def delete(user_id, id)
|
70
|
+
request(:delete, "/users/#{user_id}/user_white_lists/#{id}.json")
|
71
|
+
end
|
72
|
+
|
73
|
+
end
|
74
|
+
end
|