Class/Module Index [+]

Quicksearch

Deltacloud::Drivers::Gogrid::GogridDriver

Constants

USER_NAME_MAX

Public Instance Methods

catched_exceptions_list() click to toggle source
# File lib/deltacloud/drivers/gogrid/gogrid_driver.rb, line 337
def catched_exceptions_list
  {
    :auth => [ /Forbidden/ ],
    :error => [ /Error/ ],
    :glob => [ /(.*)/ ]
  }
end
create_instance(credentials, image_id, opts={}) click to toggle source
# File lib/deltacloud/drivers/gogrid/gogrid_driver.rb, line 97
def create_instance(credentials, image_id, opts={})
  server_ram = nil
  if opts[:hwp_memory]
    mem = opts[:hwp_memory].to_i
    server_ram = (mem == 512) ? "512MB" : "#{mem / 1024}GB"
  else
    server_ram = "512MB"
  end

  name = opts[:name]
  if not name
    name = "Server #{Time.now.to_i.to_s.reverse[0..3]}#{rand(9)}"
  end

  if name.length > USER_NAME_MAX
    raise "Parameter name must be #{USER_NAME_MAX} characters or less"
  end

  client = new_client(credentials)
  params = {
    'name' => name,
    'image' => image_id,
    'server.ram' => server_ram,
    'ip' => get_free_ip_from_realm(credentials, opts[:realm_id] || '1')
  }
  params.merge!('isSandbox' => 'true') if opts[:sandbox]
  safely do
    instance = client.request('grid/server/add', params)['list'].first
    if instance
      login_data = get_login_data(client, instance[:id])
      if login_data['username'] and login_data['password']
        instance['username'] = login_data['username']
        instance['password'] = login_data['password']
        inst = convert_instance(instance, credentials.user)
      else
        inst = convert_instance(instance, credentials.user)
        inst.authn_error = "Unable to fetch password"
      end
      return inst
    else
      return nil
    end
  end
end
create_load_balancer(credentials, opts={}) click to toggle source
# File lib/deltacloud/drivers/gogrid/gogrid_driver.rb, line 226
def create_load_balancer(credentials, opts={})
   gogrid = new_client(credentials)
   balancer, l_instance = nil, nil
   safely do
     virtip = get_free_ip_from_realm(credentials, opts['realm_id'])
     if opts['instance_id']
       l_instance = instance(credentials, :id => opts['instance_id'])
       real_ip = {
         'realiplist.0.port' => opts['listener_instance_port'].to_i,
         'realiplist.0.ip' => l_instance ? l_instance.public_addresses.first : ""
       }
     else
       real_ip = false
     end
     request = {
       'name' => opts['name'],
       'virtualip.ip' => virtip,
       'virtualip.port' => opts['listener_balancer_port'].to_i,
     }
     request.merge!(real_ip) if real_ip
     balancer = gogrid.request('grid/loadbalancer/add', request)['list'].first
   end
   balancer = convert_load_balancer(credentials, balancer)
   balancer.instances = [l_instance] if l_instance
   balancer
 end
destroy_instance(credentials, id) click to toggle source
# File lib/deltacloud/drivers/gogrid/gogrid_driver.rb, line 208
def destroy_instance(credentials, id)
  safely do
    new_client(credentials).request('grid/server/delete', { 'name' => id})
  end
end
destroy_load_balancer(credentials, id) click to toggle source
# File lib/deltacloud/drivers/gogrid/gogrid_driver.rb, line 253
def destroy_load_balancer(credentials, id)
  gogrid = new_client(credentials)
  balancer = nil
  safely do
    balancer = gogrid.request('grid/loadbalancer/delete', { 'name' => id })
  end
