Example #1
0
 def _do_network_init(self):
     ran_fn = sh.joinpths(self.get_option("trace_dir"), NET_INITED_FN)
     if not sh.isfile(ran_fn) and self.net_enabled:
         LOG.info("Creating your nova network to be used with instances.")
         # Figure out the commands to run
         mp = {}
         cmds = []
         mp["CFG_FILE"] = sh.joinpths(self.get_option("cfg_dir"), API_CONF)
         mp["BIN_DIR"] = sh.joinpths(self.get_option("app_dir"), BIN_DIR)
         if self.cfg.getboolean("nova", "enable_fixed"):
             # Create a fixed network
             mp["FIXED_NETWORK_SIZE"] = self.cfg.getdefaulted("nova", "fixed_network_size", "256")
             mp["FIXED_RANGE"] = self.cfg.getdefaulted("nova", "fixed_range", "10.0.0.0/24")
             cmds.extend(FIXED_NET_CMDS)
         if not self.get_option("quantum"):
             if self.cfg.getboolean("nova", "enable_floating"):
                 # Create a floating network + test floating pool
                 cmds.extend(FLOATING_NET_CMDS)
                 mp["FLOATING_RANGE"] = self.cfg.getdefaulted("nova", "floating_range", "172.24.4.224/28")
                 mp["TEST_FLOATING_RANGE"] = self.cfg.getdefaulted("nova", "test_floating_range", "192.168.253.0/29")
                 mp["TEST_FLOATING_POOL"] = self.cfg.getdefaulted("nova", "test_floating_pool", "test")
         else:
             LOG.info("Not creating floating IPs (not supported by quantum server)")
             LOG.info(
                 "Waiting %s seconds so that quantum can start up before running first time init." % (self.wait_time)
             )
             sh.sleep(self.wait_time)
         # Anything to run??
         if cmds:
             utils.execute_template(*cmds, params=mp)
         # Writing this makes sure that we don't init again
         cmd_mp = {"cmds": cmds, "replacements": mp}
         sh.write_file(ran_fn, utils.prettify_yaml(cmd_mp))
         LOG.info("If you wish to re-run initialization, delete %s", colorizer.quote(ran_fn))
Example #2
0
 def pre_uninstall(self):
     dbtype = self.get_option("type")
     dbactions = self.distro.get_command_config(dbtype, quiet=True)
     try:
         if dbactions:
             LOG.info(
                 ("Attempting to reset your db password to %s so" " that we can set it the next time you install."),
                 colorizer.quote(RESET_BASE_PW),
             )
             pwd_cmd = self.distro.get_command(dbtype, "set_pwd")
             if pwd_cmd:
                 LOG.info("Ensuring your database is started before we operate on it.")
                 self.runtime.start()
                 self.runtime.wait_active()
                 params = {
                     "OLD_PASSWORD": dbhelper.get_shared_passwords(self)["pw"],
                     "NEW_PASSWORD": RESET_BASE_PW,
                     "USER": self.get_option("user", default_value="root"),
                 }
                 cmds = [{"cmd": pwd_cmd}]
                 utils.execute_template(*cmds, params=params)
     except IOError:
         LOG.warn(
             (
                 "Could not reset the database password. You might have to manually "
                 "reset the password to %s before the next install"
             ),
             colorizer.quote(RESET_BASE_PW),
         )
Example #3
0
 def _do_network_init(self):
     ran_fn = self.net_init_fn
     if not sh.isfile(ran_fn) and self.get_bool_option('do-network-init'):
         # Figure out the commands to run
         cmds = []
         mp = {
             'CFG_FILE': self.config_path,
             'BIN_DIR': self.bin_dir
         }
         mp['BIN_DIR'] = self.bin_dir
         if self.get_bool_option('enable_fixed'):
             # Create a fixed network
             mp['FIXED_NETWORK_SIZE'] = self.get_option('fixed_network_size', default_value='256')
             mp['FIXED_RANGE'] = self.get_option('fixed_range', default_value='10.0.0.0/24')
             cmds.extend(FIXED_NET_CMDS)
         if self.get_bool_option('enable_floating'):
             # Create a floating network + test floating pool
             cmds.extend(FLOATING_NET_CMDS)
             mp['FLOATING_RANGE'] = self.get_option('floating_range', default_value='172.24.4.224/28')
             mp['TEST_FLOATING_RANGE'] = self.get_option('test_floating_range', default_value='192.168.253.0/29')
             mp['TEST_FLOATING_POOL'] = self.get_option('test_floating_pool', default_value='test')
         # Anything to run??
         if cmds:
             LOG.info("Creating your nova network to be used with instances.")
             utils.execute_template(*cmds, params=mp)
         # Writing this makes sure that we don't init again
         cmd_mp = {
             'cmds': cmds,
             'replacements': mp,
         }
         sh.write_file(ran_fn, utils.prettify_yaml(cmd_mp))
         LOG.info("If you wish to re-run network initialization, delete %s", colorizer.quote(ran_fn))
