solusvm 1.2.1 → 1.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -3,12 +3,11 @@ require 'test_helper'
3
3
  class TestClient < Test::Unit::TestCase
4
4
 
5
5
  def setup
6
- setup_solusvm
7
- @client = Solusvm::Client.new
6
+ @client = Solusvm::Client.new(solusvm_params)
8
7
  end
9
8
 
10
9
  def test_create
11
- options = {:username => 'vps123', :password=> '123456', :email=> 'email@address.com', :firstname => 'phill', :lastname => 'smith'}
10
+ options = {username: 'vps123', password: '123456', email: 'email@address.com', firstname: 'phill', lastname: 'smith'}
12
11
  VCR.use_cassette "client/create" do
13
12
  @client.create(options)
14
13
  end
@@ -28,14 +27,14 @@ class TestClient < Test::Unit::TestCase
28
27
  end
29
28
  assert_equal 'Empty username field', @client.statusmsg
30
29
  end
31
-
30
+
32
31
  def test_exists
33
32
  VCR.use_cassette "client/exists" do
34
33
  assert @client.exists?("vps123")
35
34
  end
36
- assert_equal 'Client exists', @client.statusmsg
35
+ assert_equal 'Client exists', @client.statusmsg
37
36
  end
38
-
37
+
39
38
  def test_change_password
40
39
  VCR.use_cassette "client/change_password" do
41
40
  assert @client.change_password("vps123","123456")
@@ -74,13 +73,13 @@ class TestClient < Test::Unit::TestCase
74
73
  end
75
74
 
76
75
  def test_list
77
- Solusvm.config("api_id1", api_login[:key], :url => 'http://www.example.com/api')
76
+ @client = Solusvm::Client.new(api_id: "api_id1", api_key: api_login[:key], url: 'http://www.example.com/api')
78
77
  VCR.use_cassette "client/list" do
79
78
  @client.list
80
79
  end
81
80
 
82
81
  client = @client.returned_parameters["clients"]["client"].first
83
-
82
+
84
83
  assert_equal "1", client["id"]
85
84
  assert_equal "vps123", client["username"]
86
85
  assert_equal "vps123@email.com", client["email"]
@@ -94,16 +93,16 @@ class TestClient < Test::Unit::TestCase
94
93
  end
95
94
 
96
95
  def test_list_empty
97
- Solusvm.config("api_id2", api_login[:key], :url => 'http://www.example.com/api')
96
+ @client = Solusvm::Client.new(api_id: "api_id2", api_key: api_login[:key], url: 'http://www.example.com/api')
98
97
  VCR.use_cassette "client/list" do
99
98
  assert @client.list.empty?
100
99
  end
101
100
  end
102
101
 
103
102
  def test_list_fail
104
- Solusvm.config("api_id3", api_login[:key], :url => 'http://www.example.com/api')
105
- VCR.use_cassette "client/list" do
103
+ @client = Solusvm::Client.new(api_id: "api_id3", api_key: api_login[:key], url: 'http://www.example.com/api')
104
+ VCR.use_cassette "client/list" do
106
105
  assert_nil @client.list
107
106
  end
108
107
  end
109
- end
108
+ end
@@ -2,8 +2,7 @@ require 'test_helper'
2
2
 
3
3
  class TestGeneral < Test::Unit::TestCase
4
4
  def setup
5
- setup_solusvm
6
- @general = Solusvm::General.new
5
+ @general = Solusvm::General.new(solusvm_params)
7
6
  end
8
7
 
9
8
  def test_templates
@@ -54,4 +53,4 @@ class TestGeneral < Test::Unit::TestCase
54
53
  def test_isos_with_invalid_type
55
54
  assert !@general.isos('whatever')
56
55
  end
57
- end
56
+ end
@@ -2,9 +2,9 @@ require 'test_helper'
2
2
 
3
3
  class TestHash < Test::Unit::TestCase
4
4
  def test_reverse_merge
5
- defaults = { :a => "x", :b => "y", :c => 10 }.freeze
6
- options = { :a => 1, :b => 2 }
7
- expected = { :a => 1, :b => 2, :c => 10 }
5
+ defaults = { a: "x", b: "y", c: 10 }.freeze
6
+ options = { a: 1, b: 2 }
7
+ expected = { a: 1, b: 2, c: 10 }
8
8
 