end
hardware_profiles(credentials, opts={}) click to toggle source
# File lib/deltacloud/drivers/gogrid/gogrid_driver.rb, line 44
def hardware_profiles(credentials, opts={})
  client = new_client(credentials)
  safely do
    server_types = client.request('common/lookup/list', { 'lookup' => 'server.type' })
    server_rams = client.request('common/lookup/list', { 'lookup' => 'server.ram' })
    @hardware_profiles = []
    server_types['list'].each do |type|
      memory_values = server_rams['list'].collect do |r|
          r['name'] =~ /MB$/ ? r['name'].gsub(/MB$/, '').to_i : (r['name'].gsub(/(\w{2})$/, '')).to_i*1024
      end
      @hardware_profiles << ::Deltacloud::HardwareProfile.new(type['name'].tr(' ', '-').downcase) do
        cpu 2
        memory memory_values
        storage 25
      end
    end
  end
  @hardware_profiles
end
images(credentials, opts=nil) click to toggle source
# File lib/deltacloud/drivers/gogrid/gogrid_driver.rb, line 69
def images(credentials, opts=nil)
  imgs = []
  if opts and opts[:id]
    safely do
      imgs = [convert_image(new_client(credentials).request('grid/image/get', { 'id' => opts[:id] })['list'].first)]
    end
  else
    safely do
      imgs = new_client(credentials).request('grid/image/list', { 'state' => 'Available'})['list'].collect do |image|
        convert_image(image, credentials.user)
      end
    end
  end
  imgs = filter_on( imgs, :architecture, opts )
  imgs.sort_by{|e| [e.owner_id, e.description]}
end
instances(credentials, opts=nil) click to toggle source
# File lib/deltacloud/drivers/gogrid/gogrid_driver.rb, line 169
def instances(credentials, opts=nil)
  instances = []
  if opts and opts[:id]
    begin
      client = new_client(credentials)
      instance = client.request('grid/server/get', { 'name' => opts[:id] })['list'].first
      login_data = get_login_data(client, instance['id'])
      if login_data['username'] and login_data['password']
        instance['username'] = login_data['username']
        instance['password'] = login_data['password']
        inst = convert_instance(instance, credentials.user)
      else
        inst = convert_instance(instance, credentials.user)
        inst.authn_error = "Unable to fetch password"
      end
      instances = [inst]
    rescue Exception => e
      if e.message == "400 Bad Request"
        # in the case of a VM that we just made, the grid/server/get method
        # throws a "400 Bad Request error".  In this case we try again by
        # getting a full listing a filtering on the id.  This could
        # potentially take a long time, but I don't see another way to get
        # information about a newly created instance
        instances = list_instances(credentials, opts[:id])
      end
    end
  else
    instances = list_instances(credentials, nil)
  end
  instances = filter_on( instances, :state, opts )
  instances
end
key(credentials, opts=nil) click to toggle source
# File lib/deltacloud/drivers/gogrid/gogrid_driver.rb, line 304
def key(credentials, opts=nil)
  keys(credentials, opts).first
end
keys(credentials, opts=nil) click to toggle source
# File lib/deltacloud/drivers/gogrid/gogrid_driver.rb, line 308
def keys(credentials, opts=nil)
  gogrid = new_client( credentials )
  creds = []
  safely do
    gogrid.request('support/password/list')['list'].each do |password|
      creds << convert_key(password)
    end
  end
  return creds
end
lb_register_instance(credentials, opts={}) click to toggle source
# File lib/deltacloud/drivers/gogrid/gogrid_driver.rb, line 285
def lb_register_instance(credentials, opts={})
  client = new_client(credentials)
  instance = instance(credentials, :id => opts[:instance_id])
  balancer = client.request('grid/loadbalancer/get', { 'name' => opts[:id]})['list'].first
  safely do
    convert_load_balancer(credentials, client.request('grid/loadbalancer/edit', {
      "id" => balancer['id'],
      "realiplist.#{balancer['realiplist'].size}.ip" => instance.public_addresses.first,
      "realiplist.#{balancer['realiplist'].size}.port" => balancer['virtualip']['port']
    }))
  end
end
lb_unregister_instance(credentials, opts={}) click to toggle source

Move this to capabilities

# File lib/deltacloud/drivers/gogrid/gogrid_driver.rb, line 299
def lb_unregister_instance(credentials, opts={})
    raise Deltacloud::BackendFeatureUnsupported.new('501',
  'Unregistering instances from load balancer is not supported in GoGrid')
