Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ENV['FOREMAN_YML'] ||= File.expand_path(File.join(File.dirname(__FILE__), 'foreman.yml'))
- require 'foreman_api'
- require 'pry'
- require 'rest_client'
- require 'yaml'
- require 'json'
- require 'pp'
- config = YAML.load(File.read(ENV['FOREMAN_YML']))
- options = {
- :base_url => config['url'],
- :username => config['username'],
- :password => config['password'],
- }
- SmartClassParameter = ForemanApi::Resources::SmartClassParameter.new(options)
- ib_interfaces = SmartClassParameter.index(:search => 'puppetclass = infiniband and key = interfaces')[0]['results'].first
- ib_interfaces_id = ib_interfaces['id']
- ib_interface_data = {
- 'override_value' => {
- 'match' => 'fqdn=c0936.brazos.tamu.edu',
- 'value' => {'ib0'=>{'ipaddr'=>'192.168.209.98','netmask'=>'255.255.252.0'}},
- }
- }
- pp ib_interface_data
- =begin
- {"override_value"=>
- {"match"=>"fqdn=c0936.brazos.tamu.edu",
- "value"=>{"ib0"=>{"ipaddr"=>"192.168.209.98", "netmask"=>"255.255.252.0"}}}}
- =end
- rest_opts = {
- :content_type => 'application/json',
- :accept => 'application/json;version=2',
- }
- rest_url_base = "https://#{config['username']}:#{config['password']}@foreman.brazos.tamu.edu"
- response = RestClient.post("#{rest_url_base}/api/smart_class_parameters/#{ib_interfaces_id}/override_values", ib_interface_data.to_json, rest_opts)
- data = JSON.parse(response)
- pp data
- =begin
- {"id"=>372,
- "match"=>"fqdn=c0936.DOMAIN_OMITTED",
- "value"=>{"ib0"=>{"ipaddr"=>"192.168.209.98", "netmask"=>"255.255.252.0"}},
- "created_at"=>"2014-05-05T16:49:11Z",
- "updated_at"=>"2014-05-05T16:49:11Z"}
- =end
- exit 0
- =begin
- Value in Foreman:
- --- !ruby/hash:ActiveSupport::HashWithIndifferentAccess
- ib0: !ruby/hash:ActiveSupport::HashWithIndifferentAccess
- ipaddr: 192.168.209.98
- netmask: 255.255.252.0
- =end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement