예제 #1
0
    def _configure(self) -> None:
        """Configure RabbitMQ

        (actions may have already been run, in which case we fail silently).
        """
        # Configure RabbitMQ
        check('{SNAP}/bin/setup-rabbit'.format(**_env))
예제 #2
0
    def yes(self, answer: str) -> None:

        log.info('Configuring Glance ...')

        if not call('openstack', 'user', 'show', 'glance'):
            check('openstack', 'user', 'create', '--domain', 'default',
                  '--password',
                  shell.config_get('config.credentials.glance-password'),
                  'glance')
            check('openstack', 'role', 'add', '--project', 'service', '--user',
                  'glance', 'admin')

        if not call('openstack', 'service', 'show', 'image'):
            check('openstack', 'service', 'create', '--name', 'glance',
                  '--description', '"OpenStack Image"', 'image')
            for endpoint in ['internal', 'admin', 'public']:
                check('openstack', 'endpoint', 'create', '--region',
                      'microstack', 'image', endpoint,
                      'http://{compute_ip}:9292'.format(**_env))

        check('snap-openstack', 'launch', 'glance-manage', 'db_sync')
        # TODO: remove the glance registry
        # https://blueprints.launchpad.net/glance/+spec/deprecate-registry
        for service in [
                'glance-api',
                'registry',
        ]:
            enable(service)

        nc_wait(_env['compute_ip'], '9292')

        sleep(5)  # TODO: log_wait

        self._fetch_cirros()
예제 #3
0
    def yes(self, answer: str) -> None:
        log.info('Configuring the Cinder services...')

        if not call('openstack', 'user', 'show', 'cinder'):
            check('openstack', 'user', 'create', '--domain', 'default',
                  '--password',
                  shell.config_get('config.credentials.cinder-password'),
                  'cinder')
            check('openstack', 'role', 'add', '--project', 'service', '--user',
                  'cinder', 'admin')

        control_ip = _env['control_ip']
        for endpoint in ['public', 'internal', 'admin']:
            for api_version in ['v2', 'v3']:
                if not call('openstack', 'service', 'show',
                            f'cinder{api_version}'):
                    check('openstack', 'service', 'create', '--name',
                          f'cinder{api_version}', '--description',
                          f'"Cinder {api_version} API"',
                          f'volume{api_version}')
                if not check_output('openstack', 'endpoint', 'list',
                                    '--service', f'volume{api_version}',
                                    '--interface', endpoint):
                    check(
                        'openstack', 'endpoint', 'create', '--region',
                        'microstack', f'volume{api_version}', endpoint,
                        f'http://{control_ip}:8776/{api_version}/'
                        '$(project_id)s')
        log.info('Running Cinder DB migrations...')
        check('snap-openstack', 'launch', 'cinder-manage', 'db', 'sync')

        enable('cinder-uwsgi')
        enable('cinder-scheduler')
예제 #4
0
    def yes(self, answer: str) -> None:

        log.info('Configuring Glance ...')

        if not call('openstack', 'user', 'show', 'glance'):
            check('openstack', 'user', 'create', '--domain', 'default',
                  '--password', 'glance', 'glance')
            check('openstack', 'role', 'add', '--project', 'service',
                  '--user', 'glance', 'admin')

        if not call('openstack', 'service', 'show', 'image'):
            check('openstack', 'service', 'create', '--name', 'glance',
                  '--description', '"OpenStack Image"', 'image')
            for endpoint in ['internal', 'admin', 'public']:
                check('openstack', 'endpoint', 'create', '--region',
                      'microstack', 'image', endpoint,
                      'http://{extgateway}:9292'.format(**_env))

        check('snap-openstack', 'launch', 'glance-manage', 'db_sync')

        restart('glance*')

        nc_wait(_env['extgateway'], '9292')

        sleep(5)  # TODO: log_wait

        self._fetch_cirros()
