Example #1
0
 def command_10_bootstrapChef(self, user, message, args):
     """([Cc]hef)\s+(bootstrap)( +(.*))?$(?i)"""
     action = args[1]
     target = None
     try:
         print "args"
         print args
         if args[2] != None:
             target = args[2]
             target = target.lstrip()
         else:
             target = "all"
     except:
         pass
     if action == "bootstrap":
         try:
             if not target:
                 self.replyMessage(user, "You need to load a site first.")
             else:
                 for host in self.devload.hosts:
                     self.replyMessage(user, "Performing chef bootstrap " + target + " on " + host[0])
                     print host
                     self.devload.device_type = host[3]
                     guardian_angel = actions(host[3], host[0], host[1], host[2], debug=self.debug)
                     data = guardian_angel.chef_bootstrap(target)
                     for line in data:
                         self.replyMessage(user, host[0] + ": " + line)
                         # time.sleep(1)
         except Exception, e:
             for i in e:
                 msg = "Exception: %s" % e
                 self.replyMessage(user, msg)
             pass
Example #2
0
 def command_07_bootstrapSdn(self, user, message, args):
     """([Ss]dn)\s+(bootstrap)( +(.*))?$(?i)"""
     action = args[1]
     target = None
     try:
         print "args"
         print args
         if args[2] != None:
             target = args[2]
             target = target.lstrip()
         else:
             target = "all"
     except:
         pass
     if action == "bootstrap":
         try:
             if not target:
                 self.replyMessage(user, "You need to load a site first.")
             else:
                 for host in self.devload.hosts:
                     self.replyMessage(user, "Performing knife " + target + " on " + host[0])
                     print host
                     self.devload.device_type = host[3]
                     guardian_angel = actions(host[3], host[0], host[1], host[2], debug=self.debug)
                     self.replyMessage(user, "Bootstrapping " + host[0])
                     guardian_angel.chef_bootstrap(target)
         except Exception, e:
             for i in e:
                 msg = "Exception: %s" % e
                 self.replyMessage(user, msg)
             pass
Example #3
0
 def command_06_backupSdn(self, user, message, args):
     """([Ss]dn)\s+(backup)"""
     action = args[1]
     try:
         print "args"
         print args
         if args[2] != None:
             target = args[2]
             target = target.lstrip()
         else:
             target = "all"
     except:
         pass
     if action == "backup":
         try:
             if not self.devload.hosts:
                 self.replyMessage(user, "You need to load a site first.")
             else:
                 for host in self.devload.hosts:
                     self.replyMessage(user, "Performing backup on " + host[0])
                     print host
                     self.devload.device_type = host[3]
                     guardian_angel = actions(host[3], host[0], host[1], host[2], debug=self.debug)
                     self.replyMessage(user, "Backing up " + host[0])
                     guardian_angel.perform_backup()
         except Exception, e:
             for i in e:
                 msg = "Exception: %s" % e
                 self.replyMessage(user, msg)
             pass
Example #4
0
	def do_backup(self, args):
		"""backup 
		performs a backup on the device"""
		if self.device_type is not None:
			for host in self.hosts:
				print "Backing up %s" % host[0]
				guardian_angel=sdn.actions(self.device_type, host[0], host[1], host[2],debug=self.debug)
				guardian_angel.perform_backup()
		else:
			print "Not connected or configured"
Example #5
0
    def command_11_knifeChef(self, user, message, args):
        """([Cc]hef)\s+(knife)( +(.*))?$(?i)"""
        action = args[1]
        target = None
        try:
            print "args"
            print args
            if args[2] != None:
                target = args[2]
                target = target.lstrip()
            else:
                target = "all"
        except:
            pass
        if action == "knife":
            try:
                if not target:
                    self.replyMessage(user, "You need to load a site first.")
                else:
                    for host in self.devload.hosts:
                        print "knifechef: is this a chefserver?:"
                        host
                        if host[3] != "chefserver":
                            continue
                        self.replyMessage(user, "Performing knife " + target + " on " + host[0])
                        self.devload.device_type = host[3]
                        try:
                            if config.sshkeys[host[3]]:
                                sshkey = config.sshkeys[host[3]]
                            else:
                                sshkey = config.sshkey
                        except:
                            sshkey = config.sshkey
                        guardian_angel = actions(host[3], host[0], host[1], host[2], sshkey=sshkey)
                        data = guardian_angel.chef_knife(target)
                        if data:
                            reply = ""
                            for line in data:
                                reply += "%s\n" % line

                            self.replyMessage(user, reply)

            except Exception, e:
                for i in e:
                    msg = "Exception: %s" % e
                    self.replyMessage(user, msg)
                pass
Example #6
0
parser.add_option("-p", "--pass", type="string", dest="PASS", help="Password to use.", default=False)
parser.add_option("-t", "--type", type="string", dest="TYPE", help="Device type that Host is, options are ciscoswitch,ciscoasa,bigip,arista,hp. default ciscoswitch", default="ciscoswitch")
parser.add_option("-d", "--destination",  type="string", dest="DESTINATION", help="Directory to save the backups, underneath /var/lib/tftpboot, default is backups/", default=False)
parser.add_option("-c", "--cron", action="store_true", dest="CRON", help="Run as a cron", default=False)
parser.add_option("-k", "--key", type="string", dest="SSHKEY", help="The path to the SSH Key to use.", default=False)

# global debug switch
bigbadbug=True
		
if __name__=='__main__':
	try:
		"""
		test whether we are a cron run,
		or only doing one device
		"""
		(options, args) = parser.parse_args()
		if options.CRON == True:
			sdn.actions(debug=bigbadbug).perform_backup_cron()
		else:
			# check the basic info
			if options.USER and options.HOST:
				pass
			else:
				raise Exception("Usage: python backup.py -u user -p pass -x host OR python backup.py --cron")
			print "Performing backup on device %s, type %s ... " % (options.HOST,options.TYPE)
			dobackup = sdn.actions(options.TYPE, options.HOST, options.USER, options.PASS, debug=bigbadbug)
			dobackup.perform_backup()
			dobackup.commit_changes()
	except Exception as e:
		print e
Example #7
0
	def do_ban_ip(self,attacker):
		if self.device_type is not None:
			for host in self.hosts:
				banhammer=sdn.actions(self.device_type, host[0], host[1], host[2],debug=self.debug)
				banhammer.ban_ip(attacker)