Example #4
0
    def post_install(self):
        comp.PkgInstallComponent.post_install(self)

        # Fix up the db configs
        self._configure_db_confs()

        # Extra actions to ensure we are granted access
        dbtype = self.cfg.get("db", "type")
        dbactions = self.distro.get_command_config(dbtype, quiet=True)

        # Set your password
        try:
            if dbactions:
                pwd_cmd = self.distro.get_command(dbtype, 'set_pwd')
                if pwd_cmd:
                    LOG.info(("Attempting to set your db password"
                          " just incase it wasn't set previously."))
                    LOG.info("Ensuring your database is started before we operate on it.")
                    self.runtime.restart()
                    params = {
                        'NEW_PASSWORD': self.cfg.get_password("sql", PASSWORD_PROMPT),
                        'USER': self.cfg.getdefaulted("db", "sql_user", 'root'),
                        'OLD_PASSWORD': RESET_BASE_PW,
                        }
                    cmds = [{'cmd': pwd_cmd}]
                    utils.execute_template(*cmds, params=params)
        except IOError:
            LOG.warn(("Couldn't set your db password. It might have already been "
                       "set by a previous process."))

        # Ensure access granted
        user = self.cfg.getdefaulted("db", "sql_user", 'root')
        dbhelper.grant_permissions(self.cfg, self.distro, user, restart_func=self.runtime.restart)
 def _setup_vol_groups(self):
     LOG.info("Attempting to setup volume groups for nova volume management.")
     mp = dict()
     backing_file = self.cfg.getdefaulted('nova', 'volume_backing_file',
                    sh.joinpths(self.installer.get_option('app_dir'), 'nova-volumes-backing-file'))
     vol_group = self.cfg.getdefaulted('nova', 'volume_group', 'nova-volumes')
     backing_file_size = utils.to_bytes(self.cfg.getdefaulted('nova', 'volume_backing_file_size', '2052M'))
     mp['VOLUME_GROUP'] = vol_group
     mp['VOLUME_BACKING_FILE'] = backing_file
     mp['VOLUME_BACKING_FILE_SIZE'] = backing_file_size
     try:
         utils.execute_template(*VG_CHECK_CMD, params=mp)
         LOG.warn("Volume group already exists: %r" % (vol_group))
     except exceptions.ProcessExecutionError as err:
         # Check that the error from VG_CHECK is an expected error
         if err.exit_code != 5:
             raise
         LOG.info("Need to create volume group: %r" % (vol_group))
         sh.touch_file(backing_file, die_if_there=False, file_size=backing_file_size)
         vg_dev_result = utils.execute_template(*VG_DEV_CMD, params=mp)
         if vg_dev_result and vg_dev_result[0]:
             LOG.debug("VG dev result: %s" % (vg_dev_result))
             # Strip the newlines out of the stdout (which is in the first
             # element of the first (and only) tuple in the response
             (sysout, _) = vg_dev_result[0]
             mp['DEV'] = sysout.replace('\n', '')
             utils.execute_template(*VG_CREATE_CMD, params=mp)
     # One way or another, we should have the volume group, Now check the
     # logical volumes
     self._process_lvs(mp)
     # Finish off by restarting tgt, and ignore any errors
     cmdrestart = self.distro.get_command('iscsi', 'restart', quiet=True)
     if cmdrestart:
         sh.execute(*cmdrestart, run_as_root=True, check_exit_code=False)