예제 #5
0
    def yes(self, answer: str) -> None:
        """Since this is an auto question, we always execute yes."""
        log.info('Loading config and writing templates ...')

        log.info('Validating config ...')
        for key in ['ospassword', 'extgateway', 'extcidr', 'dns']:
            val = check_output('snapctl', 'get', key)
            if not val:
                raise ConfigError(
                    'Expected config value {} is not set.'.format(key))
            _env[key] = val

        log.info('Writing out templates ...')
        check('snap-openstack', 'setup')

        # Parse microstack.rc, and load into _env
        # TODO: write something more robust (this breaks on comments
        # at end of line.)
        mstackrc = '{SNAP_COMMON}/etc/microstack.rc'.format(**_env)
        with open(mstackrc, 'r') as rc_file:
            for line in rc_file.readlines():
                if not line.startswith('export'):
                    continue
                key, val = line[7:].split('=')
                _env[key.strip()] = val.strip()
예제 #6
0
 def no(self, answer: bool) -> None:
     check(
         'snapctl', 'set', f'config.cinder.lvm.setup-file-backed-lvm='
         f'{str(answer).lower()}')
     disable('setup-lvm-loopdev')
     disable('cinder-volume')
     disable('iscsid')
     disable('target')
예제 #7
0
    def yes(self, answer: str) -> None:

        log.info('restarting libvirt and virtlogd ...')
        # This fixes an issue w/ logging not getting set.
        # TODO: fix issue.
        restart('*virt*')

        check('snapctl', 'set', 'initialized=true')
        log.info('Complete. Marked microstack as initialized!')
예제 #8
0
 def yes(self, answer: bool) -> None:
     check(
         'snapctl', 'set',
         f'config.cinder.setup-loop-based-cinder-lvm-backend'
         f'={str(answer).lower()}')
     log.info('Setting up cinder-volume service with the LVM backend...')
     enable('setup-lvm-loopdev')
     enable('cinder-volume')
     enable('target')
     enable('iscsid')
예제 #9
0
    def _bootstrap(self) -> None:

        if call('openstack', 'user', 'show', 'admin'):
            return

        bootstrap_url = 'http://{extgateway}:5000/v3/'.format(**_env)

        check('snap-openstack', 'launch', 'keystone-manage', 'bootstrap',
              '--bootstrap-password', _env['ospassword'],
              '--bootstrap-admin-url', bootstrap_url,
              '--bootstrap-internal-url', bootstrap_url,
              '--bootstrap-public-url', bootstrap_url)
예제 #10
0
    def _bootstrap(self) -> None:

        if call('openstack', 'user', 'show', 'admin'):
            return

        bootstrap_url = 'http://{control_ip}:5000/v3/'.format(**_env)

        check('snap-openstack', 'launch', 'keystone-manage', 'bootstrap',
              '--bootstrap-password', _env['keystone_password'],
              '--bootstrap-admin-url', bootstrap_url,
              '--bootstrap-internal-url', bootstrap_url,
              '--bootstrap-public-url', bootstrap_url, '--bootstrap-region-id',
              'microstack')
예제 #11
0
    def yes(self, answer: str) -> None:

        log.info('restarting libvirt and virtlogd ...')
        # This fixes an issue w/ logging not getting set.
        # TODO: fix issue.
        restart('*virt*')

        # Start horizon
        check('snapctl', 'start',
              environ['SNAP_INSTANCE_NAME'] + '.horizon-uwsgi')

        check('snapctl', 'set', 'initialized=true')
        log.info('Complete. Marked microstack as initialized!')
