Skip to content

Commit

Permalink
Merge pull request #4 from StackPointCloud/master
Browse files Browse the repository at this point in the history
Adjusted model delete method to retain requestId
  • Loading branch information
edevenport committed Sep 23, 2015
2 parents 6ffe9e1 + 46f4d7b commit 617c750
Show file tree
Hide file tree
Showing 21 changed files with 60 additions and 73 deletions.
4 changes: 3 additions & 1 deletion lib/profitbricks/datacenter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,13 @@ module ProfitBricks
# Datacenter class
class Datacenter < ProfitBricks::Model
def delete
ProfitBricks.request(
response = ProfitBricks.request(
method: :delete,
path: "/datacenters/#{self.id}",
expects: 202
)
self.requestId = response[:requestId]
self
end

def update(options = {})
Expand Down
4 changes: 3 additions & 1 deletion lib/profitbricks/firewall.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,13 @@ class Firewall < ProfitBricks::Model

# Delete the firewall rule.
def delete
ProfitBricks.request(
response = ProfitBricks.request(
method: :delete,
path: "/datacenters/#{self.datacenterId}/servers/#{self.serverId}/nics/#{self.nicId}/firewallrules/#{self.id}",
expects: 202
)
self.requestId = response[:requestId]
self
end

# Update the firewall rule.
Expand Down
4 changes: 3 additions & 1 deletion lib/profitbricks/lan.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,13 @@ class LAN < ProfitBricks::Model

# Delete the LAN.
def delete
ProfitBricks.request(
response = ProfitBricks.request(
method: :delete,
path: "/datacenters/#{self.datacenterId}/lans/#{self.id}",
expects: 202
)
self.requestId = response[:requestId]
self
end

# Update the LAN.
Expand Down
4 changes: 3 additions & 1 deletion lib/profitbricks/loadbalancer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,13 @@ module ProfitBricks
class Loadbalancer < ProfitBricks::Model
# Delete the loadbalancer.
def delete
ProfitBricks.request(
response = ProfitBricks.request(
method: :delete,
path: "/datacenters/#{self.datacenterId}/loadbalancers/#{self.id}",
expects: 202
)
self.requestId = response[:requestId]
self
end

# Update the loadbalancer.
Expand Down
4 changes: 3 additions & 1 deletion lib/profitbricks/nic.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,13 @@ class NIC < ProfitBricks::Model

# Delete the NIC.
def delete
ProfitBricks.request(
response = ProfitBricks.request(
method: :delete,
path: "/datacenters/#{self.datacenterId}/servers/#{self.serverId}/nics/#{self.id}",
expects: 202
)
self.requestId = response[:requestId]
self
end

# Update the NIC.
Expand Down
4 changes: 3 additions & 1 deletion lib/profitbricks/server.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,13 @@ module ProfitBricks
class Server < ProfitBricks::Model
# Delete the server.
def delete
ProfitBricks.request(
response = ProfitBricks.request(
method: :delete,
path: "/datacenters/#{datacenterId}/servers/#{id}",
expects: 202
)
self.requestId = response[:requestId]
self
end

# Update the server.
Expand Down
4 changes: 3 additions & 1 deletion lib/profitbricks/snapshot.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,13 @@ class Snapshot < ProfitBricks::Model

# Delete the snapshot.
def delete
ProfitBricks.request(
response = ProfitBricks.request(
method: :delete,
path: "/snapshots/#{self.id}",
expects: 202
)
self.requestId = response[:requestId]
self
end

# Update the snapshot.
Expand Down
2 changes: 1 addition & 1 deletion lib/profitbricks/version.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module ProfitBricks
VERSION = "1.0.4"
VERSION = "1.0.5"
end
4 changes: 3 additions & 1 deletion lib/profitbricks/volume.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,13 @@ class Volume < ProfitBricks::Model

# Delete the volume.
def delete
ProfitBricks.request(
response = ProfitBricks.request(
method: :delete,
path: "/datacenters/#{self.datacenterId}/volumes/#{self.id}",
expects: 202
)
self.requestId = response[:requestId]
self
end

# Update the volume.
Expand Down
32 changes: 9 additions & 23 deletions spec/datacenter_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,7 @@

it '#create' do
expect(@datacenter.type).to eq('datacenter')
expect(@datacenter.id).to match(
/^[a-f0-9]{8}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{12}$/i
)
expect(@datacenter.id).to match(options[:uuid])
expect(@datacenter.properties['name']).to eq('Ruby SDK Datacenter')
expect(@datacenter.properties['description']).to eq('SDK test environment')
expect(@datacenter.properties['location']).to eq('de/fkb')
Expand All @@ -37,9 +35,7 @@

expect(datacenters.count).to be > 0
expect(datacenters[0].type).to eq('datacenter')
expect(datacenters[0].id).to match(
/^[a-f0-9]{8}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{12}$/i
)
expect(datacenters[0].id).to match(options[:uuid])
end

it '#get' do
Expand Down Expand Up @@ -68,17 +64,15 @@
datacenter = ProfitBricks::Datacenter.create(options[:datacenter])
datacenter.wait_for { ready? }

expect(datacenter.delete).to be_kind_of(Hash)
expect(datacenter.delete.requestId).to match(options[:uuid])
expect(datacenter.wait_for { ready? }).to be_kind_of(Hash)
end

it '#list_servers' do
servers = @datacenter.list_servers

expect(servers[0].type).to eq('server')
expect(servers[0].id).to match(
/^[a-f0-9]{8}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{12}$/i
)
expect(servers[0].id).to match(options[:uuid])
expect(servers[0].properties['name']).to eq('New Server')
expect(servers[0].properties['cores']).to be_kind_of(Integer)
expect(servers[0].properties['ram']).to eq(1024)
Expand All @@ -92,9 +86,7 @@
server = @datacenter.get_server(@server.id)

expect(server.type).to eq('server')
expect(server.id).to match(
/^[a-f0-9]{8}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{12}$/i
)
expect(server.id).to match(options[:uuid])
expect(server.properties['name']).to eq('New Server')
expect(server.properties['cores']).to be_kind_of(Integer)
expect(server.properties['ram']).to eq(1024)
Expand Down Expand Up @@ -122,9 +114,7 @@
volumes = @datacenter.list_volumes

expect(volumes[0].type).to eq('volume')
expect(volumes[0].id).to match(
/^[a-f0-9]{8}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{12}$/i
)
expect(volumes[0].id).to match(options[:uuid])
expect(volumes[0].properties['name']).to eq('my boot volume for server 1')
expect(volumes[0].properties['size']).to eq(10)
expect(volumes[0].properties['bus']).to be nil
Expand All @@ -139,9 +129,7 @@
volume = @datacenter.get_volume(@volume.id)

expect(volume.type).to eq('volume')
expect(volume.id).to match(
/^[a-f0-9]{8}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{12}$/i
)
expect(volume.id).to match(options[:uuid])
expect(volume.properties['name']).to eq('my boot volume for server 1')
expect(volume.properties['size']).to eq(10)
expect(volume.properties['bus']).to be nil
Expand All @@ -157,9 +145,7 @@
volume = @datacenter.get_volume(@volume.id)

expect(volume.type).to eq('volume')
expect(volume.id).to match(
/^[a-f0-9]{8}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{12}$/i
)
expect(volume.id).to match(options[:uuid])
expect(volume.properties['name']).to eq('my boot volume for server 1')
expect(volume.properties['size']).to eq(10)
expect(volume.properties['bus']).to be nil
Expand Down Expand Up @@ -207,7 +193,7 @@
expect(lans[0].type).to eq('lan')
expect(lans[0].id).to match(/^\d+$/)
expect(lans[0].properties['name']).to eq('public Lan 4')
expect(lans[0].properties['public']).to be false
expect(lans[0].properties['public']).to be true
end

it '#get_lan' do
Expand Down
4 changes: 2 additions & 2 deletions spec/firewall_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@

it '#create' do
expect(@fwrule.type).to eq('firewall-rule')
expect(@fwrule.id).to be_kind_of(String)
expect(@fwrule.id).to match(options[:uuid])
expect(@fwrule.properties['name']).to eq('SSH')
expect(@fwrule.properties['protocol']).to eq('TCP')
expect(@fwrule.properties['sourceMac']).to eq('01:23:45:67:89:00')
Expand Down Expand Up @@ -90,6 +90,6 @@
fwrule = ProfitBricks::Firewall.create(@datacenter.id, @server.id, @nic.id, options[:fwrule])
fwrule.wait_for { ready? }

expect(fwrule.delete).to have_key(:requestId)
expect(fwrule.delete.requestId).to match(options[:uuid])
end
end
4 changes: 2 additions & 2 deletions spec/image_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
it '#list' do
expect(@images.count).to be > 0
expect(@images[0].type).to eq('image')
expect(@images[0].id).to be_kind_of(String)
expect(@images[0].id).to match(options[:uuid])
expect(@images[0].properties['name']).to be_kind_of(String)
expect(@images[0].properties['description']).to be nil
expect(@images[0].properties['location']).to match(/\w+\/\w+/)
Expand All @@ -19,7 +19,7 @@
image = ProfitBricks::Image.get(@images[0].id)

expect(image.type).to eq('image')
expect(image.id).to be_kind_of(String)
expect(image.id).to match(options[:uuid])
expect(image.properties['name']).to be_kind_of(String)
expect(image.properties['description']).to be nil
expect(image.properties['location']).to match(/\w+\/\w+/)
Expand Down
8 changes: 2 additions & 6 deletions spec/ipblock_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,7 @@
# alias: create
it '#reserve' do
expect(@ipblock.type).to eq('ipblock')
expect(@ipblock.id).to match(
/^[a-f0-9]{8}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{12}$/i
)
expect(@ipblock.id).to match(options[:uuid])
expect(@ipblock.properties['ips'].count).to be > 0
expect(@ipblock.properties['location']).to eq('de/fra')
expect(@ipblock.properties['size']).to eq(1)
Expand All @@ -25,9 +23,7 @@

expect(ipblocks.count).to be > 0
expect(ipblocks[0].type).to eq('ipblock')
expect(ipblocks[0].id).to match(
/^[a-f0-9]{8}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{12}$/i
)
expect(ipblocks[0].id).to match(options[:uuid])
expect(ipblocks[0].properties['ips'].count).to be > 0
expect(ipblocks[0].properties['location']).to eq('de/fra')
expect(ipblocks[0].properties['size']).to be_kind_of(Integer)
Expand Down
2 changes: 1 addition & 1 deletion spec/lan_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@
lan = ProfitBricks::LAN.create(@datacenter.id, options[:lan])
lan.wait_for { ready? }

expect(lan.delete).to be_kind_of(Hash)
expect(lan.delete.requestId).to match(options[:uuid])
end

it '#list_members' do
Expand Down
4 changes: 2 additions & 2 deletions spec/loadbalancer_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@

it '#create' do
expect(@loadbalancer.type).to eq('loadbalancer')
expect(@loadbalancer.id).to be_kind_of(String)
expect(@loadbalancer.id).to match(options[:uuid])
expect(@loadbalancer.properties['name']).to eq('My LB')
expect(@loadbalancer.properties['ip']).to be nil
expect(@loadbalancer.properties['dhcp']).to be true
Expand Down Expand Up @@ -75,7 +75,7 @@
loadbalancer = ProfitBricks::Loadbalancer.create(@datacenter.id, options[:loadbalancer])
loadbalancer.wait_for { ready? }

expect(loadbalancer.delete).to have_key(:requestId)
expect(loadbalancer.delete.requestId).to match(options[:uuid])
end

it '#list_balanced_nics' do
Expand Down
4 changes: 2 additions & 2 deletions spec/nic_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@

it '#create' do
expect(@nic.type).to eq('nic')
expect(@nic.id).to be_kind_of(String)
expect(@nic.id).to match(options[:uuid])
expect(@nic.properties['name']).to eq('nic1')
expect(@nic.properties['ips']).to be_kind_of(Array)
expect(@nic.properties['dhcp']).to be true
Expand Down Expand Up @@ -66,7 +66,7 @@
nic = ProfitBricks::NIC.create(@datacenter.id, @server.id, options[:nic])
nic.wait_for { ready? }

expect(nic.delete).to be_kind_of(Hash)
expect(nic.delete.requestId).to match(options[:uuid])
end

it '#list_firewall_rules' do
Expand Down
4 changes: 2 additions & 2 deletions spec/request_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,14 @@

expect(requests.count).to be > 0
expect(requests[0].type).to eq('request')
expect(requests[0].id).to be_kind_of(String)
expect(requests[0].id).to match(options[:uuid])
end

it '#get' do
request = ProfitBricks::Request.get(@request.id)

expect(request.type).to eq('request')
expect(request.id).to be_kind_of(String)
expect(request.id).to match(options[:uuid])
expect(request.properties['method']).to eq('POST')
end

Expand Down
Loading

0 comments on commit 617c750

Please sign in to comment.