def post_install(self, pkgs, params=None):
     for info in pkgs:
         cmds = info.get('post-install')
         if cmds:
             LOG.info("Running post-install commands for package %s.",
                      info['name'])
             utils.execute_template(*cmds, params=params)
 def pre_uninstall(self):
     dbtype = self.cfg.get("db", "type")
     dbactions = DB_ACTIONS.get(dbtype)
     try:
         #TODO: maybe this should be a subclass that handles these differences
         if dbactions and dbtype == MYSQL:
             LOG.info(("Attempting to reset your mysql password so"
                       " that we can set it the next time you install."))
             pwd_cmd = dbactions.get('set_pwd')
             if pwd_cmd:
                 LOG.info("Ensuring your database is started before we operate on it.")
                 self.runtime.restart()
                 user = self.cfg.get("db", "sql_user")
                 old_pw = self.cfg.get("passwords", 'sql')
                 params = {
                     'OLD_PASSWORD': old_pw,
                     'NEW_PASSWORD': RESET_BASE_PW,
                     'USER': user,
                     }
                 cmds = [{'cmd': pwd_cmd}]
                 utils.execute_template(*cmds, params=params, shell=True)
     except IOError:
         LOG.warn(("Could not reset the database password. You might have to manually "
                   "reset the password to \"%s\" before the next install") % (RESET_BASE_PW))
         LOG.info("To aid in this check out: [%s]", " or ".join(SQL_RESET_PW_LINKS))
Exemple #3
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 %r so"
                       " that we can set it the next time you install.") %
                      (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.pw_gen.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 %r before the next install") %
                  (RESET_BASE_PW))
         utils.log_iterable(SQL_RESET_PW_LINKS,
                            logger=LOG,
                            header="To aid in this check out:")
 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)
    def _register(self):
        if self.kernel:
            LOG.info('Adding kernel %s to glance.', self.kernel)
            params = {'TOKEN': self.token, 'IMAGE_NAME': self.image_name}
            cmd = {'cmd': Image.KERNEL_FORMAT}
            with open(self.kernel) as file_:
                res = utils.execute_template(cmd,
                    params=params, stdin_fh=file_,
                    close_stdin=True)
            self.kernel_id = res[0][0].split(':')[1].strip()

        if self.initrd:
            LOG.info('Adding ramdisk %s to glance.', self.initrd)
            params = {'TOKEN': self.token, 'IMAGE_NAME': self.image_name}
            cmd = {'cmd': Image.INITRD_FORMAT}
            with open(self.initrd) as file_:
                res = utils.execute_template(cmd, params=params,
                    stdin_fh=file_, close_stdin=True)
            self.initrd_id = res[0][0].split(':')[1].strip()

        LOG.info('Adding image %s to glance.', self.image_name)
        params = {'TOKEN': self.token, 'IMAGE_NAME': self.image_name, \
                  'KERNEL_ID': self.kernel_id, 'INITRD_ID': self.initrd_id}
        cmd = {'cmd': Image.IMAGE_FORMAT}
        with open(self.image) as file_:
            utils.execute_template(cmd, params=params,
                stdin_fh=file_, close_stdin=True)
Exemple #6
0
 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.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: %s" % (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: %s" % (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)
Exemple #7
0
 def post_install(self, pkgs, params=None):
     for info in pkgs:
         cmds = info.get('post-install')
         if cmds:
             LOG.info("Running post-install commands for package %s.",
                      info['name'])
             utils.execute_template(*cmds, params=params)
 def restart(self):
     cmds = [{
         'cmd': self.distro.get_command('apache', 'restart'),
         'run_as_root': True,
     }]
     utils.execute_template(*cmds, check_exit_code=True, params={})
     return 1
