bsdci / libioc

A Python library to manage jails with ioc{age,ell}
https://bsd.ci/libioc
Other
38 stars 11 forks source link

not changed running status for jail. #595

Closed himrock922 closed 5 years ago

himrock922 commented 5 years ago

Hi All, I developing of jail hosting system via Django. if stop and start method execute via libiocage, a jail status not changed of running or stopping.

The below response is result for iocage.datasets via iocage and jail.running via libiocage.

from django.shortcuts import render
from django.http import Http404
from django.http import HttpResponse
from iocage_lib import iocage as iocage_lib
import json
import iocage

def index(request):
    try:
        jails = iocage.Jails()
        jail = iocage_lib.ioc_list.IOCList()
        print(jails[0].running)
        print(jail.list_datasets())
    except (Exception, SystemExit):
        raise Http404("Jails does not exist")
    return render(request, 'jails/index.html', {'jails': jails })

def start(request):
    try:
        response = json.loads(request.body)
        jail = iocage.Jail(response['jail_name'])
        jail.start()
    except (Exception, SystemExit):
        raise Http404("Jail does not exist")
    return HttpResponse('OK')

def stop(request):
    try:
        response = json.loads(request.body)
        jail = iocage.Jail(response['jail_name'])
        jail.stop()
    except (Exception, SystemExit):
        raise Http404("Jail does not exist")
    return HttpResponse('OK')

+-----+--------+-------+--------------+--------------+ | JID | NAME | STATE | RELEASE | IP4 | +=====+========+=======+==============+==============+ | 12 | myjail | up | 11.2-RELEASE | 192.168.1.10 |

↑ iocage response


* After Django restart

System check identified no issues (0 silenced). December 31, 2018 - 00:17:54 Django version 2.1.4, using settings 'jail_hosting_system.settings' Starting development server at http://****:8080/ Quit the server with CONTROL-C.

True <- libiocage response +-----+--------+-------+--------------+--------------+ | JID | NAME | STATE | RELEASE | IP4 | +=====+========+=======+==============+==============+ | 12 | myjail | up | 11.2-RELEASE | 192.168.1.10 | +-----+--------+-------+--------------+--------------+ [31/Dec/2018 00:18:20] "GET /jails/ HTTP/1.1" 200 1742

↑ iocage response


But...after  stop method execute

[31/Dec/2018 00:18:58] "PUT /jails/stop HTTP/1.1" 200 2 True <- libiocage response

+-----+--------+-------+--------------+--------------+ | JID | NAME | STATE | RELEASE | IP4 | +=====+========+=======+==============+==============+ | - | myjail | down | 11.2-RELEASE | 192.168.1.10 | +-----+--------+-------+--------------+--------------+

↑ iocage response [31/Dec/2018 00:19:04] "GET /jails/ HTTP/1.1" 200 1742


* Such version

less requirements.txt ioc==0.3.2 iocage==0.3.2 iocage-cli==1.0a1 iocage-lib==1.0a1



Regards.

Make sure to follow and check these boxes before submitting an issue! Thank you.

- [x] Supply `iocage --version`
- [ ] Supply the commands used, along with any steps to recreate it.
- [ ] Provide the output from the command you issued.
- [ ] Supply what you expected the result or output to be
- [ ] Checked that the problem has not already been fixed on `master` if using
 a stable release.
gronke commented 5 years ago

Jail State lookup is an expensive operation (using subprocess.Popen to call jls). When you suspect not to be the sole jail manager, consider updating the global jails state or an individual jails state as such:

import ioc
jail = ioc.Jail("myjail")
print(jail.running)
# .. something happened in between
jail.state.query()
print(jail.running)
import ioc
jails = ioc.Jails()
print(jails[0].running)
# .. something happened in between
jails.states.query()
print(jails[0].running)

Please note that during your Issue the package module namespace changed from iocage to ioc.