profitbricks-sdk-ruby 3.0.2 → 4.0.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.
data/spec/image_spec.rb CHANGED
@@ -21,9 +21,32 @@ describe ProfitBricks::Image do
21
21
  expect(image.type).to eq('image')
22
22
  expect(image.id).to match(options[:uuid])
23
23
  expect(image.properties['name']).to be_kind_of(String)
24
+ expect(image.properties['name']).not_to be nil
24
25
  expect(image.properties['description']).to be nil
25
26
  expect(image.properties['location']).to match(/\w+\/\w+/)
26
27
  expect(image.properties['size']).to be > 0
28
+
29
+ expect(image.properties['cpuHotPlug']).to eq(true).or(eq(false))
30
+ expect(image.properties['cpuHotUnplug']).to eq(true).or(eq(false))
31
+ expect(image.properties['ramHotPlug']).to eq(true).or(eq(false))
32
+ expect(image.properties['ramHotUnplug']).to eq(true).or(eq(false))
33
+ expect(image.properties['nicHotPlug']).to eq(true).or(eq(false))
34
+ expect(image.properties['nicHotUnplug']).to eq(true).or(eq(false))
35
+ expect(image.properties['discVirtioHotPlug']).to eq(true).or(eq(false))
36
+ expect(image.properties['discVirtioHotUnplug']).to eq(true).or(eq(false))
37
+ expect(image.properties['discScsiHotPlug']).to eq(true).or(eq(false))
38
+ expect(image.properties['discScsiHotUnplug']).to eq(true).or(eq(false))
39
+ expect(image.properties['public']).to eq(true).or(eq(false))
40
+
41
+ expect(image.properties['imageAliases']).to be_an_instance_of(Array)
42
+
43
+ expect(image.properties).to have_key("location")
44
+ expect(image.properties).to have_key("licenceType")
45
+ expect(image.properties).to have_key("imageType")
46
+ end
47
+
48
+ it '#get failure' do
49
+ expect { ProfitBricks::Image.get(options[:bad_id]) }.to raise_error(Excon::Error::NotFound, /Resource does not exist/)
27
50
  end
28
51
 
29
52
  # Unable to test in production due to public images.
data/spec/ipblock_spec.rb CHANGED
@@ -14,8 +14,13 @@ describe ProfitBricks::IPBlock do
14
14
  expect(@ipblock.type).to eq('ipblock')
15
15
  expect(@ipblock.id).to match(options[:uuid])
16
16
  expect(@ipblock.properties['ips'].count).to be > 0
17
- expect(@ipblock.properties['location']).to eq('de/fra')
18
- expect(@ipblock.properties['size']).to eq(1)
17
+ expect(@ipblock.properties['name']).to eq('Ruby SDK Test')
18
+ expect(@ipblock.properties['location']).to eq('us/las')
19
+ expect(@ipblock.properties['size']).to eq(2)
20
+ end
21
+
22
+ it '#reserve failure' do
23
+ expect { ProfitBricks::IPBlock.reserve({ name: 'Ruby SDK Test', size: '1' }) }.to raise_error(Excon::Error::UnprocessableEntity, /Attribute 'location' is required/)
19
24
  end
20
25
 
21
26
  it '#list' do
@@ -25,7 +30,7 @@ describe ProfitBricks::IPBlock do
25
30
  expect(ipblocks[0].type).to eq('ipblock')
26
31
  expect(ipblocks[0].id).to match(options[:uuid])
27
32
  expect(ipblocks[0].properties['ips'].count).to be > 0
28
- expect(ipblocks[0].properties['location']).to eq('de/fra')
33
+ expect(ipblocks[0].properties['location']).to eq('us/las')
29
34
  expect(ipblocks[0].properties['size']).to be_kind_of(Integer)
30
35
  end
31
36
 
@@ -34,9 +39,14 @@ describe ProfitBricks::IPBlock do
34
39
 
35
40
  expect(ipblock.type).to eq('ipblock')
36
41
  expect(ipblock.id).to eq(@ipblock.id)