9
9
  # Should merge defaults into options, creating a new hash.
10
10
  assert_equal expected, options.reverse_merge(defaults)
@@ -17,7 +17,7 @@ class TestHash < Test::Unit::TestCase
17
17
  end
18
18
 
19
19
  def test_to_query
20
- defaults = { :a => "x", :b => "y", :c => 10 }
20
+ defaults = { a: "x", b: "y", c: 10 }
21
21
  expected = "a=x&b=y&c=10".split('&').sort
22
22
  actual = defaults.to_query.split('&').sort
23
23
 
@@ -2,8 +2,7 @@ require 'test_helper'
2
2
 
3
3
  class TestNode < Test::Unit::TestCase
4
4
  def setup
5
- setup_solusvm
6
- @nodes = Solusvm::Node.new
5
+ @nodes = Solusvm::Node.new(solusvm_params)
7
6
  end
8
7
 
9
8
  def test_list
@@ -22,6 +21,12 @@ class TestNode < Test::Unit::TestCase
22
21
  assert !@nodes.list('whatever')
23
22
  end
24
23
 
24
+ def test_list_groups
25
+ VCR.use_cassette "node/list_groups" do
26
+ assert_equal ['--none--', 'nodegroup1', 'nodegroup2', 'nodegroup3'], @nodes.list_groups
27
+ end
28
+ end
29
+
25
30
  def test_statistics
26
31
  VCR.use_cassette "node/statistics" do
27
32
  @nodes.statistics(1)
@@ -45,14 +50,14 @@ class TestNode < Test::Unit::TestCase
45
50
  end
46
51
 
47
52
  def test_list_all_ips_available
48
- Solusvm.config("api_id1", api_login[:key], :url => 'http://www.example.com/api')
53
+ @nodes = Solusvm::Node.new(solusvm_params.merge(api_id: "api_id1", url: 'http://www.example.com/api'))
49
54
  VCR.use_cassette "node/available_ips" do
50
55
  assert_equal %w(123.123.123.123 124.124.124.124 125.125.125.125).sort, @nodes.available_ips(1).sort
51
56
  end
52
57
  end
53
58
 
54
59
  def test_list_all_ips_not_available
55
- Solusvm.config("api_id2", api_login[:key], :url => 'http://www.example.com/api')
60
+ @nodes = Solusvm::Node.new(solusvm_params.merge(api_id: "api_id2", url: 'http://www.example.com/api'))
56
61
  VCR.use_cassette "node/available_ips" do
57
62
  assert @nodes.available_ips(1).empty?
58
63
  end
@@ -69,7 +74,7 @@ class TestNode < Test::Unit::TestCase
69
74
  end
70
75
 
71
76
  def test_virtualservers
72
- Solusvm.config("api_id1", api_login[:key], :url => 'http://www.example.com/api')
77
+ @nodes = Solusvm::Node.new(solusvm_params.merge(api_id: "api_id1", url: 'http://www.example.com/api'))
73
78
  VCR.use_cassette "node/virtualservers" do
74
79
  @nodes.virtualservers(1)
75
80
  end
@@ -90,14 +95,14 @@ class TestNode < Test::Unit::TestCase
90
95
  end
91
96
 
92
97
  def test_virtualservers_empty
93
- Solusvm.config("api_id2", api_login[:key], :url => 'http://www.example.com/api')
98
+ @nodes = Solusvm::Node.new(solusvm_params.merge(api_id: "api_id2", url: 'http://www.example.com/api'))
94
99
  VCR.use_cassette "node/virtualservers" do
95
100
  assert @nodes.virtualservers(1).empty?
96
101
  end
97
102
  end
98
103
 
99
104
  def test_virtualservers_fail
100
- Solusvm.config("api_id3", api_login[:key], :url => 'http://www.example.com/api')
105
+ @nodes = Solusvm::Node.new(solusvm_params.merge(api_id: "api_id3", url: 'http://www.example.com/api'))
101
106
  VCR.use_cassette "node/virtualservers" do
102
107
  assert_nil @nodes.virtualservers(1)
103
108
  end
@@ -3,17 +3,16 @@ require 'test_helper'
3
3
  class TestReseller < Test::Unit::TestCase