Exemple #9
0
    def _register(self, image_name, location):

        # Upload the kernel, if we have one
        kernel = location.pop('kernel', None)
        kernel_id = ''
        if kernel:
            LOG.info('Adding kernel %s to glance.', kernel)
            params = dict(kernel)
            params['TOKEN'] = self.token
            params['NAME'] = "%s-vmlinuz" % (image_name)
            cmd = {'cmd': IMAGE_ADD}
            with open(params['FILE_NAME'], 'r') as fh:
                res = utils.execute_template(cmd,
                    params=params, stdin_fh=fh,
                    close_stdin=True)
            if res:
                (stdout, _) = res[0]
                kernel_id = stdout.split(':')[1].strip()

        # Upload the ramdisk, if we have one
        initrd = location.pop('ramdisk', None)
        initrd_id = ''
        if initrd:
            LOG.info('Adding ramdisk %s to glance.', initrd)
            params = dict(initrd)
            params['TOKEN'] = self.token
            params['NAME'] = "%s-initrd" % (image_name)
            cmd = {'cmd': IMAGE_ADD}
            with open(params['FILE_NAME'], 'r') as fh:
                res = utils.execute_template(cmd,
                    params=params, stdin_fh=fh,
                    close_stdin=True)
            if res:
                (stdout, _) = res[0]
                initrd_id = stdout.split(':')[1].strip()

        # Upload the root, we must have one...
        root_image = dict(location)
        LOG.info('Adding image %s to glance.', root_image)
        add_cmd = list(IMAGE_ADD)
        params = dict(root_image)
        params['TOKEN'] = self.token
        params['NAME'] = image_name
        if kernel_id:
            add_cmd += ['kernel_id=%KERNEL_ID%']
            params['KERNEL_ID'] = kernel_id
        if initrd_id:
            add_cmd += ['ramdisk_id=%INITRD_ID%']
            params['INITRD_ID'] = initrd_id
        cmd = {'cmd': add_cmd}
        with open(params['FILE_NAME'], 'r') as fh:
            res = utils.execute_template(cmd,
                params=params, stdin_fh=fh,
                close_stdin=True)
        img_id = ''
        if res:
            (stdout, _) = res[0]
            img_id = stdout.split(':')[1].strip()

        return img_id
Exemple #10
0
 def post_install(self):
     parent_result = comp.PkgInstallComponent.post_install(self)
     #extra actions to ensure we are granted access
     dbtype = self.cfg.get("db", "type")
     dbactions = DB_ACTIONS.get(dbtype)
     if dbactions and dbactions.get('grant_all'):
         #update the DB to give user 'USER'@'%' full control of the all databases:
         grant_cmd = dbactions.get('grant_all')
         params = self._get_param_map(None)
         cmds = list()
         cmds.append({
             'cmd': grant_cmd,
             'run_as_root': False,
         })
         #shell seems to be needed here
         #since python escapes this to much...
         utils.execute_template(*cmds, params=params, shell=True)
     #special mysql actions
     if dbactions and dbtype == MYSQL:
         cmd = dbactions.get('host_adjust')
         if cmd:
             sh.execute(*cmd, run_as_root=True, shell=True)
     #restart it to make sure all good
     self.runtime.restart()
     return parent_result
 def post_install(self, pkgs, installparams=None):
     pkgnames = sorted(pkgs.keys())
     for name in pkgnames:
         packageinfo = pkgs.get(name)
         postinstallcmds = packageinfo.get(settings.POST_INSTALL)
         if postinstallcmds and len(postinstallcmds):
             LOG.info("Running post-install commands for package %s." % (name))
             utils.execute_template(*postinstallcmds, params=installparams)
 def post_start(self):
     comp.PythonRuntime.post_start(self)
     if CREATE_CIDR in self.component_opts or not self.component_opts:
         LOG.info("Waiting %s seconds so that the melange server can start up before cidr range creation." % (WAIT_ONLINE_TO))
         sh.sleep(WAIT_ONLINE_TO)
         mp = dict()
         mp['CIDR_RANGE'] = self.cfg.getdefaulted('melange', 'm_mac_range', DEF_CIDR_RANGE)
         utils.execute_template(*CIDR_CREATE_CMD, params=mp)
 def start(self, name, program, *args, **kargs):
     app_dir = kargs.get('app_dir')
     params = dict()
     params['NAME'] = name + NAME_POSTFIX
     runcmd = SCREEN_MAKE + [program] + list(args)
     cmds = [{'cmd':runcmd}]
     utils.execute_template(*cmds, params=params, cwd=app_dir, **kargs)
     return None
 def _sync_db(self):
     LOG.info("Syncing keystone to database named %s", DB_NAME)
     params = dict()
     #it seems like this command only works if fully specified
     #probably a bug
     params['BINDIR'] = self.bindir
     cmds = [{'cmd': SYNC_DB_CMD}]
     utils.execute_template(*cmds, cwd=self.bindir, params=params)