37
- expect(ipblock.properties['ips'].count).to be > 0
38
- expect(ipblock.properties['location']).to eq('de/fra')
39
- expect(ipblock.properties['size']).to eq(1)
42
+ expect(ipblock.properties['ips'].count).to eq(2)
43
+ expect(ipblock.properties['name']).to eq('Ruby SDK Test')
44
+ expect(ipblock.properties['location']).to eq('us/las')
45
+ expect(ipblock.properties['size']).to eq(2)
46
+ end
47
+
48
+ it '#get failure' do
49
+ expect { ProfitBricks::IPBlock.get(options[:bad_id]) }.to raise_error(Excon::Error::NotFound, /Resource does not exist/)
40
50
  end
41
51
 
42
52
  # alias: delete
data/spec/lan_spec.rb CHANGED
@@ -13,26 +13,46 @@ describe ProfitBricks::LAN do
13
13
 
14
14
  @nic = ProfitBricks::NIC.create(@datacenter.id, @server.id, lan: @lan.id)
15
15
  @nic.wait_for { ready? }
16
+
17
+ @ip_block = ProfitBricks::IPBlock.reserve(options[:ipblock_failover])
18
+ @ip_block.wait_for { ready? }
16
19
  end
17
20
 
18
21
  after(:all) do
19
22
  @datacenter.delete
23
+ @datacenter.wait_for { ready? }
24
+ @ip_block.release
25
+ @ip_block.wait_for { ready? }
20
26
  end
21
27
 
22
28
  it '#create' do
23
29
  expect(@lan.type).to eq('lan')
24
30
  expect(@lan.id).to match(/^\d+$/)
25
- expect(@lan.properties['name']).to eq('public Lan 4')
31
+ expect(@lan.properties['name']).to eq('Ruby SDK Test')
26
32
  expect(@lan.properties['public']).to be true
27
33
  end
28
34
 
35
+ # it '#create failure' do
36
+ # expect { ProfitBricks::LAN.create(options[:bad_id], options[:bad_lan]) }.to raise_error(Excon::Error::UnprocessableEntity, /Attribute 'location' is required/)
37
+ # end
38
+
39
+ it '#create composite' do
40
+ create_data=options[:lan]
41
+ nics=[@nic.id]
42
+ create_data['nics']=nics
43
+ @lan_composite = ProfitBricks::LAN.create(@datacenter.id,create_data)
44
+ @lan_composite.wait_for { ready? }
45
+ expect(@lan_composite.type).to eq('lan')
46
+ expect(@lan_composite.entities['nics']['items'].size).to eq(1)
47
+ end
48
+
29
49
  it '#list' do
30
50
  lans = ProfitBricks::LAN.list(@datacenter.id)
31
51
 
32
52
  expect(lans.count).to be > 0
33
53
  expect(lans[0].type).to eq('lan')
34
54
  expect(lans[0].id).to match(/^\d+$/)
35
- expect(lans[0].properties['name']).to eq('public Lan 4')
55
+ expect(lans[0].properties['name']).to eq('Ruby SDK Test')
36
56
  expect(lans[0].properties['public']).to be true
37
57
  end
38
58
 
@@ -41,30 +61,53 @@ describe ProfitBricks::LAN do
41
61
 
42
62
  expect(lan.type).to eq('lan')
43
63
  expect(lan.id).to eq(@lan.id)
44
- expect(lan.properties['name']).to eq('public Lan 4')
64
+ expect(lan.properties['name']).to eq('Ruby SDK Test')
45
65
  expect(lan.properties['public']).to be true
46
66
  end
47
67
 
68
+ it '#get failure' do
69
+ expect { ProfitBricks::LAN.get(@datacenter.id,options[:bad_id]) }.to raise_error(Excon::Error::NotFound, /Resource does not exist/)
70
+ end
71
+
48
72
  it '#update' do
49
- lan = @lan.update(public: 'false')
73
+ lan = @lan.update({ public: false, name: 'Ruby SDK Test - RENAME' })
50
74
 
51
75
  expect(lan.type).to eq('lan')
52
76
  expect(lan.id).to eq(@lan.id)
53
- expect(lan.properties['name']).to eq('public Lan 4')
77
+ expect(lan.properties['name']).to eq('Ruby SDK Test - RENAME')
54
78
  expect(lan.properties['public']).to be false