예제 #12
0
    def yes(self, answer: str) -> None:
        log.info('Configuring the Placement service...')

        if not call('openstack', 'user', 'show', 'placement'):
            check(
                'openstack',
                'user',
                'create',
                '--domain',
                'default',
                '--password',
                shell.config_get('config.credentials.placement-password'),
                'placement',
            )
            check('openstack', 'role', 'add', '--project', 'service', '--user',
                  'placement', 'admin')

        if not call('openstack', 'service', 'show', 'placement'):
            check('openstack', 'service', 'create', '--name', 'placement',
                  '--description', '"Placement API"', 'placement')

            for endpoint in ['public', 'internal', 'admin']:
                call('openstack', 'endpoint', 'create', '--region',
                     'microstack', 'placement', endpoint,
                     'http://{control_ip}:8778'.format(**_env))

        log.info('Running Placement DB migrations...')
        check('snap-openstack', 'launch', 'placement-manage', 'db', 'sync')
        enable('placement-uwsgi')
예제 #13
0
    def yes(self, answer: bool):
        log.info('Configuring clustering ...')

        role_question = clustering.Role()
        if not (self.interactive and self.role_interactive):
            role_question.interactive = False
        role_question.ask()

        questions = [
            # Skipped for the compute role and is automatically taken
            # from the connection string.
            clustering.ControlIp(),
            # Skipped for the control role since it is identical to the
            # control node IP.
            clustering.ComputeIp(),
        ]
        for question in questions:
            if not self.interactive:
                question.interactive = False
            question.ask()

        connection_string_question = clustering.ConnectionString()
        if not (self.interactive and self.connection_string_interactive):
            connection_string_question.interactive = False
        connection_string_question.ask()

        role = shell.config_get('config.cluster.role')

        if role == 'compute':
            log.info('Setting up as a compute node.')
            # Gets config info and sets local env vals.
            check_output('microstack_join')
            shell.config_set(
                **{
                    'config.services.control-plane': 'false',
                    'config.services.hypervisor': 'true',
                })

        if role == 'control':
            log.info('Setting up as a control node.')
            shell.config_set(
                **{
                    'config.services.control-plane': 'true',
                    'config.services.hypervisor': 'true',
                })
            # Generate a self-signed certificate for the clustering service.
            cluster_tls.generate_selfsigned()

        # Write templates
        check('snap-openstack', 'setup')
예제 #14
0
    def yes(self, answer: str) -> None:
        """Setup Databases.

        Create all the MySQL databases we require, then setup the
        fernet keys and create the service project.

        """
        log.info('Waiting for MySQL server to start ...')
        self._wait()
        log.info('Mysql server started! Creating databases ...')
        self._create_dbs()

        check('snapctl', 'set', 'database.ready=true')

        enable('nginx')

        log.info('Configuring Keystone Fernet Keys ...')
        check('snap-openstack', 'launch', 'keystone-manage', 'fernet_setup',
              '--keystone-user', 'root', '--keystone-group', 'root')
        check('snap-openstack', 'launch', 'keystone-manage', 'db_sync')

        enable('keystone-uwsgi')

        log.info('Bootstrapping Keystone ...')
        self._bootstrap()

        log.info('Creating service project ...')
        if not call('openstack', 'project', 'show', 'service'):
            check('openstack', 'project', 'create', '--domain', 'default',
                  '--description', 'Service Project', 'service')

        log.info('Keystone configured!')
예제 #15
0
    def _flavors(self) -> None:
        """Create default flavors."""

        if not call('openstack', 'flavor', 'show', 'm1.tiny'):
            check('openstack', 'flavor', 'create', '--id', '1', '--ram', '512',
                  '--disk', '1', '--vcpus', '1', 'm1.tiny')
        if not call('openstack', 'flavor', 'show', 'm1.small'):
            check('openstack', 'flavor', 'create', '--id', '2', '--ram',
                  '2048', '--disk', '20', '--vcpus', '1', 'm1.small')
        if not call('openstack', 'flavor', 'show', 'm1.medium'):
            check('openstack', 'flavor', 'create', '--id', '3', '--ram',
                  '4096', '--disk', '20', '--vcpus', '2', 'm1.medium')
        if not call('openstack', 'flavor', 'show', 'm1.large'):
            check('openstack', 'flavor', 'create', '--id', '4', '--ram',
                  '8192', '--disk', '20', '--vcpus', '4', 'm1.large')
        if not call('openstack', 'flavor', 'show', 'm1.xlarge'):
            check('openstack', 'flavor', 'create', '--id', '5', '--ram',
                  '16384', '--disk', '20', '--vcpus', '8', 'm1.xlarge')
