Ejemplo n.º 1
0
    def deleteGroup(self, *args, **kwargs):
        c = VMGroup(VMGroup.id == kwargs.get('id', 0)).delete()
        vcube.getInstance().pumpEvent({
            'eventSource': 'vcube',
            'eventType': 'VMGroupRemoved',
            'group_id': kwargs.get('id', 0)
        })

        return True
Ejemplo n.º 2
0
    def addGroup(self, *args, **kwargs):
        c = VMGroup(VMGroup.name == kwargs.get('name'))
        for attr in ['name', 'description', 'parent_id']:
            setattr(c, attr, kwargs.get(attr))
        c.save()

        vcube.getInstance().pumpEvent({
            'eventSource': 'vcube',
            'eventType': 'VMGroupAdded',
            'group': dict(c._data.copy())
        })

        return True
Ejemplo n.º 3
0
    def updateGroup(self, *args, **kwargs):

        c = VMGroup.get(VMGroup.id == kwargs.get('id', 0))

        for attr in ['name', 'description', 'parent_id']:
            if kwargs.get(attr, None) is not None:
                setattr(c, attr, kwargs.get(attr))
        c.save()

        vcube.getInstance().pumpEvent({
            'eventSource': 'vcube',
            'eventType': 'VMGroupUpdated',
            'group': dict(c._data.copy())
        })

        return True
Ejemplo n.º 4
0
    def login(self, *args, **kwargs):

        pprint.pprint(kwargs)

        user = vcube.getInstance().accounts.authenticate(
            kwargs.get('u', ''), kwargs.get('p', ''))
        if user != False:
            cherrypy.session['user'] = user
            print "OK!!!!"
            return self.getSession(_jsonout_raw=True)
        return False
Ejemplo n.º 5
0
    def deleteConnector(self, *args, **kwargs):
        
        c = Connector.get(Connector.id == kwargs.get('id',0))
        
        # Keep name for details
        name = c.name
        
        c.delete()
        
        # Tell application that a connector was removed
        vcube.getInstance().removeConnector(kwargs.get('id',0))
        

        vcube.getInstance().pumpEvent({
            'eventSource' : 'vcube',
            'eventType':'ConnectorRemoved',
            'connector_id' : kwargs.get('id', 0)
        })
        

        vcube.getInstance().logTask({
            'name': 'Remove connector',
            'user': cherrypy.session.get('user',{}).get('username','Unknown'),
            'details': 'Connector `%s` removed' %(name,),
            'category': constants.LOG_CATEGORY['CONNECTOR'],
            'connector': kwargs.get('id', 0),
            'machine': '',
            'status': constants.TASK_STATUS['COMPLETED']
            
        })


        return True
Ejemplo n.º 6
0
    def vboxAction(self, *args, **kwargs):

        cherrypy.response.headers['Content-Type'] = 'application/json'

        fn = os.path.basename(cherrypy.url())

        jsonResponse = copy.deepcopy(jsonResponseTemplate)

        startTime = time.time()

        try:

            if not kwargs.get('connector', None):
                raise Exception(
                    "No VirtualBox connector id specified (%s) %s" %
                    (fn, kwargs))

            response = vcube.getInstance().vboxAction(
                kwargs['connector'], fn, kwargs,
                cherrypy.session.get('user', {}).get('username', 'Unknown'))

            jsonResponse['data'].update(response)

        except Exception as ex:

            e = {
                'details': traceback.format_exc(),
                'error': '%s' % (str(ex), )
            }
            jsonResponse['data']['errors'].append(e)

        jsonResponse['data']['messages'].append(
            "vboxAction %s took %s seconds" % (fn, time.time() - startTime))

        if kwargs.get('_dispatcher_pprint', None):
            return pprint.pformat(jsonResponse)

        return json.dumps(jsonResponse)