55
79
  end
56
80
 
57
- it '#delete' do
81
+ it '#update_ip_failover' do
82
+ ip = @ip_block.properties['ips'][0]
83
+
84
+ server1 = ProfitBricks::Server.create(@datacenter.id, options[:server])
85
+ server1.wait_for { ready? }
86
+
58
87
  lan = ProfitBricks::LAN.create(@datacenter.id, options[:lan])
59
88
  lan.wait_for { ready? }
60
89
 
61
- expect(lan.delete.requestId).to match(options[:uuid])
90
+ nic = ProfitBricks::NIC.create(@datacenter.id, server1.id, { lan: lan.id, ips: [ip] })
91
+ nic.wait_for { ready? }
92
+
93
+ ip_failover = {}
94
+ ip_failover['ip'] = ip
95
+ ip_failover['nicUuid'] = nic.id
96
+
97
+ lan.update({ipFailover: [ip_failover]})
98
+ lan.wait_for { ready? }
99
+
100
+ server2 = ProfitBricks::Server.create(@datacenter.id, options[:server])
101
+ server2.wait_for { ready? }
102
+
103
+ nic2 = ProfitBricks::NIC.create(@datacenter.id, server2.id, { lan: lan.id, ips: [ip] })
104
+ nic2.wait_for { ready? }
62
105
  end
63
106
 
64
- it '#list_members' do
65
- members = @lan.list_members
107
+ it '#delete' do
108
+ lan = ProfitBricks::LAN.create(@datacenter.id, options[:lan])
109
+ lan.wait_for { ready? }
66
110
 
67
- expect(members.count).to be > 0
68
- expect(members[0].type).to eq('nic')
111
+ expect(lan.delete.requestId).to match(options[:uuid])
69
112
  end
70
113
  end
@@ -28,20 +28,24 @@ describe ProfitBricks::Loadbalancer do
28
28
  it '#create' do
29
29
  expect(@loadbalancer.type).to eq('loadbalancer')
30
30
  expect(@loadbalancer.id).to match(options[:uuid])
31
- expect(@loadbalancer.properties['name']).to eq('My LB')
31
+ expect(@loadbalancer.properties['name']).to eq('Ruby SDK Test')
32
32
  expect(@loadbalancer.properties['ip']).to be nil
33
33
  expect(@loadbalancer.properties['dhcp']).to be true
34
34
  expect(@loadbalancer.entities).to be nil
35
35
  end
36
36
 
37
+ it '#create failure' do
38
+ expect { ProfitBricks::Loadbalancer.create(options[:bad_id], options[:bad_loadbalancer]) }.to raise_error(Excon::Error::NotFound)
39
+ end
40
+
37
41
  it '#list' do
38
42
  loadbalancers = ProfitBricks::Loadbalancer.list(@datacenter.id)
39
43
 
40
44
  expect(loadbalancers.count).to be > 0
41
45
  expect(loadbalancers[0].type).to eq('loadbalancer')
42
46
  expect(loadbalancers[0].id).to eq(@loadbalancer.id)
43
- expect(loadbalancers[0].properties['name']).to eq('My LB')
44
- expect(loadbalancers[0].properties['ip']).to be_kind_of(String)
47
+ expect(loadbalancers[0].properties['name']).to eq('Ruby SDK Test')
48
+ expect(loadbalancers[0].properties['ip']).not_to be nil
45
49
  expect(loadbalancers[0].properties['dhcp']).to be true
46
50
  expect(loadbalancers[0].entities).to be_kind_of(Hash)
47
51
  end
@@ -51,22 +55,26 @@ describe ProfitBricks::Loadbalancer do
51
55
 
52
56
  expect(loadbalancer.type).to eq('loadbalancer')
53
57
  expect(loadbalancer.id).to eq(@loadbalancer.id)
54
- expect(loadbalancer.properties['name']).to eq('My LB')
58
+ expect(loadbalancer.properties['name']).to eq('Ruby SDK Test')
55
59
  expect(loadbalancer.properties['ip']).to be_kind_of(String)
56
60
  expect(loadbalancer.properties['dhcp']).to be true
57
61
  expect(loadbalancer.entities).to be_kind_of(Hash)
