Register.py 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. #!/usr/bin/env python2.6
  2. '''
  3. Licensed to the Apache Software Foundation (ASF) under one
  4. or more contributor license agreements. See the NOTICE file
  5. distributed with this work for additional information
  6. regarding copyright ownership. The ASF licenses this file
  7. to you under the Apache License, Version 2.0 (the
  8. "License"); you may not use this file except in compliance
  9. with the License. You may obtain a copy of the License at
  10. http://www.apache.org/licenses/LICENSE-2.0
  11. Unless required by applicable law or agreed to in writing, software
  12. distributed under the License is distributed on an "AS IS" BASIS,
  13. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14. See the License for the specific language governing permissions and
  15. limitations under the License.
  16. '''
  17. import os
  18. import time
  19. import subprocess
  20. from Hardware import Hardware
  21. import hostname
  22. from HostInfo import HostInfo
  23. firstContact = True
  24. class Register:
  25. """ Registering with the server. Get the hardware profile and
  26. declare success for now """
  27. def __init__(self, config):
  28. self.hardware = Hardware(config)
  29. self.config = config
  30. def build(self, id='-1'):
  31. global clusterId, clusterDefinitionRevision, firstContact
  32. timestamp = int(time.time()*1000)
  33. hostInfo = HostInfo(self.config)
  34. agentEnv = { }
  35. hostInfo.register(agentEnv, False, False)
  36. version = self.read_agent_version()
  37. register = { 'responseId' : int(id),
  38. 'timestamp' : timestamp,
  39. 'hostname' : hostname.hostname(),
  40. 'publicHostname' : hostname.public_hostname(),
  41. 'hardwareProfile' : self.hardware.get(),
  42. 'agentEnv' : agentEnv,
  43. 'agentVersion' : version
  44. }
  45. return register
  46. def read_agent_version(self):
  47. data_dir = self.config.get('agent', 'prefix')
  48. ver_file = os.path.join(data_dir, 'version')
  49. f = open(ver_file, "r")
  50. version = f.read().strip()
  51. f.close()
  52. return version