Exemple #15
0
 def post_start(self):
     comp.PythonRuntime.post_start(self)
     if "create-cidr" in self.options:
         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)
def restart(distro):
    if _status(distro) != _ALIVE:
        cmds = list()
        cmds.append({"cmd": LIBVIRT_RESTART_CMD, "run_as_root": True})
        mp = dict()
        mp["SERVICE"] = SV_NAME_MAP[distro]
        utils.execute_template(*cmds, params=mp)
        LOG.info("Restarting the libvirt service, please wait %s seconds until its started." % (WAIT_ALIVE_TIME))
        time.sleep(WAIT_ALIVE_TIME)
 def restart(self):
     cmds = [{
         'cmd': self.distro.get_command('apache', 'restart'),
         'run_as_root': True,
         }]
     utils.execute_template(*cmds,
                             check_exit_code=True,
                             params={})
     return 1
Exemple #18
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(dbtype, quiet=True)

        # Set your password
        try:
            if dbactions:
                pwd_cmd = dbactions.get('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.pw_gen.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, shell=True)
        except IOError:
            LOG.warn(
                ("Couldn't set your db password. It might have already been "
                 "set by a previous process."))

        # Ensure access granted
        if dbactions:
            grant_cmd = dbactions.get('grant_all')
            if grant_cmd:
                user = self.cfg.getdefaulted("db", "sql_user", 'root')
                LOG.info(
                    "Updating the DB to give user '%s' full control of all databases."
                    % (user))
                LOG.info(
                    "Ensuring your database is started before we operate on it."
                )
                self.runtime.restart()
                params = {
                    'PASSWORD':
                    self.pw_gen.get_password("sql", PASSWORD_PROMPT),
                    'USER': user,
                }
                cmds = [{'cmd': grant_cmd}]
                # Shell seems to be needed here
                # since python escapes this to much...
                utils.execute_template(*cmds, params=params, shell=True)
 def stop(self):
     curr_status = self.status()
     if curr_status != comp.STATUS_STOPPED:
         cmds = [{
             'cmd': self.distro.get_command('apache', 'stop'),
             'run_as_root': True,
         }]
         utils.execute_template(*cmds, check_exit_code=True, params={})
         return 1
     return 0
    def _register(self, image_name, locations):

        # Upload the kernel, if we have one
        kernel = locations.get('kernel')
        kernel_id = ''
        if kernel:
            LOG.info('Adding kernel %r to glance.', kernel)
            params = {'TOKEN': self.token, 'IMAGE_NAME': image_name}
            cmd = {'cmd': KERNEL_ADD}
            with open(kernel, 'r') as fh:
                res = utils.execute_template(cmd,
                                             params=params,
                                             stdin_fh=fh,
                                             close_stdin=True)
            if res:
                (stdout, _) = res[0]
                kernel_id = stdout.split(':')[1].strip()

        # Upload the ramdisk, if we have one
        initrd = locations.get('ramdisk')
        initrd_id = ''
        if initrd:
            LOG.info('Adding ramdisk %r to glance.', initrd)
            params = {'TOKEN': self.token, 'IMAGE_NAME': image_name}
            cmd = {'cmd': INITRD_ADD}
            with open(initrd, 'r') as fh:
                res = utils.execute_template(cmd,
                                             params=params,
                                             stdin_fh=fh,
                                             close_stdin=True)
            if res:
                (stdout, _) = res[0]
                initrd_id = stdout.split(':')[1].strip()

        # Upload the root, we must have one...
        img_id = ''
        root_image = locations['image']
        LOG.info('Adding image %r to glance.', root_image)
        params = {
            'TOKEN': self.token,
            'IMAGE_NAME': image_name,
            'KERNEL_ID': kernel_id,
            'INITRD_ID': initrd_id
        }
        cmd = {'cmd': IMAGE_ADD}
        with open(root_image, 'r') as fh:
            res = utils.execute_template(cmd,
                                         params=params,
                                         stdin_fh=fh,
                                         close_stdin=True)
        if res:
            (stdout, _) = res[0]
            img_id = stdout.split(':')[1].strip()

        return img_id
def restart(distro):
    if _status(distro) != _ALIVE:
        cmds = list()
        cmds.append({
            'cmd': LIBVIRT_RESTART_CMD,
            'run_as_root': True,
        })
        mp = dict()
        mp['SERVICE'] = SV_NAME_MAP[distro]
        utils.execute_template(*cmds,
                                params=mp)
 def start(self):
     curr_status = self.status()
     if curr_status == comp.STATUS_STARTED:
         return self.restart()
     else:
         cmds = [{
             'cmd': self.distro.get_command('apache', 'start'),
             'run_as_root': True,
         }]
         utils.execute_template(*cmds, check_exit_code=True, params={})
         return 1
Exemple #23
0
def restart(distro):
    if _status(distro) != _ALIVE:
        cmds = [{
            'cmd': distro.get_command('libvirt', 'restart'),
            'run_as_root': True,
        }]
        utils.execute_template(*cmds, params={})
        LOG.info(
            "Restarting the libvirt service, please wait %s seconds until its started."
            % (WAIT_ALIVE_TIME))
        sh.sleep(WAIT_ALIVE_TIME)
 def stop(self):
     curr_status = self.status()
     if curr_status != comp.STATUS_STOPPED:
         cmds = [{
                 'cmd': self.distro.get_command('apache', 'stop'),
                 'run_as_root': True,
                 }]
         utils.execute_template(*cmds,
                                 check_exit_code=True)
         return 1
     return 0
Exemple #25
0
 def _setup_network(self):
     LOG.info("Creating your nova network to be used with instances.")
     mp = dict()
     mp['BINDIR'] = self.bindir
     mp['CFGFILE'] = sh.joinpths(self.cfgdir, API_CONF)
     mp['FLOATING_RANGE'] = self.cfg.get('nova', 'floating_range')
     mp['TEST_FLOATING_RANGE'] = self.cfg.get('nova', 'test_floating_range')
     mp['TEST_FLOATING_POOL'] = self.cfg.get('nova', 'test_floating_pool')
     mp['FIXED_NETWORK_SIZE'] = self.cfg.get('nova', 'fixed_network_size')
     mp['FIXED_RANGE'] = self.cfg.get('nova', 'fixed_range')
     #TODO this needs to be fixed for quantum!
     utils.execute_template(*NETWORK_SETUP_CMDS, params=mp, tracewriter=self.tracewriter)
 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)
 def restart(self):
     mp = dict()
     mp['SERVICE'] = APACHE_SVC_NAME[self.distro]
     cmds = list()
     cmds.append({
         'cmd': APACHE_RESTART_CMD,
         'run_as_root': True,
     })
     utils.execute_template(*cmds,
                         check_exit_code=True,
                         params=mp)
     return 1
