Example #1
0
    def __init__(self, wok_options):
        if hasattr(wok_options, "model"):
            self.model = wok_options.model
        elif wok_options.test:
            self.model = mockmodel.MockModel()
        else:
            self.model = kimchiModel.Model()

        dev_env = wok_options.environment != 'production'
        super(KimchiRoot, self).__init__(self.model, dev_env)

        for ident, node in sub_nodes.items():
            setattr(self, ident, node(self.model))

        if isinstance(self.model, kimchiModel.Model):
            vnc_ws_proxy = vnc.new_ws_proxy()
            cherrypy.engine.subscribe('exit', vnc_ws_proxy.terminate)

        self.api_schema = json.load(open(os.path.join(os.path.dirname(
                                    os.path.abspath(__file__)), 'API.json')))
        self.paths = config.kimchiPaths
        self.domain = 'kimchi'
        self.messages = messages

        make_dirs = [
            os.path.dirname(os.path.abspath(config.get_object_store())),
            os.path.abspath(config.get_distros_store()),
            os.path.abspath(config.get_screenshot_path())
        ]
        for directory in make_dirs:
            if not os.path.isdir(directory):
                os.makedirs(directory)
Example #2
0
    def _generate_thumbnail(self):
        thumbnail = os.path.join(
            config.get_screenshot_path(),
            '%s-%s.png' % (self.vm_uuid, str(uuid.uuid4())))

        self._get_test_result()
        if stream_test_result is None:
            self._watch_stream_creation(thumbnail)
        elif stream_test_result:
            try:
                self._generate_scratch(thumbnail)
            except Exception:
                wok_log.error('screenshot_creation: Unable to create '
                              'screenshot image %s.' % thumbnail)
        else:
            self._create_black_image(thumbnail)

        if os.path.getsize(thumbnail) == 0:
            self._create_black_image(thumbnail)
        else:
            im = Image.open(thumbnail)
            try:
                # Prevent Image lib from lazy load,
                # work around pic truncate validation in thumbnail generation
                im.thumbnail(self.THUMBNAIL_SIZE)
            except Exception as e:
                wok_log.warning('Image load with warning: %s.' % e)
            im.save(thumbnail, 'PNG')

        self.info['thumbnail'] = thumbnail
Example #3
0
    def __init__(self, wok_options):
        make_dirs = [
            os.path.dirname(os.path.abspath(config.get_object_store())),
            os.path.abspath(config.get_distros_store()),
            os.path.abspath(config.get_screenshot_path()),
            os.path.abspath(config.get_virtviewerfiles_path())
        ]
        for directory in make_dirs:
            if not os.path.isdir(directory):
                os.makedirs(directory)

        # When running on test mode, specify the objectstore location to
        # remove the file on server shutting down. That way, the system will
        # not suffer any change while running on test mode
        if wok_options.test and (wok_options.test is True
                                 or wok_options.test.lower() == 'true'):
            self.objectstore_loc = tempfile.mktemp()
            self.model = mockmodel.MockModel(self.objectstore_loc)

            def remove_objectstore():
                if os.path.exists(self.objectstore_loc):
                    os.unlink(self.objectstore_loc)

            cherrypy.engine.subscribe('exit', remove_objectstore)
        else:
            self.model = kimchiModel.Model()

        dev_env = wok_options.environment != 'production'
        super(Kimchi, self).__init__(self.model, dev_env)

        for ident, node in sub_nodes.items():
            setattr(self, ident, node(self.model))

        self.api_schema = json.load(
            open(
                os.path.join(os.path.dirname(os.path.abspath(__file__)),
                             'API.json')))
        self.paths = config.kimchiPaths
        self.domain = 'kimchi'
        self.messages = messages

        self.extends = {
            "/plugins/gingerbase": {
                "host-dashboard.html": "/plugins/kimchi/js/kimchi.peers.js"
            }
        }

        self.depends = ['gingerbase']

        # Some paths or URI's present in the objectstore have changed after
        # Kimchi 2.0.0 release. Check here if an upgrade in the schema and data
        # are necessary.
        if upgrade_objectstore_schema(config.get_object_store(), 'version'):
            upgrade_objectstore_data('icon', 'images', 'plugins/kimchi/')
            upgrade_objectstore_data('storagepool', '/storagepools',
                                     '/plugins/kimchi')
            upgrade_objectstore_template_disks(self.model.conn)

        # Upgrade memory data, if necessary
        upgrade_objectstore_memory()
Example #4
0
 def __init__(self, args):
     self.vm_uuid = args['uuid']
     args.setdefault(
         'thumbnail',
         os.path.join(config.get_screenshot_path(),
                      '%s-%s.png' % (self.vm_uuid, str(uuid.uuid4()))))
     self.info = args