예제 #16
0
    def yes(self, answer: str) -> None:
        log.info('restarting libvirt and virtlogd ...')
        # This fixes an issue w/ logging not getting set.
        # TODO: fix issue.
        restart('libvirtd')
        restart('virtlogd')
        restart('nova-compute')

        role = shell.config_get('config.cluster.role')
        if role == 'control':
            # TODO: since snap-openstack launch is used, this depends on the
            # database readiness and hence the clustering service is enabled
            # and started here. There needs to be a better way to do this.
            enable('cluster-uwsgi')
            enable('horizon-uwsgi')

        check('snapctl', 'set', 'initialized=true')
        log.info('Complete. Marked microstack as initialized!')
예제 #17
0
    def after(self, answer):
        """Our value has been saved.

        Run 'snap-openstack setup' to write it out, and load any changes to
        microstack.rc.

        # TODO this is a bit messy and redundant. Come up with a clean
        way of loading and writing config after the run of
        ConfigQuestions have been asked.

        """
        check('snap-openstack', 'setup')

        mstackrc = '{SNAP_COMMON}/etc/microstack.rc'.format(**_env)
        with open(mstackrc, 'r') as rc_file:
            for line in rc_file.readlines():
                if not line.startswith('export'):
                    continue
                key, val = line[7:].split('=')
                _env[key.strip()] = val.strip()
예제 #18
0
    def _save(self, answer):
        """Save off our answer, for later retrieval.

        Store the value of this question's answer in the questions
        namespace in the snap config.

        """
        key = inflection.dasherize(
            inflection.underscore(self.__class__.__name__))

        # By this time in the process 'yes' or 'no' answers will have
        # been converted to booleans. Convert them to a lowercase
        # 'true' or 'false' string for storage in the snapctl config.
        if self._type == 'boolean':
            answer = str(answer).lower()

        shell.check('snapctl', 'set',
                    'questions.{key}={val}'.format(key=key, val=answer))

        return answer
예제 #19
0
    def _fetch_cirros(self) -> None:

        if call('openstack', 'image', 'show', 'cirros'):
            return

        env = dict(**_env)
        env['VER'] = '0.4.0'
        env['IMG'] = 'cirros-{VER}-x86_64-disk.img'.format(**env)

        log.info('Fetching cirros image ...')

        cirros_path = '{SNAP_COMMON}/images/{IMG}'.format(**env)

        if not path.exists(cirros_path):
            check('mkdir', '-p', '{SNAP_COMMON}/images'.format(**env))
            download(
                'http://download.cirros-cloud.net/{VER}/{IMG}'.format(**env),
                '{SNAP_COMMON}/images/{IMG}'.format(**env))

        check('openstack', 'image', 'create', '--file',
              '{SNAP_COMMON}/images/{IMG}'.format(**env), '--public',
              '--container-format=bare', '--disk-format=qcow2', 'cirros')
예제 #20
0
    def _save(self, answer):
        """Save off our answer, for later retrieval.

        Store the value of this question's answer in the questions
        namespace in the snap config.

        """
        # By this time in the process 'yes' or 'no' answers will have
        # been converted to booleans. Convert them to a lowercase
        # 'true' or 'false' string for storage in the snapctl config.
        if self._type == 'auto':
            return

        if self._type == 'boolean':
            answer = str(answer).lower()

        if answer is None:
            answer = 'null'

        shell.check('snapctl', 'set', '{key}={val}'.format(key=self.config_key,
                                                           val=answer))

        return answer