Example #6
0
 def _do_network_init(self):
     ran_fn = self.net_init_fn
     if not sh.isfile(ran_fn) and self.get_bool_option("do-network-init"):
         # Figure out the commands to run
         cmds = []
         mp = {"CFG_FILE": self.config_path, "BIN_DIR": self.bin_dir}
         mp["BIN_DIR"] = self.bin_dir
         if self.get_bool_option("enable_fixed"):
             # Create a fixed network
             mp["FIXED_NETWORK_SIZE"] = self.get_option("fixed_network_size", default_value="256")
             mp["FIXED_RANGE"] = self.get_option("fixed_range", default_value="10.0.0.0/24")
             cmds.extend(FIXED_NET_CMDS)
         if self.get_bool_option("enable_floating"):
             # Create a floating network + test floating pool
             cmds.extend(FLOATING_NET_CMDS)
             mp["FLOATING_RANGE"] = self.get_option("floating_range", default_value="172.24.4.224/28")
             mp["TEST_FLOATING_RANGE"] = self.get_option("test_floating_range", default_value="192.168.253.0/29")
             mp["TEST_FLOATING_POOL"] = self.get_option("test_floating_pool", default_value="test")
         # Anything to run??
         if cmds:
             LOG.info("Creating your nova network to be used with instances.")
             utils.execute_template(*cmds, params=mp)
         # Writing this makes sure that we don't init again
         cmd_mp = {"cmds": cmds, "replacements": mp}
         sh.write_file(ran_fn, utils.prettify_yaml(cmd_mp))
         LOG.info("If you wish to re-run network initialization, delete %s", colorizer.quote(ran_fn))
Example #7
0
 def _setup_pki(self):
     LOG.info("Setting up keystone's pki support.")
     for value in kconf.PKI_FILES.values():
         sh.mkdirslist(sh.dirname(sh.joinpths(self.configurator.link_dir, value)),
                       tracewriter=self.tracewriter)
     pki_cmd = MANAGE_CMD + ['pki_setup']
     cmds = [{'cmd': pki_cmd}]
     utils.execute_template(*cmds, cwd=self.bin_dir, params=self.config_params(None))
 def post_start(self):
     comp.PythonRuntime.post_start(self)
     if self.get_option('create-cidr'):
         LOG.info("Waiting %s seconds so that the melange server can start up before cidr range creation." % (self.wait_time))
         sh.sleep(self.wait_time)
         mp = dict()
         mp['CIDR_RANGE'] = self.cfg.getdefaulted('melange', 'm_mac_range', DEF_CIDR_RANGE)
         utils.execute_template(*CIDR_CREATE_CMD, params=mp)
Example #9
0
 def check_virt(self, virt_type):
     virt_protocol = LIBVIRT_PROTOCOL_MAP.get(virt_type)
     self.restart_service()
     self.wait_active()
     cmds = [{
         'cmd': self.distro.get_command('libvirt', 'verify'),
     }]
     mp = {
         'VIRT_PROTOCOL': virt_protocol,
         'VIRT_TYPE': virt_type,
     }
     utils.execute_template(*cmds, params=mp)
 def check_virt(self, virt_type):
     virt_protocol = LIBVIRT_PROTOCOL_MAP.get(virt_type)
     self.restart_service()
     cmds = list()
     cmds.append({
         'cmd': self.distro.get_command('libvirt', 'verify'),
         'run_as_root': True,
     })
     mp = dict()
     mp['VIRT_PROTOCOL'] = virt_protocol
     mp['VIRT_TYPE'] = virt_type
     utils.execute_template(*cmds, params=mp)
Example #11
0
def drop_db(distro, dbtype, user, pw, dbname, **kwargs):
    dropcmd = distro.get_command(dbtype, "drop_db", silent=True)
    if dropcmd:
        LOG.info("Dropping %s database: %s", colorizer.quote(dbtype), colorizer.quote(dbname))
        params = dict()
        params["PASSWORD"] = pw
        params["USER"] = user
        params["DB"] = dbname
        cmds = list()
        cmds.append({"cmd": dropcmd, "run_as_root": False})
        utils.execute_template(*cmds, params=params)
    else:
        msg = BASE_ERROR % ("drop", dbtype)
        raise NotImplementedError(msg)
