Exemplo n.º 1
0
def cmd(s, comment=None):
  if comment is not None:
    comment = colored('(%s)' % comment, 'green')
  else:
    comment = ''
  print '# %s %s' % (colored(s, 'yellow'), comment)
  if not settings.dryrun:
    shell_cmd(s)
Exemplo n.º 2
0
def check_selinux():
    selinux = run_shell_command('getenforce')
    if 'Disabled' not in selinux:
        print(
            colored(
                'selinux should be disabled, please disable it if you '
                'don\'t want unexpected behaviour.', Colors.WARNING))
Exemplo n.º 3
0
  def __init__(self, topo, controller, switch=Switch, rate=None):
    if os.getuid() != 0:
      print colored('Please run as root.', 'red')
      sys.exit(-1)
    
    fixLimits()
    # use our own host definition
    self.host = Host
    # but user supplied switch :p
    self.switch = switch
    
    self.next_host_id = 1
    self.next_switch_id = 1

    self.hosts = []
    self.switches = []
    self.controllers = []
    self.name_to_node = {}

    self.topo = topo
    self.rate = rate
Exemplo n.º 4
0
def check_cgroups():
    if not os.path.exists('/sys/fs/cgroup/cgroup.controllers'):
        print(colored('cgroups v1 is not supported', Colors.FAIL))
        print('Enable cgroups v2 please')
        sys.exit(666)
Exemplo n.º 5
0
def check_dashboard():
    if not os.path.exists(os.path.join(CEPH_ROOT, 'dist')):
        print(colored('Missing build in dashboard', Colors.WARNING))
Exemplo n.º 6
0
    def start(self):
        check_cgroups()
        check_selinux()
        osds = Config.get('osds')
        hosts = Config.get('hosts')

        # ensure boxes don't exist
        self.down()

        # podman is ran without sudo
        if engine() == 'podman':
            I_am = run_shell_command('whoami')
            if 'root' in I_am:
                print(root_error_msg)
                sys.exit(1)

        print('Checking docker images')
        if not image_exists(CEPH_IMAGE):
            get_ceph_image()
        if not image_exists(BOX_IMAGE):
            get_box_image()

        used_loop = ""
        if not Config.get('skip_create_loop'):
            print(
                'Adding logical volumes (block devices) in loopback device...')
            used_loop = osd.create_loopback_devices(osds)
            print(f'Added {osds} logical volumes in a loopback device')
        loop_device_arg = ""
        if used_loop:
            loop_device_arg = f'--device {used_loop} -v /dev/vg1:/dev/vg1:Z'
            for o in range(osds):
                loop_device_arg += f' --device /dev/dm-{o}'

        print('Starting containers')

        if engine() == 'docker':
            dcflags = f'-f {Config.get("docker_yaml")}'
            if not os.path.exists('/sys/fs/cgroup/cgroup.controllers'):
                dcflags += f' -f {Config.get("docker_v1_yaml")}'
            run_shell_command(
                f'{engine_compose()} {dcflags} up --scale hosts={hosts} -d')
        else:
            run_shell_command(
                f'{engine_compose()} -f {Config.get("podman_yaml")} --podman-run-args "--group-add keep-groups --network=host --device /dev/fuse -it {loop_device_arg}" up --scale hosts={hosts} -d'
            )

        run_shell_command('sudo sysctl net.ipv4.conf.all.forwarding=1')
        run_shell_command('sudo iptables -P FORWARD ACCEPT')

        # don't update clock with chronyd / setup chronyd on all boxes
        chronyd_setup = """
        sed 's/$OPTIONS/-x/g' /usr/lib/systemd/system/chronyd.service -i
        systemctl daemon-reload
        systemctl start chronyd
        systemctl status --no-pager chronyd
        """
        for h in range(hosts):
            run_dc_shell_commands(h + 1, 'hosts', chronyd_setup)
        run_dc_shell_commands(1, 'seed', chronyd_setup)

        print('Seting up host ssh servers')
        for h in range(hosts):
            host._setup_ssh('hosts', h + 1)

        host._setup_ssh('seed', 1)

        verbose = '-v' if Config.get('verbose') else ''
        skip_deploy = '--skip-deploy-osds' if Config.get(
            'skip-deploy-osds') else ''
        skip_monitoring_stack = ('--skip-monitoring-stack' if
                                 Config.get('skip-monitoring-stack') else '')
        skip_dashboard = '--skip-dashboard' if Config.get(
            'skip-dashboard') else ''
        box_bootstrap_command = (
            f'/cephadm/box/box.py {verbose} --engine {engine()} cluster bootstrap '
            f'--osds {osds} '
            f'--hosts {hosts} '
            f'{skip_deploy} '
            f'{skip_dashboard} '
            f'{skip_monitoring_stack} ')
        run_dc_shell_command(box_bootstrap_command, 1, 'seed')

        info = get_boxes_container_info()
        ips = info['ips']
        hostnames = info['hostnames']
        print(ips)
        host._copy_cluster_ssh_key(ips)

        expanded = Config.get('expanded')
        if expanded:
            host._add_hosts(ips, hostnames)

        # TODO: add osds
        if expanded and not Config.get('skip-deploy-osds'):
            if engine() == 'podman':
                print('osd deployment not supported in podman')
            else:
                print('Deploying osds... This could take up to minutes')
                osd.deploy_osds_in_vg('vg1')
                print('Osds deployed')

        dashboard_ip = 'localhost'
        info = get_boxes_container_info(with_seed=True)
        if engine() == 'docker':
            for i in range(info['size']):
                if 'seed' in info['container_names'][i]:
                    dashboard_ip = info["ips"][i]
        print(
            colored(f'dashboard available at https://{dashboard_ip}:8443',
                    Colors.OKGREEN))

        print('Bootstrap finished successfully')
