Class: Fog::Compute::StormOnDemand::Real

Inherits:
Object
  • Object
show all
Defined in:
lib/fog/compute/storm_on_demand.rb,
lib/fog/compute/requests/storm_on_demand/get_stats.rb,
lib/fog/compute/requests/storm_on_demand/get_server.rb,
lib/fog/compute/requests/storm_on_demand/list_images.rb,
lib/fog/compute/requests/storm_on_demand/clone_server.rb,
lib/fog/compute/requests/storm_on_demand/list_configs.rb,
lib/fog/compute/requests/storm_on_demand/list_servers.rb,
lib/fog/compute/requests/storm_on_demand/create_server.rb,
lib/fog/compute/requests/storm_on_demand/delete_server.rb,
lib/fog/compute/requests/storm_on_demand/reboot_server.rb,
lib/fog/compute/requests/storm_on_demand/resize_server.rb,
lib/fog/compute/requests/storm_on_demand/list_balancers.rb,
lib/fog/compute/requests/storm_on_demand/list_templates.rb,
lib/fog/compute/requests/storm_on_demand/list_private_ips.rb,
lib/fog/compute/requests/storm_on_demand/add_balancer_node.rb,
lib/fog/compute/requests/storm_on_demand/remove_balancer_node.rb

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Real

Returns a new instance of Real.



84
85
86
87
88
89
90
91
92
93
94
# File 'lib/fog/compute/storm_on_demand.rb', line 84

def initialize(options={})
  require 'multi_json'
  uri = URI.parse(options[:storm_on_demand_auth_url] ||= API_URL)
  @host   = uri.host
  @path   = uri.path
  @port   = uri.port
  @scheme = uri.scheme
  @storm_on_demand_username = options[:storm_on_demand_username]
  @storm_on_demand_password = options[:storm_on_demand_password]
  @connection = Fog::Connection.new("#{@scheme}://#{@host}:#{@port}")
end

Instance Method Details

#add_balancer_node(options = {}) ⇒ Object



6
7
8
9
10
11
# File 'lib/fog/compute/requests/storm_on_demand/add_balancer_node.rb', line 6

def add_balancer_node(options = {})
  request(
    :path     => "/network/loadbalancer/addnode",
    :body     => MultiJson.encode({:params => options})
  )
end

#clone_server(options = {}) ⇒ Object



6
7
8
9
10
11
# File 'lib/fog/compute/requests/storm_on_demand/clone_server.rb', line 6

def clone_server(options = {})
  request(
    :path     => "/storm/server/clone",
    :body     => MultiJson.encode({:params => options})
  )
end

#create_server(options = {}) ⇒ Object



6
7
8
9
10
11
# File 'lib/fog/compute/requests/storm_on_demand/create_server.rb', line 6

def create_server(options = {})
  request(
    :path     => "/storm/server/create",
    :body     => MultiJson.encode({:params => options})
  )
end

#delete_server(options = {}) ⇒ Object



6
7
8
9
10
11
# File 'lib/fog/compute/requests/storm_on_demand/delete_server.rb', line 6

def delete_server(options = {})
  request(
    :path     => "/storm/server/destroy",
    :body     => MultiJson.encode({:params => options})
  )
end

#get_server(options = {}) ⇒ Object



6
7
8
9
10
11
# File 'lib/fog/compute/requests/storm_on_demand/get_server.rb', line 6

def get_server(options = {})
  request(
    :path     => "/storm/server/details",
    :body     => MultiJson.encode({:params => options})
  )
end

#get_stats(options = {}) ⇒ Object



6
7
8
9
10
11
# File 'lib/fog/compute/requests/storm_on_demand/get_stats.rb', line 6

def get_stats(options = {})
  request(
    :path     => "/monitoring/load/stats",
    :body     => MultiJson.encode({:params => options})
  )
end

#list_balancers(options = {}) ⇒ Object



