services/chef-services/cookbooks/cloudify/libraries/cloudify.rb
def cloudify_rest(method, scope, application, service, instance, key, value=nil)
        cloudify_uri = URI.parse(node['cloudify']['management_rest_url'])
        cloudify_rest_uri = cloudify_resource_uri(scope, application, service, instance)
        request = case method
        when :post
            r = ::Net::HTTP::Post.new(cloudify_rest_uri)
            r.body = ::Chef::JSONCompat.to_json({key => value}) if value
            r
        when :delete
            ::Net::HTTP::Delete.new(cloudify_rest_uri + "/" + key)
        when :get
            ::Net::HTTP::Get.new(cloudify_rest_uri)
        else
            raise RuntimeError, "Method #{method} not implemented for Cloudify REST"
        end

        request.content_type = 'application/json'     

        response = Net::HTTP.start(cloudify_uri.host, cloudify_uri.port) do |http|
            http.request(request)
        end
        
        unless response.code == '200'
          raise RuntimeError.new "The REST request failed with code #{response.code}"
        end
    end
#a wrapper for et::HTTP.start that yields a connection to REST interface
a wrapper for et::HTTP.start that yields a connection to REST interface
a wrapper for et :: HTTP . start that yields a connection to REST interface
def cloudify_rest(method, scope, application, service, instance, key, value=nil)
        cloudify_uri = URI.parse(node['cloudify']['management_rest_url'])
        cloudify_rest_uri = cloudify_resource_uri(scope, application, service, instance)
        request = case method
        when :post
            r = ::Net::HTTP::Post.new(cloudify_rest_uri)
            r.body = ::Chef::JSONCompat.to_json({key => value}) if value
            r
        when :delete
            ::Net::HTTP::Delete.new(cloudify_rest_uri + "/" + key)
        when :get
            ::Net::HTTP::Get.new(cloudify_rest_uri)
        else
            raise RuntimeError, "Method #{method} not implemented for Cloudify REST"
        end
        request.content_type = 'application/json'     
        response = Net::HTTP.start(cloudify_uri.host, cloudify_uri.port) do |http|
            http.request(request)
        end
        unless response.code == '200'
          raise RuntimeError.new "The REST request failed with code #{response.code}"
        end
    end
def cloudify_rest ( method , scope , application , service , instance , key , value = nil ) cloudify_uri = URI . parse ( node [ 'cloudify' ] [ 'management_rest_url' ] ) cloudify_rest_uri = cloudify_resource_uri ( scope , application , service , instance ) request = case method when :post r = :: Net :: HTTP :: Post . new ( cloudify_rest_uri ) r . body = :: Chef :: JSONCompat . to_json ( { key => value } ) if value r when :delete :: Net :: HTTP :: Delete . new ( cloudify_rest_uri + "/" + key ) when :get :: Net :: HTTP :: Get . new ( cloudify_rest_uri ) else raise RuntimeError , "Method #{method} not implemented for Cloudify REST" end request . content_type = 'application/json' response = Net :: HTTP . start ( cloudify_uri . host , cloudify_uri . port ) do | http | http . request ( request ) end unless response . code == '200' raise RuntimeError . new "The REST request failed with code #{response.code}" end end
a wrapper for et::HTTP.start that yields a connection to REST interface
a wrapper for et :: HTTP . start that yields a connection to REST interface
method
scope
application
service
instance
key
value