예제 #1
0
    def read(self):
        #
        # If on RHEV-M the user data will be contained on the
        # floppy device in file deltacloud-user-data.txt.
        # To access it:
        #    modprobe floppy
        #    mount /dev/fd0 /media
        #    read /media/deltacloud-user-data.txt
        #
        # Note:
        # On RHEVm the deltacloud drive had been delivering the user
        # data base64 decoded at one point that changed such that the
        # deltacloud drive leaves the date base64 encoded. This
        # Code segment will handle both base64 encoded and decoded
        # user data.
        #
        # Since ':' is used as a field delimiter in the user data
        # and is not a valid base64 char, if ':' is found assume
        # the data is already base64 decoded.
        #
        #    modprobe floppy
        cmd = ['/sbin/modprobe', 'floppy']
        ret = run_cmd(cmd)
        if ret['subproc'].returncode != 0:
            raise AAError(('Failed command: \n%s \nError: \n%s') % \
                (' '.join(cmd), str(ret['err'])))

        cmd = ['/bin/mkdir', '/media']
        ret = run_cmd(cmd)
        # If /media is already there (1) or any other error (0)
        if (ret['subproc'].returncode != 1) and  \
           (ret['subproc'].returncode != 0):
            raise AAError(('Failed command: \n%s \nError: \n%s') % \
                (' '.join(cmd), str(ret['err'])))

        cmd = ['/bin/mount', '/dev/fd0', '/media']
        ret = run_cmd(cmd)
        # If /media is already mounted (32) or any other error (0)
        if (ret['subproc'].returncode != 32) and  \
           (ret['subproc'].returncode != 0):
            raise AAError(('Failed command: \n%s \nError: \n%s') % \
                (' '.join(cmd), str(ret['err'])))

        # Condfig Server (CS) address:port.
        # This could be done using "with open()" but that's not available
        # in Python 2.4 as used on RHEL5
        try:
            user_data_file = open(DELTA_CLOUD_USER_DATA, 'r')
            user_data = user_data_file.read().strip()
            user_data_file.close()
        except Exception, e:
            raise AAError('Failed accessing RHEVm user data: %s' % e)
예제 #2
0
    def read(self):
        #
        # If on RHEV-M the user data will be contained on the
        # floppy device in file deltacloud-user-data.txt.
        # To access it:
        #    modprobe floppy
        #    mount /dev/fd0 /media
        #    read /media/deltacloud-user-data.txt
        #
        # Note:
        # On RHEVm the deltacloud drive had been delivering the user
        # data base64 decoded at one point that changed such that the
        # deltacloud drive leaves the date base64 encoded. This
        # Code segment will handle both base64 encoded and decoded
        # user data.
        #
        # Since ':' is used as a field delimiter in the user data
        # and is not a valid base64 char, if ':' is found assume
        # the data is already base64 decoded.
        #
        #    modprobe floppy
        cmd = ['/sbin/modprobe', 'floppy']
        ret = run_cmd(cmd)
        if ret['subproc'].returncode != 0:
            raise AAError(('Failed command: \n%s \nError: \n%s') % \
                (' '.join(cmd), str(ret['err'])))

        cmd = ['/bin/mkdir', '/media']
        ret = run_cmd(cmd)
        # If /media is already there (1) or any other error (0)
        if (ret['subproc'].returncode != 1) and  \
           (ret['subproc'].returncode != 0):
            raise AAError(('Failed command: \n%s \nError: \n%s') % \
                (' '.join(cmd), str(ret['err'])))

        cmd = ['/bin/mount', '/dev/fd0', '/media']
        ret = run_cmd(cmd)
        # If /media is already mounted (32) or any other error (0)
        if (ret['subproc'].returncode != 32) and  \
           (ret['subproc'].returncode != 0):
            raise AAError(('Failed command: \n%s \nError: \n%s') % \
                (' '.join(cmd), str(ret['err'])))

        # Condfig Server (CS) address:port.
        # This could be done using "with open()" but that's not available
        # in Python 2.4 as used on RHEL5
        try:
            user_data_file = open(DELTA_CLOUD_USER_DATA, 'r')
            user_data = user_data_file.read().strip()
            user_data_file.close()
        except Exception, e:
            raise AAError('Failed accessing RHEVm user data: %s' % e)