Exemple #28
0
 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)
 def start(self):
     curr_status = self.status()
     if curr_status == comp.STATUS_STARTED:
         return self.restart()
     else:
         cmds = [{
                 'cmd': self.distro.get_command('apache', 'start'),
                 'run_as_root': True,
                 }]
         utils.execute_template(*cmds,
                 check_exit_code=True,
                 params={})
         return 1
 def stop(self):
     curr_status = self.status()
     if curr_status == comp.STATUS_STARTED:
         mp = dict()
         mp['SERVICE'] = APACHE_SVC_NAME[self.distro]
         cmds = list()
         cmds.append({
             'cmd': APACHE_STOP_CMD,
             'run_as_root': True,
         })
         utils.execute_template(*cmds, params=mp)
         return 1
     return 0
 def _setup_bridge(self):
     if not self.q_vswitch_agent or "no-ovs-bridge-init" in self.options:
         return
     bridge = self.cfg.getdefaulted("quantum", "ovs_bridge", "br-int")
     LOG.info("Fixing up ovs bridge named %s.", 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)
    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 = DB_ACTIONS.get(dbtype)

        #set your password
        try:
            #TODO: maybe this should be a subclass that handles these differences
            if dbactions and dbtype == MYSQL:
                pwd_cmd = dbactions.get('set_pwd')
                if pwd_cmd:
                    LOG.info(("Attempting to set your mysql password"
                          " just incase it wasn't set previously."))
                    LOG.info("Ensuring mysql is started.")
                    self.runtime.restart()
                    params = {
                        'NEW_PASSWORD': self.cfg.get("passwords", "sql"),
                        'USER': self.cfg.get("db", "sql_user"),
                        'OLD_PASSWORD': RESET_BASE_PW,
                        }
                    cmds = [{'cmd': pwd_cmd}]
                    utils.execute_template(*cmds, params=params, shell=True)
        except IOError:
            LOG.warn(("Couldn't set your password. It might have already been "
                       "set by a previous process."))

        #ensure access granted
        if dbactions:
            grant_cmd = dbactions.get('grant_all')
            if grant_cmd:
                user = self.cfg.get("db", "sql_user")
                LOG.info("Updating the DB to give user '%s' full control of all databases." % (user))
                LOG.info("Ensuring your database is started.")
                self.runtime.restart()
                params = {
                    'PASSWORD': self.cfg.get("passwords", "sql"),
                    'USER': user,
                }
                cmds = list()
                cmds.append({
                    'cmd': grant_cmd,
                })
                #shell seems to be needed here
                #since python escapes this to much...
                utils.execute_template(*cmds, params=params, shell=True)
 def _setup_network(self):
     LOG.info("Creating your nova network to be used with instances.")
     mp = dict()
     mp['BINDIR'] = self.bindir
     mp['CFGFILE'] = sh.joinpths(self.cfgdir, API_CONF)
     mp['FLOATING_RANGE'] = self.cfg.get('nova', 'floating_range')
     mp['TEST_FLOATING_RANGE'] = self.cfg.get('nova', 'test_floating_range')
     mp['TEST_FLOATING_POOL'] = self.cfg.get('nova', 'test_floating_pool')
     mp['FIXED_NETWORK_SIZE'] = self.cfg.get('nova', 'fixed_network_size')
     mp['FIXED_RANGE'] = self.cfg.get('nova', 'fixed_range')
     if settings.QUANTUM in self.instances:
         cmds = NETWORK_SETUP_CMDS[0:1]
     else:
         cmds = NETWORK_SETUP_CMDS
     utils.execute_template(*cmds, params=mp, tracewriter=self.tracewriter)
 def _setup_bridge(self):
     bridge = self.cfg.get("quantum", "ovs_bridge")
     if bridge:
         LOG.info("Fixing up ovs bridge named %s.", 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,
             })
         if cmds:
             utils.execute_template(*cmds, params=params)
 def start(self):
     curr_status = self.status()
     if curr_status == comp.STATUS_STARTED:
         return self.restart()
     else:
         mp = dict()
         mp['SERVICE'] = APACHE_SVC_NAME[self.distro]
         cmds = list()
         cmds.append({
             'cmd': APACHE_START_CMD,
             'run_as_root': True,
         })
         utils.execute_template(*cmds,
                 check_exit_code=True,
                 params=mp)
         return 1
 def _setup_bridge(self):
     if not self.q_vswitch_agent or \
             'no-ovs-bridge-init' in self.options:
         return
     bridge = self.cfg.getdefaulted("quantum", "ovs_bridge", 'br-int')
     LOG.info("Fixing up ovs bridge named %s.", 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)