58
62
  end
59
63
 
64
+ it '#get failure' do
65
+ expect { ProfitBricks::Loadbalancer.get(@datacenter.id, options[:bad_id]) }.to raise_error(Excon::Error::NotFound)
66
+ end
67
+
60
68
  it '#update' do
61
69
  loadbalancer = @loadbalancer.update(
62
- ip: '10.1.1.2'
70
+ name: 'Ruby SDK Test - RENAME'
63
71
  )
64
72
  loadbalancer.wait_for { ready? }
65
73
 
66
74
  expect(loadbalancer.type).to eq('loadbalancer')
67
75
  expect(loadbalancer.id).to eq(@loadbalancer.id)
68
- expect(loadbalancer.properties['name']).to eq('My LB')
69
- expect(loadbalancer.properties['ip']).to eq('10.1.1.2')
76
+ expect(loadbalancer.properties['name']).to eq('Ruby SDK Test - RENAME')
77
+ #expect(loadbalancer.properties['ip']).to eq('10.1.1.2')
70
78
  expect(loadbalancer.properties['dhcp']).to be true
71
79
  expect(loadbalancer.entities).to be nil
72
80
  end
@@ -83,7 +91,7 @@ describe ProfitBricks::Loadbalancer do
83
91
 
84
92
  expect(balanced_nics.count).to be > 0
85
93
  expect(balanced_nics[0].type).to eq('nic')
86
- expect(balanced_nics[0].properties['name']).to eq('nic1')
94
+ expect(balanced_nics[0].properties['name']).to eq('Ruby SDK Test')
87
95
  expect(balanced_nics[0].properties['ips']).to be_kind_of(Array)
88
96
  expect(balanced_nics[0].properties['dhcp']).to be true
89
97
  expect(balanced_nics[0].properties['lan']).to be_kind_of(Integer)
@@ -93,17 +101,21 @@ describe ProfitBricks::Loadbalancer do
93
101
  balanced_nic = @loadbalancer.get_balanced_nic(@nic.id)
94
102
 
95
103
  expect(balanced_nic.type).to eq('nic')
96
- expect(balanced_nic.properties['name']).to eq('nic1')
104
+ expect(balanced_nic.properties['name']).to eq('Ruby SDK Test')
97
105
  expect(balanced_nic.properties['ips']).to be_kind_of(Array)
106
+ expect(balanced_nic.properties['ips'].count).to be > 0
98
107
  expect(balanced_nic.properties['dhcp']).to be true
99
108
  expect(balanced_nic.properties['lan']).to be_kind_of(Integer)
109
+ expect(balanced_nic.properties['nat']).to eq(true).or(eq(false))
110
+ expect(balanced_nic.properties['firewallActive']).to eq(true).or(eq(false))
111
+ expect(balanced_nic.properties['mac']).to match(options[:mac_addres])
100
112
  end
101
113
 
102
114
  it '#associate_balanced_nic' do
103
115
  balanced_nic = @loadbalancer.associate_balanced_nic(@nic.id)
104
116
 
105
117
  expect(balanced_nic.type).to eq('nic')
106
- expect(balanced_nic.properties['name']).to eq('nic1')
118
+ expect(balanced_nic.properties['name']).to eq('Ruby SDK Test')
107
119
  expect(balanced_nic.properties['ips']).to be_kind_of(Array)
108
120
  expect(balanced_nic.properties['dhcp']).to be true
109
121
  expect(balanced_nic.properties['lan']).to be_kind_of(Integer)
@@ -8,13 +8,19 @@ describe ProfitBricks::Location do
8
8
  expect(@locations[0].type).to eq('location')
9
9
  expect(@locations[0].id).to match(/^\w+\/\w+$/)
10
10
  expect(@locations[0].properties['name']).to be_kind_of(String)
11
+ expect(@locations.find { |item| item.id == 'us/las' }).to_not be_nil
11
12
  end
12
13
 
13
14
  it '#get' do
14
15
  location = ProfitBricks::Location.get('us/las')
15
16
 
17
+ expect(location.id).to eq('us/las')
16
18
  expect(location.type).to eq('location')
17
19
  expect(location.id).to match(/^\w+\/\w+$/)