예제 #3
0
    def gen_env(self):
        '''
        Description:
          Generate the os environment variables from the config params.

        Input:
          serv_name - A service name
              e.g.:
              jon_agent_config

          param_val - A parameter name&val pair. The value is base64 encoded.
              e.g.:
              jon_server_ip&MTkyLjE2OC4wLjE=

        Output:
          Set environment variables of the form:
          <name>=<value>
              e.g.:
              jon_server_ip=base64.b64decode('MTkyLjE2OC4wLjE=')
              jon_server_ip='192.168.0.1

        Raises AAError when encountering an error.

        '''
        LOGGER.debug('Invoked gen_env()')

        for param in self.params:
            var_name = '_'.join(('AUDREY_VAR', self.name, param))
            os.environ[var_name] = \
                base64.b64decode(self.params[param])

            # Get what was set and log it.
            cmd = ['/usr/bin/printenv', var_name]
            ret = run_cmd(cmd)
            LOGGER.debug(var_name + '=' + str(ret['out'].strip()))
예제 #4
0
파일: service.py 프로젝트: AsherBond/audrey
    def gen_env(self):
        '''
        Description:
          Generate the os environment variables from the config params.

        Input:
          serv_name - A service name
              e.g.:
              jon_agent_config

          param_val - A parameter name&val pair. The value is base64 encoded.
              e.g.:
              jon_server_ip&MTkyLjE2OC4wLjE=

        Output:
          Set environment variables of the form:
          <name>=<value>
              e.g.:
              jon_server_ip=base64.b64decode('MTkyLjE2OC4wLjE=')
              jon_server_ip='192.168.0.1

        Raises AAError when encountering an error.

        '''
        LOGGER.debug('Invoked gen_env()')

        for param in self.params:
            var_name = '_'.join(('AUDREY_VAR', self.name, param))
            os.environ[var_name] = \
                base64.b64decode(self.params[param])

            # Get what was set and log it.
            cmd = ['/usr/bin/printenv', var_name]
            ret = run_cmd(cmd)
            LOGGER.debug(var_name + '=' + str(ret['out'].strip()))
예제 #5
0
    def read(self):
        #
        # If on vSphere the user data will be contained on the
        # floppy device in file deltacloud-user-data.txt.
        # To access it:
        #    mount /dev/fd0 /media
        #    read /media/deltacloud-user-data.txt
        #
        # Note:
        # On vSphere the deltacloud drive had been delivering the user
        # data base64 decoded at one point that changed such that the
        # deltacloud drive leaves the date base64 encoded. This
        # Code segment will handle both base64 encoded and decoded
        # user data.
        cmd = ['/bin/mkdir', '/media']
        ret = run_cmd(cmd)
        # If /media is already there (1) or any other error (0)
        if (ret['subproc'].returncode != 1) and  \
           (ret['subproc'].returncode != 0):
            raise AAError(('Failed command: \n%s \nError: \n%s') % \
                (' '.join(cmd), str(ret['err'])))

        cmd = ['/bin/mount', '/dev/cdrom', '/media']
        ret = run_cmd(cmd)
        # If /media is already mounted (32) or any other error (0)
        if (ret['subproc'].returncode != 32) and  \
           (ret['subproc'].returncode != 0):
            raise AAError(('Failed command: \n%s \nError: \n%s') % \
                (' '.join(cmd), str(ret['err'])))

        try:
            user_data_file = open(DELTA_CLOUD_USER_DATA, 'r')
            user_data = user_data_file.read().strip()
            user_data_file.close()
        except Exception, e:
            raise AAError('Failed accessing vSphere user data file. %s' % e)
