Class: Deltacloud::Drivers::RimuHosting::RimuHostingDriver

Inherits:
BaseDriver
  • Object
show all
Defined in:
lib/deltacloud/drivers/rimuhosting/rimuhosting_driver.rb

Instance Method Summary collapse

Methods inherited from BaseDriver

#catched_exceptions_list, declare_feature, define_hardware_profile, define_instance_states, feature, feature_decl_for, feature_decls, #features, features, #filter_hardware_profiles, #filter_on, #find_hardware_profile, #hardware_profile, hardware_profiles, #has_collection?, #image, #instance, #instance_actions_for, instance_state_machine, #instance_state_machine, #realm, #storage_snapshot, #storage_snapshots, #storage_volume, #storage_volumes, #supported_collections

Instance Method Details

#convert_srv_to_instance(inst) ⇒ Object



124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
# File 'lib/deltacloud/drivers/rimuhosting/rimuhosting_driver.rb', line 124

def convert_srv_to_instance( inst )
  Instance.new({
          :id => inst["order_oid"].to_s,
          :name => inst["domain_name"],
          :image_id => "lenny",
          :state => "RUNNING",
          :name => inst["domain_name"],
          :realm_id => "RH",
          :owner_id => "root",
          :instance_profile => InstanceProfile.new("none"),
          :actions => instance_actions_for("RUNNING"),
          :public_addresses => inst["allocated_ips"]["primary_ip"],
          :launch_time => inst["billing_info"]["order_date"]["iso_format"]
  })
end

#create_instance(credentials, image_id, opts) ⇒ Object



111
112
113
114
115
116
117
118
119
120
121
122
# File 'lib/deltacloud/drivers/rimuhosting/rimuhosting_driver.rb', line 111

def create_instance(credentials, image_id, opts)
   rh = RimuHostingClient.new(credentials)
  # really need to raise an exception here.
  hwp_id = opts[:hwp_id] || 1
  # really bad, but at least its a fqdn
  name = Time.now.to_s + '.com'
  if (opts[:name]) then
    name = opts[:name]
  end
  convert_srv_to_instance(rh.create_server(image_id, hwp_id, name))

end

#destroy_instance(credentials, id) ⇒ Object



104
105
106
107
108
109
# File 'lib/deltacloud/drivers/rimuhosting/rimuhosting_driver.rb', line 104

def destroy_instance(credentials, id)
  safely do
    rh = RimuHostingClient.new(credentials)
    return rh.delete_server(id)
  end
end

#hardware_profiles(credentials, opts = nil) ⇒ Object



49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# File 'lib/deltacloud/drivers/rimuhosting/rimuhosting_driver.rb', line 49

def hardware_profiles(credentials, opts = nil)
  safely do
    rh = RimuHostingClient.new(credentials)
    results = rh.list_plans.map do |plan|
      # FIXME: x86 is not a valid architecture; what is Rimu offering ?
      # FIXME: VPS plans offer a range of memory/storage, but that's
      #        not contained in hte pricing_plan_infos
      HardwareProfile.new(plan["pricing_plan_code"]) do
        memory plan["minimum_memory_mb"].to_f
        storage plan["minimum_disk_gb"].to_i
        architecture "x86"
      end
    end
  end
  filter_hardware_profiles(results, opts)
end

#images(credentails, opts = nil) ⇒ Object



31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/deltacloud/drivers/rimuhosting/rimuhosting_driver.rb', line 31

def images(credentails, opts=nil)
  safely do
    rh = RimuHostingClient.new(credentails)
    images = rh.list_images.map do | image |
      Image.new({
              :id => image["distro_code"].gsub(/\./,"-"),
              :name => image["distro_code"],
              :description => image["distro_description"],
              :owner_id => "root",
              :architecture => "x86"
      })
    end
  end
  images.sort_by{|e| [e.description]}
  images = filter_on( images, :id, opts)
  images
end

#instances(credentials, opts = nil) ⇒ Object



74
75
76
77
78
79
80
81
82
83
84
# File 'lib/deltacloud/drivers/rimuhosting/rimuhosting_driver.rb', line 74

def instances(credentials, opts=nil)
  safely do
    rh = RimuHostingClient.new(credentials)
    instances = rh.list_nodes.map do | inst |
      convert_srv_to_instance(inst)
    end
  end
  instances = filter_on( instances, :id, opts)
  instances = filter_on( instances, :state, opts )
  instances
end

#realms(credentials, opts = nil) ⇒ Object



66
67
68
69
70
71
72
# File 'lib/deltacloud/drivers/rimuhosting/rimuhosting_driver.rb', line 66

def realms(credentials, opts=nil)
  [Realm.new( {
          :id=>"rimu",
          :name=>"RimuHosting",
          :state=> "AVAILABLE"
  } )]
end

#reboot_instance(credentials, id) ⇒ Object



86
87
88
89
90
91
# File 'lib/deltacloud/drivers/rimuhosting/rimuhosting_driver.rb', line 86

def reboot_instance(credentials, id)
  safely do
    rh = RimuHostingClient.new(credentials)
    rh.set_server_state(id, :RESTARTING)
  end
end

#safely(&block) ⇒ Object



153
154
155
156
157
158
159
# File 'lib/deltacloud/drivers/rimuhosting/rimuhosting_driver.rb', line 153

def safely(&block)
  begin
    block.call
  rescue Exception => e
    raise Deltacloud::BackendError.new(500, e.class.to_s, e.message, e.backtrace)
  end
end

#start_instance(credentials, id) ⇒ Object



93
94
95
96
97
98
# File 'lib/deltacloud/drivers/rimuhosting/rimuhosting_driver.rb', line 93

def start_instance(credentials, id)
  safely do
    rh = RimuHostingClient.new(credentials)
    rh.set_server_state(id, :STARTED)
  end
end

#stop_instance(credentials, id) ⇒ Object



100
101
102
# File 'lib/deltacloud/drivers/rimuhosting/rimuhosting_driver.rb', line 100

def stop_instance(credentials, id)
  destroy_instance(credentials, id)
end