Ejemplo n.º 7
0
    def machineGetScreenShot(self, *args, **kwargs):
        """
                // Let the browser cache saved state images
        $ctime = 0;
        if(strpos($_SERVER['HTTP_IF_NONE_MATCH'],'_')) {
            $ctime = preg_replace("/.*_/",str_replace('"','',$_SERVER['HTTP_IF_NONE_MATCH']));
        } else if(strpos($_ENV['HTTP_IF_NONE_MATCH'],'_')) {
            $ctime = preg_replace("/.*_/",str_replace('"','',$_ENV['HTTP_IF_NONE_MATCH']));
        } else if(strpos($_SERVER['HTTP_IF_MODIFIED_SINCE'],'GMT')) {
            $ctime = strtotime($_SERVER['HTTP_IF_MODIFIED_SINCE']);
        } else if(strpos($_ENV['HTTP_IF_MODIFIED_SINCE'],'GMT')) {
            $ctime = strtotime($_ENV['HTTP_IF_MODIFIED_SINCE']);
        }
        
        if($dlm <= $ctime) {
            if (strpos(strtolower(php_sapi_name()),'cgi') !== false) {
                Header("Status: 304 Not Modified");
            } else {
                Header("HTTP/1.0 304 Not Modified");
            }
              exit;
        }
        """
        try:

            response = vcube.getInstance().vboxAction(kwargs['connector'],
                                                      'machineGetScreenShot',
                                                      kwargs)

            cherrypy.response.headers['Content-Type'] = 'image/png'

            return base64.b64decode(response['responseData'])

        except Exception as e:
            pprint.pprint(e)
            return None
Ejemplo n.º 8
0
    def addConnector(self, *args, **kwargs):
        ex = None
        try:
            ex = Connector(Connector.name == kwargs.get('name')).get()
        except:
            pass
        if ex:
            raise Exception("A connector with that name exists")
        
        c = Connector()
        for attr in ['name','location','description']:
            setattr(c, attr, kwargs.get(attr))
        c.state = 0
        c.save()
        
        # Tell application that a connector was added
        vcube.getInstance().addConnector(dict(c._data.copy()))
        
        vcube.getInstance().pumpEvent({
            'eventSource' : 'vcube',
            'eventType':'ConnectorAdded',
            'connector_id' : c.id,
            'connector' : dict(c._data.copy())
        })

    
        vcube.getInstance().logTask({
            'name': 'Add connector',
            'user': cherrypy.session.get('user',{}).get('username','Unknown'),
            'details': 'Connector `%s` added' %(kwargs.get('name'),),
            'machine': '',
            'category': constants.LOG_CATEGORY['CONNECTOR'],
            'connector': kwargs.get('id', 0),
            'status': constants.TASK_STATUS['COMPLETED']
            
        })
    
        return True
Ejemplo n.º 9
0
    def updateConnector(self, *args, **kwargs):
        c = Connector.get(Connector.id == kwargs.get('id',0))
        for attr in ['name','location', 'description', 'state_text']:
            if kwargs.get(attr, None) is not None:
                setattr(c, attr, kwargs.get(attr))
                
        
        stateChanged = False
        if kwargs.get('state',None) is not None:
            if int(kwargs['state']) == constants.CONNECTOR_STATES['DISABLED'] or (c.state == constants.CONNECTOR_STATES['DISABLED'] and int(kwargs['state']) == constants.CONNECTOR_STATES['DISCONNECTED']):
                c.state = kwargs.get('state')
                stateChanged = True

        c.save()
        
        # Tell application that a connector was removed
        vcube.getInstance().updateConnector(dict(c._data.copy()))

        vcube.getInstance().pumpEvent({
            'eventSource' : 'vcube',
            'eventType':'ConnectorUpdated',
            'connector_id' : c.id,
            'connector' : dict(c._data.copy())
        })

        vcube.getInstance().logTask({
            'name': 'Save connector settings',
            'user': cherrypy.session.get('user',{}).get('username','Unknown'),
            'details': 'Connector `%s` configuration changed' %(c.name,) + ('. State: %s' %(constants.CONNECTOR_STATES_TEXT[c.state],) if stateChanged else ''),
            'category': constants.LOG_CATEGORY['CONNECTOR'],
            'connector': kwargs.get('id', 0),
            'machine': '',
            'status': constants.TASK_STATUS['COMPLETED']
            
        })

        return True
Ejemplo n.º 10
0
 def getVirtualMachines(self, *args, **kwargs):
     return vcube.getInstance().getVirtualMachines()
Ejemplo n.º 11
0
 def getUsers(self, *args, **kwargs):
     return vcube.getInstance().accounts.getUsers()
Ejemplo n.º 12
0
 def addGroup(self, *args, **kwargs):
     return vcube.getInstance().accounts.addGroup(kwargs)
Ejemplo n.º 13
0
 def updateGroup(self, *args, **kwargs):
     return vcube.getInstance().accounts.updateGroup(kwargs)