예제 #6
0
    def read(self):
        #
        # If on vSphere the user data will be contained on the
        # floppy device in file deltacloud-user-data.txt.
        # To access it:
        #    mount /dev/fd0 /media
        #    read /media/deltacloud-user-data.txt
        #
        # Note:
        # On vSphere the deltacloud drive had been delivering the user
        # data base64 decoded at one point that changed such that the
        # deltacloud drive leaves the date base64 encoded. This
        # Code segment will handle both base64 encoded and decoded
        # user data.
        cmd = ['/bin/mkdir', '/media']
        ret = run_cmd(cmd)
        # If /media is already there (1) or any other error (0)
        if (ret['subproc'].returncode != 1) and  \
           (ret['subproc'].returncode != 0):
            raise AAError(('Failed command: \n%s \nError: \n%s') % \
                (' '.join(cmd), str(ret['err'])))

        cmd = ['/bin/mount', '/dev/cdrom', '/media']
        ret = run_cmd(cmd)
        # If /media is already mounted (32) or any other error (0)
        if (ret['subproc'].returncode != 32) and  \
           (ret['subproc'].returncode != 0):
            raise AAError(('Failed command: \n%s \nError: \n%s') % \
                (' '.join(cmd), str(ret['err'])))

        try:
            user_data_file = open(DELTA_CLOUD_USER_DATA, 'r')
            user_data = user_data_file.read().strip()
            user_data_file.close()
        except Exception, e:
            raise AAError('Failed accessing vSphere user data file. %s' % e)
예제 #7
0
파일: tooling.py 프로젝트: AsherBond/audrey
    def invoke(self, service):
        '''
        Description:
            Invoke the configuration tooling for the specified services.

        Input:
            services - A list of ServiceParams objects.

        '''
        service.gen_env()
        try:
            top_level, tooling_path = self.find_tooling(service.name)
        except AAError:
            # No tooling found. Try the next service.
            return -1

        if top_level:
            pass
            # this case has been eliminated from the design spec
            # and probably will never be used.

        cmd = [tooling_path]
        cmd_dir = os.path.dirname(tooling_path)
        ret = run_cmd(cmd, cmd_dir)
        LOGGER.info('Execute Tooling command: ' + ' '.join(cmd))

        retcode = ret['subproc'].returncode
        LOGGER.info('\n\tStart Output of: %s >>>\n%s\n\t<<< End Output' % \
                (' '.join(cmd), ret['out']))
        if retcode == 0:
            # Command successed, log the output.
            LOGGER.info('return code: %s' % retcode)
        else:
            # Command failed, log the errors.
            LOGGER.error('error code: %s' % retcode)
            LOGGER.error('error msg: %s' % ret['err'])

        return retcode
예제 #8
0
    def invoke(self, service):
        '''
        Description:
            Invoke the configuration tooling for the specified services.

        Input:
            services - A list of ServiceParams objects.

        '''
        service.gen_env()
        try:
            top_level, tooling_path = self.find_tooling(service.name)
        except AAError:
            # No tooling found. Try the next service.
            return -1

        if top_level:
            pass
            # this case has been eliminated from the design spec
            # and probably will never be used.

        cmd = [tooling_path]
        cmd_dir = os.path.dirname(tooling_path)
        ret = run_cmd(cmd, cmd_dir)
        LOGGER.info('Execute Tooling command: ' + ' '.join(cmd))

        retcode = ret['subproc'].returncode
        LOGGER.info('\n\tStart Output of: %s >>>\n%s\n\t<<< End Output' % \
                (' '.join(cmd), ret['out']))
        if retcode == 0:
            # Command successed, log the output.
            LOGGER.info('return code: %s' % retcode)
        else:
            # Command failed, log the errors.
            LOGGER.error('error code: %s' % retcode)
            LOGGER.error('error msg: %s' % ret['err'])

        return retcode
예제 #9
0
파일: shell.py 프로젝트: ryanyard/audrey
 def test_fail_run_cmd(self):
     self.assertEqual("[Errno 2] No such file or directory",
         run_cmd(["notreal"])['err'])
예제 #10
0
 def test_fail_run_cmd(self):
     self.assertEqual("[Errno 2] No such file or directory",
         run_cmd(["notreal"])['err'])