1
0
Fork 0
mirror of https://github.com/fog/fog.git synced 2022-11-09 13:51:43 -05:00

Add joyent API version and network support GH-1853

Adding support for listing networks in the Joyent Cloud.
:joyent_version was defined in a way that it would always
fall back to the default '~6.5'. Creating servers with
a particular network requires setting :joyent_version to '~7.0'
or greater.
This commit is contained in:
Blake Irvin and Eric Saxby 2013-05-31 18:01:42 -07:00 committed by Kevin Chan
parent 8f2c84ae93
commit 5fc41c8dc2
5 changed files with 98 additions and 2 deletions

View file

@ -11,6 +11,7 @@ module Fog
recognizes :joyent_url
recognizes :joyent_keyname
recognizes :joyent_keyfile
recognizes :joyent_version
model_path 'fog/joyent/models/compute'
request_path 'fog/joyent/requests/compute'
@ -71,7 +72,10 @@ module Fog
request :delete_machine_tag
request :delete_all_machine_tags
# Networks
collection :networks
model :network
request :list_networks
class Mock
def self.data
@ -163,7 +167,7 @@ module Fog
response
rescue Excon::Errors::Error => e
raise_if_error(e.request, e.response)
raise_if_error!(e.request, e.response)
end
private

View file

@ -0,0 +1,12 @@
module Fog
module Compute
class Joyent
class Network < Fog::Model
identity :id
attribute :name
end
end
end
end

View file

@ -0,0 +1,15 @@
require 'fog/joyent/models/compute/network'
module Fog
module Compute
class Joyent
class Networks < Fog::Collection
model Fog::Compute::Joyent::Network
def all
load(service.list_networks.body)
end
end
end
end
end

View file

@ -0,0 +1,26 @@
module Fog
module Compute
class Joyent
class Mock
def list_networks(options={})
res = Excon::Response.new
res.status = 200
res.body = self.data[:networks].values
res
end
end
class Real
def list_networks(options={})
request(
:path => "/my/networks",
:method => "GET",
:query => options,
:expects => 200
)
end
end
end
end
end

View file

@ -0,0 +1,39 @@
Shindo.tests("Fog::Compute[:joyent] | network requests", ["joyent"]) do
@provider = Fog::Compute[:joyent]
@network_format = {
"id" => String,
"name" => String,
"public" => Fog::Boolean
}
if Fog.mock?
@networks = Fog::Compute[:joyent].data[:networks] = {
"193d6804-256c-4e89-a4cd-46f045959993" => {
"id" => "193d6804-256c-4e89-a4cd-46f045959993",
"name" => "Joyent-SDC-Private",
"public" => false
},
"1e7bb0e1-25a9-43b6-bb19-f79ae9540b39" => {
"id" => "1e7bb0e1-25a9-43b6-bb19-f79ae9540b39",
"name" => "Joyent-SDC-Public",
"public" => true
}
}
end
tests("#list_networks") do
if Fog.mock?
returns(@networks.length, "correct number of networks") do
@provider.list_networks.body.length
end
end
returns(Array, "returns an Array of networks") do
@provider.list_networks.body.class
end
formats([@network_format]) do
@provider.list_networks.body
end
end
end