From 5987cb9e49c0f8df838b80f68e6cc947d5383d25 Mon Sep 17 00:00:00 2001 From: David Flores Date: Tue, 1 Oct 2019 12:36:27 +0100 Subject: [PATCH 1/5] Adding keyword --- pyproject.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyproject.toml b/pyproject.toml index 460ebc3..8c35eb2 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -7,7 +7,7 @@ license = "MIT" readme = "README.md" repository = "https://github.com/davidban77/gns3fy" homepage = "https://github.com/davidban77/gns3fy" -keywords = ["network", "gns3"] +keywords = ["network", "gns3", "python"] classifiers = [ "Programming Language :: Python :: 3.7", "Programming Language :: Python :: 3.6", From a4fb6aa4f6a9a426bba3523697a4f90f4f5c897c Mon Sep 17 00:00:00 2001 From: David Flores Date: Tue, 1 Oct 2019 12:37:12 +0100 Subject: [PATCH 2/5] restapi keyword --- pyproject.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyproject.toml b/pyproject.toml index 8c35eb2..5d18f4a 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -7,7 +7,7 @@ license = "MIT" readme = "README.md" repository = "https://github.com/davidban77/gns3fy" homepage = "https://github.com/davidban77/gns3fy" -keywords = ["network", "gns3", "python"] +keywords = ["network", "gns3", "python", "restapi"] classifiers = [ "Programming Language :: Python :: 3.7", "Programming Language :: Python :: 3.6", From e2129e3b3e834a15dd8352a66540384c513c7b5e Mon Sep 17 00:00:00 2001 From: David Flores Date: Tue, 1 Oct 2019 12:52:55 +0100 Subject: [PATCH 3/5] Adding restore snapshot method --- Makefile | 4 ++-- docs/content/api_reference.md | 17 +++++++++++++++++ gns3fy/gns3fy.py | 31 +++++++++++++++++++++++++++++++ tests/test_api.py | 16 ++++++++++++++++ 4 files changed, 66 insertions(+), 2 deletions(-) diff --git a/Makefile b/Makefile index 00f5354..70489af 100644 --- a/Makefile +++ b/Makefile @@ -1,9 +1,9 @@ # Needs to be on master branch docs-publish: - cd docs; git checkout develop; mkdocs gh-deploy -m "[ci skip]" + cd docs; mkdocs gh-deploy -m "[ci skip]" docs-generate: - cd docs; git checkout develop; pydoc-markdown > content/api_reference.md + cd docs; pydoc-markdown > content/api_reference.md docs-show: cd docs; mkdocs serve diff --git a/docs/content/api_reference.md b/docs/content/api_reference.md index 228c524..580b064 100644 --- a/docs/content/api_reference.md +++ b/docs/content/api_reference.md @@ -1098,3 +1098,20 @@ Deletes a snapshot of the project - `name` or `snapshot_id` +### `Project.restore_snapshot()` + +```python +def restore_snapshot(self, name=None, snapshot_id=None) +``` + +Restore a snapshot from disk + +**Required Project instance attributes:** + +- `project_id` +- `connector` + +**Required keyword aguments:** + +- `name` or `snapshot_id` + diff --git a/gns3fy/gns3fy.py b/gns3fy/gns3fy.py index 927cfc0..6a944e9 100644 --- a/gns3fy/gns3fy.py +++ b/gns3fy/gns3fy.py @@ -1866,3 +1866,34 @@ def delete_snapshot(self, name=None, snapshot_id=None): self.connector.http_call("delete", _url) self.get_snapshots() + + def restore_snapshot(self, name=None, snapshot_id=None): + """ + Restore a snapshot from disk + + **Required Project instance attributes:** + + - `project_id` + - `connector` + + **Required keyword aguments:** + + - `name` or `snapshot_id` + """ + self._verify_before_action() + + self.get_snapshots() + + _snapshot = self.get_snapshot(name=name, snapshot_id=snapshot_id) + if not _snapshot: + raise ValueError("Snapshot not found") + + _url = ( + f"{self.connector.base_url}/projects/{self.project_id}/snapshots/" + f"{_snapshot['snapshot_id']}/restore" + ) + + self.connector.http_call("post", _url) + + # Update the whole project + self.get() diff --git a/tests/test_api.py b/tests/test_api.py index aa41d57..96c2d99 100644 --- a/tests/test_api.py +++ b/tests/test_api.py @@ -156,6 +156,12 @@ def post_put_matcher(request): resp.json = lambda: _returned resp.status_code = 201 return resp + elif request.path_url.endswith( + f"/{CPROJECT['id']}/snapshots/44e08d78-0ee4-4b8f-bad4-117aa67cb759/restore" + ): + _returned = json_api_test_project() + resp.json = lambda: _returned + resp.status_code = 201 return resp elif request.path_url.endswith(f"/{CPROJECT['id']}/nodes"): _data = request.json() @@ -1444,3 +1450,13 @@ def test_delete_snapshot(self, api_test_project): def test_error_delete_snapshot_not_found(self, api_test_project): with pytest.raises(ValueError, match="Snapshot not found"): api_test_project.delete_snapshot(snapshot_id="dummmy") + + def test_restore_snapshot(self, api_test_project): + response = api_test_project.restore_snapshot( + snapshot_id="44e08d78-0ee4-4b8f-bad4-117aa67cb759" + ) + assert response is None + + def test_error_restore_snapshot_not_found(self, api_test_project): + with pytest.raises(ValueError, match="Snapshot not found"): + api_test_project.restore_snapshot(snapshot_id="dummmy") From c10086fddd850cbafb9911d570c410aa120f375e Mon Sep 17 00:00:00 2001 From: David Flores Date: Tue, 1 Oct 2019 12:58:49 +0100 Subject: [PATCH 4/5] Bumping to version 0.5.2 --- docs/content/about/changelog.md | 6 ++++++ pyproject.toml | 2 +- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/docs/content/about/changelog.md b/docs/content/about/changelog.md index a2516b6..2e5118a 100644 --- a/docs/content/about/changelog.md +++ b/docs/content/about/changelog.md @@ -8,6 +8,12 @@ pip install -U gns3fy ## 0.5.1 +**Enhancement:** + +- Added `restore_snapshot` to the available snapshot methods of a project + +## 0.5.1 + **Fix:** - Argument specification for project snapshot methods diff --git a/pyproject.toml b/pyproject.toml index 5d18f4a..2179938 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name = "gns3fy" -version = "0.5.1" +version = "0.5.2" description = "Python wrapper around GNS3 Server API" authors = ["David Flores "] license = "MIT" From 9b104a71e9b4e1da671baf3b16957d42abbc6544 Mon Sep 17 00:00:00 2001 From: David Flores Date: Tue, 1 Oct 2019 13:00:06 +0100 Subject: [PATCH 5/5] Fixing version number --- docs/content/about/changelog.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/content/about/changelog.md b/docs/content/about/changelog.md index 2e5118a..63a81bc 100644 --- a/docs/content/about/changelog.md +++ b/docs/content/about/changelog.md @@ -6,7 +6,7 @@ pip install -U gns3fy # Releases -## 0.5.1 +## 0.5.2 **Enhancement:**