Ejemplo n.º 1
0
    def get_stack_status(self):
        # split service stack id into positional components
        planet_name = self.service_id.split('/')[1]

        # acquire provider stack status
        stack_status = None
        planet = Planet(planet_name)

        # TODO/DECISION: fail silently and let context determine action or raise errors?
        # attempt to acquire stack status
        try:
            stack_id = self.stack_info[0].values()[0]['cloud']['stack_id']
            stack_status = call_cloud_api(
                planet=planet,
                stack_name=stack_id,
                action='get_instance_info',
            )
        except Exception as e:
            pass

        return stack_status
Ejemplo n.º 2
0
    def execute(self):
        # initialize service status query using skybase service registry id
        query = PlanetStateDbQuery.init_from_id(
            self.args['skybase_id'],
            query_type = PlanetStateQueryTypes.WILDCARD)

        # execute query and return standard result
        query_result = query.format_result_set(query.execute())

        # tabular output header
        service_output = '\n{0}\t\t{1}\t\t{2}\n\n'.format('ip_address', 'role_name', 'stack_name')

        # gather and format state information for each stack, role, and
        # instance ip address for query result
        for result in query_result:

            # unpack query result
            recid, instance_info = result.items()[0]
            stackname = instance_info['cloud']['stack_name']

            # TODO: performance / DRY enhancement: register planet and only init when not present
            planet_name = recid.split('/')[1]
            planet = Planet(planet_name)

            # get stack status
            stack_status = call_cloud_api(
                    planet=planet,
                    stack_name=stackname,
                    action='get_stack_status',
            )

            # report state information if stack launch complete
            stack_output = ''
            if stack_status == 'CREATE_COMPLETE':
                # call cloud provider for ip addresses
                stack_info = call_cloud_api(
                    planet=planet,
                    stack_name=stackname,
                    action='get_instance_ip',
                )
                
                # parse stack, role, instance info for ip addresses and
                # present in tabular format
                for instance_role_name, instances in stack_info.items():
                    # prepare output line for each ip address
                    for inst in instances:
                        # prepare complete line of output
                        role_ip_info = '{0}\t\t{1}\t\t{2}\n\n'.format(str(inst['private_ip_address']), instance_role_name, stackname)

                        # accumulate stack output
                        stack_output += role_ip_info
            else:
                # accumulate stack output
                stack_output += '\n\nWARNING: Stack "{0}" Status is "{1}" - no IP info \n'.format(
                    stackname, stack_status)

            # accumulate service output
            service_output = service_output + stack_output

        # prepare results
        self.result.output = service_output.strip()
        self.result.format = skytask.output_format_raw
        return self.result
Ejemplo n.º 3
0
    def execute(self):
        # initialize service status query using skybase service registry id
        query = PlanetStateDbQuery.init_from_id(
            self.args['skybase_id'], query_type=PlanetStateQueryTypes.WILDCARD)

        # execute query and return standard result
        query_result = query.format_result_set(query.execute())

        # tabular output header
        service_output = '\n{0}\t\t{1}\t\t{2}\n\n'.format(
            'ip_address', 'role_name', 'stack_name')

        # gather and format state information for each stack, role, and
        # instance ip address for query result
        for result in query_result:

            # unpack query result
            recid, instance_info = result.items()[0]
            stackname = instance_info['cloud']['stack_name']

            # TODO: performance / DRY enhancement: register planet and only init when not present
            planet_name = recid.split('/')[1]
            planet = Planet(planet_name)

            # get stack status
            stack_status = call_cloud_api(
                planet=planet,
                stack_name=stackname,
                action='get_stack_status',
            )

            # report state information if stack launch complete
            stack_output = ''
            if stack_status == 'CREATE_COMPLETE':
                # call cloud provider for ip addresses
                stack_info = call_cloud_api(
                    planet=planet,
                    stack_name=stackname,
                    action='get_instance_ip',
                )

                # parse stack, role, instance info for ip addresses and
                # present in tabular format
                for instance_role_name, instances in stack_info.items():
                    # prepare output line for each ip address
                    for inst in instances:
                        # prepare complete line of output
                        role_ip_info = '{0}\t\t{1}\t\t{2}\n\n'.format(
                            str(inst['private_ip_address']),
                            instance_role_name, stackname)

                        # accumulate stack output
                        stack_output += role_ip_info
            else:
                # accumulate stack output
                stack_output += '\n\nWARNING: Stack "{0}" Status is "{1}" - no IP info \n'.format(
                    stackname, stack_status)

            # accumulate service output
            service_output = service_output + stack_output

        # prepare results
        self.result.output = service_output.strip()
        self.result.format = skytask.output_format_raw
        return self.result
Ejemplo n.º 4
0
    def execute(self):
        # unpack args
        skybase_id = self.args.get('skybase_id')
        planet_name = self.args.get('planet_name')
        service_name = self.args.get('service_name')
        continent_tag = self.args.get('tag')
        stack_name = self.args.get('stack_name')
        verbose = self.args.get('verbose')

        # test if any query filtering args are provided to drive type of query
        no_query_args = skybase_id == planet_name == service_name == continent_tag == stack_name == None

        # initialize service status query
        if no_query_args:
            # no query filter args provided; limit output to planet list
            query = PlanetStateDbQuery(
                planet=planet_name,
                service=service_name,
                tag=continent_tag,
                stack=stack_name,
                query_type=PlanetStateQueryTypes.DRILLDOWN,
            )
        elif skybase_id:
            # query by unique skybase id
            query = PlanetStateDbQuery.init_from_id(skybase_id,)
        else:
            # query by provided arguments
            query = PlanetStateDbQuery(
                planet=planet_name,
                service=service_name,
                tag=continent_tag,
                stack=stack_name,
                query_type=PlanetStateQueryTypes.WILDCARD,
            )

        # execute query and return standard result
        query_result = query.format_result_set(query.execute())


        # extend query results if working with skybase ID or filter args that return stacks
        if not no_query_args:
            for result in query_result:
                # unpack query result
                recid, info = result.items()[0]
                stackname = info['cloud']['stack_name']

                # TODO: performance / DRY enhancement: register planet and only init when not present
                planet_name = recid.split('/')[1]
                planet = Planet(planet_name)

                # get stack status
                try:
                    stack_status = call_cloud_api(
                            planet=planet,
                            stack_name=stackname,
                            action='get_stack_status',
                    )
                except Exception as e:
                    stack_status = e.message

                # add skybase ID
                info['skybase_id'] = recid

                # add status to results
                info['cloud'].update({'stack_status': stack_status})

                # query cloud provider for current state information
                if verbose and stack_status == 'CREATE_COMPLETE':
                    instance_info = call_cloud_api(
                        planet=planet,
                        stack_name=stackname,
                        action='get_instance_info',
                    )
                    # insert roles info into query result object
                    info['roles'] = instance_info

        # execute query
        self.result.output = query_result
        self.result.format = skytask.output_format_json
        return self.result