def do_prepare(self, context, packages, databases, memory_mb, users, device_path=None, mount_point=None, backup_info=None, config_contents=None, root_password=None, overrides=None, cluster_config=None, snapshot=None): """This is called from prepare in the base class.""" self.app.install_if_needed(packages) self.app.wait_for_start() self.app.stop_db() self.app.clear_storage() mount_point = system.MONGODB_MOUNT_POINT if device_path: device = volume.VolumeDevice(device_path) # unmount if device is already mounted device.unmount_device(device_path) device.format() if os.path.exists(system.MONGODB_MOUNT_POINT): device.migrate_data(mount_point) device.mount(mount_point) operating_system.chown(mount_point, system.MONGO_USER, system.MONGO_USER, as_root=True) LOG.debug("Mounted the volume %(path)s as %(mount)s." % {'path': device_path, "mount": mount_point}) if config_contents: # Save resolved configuration template first. self.app.configuration_manager.save_configuration(config_contents) # Apply guestagent specific configuration changes. self.app.apply_initial_guestagent_configuration( cluster_config, mount_point) if not cluster_config: # Create the Trove admin user. self.app.secure() # Don't start mongos until add_config_servers is invoked, # don't start members as they should already be running. if not (self.app.is_query_router or self.app.is_cluster_member): self.app.start_db(update_db=True) if not cluster_config and backup_info: self._perform_restore(backup_info, context, mount_point, self.app) if service.MongoDBAdmin().is_root_enabled(): self.app.status.report_root(context, 'root') if not cluster_config and root_password: LOG.debug('Root password provided. Enabling root.') service.MongoDBAdmin().enable_root(root_password) if not cluster_config: if databases: self.create_database(context, databases) if users: self.create_user(context, users)
def list_users(self, context, limit=None, marker=None, include_marker=False): LOG.debug("Listing users.") return service.MongoDBAdmin().list_users(limit, marker, include_marker)
def grant_access(self, context, username, hostname, databases): LOG.debug("Granting access.") return service.MongoDBAdmin().grant_access(username, databases)
def get_user(self, context, username, hostname): LOG.debug("Getting user.") return service.MongoDBAdmin().get_user(username)
def delete_user(self, context, user): LOG.debug("Deleting user.") with EndNotification(context): return service.MongoDBAdmin().delete_user(user)
def delete_database(self, context, database): LOG.debug("Deleting database.") with EndNotification(context): return service.MongoDBAdmin().delete_database(database)
def prepare(self, context, packages, databases, memory_mb, users, device_path=None, mount_point=None, backup_info=None, config_contents=None, root_password=None, overrides=None, cluster_config=None, snapshot=None): """Makes ready DBAAS on a Guest container.""" LOG.debug("Preparing MongoDB instance.") self.app.status.begin_install() self.app.install_if_needed(packages) self.app.wait_for_start() self.app.stop_db() self.app.clear_storage() mount_point = system.MONGODB_MOUNT_POINT if device_path: device = volume.VolumeDevice(device_path) # unmount if device is already mounted device.unmount_device(device_path) device.format() if os.path.exists(system.MONGODB_MOUNT_POINT): device.migrate_data(mount_point) device.mount(mount_point) operating_system.chown(mount_point, system.MONGO_USER, system.MONGO_USER, as_root=True) LOG.debug("Mounted the volume %(path)s as %(mount)s." % { 'path': device_path, "mount": mount_point }) if config_contents: # Save resolved configuration template first. self.app.configuration_manager.save_configuration(config_contents) # Apply guestagent specific configuration changes. self.app.apply_initial_guestagent_configuration( cluster_config, mount_point) if not cluster_config: # Create the Trove admin user. self.app.secure() # Don't start mongos until add_config_servers is invoked. if not self.app.is_query_router: self.app.start_db(update_db=False) if not cluster_config and backup_info: self._perform_restore(backup_info, context, mount_point, self.app) if service.MongoDBAdmin().is_root_enabled(): self.app.status.report_root('root') if not cluster_config and root_password: LOG.debug('Root password provided. Enabling root.') service.MongoDBAdmin().enable_root(root_password) if not cluster_config: if databases: self.create_database(context, databases) if users: self.create_user(context, users) if cluster_config: self.app.status.set_status( ds_instance.ServiceStatuses.BUILD_PENDING) else: self.app.status.set_status(ds_instance.ServiceStatuses.RUNNING) LOG.info(_('Completed setup of MongoDB database instance.'))
def enable_root_with_password(self, context, root_password=None): return service.MongoDBAdmin().enable_root(root_password)
def change_passwords(self, context, users): LOG.debug("Changing password.") with EndNotification(context): return service.MongoDBAdmin().change_passwords(users)
def delete_user(self, context, user): LOG.debug("Deleting user.") return service.MongoDBAdmin().delete_user(user)
def delete_database(self, context, database): LOG.debug("Deleting database.") return service.MongoDBAdmin().delete_database(database)
def create_user(self, context, users): LOG.debug("Creating user(s).") return service.MongoDBAdmin().create_users(users)
def create_database(self, context, databases): LOG.debug("Creating database(s).") return service.MongoDBAdmin().create_database(databases)
def change_passwords(self, context, users): LOG.debug("Changing password.") return service.MongoDBAdmin().change_passwords(users)
def revoke_access(self, context, username, hostname, database): LOG.debug("Revoking access.") return service.MongoDBAdmin().revoke_access(username, database)
def list_access(self, context, username, hostname): LOG.debug("Listing access.") return service.MongoDBAdmin().list_access(username)
def update_attributes(self, context, username, hostname, user_attrs): LOG.debug("Updating database attributes.") with EndNotification(context): return service.MongoDBAdmin().update_attributes( username, user_attrs)
def enable_root(self, context): LOG.debug("Enabling root.") return service.MongoDBAdmin().enable_root()
def create_database(self, context, databases): LOG.debug("Creating database(s).") with EndNotification(context): return service.MongoDBAdmin().create_database(databases)
def is_root_enabled(self, context): LOG.debug("Checking if root is enabled.") return service.MongoDBAdmin().is_root_enabled()
def create_user(self, context, users): LOG.debug("Creating user(s).") with EndNotification(context): return service.MongoDBAdmin().create_users(users)