def containeraction(): """ start/stop/delete container """ config = Kconfig() k = config.k if 'name' in request.form: name = request.form['name'] action = request.form['action'] if action == 'start': result = dockerutils.start_container(k, name) elif action == 'stop': result = dockerutils.stop_container(k, name) elif action == 'delete': result = dockerutils.delete_container(k, name) else: result = "Nothing to do" print(result) response = jsonify(result) response.status_code = 200 return response else: failure = {'result': 'failure', 'reason': "Invalid Data"} response.status_code = 400 return jsonify(failure)
def start(args): """Start vm/container""" names = args.names container = args.container global config k = config.k if container: for name in names: common.pprint("Starting container %s..." % name, color='green') dockerutils.start_container(k, name) else: codes = [] for name in names: common.pprint("Starting vm %s..." % name, color='green') result = k.start(name) code = common.handle_response(result, name, element='', action='started') codes.append(code) os._exit(1 if 1 in codes else 0)
def containeraction(): """ start/stop/delete container """ from kvirt import dockerutils config = Kconfig() k = config.k if 'name' in request.form: name = request.form['name'] action = request.form['action'] if action == 'start': result = dockerutils.start_container(k, name) elif action == 'stop': result = dockerutils.stop_container(k, name) elif action == 'delete': result = dockerutils.delete_container(k, name) elif action == 'create' and 'profile' in request.form: profile = [ prof for prof in config.list_containerprofiles() if prof[0] == request.form['profile'] ][0] if name is None: name = nameutils.get_random_name() image, nets, ports, volumes, cmd = profile[1:] result = dockerutils.create_container(k, name=name, image=image, nets=nets, cmd=cmd, ports=ports, volumes=volumes) result = dockerutils.create_container(k, name, profile) else: result = "Nothing to do" print(result) response = jsonify(result) response.status_code = 200 return response else: failure = {'result': 'failure', 'reason': "Invalid Data"} response.status_code = 400 return jsonify(failure)