4
4
 
5
5
  def setup
6
- setup_solusvm
7
- @reseller = Solusvm::Reseller.new
6
+ @reseller = Solusvm::Reseller.new(solusvm_params)
8
7
  end
9
8
 
10
9
  def test_create
11
- options = {:username => 'reseller123', :password=> '123456', :email=> 'reseller3@email.com', :firstname => 'Phill', :lastname => 'Smith'}
12
-
10
+ options = {username: 'reseller123', password: '123456', email: 'reseller3@email.com', firstname: 'Phill', lastname: 'Smith'}
11
+
13
12
  VCR.use_cassette "reseller/create" do
14
- @reseller.create(options)
13
+ @reseller.create(options)
15
14
  end
16
-
15
+
17
16
  params = @reseller.returned_parameters
18
17
 
19
18
  assert params
@@ -32,13 +31,13 @@ class TestReseller < Test::Unit::TestCase
32
31
  end
33
32
 
34
33
  def test_change_resources
35
- options = {:maxvps => 10}
34
+ options = {maxvps: 10}
36
35
  VCR.use_cassette "reseller/change_resources" do
37
36
  @reseller.change_resources("vps123", options)
38
37
  end
39
-
38
+
40
39
  params = @reseller.returned_parameters
41
-
40
+
42
41
  assert params
43
42
  assert "10", params['maxvps']
44
43
  end
@@ -53,9 +52,9 @@ class TestReseller < Test::Unit::TestCase
53
52
  VCR.use_cassette "reseller/info" do
54
53
  @reseller.info("vps123")
55
54
  end
56
-
55
+
57
56
  params = @reseller.returned_parameters
58
-
57
+
59
58
  assert params
60
59
  assert_equal "reseller123", params['username']
61
60
  assert_equal "Phill", params['firstname']
@@ -71,14 +70,14 @@ class TestReseller < Test::Unit::TestCase
71
70
  end
72
71
 
73
72
  def test_list
74
- Solusvm.config("api_id1", api_login[:key], :url => 'http://www.example.com/api')
73
+ @reseller = Solusvm::Reseller.new(solusvm_params.merge(api_id: 'api_id1', url: 'http://www.example.com/api'))
75
74
  VCR.use_cassette "reseller/list" do
76
75
  assert_equal %w(username1 username2 username3), @reseller.list
77
76
  end
78
77
  end
79
78
 
80
79
  def test_list_empty
81
- Solusvm.config("api_id2", api_login[:key], :url => 'http://www.example.com/api')
80
+ @reseller = Solusvm::Reseller.new(solusvm_params.merge(api_id: 'api_id2', url: 'http://www.example.com/api'))
82
81
  VCR.use_cassette "reseller/list" do
83
82
  assert !@reseller.list
84
83
  end
@@ -90,4 +89,4 @@ class TestReseller < Test::Unit::TestCase
90
89
  end
91
90
  end
92
91
 
93
- end
92
+ end
@@ -2,13 +2,12 @@ require 'test_helper'
2
2
 
3
3
  class TestServer < Test::Unit::TestCase
4
4
  def setup
5
- setup_solusvm
6
- @server = Solusvm::Server.new
5
+ @server = Solusvm::Server.new(solusvm_params)
7
6
  end
8
7
 
9
8
  def test_create
10
- options = {:hostname => 'server.hostname.com', :type => 'xen', :username => 'bob', :password => '123456',
11
- :node => 'node1', :plan => 'plan1', :template => 'mytpl', :ips => 1}
9
+ options = {hostname: 'server.hostname.com', type: 'xen', username: 'bob', password: '123456',
10
+ node: 'node1', plan: 'plan1', template: 'mytpl', ips: 1}
12
11
  hostname = options.delete(:hostname)
13
12
  password = options.delete(:password)
14
13
  VCR.use_cassette "server/create" do
@@ -37,7 +36,7 @@ class TestServer < Test::Unit::TestCase
37
36
  end
38
37
  assert_equal 'Virtual server is being rebuilt', @server.statusmsg
39
38
  end
40
-
39
+
41
40
  def test_boot
42
41
  VCR.use_cassette "server/boot" do
43
42
  assert @server.boot(1)
@@ -133,7 +132,16 @@ class TestServer < Test::Unit::TestCase
133
132
  end