Exemple #37
0
def drop_db(cfg, pw_gen, distro, dbname):
    dbtype = cfg.get("db", "type")
    dropcmd = distro.get_command(dbtype, 'drop_db', silent=True)
    if dropcmd:
        params = dict()
        params['PASSWORD'] = pw_gen.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)
Exemple #38
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(dbtype, quiet=True)

        # Set your password
        try:
            if dbactions:
                pwd_cmd = dbactions.get('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.pw_gen.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, shell=True)
        except IOError:
            LOG.warn(("Couldn't set your db password. It might have already been "
                       "set by a previous process."))

        # Ensure access granted
        if dbactions:
            grant_cmd = dbactions.get('grant_all')
            if grant_cmd:
                user = self.cfg.getdefaulted("db", "sql_user", 'root')
                LOG.info("Updating the DB to give user '%s' full control of all databases." % (user))
                LOG.info("Ensuring your database is started before we operate on it.")
                self.runtime.restart()
                params = {
                    'PASSWORD': self.pw_gen.get_password("sql", PASSWORD_PROMPT),
                    'USER': user,
                }
                cmds = [{'cmd': grant_cmd}]
                # Shell seems to be needed here
                # since python escapes this to much...
                utils.execute_template(*cmds, params=params, shell=True)
 def _setup_bridge(self):
     if not self.q_vswitch_agent or \
             'no-ovs-bridge-init' in self.options:
         return
     bridge = self.cfg.getdefaulted("quantum", "ovs_bridge", 'br-int')
     LOG.info("Fixing up ovs bridge named %s.", 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)
def drop_db(cfg, pw_gen, distro, dbname):
    dbtype = cfg.get("db", "type")
    dropcmd = distro.get_command(dbtype, 'drop_db', silent=True)
    if dropcmd:
        params = dict()
        params['PASSWORD'] = pw_gen.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)
 def _setup_vol_groups(self):
     LOG.info("Attempting to setup volume groups for nova volume management.")
     mp = dict()
     backing_file = self.cfg.get('nova', 'volume_backing_file')
     # check if we need to have a default backing file
     if not backing_file:
         backing_file = sh.joinpths(self.appdir, 'nova-volumes-backing-file')
     vol_group = self.cfg.get('nova', 'volume_group')
     backing_file_size = utils.to_bytes(self.cfg.get('nova', 'volume_backing_file_size'))
     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: %s" % (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: %s" % (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)
         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
         mp['DEV'] = vg_dev_result[0][0].replace('\n', '')
         utils.execute_template(*VG_CREATE_CMD, params=mp, tracewriter=self.tracewriter)
     # 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
     utils.execute_template(*RESTART_TGT_CMD, check_exit_code=False, tracewriter=self.tracewriter)
