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/.gitignore
CHANGED
data/.rbenv-version
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
1.9.2-p290
|
data/.rspec
CHANGED
@@ -1,2 +1,2 @@
|
|
1
|
-
--format
|
1
|
+
--format p
|
2
2
|
--color
|
data/.rvmrc
CHANGED
@@ -1 +1,41 @@
|
|
1
|
-
|
1
|
+
#!/usr/bin/env bash
|
2
|
+
|
3
|
+
# This is an RVM Project .rvmrc file, used to automatically load the ruby
|
4
|
+
# development environment upon cd'ing into the directory
|
5
|
+
|
6
|
+
# First we specify our desired <ruby>[@<gemset>], the @gemset name is optional.
|
7
|
+
environment_id="ruby-1.8.7-p334@squall"
|
8
|
+
|
9
|
+
#
|
10
|
+
# First we attempt to load the desired environment directly from the environment
|
11
|
+
# file. This is very fast and efficicent compared to running through the entire
|
12
|
+
# CLI and selector. If you want feedback on which environment was used then
|
13
|
+
# insert the word 'use' after --create as this triggers verbose mode.
|
14
|
+
#
|
15
|
+
if [[ -d "${rvm_path:-$HOME/.rvm}/environments" \
|
16
|
+
&& -s "${rvm_path:-$HOME/.rvm}/environments/$environment_id" ]]
|
17
|
+
then
|
18
|
+
\. "${rvm_path:-$HOME/.rvm}/environments/$environment_id"
|
19
|
+
|
20
|
+
if [[ -s ".rvm/hooks/after_use" ]]
|
21
|
+
then
|
22
|
+
. ".rvm/hooks/after_use"
|
23
|
+
fi
|
24
|
+
else
|
25
|
+
# If the environment file has not yet been created, use the RVM CLI to select.
|
26
|
+
if ! rvm --create "$environment_id"
|
27
|
+
then
|
28
|
+
echo "Failed to create RVM environment ''."
|
29
|
+
fi
|
30
|
+
fi
|
31
|
+
|
32
|
+
#
|
33
|
+
# If you use an RVM gemset file to install a list of gems (*.gems), you can have
|
34
|
+
# it be automatically loaded. Uncomment the following and adjust the filename if
|
35
|
+
# necessary.
|
36
|
+
#
|
37
|
+
# filename=".gems"
|
38
|
+
# if [[ -s "$filename" ]] ; then
|
39
|
+
# rvm gemset import "$filename" | grep -v already | grep -v listed | grep -v complete | sed '/^$/d'
|
40
|
+
# fi
|
41
|
+
|
data/.travis.yml
CHANGED
@@ -1,7 +1,17 @@
|
|
1
|
-
|
1
|
+
language: ruby
|
2
|
+
script: "bundle exec rake spec"
|
3
|
+
notifications:
|
4
|
+
email:
|
5
|
+
recipients:
|
6
|
+
- engineering@internal.site5.com
|
7
|
+
on_success: never
|
8
|
+
on_failure: always
|
2
9
|
rvm:
|
3
10
|
- 1.8.7
|
4
11
|
- 1.9.2
|
12
|
+
- 1.9.3
|
5
13
|
- ree
|
6
|
-
- rbx
|
7
|
-
-
|
14
|
+
- rbx-head
|
15
|
+
- rbx-18mode
|
16
|
+
- jruby-18mode
|
17
|
+
- jruby-19mode
|
data/README.md
CHANGED
@@ -1,69 +1,164 @@
|
|
1
|
-
Squall
|
2
|
-
|
3
|
-
[![Build Status](http://travis-ci.org/site5/squall.png)](http://travis-ci.org/site5/squall)
|
1
|
+
Squall [![Squall Build Status][Build Icon]][Build Status]
|
2
|
+
=========================================================
|
4
3
|
|
4
|
+
A Ruby library for working with the [OnApp REST API][].
|
5
5
|
|
6
|
-
|
6
|
+
Squall has been tested on MRI 1.8.7, MRI 1.9.2, MRI 1.9.3 Preview 1,
|
7
|
+
Rubinius 2.0.0pre, and JRuby 1.6.2.
|
7
8
|
|
8
|
-
[RDoc]
|
9
|
+
Documentation is available in [RDoc][] format.
|
9
10
|
|
10
|
-
|
11
|
+
[Build Status]: http://travis-ci.org/site5/squall
|
12
|
+
[Build Icon]: https://secure.travis-ci.org/site5/squall.png?branch=master
|
13
|
+
[OnApp REST API]: https://help.onapp.com/manual.php?m=2
|
14
|
+
[RDoc]: http://rdoc.info/github/site5/squall/master/frames
|
11
15
|
|
12
16
|
Install
|
13
17
|
-------
|
14
18
|
|
15
19
|
gem install squall
|
20
|
+
bundle install
|
16
21
|
|
22
|
+
Configuration
|
23
|
+
-------------
|
17
24
|
|
18
|
-
|
19
|
-
-----
|
25
|
+
You have two main options for configuring Squall.
|
20
26
|
|
21
|
-
|
27
|
+
Directly in a config block:
|
22
28
|
|
23
29
|
require 'squall'
|
24
30
|
|
25
31
|
Squall.config do |c|
|
26
|
-
c.base_uri 'https://onappurl.com'
|
27
|
-
c.username 'username'
|
28
|
-
c.password 'topsecret'
|
32
|
+
c.base_uri 'https://onappurl.com' # Root level URI for OnApp instance
|
33
|
+
c.username 'username' # OnApp username
|
34
|
+
c.password 'topsecret' # OnApp password
|
35
|
+
c.debug true # Toggle HTTParty debugging (prints to $stderr)
|
29
36
|
end
|
30
37
|
|
31
|
-
|
38
|
+
Squall can load configuration from a yaml file:
|
39
|
+
|
40
|
+
# .squall.yml
|
41
|
+
base_uri: 'https://onappurl.com'
|
42
|
+
username: 'username'
|
43
|
+
password: 'topsecret'
|
44
|
+
debug: false
|
45
|
+
|
46
|
+
To load it (by default it assumes ~/.squall.yml):
|
47
|
+
|
48
|
+
Squall.config_file(/[path]/[to]/.squall.yml)
|
49
|
+
|
50
|
+
It is also possible to change individual configuration settings on the fly.
|
51
|
+
|
52
|
+
Squall.configuration.debug(true)
|
53
|
+
|
54
|
+
Note: you will need to re-instantiate all modules after changing Squall's configuration.
|
55
|
+
|
56
|
+
Usage
|
57
|
+
-----
|
58
|
+
|
59
|
+
Show the info for a VM:
|
32
60
|
|
33
61
|
vm = Squall::VirtualMachine.new
|
34
62
|
vm.show 1
|
35
63
|
|
36
|
-
|
37
|
-
Create a new VM
|
64
|
+
Create a new VM:
|
38
65
|
|
39
66
|
vm = Squall::VirtualMachine.new
|
40
67
|
|
41
68
|
params = {
|
42
|
-
:label
|
43
|
-
:hypervisor_id
|
44
|
-
:hostname
|
45
|
-
:memory
|
46
|
-
:cpus
|
47
|
-
:cpu_shares
|
48
|
-
:primary_disk_size => 10
|
69
|
+
:label => 'testmachine',
|
70
|
+
:hypervisor_id => 5,
|
71
|
+
:hostname => 'testmachine',
|
72
|
+
:memory => 512,
|
73
|
+
:cpus => 1,
|
74
|
+
:cpu_shares => 10,
|
75
|
+
:primary_disk_size => 10,
|
76
|
+
:template_id => 1
|
49
77
|
}
|
50
78
|
|
51
79
|
vm.create params
|
52
80
|
|
81
|
+
Supported Methods
|
82
|
+
-----------------
|
83
|
+
|
84
|
+
This gem partially implements the OnApp API v2.3.
|
85
|
+
|
86
|
+
The following OnApp modules have been added:
|
87
|
+
|
88
|
+
* Data store zones
|
89
|
+
* Firewall rules
|
90
|
+
* Hypervisors
|
91
|
+
* Hypervisor zones
|
92
|
+
* IP addresses
|
93
|
+
* IP address joins
|
94
|
+
* Networks
|
95
|
+
* Network zones
|
96
|
+
* Users
|
97
|
+
* User groups
|
98
|
+
* Roles
|
99
|
+
* Statistics
|
100
|
+
* Templates
|
101
|
+
* Transactions
|
102
|
+
* Virtual machines
|
103
|
+
* Whitelists
|
104
|
+
|
105
|
+
The following still need to be added:
|
106
|
+
|
107
|
+
* Billing plans
|
108
|
+
* Currencies
|
109
|
+
* Network interfaces
|
110
|
+
* Disks
|
111
|
+
* Template groups
|
112
|
+
* Software licenses
|
113
|
+
* Resolvers
|
114
|
+
* VM autoscaling
|
115
|
+
* Load Balancers
|
116
|
+
* CDN edge servers
|
117
|
+
* CDN resources
|
118
|
+
* CDN edge groups
|
119
|
+
* Backups
|
120
|
+
* Autobackup Presets
|
121
|
+
* Schedules
|
122
|
+
* SSH keys
|
123
|
+
* Alerts
|
124
|
+
* Logs
|
125
|
+
* System configuration
|
126
|
+
|
127
|
+
Tests
|
128
|
+
-----
|
129
|
+
|
130
|
+
Squall uses rspec for tests. To run:
|
53
131
|
|
132
|
+
bundle exec rake # Runs all tests
|
133
|
+
bundle exec rspec spec/squall/[module]_spec.rb # Runs tests for a specific module
|
134
|
+
|
135
|
+
Squall uses [VCR](https://github.com/myronmarston/vcr) to cache server
|
136
|
+
responses to test against. To test via live http connections, pass RERECORD=1
|
137
|
+
into test command. NOTE: since OnApp does not currently support a test
|
138
|
+
environment this is not recommended unless you know what you're doing, as it
|
139
|
+
will destroy live data!
|
140
|
+
|
141
|
+
Known issues:
|
142
|
+
|
143
|
+
1. VirtualMachine#change_user currently breaks the parser on an invalid
|
144
|
+
user_id because OnApp returns html instead of JSON
|
145
|
+
2. VirtualMachine#create is currently broken in certain cases. See
|
146
|
+
<https://help.onapp.com/kb_article.php?s=0b397f5b851334cea54da9ddd829bf5f&ref=8181-TYFH-8069>
|
147
|
+
3. FirewallRule#edit and #create break the parser by returning invalid JSON
|
54
148
|
|
55
149
|
Note on Patches/Pull Requests
|
56
|
-
|
57
|
-
|
150
|
+
-----------------------------
|
151
|
+
|
58
152
|
* Fork the project.
|
59
153
|
* Make your feature addition or bug fix.
|
60
154
|
* Add tests for it. This is important so I don't break it in a
|
61
155
|
future version unintentionally.
|
62
156
|
* Commit, do not mess with rakefile, version, or history.
|
63
|
-
(if you want to have your own version, that is fine but bump version in a
|
157
|
+
(if you want to have your own version, that is fine but bump version in a
|
158
|
+
commit by itself I can ignore when I pull)
|
64
159
|
* Send me a pull request. Bonus points for topic branches.
|
65
160
|
|
66
161
|
Copyright
|
67
|
-
|
162
|
+
---------
|
68
163
|
|
69
|
-
Copyright (c)
|
164
|
+
Copyright (c) 2012 Site5 LLC. See LICENSE for details.
|
data/Rakefile
CHANGED
@@ -18,44 +18,15 @@ end
|
|
18
18
|
RSpec::Core::RakeTask.new :spec
|
19
19
|
Bundler::GemHelper.install_tasks
|
20
20
|
|
21
|
-
desc "Sanitize sensitive info from cassettes"
|
22
|
-
task :sanitize_cassettes do
|
23
|
-
yaml = File.join(ENV['HOME'], '.squall.yml')
|
24
|
-
if File.exists?(yaml)
|
25
|
-
config = YAML::load_file(yaml)
|
26
|
-
uri = URI.parse(config['base_uri']).host
|
27
|
-
user = config['username']
|
28
|
-
pass = config['password']
|
29
|
-
|
30
|
-
path = File.join(File.dirname(__FILE__), 'spec', 'vcr_cassettes')
|
31
|
-
files = Dir.glob("#{path}/**/*.yml")
|
32
|
-
if files.any?
|
33
|
-
files.each do |file|
|
34
|
-
old = File.read(file)
|
35
|
-
# if old.match(/#{uri}|#{user}|#{pass}/)
|
36
|
-
puts "Sanitizing #{file}"
|
37
|
-
old.gsub!(user, 'user')
|
38
|
-
old.gsub!(pass, 'pass')
|
39
|
-
old.gsub!(uri, 'www.example.com')
|
40
|
-
old.gsub!(/_onapp_session=(.*?);/, "_onapp_session=WHAT;")
|
41
|
-
old.gsub!(/- Basic .*/, "- Basic WHAT")
|
42
|
-
File.open(file, 'w') do |f|
|
43
|
-
f.write old
|
44
|
-
end
|
45
|
-
# end
|
46
|
-
end
|
47
|
-
else
|
48
|
-
puts "Nothing to sanitize"
|
49
|
-
end
|
50
|
-
else
|
51
|
-
puts "I can't sanitize without setting up WHM_HASH and WHM_HOST"
|
52
|
-
end
|
53
|
-
end
|
54
|
-
|
55
21
|
desc "Run all specs with rcov"
|
56
22
|
RSpec::Core::RakeTask.new(:rcov) do |t|
|
57
23
|
t.rcov = true
|
58
24
|
t.rcov_opts = %w{--exclude osx\/objc,gems\/,spec\/,features\/}
|
59
25
|
end
|
60
26
|
|
27
|
+
desc "Open an irb session preloaded with this library"
|
28
|
+
task :console do
|
29
|
+
sh "irb -rubygems -r ./lib/squall.rb -I ./lib"
|
30
|
+
end
|
31
|
+
|
61
32
|
task :default => [:spec]
|
@@ -0,0 +1,58 @@
|
|
1
|
+
module Squall
|
2
|
+
# OnApp DataStoreZone
|
3
|
+
class DataStoreZone < Base
|
4
|
+
# Returns a list of data store zones
|
5
|
+
def list
|
6
|
+
response = request(:get, "/data_store_zones.json")
|
7
|
+
response.collect { |i| i['data_store_group'] }
|
8
|
+
end
|
9
|
+
|
10
|
+
# Get the details for a data store zone
|
11
|
+
#
|
12
|
+
# ==== Params
|
13
|
+
#
|
14
|
+
# * +id+ - ID of the data store zone
|
15
|
+
def show(id)
|
16
|
+
response = request(:get, "/data_store_zones/#{id}.json")
|
17
|
+
response['data_store_group']
|
18
|
+
end
|
19
|
+
|
20
|
+
# Updates an existing data store zone
|
21
|
+
#
|
22
|
+
# ==== Params
|
23
|
+
#
|
24
|
+
# * +id+ - ID of the data store zone
|
25
|
+
# * +options+ - Params for the data store zone
|
26
|
+
#
|
27
|
+
# ==== Options
|
28
|
+
#
|
29
|
+
# * +label*+ - Label for the data store zone
|
30
|
+
def edit(id, options = {})
|
31
|
+
params.required(:label).validate!(options)
|
32
|
+
response = request(:put, "/data_store_zones/#{id}.json", :query => {:pack => options})
|
33
|
+
end
|
34
|
+
|
35
|
+
# Creates a new DataStoreZone
|
36
|
+
#
|
37
|
+
# ==== Params
|
38
|
+
#
|
39
|
+
# * +options+ - Params for the data store zone
|
40
|
+
#
|
41
|
+
# ==== Options
|
42
|
+
#
|
43
|
+
# * +label*+ - Label for the data store zone
|
44
|
+
def create(options = {})
|
45
|
+
params.required(:label).validate!(options)
|
46
|
+
response = request(:post, "/data_store_zones.json", :query => {:pack => options})
|
47
|
+
end
|
48
|
+
|
49
|
+
# Deletes an existing DataStoreZone
|
50
|
+
#
|
51
|
+
# ==== Params
|
52
|
+
#
|
53
|
+
# * +id+ - ID of the data store zone
|
54
|
+
def delete(id)
|
55
|
+
request(:delete, "/data_store_zones/#{id}.json")
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
@@ -0,0 +1,66 @@
|
|
1
|
+
module Squall
|
2
|
+
# OnApp FirewallRule
|
3
|
+
class FirewallRule < Base
|
4
|
+
|
5
|
+
# Return a list of all firewall rules for a virtual machine
|
6
|
+
#
|
7
|
+
# ==== Params
|
8
|
+
#
|
9
|
+
# * +vm_id*+ - ID of the virtual machine
|
10
|
+
def list(vm_id)
|
11
|
+
response = request(:get, "/virtual_machines/#{vm_id}/firewall_rules.json")
|
12
|
+
response.collect { |firewall_rule| user['firewall_rule'] }
|
13
|
+
end
|
14
|
+
|
15
|
+
# Create a firewall rule for a virtual machine
|
16
|
+
#
|
17
|
+
# ==== Params
|
18
|
+
#
|
19
|
+
# * +vm_id*+ - ID of the virtual machine
|
20
|
+
#
|
21
|
+
# ==== Options
|
22
|
+
#
|
23
|
+
# * +command*+ - DROP or ACCEPT
|
24
|
+
# * +protocol*+ - TCP or UDP
|
25
|
+
# * +network_interface_id*+ - ID of the network interface
|
26
|
+
# * +address+ - IP address or range scope for rule. Leave blank to apply to all.
|
27
|
+
# * +port+ - Port address for rule
|
28
|
+
#
|
29
|
+
# ==== Example
|
30
|
+
#
|
31
|
+
# create :command => "DROP",
|
32
|
+
# :protocol => "TCP",
|
33
|
+
# :network_interface_id => 1
|
34
|
+
def create(vm_id, options={})
|
35
|
+
params.required(:command, :protocol, :network_interface_id).accepts(:address, :port).validate!(options)
|
36
|
+
request(:post, "/virtual_machines/#{vm_id}/firewall_rules.json", default_params(options))
|
37
|
+
end
|
38
|
+
|
39
|
+
# Edit a firewall rule
|
40
|
+
#
|
41
|
+
# ==== Params
|
42
|
+
#
|
43
|
+
# * +vm_id+ - ID of the virtual machine
|
44
|
+
# * +id+ - ID of the firewall rule
|
45
|
+
# * +options+ - Options for the firewall rule.
|
46
|
+
#
|
47
|
+
# ==== Options
|
48
|
+
#
|
49
|
+
# See #create
|
50
|
+
def edit(vm_id, id, options={})
|
51
|
+
params.accepts(:command, :protocol, :network_interface_id, :address, :port).validate!(options)
|
52
|
+
request(:put, "/virtual_machines/#{vm_id}/firewall_rules/#{id}.json", default_params(options))
|
53
|
+
end
|
54
|
+
|
55
|
+
# Delete a firewall rule
|
56
|
+
#
|
57
|
+
# ==== Params
|
58
|
+
#
|
59
|
+
# * +vm_id*+ - ID of the virtual machine
|
60
|
+
# * +id+ - ID of the firewall rule
|
61
|
+
def delete(vm_id, id)
|
62
|
+
request(:delete, "/virtual_machines/#{vm_id}/firewall_rules/#{id}.json")
|
63
|
+
end
|
64
|
+
|
65
|
+
end
|
66
|
+
end
|
data/lib/squall/hypervisor.rb
CHANGED
@@ -2,17 +2,17 @@ module Squall
|
|
2
2
|
# OnApp Hypervisor
|
3
3
|
class Hypervisor < Base
|
4
4
|
|
5
|
-
# Returns a list of all
|
5
|
+
# Returns a list of all hypervisors
|
6
6
|
def list
|
7
7
|
req = request(:get, '/settings/hypervisors.json')
|
8
8
|
req.collect { |hv| hv['hypervisor'] }
|
9
9
|
end
|
10
10
|
|
11
|
-
# Returns the
|
11
|
+
# Returns the hypervisor info as a hash
|
12
12
|
#
|
13
|
-
# ====
|
13
|
+
# ==== Params
|
14
14
|
#
|
15
|
-
# * +id+ - The id of the
|
15
|
+
# * +id+ - The id of the hypervisor
|
16
16
|
def show(id)
|
17
17
|
req = request(:get, "/settings/hypervisors/#{id}.json")
|
18
18
|
req.first[1]
|
@@ -20,41 +20,93 @@ module Squall
|
|
20
20
|
|
21
21
|
# Create a new Hypervisor
|
22
22
|
#
|
23
|
+
# ==== Params
|
24
|
+
#
|
25
|
+
# * +options+ - Options for creating the hypervisor
|
26
|
+
#
|
23
27
|
# ==== Options
|
24
28
|
#
|
25
|
-
# * +
|
29
|
+
# * +label*+ - Label for the hypervisor
|
30
|
+
# * +ip_address*+ - IP for the hypervisor
|
31
|
+
# * +hypervisor_type*+ - Type of the hypervisor
|
26
32
|
#
|
27
33
|
# ==== Example
|
28
34
|
#
|
29
35
|
# create :label => 'myhv', :ip_address => '127.0.0.1', :hypervisor_type => 'xen'
|
30
36
|
def create(options = {})
|
31
|
-
params.required(:label, :ip_address, :hypervisor_type).validate!(options)
|
37
|
+
params.required(:label, :ip_address, :hypervisor_type).accepts(:memory_overhead, :enabled, :hypervisor_group_id, :disable_failover).validate!(options)
|
32
38
|
req = request(:post, '/settings/hypervisors.json', default_params(options))
|
33
39
|
req.first[1]
|
34
40
|
end
|
35
41
|
|
36
42
|
# Edit a Hypervisor
|
37
43
|
#
|
38
|
-
# ====
|
44
|
+
# ==== Params
|
39
45
|
#
|
46
|
+
# * +id*+ - ID of the hypervisor
|
40
47
|
# * +options+ - Params for editing the Hypervisor
|
48
|
+
#
|
49
|
+
# ==== Options
|
50
|
+
#
|
51
|
+
# See #create
|
52
|
+
#
|
41
53
|
# ==== Example
|
42
54
|
#
|
43
|
-
# edit :label => 'myhv', :ip_address => '127.0.0.1'
|
55
|
+
# edit 1, :label => 'myhv', :ip_address => '127.0.0.1'
|
44
56
|
def edit(id, options ={})
|
45
|
-
params.accepts(:label, :ip_address).validate!(options)
|
57
|
+
params.accepts(:label, :ip_address, :hypervisor_type, :memory_overhead, :enabled, :hypervisor_group_id, :disable_failover).validate!(options)
|
46
58
|
request(:put, "/settings/hypervisors/#{id}.json", default_params(options))
|
47
59
|
end
|
48
60
|
|
49
|
-
# Reboot a
|
61
|
+
# Reboot a hypervisor
|
62
|
+
#
|
63
|
+
# ==== Params
|
64
|
+
#
|
65
|
+
# * +id*+ - ID of the hypervisor
|
50
66
|
def reboot(id)
|
51
67
|
response = request(:get, "/settings/hypervisors/#{id}/rebooting.json")
|
52
68
|
response['hypervisor']
|
53
69
|
end
|
54
70
|
|
55
|
-
# Delete a
|
71
|
+
# Delete a hypervisor
|
72
|
+
#
|
73
|
+
# ==== Params
|
74
|
+
#
|
75
|
+
# * +id*+ - ID of the hypervisor
|
56
76
|
def delete(id)
|
57
77
|
req = request(:delete, "/settings/hypervisors/#{id}.json")
|
58
78
|
end
|
79
|
+
|
80
|
+
def virtual_machines(id)
|
81
|
+
response = request(:get, "/settings/hypervisors/#{id}/virtual_machines.json")
|
82
|
+
response.collect { |vm| vm['virtual_machine'] }
|
83
|
+
end
|
84
|
+
|
85
|
+
def data_store_joins(id)
|
86
|
+
response = request(:get, "/settings/hypervisors/#{id}/data_store_joins.json")
|
87
|
+
response.collect { |dsj| dsj['data_store_join'] }
|
88
|
+
end
|
89
|
+
|
90
|
+
def add_data_store_join(id, data_store_id)
|
91
|
+
request(:post, "/settings/hypervisors/#{id}/data_store_joins.json", :query => {:data_store_id => data_store_id})
|
92
|
+
end
|
93
|
+
|
94
|
+
def remove_data_store_join(id, data_store_join_id)
|
95
|
+
request(:delete, "/settings/hypervisors/#{id}/data_store_joins/#{data_store_join_id}.json")
|
96
|
+
end
|
97
|
+
|
98
|
+
def network_joins(id)
|
99
|
+
response = request(:get, "/settings/hypervisors/#{id}/network_joins.json")
|
100
|
+
response.collect { |nj| nj['network_join'] }
|
101
|
+
end
|
102
|
+
|
103
|
+
def add_network_join(id, options)
|
104
|
+
params.required(:network_id, :interface).validate!(options)
|
105
|
+
request(:post, "/settings/hypervisors/#{id}/network_joins.json", :query => {:network_join => options})
|
106
|
+
end
|
107
|
+
|
108
|
+
def remove_network_join(id, network_join_id)
|
109
|
+
request(:delete, "/settings/hypervisors/#{id}/network_joins/#{network_join_id}.json")
|
110
|
+
end
|
59
111
|
end
|
60
112
|
end
|