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

[stormondemand|vpn] Add new VPN service and APIs

This commit is contained in:
Eric Wong 2013-05-25 17:02:43 +08:00
parent 8c0f8a44b6
commit 80690e700e
9 changed files with 205 additions and 0 deletions

View file

@ -12,6 +12,7 @@ module Fog
service(:monitoring, 'storm_on_demand/monitoring', 'Monitoring')
service(:support, 'storm_on_demand/support', 'Support')
service(:account, 'storm_on_demand/account', 'Account')
service(:vpn, 'storm_on_demand/vpn', 'VPN')
end
end

View file

@ -0,0 +1,30 @@
require 'fog/core/model'
module Fog
module VPN
class StormOnDemand
class Vpn < Fog::Model
identity :uniq_id
attribute :active
attribute :activeStatus
attribute :current_users
attribute :domain
attribute :max_users
attribute :network_range
attribute :region_id
attribute :vpn
def initialize(attributes={})
super
end
def update(options={})
requires :identity
service.update_vpn({:uniq_id => identity}.merge!(options))
end
end
end
end
end

View file

@ -0,0 +1,27 @@
require 'fog/core/collection'
require 'fog/storm_on_demand/models/vpn/vpn'
module Fog
module VPN
class StormOnDemand
class Vpns < Fog::Collection
model Fog::VPN::StormOnDemand::Vpn
def create(options)
vpn = service.create_vpn(options).body
new(vpn)
end
def get(uniq_id)
vpn = service.get_vpn(:uniq_id => uniq_id).body
new(vpn)
end
def all_users(options={})
service.list_vpn_users(options).body['items']
end
end
end
end
end

View file

@ -0,0 +1,16 @@
module Fog
module VPN
class StormOnDemand
class Real
def create_vpn(options={})
request(
:path => '/VPN/create',
:body => Fog::JSON.encode(:params => options)
)
end
end
end
end
end

View file

@ -0,0 +1,16 @@
module Fog
module VPN
class StormOnDemand
class Real
def get_vpn(options={})
request(
:path => '/VPN/details',
:body => Fog::JSON.encode(:params => options)
)
end
end
end
end
end

View file

@ -0,0 +1,16 @@
module Fog
module VPN
class StormOnDemand
class Real
def list_vpn_users(options={})
request(
:path => '/VPN/list',
:body => Fog::JSON.encode(:params => options)
)
end
end
end
end
end

View file

@ -0,0 +1,16 @@
module Fog
module VPN
class StormOnDemand
class Real
def update_vpn(options={})
request(
:path => '/VPN/update',
:body => Fog::JSON.encode(:params => options)
)
end
end
end
end
end

View file

@ -0,0 +1,58 @@
require 'fog/storm_on_demand'
require 'fog/storm_on_demand/shared'
require 'fog/vpn'
module Fog
module VPN
class StormOnDemand < Fog::Service
requires :storm_on_demand_username, :storm_on_demand_password
recognizes :storm_on_demand_auth_url
model_path 'fog/storm_on_demand/models/vpn'
model :vpn
collection :vpns
request_path 'fog/storm_on_demand/requests/vpn'
request :create_vpn
request :get_vpn
request :list_vpn_users
request :update_vpn
class Mock
def self.data
@data ||= Hash.new
end
def self.reset
@data = nil
end
def self.reset_data(keys=data.keys)
for key in [*keys]
data.delete(key)
end
end
def initialize(options={})
@storm_on_demand_username = options[:storm_on_demand_username]
end
def data
self.class.data[@storm_on_demand_username]
end
def reset_data
self.class.data.delete(@storm_on_demand_username)
end
end
class Real
include Fog::StormOnDemand::RealShared
end
end
end
end

25
lib/fog/vpn.rb Normal file
View file

@ -0,0 +1,25 @@
module Fog
module VPN
def self.[](provider)
self.new(:provider => provider)
end
def self.new(attributes)
attributes = attributes.dup
provider = attributes.delete(:provider).to_s.downcase.to_sym
if provider == :stormondemand
require 'fog/storm_on_demand/vpn'
Fog::VPN::StormOnDemand.new(attributes)
else
raise ArgumentError.new("#{provider} has no vpn service")
end
end
def self.providers
Fog.services[:vpn]
end
end
end