134
133
 
135
134
  def test_add_ip
136
- #flunk "This is broken on the SolusVM API Level"
135
+ VCR.use_cassette "server/add_ip" do
136
+ assert_equal '123.123.123.123', @server.add_ip(1)
137
+ end
138
+ assert_equal 'Ip address added', @server.statusmsg
139
+ end
140
+
141
+ def test_del_ip
142
+ VCR.use_cassette "server/del_ip" do
143
+ assert @server.del_ip(1, '123.123.123.123')
144
+ end
137
145
  end
138
146
 
139
147
  def test_change_plan
@@ -221,7 +229,7 @@ class TestServer < Test::Unit::TestCase
221
229
  assert_equal 'theconsolepassword', info['consolepassword']
222
230
  assert_equal 'theconsoleusername', info['consoleusername']
223
231
  end
224
-
232
+
225
233
  def test_info_all
226
234
  VCR.use_cassette "server/info_all" do
227
235
  @server.info_all(1)
@@ -236,7 +244,7 @@ class TestServer < Test::Unit::TestCase
236
244
  assert_equal "236223201280,103640707072,132582494208,44", info["hdd"]
237
245
  assert_equal "/graphs/9/214/214-8f7daef90bc75037489af4217af674a67df545ba05c8a6bcd5341d5894f2f905bf23976f52c0104415c1694135d51f204ddfd7b11bbe87c195a5de4a-86400.png", info["trafficgraph"]
238
246
  assert_equal "/graphs/9/214/214-load-8f7daef90bc75037489af4217af674a67df545ba05c8a6bcd5341d5894f2f905bf23976f52c0104415c1694135d51f204ddfd7b11bbe87c195a5de4a-86400.png", info["loadgraph"]
239
- assert_equal "/graphs/9/214/214-mem-8f7daef90bc75037489af4217af674a67df545ba05c8a6bcd5341d5894f2f905bf23976f52c0104415c1694135d51f204ddfd7b11bbe87c195a5de4a-86400.png", info["memorygraph"]
247
+ assert_equal "/graphs/9/214/214-mem-8f7daef90bc75037489af4217af674a67df545ba05c8a6bcd5341d5894f2f905bf23976f52c0104415c1694135d51f204ddfd7b11bbe87c195a5de4a-86400.png", info["memorygraph"]
240
248
  end
241
249
 
242
250
  def test_mountiso
@@ -250,4 +258,4 @@ class TestServer < Test::Unit::TestCase
250
258
  assert @server.unmountiso(1)
251
259
  end
252
260
  end
253
- end
261
+ end
data/test/test_helper.rb CHANGED
@@ -15,7 +15,7 @@ VCR.configure do |c|
15
15
  path2, params2 = request2.uri.split('?')
16
16
  path1 == path2 && Set.new(params1.to_s.split('&')) == Set.new(params2.to_s.split('&'))
17
17
  end
18
- c.default_cassette_options = { :record => :none, :match_requests_on => [:method, :uri_with_unordered_params] }
18
+ c.default_cassette_options = { record: :none, match_requests_on: [:method, :uri_with_unordered_params] }
19
19
  end
20
20
 
21
21
  # Use TURN if available
@@ -35,15 +35,19 @@ class Test::Unit::TestCase
35
35
  end
36
36
 
37
37
  def api_login
38
- {:id => 'api_id', :key => 'api_key'}
38
+ {id: 'api_id', key: 'api_key'}
39
39
  end
40
40
 
41
- def setup_solusvm
42
- Solusvm.config(api_login[:id], api_login[:key], :url => 'http://www.example.com/api')
41
+ def solusvm_params
42
+ {
43
+ api_id: api_login[:id],
44
+ api_key: api_login[:key],
45
+ url: 'http://www.example.com/api'
46
+ }
43
47
  end
44
48
 
45
49
  def cli_expand_base_arguments(options)
46
- arguments = ["--api-login", "thelogin", "--api-key", "thekey", "--api-url", "theurl"]
50
+ arguments = ["--api-login", "api_id", "--api-key", "api_key", "--api-url", "http://www.example.com/api"]
47
51
  options + arguments
48
52
  end
49
53
 
@@ -42,4 +42,27 @@ http_interactions:
42
42
  <statusmsg>error message</statusmsg>
