Merge remote-tracking branch 'origin/ci280'
* origin/ci280: ci: Another round of fixes for random Ansible UI breakage in 2.7/2.8 ci: work around various broken aspects of Travis VM image Use virtualenv Python for stub connections to workaround problem ci: Ansible 2.8 requires Python 2.7. tests: add 2.8 format async error timeout message ansible: prevent tempfile.mkstemp() leaks. update gitignore again ci: try bumping more Travis jobs to Ansible 2.8. add .*.pid to gitignore tests: allow running without hdrhistograms library. issue #578: update Changelog. travis: exclude docs-master from CI issue #589: ensure real FileService/PushFileService are in the docs issue #589: ensure real FileService/PushFileService are in the docs docs: add new contributor entry issue #589: remove outdated/incomplete examples issue #589: split services example out and make it run.pull/595/head
commit
de12097bc4
@ -1,15 +0,0 @@
|
|||||||
|
|
||||||
import mitogen.master
|
|
||||||
import mitogen.unix
|
|
||||||
import mitogen.service
|
|
||||||
import mitogen.utils
|
|
||||||
|
|
||||||
|
|
||||||
PING = 500
|
|
||||||
|
|
||||||
|
|
||||||
mitogen.utils.log_to_file()
|
|
||||||
|
|
||||||
router, parent = mitogen.unix.connect('/tmp/mitosock')
|
|
||||||
with router:
|
|
||||||
print(mitogen.service.call(parent, CONNECT_BY_ID, {}))
|
|
@ -0,0 +1,52 @@
|
|||||||
|
import mitogen
|
||||||
|
import mitogen.service
|
||||||
|
|
||||||
|
|
||||||
|
class FileService(mitogen.service.Service):
|
||||||
|
"""
|
||||||
|
Simple file server, for demonstration purposes only! Use of this in
|
||||||
|
real code would be a security vulnerability as it would permit children
|
||||||
|
to read any file from the master's disk.
|
||||||
|
"""
|
||||||
|
|
||||||
|
@mitogen.service.expose(policy=mitogen.service.AllowAny())
|
||||||
|
@mitogen.service.arg_spec(spec={
|
||||||
|
'path': str
|
||||||
|
})
|
||||||
|
def read_file(self, path):
|
||||||
|
with open(path, 'rb') as fp:
|
||||||
|
return fp.read()
|
||||||
|
|
||||||
|
|
||||||
|
def download_file(source_context, path):
|
||||||
|
s = source_context.call_service(
|
||||||
|
service_name=FileService, # may also be string 'pkg.mod.FileService'
|
||||||
|
method_name='read_file',
|
||||||
|
path=path,
|
||||||
|
)
|
||||||
|
|
||||||
|
with open(path, 'w') as fp:
|
||||||
|
fp.write(s)
|
||||||
|
|
||||||
|
|
||||||
|
def download_some_files(source_context, paths):
|
||||||
|
for path in paths:
|
||||||
|
download_file(source_context, path)
|
||||||
|
|
||||||
|
|
||||||
|
@mitogen.main()
|
||||||
|
def main(router):
|
||||||
|
pool = mitogen.service.Pool(router, services=[
|
||||||
|
FileService(router),
|
||||||
|
])
|
||||||
|
|
||||||
|
remote = router.ssh(hostname='k3')
|
||||||
|
remote.call(download_some_files,
|
||||||
|
source_context=router.myself(),
|
||||||
|
paths=[
|
||||||
|
'/etc/passwd',
|
||||||
|
'/etc/hosts',
|
||||||
|
]
|
||||||
|
)
|
||||||
|
pool.stop()
|
||||||
|
|
@ -1,20 +0,0 @@
|
|||||||
|
|
||||||
# The service framework will fundamentally change (i.e. become much nicer, and
|
|
||||||
# hopefully lose those hard-coded magic numbers somehow), but meanwhile this is
|
|
||||||
# a taster of how it looks today.
|
|
||||||
|
|
||||||
import mitogen
|
|
||||||
import mitogen.service
|
|
||||||
import mitogen.unix
|
|
||||||
|
|
||||||
|
|
||||||
class PingService(mitogen.service.Service):
|
|
||||||
def dispatch(self, dct, msg):
|
|
||||||
return 'Hello, world'
|
|
||||||
|
|
||||||
|
|
||||||
@mitogen.main()
|
|
||||||
def main(router):
|
|
||||||
listener = mitogen.unix.Listener(router, path='/tmp/mitosock')
|
|
||||||
service = PingService(router)
|
|
||||||
service.run()
|
|
Loading…
Reference in New Issue