Sha256: 224a2da6fd544b865cead0f62a6a51c7fc253a110e41e9089cef0a3623c2298d

Contents?: true

Size: 1.25 KB

Versions: 1

Compression:

Stored size: 1.25 KB

Contents

require 'fog/ecloud/models/compute/server'

module Fog
  module Compute
    class Ecloud

      class Servers < Fog::Ecloud::Collection

        undef_method :create

        model Fog::Compute::Ecloud::Server

        attribute :href, :aliases => :Href

        def all
          check_href!(:parent => "Vdc")
          load(_vapps)
        end

        def get(uri)
          if data = connection.get_vapp(uri)
            new(data.body)
          end
        rescue Fog::Errors::NotFound
          nil
        end

        def create( catalog_item_uri, options )
          options[:vdc_uri] = href
          options[:cpus] ||= 1
          options[:memory] ||= 512
          options[:computePool] ||= ""
          data = connection.instantiate_vapp_template( catalog_item_uri, options ).body
          object = new(data)
          object
        end

        private

        def _resource_entities
          if Hash === resource_entities = connection.get_vdc(href).body[:ResourceEntities]
            resource_entities[:ResourceEntity]
          end
        end

        def _vapps
          resource_entities = _resource_entities
          if resource_entities.nil?
            []
          else
            resource_entities
          end
        end

      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
michiels-fog-1.3.1 lib/fog/ecloud/models/compute/servers.rb