43
43
  http_version: "1.1"
44
44
  recorded_at: Tue, 01 Nov 2011 04:58:44 GMT
45
- recorded_with: VCR 2.0.0
45
+ - request:
46
+ method: get
47
+ uri: http://www.example.com/api?action=testnostatus&vserverid=1&id=api_id&key=api_key
48
+ body:
49
+ encoding: UTF-8
50
+ string: ""
51
+ headers: {}
52
+ response:
53
+ status:
54
+ code: 200
55
+ message: OK
56
+ body:
57
+ encoding: UTF-8
58
+ string: <mainipaddress>123.123.123.123</mainipaddress>
59
+ <extraipaddress>122.122.122.122,111.111.111.111</extraipaddress>
60
+ <rootpassword>123456</rootpassword>
61
+ <vserverid>100</vserverid>
62
+ <consoleuser>console-123</consoleuser>
63
+ <consolepassword>123456</consolepassword>
64
+ <hostname>server.hostname.com</hostname>
65
+ <virtid>vm101|101</virtid>
66
+ http_version: "1.1"
67
+ recorded_at: Tue, 01 Nov 2011 04:58:44 GMT
68
+ recorded_with: VCR 2.0.0
@@ -0,0 +1,28 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: get
5
+ uri: http://www.test.com/api?action=testconfig&vserverid=1&id=instance_id&key=instance_key
6
+ body:
7
+ encoding: UTF-8
8
+ string: ""
9
+ headers: {}
10
+ response:
11
+ status:
12
+ code: 200
13
+ message: OK
14
+ body:
15
+ encoding: UTF-8
16
+ string: <status>success</status>
17
+ <statusmsg>Virtual server created</statusmsg>
18
+ <mainipaddress>123.123.123.123</mainipaddress>
19
+ <extraipaddress>122.122.122.122,111.111.111.111</extraipaddress>
20
+ <rootpassword>123456</rootpassword>
21
+ <vserverid>100</vserverid>
22
+ <consoleuser>console-123</consoleuser>
23
+ <consolepassword>123456</consolepassword>
24
+ <hostname>server.hostname.com</hostname>
25
+ <virtid>vm101|101</virtid>
26
+ http_version: "1.1"
27
+ recorded_at: Tue, 01 Nov 2011 04:58:44 GMT
28
+ recorded_with: VCR 2.0.0
@@ -0,0 +1,20 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: get
5
+ uri: http://www.example.com/api?action=listnodegroups&id=api_id&key=api_key
6
+ body:
7
+ encoding: UTF-8
8
+ string: ""
9
+ headers: {}
10
+ response:
11
+ status:
12
+ code: 200
13
+ message: OK
14
+ body:
15
+ encoding: UTF-8
16
+ string: <status>success</status>
17
+ <statusmsg></statusmsg>
18
+ <nodegroups>0|--none--,1|nodegroup1,2|nodegroup2,3|nodegroup3</nodegroups>
19
+ http_version: "1.1"
20
+ recorded_at: Tue, 01 Nov 2011 04:58:44 GMT
@@ -0,0 +1,15 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: get
5
+ uri: http://www.example.com/api?action=vserver-addip&vserverid=1&id=api_id&key=api_key
6
+ body: ''
7
+ headers: {}
8
+ response:
9
+ status:
10
+ code: 200
11
+ message: OK
12
+ body: <status>success</status><statusmsg>Ip address added</statusmsg><ipaddress>123.123.123.123</ipaddress>
13
+ http_version: '1.1'
14
+ recorded_at: Tue, 01 Nov 2011 04:58:44 GMT
15
+ recorded_with: VCR 2.0.0
@@ -0,0 +1,15 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: get
5
+ uri: http://www.example.com/api?action=vserver-delip&vserverid=1&ipaddr=123.123.123.123&id=api_id&key=api_key
6
+ body: ''
7
+ headers: {}
8
+ response:
9
+ status:
10
+ code: 200
11
+ message: OK
12
+ body: <status>success</status><statusmsg>Ip address deleted</statusmsg>
13
+ http_version: '1.1'
14
+ recorded_at: Tue, 01 Nov 2011 04:58:44 GMT
15
+ recorded_with: VCR 2.0.0