Skip to content

Commit

Permalink
Bumping to version 0.5.2
Browse files Browse the repository at this point in the history
  • Loading branch information
davidban77 committed Oct 1, 2019
2 parents 3c6faee + 9b104a7 commit c9c2b17
Show file tree
Hide file tree
Showing 6 changed files with 74 additions and 4 deletions.
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
@@ -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
Expand Down
6 changes: 6 additions & 0 deletions docs/content/about/changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:**
Expand Down
17 changes: 17 additions & 0 deletions docs/content/api_reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`

31 changes: 31 additions & 0 deletions gns3fy/gns3fy.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
4 changes: 2 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -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 <davidflores7_8@hotmail.com>"]
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",
Expand Down
16 changes: 16 additions & 0 deletions tests/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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")

0 comments on commit c9c2b17

Please sign in to comment.