예제 #21
0
    def yes(self, answer: str) -> None:

        if 'microstack' not in check_output('openstack', 'keypair', 'list'):
            log.info('Creating microstack keypair (~/.ssh/{})'.format(answer))
            check('mkdir', '-p', '{HOME}/.ssh'.format(**_env))
            check('chmod', '700', '{HOME}/.ssh'.format(**_env))
            id_ = check_output('openstack', 'keypair', 'create', 'microstack')
            id_path = '{HOME}/.ssh/{answer}'.format(HOME=_env['HOME'],
                                                    answer=answer)

            with open(id_path, 'w') as file_:
                file_.write(id_)
            check('chmod', '600', id_path)
            # TODO: too many assumptions in the below. Make it portable!
            user = _env['HOME'].split("/")[2]
            check('chown', '{}:{}'.format(user, user), id_path)
예제 #22
0
    def yes(self, answer: str) -> None:
        # Create security group rules
        log.info('Creating security group rules ...')
        group_id = check_output('openstack', 'security', 'group', 'list',
                                '--project', 'admin', '-f', 'value', '-c',
                                'ID')
        rules = check_output('openstack', 'security', 'group', 'rule', 'list',
                             '--format', 'json')
        ping_rule = False
        ssh_rule = False

        for rule in json.loads(rules):
            if rule['Security Group'] == group_id:
                if rule['IP Protocol'] == 'icmp':
                    ping_rule = True
                if rule['IP Protocol'] == 'tcp':
                    ssh_rule = True

        if not ping_rule:
            check('openstack', 'security', 'group', 'rule', 'create', group_id,
                  '--proto', 'icmp')
        if not ssh_rule:
            check('openstack', 'security', 'group', 'rule', 'create', group_id,
                  '--proto', 'tcp', '--dst-port', '22')
예제 #23
0
def set_network_info() -> None:
    """Find and use the  default network on a machine.

    Helper to find the default network on a machine, and configure
    MicroStack to use it in its default settings.

    """
    try:
        ip, gate, cidr = default_network()
    except Exception:
        # TODO: more specific exception handling.
        log.exception('Could not determine default network info. '
                      'Falling back on 10.20.20.1')
        return

    check('snapctl', 'set', 'config.network.ext-gateway={}'.format(gate))
    check('snapctl', 'set', 'config.network.ext-cidr={}'.format(cidr))
    check('snapctl', 'set', 'config.network.control-ip={}'.format(ip))
    check('snapctl', 'set',
          'config.network.node-fqdn={}'.format(socket.getfqdn()))
예제 #24
0
    def yes(self, answer: str) -> None:
        log.info('Configuring Neutron')

        if not call('openstack', 'user', 'show', 'neutron'):
            check('openstack', 'user', 'create', '--domain', 'default',
                  '--password', 'neutron', 'neutron')
            check('openstack', 'role', 'add', '--project', 'service',
                  '--user', 'neutron', 'admin')

        if not call('openstack', 'service', 'show', 'network'):
            check('openstack', 'service', 'create', '--name', 'neutron',
                  '--description', '"OpenStack Network"', 'network')
            for endpoint in ['public', 'internal', 'admin']:
                call('openstack', 'endpoint', 'create', '--region',
                     'microstack', 'network', endpoint,
                     'http://{extgateway}:9696'.format(**_env))

        check('snap-openstack', 'launch', 'neutron-db-manage', 'upgrade',
              'head')

        restart('neutron-*')

        nc_wait(_env['extgateway'], '9696')

        sleep(5)  # TODO: log_wait

        if not call('openstack', 'network', 'show', 'test'):
            check('openstack', 'network', 'create', 'test')

        if not call('openstack', 'subnet', 'show', 'test-subnet'):
            check('openstack', 'subnet', 'create', '--network', 'test',
                  '--subnet-range', '192.168.222.0/24', 'test-subnet')

        if not call('openstack', 'network', 'show', 'external'):
            check('openstack', 'network', 'create', '--external',
                  '--provider-physical-network=physnet1',
                  '--provider-network-type=flat', 'external')
        if not call('openstack', 'subnet', 'show', 'external-subnet'):
            check('openstack', 'subnet', 'create', '--network', 'external',
                  '--subnet-range', _env['extcidr'], '--no-dhcp',
                  'external-subnet')

        if not call('openstack', 'router', 'show', 'test-router'):
            check('openstack', 'router', 'create', 'test-router')
            check('openstack', 'router', 'add', 'subnet', 'test-router',
                  'test-subnet')
            check('openstack', 'router', 'set', '--external-gateway',
                  'external', 'test-router')