6
7
8
9
10
11
# File 'lib/fog/compute/requests/storm_on_demand/list_balancers.rb', line 6

def list_balancers(options = {})
  request(
    :path     => "/network/loadbalancer/list",
    :body     => MultiJson.encode(options)
  )
end

#list_configs(options = {}) ⇒ Object



6
7
8
9
10
11
# File 'lib/fog/compute/requests/storm_on_demand/list_configs.rb', line 6

def list_configs(options = {})
  request(
    :path     => "/storm/config/list",
    :body     => MultiJson.encode(options)
  )
end

#list_images(options = {}) ⇒ Object



6
7
8
9
10
11
# File 'lib/fog/compute/requests/storm_on_demand/list_images.rb', line 6

def list_images(options = {})
  request(
    :path     => "/server/image/list",
    :body     => MultiJson.encode(options)
  )
end

#list_private_ips(options = {}) ⇒ Object



6
7
8
9
10
11
# File 'lib/fog/compute/requests/storm_on_demand/list_private_ips.rb', line 6

def list_private_ips(options = {})
  request(
    :path     => "/network/private/get",
    :body     => MultiJson.encode(options)
  )
end

#list_servers(options = {}) ⇒ Object



6
7
8
9
10
11
# File 'lib/fog/compute/requests/storm_on_demand/list_servers.rb', line 6

def list_servers(options = {})
  request(
    :path     => "/storm/server/list",
    :body     => MultiJson.encode(options)
  )
end

#list_templates(options = {}) ⇒ Object



6
7
8
9
10
11
# File 'lib/fog/compute/requests/storm_on_demand/list_templates.rb', line 6

def list_templates(options = {})
  request(
    :path     => "/server/template/list",
    :body     => MultiJson.encode(options)
  )
end

#reboot_server(options = {}) ⇒ Object



6
7
8
9
10
11
# File 'lib/fog/compute/requests/storm_on_demand/reboot_server.rb', line 6

def reboot_server(options = {})
  request(
    :path     => "/storm/server/reboot",
    :body     => MultiJson.encode({:params => options})
  )
end

#reloadObject



96
97
98
# File 'lib/fog/compute/storm_on_demand.rb', line 96

def reload
  @connection.reset
end

#remove_balancer_node(options = {}) ⇒ Object



6
7
8
9
10
11
# File 'lib/fog/compute/requests/storm_on_demand/remove_balancer_node.rb', line 6

def remove_balancer_node(options = {})
  request(
    :path     => "/network/loadbalancer/removenode",
    :body     => MultiJson.encode({:params => options})
  )
end

#request(params) ⇒ Object



100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
# File 'lib/fog/compute/storm_on_demand.rb', line 100

def request(params)
  begin
    response = @connection.request(params.merge!({
      :headers  => {
        'Content-Type' => 'application/json',
        'Authorization' => 'Basic ' << Base64.encode64("#{@storm_on_demand_username}:#{@storm_on_demand_password}").chomp
      }.merge!(params[:headers] || {}),
      :host     => @host,
      :path     => "#{@path}/#{params[:path]}",
      :expects  => 200,
      :method   => :post
    }))
  rescue Excon::Errors::HTTPStatusError => error
    raise case error
    when Excon::Errors::NotFound
      Fog::StormOnDemand::Compute::NotFound.slurp(error)
    else
      error
    end
  end
  unless response.body.empty?
    response.body = MultiJson.decode(response.body)
  end
  if response.body.keys.include?('full_error')
    raise(Fog::Compute::StormOnDemand::Error, response.body.inspect)
  end
  response
end

#resize_server(options = {}) ⇒ Object



6
7
8
9
10
11
# File 'lib/fog/compute/requests/storm_on_demand/resize_server.rb', line 6

def resize_server(options = {})
  request(
    :path     => "/storm/server/resize",
    :body     => MultiJson.encode({:params => options})
  )
end