def create_db(cfg, dbname):
    dbtype = cfg.get("db", "type")
    dbactions = DB_ACTIONS.get(dbtype)
    if dbactions and dbactions.get('create_db'):
        createcmd = dbactions.get('create_db')
        params = dict()
        params['PASSWORD'] = cfg.get("passwords", "sql")
        params['USER'] = cfg.get("db", "sql_user")
        params['DB'] = dbname
        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 _load(self):
     if self._loaded:
         return
     LOG.info('Loading current glance image information.')
     params = {'TOKEN': self.token}
     cmd = {'cmd': DETAILS_SHOW}
     res = utils.execute_template(cmd, params=params)
     if res:
         (stdout, _) = res[0]
         self._parse(stdout)
     self._loaded = True
 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.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)
Exemple #45
0
def _status(distro):
    cmds = [{
        'cmd': distro.get_command('libvirt', 'status'),
        'run_as_root': True,
    }]
    result = utils.execute_template(*cmds, check_exit_code=False, params={})
    if not result or not result[0]:
        return _DEAD
    (sysout, stderr) = result[0]
    combined = str(sysout) + str(stderr)
    combined = combined.lower()
    if combined.find("running") != -1 or combined.find('start') != -1:
        return _ALIVE
    else:
        return _DEAD
 def status(self):
     cmds = [{
         'cmd': self.distro.get_command('apache', 'status'),
         'run_as_root': True,
     }]
     run_result = utils.execute_template(*cmds, check_exit_code=False)
     if not run_result or not run_result[0]:
         return comp.STATUS_UNKNOWN
     (sysout, stderr) = run_result[0]
     combined = (str(sysout) + str(stderr)).lower()
     if combined.find("is running") != -1:
         return comp.STATUS_STARTED
     elif combined.find("not running") != -1 or \
          combined.find("stopped") != -1 or \
          combined.find('unrecognized') != -1:
         return comp.STATUS_STOPPED
     else:
         return comp.STATUS_UNKNOWN
 def _sync_db(self):
     LOG.info("Syncing nova to database named %r", DB_NAME)
     mp = self._get_param_map(None)
     utils.execute_template(*DB_SYNC_CMD, params=mp)
