-
Notifications
You must be signed in to change notification settings - Fork 664
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
579: custom_image_host: Update custom images information when requested r=Saviq a=townsend2010 Fixes #569 Co-authored-by: Chris Townsend <[email protected]> Co-authored-by: Ricardo Abreu <[email protected]>
- Loading branch information
Showing
9 changed files
with
189 additions
and
51 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
/* | ||
* Copyright (C) 2019 Canonical, Ltd. | ||
* | ||
* This program is free software; you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation; version 3. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
* | ||
*/ | ||
|
||
#include "common_image_host.h" | ||
|
||
namespace mp = multipass; | ||
|
||
mp::CommonVMImageHost::CommonVMImageHost(std::chrono::seconds manifest_time_to_live) | ||
: manifest_time_to_live{manifest_time_to_live}, last_update{} | ||
{ | ||
} | ||
|
||
void mp::CommonVMImageHost::for_each_entry_do(const Action& action) | ||
{ | ||
update_manifests(); | ||
|
||
for_each_entry_do_impl(action); | ||
} | ||
|
||
auto mp::CommonVMImageHost::info_for_full_hash(const std::string& full_hash) -> VMImageInfo | ||
{ | ||
update_manifests(); | ||
|
||
return info_for_full_hash_impl(full_hash); | ||
} | ||
|
||
void mp::CommonVMImageHost::update_manifests() | ||
{ | ||
const auto now = std::chrono::steady_clock::now(); | ||
if ((now - last_update) > manifest_time_to_live || empty()) | ||
{ | ||
clear(); | ||
fetch_manifests(); | ||
|
||
last_update = now; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
/* | ||
* Copyright (C) 2019 Canonical, Ltd. | ||
* | ||
* This program is free software; you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation; version 3. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
* | ||
*/ | ||
|
||
#ifndef MULTIPASS_COMMON_IMAGE_HOST_H_ | ||
#define MULTIPASS_COMMON_IMAGE_HOST_H_ | ||
|
||
#include "multipass/vm_image_host.h" | ||
|
||
#include <chrono> | ||
|
||
namespace multipass | ||
{ | ||
|
||
class CommonVMImageHost : public VMImageHost | ||
{ | ||
public: | ||
CommonVMImageHost(std::chrono::seconds manifest_time_to_live); | ||
void for_each_entry_do(const Action& action) final; | ||
VMImageInfo info_for_full_hash(const std::string& full_hash) final; | ||
|
||
protected: | ||
void update_manifests(); | ||
|
||
virtual void for_each_entry_do_impl(const Action& action) = 0; | ||
virtual VMImageInfo info_for_full_hash_impl(const std::string& full_hash) = 0; | ||
virtual bool empty() const = 0; | ||
virtual void clear() = 0; | ||
virtual void fetch_manifests() = 0; | ||
|
||
private: | ||
std::chrono::seconds manifest_time_to_live; | ||
std::chrono::steady_clock::time_point last_update; | ||
|
||
}; | ||
|
||
} | ||
|
||
|
||
#endif /* MULTIPASS_COMMON_IMAGE_HOST_H_ */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.