18
20
  expect(location.properties['name']).to be_kind_of(String)
19
21
  end
22
+
23
+ it '#get failure' do
24
+ expect { ProfitBricks::Location.get("us/aa") }.to raise_error(Excon::Error::NotFound, /Resource does not exist/)
25
+ end
20
26
  end
data/spec/nic_spec.rb CHANGED
@@ -22,10 +22,16 @@ describe ProfitBricks::NIC do
22
22
  it '#create' do
23
23
  expect(@nic.type).to eq('nic')
24
24
  expect(@nic.id).to match(options[:uuid])
25
- expect(@nic.properties['name']).to eq('nic1')
25
+ expect(@nic.properties['name']).to eq('Ruby SDK Test')
26
26
  expect(@nic.properties['ips']).to be_kind_of(Array)
27
27
  expect(@nic.properties['dhcp']).to be true
28
+ expect(@nic.properties['firewallActive']).to be true
28
29
  expect(@nic.properties['lan']).to eq(1)
30
+ expect(@nic.properties['nat']).to be false
31
+ end
32
+
33
+ it '#create failure' do
34
+ expect { ProfitBricks::NIC.create(@datacenter.id, @server.id, name: 'Ruby SDK Test') }.to raise_error(Excon::Error::UnprocessableEntity, /Attribute 'lan' is required/)
29
35
  end
30
36
 
31
37
  it '#list' do
@@ -34,7 +40,7 @@ describe ProfitBricks::NIC do
34
40
  expect(nics.count).to be > 0
35
41
  expect(nics[0].type).to eq('nic')
36
42
  expect(nics[0].id).to eq(@nic.id)
37
- expect(nics[0].properties['name']).to eq('nic1')
43
+ expect(nics[0].properties['name']).to eq('Ruby SDK Test')
38
44
  expect(nics[0].properties['ips']).to be_kind_of(Array)
39
45
  expect(nics[0].properties['dhcp']).to be true
40
46
  expect(nics[0].properties['lan']).to eq(1)
@@ -45,18 +51,24 @@ describe ProfitBricks::NIC do
45
51
 
46
52
  expect(nic.type).to eq('nic')
47
53
  expect(nic.id).to eq(@nic.id)
48
- expect(nic.properties['name']).to eq('nic1')
54
+ expect(nic.properties['name']).to eq('Ruby SDK Test')
49
55
  expect(nic.properties['ips']).to be_kind_of(Array)
50
56
  expect(nic.properties['dhcp']).to be true
51
57
  expect(nic.properties['lan']).to eq(1)
58
+ expect(nic.properties['firewallActive']).to be true
59
+ expect(nic.properties['nat']).to be false
60
+ end
61
+
62
+ it '#get failure' do
63
+ expect { ProfitBricks::NIC.get(@datacenter.id, @server.id, options[:bad_id]) }.to raise_error(Excon::Error::NotFound, /Resource does not exist/)
52
64
  end
53
65
 
54
66
  it '#update' do
55
- nic = @nic.update(ips: ['10.1.1.1', '10.1.1.2'])
67
+ nic = @nic.update(name: 'Ruby SDK Test - RENAME')
56
68
 
57
69
  expect(nic.type).to eq('nic')
58
70
  expect(nic.id).to eq(@nic.id)
59
- expect(nic.properties['name']).to eq('nic1')
71
+ expect(nic.properties['name']).to eq('Ruby SDK Test - RENAME')
60
72
  expect(nic.properties['ips']).to be_kind_of(Array)
61
73
  expect(nic.properties['dhcp']).to be true
62
74
  expect(nic.properties['lan']).to eq(1)
data/spec/request_spec.rb CHANGED
@@ -28,10 +28,15 @@ describe ProfitBricks::Request do
28
28
  expect(request.properties['method']).to eq('POST')
29
29
  end
30
30
 
31
+ it '#get failure' do
32
+ expect { ProfitBricks::Request.get(options[:bad_id]) }.to raise_error(Excon::Error::NotFound, /Resource does not exist/)
33
+ end
34
+
31
35
  it '#status' do
32
36
  status = @request.status
33
37
 
34
38
  expect(status.type).to eq('request-status')
