diff --git a/lib/fog/compute/linode.rb b/lib/fog/compute/linode.rb index ed6d1bd9f..d93033ff4 100644 --- a/lib/fog/compute/linode.rb +++ b/lib/fog/compute/linode.rb @@ -7,6 +7,12 @@ module Fog recognizes :provider # remove post deprecation model_path 'fog/compute/models/linode' + model :flavor + collection :flavors + model :image + collection :images + model :server + collection :servers request_path 'fog/compute/requests/linode' request :avail_datacenters diff --git a/lib/fog/compute/models/linode/flavor.rb b/lib/fog/compute/models/linode/flavor.rb new file mode 100644 index 000000000..d0a52395a --- /dev/null +++ b/lib/fog/compute/models/linode/flavor.rb @@ -0,0 +1,24 @@ +require 'fog/core/model' + +module Fog + module Linode + class Compute + class Flavor < Fog::Model + identity :id + + attribute :disk + attribute :name + attribute :ram + attribute :price + + def cores + 4 # linode always has 4 cores + end + + def bits + 0 # these are determined by images you select not the hardware + end + end + end + end +end diff --git a/lib/fog/compute/models/linode/flavors.rb b/lib/fog/compute/models/linode/flavors.rb new file mode 100644 index 000000000..d50e33f70 --- /dev/null +++ b/lib/fog/compute/models/linode/flavors.rb @@ -0,0 +1,34 @@ +require 'fog/core/collection' +require 'fog/compute/models/linode/flavor' + +module Fog + module Linode + class Compute + + class Flavors < Fog::Collection + + model Fog::Linode::Compute::Flavor + + def all + load flavors + end + + def get(id) + new flavors(id).first + rescue Fog::Linode::Compute::NotFound + nil + end + + private + def flavors(flavor_id=nil) + connection.avail_linodeplans(flavor_id).body['DATA'].tap { |data| map_flavors data } + end + + def map_flavors(flavors) + flavors.map! { |flavor| flavor.each_with_object({}) { |(k, v), h| h[k.downcase.to_sym] = v } } + flavors.each { |flavor| flavor.merge! :name => flavor[:label], :id => flavor[:planid] } + end + end + end + end +end diff --git a/lib/fog/compute/models/linode/image.rb b/lib/fog/compute/models/linode/image.rb new file mode 100644 index 000000000..e69de29bb diff --git a/lib/fog/compute/models/linode/images.rb b/lib/fog/compute/models/linode/images.rb new file mode 100644 index 000000000..e69de29bb diff --git a/lib/fog/compute/models/linode/server.rb b/lib/fog/compute/models/linode/server.rb new file mode 100644 index 000000000..e69de29bb diff --git a/lib/fog/compute/models/linode/servers.rb b/lib/fog/compute/models/linode/servers.rb new file mode 100644 index 000000000..e69de29bb