Sha256: d7ede9c1c708de0d3892a945e6d7a337892d70812d27d1b4c737143568c075ff

Contents?: true

Size: 1.43 KB

Versions: 3

Compression:

Stored size: 1.43 KB

Contents

module Vcloud
  module Core
    class VappTemplate

      attr_reader :id

      def initialize(id)
        unless id =~ /^#{self.class.id_prefix}-[-0-9a-f]+$/
          raise "#{self.class.id_prefix} id : #{id} is not in correct format"
        end
        @id = id
      end

      def vcloud_attributes
        Vcloud::Fog::ServiceInterface.new.get_vapp_template(id)
      end

      def href
        vcloud_attributes[:href]
      end

      def name
        vcloud_attributes[:name]
      end

      def self.get_ids_by_name_and_catalog name, catalog_name
        raise "provide Catalog and vAppTemplate name" unless name && catalog_name
        q = Query.new(
          'vAppTemplate',
          :filter => "name==#{name};catalogName==#{catalog_name}"
        )
        unless query_results = q.get_all_results
          raise "Error retreiving #{q.type} query '#{q.filter}'"
        end
        query_results.collect do |record|
          record[:href].split('/').last if record.key?(:href)
        end
      end

      def self.get catalog_name, catalog_item_name
        ids = self.get_ids_by_name_and_catalog(catalog_item_name, catalog_name)
        raise 'Could not find template vApp' if ids.size == 0
        if ids.size > 1
          raise "Template #{catalog_item_name} is not unique in catalog #{catalog_name}"
        end
        return self.new(ids.first)
      end

      def self.id_prefix
        'vappTemplate'
      end

    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
vcloud-core-0.0.9 lib/vcloud/core/vapp_template.rb
vcloud-core-0.0.8 lib/vcloud/core/vapp_template.rb
vcloud-core-0.0.7 lib/vcloud/core/vapp_template.rb