def make_host_reachable(self): updates = { 'rpc_address': "0.0.0.0", 'listen_address': operating_system.get_ip_address(), 'seed': operating_system.get_ip_address() } self.update_conf_with_group(updates)
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): """Makes ready DBAAS on a Guest container.""" LOG.debug(_("Prepare MongoDB instance")) self.status.begin_install() self.app.install_if_needed(packages) self.app.stop_db() self.app.clear_storage() mount_point = system.MONGODB_MOUNT_POINT if device_path: device = volume.VolumeDevice(device_path) device.format() if os.path.exists(system.MONGODB_MOUNT_POINT): device.migrate_data(mount_point) device.mount(mount_point) self.app.update_owner(mount_point) LOG.debug(_("Mounted the volume %(path)s as %(mount)s") % {'path': device_path, "mount": mount_point}) if mount_point: config_contents = self.app.update_config_contents( config_contents, { 'dbpath': mount_point, 'bind_ip': operating_system.get_ip_address() }) self.app.start_db_with_conf_changes(config_contents) LOG.info(_('"prepare" call has finished.'))
def initial_setup(self): self.ip_address = operating_system.get_ip_address() mount_point = CONF.couchbase.mount_point try: LOG.info(_('Couchbase Server change data dir path.')) operating_system.update_owner('couchbase', 'couchbase', mount_point) pwd = CouchbaseRootAccess.get_password() utils.execute_with_timeout((system.cmd_node_init % { 'data_path': mount_point, 'IP': self.ip_address, 'PWD': pwd }), shell=True) utils.execute_with_timeout(system.cmd_rm_old_data_dir, shell=True) LOG.debug('Couchbase Server initialize cluster.') utils.execute_with_timeout((system.cmd_cluster_init % { 'IP': self.ip_address, 'PWD': pwd }), shell=True) utils.execute_with_timeout(system.cmd_set_swappiness, shell=True) utils.execute_with_timeout(system.cmd_update_sysctl_conf, shell=True) LOG.info(_('Couchbase Server initial setup finished.')) except exception.ProcessExecutionError: LOG.exception(_('Error performing initial Couchbase setup.')) raise RuntimeError("Couchbase Server initial setup failed")
def initial_setup(self): self.ip_address = operating_system.get_ip_address() mount_point = CONF.get('couchbase').mount_point try: LOG.info(_('Couchbase Server change data dir path')) utils.execute_with_timeout(system.cmd_own_data_dir, shell=True) pwd = CouchbaseRootAccess.get_password() utils.execute_with_timeout((system.cmd_node_init % { 'data_path': mount_point, 'IP': self.ip_address, 'PWD': pwd }), shell=True) utils.execute_with_timeout(system.cmd_rm_old_data_dir, shell=True) LOG.info(_('Couchbase Server initialize cluster')) utils.execute_with_timeout((system.cmd_cluster_init % { 'IP': self.ip_address, 'PWD': pwd }), shell=True) utils.execute_with_timeout(system.cmd_set_swappiness, shell=True) utils.execute_with_timeout(system.cmd_update_sysctl_conf, shell=True) LOG.info(_('Couchbase Server initial setup finished')) except exception.ProcessExecutionError as e: LOG.error(_('Process execution error %s') % e) raise RuntimeError("Couchbase Server initial setup failed")
def initial_setup(self): self.ip_address = operating_system.get_ip_address() mount_point = CONF.get('couchbase').mount_point try: LOG.info(_('Couchbase Server change data dir path')) utils.execute_with_timeout(system.cmd_own_data_dir, shell=True) pwd = CouchbaseRootAccess.get_password() utils.execute_with_timeout( (system.cmd_node_init % {'data_path': mount_point, 'IP': self.ip_address, 'PWD': pwd}), shell=True) utils.execute_with_timeout( system.cmd_rm_old_data_dir, shell=True) LOG.info(_('Couchbase Server initialize cluster')) utils.execute_with_timeout( (system.cmd_cluster_init % {'IP': self.ip_address, 'PWD': pwd}), shell=True) utils.execute_with_timeout(system.cmd_set_swappiness, shell=True) utils.execute_with_timeout(system.cmd_update_sysctl_conf, shell=True) LOG.info(_('Couchbase Server initial setup finished')) except exception.ProcessExecutionError as e: LOG.error(_('Process execution error %s') % e) raise RuntimeError("Couchbase Server initial setup failed")
def do_mongo(self, db_cmd): cmd = ('mongo --host ' + operating_system.get_ip_address() + ' --quiet --eval \'printjson(%s)\'' % db_cmd) # TODO(ramashri) see if hardcoded values can be removed out, err = utils.execute_with_timeout(cmd, shell=True, timeout=100) LOG.debug(out.strip()) return (out, err)
def initial_setup(self): self.ip_address = operating_system.get_ip_address() mount_point = CONF.couchbase.mount_point try: LOG.info(_('Couchbase Server change data dir path.')) operating_system.update_owner('couchbase', 'couchbase', mount_point) pwd = CouchbaseRootAccess.get_password() utils.execute_with_timeout( (system.cmd_node_init % {'data_path': mount_point, 'IP': self.ip_address, 'PWD': pwd}), shell=True) utils.execute_with_timeout( system.cmd_rm_old_data_dir, shell=True) LOG.debug('Couchbase Server initialize cluster.') utils.execute_with_timeout( (system.cmd_cluster_init % {'IP': self.ip_address, 'PWD': pwd}), shell=True) utils.execute_with_timeout(system.cmd_set_swappiness, shell=True) utils.execute_with_timeout(system.cmd_update_sysctl_conf, shell=True) LOG.info(_('Couchbase Server initial setup finished.')) except exception.ProcessExecutionError: LOG.exception(_('Error performing initial Couchbase setup.')) raise RuntimeError("Couchbase Server initial setup failed")
def _get_actual_db_status(self): self.ip_address = operating_system.get_ip_address() try: out, err = utils.execute_with_timeout((system.cmd_couchbase_status % {"IP": self.ip_address}), shell=True) server_stats = json.loads(out) if not err and server_stats["clusterMembership"] == "active": return rd_instance.ServiceStatuses.RUNNING else: return rd_instance.ServiceStatuses.SHUTDOWN except exception.ProcessExecutionError as e: LOG.error(_("Process execution %s ") % e) return rd_instance.ServiceStatuses.SHUTDOWN
def _get_actual_db_status(self): try: if self._is_config_server() is True: status_check = (system.CMD_STATUS % (operating_system.get_ip_address() + ' --port 27019')) else: status_check = (system.CMD_STATUS % operating_system.get_ip_address()) out, err = utils.execute_with_timeout(status_check, shell=True) if not err and "connected to:" in out: return ds_instance.ServiceStatuses.RUNNING else: return ds_instance.ServiceStatuses.SHUTDOWN except exception.ProcessExecutionError as e: LOG.error(_("Process execution %s") % e) return ds_instance.ServiceStatuses.SHUTDOWN except OSError as e: LOG.error(_("OS Error %s") % e) return ds_instance.ServiceStatuses.SHUTDOWN
def _get_actual_db_status(self): try: if self._is_config_server() is True: status_check = ( system.CMD_STATUS % (operating_system.get_ip_address() + ' --port 27019')) else: status_check = (system.CMD_STATUS % operating_system.get_ip_address()) out, err = utils.execute_with_timeout(status_check, shell=True) if not err and "connected to:" in out: return ds_instance.ServiceStatuses.RUNNING else: return ds_instance.ServiceStatuses.SHUTDOWN except exception.ProcessExecutionError as e: LOG.exception(_("Process execution %s.") % e) return ds_instance.ServiceStatuses.SHUTDOWN except OSError as e: LOG.exception(_("OS Error %s.") % e) return ds_instance.ServiceStatuses.SHUTDOWN
def get_config_changes(self, cluster_config, mount_point=None): LOG.debug("Getting configuration changes.") config_changes = {} if cluster_config is not None: config_changes['bind_ip'] = operating_system.get_ip_address() if cluster_config["instance_type"] == "config_server": config_changes["configsvr"] = "true" elif cluster_config["instance_type"] == "member": config_changes["replSet"] = cluster_config["replica_set_name"] if (mount_point is not None and (cluster_config is None or cluster_config['instance_type'] != "query_router")): config_changes['dbpath'] = mount_point return config_changes
def set_password(self, root_password): self.ip_address = operating_system.get_ip_address() child = pexpect.spawn(system.cmd_reset_pwd % {'IP': self.ip_address}) try: child.expect('.*password.*') child.sendline(root_password) child.expect('.*(yes/no).*') child.sendline('yes') child.expect('.*successfully.*') except pexpect.TIMEOUT: child.delayafterclose = 1 child.delayafterterminate = 1 child.close(force=True) self.write_password_to_file(root_password)
def _get_actual_db_status(self): self.ip_address = operating_system.get_ip_address() try: out, err = utils.execute_with_timeout( (system.cmd_couchbase_status % { 'IP': self.ip_address }), shell=True) server_stats = json.loads(out) if not err and server_stats["clusterMembership"] == "active": return rd_instance.ServiceStatuses.RUNNING else: return rd_instance.ServiceStatuses.SHUTDOWN except exception.ProcessExecutionError as e: LOG.error(_("Process execution %s ") % e) return rd_instance.ServiceStatuses.SHUTDOWN
def _get_actual_db_status(self): self.ip_address = operating_system.get_ip_address() try: pwd = CouchbaseRootAccess.get_password() out, err = utils.execute_with_timeout( (system.cmd_couchbase_status % {'IP': self.ip_address, 'PWD': pwd}), shell=True) server_stats = json.loads(out) if not err and server_stats["clusterMembership"] == "active": return rd_instance.ServiceStatuses.RUNNING else: return rd_instance.ServiceStatuses.SHUTDOWN except exception.ProcessExecutionError: LOG.exception(_("Error getting Couchbase status.")) return rd_instance.ServiceStatuses.SHUTDOWN
def get_config_changes(self, cluster_config, mount_point=None): config_changes = {} if cluster_config is not None: config_changes['bind_ip'] = operating_system.get_ip_address() # TODO(ramashri) remove smallfiles config at end of dev testing if cluster_config["instance_type"] == "config_server": config_changes["configsvr"] = "true" config_changes["smallfiles"] = "true" elif cluster_config["instance_type"] == "member": config_changes["replSet"] = cluster_config["replica_set_name"] config_changes["smallfiles"] = "true" if (mount_point is not None and (cluster_config is None or cluster_config['instance_type'] != "query_router")): config_changes['dbpath'] = mount_point return config_changes
def _get_actual_db_status(self): self.ip_address = operating_system.get_ip_address() try: pwd = CouchbaseRootAccess.get_password() out, err = utils.execute_with_timeout( (system.cmd_couchbase_status % { 'IP': self.ip_address, 'PWD': pwd }), shell=True) server_stats = json.loads(out) if not err and server_stats["clusterMembership"] == "active": return rd_instance.ServiceStatuses.RUNNING else: return rd_instance.ServiceStatuses.SHUTDOWN except exception.ProcessExecutionError: LOG.exception(_("Error getting Couchbase status.")) return rd_instance.ServiceStatuses.SHUTDOWN
def initial_setup(self): self.ip_address = operating_system.get_ip_address() mount_point = CONF.get("couchbase").mount_point try: LOG.info(_("Couchbase Server change data dir path")) utils.execute_with_timeout(system.cmd_own_data_dir, shell=True) utils.execute_with_timeout( (system.cmd_node_init % {"data_path": mount_point, "IP": self.ip_address}), shell=True ) utils.execute_with_timeout(system.cmd_rm_old_data_dir, shell=True) LOG.info(_("Couchbase Server initialize cluster")) utils.execute_with_timeout((system.cmd_cluster_init % {"IP": self.ip_address}), shell=True) utils.execute_with_timeout(system.cmd_set_swappiness, shell=True) utils.execute_with_timeout(system.cmd_update_sysctl_conf, shell=True) LOG.info(_("Couchbase Server initial setup finished")) except exception.ProcessExecutionError as e: LOG.error(_("Process execution error %s") % e) raise RuntimeError("Couchbase Server initial setup failed")
def set_password(self, root_password): self.ip_address = operating_system.get_ip_address() child = pexpect.spawn(system.cmd_reset_pwd % {'IP': self.ip_address}) try: child.expect('.*password.*') child.sendline(root_password) child.expect('.*(yes/no).*') child.sendline('yes') child.expect('.*successfully.*') except pexpect.TIMEOUT: child.delayafterclose = 1 child.delayafterterminate = 1 try: child.close(force=True) except pexpect.ExceptionPexpect: # Close fails to terminate a sudo process on some OSes. subprocess.call(['sudo', 'kill', str(child.pid)]) self.write_password_to_file(root_password)
def _get_actual_db_status(self): self.ip_address = operating_system.get_ip_address() pwd = None try: pwd = CouchbaseRootAccess.get_password() return self._get_status_from_couchbase(pwd) except exception.ProcessExecutionError: # log the exception, but continue with native config approach LOG.exception(_("Error getting the Couchbase status.")) try: out, err = utils.execute_with_timeout( system.cmd_get_password_from_config, shell=True) except exception.ProcessExecutionError: LOG.exception( _("Error getting the root password from the " "native Couchbase config file.")) return rd_instance.ServiceStatuses.SHUTDOWN config_pwd = out.strip() if out is not None else None if not config_pwd or config_pwd == pwd: LOG.debug("The root password from the native Couchbase config " "file is either empty or already matches the " "stored value.") return rd_instance.ServiceStatuses.SHUTDOWN try: status = self._get_status_from_couchbase(config_pwd) except exception.ProcessExecutionError: LOG.exception( _("Error getting Couchbase status using the " "password parsed from the native Couchbase " "config file.")) return rd_instance.ServiceStatuses.SHUTDOWN # if the parsed root password worked, update the stored value to # avoid having to consult/parse the couchbase config file again. LOG.debug("Updating the stored value for the Couchbase " "root password.") CouchbaseRootAccess().write_password_to_file(config_pwd) return status
def _get_actual_db_status(self): self.ip_address = operating_system.get_ip_address() pwd = None try: pwd = CouchbaseRootAccess.get_password() return self._get_status_from_couchbase(pwd) except exception.ProcessExecutionError: # log the exception, but continue with native config approach LOG.exception(_("Error getting the Couchbase status.")) try: out, err = utils.execute_with_timeout( system.cmd_get_password_from_config, shell=True) except exception.ProcessExecutionError: LOG.exception(_("Error getting the root password from the " "native Couchbase config file.")) return rd_instance.ServiceStatuses.SHUTDOWN config_pwd = out.strip() if out is not None else None if not config_pwd or config_pwd == pwd: LOG.debug("The root password from the native Couchbase config " "file is either empty or already matches the " "stored value.") return rd_instance.ServiceStatuses.SHUTDOWN try: status = self._get_status_from_couchbase(config_pwd) except exception.ProcessExecutionError: LOG.exception(_("Error getting Couchbase status using the " "password parsed from the native Couchbase " "config file.")) return rd_instance.ServiceStatuses.SHUTDOWN # if the parsed root password worked, update the stored value to # avoid having to consult/parse the couchbase config file again. LOG.debug("Updating the stored value for the Couchbase " "root password.") CouchbaseRootAccess().write_password_to_file(config_pwd) return status
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the # License for the specific language governing permissions and limitations # under the License. # from trove.common import cfg from trove.common import utils from trove.guestagent.common import operating_system from trove.guestagent.datastore.mongodb import service as mongo_service from trove.guestagent.strategies.restore import base from trove.openstack.common import log as logging CONF = cfg.CONF LOG = logging.getLogger(__name__) IP = operating_system.get_ip_address() LARGE_TIMEOUT = 600 MONGODB_DBPATH = CONF.mongodb.mount_point MONGO_DUMP_DIR = MONGODB_DBPATH + "/dump" class MongoDump(base.RestoreRunner): __strategy_name__ = 'mongodump' base_restore_cmd = 'sudo tar xPf -' cleanup_commands = [ 'sudo rm -fr ' + MONGO_DUMP_DIR, 'sudo chown -R mongodb:nogroup ' + MONGODB_DBPATH ] def __init__(self, *args, **kwargs):
def get_master_ref(self, service, snapshot_info): master_ref = { 'host': operating_system.get_ip_address(), 'port': service.get_port() } return master_ref