Esempio n. 1
0
    def parse_cs_str(self, src, tooling):
        """
        Description:
            Parse the provides parameters text message sent from the
            Config Server.

        Input:
            The provides parameters string obtained from the Config Server.

            The delimiters will be an | and an &

            To ensure all the data was received the entire string will be
            terminated with an "|".

            This will be a continuous text string (no CR or New Line).

            Format:
            |name1&name2...&nameN|

            e.g.:
            |ipaddress&virtual|

        Returns:
            - Provides populated with param names
                  as the keys and None as the value
        """

        CSClient.validate_message(src)

        # split and prune the payload
        src = src[1:-1].split("|")
        if len(src) >= 1:
            for provides in src[0].split("&"):
                if provides:
                    self[provides] = None

        return self
Esempio n. 2
0
    def parse_cs_str(self, src, tooling):
        '''
        Description:
            Parse the provides parameters text message sent from the
            Config Server.

        Input:
            The provides parameters string obtained from the Config Server.

            The delimiters will be an | and an &

            To ensure all the data was received the entire string will be
            terminated with an "|".

            This will be a continuous text string (no CR or New Line).

            Format:
            |name1&name2...&nameN|

            e.g.:
            |ipaddress&virtual|

        Returns:
            - Provides populated with param names
                  as the keys and None as the value
        '''

        CSClient.validate_message(src)

        # split and prune the payload
        src = src[1:-1].split('|')
        if len(src) >= 1:
            for provides in src[0].split('&'):
                if provides:
                    self[provides] = None

        return self
Esempio n. 3
0
    def parse_require_config(src, tooling):
        '''
        Description:
          Parse the required config text message sent from the Config Server.

        Input:
          The required config string obtained from the Config Server,
          delimited by an | and an &

          Two tags will mark the sections of the data,
          '|service|' and  '|parameters|'

          To ensure all the data was received the entire string will be
          terminated with an "|".

          The string "|service|" will precede a service names.

          The string "|parameters|" will precede the parameters for
          the preceeding service, in the form: names&<b64 encoded values>.

        This will be a continuous text string (no CR or New Line).

          Format (repeating for each service):

          |service|<s1>|parameters|name1&<b64val>|name2&<b64val>|nameN&<b64v>|

          e.g.:
          |service|ssh::server|parameters|ssh_port&<b64('22')>
          |service|apache2::common|apache_port&<b64('8081')>|

        Returns:
            - A list of ServiceParams objects.
        '''

        services = []
        new = None

        CSClient.validate_message(src)

        # Message specific validation
        if src == '||':
            # special case indicating no required config needed.
            return []

        # split on pipe and chop of first and last, they will always be empty
        src = src.split('|')[1:-1]
        # get the indexes of the service identifiers
        srvs = deque([i for i, x in enumerate(src) if x == 'service'])
        srvs.append(len(src))

        if srvs[0] != 0:
            raise AAError(('|service| is not the first tag found. %s') % (src))

        while len(srvs) > 1:
            # rebuild a single service's cs string
            svc_str = "|%s|" % "|".join(src[srvs[0]:srvs[1]])
            name = src[srvs[0] + 1]
            if name in ['service', 'parameters'] or '&' in name:
                raise AAError('invalid service name: %s' % name)
            # instanciate the service with it's name
            svc = Service(name, tooling)
            svc.parse_configs(svc_str)
            services.append(svc)
            srvs.popleft()

        return services
Esempio n. 4
0
    def parse_require_config(src, tooling):
        '''
        Description:
          Parse the required config text message sent from the Config Server.

        Input:
          The required config string obtained from the Config Server,
          delimited by an | and an &

          Two tags will mark the sections of the data,
          '|service|' and  '|parameters|'

          To ensure all the data was received the entire string will be
          terminated with an "|".

          The string "|service|" will precede a service names.

          The string "|parameters|" will precede the parameters for
          the preceeding service, in the form: names&<b64 encoded values>.

        This will be a continuous text string (no CR or New Line).

          Format (repeating for each service):

          |service|<s1>|parameters|name1&<b64val>|name2&<b64val>|nameN&<b64v>|

          e.g.:
          |service|ssh::server|parameters|ssh_port&<b64('22')>
          |service|apache2::common|apache_port&<b64('8081')>|

        Returns:
            - A list of ServiceParams objects.
        '''

        services = []
        new = None

        CSClient.validate_message(src)

        # Message specific validation
        if src == '||':
            # special case indicating no required config needed.
            return []

        # split on pipe and chop of first and last, they will always be empty
        src = src.split('|')[1:-1]
        # get the indexes of the service identifiers
        srvs = deque([i for i,x in enumerate(src) if x == 'service'])
        srvs.append(len(src))

        if srvs[0] != 0:
            raise AAError(('|service| is not the first tag found. %s') % (src))

        while len(srvs) > 1:
            # rebuild a single service's cs string
            svc_str = "|%s|" % "|".join(src[srvs[0]:srvs[1]])
            name = src[srvs[0]+1]
            if name in ['service', 'parameters'] or '&' in name:
                raise AAError('invalid service name: %s' % name)
            # instanciate the service with it's name
            svc = Service(name, tooling)
            svc.parse_configs(svc_str)
            services.append(svc)
            srvs.popleft()

        return services