Exemplo n.º 7
0
    def __init__(self, cmd, name='', prompt=None, timeout=5, delay=0.1, idleout=None,
                 use_pty_stdin=False, use_pty_stdout=False, use_shell=False,
                 print_input=lambda x: util.print_cyan(x, end=''),
                 print_output=util.print_no_newline,
                 print_stderr=lambda x: sys.stderr.write(util.colored(x, ['magenta'])),
                 print_warn=util.print_warn,
                 print_error=util.print_error,
                 hide_output=False,
                 flush=False, scrollback=False,
                 retry=0, lazy=False,
                 disable_echo=False,
                 auto_reconnect=False):
        """Open a programmably interactive process.

        Parameters:

        - cmd: the command line to start the process.
        - name: a string name for the process.
        - prompt: the command prompt of the process. If specified, when the prompt is
                found in the program output, a command execution is considered done.
                This prompt string can be regex pattern.
        - timeout: value in seconds, to timeout a command execution, in case
                the prompt or expected output is not found. If None, default to 5.
        - delay: value in second (can be 0.00x), max time to wait in select().
        - idleout: value in seconds, return if no more output for certain time.
                If idleout is None, won't check the output idle time.
        - use_pty_stdin: By default, stdin uses TTY native terminal device.
                Set this flag to True, to avoid tcgetattr error, for programs
                which use PTY pseudo terminal device as stdin.
        - print_intput: method to print the input command send to the process.
        - print_output: method to print the process's stdout output.
        - print_stderr: method to print the process's stderr output.
        - print_warn: method to print any warning and non-critical error.
        - print_error: method to print any critical error.
        - hide_output: if True, don't print the output of process starting.
        - flush: If true, flush the program's startup output.
        - scrollback: If true, archieve all the output in scrollback_buf, for later use.
        - retry: number of times to retry to connect in case initial connection fails.
        - lazy: If False, spawn the subprocess immediately. If True, defer the actual spawn,
                which can be done later when the subprocess is actually used.
        - disable_echo: if True, disable the terminal echo for input characters,
                so the output log can be cleaner for some application.
        - auto_reconnect: if True, attemp to reconnect if a connection is dropped

        NOTE: it uses fcntl to have a non-blocking pipe file object for
        subprocess, so that stdout.read won't hang. This only works for UNIX.
        """

        # init default values
        self.cmdline = cmd
        self.name = name
        self.prompt = prompt
        self.delay = delay
        self.timeout = timeout if timeout is not None else 5
        self.idleout = idleout
        self.max_idle_gap = 0   # record the max idle gap between outputs within 1 execution.
        self._idle_gaps = [0]
        self.use_pty_stdin = use_pty_stdin
        self.use_pty_stdout = use_pty_stdout
        self.use_shell = use_shell
        self._init_retry = retry
        self._init_flush = flush
        self.hide_output = hide_output
        self._remaining_output = ''      # remaining stdout output from previous execution
        self._remaining_err_output = ''  # remaining stderr output from previous execution
        self._peek_out = self._peek_err = ''  # store any peeked output for later use.
        no_print = lambda x: None
        self.print_input = print_input if print_input else no_print
        self.print_output = print_output if print_output else no_print
        self.print_stderr = print_stderr if print_stderr else no_print
        self.print_warn = print_warn if print_warn else no_print
        self.print_error = print_error if print_error else no_print
        self.scrollback = scrollback
        self.scroll_buf = ''
        self._disable_echo = disable_echo
        self._replace_ctrl_c = False
        self._auto_reconnect = auto_reconnect
        self._had_connect = False

        if not lazy:
            self._connect()
Exemplo n.º 8
0
def cmd(s):
  print '# %s' % colored(s, 'yellow')
  if not settings.dryrun:
    run(s)