Example #12
0
def grant_permissions(dbtype, distro, user, pw, restart_func=None):
    """
    Grant permissions on the database.
    """
    dbactions = distro.get_command_config(dbtype, quiet=True)
    if dbactions:
        grant_cmd = distro.get_command(dbtype, "grant_all")
        if grant_cmd:
            if restart_func:
                LOG.info("Ensuring the database is started.")
                restart_func()
            params = {"PASSWORD": pw, "USER": user}
            cmds = [{"cmd": grant_cmd}]
            LOG.info("Giving user %s full control of all databases.", colorizer.quote(user))
            utils.execute_template(*cmds, params=params)
    return
Example #13
0
def drop_db(distro, dbtype, user, pw, dbname, **kwargs):
    dropcmd = distro.get_command(dbtype, 'drop_db', silent=True)
    if dropcmd:
        LOG.info('Dropping %s database: %s', colorizer.quote(dbtype), colorizer.quote(dbname))
        params = dict()
        params['PASSWORD'] = pw
        params['USER'] = user
        params['DB'] = dbname
        cmds = list()
        cmds.append({
            'cmd': dropcmd,
        })
        utils.execute_template(*cmds, params=params)
    else:
        msg = BASE_ERROR % ('drop', dbtype)
        raise NotImplementedError(msg)
Example #14
0
def create_db(distro, dbtype, user, pw, dbname, **kwargs):
    createcmd = distro.get_command(dbtype, "create_db", silent=True)
    if createcmd:
        charset = kwargs.get("charset", "utf8")
        LOG.info("Creating %s database: %s (%s)", colorizer.quote(dbtype), colorizer.quote(dbname), charset)
        params = dict()
        params["PASSWORD"] = pw
        params["USER"] = user
        params["DB"] = dbname
        params["CHARACTER_SET"] = charset
        cmds = list()
        cmds.append({"cmd": createcmd, "run_as_root": False})
        utils.execute_template(*cmds, params=params)
    else:
        msg = BASE_ERROR % ("create", dbtype)
        raise NotImplementedError(msg)
 def _setup_bridge(self):
     if not self.q_vswitch_agent or not self.get_option('ovs-bridge-init'):
         return
     else:
         bridge = self.cfg.getdefaulted("quantum", "ovs_bridge", 'br-int')
         LOG.info("Fixing up ovs bridge named: %s", colorizer.quote(bridge))
         external_id = self.cfg.getdefaulted("quantum", 'ovs_bridge_external_name', bridge)
         params = dict()
         params['OVS_BRIDGE'] = bridge
         params['OVS_EXTERNAL_ID'] = external_id
         cmds = list()
         for cmd_templ in OVS_BRIDGE_CMDS:
             cmds.append({
                 'cmd': cmd_templ,
                 'run_as_root': True,
             })
         utils.execute_template(*cmds, params=params)
Example #16
0
def drop_db(cfg, distro, dbname):
    dbtype = cfg.get("db", "type")
    dropcmd = distro.get_command(dbtype, 'drop_db', silent=True)
    if dropcmd:
        LOG.info('Dropping %s database: %s', colorizer.quote(dbtype), colorizer.quote(dbname))
        params = dict()
        params['PASSWORD'] = cfg.get_password("sql", PASSWORD_PROMPT)
        params['USER'] = cfg.getdefaulted("db", "sql_user", 'root')
        params['DB'] = dbname
        cmds = list()
        cmds.append({
            'cmd': dropcmd,
            'run_as_root': False,
        })
        utils.execute_template(*cmds, params=params)
    else:
        msg = BASE_ERROR % ('drop', dbtype)
        raise NotImplementedError(msg)
Example #17
0
def create_db(distro, dbtype, user, pw, dbname, **kwargs):
    createcmd = distro.get_command(dbtype, 'create_db', silent=True)
    if createcmd:
        charset = kwargs.get('charset', 'utf8')
        LOG.info('Creating %s database: %s (%s)', colorizer.quote(dbtype), colorizer.quote(dbname), charset)
        params = dict()
        params['PASSWORD'] = pw
        params['USER'] = user
        params['DB'] = dbname
        params['CHARACTER_SET'] = charset
        cmds = list()
        cmds.append({
            'cmd': createcmd,
        })
        utils.execute_template(*cmds, params=params)
    else:
        msg = BASE_ERROR % ('create', dbtype)
        raise NotImplementedError(msg)