Example #5
0
    def __init__(self, wok_options):
        if hasattr(wok_options, "model"):
            self.model = wok_options.model
        elif wok_options.test:
            self.model = mockmodel.MockModel()
        else:
            self.model = kimchiModel.Model()

        dev_env = wok_options.environment != 'production'
        super(KimchiRoot, self).__init__(self.model, dev_env)

        for ident, node in sub_nodes.items():
            setattr(self, ident, node(self.model))

        if isinstance(self.model, kimchiModel.Model):
            vnc_ws_proxy = vnc.new_ws_proxy()
            cherrypy.engine.subscribe('exit', vnc_ws_proxy.terminate)

        self.api_schema = json.load(
            open(
                os.path.join(os.path.dirname(os.path.abspath(__file__)),
                             'API.json')))
        self.paths = config.kimchiPaths
        self.domain = 'kimchi'
        self.messages = messages

        make_dirs = [
            os.path.dirname(os.path.abspath(config.get_object_store())),
            os.path.abspath(config.get_distros_store()),
            os.path.abspath(config.get_debugreports_path()),
            os.path.abspath(config.get_screenshot_path())
        ]
        for directory in make_dirs:
            if not os.path.isdir(directory):
                os.makedirs(directory)
Example #6
0
 def __init__(self, args):
     self.vm_uuid = args['uuid']
     args.setdefault('thumbnail',
                     os.path.join(config.get_screenshot_path(),
                                  '%s-%s.png' %
                                  (self.vm_uuid, str(uuid.uuid4()))))
     self.info = args
Example #7
0
    def _generate_thumbnail(self):
        thumbnail = os.path.join(config.get_screenshot_path(), '%s-%s.png' %
                                 (self.vm_uuid, str(uuid.uuid4())))

        self._get_test_result()
        if stream_test_result is None:
            self._watch_stream_creation(thumbnail)
        elif stream_test_result:
            try:
                self._generate_scratch(thumbnail)
            except:
                wok_log.error("screenshot_creation: Unable to create "
                              "screenshot image %s." % thumbnail)
        else:
            self._create_black_image(thumbnail)

        if os.path.getsize(thumbnail) == 0:
            self._create_black_image(thumbnail)
        else:
            im = Image.open(thumbnail)
            try:
                # Prevent Image lib from lazy load,
                # work around pic truncate validation in thumbnail generation
                im.thumbnail(self.THUMBNAIL_SIZE)
            except Exception as e:
                wok_log.warning("Image load with warning: %s." % e)
            im.save(thumbnail, "PNG")

        self.info['thumbnail'] = thumbnail
Example #8
0
    def __init__(self, wok_options):
        make_dirs = [
            os.path.dirname(os.path.abspath(config.get_object_store())),
            os.path.abspath(config.get_distros_store()),
            os.path.abspath(config.get_screenshot_path()),
            os.path.abspath(config.get_virtviewerfiles_path()),
        ]
        for directory in make_dirs:
            if not os.path.isdir(directory):
                os.makedirs(directory)

        # When running on test mode, specify the objectstore location to
        # remove the file on server shutting down. That way, the system will
        # not suffer any change while running on test mode
        if wok_options.test and (
            wok_options.test is True or wok_options.test.lower() == 'true'
        ):
            self.objectstore_loc = tempfile.mktemp()
            self.model = mockmodel.MockModel(self.objectstore_loc)

            def remove_objectstore():
                if os.path.exists(self.objectstore_loc):
                    os.unlink(self.objectstore_loc)

            cherrypy.engine.subscribe('exit', remove_objectstore)
        else:
            self.model = kimchiModel.Model()

        dev_env = wok_options.environment != 'production'
        super(Kimchi, self).__init__(self.model, dev_env)

        for ident, node in sub_nodes.items():
            setattr(self, ident, node(self.model))

        with open(
            os.path.join(os.path.dirname(
                os.path.abspath(__file__)), 'API.json')
        ) as fd:
            self.api_schema = json.load(fd)

        self.paths = config.kimchiPaths
        self.domain = 'kimchi'
        self.messages = messages

        # Some paths or URI's present in the objectstore have changed after
        # Kimchi 2.0.0 release. Check here if an upgrade in the schema and data
        # are necessary.
        if upgrade_objectstore_schema(config.get_object_store(), 'version'):
            upgrade_objectstore_data('icon', 'images', 'plugins/kimchi/')
            upgrade_objectstore_data(
                'storagepool', '/storagepools', '/plugins/kimchi')
            upgrade_objectstore_template_disks(self.model.conn)

        # Upgrade memory data, if necessary
        upgrade_objectstore_memory()
