def start(self): base_img_dir = NetemConfig.instance().get("general", "image_dir") b_img = os.path.join(base_img_dir, "junos-pynetem-%s.img" % self.img_type) cmd = "%s create -f qcow2 -b %s %s" % (QEMU_IMG, b_img, self.img) self._command(cmd) super(JunosInstance, self).start()
def __init__(self, p2p_sw, prj_id, image_dir, img_type, name, node_config): super(QEMUInstance, self).__init__(prj_id, name) self.p2p_sw = p2p_sw self.kvm = NetemConfig.instance().getboolean("qemu", "enable_kvm") self.memory = "memory" in node_config and node_config["memory"] or None self.need_acpi = "acpi" not in node_config and True \ or node_config.as_bool("acpi") self.shell_process = None self.telnet_port = node_config.as_int("console") self.img = os.path.join(image_dir, "%s.img" % name) self.interfaces = [] self.capture_processes = {} if not os.path.isfile(self.img): base_img_dir = NetemConfig.instance().get("general", "image_dir") b_img = os.path.join(base_img_dir, "%s.img" % img_type) cmd = "%s create -f qcow2 -b %s %s" % (QEMU_IMG, b_img, self.img) self._command(cmd)
def __init__(self, netid, project, loop): # init daemon client daemon = NetemDaemonClient.instance() s_name = NetemConfig.instance().get("general", "daemon_socket") daemon.set_socket_path(s_name) self.server = None self.project = NetemProject(daemon, netid, project) self.loop = loop self.clients = []
def __init__(self, s_port): self.config = NetemConfig.instance() self.allow_cli_args = False self.s_port = s_port self.spinner = None super(NetemConsole, self).__init__() if "DISPLAY" not in os.environ: os.environ["DISPLAY"] = ":0.0" self.__open_display() # install SIGHUP handler signal.signal(signal.SIGHUP, self.sighup_handler)
def open_shell(self, bash=False): if self.shell_process is not None \ and self.shell_process.poll() is None: raise NetemError("The console is already opened") term_cmd = NetemConfig.instance().get("general", "terminal") % { "title": self.name, "cmd": "telnet localhost %d" % self.telnet_port, } args = shlex.split(term_cmd) self.shell_process = subprocess.Popen(args, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=False)
def __init__(self, p2p_sw, prj_id, conf_dir, img_type, name, node_config): super(QEMUInstance, self).__init__(prj_id, name) self.conf_dir = conf_dir self.p2p_sw = p2p_sw self.kvm = NetemConfig.instance().getboolean("qemu", "enable_kvm") self.img_type = img_type self.memory = "memory" in node_config and node_config["memory"] or None self.need_acpi = "acpi" not in node_config and True \ or node_config.as_bool("acpi") self.shell_process = None self.telnet_port = node_config.as_int("console") self.img = os.path.join("/tmp", "%s-%s.img" % (prj_id, name)) self.interfaces = [] self.capture_processes = {}
def open_shell(self, bash=False): term_cmd = NetemConfig.instance().get("general", "terminal") shell_cmd = bash and self.BASH or self.SHELL if CONSOLE_PROCESS == "daemon": # console is launch by the daemon display = get_x11_env() self.daemon.docker_shell(self.container_name, self.name, shell_cmd, display, term_cmd) else: # user cmd = term_cmd % { "title": self.name, "cmd": "docker exec -it %s %s" % (self.container_name, shell_cmd) } cmd_run_app(cmd)
# (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License along # with this program; if not, write to the Free Software Foundation, Inc., # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. from pynetem import get_docker_images from pynetem.ui.config import NetemConfig from pynetem.check._base import _BaseCheck DOCKER_IMAGES = get_docker_images(NetemConfig.instance()) class DockerNodeCheck(_BaseCheck): def get_name(self): return "docker" def get_desc(self): return "Docker node check" def check(self, network): for name in network["nodes"]: node = network["nodes"][name] if node["type"].startswith("docker."): self.__check_type(name, node["type"]) self.__check_node_args(name, node)
# GNU General Public License for more details. # # You should have received a copy of the GNU General Public License along # with this program; if not, write to the Free Software Foundation, Inc., # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. import os import logging import shutil from pynetem import NetemError, get_docker_images from pynetem.ui.config import NetemConfig from pynetem.wrapper import _BaseWrapper from pynetem.wrapper.link import NetemLinkFactory from pynetem.utils import cmd_run_app, get_x11_env config = NetemConfig.instance() DOCKER_IMAGES = get_docker_images(config) CONSOLE_PROCESS = config.get("docker", "console") CAPTURE_PROCESS = config.get("docker", "capture") def require_running(func): def running_func(self, *args, **kwargs): if not self.running: print("Warning: try to execute action " "%s on stopped node" % func.__name__) return return func(self, *args, **kwargs) running_func.__name__ = func.__name__ return running_func
def __check_image(self, node_type): null, image = node_type.split(".", 1) img_folder = NetemConfig.instance().get("general", "image_dir") img_path = os.path.join(img_folder, "%s.img" % image) if not os.path.isfile(img_path): self.add_error("image %s does not exist in images dir" % image)
def get_memory(self): if self.memory is not None: return self.memory return NetemConfig.instance().get("qemu", "memory")