Example #18
0
def grant_permissions(cfg, distro, user, restart_func=None):
    """
    Grant permissions on the database.
    """
    dbtype = cfg.get("db", "type")
    dbactions = distro.get_command_config(dbtype, quiet=True)
    if dbactions:
        grant_cmd = distro.get_command(dbtype, 'grant_all')
        if grant_cmd:
            if restart_func:
                LOG.info("Ensuring the database is started")
                restart_func()
            params = {
                'PASSWORD': cfg.get_password("sql", PASSWORD_PROMPT),
                'USER': user,
            }
            cmds = [{'cmd': grant_cmd}]
            LOG.info("Giving user %s full control of all databases.", colorizer.quote(user))
            utils.execute_template(*cmds, params=params)
    return
Example #19
0
 def _process_lvs(self, mp):
     LOG.info("Attempting to setup logical volumes for nova volume management.")
     lvs_result = utils.execute_template(*VG_LVS_CMD, params=mp)
     if lvs_result and lvs_result[0]:
         vol_name_prefix = self.cfg.getdefaulted('nova', 'volume_name_prefix', DEF_VOL_PREFIX)
         LOG.debug("Using volume name prefix: %r" % (vol_name_prefix))
         (sysout, _) = lvs_result[0]
         for stdout_line in sysout.split('\n'):
             stdout_line = stdout_line.strip()
             if stdout_line:
                 # Ignore blank lines
                 LOG.debug("Processing LVS output line: %r" % (stdout_line))
                 if stdout_line.startswith(vol_name_prefix):
                     # TODO still need to implement the following:
                     # tid=`egrep "^tid.+$lv" /proc/net/iet/volume | cut -f1 -d' ' | tr ':' '='`
                     # if [[ -n "$tid" ]]; then
                     #   lun=`egrep "lun.+$lv" /proc/net/iet/volume | cut -f1 -d' ' | tr ':' '=' | tr -d '\t'`
                     #   sudo ietadm --op delete --$tid --$lun
                     # fi
                     # sudo lvremove -f $VOLUME_GROUP/$lv
                     raise NotImplementedError("LVS magic not yet implemented!")
                 mp['LV'] = stdout_line
                 utils.execute_template(*VG_LVREMOVE_CMD, params=mp)
Example #20
0
 def pre_uninstall(self):
     dbtype = self.cfg.get("db", "type")
     dbactions = self.distro.get_command_config(dbtype, quiet=True)
     try:
         if dbactions:
             LOG.info(("Attempting to reset your db password to %s so"
                       " that we can set it the next time you install."), colorizer.quote(RESET_BASE_PW))
             pwd_cmd = self.distro.get_command(dbtype, 'set_pwd')
             if pwd_cmd:
                 LOG.info("Ensuring your database is started before we operate on it.")
                 self.runtime.restart()
                 params = {
                     'OLD_PASSWORD': self.cfg.get_password('sql', PASSWORD_PROMPT),
                     'NEW_PASSWORD': RESET_BASE_PW,
                     'USER': self.cfg.getdefaulted("db", "sql_user", 'root'),
                     }
                 cmds = [{'cmd': pwd_cmd}]
                 utils.execute_template(*cmds, params=params)
     except IOError:
         LOG.warn(("Could not reset the database password. You might have to manually "
                   "reset the password to %s before the next install"), colorizer.quote(RESET_BASE_PW))
         utils.log_iterable(SQL_RESET_PW_LINKS, logger=LOG,
                             header="To aid in this check out:")
Example #21
0
    def post_install(self):
        binstall.PkgInstallComponent.post_install(self)

        # Fix up the db configs
        self._configure_db_confs()

        # Extra actions to ensure we are granted access
        dbtype = self.get_option("type")
        dbactions = self.distro.get_command_config(dbtype, quiet=True)

        # Set your password
        try:
            if dbactions:
                pwd_cmd = self.distro.get_command(dbtype, "set_pwd")
                if pwd_cmd:
                    LOG.info(("Attempting to set your db password" " just incase it wasn't set previously."))
                    LOG.info("Ensuring your database is started before we operate on it.")
                    self.runtime.start()
                    self.runtime.wait_active()
                    params = {
                        "NEW_PASSWORD": dbhelper.get_shared_passwords(self)["pw"],
                        "USER": self.get_option("user", default_value="root"),
                        "OLD_PASSWORD": RESET_BASE_PW,
                    }
                    cmds = [{"cmd": pwd_cmd}]
                    utils.execute_template(*cmds, params=params)
        except IOError:
            LOG.warn(("Couldn't set your db password. It might have already been " "set by a previous process."))

        # Ensure access granted
        dbhelper.grant_permissions(
            dbtype,
            distro=self.distro,
            user=self.get_option("user", default_value="root"),
            restart_func=self.runtime.restart,
            **dbhelper.get_shared_passwords(self)
        )