Example #9
0
    def __init__(self, wok_options):
        make_dirs = [
            os.path.dirname(os.path.abspath(config.get_object_store())),
            os.path.abspath(config.get_distros_store()),
            os.path.abspath(config.get_screenshot_path()),
            os.path.abspath(config.get_virtviewerfiles_path())
        ]
        for directory in make_dirs:
            if not os.path.isdir(directory):
                os.makedirs(directory)

        if hasattr(wok_options, "model"):
            self.model = wok_options.model
        elif wok_options.test:
            self.model = mockmodel.MockModel()
        else:
            self.model = kimchiModel.Model()

        dev_env = wok_options.environment != 'production'
        super(Kimchi, self).__init__(self.model, dev_env)

        for ident, node in sub_nodes.items():
            setattr(self, ident, node(self.model))

        if isinstance(self.model, kimchiModel.Model):
            ws_proxy = websocket.new_ws_proxy()
            cherrypy.engine.subscribe('exit', ws_proxy.terminate)

        self.api_schema = json.load(
            open(
                os.path.join(os.path.dirname(os.path.abspath(__file__)),
                             'API.json')))
        self.paths = config.kimchiPaths
        self.domain = 'kimchi'
        self.messages = messages

        self.extends = {
            "/plugins/gingerbase": {
                "host-dashboard.html": "/plugins/kimchi/js/kimchi.peers.js"
            }
        }

        # Some paths or URI's present in the objectstore have changed after
        # Kimchi 2.0.0 release. Check here if an upgrade in the schema and data
        # are necessary.
        if upgrade_objectstore_schema(config.get_object_store(), 'version'):
            upgrade_objectstore_data('icon', 'images', 'plugins/kimchi/')
            upgrade_objectstore_data('storagepool', '/storagepools',
                                     '/plugins/kimchi')
            upgrade_objectstore_template_disks(self.model.conn)

        # Upgrade memory data, if necessary
        upgrade_objectstore_memory()
Example #10
0
    def __init__(self, wok_options):
        make_dirs = [
            os.path.dirname(os.path.abspath(config.get_object_store())),
            os.path.abspath(config.get_distros_store()),
            os.path.abspath(config.get_screenshot_path()),
            os.path.abspath(config.get_virtviewerfiles_path())
        ]
        for directory in make_dirs:
            if not os.path.isdir(directory):
                os.makedirs(directory)

        if hasattr(wok_options, "model"):
            self.model = wok_options.model
        elif wok_options.test:
            self.model = mockmodel.MockModel()
        else:
            self.model = kimchiModel.Model()

        dev_env = wok_options.environment != 'production'
        super(Kimchi, self).__init__(self.model, dev_env)

        for ident, node in sub_nodes.items():
            setattr(self, ident, node(self.model))

        if isinstance(self.model, kimchiModel.Model):
            ws_proxy = websocket.new_ws_proxy()
            cherrypy.engine.subscribe('exit', ws_proxy.terminate)

        self.api_schema = json.load(open(os.path.join(os.path.dirname(
                                    os.path.abspath(__file__)), 'API.json')))
        self.paths = config.kimchiPaths
        self.domain = 'kimchi'
        self.messages = messages

        self.extends = {
            "/plugins/gingerbase": {
                "host-dashboard.html": "/plugins/kimchi/js/kimchi.peers.js"
            }
        }

        # Some paths or URI's present in the objectstore have changed after
        # Kimchi 2.0.0 release. Check here if an upgrade in the schema and data
        # are necessary.
        if upgrade_objectstore_schema(config.get_object_store(), 'version'):
            upgrade_objectstore_data('icon', 'images', 'plugins/kimchi/')
            upgrade_objectstore_data('storagepool', '/storagepools',
                                     '/plugins/kimchi')
            upgrade_objectstore_template_disks(self.model.conn)

        # Upgrade memory data, if necessary
        upgrade_objectstore_memory()
Example #11
0
 def _clean_extra(self, window=-1):
     """
     Clear screenshots before time specified by window,
     Clear all screenshots if window is -1.
     """
     try:
         now = time.time()
         clear_list = glob.glob(
             '%s/%s-*.png' % (config.get_screenshot_path(), self.vm_uuid))
         for f in clear_list:
             if now - os.path.getmtime(f) > window:
                 os.unlink(f)
     except OSError:
         pass
Example #12
0
 def _clean_extra(self, window=-1):
     """
     Clear screenshots before time specified by window,
     Clear all screenshots if window is -1.
     """
     try:
         now = time.time()
         clear_list = glob.glob("%s/%s-*.png" %
                                (config.get_screenshot_path(),
                                 self.vm_uuid))
         for f in clear_list:
             if now - os.path.getmtime(f) > window:
                 os.unlink(f)
     except OSError:
         pass