'Perform the bootstrap actions.
Create bootstrap user, project, and role so that CMS, humans, or
scripts can continue to perform initial setup (domains, projects,
services, endpoints, etc) of Keystone when standing up a new
deployment.'

def do_bootstrap(self):

    self._get_config()
    if (self.password is None):
        print(_('Either    --bootstrap-password    argument    or    OS_BOOTSTRAP_PASSWORD    must    be    set.'))
        raise ValueError
    default_domain = {'id': CONF.identity.default_domain_id, 'name': 'Default', 'enabled': True, 'description': 'The    default    domain'}
    try:
        self.resource_manager.create_domain(domain_id=default_domain['id'], domain=default_domain)
        LOG.info('Created    domain    %s', default_domain['id'])
    except exception.Conflict:
        LOG.info('Domain    %s    already    exists,    skipping    creation.', default_domain['id'])
    try:
        self.resource_manager.create_project(project_id=self.project_id, project={'enabled': True, 'id': self.project_id, 'domain_id': default_domain['id'], 'description': 'Bootstrap    project    for    initializing    the    cloud.', 'name': self.project_name})
        LOG.info('Created    project    %s', self.project_name)
    except exception.Conflict:
        LOG.info('Project    %s    already    exists,    skipping    creation.', self.project_name)
        project = self.resource_manager.get_project_by_name(self.project_name, default_domain['id'])
        self.project_id = project['id']
    try:
        user = self.identity_manager.get_user_by_name(self.username, default_domain['id'])
        LOG.info('User    %s    already    exists,    skipping    creation.', self.username)
        update = {}
        enabled = user['enabled']
        if (not enabled):
            update['enabled'] = True
        try:
            self.identity_manager.driver.authenticate(user['id'], self.password)
        except AssertionError:
            update['password'] = self.password
        if update:
            user = self.identity_manager.update_user(user['id'], update)
            LOG.info('Reset    password    for    user    %s.', self.username)
            if ((not enabled) and user['enabled']):
                LOG.info('Enabled    user    %s.', self.username)
    except exception.UserNotFound:
        user = self.identity_manager.create_user(user_ref={'name': self.username, 'enabled': True, 'domain_id': default_domain['id'], 'password': self.password})
        LOG.info('Created    user    %s', self.username)
    try:
        self.role_manager.create_role(role_id=self.role_id, role={'name': self.role_name, 'id': self.role_id})
        LOG.info('Created    role    %s', self.role_name)
    except exception.Conflict:
        LOG.info('Role    %s    exists,    skipping    creation.', self.role_name)
        hints = driver_hints.Hints()
        hints.add_filter('name', self.role_name)
        role = self.role_manager.list_roles(hints)
        self.role_id = role[0]['id']
    try:
        self.assignment_manager.add_role_to_user_and_project(user_id=user['id'], tenant_id=self.project_id, role_id=self.role_id)
        LOG.info('Granted    %(role)s    on    %(project)s    to    user    %(username)s.', {'role': self.role_name, 'project': self.project_name, 'username': self.username})
    except exception.Conflict:
        LOG.info('User    %(username)s    already    has    %(role)s    on    %(project)s.', {'username': self.username, 'role': self.role_name, 'project': self.project_name})
    if self.region_id:
        try:
            self.catalog_manager.create_region(region_ref={'id': self.region_id})
            LOG.info('Created    region    %s', self.region_id)
        except exception.Conflict:
            LOG.info('Region    %s    exists,    skipping    creation.', self.region_id)
    if (self.public_url or self.admin_url or self.internal_url):
        hints = driver_hints.Hints()
        hints.add_filter('type', 'identity')
        services = self.catalog_manager.list_services(hints)
        if services:
            service_ref = services[0]
            hints = driver_hints.Hints()
            hints.add_filter('service_id', service_ref['id'])
            if self.region_id:
                hints.add_filter('region_id', self.region_id)
            endpoints = self.catalog_manager.list_endpoints(hints)
        else:
            service_ref = {'id': uuid.uuid4().hex, 'name': self.service_name, 'type': 'identity', 'enabled': True}
            self.catalog_manager.create_service(service_id=service_ref['id'], service_ref=service_ref)
            endpoints = []
        self.service_id = service_ref['id']
        available_interfaces = {e['interface']: e for e in endpoints}
        expected_endpoints = {'public': self.public_url, 'internal': self.internal_url, 'admin': self.admin_url}
        for (interface, url) in expected_endpoints.items():
            if (not url):
                continue
            try:
                endpoint_ref = available_interfaces[interface]
            except KeyError:
                endpoint_ref = {'id': uuid.uuid4().hex, 'interface': interface, 'url': url, 'service_id': self.service_id, 'enabled': True}
                if self.region_id:
                    endpoint_ref['region_id'] = self.region_id
                self.catalog_manager.create_endpoint(endpoint_id=endpoint_ref['id'], endpoint_ref=endpoint_ref)
                LOG.info('Created    %(interface)s    endpoint    %(url)s', {'interface': interface, 'url': url})
            else:
                LOG.info('Skipping    %s    endpoint    as    already    created', interface)
            self.endpoints[interface] = endpoint_ref['id']
    self.assignment_manager.ensure_default_role()