Example #22
0
 def _sync_db(self):
     LOG.info("Syncing keystone to database: %s", colorizer.quote(DB_NAME))
     sync_cmd = MANAGE_CMD + ['db_sync']
     cmds = [{'cmd': sync_cmd, 'run_as_root': True}]
     utils.execute_template(*cmds, cwd=self.bin_dir, params=self.config_params(None))
Example #23
0
 def _sync_db(self):
     LOG.info("Syncing nova to database named: %s",
              colorizer.quote(DB_NAME))
     utils.execute_template(*DB_SYNC_CMD, params=self.config_params(None))
Example #24
0
 def _sync_db(self):
     LOG.info("Syncing nova to database named: %s", colorizer.quote(DB_NAME))
     mp = self._get_param_map(None)
     utils.execute_template(*DB_SYNC_CMD, params=mp)
 def _sync_db(self):
     LOG.info("Syncing melange to database: %s", colorizer.quote(DB_NAME))
     utils.execute_template(*DB_SYNC_CMD, params=self._get_param_map(None))
Example #26
0
 def post_install(self, pkg, params=None):
     cmds = pkg.get('post-install')
     if cmds:
         LOG.info("Running post-install commands for package %s.", colorizer.quote(pkg['name']))
         utils.execute_template(*cmds, params=params)
Example #27
0
 def _sync_db(self):
     LOG.info("Syncing heat to database: %s",
              colorizer.quote(self.configurator.DB_NAME))
     cmds = [{'cmd': SYNC_DB_CMD}]
     utils.execute_template(*cmds, cwd=self.bin_dir)
 def _sync_db(self):
     LOG.info("Syncing keystone to database: %s", colorizer.quote(DB_NAME))
     mp = self._get_param_map(None)
     cmds = [{'cmd': SYNC_DB_CMD, 'run_as_root': True}]
     utils.execute_template(*cmds, cwd=self.bin_dir, params=mp)
Example #29
0
 def _sync_db(self):
     LOG.info("Syncing keystone to database: %s", colorizer.quote(self.configurator.DB_NAME))
     sync_cmd = MANAGE_CMD + ['db_sync']
     cmds = [{'cmd': sync_cmd}]
     utils.execute_template(*cmds, cwd=self.bin_dir, params=self.config_params(None))
Example #30
0
 def _sync_db(self):
     LOG.info("Syncing glance to database: %s", colorizer.quote(DB_NAME))
     cmds = [{'cmd': SYNC_DB_CMD, 'run_as_root': True}]
     utils.execute_template(*cmds,
                            cwd=self.bin_dir,
                            params=self.config_params(None))
Example #31
0
 def _sync_db(self):
     LOG.info("Syncing nova to database named: %s", colorizer.quote(DB_NAME))
     utils.execute_template(*DB_SYNC_CMD, params=self.config_params(None))
Example #32
0
 def post_install(self, pkg, params=None):
     cmds = pkg.get('post-install')
     if cmds:
         LOG.info("Running post-install commands for package %s.",
                  colorizer.quote(pkg['name']))
         utils.execute_template(*cmds, params=params)
Example #33
0
 def _sync_db(self):
     LOG.info("Syncing glance to database: %s", colorizer.quote(DB_NAME))
     cmds = [{'cmd': SYNC_DB_CMD, 'run_as_root': True}]
     utils.execute_template(*cmds, cwd=self.bin_dir, params=self.config_params(None))
Example #34
0
 def _sync_db(self):
     LOG.info("Syncing cinder to database: %s", colorizer.quote(self.configurator.DB_NAME))
     cmds = [{'cmd': SYNC_DB_CMD}]
     utils.execute_template(*cmds, cwd=self.bin_dir, params=self.config_params(None))