profitbricks 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.autotest +23 -0
- data/.gemtest +0 -0
- data/.rspec +3 -0
- data/CHANGELOG.md +6 -0
- data/Gemfile +8 -0
- data/Gemfile.lock +53 -0
- data/Manifest.txt +106 -0
- data/README.md +70 -0
- data/Rakefile +31 -0
- data/bin/profitbricks +3 -0
- data/examples/create_datacenter.rb +57 -0
- data/lib/profitbricks/config.rb +16 -0
- data/lib/profitbricks/data_center.rb +100 -0
- data/lib/profitbricks/extensions.rb +9 -0
- data/lib/profitbricks/image.rb +47 -0
- data/lib/profitbricks/ip_block.rb +49 -0
- data/lib/profitbricks/model.rb +102 -0
- data/lib/profitbricks/nic.rb +103 -0
- data/lib/profitbricks/profitbricks.rb +86 -0
- data/lib/profitbricks/server.rb +83 -0
- data/lib/profitbricks/storage.rb +84 -0
- data/lib/profitbricks.rb +15 -0
- data/profitbricks.gemspec +34 -0
- data/spec/fixtures/add_public_ip_to_nic/success.json +10 -0
- data/spec/fixtures/add_public_ip_to_nic/success.xml +1 -0
- data/spec/fixtures/clear_data_center/success.json +10 -0
- data/spec/fixtures/clear_data_center/success.xml +1 -0
- data/spec/fixtures/connect_storage_to_server/success.json +10 -0
- data/spec/fixtures/connect_storage_to_server/success.xml +1 -0
- data/spec/fixtures/create_data_center/success.json +10 -0
- data/spec/fixtures/create_data_center/success.xml +1 -0
- data/spec/fixtures/create_nic/success.json +11 -0
- data/spec/fixtures/create_nic/success.xml +1 -0
- data/spec/fixtures/create_server/minimal.json +11 -0
- data/spec/fixtures/create_server/minimal.xml +1 -0
- data/spec/fixtures/create_storage/success.json +11 -0
- data/spec/fixtures/create_storage/success.xml +1 -0
- data/spec/fixtures/delete_data_center/success.json +8 -0
- data/spec/fixtures/delete_data_center/success.xml +1 -0
- data/spec/fixtures/delete_nic/success.json +10 -0
- data/spec/fixtures/delete_nic/success.xml +1 -0
- data/spec/fixtures/delete_server/success.json +10 -0
- data/spec/fixtures/delete_server/success.xml +1 -0
- data/spec/fixtures/delete_storage/failture.json +16 -0
- data/spec/fixtures/delete_storage/failture.xml +1 -0
- data/spec/fixtures/delete_storage/success.json +10 -0
- data/spec/fixtures/delete_storage/success.xml +1 -0
- data/spec/fixtures/disconnect_storage_from_server/failture.json +16 -0
- data/spec/fixtures/disconnect_storage_from_server/failture.xml +1 -0
- data/spec/fixtures/disconnect_storage_from_server/success.json +10 -0
- data/spec/fixtures/disconnect_storage_from_server/success.xml +1 -0
- data/spec/fixtures/get_all_data_centers/empty.json +1 -0
- data/spec/fixtures/get_all_data_centers/empty.xml +1 -0
- data/spec/fixtures/get_all_data_centers/test_datacenter.json +10 -0
- data/spec/fixtures/get_all_data_centers/test_datacenter.xml +1 -0
- data/spec/fixtures/get_all_images/success.json +100 -0
- data/spec/fixtures/get_all_images/success.xml +1 -0
- data/spec/fixtures/get_all_public_ip_blocks/success.json +16 -0
- data/spec/fixtures/get_all_public_ip_blocks/success.xml +1 -0
- data/spec/fixtures/get_data_center/create.json +147 -0
- data/spec/fixtures/get_data_center/create.xml +1 -0
- data/spec/fixtures/get_data_center/two_servers_with_storage.json +147 -0
- data/spec/fixtures/get_data_center/two_servers_with_storage.xml +1 -0
- data/spec/fixtures/get_data_center_state/in_process.json +1 -0
- data/spec/fixtures/get_data_center_state/in_process.xml +1 -0
- data/spec/fixtures/get_data_center_state/success.json +1 -0
- data/spec/fixtures/get_data_center_state/success.xml +1 -0
- data/spec/fixtures/get_image/success.json +15 -0
- data/spec/fixtures/get_image/success.xml +1 -0
- data/spec/fixtures/get_nic/success.json +16 -0
- data/spec/fixtures/get_nic/success.xml +1 -0
- data/spec/fixtures/get_nic/two_ips.json +19 -0
- data/spec/fixtures/get_nic/two_ips.xml +1 -0
- data/spec/fixtures/get_server/after_create.json +17 -0
- data/spec/fixtures/get_server/after_create.xml +1 -0
- data/spec/fixtures/get_server/connected_storage.json +26 -0
- data/spec/fixtures/get_server/connected_storage.xml +1 -0
- data/spec/fixtures/get_storage/success.json +14 -0
- data/spec/fixtures/get_storage/success.xml +1 -0
- data/spec/fixtures/reboot_server/success.json +1 -0
- data/spec/fixtures/reboot_server/success.xml +1 -0
- data/spec/fixtures/release_public_ip_block/success.json +1 -0
- data/spec/fixtures/release_public_ip_block/success.xml +1 -0
- data/spec/fixtures/remove_public_ip_from_nic/success.json +10 -0
- data/spec/fixtures/remove_public_ip_from_nic/success.xml +1 -0
- data/spec/fixtures/reserve_public_ip_block/success.json +13 -0
- data/spec/fixtures/reserve_public_ip_block/success.xml +1 -0
- data/spec/fixtures/set_image_os_type/success.json +1 -0
- data/spec/fixtures/set_image_os_type/success.xml +1 -0
- data/spec/fixtures/set_internet_access/success.json +10 -0
- data/spec/fixtures/set_internet_access/success.xml +1 -0
- data/spec/fixtures/update_data_center/success.json +10 -0
- data/spec/fixtures/update_data_center/success.xml +1 -0
- data/spec/fixtures/update_nic/success.json +10 -0
- data/spec/fixtures/update_nic/success.xml +1 -0
- data/spec/fixtures/update_server/basic.json +10 -0
- data/spec/fixtures/update_server/basic.xml +1 -0
- data/spec/fixtures/update_storage/success.json +10 -0
- data/spec/fixtures/update_storage/success.xml +1 -0
- data/spec/profitbricks/data_center_spec.rb +95 -0
- data/spec/profitbricks/image_spec.rb +23 -0
- data/spec/profitbricks/ip_block_spec.rb +26 -0
- data/spec/profitbricks/model_spec.rb +68 -0
- data/spec/profitbricks/nic_spec.rb +55 -0
- data/spec/profitbricks/server_spec.rb +41 -0
- data/spec/profitbricks/storage_spec.rb +47 -0
- data/spec/spec_helper.rb +45 -0
- metadata +193 -0
@@ -0,0 +1 @@
|
|
1
|
+
<?xml version='1.0' encoding='UTF-8'?><S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/"><S:Body><ns2:getServerResponse xmlns:ns2="http://ws.api.profitbricks.com/"><return><dataCenterId>b3eebede-5c78-417c-b1bc-ff5de01a0602</dataCenterId><dataCenterVersion>35</dataCenterVersion><serverId>4cb6550f-3777-4818-8f4c-51233162a980</serverId><serverName>Power of two</serverName><cores>1</cores><ram>256</ram><internetAccess>false</internetAccess><connectedStorages><busType>VIRTIO</busType><deviceNumber>900</deviceNumber><size>5</size><storageId>f55952bc-da27-4e29-af89-ed212ea28e11</storageId><storageName>Test Storage</storageName></connectedStorages><provisioningState>AVAILABLE</provisioningState><virtualMachineState>RUNNING</virtualMachineState><creationTime>2012-03-04T23:04:26.329+01:00</creationTime><lastModificationTime>2012-03-05T11:25:11.704+01:00</lastModificationTime><osType>UNKNOWN</osType></return></ns2:getServerResponse></S:Body></S:Envelope>
|
@@ -0,0 +1,14 @@
|
|
1
|
+
{
|
2
|
+
"get_storage_response": {
|
3
|
+
"@xmlns:ns2": "http://ws.api.profitbricks.com/",
|
4
|
+
"return": {
|
5
|
+
"data_center_id": "b3eebede-5c78-417c-b1bc-ff5de01a0602",
|
6
|
+
"data_center_version": "31",
|
7
|
+
"os_type": "UNKNOWN",
|
8
|
+
"provisioning_state": "INACTIVE",
|
9
|
+
"size": "5",
|
10
|
+
"storage_id": "f55952bc-da27-4e29-af89-ed212ea28e11",
|
11
|
+
"storage_name": "Test Storage"
|
12
|
+
}
|
13
|
+
}
|
14
|
+
}
|
@@ -0,0 +1 @@
|
|
1
|
+
<?xml version='1.0' encoding='UTF-8'?><S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/"><S:Body><ns2:getStorageResponse xmlns:ns2="http://ws.api.profitbricks.com/"><return><dataCenterId>b3eebede-5c78-417c-b1bc-ff5de01a0602</dataCenterId><dataCenterVersion>31</dataCenterVersion><storageId>f55952bc-da27-4e29-af89-ed212ea28e11</storageId><size>5</size><storageName>Test Storage</storageName><provisioningState>INACTIVE</provisioningState><osType>UNKNOWN</osType></return></ns2:getStorageResponse></S:Body></S:Envelope>
|
@@ -0,0 +1 @@
|
|
1
|
+
{"reboot_server_response":{"return":{"request_id":"1187"},"@xmlns:ns2":"http://ws.api.profitbricks.com/"}}
|
@@ -0,0 +1 @@
|
|
1
|
+
<?xml version='1.0' encoding='UTF-8'?><S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/"><S:Body><ns2:rebootServerResponse xmlns:ns2="http://ws.api.profitbricks.com/"><return><requestId>1187</requestId></return></ns2:rebootServerResponse></S:Body></S:Envelope>
|
@@ -0,0 +1 @@
|
|
1
|
+
{"release_public_ip_block_response":{"return":{"request_id":"1429"},"@xmlns:ns2":"http://ws.api.profitbricks.com/"}}
|
@@ -0,0 +1 @@
|
|
1
|
+
<?xml version='1.0' encoding='UTF-8'?><S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/"><S:Body><ns2:releasePublicIpBlockResponse xmlns:ns2="http://ws.api.profitbricks.com/"><return><requestId>1429</requestId></return></ns2:releasePublicIpBlockResponse></S:Body></S:Envelope>
|
@@ -0,0 +1 @@
|
|
1
|
+
<?xml version='1.0' encoding='UTF-8'?><S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/"><S:Body><ns2:removePublicIpFromNicResponse xmlns:ns2="http://ws.api.profitbricks.com/"><return><requestId>1428</requestId><dataCenterId>b3eebede-5c78-417c-b1bc-ff5de01a0602</dataCenterId><dataCenterVersion>59</dataCenterVersion></return></ns2:removePublicIpFromNicResponse></S:Body></S:Envelope>
|
@@ -0,0 +1 @@
|
|
1
|
+
<?xml version='1.0' encoding='UTF-8'?><S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/"><S:Body><ns2:reservePublicIpBlockResponse xmlns:ns2="http://ws.api.profitbricks.com/"><return><requestId>1426</requestId><blockId>167bc48c-4f80-4870-b5db-13d7d762e1cd</blockId><ips>46.16.74.12</ips><ips>46.16.74.13</ips></return></ns2:reservePublicIpBlockResponse></S:Body></S:Envelope>
|
@@ -0,0 +1 @@
|
|
1
|
+
{"set_image_os_type_response":{"return":{"request_id":"1310"},"@xmlns:ns2":"http://ws.api.profitbricks.com/"}}
|
@@ -0,0 +1 @@
|
|
1
|
+
<?xml version='1.0' encoding='UTF-8'?><S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/"><S:Body><ns2:setImageOsTypeResponse xmlns:ns2="http://ws.api.profitbricks.com/"><return><requestId>1310</requestId></return></ns2:setImageOsTypeResponse></S:Body></S:Envelope>
|
@@ -0,0 +1 @@
|
|
1
|
+
<?xml version='1.0' encoding='UTF-8'?><S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/"><S:Body><ns2:setInternetAccessResponse xmlns:ns2="http://ws.api.profitbricks.com/"><return><requestId>1335</requestId><dataCenterId>b3eebede-5c78-417c-b1bc-ff5de01a0602</dataCenterId><dataCenterVersion>46</dataCenterVersion></return></ns2:setInternetAccessResponse></S:Body></S:Envelope>
|
@@ -0,0 +1 @@
|
|
1
|
+
<?xml version='1.0' encoding='UTF-8'?><S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/"><S:Body><ns2:updateDataCenterResponse xmlns:ns2="http://ws.api.profitbricks.com/"><return><requestId>1180</requestId><dataCenterId>b3eebede-5c78-417c-b1bc-ff5de01a0602</dataCenterId><dataCenterVersion>12</dataCenterVersion></return></ns2:updateDataCenterResponse></S:Body></S:Envelope>
|
@@ -0,0 +1 @@
|
|
1
|
+
<?xml version='1.0' encoding='UTF-8'?><S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/"><S:Body><ns2:updateNicResponse xmlns:ns2="http://ws.api.profitbricks.com/"><return><requestId>1422</requestId><dataCenterId>b3eebede-5c78-417c-b1bc-ff5de01a0602</dataCenterId><dataCenterVersion>56</dataCenterVersion></return></ns2:updateNicResponse></S:Body></S:Envelope>
|
@@ -0,0 +1 @@
|
|
1
|
+
<?xml version='1.0' encoding='UTF-8'?><S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/"><S:Body><ns2:updateServerResponse xmlns:ns2="http://ws.api.profitbricks.com/"><return><requestId>1189</requestId><dataCenterId>b3eebede-5c78-417c-b1bc-ff5de01a0602</dataCenterId><dataCenterVersion>20</dataCenterVersion></return></ns2:updateServerResponse></S:Body></S:Envelope>
|
@@ -0,0 +1 @@
|
|
1
|
+
<?xml version='1.0' encoding='UTF-8'?><S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/"><S:Body><ns2:updateStorageResponse xmlns:ns2="http://ws.api.profitbricks.com/"><return><requestId>1295</requestId><dataCenterId>b3eebede-5c78-417c-b1bc-ff5de01a0602</dataCenterId><dataCenterVersion>40</dataCenterVersion></return></ns2:updateStorageResponse></S:Body></S:Envelope>
|
@@ -0,0 +1,95 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Profitbricks::DataCenter do
|
4
|
+
include Savon::Spec::Macros
|
5
|
+
|
6
|
+
it "should create a new datacenter" do
|
7
|
+
savon.expects(:create_data_center).returns(:success)
|
8
|
+
savon.expects(:get_data_center).returns(:create)
|
9
|
+
dc = DataCenter.create('Test2')
|
10
|
+
dc.name.should == 'Test2'
|
11
|
+
dc.id.should == "b3eebede-5c78-417c-b1bc-ff5de01a0602"
|
12
|
+
dc.version.should == 9
|
13
|
+
end
|
14
|
+
|
15
|
+
it "should get a list of all datacenters" do
|
16
|
+
savon.expects(:get_all_data_centers).returns(:test_datacenter)
|
17
|
+
savon.expects(:get_data_center).returns(:two_servers_with_storage)
|
18
|
+
Profitbricks::DataCenter.all().count.should == 1
|
19
|
+
end
|
20
|
+
|
21
|
+
it "should handle an empty list of datacenters correctly" do
|
22
|
+
savon.expects(:get_all_data_centers).returns(:empty)
|
23
|
+
Profitbricks::DataCenter.all().count.should == 0
|
24
|
+
end
|
25
|
+
|
26
|
+
it "should find a datacenter with a given name" do
|
27
|
+
savon.expects(:get_all_data_centers).returns(:test_datacenter)
|
28
|
+
savon.expects(:get_data_center).returns(:two_servers_with_storage)
|
29
|
+
savon.expects(:get_data_center).returns(:two_servers_with_storage)
|
30
|
+
dc = Profitbricks::DataCenter.find(:name => 'Test')
|
31
|
+
dc.name.should == "Test"
|
32
|
+
dc.id.should == "b3eebede-5c78-417c-b1bc-ff5de01a0602"
|
33
|
+
dc.provisioning_state.should == "INPROCESS"
|
34
|
+
dc.version.should == 9
|
35
|
+
|
36
|
+
dc.servers.count.should == 2
|
37
|
+
dc.servers.first.class.should == Server
|
38
|
+
end
|
39
|
+
|
40
|
+
it "should reload a datacenter" do
|
41
|
+
savon.expects(:get_all_data_centers).returns(:test_datacenter)
|
42
|
+
savon.expects(:get_data_center).returns(:two_servers_with_storage)
|
43
|
+
savon.expects(:get_data_center).returns(:two_servers_with_storage)
|
44
|
+
dc = Profitbricks::DataCenter.find(:name => 'Test')
|
45
|
+
savon.expects(:get_data_center).returns(:two_servers_with_storage)
|
46
|
+
dc.reload.should == true
|
47
|
+
end
|
48
|
+
|
49
|
+
it "should update its provisioning_state" do
|
50
|
+
savon.expects(:get_data_center).returns(:two_servers_with_storage)
|
51
|
+
savon.expects(:get_data_center_state).returns(:success)
|
52
|
+
dc = Profitbricks::DataCenter.find(:id => "b3eebede-5c78-417c-b1bc-ff5de01a0602")
|
53
|
+
dc.update_state().should == 'AVAILABLE'
|
54
|
+
dc.provisioning_state.should == 'AVAILABLE'
|
55
|
+
end
|
56
|
+
|
57
|
+
it "should wait for provisioning to finish" do
|
58
|
+
savon.expects(:get_data_center).returns(:two_servers_with_storage)
|
59
|
+
dc = Profitbricks::DataCenter.find(:id => "b3eebede-5c78-417c-b1bc-ff5de01a0602")
|
60
|
+
savon.expects(:get_data_center_state).returns(:success)
|
61
|
+
savon.expects(:get_data_center).returns(:two_servers_with_storage)
|
62
|
+
dc.wait_for_provisioning
|
63
|
+
end
|
64
|
+
|
65
|
+
it "should rename a datacenter" do
|
66
|
+
savon.expects(:get_data_center).returns(:two_servers_with_storage)
|
67
|
+
savon.expects(:update_data_center).returns(:success)
|
68
|
+
dc = Profitbricks::DataCenter.find(:id => "b3eebede-5c78-417c-b1bc-ff5de01a0602")
|
69
|
+
dc.rename("Test2")
|
70
|
+
dc.name.should == 'Test2'
|
71
|
+
end
|
72
|
+
|
73
|
+
it "should rename a datacenter via setter" do
|
74
|
+
savon.expects(:get_data_center).returns(:two_servers_with_storage)
|
75
|
+
savon.expects(:update_data_center).returns(:success)
|
76
|
+
dc = Profitbricks::DataCenter.find(:id => "b3eebede-5c78-417c-b1bc-ff5de01a0602")
|
77
|
+
dc.name = "Test2"
|
78
|
+
dc.name.should == 'Test2'
|
79
|
+
end
|
80
|
+
|
81
|
+
it "should clear the datacenter" do
|
82
|
+
savon.expects(:get_data_center).returns(:two_servers_with_storage)
|
83
|
+
savon.expects(:clear_data_center).returns(:success)
|
84
|
+
dc = Profitbricks::DataCenter.find(:id => "b3eebede-5c78-417c-b1bc-ff5de01a0602")
|
85
|
+
dc.clear
|
86
|
+
dc.servers.count.should == 0
|
87
|
+
end
|
88
|
+
|
89
|
+
it "should delete a datacenter" do
|
90
|
+
savon.expects(:get_data_center).returns(:two_servers_with_storage)
|
91
|
+
savon.expects(:delete_data_center).returns(:success)
|
92
|
+
dc = Profitbricks::DataCenter.find(:id => "b3eebede-5c78-417c-b1bc-ff5de01a0602")
|
93
|
+
dc.delete.should == true
|
94
|
+
end
|
95
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Profitbricks::Image do
|
4
|
+
include Savon::Spec::Macros
|
5
|
+
|
6
|
+
it "should find all images" do
|
7
|
+
savon.expects(:get_all_images).returns(:success)
|
8
|
+
Image.all.count.should == 7
|
9
|
+
end
|
10
|
+
|
11
|
+
it "should find an image by name" do
|
12
|
+
savon.expects(:get_all_images).returns(:success)
|
13
|
+
image = Image.find(:name => "Windows8-ConsumerPreview-64bit-English.iso")
|
14
|
+
image.os_type.should == "UNKNOWN"
|
15
|
+
end
|
16
|
+
|
17
|
+
it "should update the os_type" do
|
18
|
+
savon.expects(:get_all_images).returns(:success)
|
19
|
+
savon.expects(:set_image_os_type).returns(:success)
|
20
|
+
image = Image.find(:name => "Windows8-ConsumerPreview-64bit-English.iso")
|
21
|
+
image.set_os_type("WINDOWS").os_type.should == "WINDOWS"
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Profitbricks::IpBlock do
|
4
|
+
include Savon::Spec::Macros
|
5
|
+
|
6
|
+
it "should reserve a block" do
|
7
|
+
savon.expects(:reserve_public_ip_block).returns(:success)
|
8
|
+
block = IpBlock.reserve(2)
|
9
|
+
block.ips.count.should == 2
|
10
|
+
end
|
11
|
+
|
12
|
+
it "should list all available blocks" do
|
13
|
+
savon.expects(:get_all_public_ip_blocks).returns(:success)
|
14
|
+
blocks = IpBlock.all()
|
15
|
+
blocks.count.should == 1
|
16
|
+
blocks.first.ips.count.should == 2
|
17
|
+
end
|
18
|
+
|
19
|
+
it "should release a block properly" do
|
20
|
+
savon.expects(:get_all_public_ip_blocks).returns(:success)
|
21
|
+
savon.expects(:release_public_ip_block).returns(:success)
|
22
|
+
blocks = IpBlock.all()
|
23
|
+
blocks.first.release.should == true
|
24
|
+
end
|
25
|
+
|
26
|
+
end
|
@@ -0,0 +1,68 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
module Profitbricks
|
4
|
+
class ModelTest < Profitbricks::Model
|
5
|
+
end
|
6
|
+
|
7
|
+
class ModelHasManyTest < Profitbricks::Model
|
8
|
+
has_many :model_tests
|
9
|
+
end
|
10
|
+
|
11
|
+
class ModelBelongsToTest < Profitbricks::Model
|
12
|
+
belongs_to :model_has_many_test
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
describe Profitbricks::Model do
|
17
|
+
it "should define an attribute correclty" do
|
18
|
+
mt = Profitbricks::ModelTest.new({:name => 'Test'})
|
19
|
+
mt.name.should == 'Test'
|
20
|
+
end
|
21
|
+
|
22
|
+
it "should truncate redundant attribute name" do
|
23
|
+
mt = Profitbricks::ModelTest.new({:model_test_name => 'Test'})
|
24
|
+
mt.name.should == 'Test'
|
25
|
+
end
|
26
|
+
|
27
|
+
it "should create a has_many association correclty" do
|
28
|
+
mt = Profitbricks::ModelHasManyTest.new( :model_tests => {:name => 'One'} )
|
29
|
+
mt.model_tests.count.should == 1
|
30
|
+
mt.model_tests.first.name.should == 'One'
|
31
|
+
end
|
32
|
+
|
33
|
+
it "should create a has_many association with two entries correclty" do
|
34
|
+
mt = Profitbricks::ModelHasManyTest.new( :model_tests => [{:name => 'One'}, {:name => 'Two'}] )
|
35
|
+
mt.model_tests.count.should == 2
|
36
|
+
mt.model_tests.first.name.should == 'One'
|
37
|
+
mt.model_tests.last.name.should == 'Two'
|
38
|
+
end
|
39
|
+
|
40
|
+
it "should create a belongs_to association correclty" do
|
41
|
+
mt = Profitbricks::ModelBelongsToTest.new( :model_has_many_test => {:name => 'One'} )
|
42
|
+
mt.model_has_many_test.class.should == Profitbricks::ModelHasManyTest
|
43
|
+
mt.model_has_many_test.name.should == 'One'
|
44
|
+
end
|
45
|
+
|
46
|
+
it "should raise an LoadError exception" do
|
47
|
+
lambda {
|
48
|
+
module Profitbricks
|
49
|
+
class Profitbricks::InvalidAssociation < Profitbricks::Model
|
50
|
+
belongs_to :non_existant
|
51
|
+
end
|
52
|
+
end
|
53
|
+
}.should raise_error(LoadError)
|
54
|
+
end
|
55
|
+
describe "get_xml_and_update_attributes" do
|
56
|
+
it "should execute update_attributes correclty" do
|
57
|
+
mt = Profitbricks::ModelTest.new({:name => 'Test', :camel_case => 'works'})
|
58
|
+
xml = mt.get_xml_and_update_attributes({:name => 'Test2', :camel_case => 'fails?'}, [:name, :camel_case])
|
59
|
+
xml.should == "<camelCase>fails?</camelCase><modelTestName>Test2</modelTestName>"
|
60
|
+
mt.name.should == 'Test2'
|
61
|
+
mt.camel_case.should == 'fails?'
|
62
|
+
end
|
63
|
+
it "should work as class method" do
|
64
|
+
xml = Profitbricks::ModelTest.get_xml_and_update_attributes({:name => 'Test2', :camel_case => 'fails?'}, [:name, :camel_case])
|
65
|
+
xml.should == "<camelCase>fails?</camelCase><modelTestName>Test2</modelTestName>"
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
@@ -0,0 +1,55 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Profitbricks::Nic do
|
4
|
+
include Savon::Spec::Macros
|
5
|
+
|
6
|
+
it "create a new Nic" do
|
7
|
+
savon.expects(:create_nic).returns(:success)
|
8
|
+
savon.expects(:get_nic).returns(:success)
|
9
|
+
nic = Nic.create(:lan_id => 1, :ip => "192.168.0.11", :name => "Internal", :server_id => "4cb6550f-3777-4818-8f4c-51233162a980")
|
10
|
+
nic.name.should == "Internal"
|
11
|
+
nic.lan_id.should == 1
|
12
|
+
nic.ip.should == "192.168.0.11"
|
13
|
+
end
|
14
|
+
|
15
|
+
it "should update an existing Nic" do
|
16
|
+
savon.expects(:get_nic).returns(:success)
|
17
|
+
savon.expects(:update_nic).returns(:success)
|
18
|
+
nic = Nic.find(:id => "cba8af39-b5de-477b-9795-2f02ea9cf04f")
|
19
|
+
nic.update(:name => "External").should == true
|
20
|
+
nic.name.should == "External"
|
21
|
+
end
|
22
|
+
|
23
|
+
it "should set the internet access" do
|
24
|
+
savon.expects(:get_nic).returns(:success)
|
25
|
+
savon.expects(:set_internet_access).returns(:success)
|
26
|
+
nic = Nic.find(:id => "cba8af39-b5de-477b-9795-2f02ea9cf04f")
|
27
|
+
(nic.set_internet_access = true).should == true
|
28
|
+
end
|
29
|
+
|
30
|
+
it "should be deleted" do
|
31
|
+
savon.expects(:get_nic).returns(:success)
|
32
|
+
savon.expects(:delete_nic).returns(:success)
|
33
|
+
nic = Nic.find(:id => "cba8af39-b5de-477b-9795-2f02ea9cf04f")
|
34
|
+
nic.delete.should == true
|
35
|
+
end
|
36
|
+
|
37
|
+
it "should add an ip" do
|
38
|
+
savon.expects(:get_nic).returns(:success)
|
39
|
+
savon.expects(:add_public_ip_to_nic).returns(:success)
|
40
|
+
nic = Nic.find(:id => "cba8af39-b5de-477b-9795-2f02ea9cf04f")
|
41
|
+
nic.add_ip("46.16.74.13")
|
42
|
+
nic.ips.count.should == 2
|
43
|
+
lambda {
|
44
|
+
nic.ip
|
45
|
+
}.should raise_error ArgumentError
|
46
|
+
end
|
47
|
+
|
48
|
+
it "should remove an ip" do
|
49
|
+
savon.expects(:get_nic).returns(:success)
|
50
|
+
savon.expects(:remove_public_ip_from_nic).returns(:success)
|
51
|
+
nic = Nic.find(:id => "cba8af39-b5de-477b-9795-2f02ea9cf04f")
|
52
|
+
nic.remove_ip("46.16.74.13")
|
53
|
+
nic.ips.count.should == 1
|
54
|
+
end
|
55
|
+
end
|
@@ -0,0 +1,41 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Profitbricks::Server do
|
4
|
+
include Savon::Spec::Macros
|
5
|
+
|
6
|
+
it "should create a new server with minimal arguments" do
|
7
|
+
savon.expects(:create_server).returns(:minimal)
|
8
|
+
savon.expects(:get_server).returns(:after_create)
|
9
|
+
s = Server.create(:cores => 1, :ram => 256, :name => 'Test Server', :data_center_id => "b3eebede-5c78-417c-b1bc-ff5de01a0602")
|
10
|
+
s.cores.should == 1
|
11
|
+
s.ram.should == 256
|
12
|
+
s.name.should == 'Test Server'
|
13
|
+
s.data_center_id.should == "b3eebede-5c78-417c-b1bc-ff5de01a0602"
|
14
|
+
end
|
15
|
+
it "should reboot on request" do
|
16
|
+
savon.expects(:get_server).returns(:after_create)
|
17
|
+
savon.expects(:reboot_server).returns(:success)
|
18
|
+
s = Server.find(:id => "b3eebede-5c78-417c-b1bc-ff5de01a0602")
|
19
|
+
s.reboot.should == true
|
20
|
+
end
|
21
|
+
|
22
|
+
it "should be deleted" do
|
23
|
+
savon.expects(:get_server).returns(:after_create)
|
24
|
+
savon.expects(:delete_server).returns(:success)
|
25
|
+
s = Server.find(:id => "b3eebede-5c78-417c-b1bc-ff5de01a0602")
|
26
|
+
s.delete.should == true
|
27
|
+
end
|
28
|
+
|
29
|
+
describe "updating" do
|
30
|
+
it "should update basic attributes correctly" do
|
31
|
+
savon.expects(:get_server).returns(:after_create)
|
32
|
+
savon.expects(:update_server).returns(:basic)
|
33
|
+
s = Server.find(:id => "b3eebede-5c78-417c-b1bc-ff5de01a0602")
|
34
|
+
s.update(:cores => 2, :ram => 512, :name => "Power of two", :os_type => 'WINDOWS')
|
35
|
+
s.cores.should == 2
|
36
|
+
s.ram.should == 512
|
37
|
+
s.name.should == "Power of two"
|
38
|
+
s.os_type.should == 'WINDOWS'
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|