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

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

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Real

Returns a new instance of Real.



87
88
89
90
91
92
93
94
95
96
97
98
# File 'lib/fog/storm_on_demand/compute.rb', line 87

def initialize(options={})
  uri = URI.parse(options[:storm_on_demand_auth_url] ||= API_URL)
  @connection_options = options[:connection_options] || {}
  @host       = uri.host
  @path       = uri.path
  @persistent = options[:persistent] || false
  @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}", @persistent, @connection_options)
end

Instance Method Details

#add_balancer_node(options = {}) ⇒ Object



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

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

#clone_server(options = {}) ⇒ Object



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

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

#create_server(options = {}) ⇒ Object



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

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

#delete_server(options = {}) ⇒ Object



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

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

#get_server(options = {}) ⇒ Object



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

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

#get_stats(options = {}) ⇒ Object



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

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

#list_balancers(options = {}) ⇒ Object



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

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

#list_configs(options = {}) ⇒ Object



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

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

#list_images(options = {}) ⇒ Object



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

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

#list_private_ips(options = {}) ⇒ Object



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

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

#list_servers(options = {}) ⇒ Object



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

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

#list_templates(options = {}) ⇒ Object



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

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

#reboot_server(options = {}) ⇒ Object



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

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

#reloadObject



100
101
102
# File 'lib/fog/storm_on_demand/compute.rb', line 100

def reload
  @connection.reset
end

#remove_balancer_node(options = {}) ⇒ Object



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

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

#request(params) ⇒ Object



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

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 = Fog::JSON.decode(response.body)
  end
  if response.body.has_key?('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/storm_on_demand/requests/compute/resize_server.rb', line 6

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