Exemple #1
0
    def _record_state(self, client, instance, docker_id=None):
        if docker_id is None:
            container = self.get_container(client, instance)
            if container is not None:
                docker_id = container['Id']

        if docker_id is None:
            return

        cont_dir = Config.container_state_dir()

        tmp_file_path = path.join(cont_dir, 'tmp-%s' % docker_id)
        if path.exists(tmp_file_path):
            remove(tmp_file_path)

        file_path = path.join(cont_dir, docker_id)
        if path.exists(file_path):
            remove(file_path)

        if not path.exists(cont_dir):
            makedirs(cont_dir)

        with open(tmp_file_path, 'w') as outfile:
            marshaller = get_type(MARSHALLER)
            data = marshaller.to_string(instance)
            outfile.write(data)

        rename(tmp_file_path, file_path)
def state_file_exists(docker_id):
    try:
        cont_dir = Config.container_state_dir()
        file_path = path.join(cont_dir, docker_id)
        return os.path.exists(file_path)
    except:
        return False
Exemple #3
0
def state_file_exists(docker_id):
    try:
        cont_dir = Config.container_state_dir()
        file_path = path.join(cont_dir, docker_id)
        return os.path.exists(file_path)
    except:
        return False
Exemple #4
0
    def _record_state(self, client, instance, docker_id=None):
        if docker_id is None:
            container = self.get_container(client, instance)
            if container is not None:
                docker_id = container['Id']

        if docker_id is None:
            return

        cont_dir = Config.container_state_dir()

        tmp_file_path = path.join(cont_dir, 'tmp-%s' % docker_id)
        if path.exists(tmp_file_path):
            remove(tmp_file_path)

        file_path = path.join(cont_dir, docker_id)
        if path.exists(file_path):
            remove(file_path)

        if not path.exists(cont_dir):
            makedirs(cont_dir)

        with open(tmp_file_path, 'w') as outfile:
            marshaller = get_type(MARSHALLER)
            data = marshaller.to_string(instance)
            outfile.write(data)

        rename(tmp_file_path, file_path)
def remove_state_file(container):
    if container:
        try:
            cont_dir = Config.container_state_dir()
            file_path = path.join(cont_dir, container['Id'])
            if os.path.exists(file_path):
                os.remove(file_path)
        except:
            pass
Exemple #6
0
def remove_state_file(container):
    if container:
        try:
            cont_dir = Config.container_state_dir()
            file_path = path.join(cont_dir, container['Id'])
            if os.path.exists(file_path):
                os.remove(file_path)
        except:
            pass
Exemple #7
0
    def purge_state(self, client, instance):
        container = self.get_container(client, instance)
        if container is None:
            return

        docker_id = container["Id"]
        cont_dir = Config.container_state_dir()
        files = [path.join(cont_dir, "tmp-%s" % docker_id), path.join(cont_dir, docker_id)]

        for f in files:
            if path.exists(f):
                remove(f)
Exemple #8
0
    def purge_state(self, client, instance):
        container = self.get_container(client, instance)
        if container is None:
            return

        docker_id = container['Id']
        cont_dir = Config.container_state_dir()
        files = [
            path.join(cont_dir, 'tmp-%s' % docker_id),
            path.join(cont_dir, docker_id)
        ]

        for f in files:
            if path.exists(f):
                remove(f)
Exemple #9
0
    def on_startup(self):
        env = dict(os.environ)
        env['HOST_API_CATTLE_ACCESS_KEY'] = Config.access_key()
        env['HOST_API_CATTLE_SECRET_KEY'] = Config.secret_key()

        url = 'http://{0}:{1}'.format(Config.cadvisor_ip(),
                                      Config.cadvisor_port())

        background([
            'host-api', '-cadvisor-url', url, '-logtostderr=true', '-ip',
            Config.host_api_ip(), '-port',
            str(Config.host_api_port()), '-auth=true', '-host-uuid',
            DockerConfig.docker_uuid(), '-public-key',
            Config.jwt_public_key_file(), '-cattle-url',
            Config.api_url(), '-cattle-state-dir',
            Config.container_state_dir()
        ],
                   env=env)
Exemple #10
0
    def on_startup(self):
        env = dict(os.environ)
        env['HOST_API_CATTLE_ACCESS_KEY'] = Config.access_key()
        env['HOST_API_CATTLE_SECRET_KEY'] = Config.secret_key()

        url = 'http://{0}:{1}'.format(Config.cadvisor_ip(),
                                      Config.cadvisor_port())

        background(['host-api',
                    '-cadvisor-url',  url,
                    '-logtostderr=true',
                    '-ip', Config.host_api_ip(),
                    '-port', str(Config.host_api_port()),
                    '-auth=true',
                    '-host-uuid', DockerConfig.docker_uuid(),
                    '-public-key', Config.jwt_public_key_file(),
                    '-cattle-url', Config.api_url(),
                    '-cattle-state-dir', Config.container_state_dir()],
                   env=env)