Module: Bixby::Agent::Handshake
Instance Method Summary collapse
- #create_uuid ⇒ Object
- #get_hostname ⇒ Object
-
#get_mac_address ⇒ Object
Get the mac address of the system’s primary interface.
- #mac_changed? ⇒ Boolean
-
#register_agent(url, tenant, password, tags = nil) ⇒ JsonResponse
Register the agent with the server.
Methods included from Crypto
#create_keypair, #crypto_enabled?, #decrypt_from_server, #encrypt_for_server, #have_server_key?, #keypair, #private_key, #private_key_file, #public_key, #server_key, #server_key_file
Instance Method Details
#create_uuid ⇒ Object
74 75 76 |
# File 'lib/bixby-agent/agent/handshake.rb', line 74 def create_uuid UUIDTools::UUID.random_create.hexdigest end |
#get_hostname ⇒ Object
54 55 56 |
# File 'lib/bixby-agent/agent/handshake.rb', line 54 def get_hostname `hostname`.strip end |
#get_mac_address ⇒ Object
Get the mac address of the system’s primary interface
59 60 61 62 63 64 65 66 67 68 69 70 71 72 |
# File 'lib/bixby-agent/agent/handshake.rb', line 59 def get_mac_address return @mac if not @mac.nil? Facter.collection.fact(:ipaddress).value # force value to be loaded now (usually lazy-loaded) Facter.collection.fact(:interfaces).value Facter.collection.fact(:macaddress).value vals = Facter.collection.to_hash ip = vals["ipaddress"] raise "Unable to find IP address" if ip.nil? # use the primary IP of the system to find the associated interface name (e.g., en0 or eth0) int = vals.find{ |k,v| v == ip && k != "ipaddress" }.first.to_s.split(/_/)[1] raise "Unable to find primary interface" if int.nil? or int.empty? # finally, get the mac address @mac = vals["macaddress_#{int}"] end |
#mac_changed? ⇒ Boolean
50 51 52 |
# File 'lib/bixby-agent/agent/handshake.rb', line 50 def mac_changed? (not @mac_address.nil? and (@mac_address != get_mac_address())) end |
#register_agent(url, tenant, password, tags = nil) ⇒ JsonResponse
Register the agent with the server
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/bixby-agent/agent/handshake.rb', line 22 def register_agent(url, tenant, password, =nil) Bixby.manager_uri = @manager_uri = url ret = Bixby::Inventory.register_agent({ :uuid => @uuid, :public_key => self.public_key.to_s, :hostname => get_hostname(), :tenant => tenant, :password => password, :tags => , :version => Bixby::Agent::VERSION }) if ret.fail? then return ret end @access_key = ret.data["access_key"] @secret_key = ret.data["secret_key"] Bixby.client = Bixby::Client.new(access_key, secret_key) # success, store server's pub key File.open(self.server_key_file, 'w') do |f| f.puts(ret.data["server_key"]) end return ret end |