示例#1
0
	def __init__(self,hostaddr=None,noop='noop'):
		"""
		"""
		Conf.__init__(self)

		logfile = self.logfile

		c = Common()
		c.banner()
		c.client_hosts()

		self.__host=hostaddr
		self.__noop=noop
		self.__counter = 0
		self.__exclude = 0

		self.__reader = open(logfile)
		self.__startline = len(self.__reader.readlines())
		self.__reader.close()

		l = Logger('initiator')
		l.logx('-'*70)

		if self.__host=='all':
			l.logx('Update command on all hosts executed')
			self.update_all()
			l.event_counter(self.__startline)

		elif re.match(r'^\.\*$',self.__host):
			print '\n[-]--> please use \'all\' instead of \'.*\'\n'

		elif re.match(r'.*[\.\*\+\[\]]+.*',self.__host):
			l.logx('Update regex command (%s) executed' % self.__host)
			self.reget_host()
			l.event_counter(self.__startline)

		else:
			l.logx('Update command on %s executed' % self.__host)
			env.host_string=self.__host
			self.update_host()
			l.event_counter(self.__startline)

		l.logx('End of execution')
示例#2
0
	def run(self):
		""" Method used to validate the certificats and update the puppet client.
		"""
		c = Common()
		result = self.checkCertificate()

		l = Logger(c.client_name())

		try:
			if result:
				with hide('warnings','stderr'):
					print '\n[+]--> %s is already linked to the master <--\n' % c.client_name()

					if exists('/etc/.hg'):
						print '[+]--> Configuration files is going to be saved by etckeeper <--\n'
						run('/usr/sbin/etckeeper commit \"Commit by puppet\"')

					runCacher = run('puppet agent --server %s --test' % self.puppet_server)
					runSplit = string.split(runCacher,'\n')

					for runLine in runSplit:
						fullString = '%s - %s' % (c.client_name(),runLine)
						l.logx(fullString)

					l.logx('-'*70)

			else:
				print '\n[-]--> %s is not linked to the master\n' % c.client_name()

				validcertificate = ValidCert()
				validcertificate.start()

				with hide('warnings'):
					run('puppet agent --server %s --waitforcert 3 --test' % self.puppet_server)

				validcertificate.join()

		except Exception, e:
			print 'error :', e