Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

API call reduction #3

Merged
merged 1 commit into from

1 participant

@jamtur01

Should have reduced the number of API calls in a creation run and
in a regular run.

@jamtur01 jamtur01 API call reduction
Should have reduced the number of API calls in a creation run and
in a regular run.

Also incremented to v0.0.4
9fe423a
@jamtur01 jamtur01 merged commit b04e8e7 into puppetlabs:master
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Jan 5, 2012
  1. @jamtur01

    API call reduction

    jamtur01 authored
    Should have reduced the number of API calls in a creation run and
    in a regular run.
    
    Also incremented to v0.0.4
This page is out of date. Refresh to see the latest.
Showing with 24 additions and 15 deletions.
  1. +1 −1  Modulefile
  2. +23 −14 lib/puppet/provider/boundary_meter/boundary_meter.rb
View
2  Modulefile
@@ -1,5 +1,5 @@
name 'puppetlabs-bprobe'
-version '0.0.3'
+version '0.0.4'
source 'UNKNOWN'
author 'puppetlabs'
license 'Apache 2.0'
View
37 lib/puppet/provider/boundary_meter/boundary_meter.rb
@@ -47,14 +47,11 @@ def build_url(resource, action)
when :search
"https://#{API_HOST}/#{resource[:id]}/meters?name=#{resource[:name]}"
when :certificates
- meter_id = get_meter("id", resource)
- "https://#{API_HOST}/#{resource[:id]}/meters/#{meter_id}"
+ "https://#{API_HOST}/#{resource[:id]}/meters/#{@meter_id}"
when :tags
- meter_id = get_meter("id", resource)
- "https://#{API_HOST}/#{resource[:id]}/meters/#{meter_id}/tags"
+ "https://#{API_HOST}/#{resource[:id]}/meters/#{@meter_id}/tags"
when :delete
- meter_id = get_meter("id", resource)
- "https://#{API_HOST}/#{resource[:id]}/meters/#{meter_id}"
+ "https://#{API_HOST}/#{resource[:id]}/meters/#{@meter_id}"
end
end
@@ -67,8 +64,14 @@ def create_meter(resource)
Puppet.info("Creating meter #{resource[:name]}")
response = http_request(:post, url, headers, body)
+ body = JSON.parse(response.body)
+ @meter_id = body["id"]
+ @tags = body["tags"]
download_request("key", resource)
download_request("cert", resource)
+ if resource[:tags]
+ set_meter_tags(resource)
+ end
rescue Exception => e
raise Puppet::Error, "Could not create meter #{resource[:name]}, failed with #{e}"
end
@@ -134,9 +137,9 @@ def download_request(type, resource)
end
end
- def set_meter_tags(value, resource)
- meter_tags = get_meter("tags", resource).sort
- new_tags = value.sort
+ def set_meter_tags(resource)
+ meter_tags = @tags || get_meter("tags", resource)
+ new_tags = resource[:tags]
new_tags.each do |t|
unless meter_tags.include?(t)
add_meter_tag(t)
@@ -155,7 +158,7 @@ def add_meter_tag(tag)
http_request(:put, "#{url}/#{tag}", headers, "")
rescue Exception => e
- raise Puppet::Error, "Could not add meter tag: #{tag}, failed with #{e}"
+ raise Puppet::Error, "Could not add meter tag: #{tag}, failed with #{e}"
end
end
@@ -242,7 +245,12 @@ def create
end
def exists?
- get_meter("id", resource)
+ @meter_id = get_meter("id", resource)
+ if @meter_id
+ true
+ else
+ false
+ end
end
def destroy
@@ -254,10 +262,11 @@ def destroy
end
def tags
- get_meter("tags", resource)
+ @tags = get_meter("tags", resource)
+ @tags
end
- def tags=(value)
- set_meter_tags(value, resource)
+ def tags=(tags)
+ set_meter_tags(resource)
end
end
Something went wrong with that request. Please try again.