end
list_instances(credentials, id) click to toggle source
# File lib/deltacloud/drivers/gogrid/gogrid_driver.rb, line 157
def list_instances(credentials, id)
  instances = []
  safely do
    new_client(credentials).request('grid/server/list')['list'].collect do |instance|
      if id.nil? or instance['name'] == id
        instances << convert_instance(instance, credentials.user)
      end
    end
  end
  instances
end
load_balancer(credentials, opts={}) click to toggle source
# File lib/deltacloud/drivers/gogrid/gogrid_driver.rb, line 272
def load_balancer(credentials, opts={})
  gogrid = new_client(credentials)
  balancer = nil
  begin
    balancer = gogrid.request('grid/loadbalancer/get', { 'name' => opts[:id] })['list'].first
    balancer['instances'] = instances(credentials)
    return convert_load_balancer(credentials, balancer)
  rescue OpenURI::HTTPError
    balancer = load_balancers(credentials, :id => opts[:id]).first
  end
end
load_balancers(credentials, opts={}) click to toggle source
# File lib/deltacloud/drivers/gogrid/gogrid_driver.rb, line 261
def load_balancers(credentials, opts={})
  gogrid = new_client(credentials)
  balancers = []
  safely do
    balancer = gogrid.request('grid/loadbalancer/list', opts || {})['list'].each do |balancer|
      balancers << balancer
    end
  end
  balancers.collect { |b| convert_load_balancer(credentials, b) }
end
realms(credentials, opts=nil) click to toggle source
# File lib/deltacloud/drivers/gogrid/gogrid_driver.rb, line 86
def realms(credentials, opts=nil)
  realms = []
  client = new_client(credentials)
  safely do
      client.request('common/lookup/list', { 'lookup' => 'ip.datacenter' })['list'].collect do |realm|
       realms << convert_realm(realm)
    end
  end
  realms = filter_on(realms, :id, opts)
end
reboot_instance(credentials, id) click to toggle source
# File lib/deltacloud/drivers/gogrid/gogrid_driver.rb, line 202
def reboot_instance(credentials, id)
  safely do
    new_client(credentials).request('grid/server/power', { 'name' => id, 'power' => 'reboot'})
  end
end
run_on_instance(credentials, opts={}) click to toggle source
# File lib/deltacloud/drivers/gogrid/gogrid_driver.rb, line 142
def run_on_instance(credentials, opts={})
  target = instance(credentials, opts[:id])
  param = {}
  param[:credentials] = {
    :username => target.username,
    :password => target.password,
  }
  param[:credentials].merge!({ :password => opts[:password]}) if opts[:password].length>0
  param[:port] = opts[:port] || '22'
  param[:ip] = target.public_addresses
  Deltacloud::Runner.execute(opts[:cmd], param)
end
start_instance(credentials, id) click to toggle source
# File lib/deltacloud/drivers/gogrid/gogrid_driver.rb, line 220
def start_instance(credentials, id)
  safely do
    new_client(credentials).request('grid/server/power', { 'name' => id, 'power' => 'on'})
  end
end
stop_instance(credentials, id) click to toggle source
# File lib/deltacloud/drivers/gogrid/gogrid_driver.rb, line 214
def stop_instance(credentials, id)
  safely do
    new_client(credentials).request('grid/server/power', { 'name' => id, 'power' => 'off'})
  end
end
supported_collections() click to toggle source
# File lib/deltacloud/drivers/gogrid/gogrid_driver.rb, line 64
def supported_collections
  DEFAULT_COLLECTIONS.reject! { |c| [ :storage_volumes, :storage_snapshots ].include?(c) }
  DEFAULT_COLLECTIONS + [ :keys, :load_balancers ]
end
valid_credentials?(credentials) click to toggle source
# File lib/deltacloud/drivers/gogrid/gogrid_driver.rb, line 319
def valid_credentials?(credentials)
  client = new_client(credentials)
  # FIXME: We need to do this call to determine if
  #        GoGrid is working with given credentials. There is no
  #        other way to check, if given credentials are valid or not.
  return false unless new_client(credentials).request('common/lookup/list', { 'lookup' => 'ip.datacenter' })
  true
end

[Validate]

Generated with the Darkfish Rdoc Generator 2.