Exemple #48
0
    if not virt_protocol:
        return False
    try:
        restart(distro)
    except excp.ProcessExecutionError, e:
        LOG.warn("Could not restart libvirt due to [%s]" % (e))
        return False
    try:
        cmds = list()
        cmds.append({
            'cmd': VIRSH_SANITY_CMD,
            'run_as_root': True,
        })
        mp = dict()
        mp['VIRT_PROTOCOL'] = virt_protocol
        utils.execute_template(*cmds, params=mp)
        return True
    except excp.ProcessExecutionError, e:
        LOG.warn(
            "Could check if libvirt was ok for protocol [%s] due to [%s]" %
            (virt_protocol, e.message))
        return False


def clear_libvirt_domains(distro, virt_type, inst_prefix):
    libvirt = _get_virt_lib()
    if not libvirt:
        LOG.warn(
            "Could not clear out libvirt domains, libvirt not available for python."
        )
        return
 def _sync_db(self):
     LOG.info("Syncing keystone to database named %s.", DB_NAME)
     params = dict()
     params['BINDIR'] = self.bin_dir
     cmds = [{'cmd': SYNC_DB_CMD}]
     utils.execute_template(*cmds, cwd=self.bin_dir, params=params)
Exemple #50
0
 def post_install(self, pkg, params=None):
     cmds = pkg.get('post-install')
     if cmds:
         LOG.info("Running post-install commands for package %r.",
                  pkg['name'])
         utils.execute_template(*cmds, params=params)
Exemple #51
0
 def _sync_db(self):
     LOG.info("Syncing the database with melange.")
     mp = dict()
     mp['BIN_DIR'] = self.bin_dir
     mp['CFG_FILE'] = sh.joinpths(self.cfg_dir, ROOT_CONF_REAL_NAME)
     utils.execute_template(*DB_SYNC_CMD, params=mp)
Exemple #52
0
 def _sync_db(self):
     LOG.info("Syncing keystone to database named %r", DB_NAME)
     mp = self._get_param_map(None)
     cmds = [{'cmd': SYNC_DB_CMD}]
     utils.execute_template(*cmds, cwd=self.bin_dir, params=mp)
Exemple #53
0
 def _sync_db(self):
     LOG.info("Syncing the database with nova.")
     mp = dict()
     mp['BIN_DIR'] = self.bin_dir
     mp['CFGFILE'] = sh.joinpths(self.cfg_dir, API_CONF)
     utils.execute_template(*DB_SYNC_CMD, params=mp)