Sha256: 98bfc877238460e349eddb3f4802c285657d7459edbda8bb6e1c4e71b13774c9

Contents?: true

Size: 1.15 KB

Versions: 4

Compression:

Stored size: 1.15 KB

Contents

require 'net/https'
require 'uri'
require 'json'
require_relative '../../vagrant-subutai'

module VagrantSubutai
  module Rest
    class Gorjun
      def self.template_id(name, owner)
        uri = URI.parse("#{url}?name=#{name}&owner=#{owner}")
        https = Net::HTTP.new(uri.host, uri.port)
        https.use_ssl = true

        request = Net::HTTP::Get.new(uri.request_uri)
        response = https.request(request)

        case response
          when Net::HTTPOK
            response = JSON.parse(response.body)
            response[0]['id']
          else
            Put.error "Try again! #{response.body} template name #{name}, owner #{owner}"
        end
      end

      def self.url
        env = SubutaiConfig.get(:SUBUTAI_ENV)
        env = env.to_s

        if env == VagrantSubutai::Configs::Environment::PROD
          return VagrantSubutai::Configs::Gorjun::INFO_PROD
        elsif env == VagrantSubutai::Configs::Environment::MASTER
          return VagrantSubutai::Configs::Gorjun::INFO_MASTER
        elsif env == VagrantSubutai::Configs::Environment::DEV
          return VagrantSubutai::Configs::Gorjun::INFO_DEV
        end
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
vagrant-subutai-1.1.3 lib/vagrant-subutai/rest/gorjun.rb
vagrant-subutai-1.1.2 lib/vagrant-subutai/rest/gorjun.rb
vagrant-subutai-1.1.1 lib/vagrant-subutai/rest/gorjun.rb
vagrant-subutai-1.1.0 lib/vagrant-subutai/rest/gorjun.rb