def default_director(client, dname=''): '''Selects a director (preferring the value passed in if possible), and creates a new password for use with that director. You will undoubtedly want to OVERRIDE THIS to meet the needs of your own site. The default in this case is the first one returned by a select against the director table with no where clause.''' if dname: d = bacula_tools.Director().search(dname) else: d = bacula_tools.Director().Find(order_by=bacula_tools.ID)[0] password = bacula_tools.PasswordStore(client, d) password.password = bacula_tools.GENERATE password.store()
def _cli_special_print(self): '''De-reference the Director and print its name.''' the_director = bacula_tools.Director().search( self[bacula_tools.DIRECTOR_ID]) fmt = '%' + str(self._maxlen) + 's: %s' print(fmt % (bacula_tools.DIRECTOR, the_director[bacula_tools.NAME])) return
def setUp(self): bacula_tools.MYSQL_DB = 'test' bacula_tools.MYSQL_HOST = 'localhost' bacula_tools.MYSQL_USER = '******' bacula_tools.MYSQL_PASS = '******' sql = pkg_resources.resource_string( 'bacula_tools', 'data/bacula_configuration.schema').split(';') self.bc = bacula_tools.Bacula_Factory() self.bc.connect(database='test', host='localhost', user='******', passwd='test') foo = sys.stderr sys.stderr = open('/dev/null', 'w') for s in sql: s = s.strip() if not s: continue # if 'DROP TABLE' in s: continue row = self.bc.do_sql(s) self.client = bacula_tools.Client() self.client.set_name('Client') self.director = bacula_tools.Director() self.director.set_name('Director') sys.stderr = foo return
def _cli_special_do_parse(self, args): '''When setting the password, ensure that a Director is referenced. If that's the case, make the appropriate updates.''' if (args.password == None) and (args.director == None): return # Nothing to do! if (args.password == None) ^ (args.director == None): logger.warning( 'You must specify both a password and a director to change a password. No change.' ) # Bail on any password changes, but otherwise continue return the_director = bacula_tools.Director().search(args.director) if not the_director[bacula_tools.ID]: logger.warning('Unable to find a director using "%s". No change.', args.director) return password = bacula_tools.PasswordStore(self, the_director) password.password = args.password if args.monitor: if args.monitor.lower() in bacula_tools.TRUE_VALUES: password.monitor = 1 else: password.monitor = 0 password.store() return
def __str__(self): self.output = ['Console {\n Name = "%(name)s"' % self, '}'] for key in self.SETUP_KEYS: self._simple_phrase(key) c = bacula_tools.Director().search(self[DIRECTOR_ID]) self.output.insert(-1, ' Password = "******"' % c[PASSWORD]) return '\n'.join(self.output)
def bconsole(self): '''This is what we'll call to dump out the config for the bconsole''' self.output = ['Director {\n Name = "%(name)s"' % self, '}'] c = bacula_tools.Director().search(self[DIRECTOR_ID]) self.output.insert(-1, ' Password = "******"' % c[PASSWORD]) if ADDRESS in c: self.output.insert( -1, ' DirPort = %(dirport)s\n Address = %(address)s' % c) else: self.output.insert( -1, ' Dir Addresses = {\n %s \n }\n' % c[DIRADDRESSES]) return '\n'.join(self.output)
def _cli_special_print(self): '''Prints out the passwords and the directors/consoles with which they are associated''' print('\nPasswords:') sql = 'select director_id, director_type from pwords where obj_id = %s and obj_type = %s' for row in self.bc.do_sql(sql, (self[bacula_tools.ID], self.IDTAG)): if row[1] == bacula_tools.Director.IDTAG: other = bacula_tools.Director().search(row[0]) if row[1] == bacula_tools.Console.IDTAG: other = bacula_tools.Console().search(row[0]) password = bacula_tools.PasswordStore(self, other) retval = '%30s: %s' % (other[bacula_tools.NAME], password.password) print(retval) return
def __str__(self): '''String representation of a Storage suitable for inclusion in a Director configuration.''' self.output = ['Storage {\n Name = "%(name)s"' % self, '}'] if getattr(self, bacula_tools.DIRECTOR_ID, None): a = bacula_tools.PasswordStore( self, bacula_tools.Director().search(self.director_id)) if getattr(a, bacula_tools.PASSWORD, None): self.output.insert(-1, ' Password = "******"' % a.password) for key in self.dir_keys: self._simple_phrase(key) for key in self.BOOL_KEYS: self._simple_phrase(key) return '\n'.join(self.output)
def _cli_special_do_parse(self, args): '''It should be noted that a Catalog can be associated with one, and only one, Director. This function handles changing the Director from the CLI.''' if args.director == None: return # Nothing to do! the_director = bacula_tools.Director() the_director.search(args.director) if not the_director[bacula_tools.ID]: the_director.search(args.director) if not the_director[bacula_tools.ID]: logger.warning( 'Unable to find a director using "%s". Association not changed', args.director) return self.set(bacula_tools.DIRECTOR_ID, the_director[bacula_tools.ID]) return
def _cli_special_print(self): '''Print out the passwords for the CLI.''' print('\nPasswords:') sql = 'select director_id, director_type from pwords where obj_id = %s and obj_type = %s' for row in self.bc.do_sql(sql, (self[bacula_tools.ID], self.IDTAG)): if row[1] == bacula_tools.Director.IDTAG: other = bacula_tools.Director().search(row[0]) if row[1] == bacula_tools.Console.IDTAG: other = bacula_tools.Console().search(row[0]) try: password = bacula_tools.PasswordStore(self, other) print('%30s: %s' % (other[bacula_tools.NAME], password.password)) except: # There's no password assiciated with this director/console. pass return
def __str__(self): '''Convert a Client into a string suitable for inclusion into a Director's configuration.''' self.output = ['Client {\n Name = "%(name)s"' % self, '}'] self.output.insert( -1, ' %s = "%s"' % (bacula_tools.CATALOG.capitalize(), self._fk_reference(bacula_tools.CATALOG_ID)[bacula_tools.NAME])) if getattr(self, bacula_tools.DIRECTOR_ID, None): pw_store = bacula_tools.PasswordStore( self, bacula_tools.Director().search(self.director_id)) if getattr(pw_store, bacula_tools.PASSWORD, None): self.output.insert(-1, ' Password = "******"' % pw_store.password) for key in [ bacula_tools.ADDRESS, bacula_tools.FDPORT, bacula_tools.FILERETENTION, bacula_tools.JOBRETENTION, bacula_tools.MAXIMUMCONCURRENTJOBS, bacula_tools.MAXIMUMBANDWIDTHPERJOB, bacula_tools.PRIORITY ]: self._simple_phrase(key) self._yesno_phrase(bacula_tools.AUTOPRUNE) return '\n'.join(self.output)
def _cli_special_do_parse(self, args): '''Handle CLI switches for password management.''' if (args.password == None) and (args.director == None): return # Nothing to do! if (args.password == None) ^ (args.director == None): print( '\n***WARNING***: You must specify both a password and a director to change a password. Password not changed.\n' ) # Bail on any password changes, but otherwise continue return d = bacula_tools.Director() try: d.search(args.director) except: d.search(args.director) if not d[bacula_tools.ID]: print( '\n***WARNING***: Unable to find a director using "%s". Password not changed\n' % args.director) return password = bacula_tools.PasswordStore(self, d) password.password = args.password password.store() return