mirror of
https://github.com/fog/fog.git
synced 2022-11-09 13:51:43 -05:00
[Brightbox] add support for User Applications
This commit is contained in:
parent
da46fd27f6
commit
7a4c0440a4
11 changed files with 225 additions and 0 deletions
|
@ -22,6 +22,8 @@ module Fog
|
|||
model_path 'fog/brightbox/models/compute'
|
||||
collection :accounts
|
||||
model :account
|
||||
collection :applications
|
||||
model :application
|
||||
collection :servers
|
||||
model :server
|
||||
collection :server_groups
|
||||
|
@ -51,6 +53,7 @@ module Fog
|
|||
request :apply_to_firewall_policy
|
||||
request :remove_firewall_policy
|
||||
request :create_api_client
|
||||
request :create_application
|
||||
request :create_cloud_ip
|
||||
request :create_firewall_policy
|
||||
request :create_firewall_rule
|
||||
|
@ -59,6 +62,7 @@ module Fog
|
|||
request :create_server
|
||||
request :create_server_group
|
||||
request :destroy_api_client
|
||||
request :destroy_application
|
||||
request :destroy_cloud_ip
|
||||
request :destroy_firewall_policy
|
||||
request :destroy_firewall_rule
|
||||
|
@ -68,6 +72,7 @@ module Fog
|
|||
request :destroy_server_group
|
||||
request :get_account
|
||||
request :get_api_client
|
||||
request :get_application
|
||||
request :get_cloud_ip
|
||||
request :get_firewall_policy
|
||||
request :get_firewall_rule
|
||||
|
@ -81,6 +86,7 @@ module Fog
|
|||
request :get_zone
|
||||
request :list_accounts
|
||||
request :list_api_clients
|
||||
request :list_applications
|
||||
request :list_cloud_ips
|
||||
request :list_firewall_policies
|
||||
request :list_images
|
||||
|
@ -97,6 +103,7 @@ module Fog
|
|||
request :remove_servers_server_group
|
||||
request :reset_ftp_password_account
|
||||
request :reset_secret_api_client
|
||||
request :reset_secret_application
|
||||
request :shutdown_server
|
||||
request :snapshot_server
|
||||
request :start_server
|
||||
|
@ -104,6 +111,7 @@ module Fog
|
|||
request :unmap_cloud_ip
|
||||
request :update_account
|
||||
request :update_api_client
|
||||
request :update_application
|
||||
request :update_cloud_ip
|
||||
request :update_firewall_rule
|
||||
request :update_image
|
||||
|
|
27
lib/fog/brightbox/models/compute/application.rb
Normal file
27
lib/fog/brightbox/models/compute/application.rb
Normal file
|
@ -0,0 +1,27 @@
|
|||
require 'fog/core/model'
|
||||
|
||||
module Fog
|
||||
module Compute
|
||||
class Brightbox
|
||||
|
||||
class Application < Fog::Model
|
||||
|
||||
identity :id
|
||||
attribute :url
|
||||
attribute :name
|
||||
attribute :secret
|
||||
|
||||
def save
|
||||
raise Fog::Errors::Error.new('Resaving an existing object may create a duplicate') if identity
|
||||
options = {
|
||||
:name => name
|
||||
}.delete_if {|k,v| v.nil? || v == "" }
|
||||
data = connection.create_application(options)
|
||||
merge_attributes(data)
|
||||
true
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
28
lib/fog/brightbox/models/compute/applications.rb
Normal file
28
lib/fog/brightbox/models/compute/applications.rb
Normal file
|
@ -0,0 +1,28 @@
|
|||
require 'fog/core/collection'
|
||||
require 'fog/brightbox/models/compute/application'
|
||||
|
||||
module Fog
|
||||
module Compute
|
||||
class Brightbox
|
||||
|
||||
class Applications < Fog::Collection
|
||||
|
||||
model Fog::Compute::Brightbox::Application
|
||||
|
||||
def all
|
||||
data = connection.list_applications
|
||||
load(data)
|
||||
end
|
||||
|
||||
def get(identifier)
|
||||
data = connection.get_application(identifier)
|
||||
new(data)
|
||||
rescue Excon::Errors::NotFound
|
||||
nil
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
13
lib/fog/brightbox/requests/compute/create_application.rb
Normal file
13
lib/fog/brightbox/requests/compute/create_application.rb
Normal file
|
@ -0,0 +1,13 @@
|
|||
module Fog
|
||||
module Compute
|
||||
class Brightbox
|
||||
class Real
|
||||
|
||||
def create_application(options)
|
||||
request("post", "/1.0/applications", [201], options)
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
14
lib/fog/brightbox/requests/compute/destroy_application.rb
Normal file
14
lib/fog/brightbox/requests/compute/destroy_application.rb
Normal file
|
@ -0,0 +1,14 @@
|
|||
module Fog
|
||||
module Compute
|
||||
class Brightbox
|
||||
class Real
|
||||
|
||||
def destroy_application(identifier)
|
||||
return nil if identifier.nil? || identifier == ""
|
||||
request("delete", "/1.0/applications/#{identifier}", [200])
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
14
lib/fog/brightbox/requests/compute/get_application.rb
Normal file
14
lib/fog/brightbox/requests/compute/get_application.rb
Normal file
|
@ -0,0 +1,14 @@
|
|||
module Fog
|
||||
module Compute
|
||||
class Brightbox
|
||||
class Real
|
||||
|
||||
def get_application(identifier)
|
||||
return nil if identifier.nil? || identifier == ""
|
||||
request("get", "/1.0/applications/#{identifier}", [200])
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
13
lib/fog/brightbox/requests/compute/list_applications.rb
Normal file
13
lib/fog/brightbox/requests/compute/list_applications.rb
Normal file
|
@ -0,0 +1,13 @@
|
|||
module Fog
|
||||
module Compute
|
||||
class Brightbox
|
||||
class Real
|
||||
|
||||
def list_applications
|
||||
request("get", "/1.0/applications", [200])
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
|
@ -0,0 +1,14 @@
|
|||
module Fog
|
||||
module Compute
|
||||
class Brightbox
|
||||
class Real
|
||||
|
||||
def reset_secret_application(identifier)
|
||||
return nil if identifier.nil? || identifier == ""
|
||||
request("post", "/1.0/applications/#{identifier}/reset_secret", [200])
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
15
lib/fog/brightbox/requests/compute/update_application.rb
Normal file
15
lib/fog/brightbox/requests/compute/update_application.rb
Normal file
|
@ -0,0 +1,15 @@
|
|||
module Fog
|
||||
module Compute
|
||||
class Brightbox
|
||||
class Real
|
||||
|
||||
def update_application(identifier, options)
|
||||
return nil if identifier.nil? || identifier == ""
|
||||
return nil if options.empty? || options.nil?
|
||||
request("put", "/1.0/applications/#{identifier}", [200], options)
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
63
tests/brightbox/requests/compute/application_test.rb
Normal file
63
tests/brightbox/requests/compute/application_test.rb
Normal file
|
@ -0,0 +1,63 @@
|
|||
Shindo.tests('Fog::Compute[:brightbox] | api client requests', ['brightbox']) do
|
||||
|
||||
tests('success') do
|
||||
|
||||
create_options = {
|
||||
:name => "Fog@#{Time.now.iso8601}"
|
||||
}
|
||||
|
||||
tests("#create_application(#{create_options.inspect})") do
|
||||
pending if Fog.mocking?
|
||||
result = Fog::Compute[:brightbox].create_application(create_options)
|
||||
@application_id = result["id"]
|
||||
formats(Brightbox::Compute::Formats::Full::APPLICATION, false) { result }
|
||||
end
|
||||
|
||||
tests("#list_applications") do
|
||||
pending if Fog.mocking?
|
||||
result = Fog::Compute[:brightbox].list_applications
|
||||
formats(Brightbox::Compute::Formats::Collection::APPLICATION, false) { result }
|
||||
end
|
||||
|
||||
tests("#get_application('#{@application_id}')") do
|
||||
pending if Fog.mocking?
|
||||
result = Fog::Compute[:brightbox].get_application(@application_id)
|
||||
formats(Brightbox::Compute::Formats::Full::APPLICATION, false) { result }
|
||||
end
|
||||
|
||||
update_options = {:name => "Fog@#{Time.now.iso8601}"}
|
||||
tests("#update_application('#{@application_id}', #{update_options.inspect})") do
|
||||
pending if Fog.mocking?
|
||||
result = Fog::Compute[:brightbox].update_application(@application_id, update_options)
|
||||
formats(Brightbox::Compute::Formats::Full::APPLICATION, false) { result }
|
||||
end
|
||||
|
||||
tests("#reset_secret_application('#{@application_id}')") do
|
||||
pending if Fog.mocking?
|
||||
result = Fog::Compute[:brightbox].reset_secret_application(@application_id)
|
||||
formats(Brightbox::Compute::Formats::Full::APPLICATION, false) { result }
|
||||
test("new secret is visible") { ! result["secret"].nil? }
|
||||
end
|
||||
|
||||
tests("#destroy_application('#{@application_id}')") do
|
||||
pending if Fog.mocking?
|
||||
result = Fog::Compute[:brightbox].destroy_application(@application_id)
|
||||
formats(Brightbox::Compute::Formats::Full::APPLICATION, false) { result }
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
tests('failure') do
|
||||
|
||||
tests("#get_api_client('app-00000')").raises(Excon::Errors::NotFound) do
|
||||
pending if Fog.mocking?
|
||||
Fog::Compute[:brightbox].get_application('app-00000')
|
||||
end
|
||||
|
||||
tests("#get_api_client").raises(ArgumentError) do
|
||||
pending if Fog.mocking?
|
||||
Fog::Compute[:brightbox].get_application
|
||||
end
|
||||
end
|
||||
|
||||
end
|
|
@ -280,6 +280,13 @@ class Brightbox
|
|||
"account" => Brightbox::Compute::Formats::Nested::ACCOUNT
|
||||
}
|
||||
|
||||
APPLICATION = {
|
||||
"id" => String,
|
||||
"resource_type" => String,
|
||||
"url" => String,
|
||||
"name" => Fog::Nullable::String
|
||||
}
|
||||
|
||||
CLOUD_IP = {
|
||||
"id" => String,
|
||||
"resource_type" => String,
|
||||
|
@ -479,6 +486,14 @@ class Brightbox
|
|||
"account" => Brightbox::Compute::Formats::Nested::ACCOUNT
|
||||
}
|
||||
|
||||
APPLICATION = {
|
||||
"id" => String,
|
||||
"resource_type" => String,
|
||||
"url" => String,
|
||||
"name" => Fog::Nullable::String,
|
||||
"secret" => Fog::Nullable::String
|
||||
}
|
||||
|
||||
CLOUD_IP = {
|
||||
"id" => String,
|
||||
"resource_type" => String,
|
||||
|
@ -647,6 +662,7 @@ class Brightbox
|
|||
module Collection
|
||||
ACCOUNTS = [Brightbox::Compute::Formats::Collected::ACCOUNT]
|
||||
API_CLIENTS = [Brightbox::Compute::Formats::Collected::API_CLIENT]
|
||||
APPLICATION = [Brightbox::Compute::Formats::Collected::APPLICATION]
|
||||
CLOUD_IPS = [Brightbox::Compute::Formats::Collected::CLOUD_IP]
|
||||
IMAGES = [Brightbox::Compute::Formats::Collected::IMAGE]
|
||||
FIREWALL_POLICIES = [Brightbox::Compute::Formats::Collected::FIREWALL_POLICY]
|
||||
|
|
Loading…
Add table
Reference in a new issue