예제 #25
0
    def yes(self, answer: str) -> None:
        log.info('Configuring nova ...')

        if not call('openstack', 'user', 'show', 'nova'):
            check('openstack', 'user', 'create', '--domain',
                  'default', '--password', 'nova', 'nova')
            check('openstack', 'role', 'add', '--project',
                  'service', '--user', 'nova', 'admin')

        if not call('openstack', 'user', 'show', 'placement'):
            check('openstack', 'user', 'create', '--domain', 'default',
                  '--password', 'placement', 'placement')
            check('openstack', 'role', 'add', '--project', 'service',
                  '--user', 'placement', 'admin')

        if not call('openstack', 'service', 'show', 'compute'):
            check('openstack', 'service', 'create', '--name', 'nova',
                  '--description', '"Openstack Compute"', 'compute')
            for endpoint in ['public', 'internal', 'admin']:
                call('openstack', 'endpoint', 'create', '--region',
                     'microstack', 'compute', endpoint,
                     'http://{extgateway}:8774/v2.1'.format(**_env))

        if not call('openstack', 'service', 'show', 'placement'):
            check('openstack', 'service', 'create', '--name',
                  'placement', '--description', '"Placement API"',
                  'placement')

            for endpoint in ['public', 'internal', 'admin']:
                call('openstack', 'endpoint', 'create', '--region',
                     'microstack', 'placement', endpoint,
                     'http://{extgateway}:8778'.format(**_env))

        # Grant nova user access to cell0
        sql(
            "GRANT ALL PRIVILEGES ON nova_cell0.* TO 'nova'@'{extgateway}' \
            IDENTIFIED BY \'nova';".format(**_env))

        check('snap-openstack', 'launch', 'nova-manage', 'api_db', 'sync')

        if 'cell0' not in check_output('snap-openstack', 'launch',
                                       'nova-manage', 'cell_v2',
                                       'list_cells'):
            check('snap-openstack', 'launch', 'nova-manage',
                  'cell_v2', 'map_cell0')

        if 'cell1' not in check_output('snap-openstack', 'launch',
                                       'nova-manage', 'cell_v2', 'list_cells'):

            check('snap-openstack', 'launch', 'nova-manage', 'cell_v2',
                  'create_cell', '--name=cell1', '--verbose')

        check('snap-openstack', 'launch', 'nova-manage', 'db', 'sync')

        restart('nova-*')

        nc_wait(_env['extgateway'], '8774')

        sleep(5)  # TODO: log_wait

        log.info('Creating default flavors...')
        self._flavors()
