Skip to content
Snippets Groups Projects
get_osd_by_host.py 884 B
Newer Older
  • Learn to ignore specific revisions
  • #!/usr/bin/python
    import os,sys,getopt
    #systemctl list-units --type=service --state=active
    
    SCRIPT='get_osd_by_host.py'
    
    def help():
      print '%s -m <hostname>'%SCRIPT
      print '%s -h'%SCRIPT
    
    def main(argv):
       print argv
       try:
          opts, args = getopt.getopt(argv,"hm:",["machine="])
       except getopt.GetoptError:
          help()
          sys.exit(2)
       for opt, arg in opts:
          if opt == '-h':
             help()
             sys.exit()
          elif opt in ("-m", "--machine"):
             machine = arg
             cmd = os.popen("ssh %s systemctl list-units --type=service --state=active | grep ceph-osd | awk '{print $1}'"%machine).read()
             services = cmd.split("\n")
             services = services[0:-1]
             for i in services:
               print (i.split(".")[0]).split("@")[-1]
             
          else:
            help()
            sys.exit()
    
    if __name__ == "__main__":
       main(sys.argv[1:])