Sha256: ee7bf2c8013de53a47d5972edaeeeb3c7dec91afb85ffe134b2e08c01a0ee227

Contents?: true

Size: 1.42 KB

Versions: 6

Compression:

Stored size: 1.42 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::Core::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 = Vcloud::Core::QueryRunner.new
        query_results = q.run('vAppTemplate', :filter => "name==#{name};catalogName==#{catalog_name}")
        raise "Error retreiving #{q.type} query '#{q.filter}'" unless query_results
        query_results.collect do |record|
          record[:href].split('/').last if record.key?(:href)
        end
      end

      def self.get vapp_template_name, catalog_name
        ids = self.get_ids_by_name_and_catalog(vapp_template_name, catalog_name)
        raise 'Could not find template vApp' if ids.size == 0
        if ids.size > 1
          raise "Template #{vapp_template_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

6 entries across 6 versions & 1 rubygems

Version Path
vcloud-core-0.13.0 lib/vcloud/core/vapp_template.rb
vcloud-core-0.12.0 lib/vcloud/core/vapp_template.rb
vcloud-core-0.11.0 lib/vcloud/core/vapp_template.rb
vcloud-core-0.10.0 lib/vcloud/core/vapp_template.rb
vcloud-core-0.9.0 lib/vcloud/core/vapp_template.rb
vcloud-core-0.8.0 lib/vcloud/core/vapp_template.rb