def autoconnect(self, dry_run=False): """Run the network's pre_up scripts and set up the bridge based on the relevant driver.""" for net in self.networks.all(): network_bridge = net.bridge_name if network_bridge: if not net.driver.bridge_exists(network_bridge): net.driver.create_bridge(network_bridge, dry_run) else: network_bridge = net.driver.generate_bridge_name() self.add_bridge(network_bridge) env = { 'KRAFT_NETWORK_NAME': net.name, 'KRAFT_NETWORK_DRIVER': net.driver.type.name, 'KRAFT_NETWORK_BRIDGE': network_bridge } env_str = [] for var in env: env_str.append('%s=%s' % (var, env[var])) for cmd in net.pre_up: utils.execute(cmd, env, dry_run)
def execute(self, extra_args=None, background=False, paused=False, dry_run=False): logger.debug("Executing on KVM...") self._cmd.extend(('-k', self.unikernel)) if background: self._cmd.append('-X') if paused: self._cmd.append('-P') if dry_run: self._cmd.append('-D') if extra_args: self._cmd.extend(('-a', ' '.join(extra_args))) self.automount(dry_run) self.autoconnect(dry_run) if self.architecture == "x86_64": self._cmd.extend(('-t', 'x86pc')) elif self.architecture == "arm64": self._cmd.extend(('-t', 'arm64v')) if platform.machine() != self.architecture: self._cmd.append('-W') if self.arguments: self._cmd.extend(('-a', self.arguments)) cmd = [QEMU_GUEST] cmd.extend(self._cmd) for pre_up_cmd in self._pre_up: utils.execute(pre_up_cmd, dry_run=dry_run) cmd = list(map(str, cmd)) logger.debug('Running: %s' % ' '.join(cmd)) if not dry_run: process = subprocess.Popen(cmd) try: process.wait() except KeyboardInterrupt: try: process.terminate() except OSError: pass process.wait() for post_down_cmd in self._post_down: utils.execute(post_down_cmd, dry_run=dry_run)
def destroy_bridge(self, name=None): if not self.integrity_ok(): raise NetworkBridgeUnsupported(self.type.name) if name is None: name = self.name if name is not None and len(name) > 0: utils.execute([BRCTL, "delbr", name]) else: raise InvalidBridgeName(name)
def execute(self, extra_args=None, background=False, paused=False, dry_run=False): logger.debug("Executing on Xen...") self._cmd.extend(('-k', self.unikernel)) if background: self._cmd.append('-X') if paused: self._cmd.append('-P') if dry_run: self._cmd.append('-D') if extra_args: self._cmd.extend(('-a', ' '.join(extra_args))) self.automount(dry_run) self.autoconnect(dry_run) if self.arguments: self._cmd.extend(('-a', self.arguments)) cmd = self.which(XEN_GUEST) cmd.extend(self._cmd) for pre_up_cmd in self._pre_up: utils.execute(pre_up_cmd, dry_run=dry_run) cmd = list(map(str, cmd)) logger.debug('Running: %s' % ' '.join(cmd)) if not dry_run: process = subprocess.Popen(cmd) try: process.wait() except KeyboardInterrupt: try: process.terminate() except OSError: pass process.wait() for post_down_cmd in self._post_down: utils.execute(post_down_cmd, dry_run=dry_run)
def create_bridge(self, name=None, dry_run=False): if not self.integrity_ok(): raise NetworkBridgeUnsupported(self.type.name) if name is None: name = self._name if self.bridge_exists(name): logger.warning("Bridge '%s' already exists!" % name) return True if name is not None and len(name) > 0: utils.execute([BRCTL, "addbr", name], dry_run=dry_run) else: raise InvalidBridgeName(name) return True
def execute(self, extra_args=None, background=False, paused=False, dry_run=False): logger.debug("Executing on Linux...") cmd = [self.unikernel] if self.arguments: cmd.append(self.arguments) if extra_args: cmd.extend(extra_args) for pre_up_cmd in self._pre_up: utils.execute(pre_up_cmd, dry_run=dry_run) cmd = list(map(str, cmd)) logger.debug('Running: %s' % ' '.join(cmd)) if not dry_run: process = subprocess.Popen(cmd) try: process.wait() except KeyboardInterrupt: try: process.terminate() except OSError: pass process.wait() for post_down_cmd in self._post_down: utils.execute(post_down_cmd, dry_run=dry_run)
def make(ctx, self, extra=None): """Run a make target for this project.""" self.checkout() cmd = self.gen_make_cmd(extra, ctx.verbose) utils.execute(cmd)