39
+ expect(status.id).to eq("#{@request.id}/status")
35
40
  expect(status.metadata['status']).to eq('DONE')
36
41
  end
37
42
  end
@@ -0,0 +1,102 @@
1
+ require 'spec_helper'
2
+
3
+ describe ProfitBricks::Resource do
4
+ before(:all) do
5
+ @datacenter = ProfitBricks::Datacenter.create(options[:datacenter])
6
+ @datacenter.wait_for { ready? }
7
+
8
+ # images = ProfitBricks::Image.list
9
+ # @image = images[0]
10
+
11
+ @volume = ProfitBricks::Volume.create(@datacenter.id, options[:volume])
12
+ @volume.wait_for { ready? }
13
+
14
+ @snapshot = ProfitBricks::Snapshot.create(@datacenter.id, @volume.id, options[:snapshot])
15
+ @snapshot.wait_for { ready? }
16
+
17
+ @ipblock = ProfitBricks::IPBlock.reserve(options[:ipblock])
18
+ @ipblock.wait_for { ready? }
19
+ end
20
+
21
+ after(:all) do
22
+ @snapshot.delete
23
+ @volume.delete
24
+ @ipblock.release
25
+ @datacenter.delete
26
+ end
27
+
28
+ it '#list' do
29
+ resources = ProfitBricks::Resource.list
30
+
31
+ expect(resources.count).to be > 0
32
+ #expect(resources.type).to eq('collection')
33
+ end
34
+
35
+ it '#list datacenter' do
36
+ resources = ProfitBricks::Resource.list_by_type('datacenter')
37
+
38
+ expect(resources.count).to be > 0
39
+ expect(resources[0].type).to eq('datacenter')
40
+ end
41
+
42
+ # Unable to test in production at the moment. Images must be uploaded
43
+ # via FTP in production before a delete can be performed.
44
+ # it '#list image' do
45
+ # resources = ProfitBricks::Resource.list_by_type('image')
46
+ #
47
+ # expect(resources.count).to be > 0
48
+ # expect(resources[0].type).to eq('image')
49
+ # end
50
+
51
+ it '#list snapshot' do
52
+ resources = ProfitBricks::Resource.list_by_type('snapshot')
53
+
54
+ expect(resources.count).to be > 0
55
+ expect(resources[0].type).to eq('snapshot')
56
+ end
57
+
58
+ it '#list ipblock' do
59
+ resources = ProfitBricks::Resource.list_by_type('ipblock')
60
+
61
+ expect(resources.count).to be > 0
62
+ expect(resources[0].type).to eq('ipblock')
63
+ end
64
+
65
+ it '#list failure' do
66
+ expect { ProfitBricks::Resource.list_by_type('unknown') }.to raise_error(Excon::Error::NotFound)
67
+ end
68
+
69
+ it '#get datacenter' do
70
+ resource = ProfitBricks::Resource.get('datacenter', @datacenter.id)
71
+
72
+ expect(resource.id).to match(options[:uuid])
73
+ expect(resource.type).to eq('datacenter')
74
+ end
75
+
76
+ # Unable to test in production at the moment. Images must be uploaded
77
+ # via FTP in production before a delete can be performed.
78
+ # it '#get image' do
79
+ # resource = ProfitBricks::Resource.get('image', @image.id)
80
+ #
81
+ # expect(resource.id).to match(options[:uuid])
82
+ # expect(resource.type).to eq('image')
83
+ # end
84
+
85
+ it '#get snapshot' do
86
+ resource = ProfitBricks::Resource.get('snapshot', @snapshot.id)
87
+
88
+ expect(resource.id).to match(options[:uuid])
89
+ expect(resource.type).to eq('snapshot')
90
+ end
91
+
92
+ it '#get ipblock' do
93
+ resource = ProfitBricks::Resource.get('ipblock', @ipblock.id)
94
+
95
+ expect(resource.id).to match(options[:uuid])
96
+ expect(resource.type).to eq('ipblock')
97
+ end
98
+
99
+ it '#get failure' do
100
+ expect { ProfitBricks::Resource.get('unknown', options[:bad_id]) }.to raise_error(Excon::Error::NotFound)
101
+ end
102
+ end