예제 #26
0
    def yes(self, answer: str) -> None:
        log.info('Configuring nova ...')

        if not call('openstack', 'user', 'show', 'nova'):
            check('openstack', 'user', 'create', '--domain', 'default',
                  '--password', 'nova', 'nova')
            check('openstack', 'role', 'add', '--project', 'service', '--user',
                  'nova', 'admin')

        if not call('openstack', 'user', 'show', 'placement'):
            check('openstack', 'user', 'create', '--domain', 'default',
                  '--password', 'placement', 'placement')
            check('openstack', 'role', 'add', '--project', 'service', '--user',
                  'placement', 'admin')

        if not call('openstack', 'service', 'show', 'compute'):
            check('openstack', 'service', 'create', '--name', 'nova',
                  '--description', '"Openstack Compute"', 'compute')
            for endpoint in ['public', 'internal', 'admin']:
                call('openstack', 'endpoint', 'create', '--region',
                     'microstack', 'compute', endpoint,
                     'http://{extgateway}:8774/v2.1'.format(**_env))

        if not call('openstack', 'service', 'show', 'placement'):
            check('openstack', 'service', 'create', '--name', 'placement',
                  '--description', '"Placement API"', 'placement')

            for endpoint in ['public', 'internal', 'admin']:
                call('openstack', 'endpoint', 'create', '--region',
                     'microstack', 'placement', endpoint,
                     'http://{extgateway}:8778'.format(**_env))

        # Grant nova user access to cell0
        sql("GRANT ALL PRIVILEGES ON nova_cell0.* TO 'nova'@'{extgateway}' \
            IDENTIFIED BY \'nova';".format(**_env))

        # Use snapctl to start nova services.  We need to call them
        # out manually, because systemd doesn't know about them yet.
        # TODO: parse the output of `snapctl services` to get this
        # list automagically.
        for service in [
                environ['SNAP_INSTANCE_NAME'] + '.nova-api',
                environ['SNAP_INSTANCE_NAME'] + '.nova-api-metadata',
                environ['SNAP_INSTANCE_NAME'] + '.nova-compute',
                environ['SNAP_INSTANCE_NAME'] + '.nova-conductor',
                environ['SNAP_INSTANCE_NAME'] + '.nova-scheduler',
                environ['SNAP_INSTANCE_NAME'] + '.nova-uwsgi',
        ]:
            check('snapctl', 'start', service)

        check('snap-openstack', 'launch', 'nova-manage', 'api_db', 'sync')

        if 'cell0' not in check_output('snap-openstack', 'launch',
                                       'nova-manage', 'cell_v2', 'list_cells'):
            check('snap-openstack', 'launch', 'nova-manage', 'cell_v2',
                  'map_cell0')

        if 'cell1' not in check_output('snap-openstack', 'launch',
                                       'nova-manage', 'cell_v2', 'list_cells'):

            check('snap-openstack', 'launch', 'nova-manage', 'cell_v2',
                  'create_cell', '--name=cell1', '--verbose')

        check('snap-openstack', 'launch', 'nova-manage', 'db', 'sync')

        restart('nova-*')

        nc_wait(_env['extgateway'], '8774')

        sleep(5)  # TODO: log_wait

        log.info('Creating default flavors...')
        self._flavors()
예제 #27
0
    def yes(self, answer):
        log.info('Configuring networking ...')

        role = check_output('snapctl', 'get', 'config.cluster.role')

        # Enable and start the services.
        enable('ovsdb-server')
        enable('ovs-vswitchd')
        enable('ovn-ovsdb-server-sb')
        enable('ovn-ovsdb-server-nb')

        network.ExtGateway().ask()
        network.ExtCidr().ask()

        control_ip = check_output('snapctl', 'get',
                                  'config.network.control-ip')
        if role == 'control':
            nb_conn = 'unix:{SNAP_COMMON}/run/ovn/ovnnb_db.sock'.format(**_env)
            sb_conn = 'unix:{SNAP_COMMON}/run/ovn/ovnsb_db.sock'.format(**_env)
            check_output('ovs-vsctl', 'set', 'open', '.',
                         f'external-ids:ovn-encap-ip={control_ip}')
        elif role == 'compute':
            sb_conn = f'tcp:{control_ip}:6642'
            # Not used by any compute node services.
            nb_conn = ''
            compute_ip = check_output('snapctl', 'get',
                                      'config.network.compute-ip')
            # Set the IP address to be used for a tunnel endpoint.
            check_output('ovs-vsctl', 'set', 'open', '.',
                         f'external-ids:ovn-encap-ip={compute_ip}')
        else:
            raise Exception(f'Unexpected node role: {role}')

        # ovn-controller does not start unless both the ovn-encap-ip and the
        # ovn-encap-type are set.
        check_output('ovs-vsctl', 'set', 'open', '.',
                     'external-ids:ovn-encap-type=geneve')

        # Configure OVN SB and NB sockets based on the role node. For
        # single-node deployments there is no need to use a TCP socket.
        check_output('snapctl', 'set',
                     f'config.network.ovn-nb-connection={nb_conn}')
        check_output('snapctl', 'set',
                     f'config.network.ovn-sb-connection={sb_conn}')

        # Set SB database connection details for ovn-controller to pick up.
        check_output('ovs-vsctl', 'set', 'open', '.',
                     f'external-ids:ovn-remote={sb_conn}')
        check_output('ovs-vsctl', 'set', 'open', '.',
                     'external-ids:ovn-cms-options=enable-chassis-as-gw')

        # Now that we have default or overriden values, setup the
        # bridge and write all the proper values into our config
        # files.
        check('setup-br-ex')
        check('snap-openstack', 'setup')

        if role == 'control':

            enable('ovn-northd')
            enable('ovn-controller')

        network.IpForwarding().ask()
