integrate parser
Signed-off-by: Nico Schottelius <nico@kr.ethz.ch>
This commit is contained in:
		
					parent
					
						
							
								c5d960438c
							
						
					
				
			
			
				commit
				
					
						979174a568
					
				
			
		
					 1 changed files with 36 additions and 50 deletions
				
			
		
							
								
								
									
										50
									
								
								bin/cdist
									
										
									
									
									
								
							
							
						
						
									
										50
									
								
								bin/cdist
									
										
									
									
									
								
							| 
						 | 
					@ -20,13 +20,13 @@
 | 
				
			||||||
#
 | 
					#
 | 
				
			||||||
#
 | 
					#
 | 
				
			||||||
 | 
					
 | 
				
			||||||
import sys
 | 
					import argparse
 | 
				
			||||||
import subprocess # execute stuff
 | 
					 | 
				
			||||||
import os
 | 
					 | 
				
			||||||
import tempfile
 | 
					 | 
				
			||||||
import shutil
 | 
					 | 
				
			||||||
import logging
 | 
					import logging
 | 
				
			||||||
 | 
					import os
 | 
				
			||||||
 | 
					import subprocess
 | 
				
			||||||
 | 
					import shutil
 | 
				
			||||||
 | 
					import sys
 | 
				
			||||||
 | 
					import tempfile
 | 
				
			||||||
 | 
					
 | 
				
			||||||
# Given paths from installation
 | 
					# Given paths from installation
 | 
				
			||||||
BASE_DIR = os.path.abspath(os.path.join(os.path.dirname(__file__), os.pardir))
 | 
					BASE_DIR = os.path.abspath(os.path.join(os.path.dirname(__file__), os.pardir))
 | 
				
			||||||
| 
						 | 
					@ -37,6 +37,7 @@ MANIFEST_DIR               = os.path.join(CONF_DIR, "manifest")
 | 
				
			||||||
REMOTE_BASE_DIR            = "/var/lib/cdist"
 | 
					REMOTE_BASE_DIR            = "/var/lib/cdist"
 | 
				
			||||||
REMOTE_CONF_DIR            = os.path.join(REMOTE_BASE_DIR, "conf")
 | 
					REMOTE_CONF_DIR            = os.path.join(REMOTE_BASE_DIR, "conf")
 | 
				
			||||||
REMOTE_GLOBAL_EXPLORER_DIR = os.path.join(REMOTE_CONF_DIR, "explorer")
 | 
					REMOTE_GLOBAL_EXPLORER_DIR = os.path.join(REMOTE_CONF_DIR, "explorer")
 | 
				
			||||||
 | 
					VERSION                    = "2.0.0"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#class Context(object):
 | 
					#class Context(object):
 | 
				
			||||||
| 
						 | 
					@ -64,7 +65,6 @@ log = logging.getLogger()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
class Cdist:
 | 
					class Cdist:
 | 
				
			||||||
   """Cdist main class to hold arbitrary data"""
 | 
					   """Cdist main class to hold arbitrary data"""
 | 
				
			||||||
   version="2.0.0"
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
   def __init__(self, hostname, initial_manifest=False):
 | 
					   def __init__(self, hostname, initial_manifest=False):
 | 
				
			||||||
      self.hostname = hostname
 | 
					      self.hostname = hostname
 | 
				
			||||||
| 
						 | 
					@ -195,27 +195,10 @@ class Cdist:
 | 
				
			||||||
if __name__ == "__main__":
 | 
					if __name__ == "__main__":
 | 
				
			||||||
   hostname=sys.argv[1]
 | 
					   hostname=sys.argv[1]
 | 
				
			||||||
 | 
					
 | 
				
			||||||
   for host in sys.argv[1:]:
 | 
					   parser = argparse.ArgumentParser(description='cdist ' + VERSION)
 | 
				
			||||||
      c = Cdist(host)
 | 
					 | 
				
			||||||
      c.deploy_to()
 | 
					 | 
				
			||||||
      print(c.list_global_explorers())
 | 
					 | 
				
			||||||
      c.cleanup()
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
#!/usr/bin/env python3
 | 
					 | 
				
			||||||
# -*- coding: utf-8 -*-
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
import logging
 | 
					 | 
				
			||||||
# TODO: configure logging based on config and/or user given arguments
 | 
					 | 
				
			||||||
logging.basicConfig(level=logging.INFO, format='%(levelname)s: %(message)s')
 | 
					 | 
				
			||||||
log = logging.getLogger()
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
import argparse
 | 
					 | 
				
			||||||
import sys
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
if __name__ == '__main__':
 | 
					 | 
				
			||||||
    parser = argparse.ArgumentParser(description='Some helpfull blabla')
 | 
					 | 
				
			||||||
   parser.add_argument('host', nargs='+', help='one or more hosts to operate on')
 | 
					   parser.add_argument('host', nargs='+', help='one or more hosts to operate on')
 | 
				
			||||||
 | 
					   parser.add_argument('-d', '--debug', help='set log level to debug',
 | 
				
			||||||
 | 
					       action='store_true')
 | 
				
			||||||
   parser.add_argument('-i', '--initial-manifest', 
 | 
					   parser.add_argument('-i', '--initial-manifest', 
 | 
				
			||||||
       help='path to a cdist manifest or - to read from stdin',
 | 
					       help='path to a cdist manifest or - to read from stdin',
 | 
				
			||||||
       dest='manifest', required=True)
 | 
					       dest='manifest', required=True)
 | 
				
			||||||
| 
						 | 
					@ -225,17 +208,20 @@ if __name__ == '__main__':
 | 
				
			||||||
   parser.add_argument('-s', '--sequential',
 | 
					   parser.add_argument('-s', '--sequential',
 | 
				
			||||||
       help='operate on multiple hosts sequentially',
 | 
					       help='operate on multiple hosts sequentially',
 | 
				
			||||||
       action='store_false', dest='parallel')
 | 
					       action='store_false', dest='parallel')
 | 
				
			||||||
    parser.add_argument('-d', '--debug', help='set log level to debug',
 | 
					 | 
				
			||||||
        action='store_true')
 | 
					 | 
				
			||||||
   
 | 
					   
 | 
				
			||||||
   args = parser.parse_args(sys.argv[1:])
 | 
					   args = parser.parse_args(sys.argv[1:])
 | 
				
			||||||
   if args.debug:
 | 
					   if args.debug:
 | 
				
			||||||
       logging.root.setLevel(logging.DEBUG)
 | 
					       logging.root.setLevel(logging.DEBUG)
 | 
				
			||||||
    log.debug('Look ma, now whe\'re showing debug messages')
 | 
					 | 
				
			||||||
   
 | 
					   
 | 
				
			||||||
   try:
 | 
					   try:
 | 
				
			||||||
      print(args)
 | 
					      print(args)
 | 
				
			||||||
        #import cdist
 | 
					      import cdist
 | 
				
			||||||
        #sys.exit(cdist.main(args))
 | 
					      sys.exit(cdist.main(args))
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					      for host in sys.argv[1:]:
 | 
				
			||||||
 | 
					         c = Cdist(host)
 | 
				
			||||||
 | 
					         c.deploy_to()
 | 
				
			||||||
 | 
					         print(c.list_global_explorers())
 | 
				
			||||||
 | 
					         c.cleanup()
 | 
				
			||||||
   except KeyboardInterrupt:
 | 
					   except KeyboardInterrupt:
 | 
				
			||||||
       sys.exit(0)
 | 
					       sys.exit(0)
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue