In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-04-11 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >
Share
Shulou(Shulou.com)06/01 Report--
Http://blog.csdn.net/smallfish2983/article/details/38078019
According to the above guy wrote, beginners, do not spit blood, the basic function has been realized.
Root@ubuntu12:~/ansible/tornado# tree
.
├── templates
│ ├── index.html
│ └── result.html
└── test.py
Root@ubuntu12:~/ansible/tornado# cat test.py
# coding:utf-8
Import os.path
Import tornado.locale
Import tornado.httpserver
Import tornado.ioloop
Import tornado.options
Import tornado.web
From tornado.options import define, options
Import pymongo
Define (port, default=8000, help= "run on the given port", type=int)
Class Application (tornado.web.Application):
Def _ init__ (self):
# initialize something
Handlers = [
# url matching
(r "/", MainHandler)
(r "/ index", MainHandler)
(r "/ result", Module_actionHandler)
]
Settings = dict (
# Program settings, dictionary form
Template_path=os.path.join (os.path.dirname (_ _ file__), "templates")
# set the template file path
Static_path=os.path.join (os.path.dirname (_ _ file__), "static")
# set static file path, such as css\ jpg\ gif, etc.
# ui_modules= {"Book": BookModule}
# set ui module, you can add multiple modules with a dictionary
Debug=True
)
Tornado.web.Application.__init__ (self, handlers, * * settings)
# incoming settings configuration
Class MainHandler (tornado.web.RequestHandler):
# Home page function method
Def get (self):
# set get method function
Self.render (
"index.html"
)
Class Module_actionHandler (tornado.web.RequestHandler):
# define the method of module operation function
Def post (self, * args, * * kwargs):
Pattern = self.get_arguments ('pattern') [0]
# get hostname
Module_name = self.get_arguments ('module_name') [0]
# get the module name
Module_args = self.get_arguments ('module_args') [0]
# get parameters
Import ansible.runner
Runner = ansible.runner.Runner (
# run the script according to ansible's api
Module_name = module_name
Module_args = module_args
Pattern = pattern
)
Result = runner.run ()
Conn = pymongo.Connection ("localhost", 27017)
Db = conn ["ansible"]
If type (result) = = dict:
Db.ansible.insert (result)
Def pars_result (result):
# define a function to judge the result
If len (result ['dark']) > 0:
# if the dark return is not empty, the operation failed
Return result ['dark'],' failed!'
Else:
Return result ['contacted'],' success!'
Result = pars_result (result)
Self.render (
"result.html"
Message = result [0]
Result = result [1]
)
If _ name__ = = "_ _ main__":
Tornado.options.parse_command_line ()
Http_server = tornado.httpserver.HTTPServer (Application ())
Http_server.listen (options.port)
Tornado.ioloop.IOLoop.instance () .start ()
# cat index.html
Ansible
Enter arg bellow:
Pattern
Module_name
Module_args
# cat result.html
Ansible result
Ansible result
Message: `message`
Result: `result`
Attachment: http://down.51cto.com/data/2364907
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.