Ejemplo n.º 1
0
    def _update_local_cache_from_swift(self, swift_container, object_name):
        """
        Updates the local cache of microcontrollers and dependencies

        :param container: container name
        :param object_name: Name of the microcontroller or dependency
        """
        cache_target_path = os.path.join(self.conf["cache_dir"],
                                         self.scope, 'vertigo',
                                         swift_container)
        cache_target_obj = os.path.join(cache_target_path, object_name)

        if not os.path.exists(cache_target_path):
            os.makedirs(cache_target_path, 0o777)

        resp = make_swift_request("GET", self.account, swift_container, object_name)

        with open(cache_target_obj, 'w') as fn:
            fn.write(resp.body)

        set_object_metadata(cache_target_obj, resp.headers)
Ejemplo n.º 2
0
    def _update_cache(self, swift_container, object_name):
        """
        Updates the local cache of microcontrollers and dependencies

        :param container: container name
        :param object_name: Name of the microcontroller or dependency
        """
        cache_target_path = os.path.join(self.conf["cache_dir"],
                                         self.scope, 'vertigo',
                                         swift_container)
        cache_target_obj = os.path.join(cache_target_path, object_name)

        if not os.path.exists(cache_target_path):
            os.makedirs(cache_target_path, 0o777)

        resp = make_swift_request(
            "GET", self.account, swift_container, object_name)

        with open(cache_target_obj, 'w') as fn:
            fn.write(resp.body)

        set_object_metadata(cache_target_obj, resp.headers)
Ejemplo n.º 3
0
    def _update_from_cache(self, mc_main, swift_container, obj_name):
        """
        Updates the tenant microcontroller folder from the local cache.

        :param mc_main: main class of the microcontroller
        :param swift_container: container name (microcontroller or dependency)
        :param object_name: Name of the microcontroller or dependency
        """
        # if enter to this method means that the objects exist in cache
        cached_target_obj = os.path.join(self.conf["cache_dir"], self.scope,
                                         'vertigo', swift_container, obj_name)
        docker_target_dir = os.path.join(
            self.conf["mc_dir"], self.scope, mc_main)
        docker_target_obj = os.path.join(docker_target_dir, obj_name)
        update_from_cache = False

        if not os.path.exists(docker_target_dir):
            os.makedirs(docker_target_dir, 0o777)
            update_from_cache = True
        elif not os.path.isfile(docker_target_obj):
            update_from_cache = True
        else:
            cached_obj_metadata = get_object_metadata(cached_target_obj)
            docker_obj_metadata = get_object_metadata(docker_target_obj)

            cached_obj_tstamp = float(cached_obj_metadata['X-Timestamp'])
            docker_obj_tstamp = float(docker_obj_metadata['X-Timestamp'])

            if cached_obj_tstamp > docker_obj_tstamp:
                update_from_cache = True

        if update_from_cache:
            self.logger.info('Vertigo - Going to update from cache: ' +
                             swift_container + '/' + obj_name)
            copy2(cached_target_obj, docker_target_obj)
            metadata = get_object_metadata(cached_target_obj)
            set_object_metadata(docker_target_obj, metadata)
Ejemplo n.º 4
0
    def _update_from_cache(self, mc_main, swift_container, obj_name):
        """
        Updates the tenant microcontroller folder from the local cache.

        :param mc_main: main class of the microcontroller
        :param swift_container: container name (microcontroller or dependency)
        :param object_name: Name of the microcontroller or dependency
        """
        # if enter to this method means that the objects exist in cache
        cached_target_obj = os.path.join(self.conf["cache_dir"], self.scope,
                                         'vertigo', swift_container, obj_name)
        docker_target_dir = os.path.join(
            self.conf["mc_dir"], self.scope, mc_main)
        docker_target_obj = os.path.join(docker_target_dir, obj_name)
        update_from_cache = False

        if not os.path.exists(docker_target_dir):
            os.makedirs(docker_target_dir, 0o777)
            update_from_cache = True
        elif not os.path.isfile(docker_target_obj):
            update_from_cache = True
        else:
            cached_obj_metadata = get_object_metadata(cached_target_obj)
            docker_obj_metadata = get_object_metadata(docker_target_obj)

            cached_obj_tstamp = float(cached_obj_metadata['X-Timestamp'])
            docker_obj_tstamp = float(docker_obj_metadata['X-Timestamp'])

            if cached_obj_tstamp > docker_obj_tstamp:
                update_from_cache = True

        if update_from_cache:
            self.logger.info('Vertigo - Going to update from cache: ' +
                             swift_container + '/' + obj_name)
            copy2(cached_target_obj, docker_target_obj)
            metadata = get_object_metadata(cached_target_obj)
            set_object_metadata(docker_target_obj, metadata)