Ejemplo n.º 1
0
    def get(self, request, format=None):

        service_name = request.query_params.get('name', None)
        action = request.query_params.get('action', None)

        #tail = TailLog(BASE_DIR+"/", 'playbook-log')

        if service_name != '':

            try:
                    
                config = {}

                campos = []

                if action == 'install':

                    SERVICE = CharmDirectory(get_path([SERVICEDIR, service_name]))

                    for k, v in SERVICE.config._data.iteritems():

                        d = {}
                        d['field_name'] = k
                        d['nombre'] = v.get('name', None)
                        d['default'] = v.get('default', None)
                        d['tipo'] = v.get('type', None)
                        d['items'] = v.get('items', None)
                        campos.append(d)

                    config['campos'] = campos
                    config['ipadd'] = ''
                    config['username'] = ''
                    config['passwd'] = ''
                    config['receta'] = service_name
                    config['action'] = ''

                if action == 'update':

                    SERVICE = parseYaml(SERVICEDIR + '/' + service_name , '/config.yaml' )

                    for k, v in SERVICE['update'].iteritems():

                        d = {}

                        d['field_name'] = k
                        d['nombre'] = v.get('name', None)
                        d['default'] = v.get('default', None)
                        d['tipo'] = v.get('type', None)
                        d['items'] = v.get('items', None)
                        campos.append(d)

                    config['campos'] = campos
                    config['username'] = ''
                    config['passwd'] = ''
                    config['receta'] = service_name
                    config['action'] = ''

                if action == 'delete':

                    SERVICE = parseYaml(SERVICEDIR + '/' + service_name , '/config.yaml' )
                    
                    d = {}
                    d['nombre'] = 'delete'
                    campos.append(d)

                    config['campos'] = campos
                    config['username'] = ''
                    config['passwd'] = ''
                    config['receta'] = service_name
                    config['action'] = ''

                return Response (config)

            except:
                
               return Response (status=status.HTTP_404_NOT_FOUND)

        return Response (status=status.HTTP_404_NOT_FOUND)
Ejemplo n.º 2
0
    def get(self, request, format=None):
        
        """
        Variables pasadas por el cliente:
        
            service_name: Nombre del servicio.
            host: Ip donde el servicio va hacer instalado.

        """
        service_name = request.query_params.get('name', None)
        host = request.query_params.get('host', None)
        
        #
        config = {}

        #Diccionario que contiene toda la info de los servicios de la receta.
        servicios = []

        config['error'] = ''

        #Verificamos que hallan pasado el nombre del servicio y el host
        if service_name and host != '':

            try:
                #Guardamos en una variable la data del servicio contenida en un yaml
                SERVICE = parseYaml(SERVICEDIR + '/' + service_name , '/config.yaml')
                
                #Procedemos a llenar la data del servicio.
                for k, v in SERVICE['query'].iteritems():
                    d = {}
                    d['service'] = k
                    d['package'] = v.get('package', None)
                    d['description'] = v.get('description', None)
                    d['status'] = 'Desintalado'
                    d['run'] = 'Offline'

                    #Comprobaremos si el servicio esta instalado.
                    query = 'ssh kds@' + str(host) + ' dpkg -l ' + str(d['package']) + ' | grep ' + str(d['package']) + ' | cut -d " " -f1'
                  
                    command_install = subprocess.Popen(query, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
                    
                    check_success, check_err = command_install.communicate()

                    if check_success.strip('\n') == 'ii':

                        d['status'] = 'Instalado'

                    if check_err != '':

                        if check_err.split(':')[0] == 'ssh':

                            config['error'] = "La ip digitada es incorrecta y/o presenta problemas."

                    servicios.append(d)

                config['services'] = servicios

            except IOError, e:

                config['error'] = "El Servicio que intenta instalar no esta disponible."

                return Response(config)