Last active
August 29, 2015 13:58
-
-
Save nohtyp/10331844 to your computer and use it in GitHub Desktop.
Ruby Gist to remove servers from satellite server
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/env ruby | |
| require 'xmlrpc/client' | |
| require 'net/https' | |
| require 'openssl' | |
| #The following variables can take variables for puppet | |
| @SATELLITE_URL = "serverurl/rpc/api" | |
| @SATELLITE_LOGIN = "username" | |
| @SATELLITE_PASSWORD = "password" | |
| @mysystem = ARGV[0].to_s | |
| @use_ssl = true | |
| @mytimeout = 30 | |
| #Break up url to provide data for client object | |
| match = /^([^:]+):\/\/(([^@]+)@)?([^\/]+)(\/.*)?$/.match(@SATELLITE_URL) | |
| #Host and port for url | |
| @host, @port = match[4].split(":") | |
| def delete_server(myserver, myserverid) | |
| puts "This script has deleted server #{myserver} with id: #{myserverid} from #{@host}" | |
| return_code = @client.call('system.deleteSystems', @key, myserverid) | |
| end | |
| @client = XMLRPC::Client.new2("#{@SATELLITE_URL}") | |
| #disable check of ssl cert | |
| @client.instance_variable_get(:@http).instance_variable_set(:@verify_mode, OpenSSL::SSL::VERIFY_NONE) | |
| @key = @client.call('auth.login', @SATELLITE_LOGIN, @SATELLITE_PASSWORD) | |
| serverList = @client.call('system.listSystems', @key) | |
| serverList.each do |x| | |
| if x['name'] == "#{@mysystem}" | |
| delete_server(x['name'], x['id']) | |
| else | |
| next | |
| end | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment