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/about/changelog.md b/docs/content/about/changelog.md index a2516b6..63a81bc 100644 --- a/docs/content/about/changelog.md +++ b/docs/content/about/changelog.md @@ -6,6 +6,12 @@ pip install -U gns3fy # Releases +## 0.5.2 + +**Enhancement:** + +- Added `restore_snapshot` to the available snapshot methods of a project + ## 0.5.1 **Fix:** 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/pyproject.toml b/pyproject.toml index 460ebc3..2179938 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,13 +1,13 @@ [tool.poetry] name = "gns3fy" -version = "0.5.1" +version = "0.5.2" description = "Python wrapper around GNS3 Server API" authors = ["David Flores "] license = "MIT" readme = "README.md" repository = "https://github.com/davidban77/gns3fy" homepage = "https://github.com/davidban77/gns3fy" -keywords = ["network", "gns3"] +keywords = ["network", "gns3", "python", "restapi"] classifiers = [ "Programming Language :: Python :: 3.7", "Programming Language :: Python :: 3.6", 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")