def destroy(params): """Deactive specific interface, argument params is dictionary type, and includes 'ifacename' key, which is a host interface name, e.g 'eth0' """ global logger logger = params["logger"] ifacename = params["ifacename"] try: hostip = utils.get_ip_address(ifacename) logger.info("interface %s is active" % ifacename) logger.debug("interface %s ip address: %s" % (ifacename, hostip)) except: logger.error("interface %s is deactive" % ifacename) return 1 conn = sharedmod.libvirtobj["conn"] ifaceobj = conn.interfaceLookupByName(ifacename) display_current_interface(conn) try: ifaceobj.destroy(0) logger.info("destroy host interface %s" % ifacename) display_current_interface(conn) if check_destroy_interface(hostip): logger.info("destroy host interface %s is successful" % ifacename) else: logger.error("fail to check destroy interface") return 1 except libvirtError, e: logger.error("API error message: %s, error code is %s" % (e.message, e.get_error_code())) logger.error("fail to destroy interface %s" % ifacename) return 1
def destroy(params): """Deactive specific interface, argument params is dictionary type, and includes 'ifacename' key, which is a host interface name, e.g 'eth0' """ global logger logger = params['logger'] ifacename = params['ifacename'] try: hostip = utils.get_ip_address(ifacename) logger.info("interface %s is active" % ifacename) logger.debug("interface %s ip address: %s" % (ifacename, hostip)) except: logger.error("interface %s is deactive" % ifacename) return 1 conn = sharedmod.libvirtobj['conn'] ifaceobj = conn.interfaceLookupByName(ifacename) display_current_interface(conn) try: ifaceobj.destroy(0) logger.info("destroy host interface %s" % ifacename) display_current_interface(conn) if check_destroy_interface(hostip): logger.info("destroy host interface %s is successful" % ifacename) else: logger.error("fail to check destroy interface") return 1 except libvirtError, e: logger.error("API error message: %s, error code is %s" \ % (e.message, e.get_error_code())) logger.error("fail to destroy interface %s" % ifacename) return 1
def create(params): """Activate specific interface, argument params is dictionary type, and includes 'ifacename' key, which is a host interface name, e.g 'eth0' """ global logger logger = params['logger'] ifacename = params['ifacename'] try: hostip = utils.get_ip_address(ifacename) logger.error("interface %s is running" % ifacename) logger.debug("interface %s ip address: %s" % (ifacename, hostip)) return 1 except: logger.info("interface %s is deactive" % ifacename) conn = sharedmod.libvirtobj['conn'] ifaceobj = conn.interfaceLookupByName(ifacename) display_current_interface(conn) try: ifaceobj.create(0) logger.info("create host interface %s" % ifacename) display_current_interface(conn) if check_create_interface(ifacename): logger.info("create host interface %s is successful" % ifacename) else: logger.error("fail to check create interface") return 1 except libvirtError, e: logger.error("API error message: %s, error code is %s" \ % (e.message, e.get_error_code())) logger.error("fail to create interface %s" %ifacename) return 1
def check_create_interface(ifacename): """Check creating interface result, it will can ping itself if create interface is successful. """ hostip = utils.get_ip_address(ifacename) logger.debug("interface %s ip address: %s" % (ifacename, hostip)) ping_cmd = "ping -c 4 -q %s" % hostip stat, ret = commands.getstatusoutput(ping_cmd) logger.debug("ping cmds exit status: %d" % stat) logger.debug("ping cmds exit result: %s" % ret) if stat == 0: logger.debug("can ping itself") return True else: logger.error("can't ping itself") return False
def __init__(self, server_address, data_cache): self.data_cache = data_cache ThreadingTCPServer.__init__(self, server_address, PDCacheRequestHandler) def finish_request(self, request, client_address): self.RequestHandlerClass(request, client_address, self, self.data_cache) if __name__ == '__main__': config = load_global_config() cache_size = config.get('cache_size') rrd_root = config.get("RRD_root") db_handler = RRDHandler.getInstance(rrd_root) cache = PerfDataCache.getInstance(cache_size, db_handler) public_host = get_ip_address(config.get("public_interface")) cache_server_port = config.get('cache_server_port') cache_server = PDCacheServer((public_host, cache_server_port), cache) logger.info("starting cache server...") try: cache_server.serve_forever() except KeyboardInterrupt, e: sys.exit(0)
loosely_collect = ('LoadModule', 'NetModule') intensive_period = 15 loose_period = 15 if moduleprefix == '': metric_groups = generate_metric_groups(standard_module_set) else: metric_groups = generate_metric_groups(xen_platform_module_set) ######################### # generate other configs ######################### ip = get_ip_address('eth0') remote_servers = [ { 'host' : '10.0.0.11', 'port' : 20060 } ] listen_channel = { 'port' : 20070 } collect_interval = 5 #ofile = curdir + os.path.sep + 'mon_agent.out'
if options.config: print "Reading configuration from %s" % options.config configuration.read(options.config) # Fixme: make sure the file exists (config, msconfig) = utils.parse_config(configuration, options) if not config['multistage']: print "Provisioning URI is %s\n" % config['prov_uri'] sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM, socket.IPPROTO_UDP) sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) sock.bind(('224.0.1.75', options.local_port)) mreq = struct.pack('4sl', socket.inet_aton('224.0.1.75'), socket.INADDR_ANY) sock.setsockopt(socket.IPPROTO_IP, socket.IP_ADD_MEMBERSHIP, mreq) if not options.local_ip and not config['local_ip']: config['local_ip'] = utils.get_ip_address() else: config['local_ip'] = options.local_ip if not "local_port" in config and not config['local_port']: config['local_port'] = options.local_port print "Local IP Address is :: %s" % config['local_ip'] print "Local IP Port is :: %s" % config['local_port'] print "=" * 80 # Main loop while True: subs = sock.recv(10240) if options.verbose: print subs