Skip to content

Commit

Permalink
Merge pull request #106 from UpCloudLtd/2.0.0-release
Browse files Browse the repository at this point in the history
2.0.0 release
  • Loading branch information
ajmyyra committed May 5, 2021
2 parents fc1279e + 2c8fd67 commit c77bc81
Show file tree
Hide file tree
Showing 17 changed files with 144 additions and 106 deletions.
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,7 @@ Session.vim
*~
# auto-generated tag files
tags

# virtual environments
venv
.venv
30 changes: 30 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# Changelog
All notable changes to this project will be documented in this file.

Changelog was added with version 2.0.0.

The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [Unreleased]

## [2.0.0] - 2021-05-05

Python 2 is no longer supported. This is a maintenance release without
that many added features. It was mostly done to make future development easier.

### Added
- Storage upload accepts filenames in strings and PathLike or BinaryIO variables.
- Code style is now guarded by Black, flake8, isort etc.
- Improved documentation and its examples, especially regarding server creation and storage uploads.

### Changed
- Huge amount of fixups in project tests, style and imports by [akx](https://github.com/akx). Thank you! :heart:
- Zone default from storage creation has been removed, making zone a required variable with `create_storage()`.
- Passwords for server user are not created by default if SSH keys are provided.
- Tests and deployments moved fully from CircleCI to GitHub Actions.
- Fixed storage upload not reading the file into memory before uploading.
- Moved to fully using setup.cfg instead of requirements.txt.

### Removed
- Python 2 support.
84 changes: 41 additions & 43 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,44 +5,46 @@
[![PyPI version](https://badge.fury.io/py/upcloud-api.svg)](https://badge.fury.io/py/upcloud-api)
[![License](https://img.shields.io/badge/license-MIT-green.svg)](https://github.com/UpCloudLtd/upcloud-python-api/blob/master/LICENSE)

OOP-based api client for [UpCloud's API](https://developers.upcloud.com/1.3/). Features most of the API's functionality and some convenience functions that combine several API endpoints and logic.
OOP-based API client for [UpCloud's API](https://developers.upcloud.com/1.3/). Includes most of the API
functionality and some convenience functions that combine several API endpoints and logic.

Please test all of your use cases thoroughly before actual production use. Using a separate UpCloud account for testing / developing the client is recommended.
Please test all of your use cases thoroughly before actual production use. Using a separate UpCloud account for
testing / developing the client is recommended.

## Installation

``` bash
pip install upcloud-api
```

Alternatively, if you want the newest master or a devel branch - clone the project and run:
Alternatively, if you want the newest (possibly not yet released) stuff, clone the project and run:

``` bash
python setup.py install
```

### Supported Python in API v2.0.0
### Supported Python versions in API v2.0.0

- Python 3.6
- Python 3.7
- Python 3.8
- Python 3.9
- PyPy3

**We don't recommend using Python 2:**
**Python 2 has been deprecated**

- Python 2.7 is supported in API < v2.0.0
- Python 2.7 is supported in older API versions (< v2.0.0), still available in [PyPI](https://pypi.org/project/upcloud-api/1.0.1/).

## Changelog

- See the [Releases page](https://github.com/UpCloudLtd/upcloud-python-api/releases)
- Changelog is available [in its own file](CHANGELOG.md), starting from version 2.0.0.

## Usage

Note that the API finishes the request before the server is shutdown. Poll the server details to monitor server status.
You must take this into account in your automations.
More usage examples are available under [docs/]. If there's a specific thing you're interested in,
but are not able to get working, please [contact UpCloud support](https://upcloud.com/contact/).

### Defining and creating Servers
### Defining and creating servers

```python

Expand All @@ -61,22 +63,21 @@ login_user = login_user_block(

cluster = {
'web1': Server(
core_number=1, # CPU cores
memory_amount=1024, # RAM in MB
plan='2xCPU-4GB',
hostname='web1.example.com',
zone='uk-lon1', # All available zones with ids can be retrieved by using manager.get_zones()
storage_devices=[
# OS: 01000000-0000-4000-8000-000030200200, all available os templates can be retrieved by calling manager.get_templates()
# OS: template storage UUID, all available os templates can be retrieved by calling manager.get_templates()
# Note: the storage os template uuid:s will change when OS is updated. So check that the UUID is correct
# default tier: maxIOPS, the 100k IOPS storage backend
Storage(os='01000000-0000-4000-8000-000030200200', size=10),
# secondary storage, hdd for reduced cost
# secondary storage, hdd for reduced speed & cost
Storage(size=100, tier='hdd')
],
login_user=login_user # user and ssh-keys
),
'web2': Server(
core_number=1,
plan='2xCPU-4GB',
memory_amount=1024,
hostname='web2.example.com',
zone='uk-lon1',
Expand All @@ -87,7 +88,9 @@ cluster = {
login_user=login_user
),
'db': Server(
plan='2xCPU-4GB', # use a preconfigured plan, instead of custom
# use custom resources, instead of a plan
core_number=12, # CPU cores
memory_amount=49152, # RAM in MB
hostname='db.example.com',
zone='uk-lon1',
storage_devices=[
Expand All @@ -97,8 +100,7 @@ cluster = {
login_user=login_user
),
'lb': Server(
core_number=2,
memory_amount=1024,
plan='2xCPU-4GB',
hostname='balancer.example.com',
zone='uk-lon1',
storage_devices=[
Expand All @@ -109,7 +111,7 @@ cluster = {
}

for server in cluster:
manager.create_server(cluster[server]) # automatically populates the Server objects with data from API
manager.create_server(cluster[server]) # creates all server objects defined in cluster

```

Expand Down Expand Up @@ -156,20 +158,19 @@ server.start()

```

### Clone a server
### Clone a new server from existing storage

Cloning is done by giving existing storage uuid to storage_devices. Note that size of the storage
must be defined and must be at least same size than storage being cloned.
must be defined and must be at least the same size as the storage being cloned.

```python
clone = Server(
core_number=1,
memory_amount=1024,
plan='2xCPU-4GB',
hostname='cloned.server',
zone='fi-hel1',
storage_devices=[
Storage(
uuid='012bea57-0f70-4194-82d0-b3d25f4a018b',
uuid='012bea57-0f70-4154-84d0-b3d25f4a018b',
size=50 # size must be defined and it has to be at least same size than storage being cloned
),
]
Expand All @@ -190,14 +191,14 @@ server.to_dict()

```

### GET resources
### Get resources

```python

servers = manager.get_servers()
server1 = manager.get_server(UUID) # e.g servers[0].uuid
server1 = manager.get_server(uuid) # e.g servers[0].uuid
storages = manager.get_storages()
storage1 = manager.get_storage(UUID) # e.g server1.storage_devices[0].uuid
storage1 = manager.get_storage(uuid) # e.g server1.storage_devices[0].uuid
ip_addrs = manager.get_ips()
ip_addr = manager.get_ip(address) # e.g server1.ip_addresses[0].address

Expand All @@ -209,39 +210,36 @@ Set up environment and install dependencies:

``` bash
# run at project root, python3 and virtualenv must be installed
virtualenv ENV
source ENV/bin/activate
pip install -r requirements-dev.txt
virtualenv venv
source venv/bin/activate
```

Install the package in editable mode, as mentioned in
[https://docs.pytest.org/en/stable/goodpractices.html](https://docs.pytest.org/en/stable/goodpractices.html)
Install the package in editable mode.

```python
```bash
# run at project root
pip install -e .
```

Tests located in `project_root/test/` directory. Run with:
Tests are located under `test/`. Run with:

```python
```bash
py.test test/
```

To test against all supported python versions, run:

```python
```bash
tox
```

To check for possible vulnerabilities in python packages, run:

```python
safety check
```

The project also supplies a small test suite to test against the live API at `test/live_test.py`. This suite is NOT run with `py.test` as it will permanently remove all resources related to an account. It should only be run with a throwaway dev-only account when preparing for a new release. It is not shipped with PyPI releases. See source code on how to run the live tests.
The project also supplies a small test suite to test against the live API at `test/live_test.py`.
This suite is NOT run with `py.test` as it will permanently remove all resources related to an account.
It should only be run with a throwaway dev-only account when preparing for a new release. It is not shipped with
PyPI releases. See source code on how to run the live test.

## Bugs, Issues, Problems, Ideas

Feel free to open a new issue : )
Please report issues and features requests through
[the issues page](https://github.com/UpCloudLtd/upcloud-python-api/issues).
5 changes: 2 additions & 3 deletions docs/CloudManager.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,14 @@ Default timeout is 10.
```python

# create manager and form a token
manager = CloudManager("api-username", "password", timeout=15) # default timeout is 10
manager = CloudManager("api-username", "password")

```

# Account / Authentication

```python

# test token
manager.authenticate() # alias: get_account()
manager.get_account()

Expand Down Expand Up @@ -58,6 +57,6 @@ List the possible server CPU-ram configurations.

```python

manager.get_server_sizes
manager.get_server_sizes()

```
7 changes: 0 additions & 7 deletions docs/Firewall.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,4 @@
The code examples use the following:

```python
import upcloud_api
from upcloud_api import FirewallRule

manager = upcloud_api.CloudManager("username", "password")
```

# About

Expand Down
6 changes: 3 additions & 3 deletions docs/IP-address.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ The only updateable attribute is the `ptr_record`.

## List / Get

CloudManager returns IP-address objects.
CloudManager returns IPAddress objects.

```python

Expand All @@ -28,7 +28,7 @@ manager.get_ip("185.20.31.125")

## Create

The new IP-address must be attached to a server and has a random address.
A new IPAddress must be attached to a server and has a random address.

```python

Expand All @@ -51,7 +51,7 @@ server.add_ip("IPv6")

## Update

At the moment only the ptr_record (reverse DNS) of an IP can be changed.
At the moment only the ptr_record (reverse DNS) of an IP address can be changed.

```python

Expand Down
14 changes: 3 additions & 11 deletions docs/Server.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,4 @@
The examples use the following:
```python
import upcloud_api
from upcloud_api import Server
from upcloud_api import Storage

manager = upcloud_api.CloudManager("username", "password")
```

# Start / Stop / Restart

Expand Down Expand Up @@ -54,16 +47,15 @@ server = Server(
hostname = "web1.example.com",
zone = 'uk-lon1',
storage_devices = [
Storage(os = "01000000-0000-4000-8000-000030060200", size=10),
Storage(os = "01000000-0000-4000-8000-000030200200", size=10),
Storage(size=10, tier="hdd")
])

manager.create_server( server )

```

Currently available Storage operating systems are the following UpCloud public templates:
Valid Operating Systems cam be retrieved with 'manager.get_templates()'. More information on this method can be found in storage_mixin documentation.
Currently available operating system templates can be retrieved with 'manager.get_templates()'. More information on this method can be found in storage_mixin documentation.

Please refer to the [API documentation](https://www.upcloud.com/static/downloads/upcloud-apidoc-1.1.1.pdf) for the allowed Server attributes.

Expand Down Expand Up @@ -124,7 +116,7 @@ server.remove_ip(IP)

## Destroy

Destroys the Server instance and its IP-addresses. However, does not destroy the Storages.
Destroys the Server instance and its IP addresses. However, it does not destroy the Storages.

```python

Expand Down
Loading

0 comments on commit c77bc81

Please sign in to comment.