예제 #28
0
    def no(self, answer: str):
        # We assume that the control node has a connection setup for us.
        check('snapctl', 'set', 'database.ready=true')

        log.info('Disabling local MySQL ...')
        disable('mysqld')
예제 #29
0
    def yes(self, answer: str) -> None:
        """Use sysctl to setup ip forwarding."""
        log.info('Setting up ipv4 forwarding...')

        check('sysctl', 'net.ipv4.ip_forward=1')
예제 #30
0
    def yes(self, answer: str) -> None:
        log.info('Configuring nova control plane services ...')

        if not call('openstack', 'user', 'show', 'nova'):
            check('openstack', 'user', 'create', '--domain', 'default',
                  '--password',
                  shell.config_get('config.credentials.nova-password'), 'nova')
            check('openstack', 'role', 'add', '--project', 'service', '--user',
                  'nova', 'admin')
            # Assign the reader role to the nova user so that read-only
            # application credentials can be created.
            check('openstack', 'role', 'add', '--project', 'service', '--user',
                  'nova', 'reader')

        log.info('Running Nova API DB migrations'
                 ' (this may take a lot of time)...')
        check('snap-openstack', 'launch', 'nova-manage', 'api_db', 'sync')

        if 'cell0' not in check_output('snap-openstack', 'launch',
                                       'nova-manage', 'cell_v2', 'list_cells'):
            check('snap-openstack', 'launch', 'nova-manage', 'cell_v2',
                  'map_cell0')

        if 'cell1' not in check_output('snap-openstack', 'launch',
                                       'nova-manage', 'cell_v2', 'list_cells'):

            check('snap-openstack', 'launch', 'nova-manage', 'cell_v2',
                  'create_cell', '--name=cell1', '--verbose')

        log.info('Running Nova DB migrations'
                 ' (this may take a lot of time)...')
        check('snap-openstack', 'launch', 'nova-manage', 'db', 'sync')

        enable('nova-api')
        restart('nova-compute')

        for service in [
                'nova-api-metadata',
                'nova-conductor',
                'nova-scheduler',
        ]:
            enable(service)

        nc_wait(_env['compute_ip'], '8774')

        sleep(5)  # TODO: log_wait

        if not call('openstack', 'service', 'show', 'compute'):
            check('openstack', 'service', 'create', '--name', 'nova',
                  '--description', '"Openstack Compute"', 'compute')
            for endpoint in ['public', 'internal', 'admin']:
                call('openstack', 'endpoint', 'create', '--region',
                     'microstack', 'compute', endpoint,
                     'http://{control_ip}:8774/v2.1'.format(**_env))

        log.info('Creating default flavors...')

        self._flavors()