OpenSecurity/bin/opensecurity_client_restful_server.py
changeset 31 d95fe93d7a83
parent 29 3f564e1673bb
child 46 f659d8fb57a8
     1.1 --- a/OpenSecurity/bin/opensecurity_client_restful_server.py	Mon Dec 09 14:44:41 2013 +0100
     1.2 +++ b/OpenSecurity/bin/opensecurity_client_restful_server.py	Tue Dec 10 14:04:11 2013 +0100
     1.3 @@ -50,12 +50,12 @@
     1.4  # const
     1.5  
     1.6  
     1.7 -__version__ = "0.1"
     1.8 +__version__ = "0.2"
     1.9  
    1.10  
    1.11  """All the URLs we know mapping to class handler"""
    1.12  opensecurity_urls = (
    1.13 -    '/application',             'os_application',
    1.14 +    #'/application',             'os_application',
    1.15      '/credentials',             'os_credentials',
    1.16      '/notification',            'os_notification',
    1.17      '/password',                'os_password',
    1.18 @@ -67,53 +67,53 @@
    1.19  # code
    1.20  
    1.21  
    1.22 -class os_application:
    1.23 -    """OpenSecurity '/application' handler.
    1.24 +# class os_application:
    1.25 +#
    1.26 +# PRESUMLY DEAD CODE
    1.27 +#
    1.28 +    # """OpenSecurity '/application' handler.
    1.29      
    1.30 -    This is called on GET /application?vm=VM-ID&app=APP-ID
    1.31 -    This tries to access the vm identified with the label VM-ID
    1.32 -    and launched the application identified APP-ID
    1.33 -    """
    1.34 +    # This is called on GET /application?vm=VM-ID&app=APP-ID
    1.35 +    # This tries to access the vm identified with the label VM-ID
    1.36 +    # and launched the application identified APP-ID
    1.37 +    # """
    1.38      
    1.39 -    def GET(self):
    1.40 +    # def GET(self):
    1.41          
    1.42 -        # pick the arguments
    1.43 -        args = web.input()
    1.44 +        # # pick the arguments
    1.45 +        # args = web.input()
    1.46          
    1.47 -        # we _need_ a vm
    1.48 -        if not "vm" in args:
    1.49 -            raise web.badrequest('no vm given')
    1.50 +        # # we _need_ a vm
    1.51 +        # if not "vm" in args:
    1.52 +            # raise web.badrequest('no vm given')
    1.53          
    1.54 -        # we _need_ a app
    1.55 -        if not "app" in args:
    1.56 -            raise web.badrequest('no app given')
    1.57 +        # # we _need_ a app
    1.58 +        # if not "command" in args:
    1.59 +            # raise web.badrequest('no app given')
    1.60          
    1.61 -        apps = opensecurity_server.query_apps()
    1.62 -        vms = opensecurity_server.query_vms()
    1.63 +        # # check if we do have valid vm
    1.64 +        # v = [v for v in vms if v['name'] == args.vm]
    1.65 +        # if len(v) == 0:
    1.66 +            # raise web.notfound('vm not found')
    1.67 +        # v = v[0]
    1.68          
    1.69 -        # check if we do have valid vm
    1.70 -        v = [v for v in vms if v['name'] == args.vm]
    1.71 -        if len(v) == 0:
    1.72 -            raise web.notfound('vm not found')
    1.73 -        v = v[0]
    1.74 +        # # check if we do have a valid app
    1.75 +        # a = [a for a in apps if a['name'] == args.app]
    1.76 +        # if len(a) == 0:
    1.77 +            # raise web.notfound('app not found')
    1.78 +        # a = a[0]
    1.79          
    1.80 -        # check if we do have a valid app
    1.81 -        a = [a for a in apps if a['name'] == args.app]
    1.82 -        if len(a) == 0:
    1.83 -            raise web.notfound('app not found')
    1.84 -        a = a[0]
    1.85 +        # # invoke launch with 
    1.86 +        # res = "starting: launch " + v['user'] + " " + v['ip'] + " " + a['command']
    1.87 +
    1.88 +        # launch_image = os.path.join(sys.path[0], 'launch.py')
    1.89 +        # process_command = [sys.executable, launch_image, v['user'], v['ip'], a['command']]
    1.90 +        # process = subprocess.Popen(process_command, shell = False, stdout = subprocess.PIPE)
    1.91 +        # result = process.communicate()[0]
    1.92 +        # if process.returncode != 0:
    1.93 +            # return 'Launch of application aborted.'
    1.94          
    1.95 -        # invoke launch with 
    1.96 -        res = "starting: launch " + v['user'] + " " + v['ip'] + " " + a['command']
    1.97 -
    1.98 -        launch_image = os.path.join(sys.path[0], 'launch.py')
    1.99 -        process_command = [sys.executable, launch_image, v['user'], v['ip'], a['command']]
   1.100 -        process = subprocess.Popen(process_command, shell = False, stdout = subprocess.PIPE)
   1.101 -        result = process.communicate()[0]
   1.102 -        if process.returncode != 0:
   1.103 -            return 'Launch of application aborted.'
   1.104 -        
   1.105 -        return result
   1.106 +        # return result
   1.107          
   1.108  
   1.109  class os_credentials: