Skip to content

Commit a6c6a77

Browse files
author
Elias Nygren
authored
Merge pull request #26 from UpCloudLtd/0.3.7-devel
0.3.7 devel
2 parents 28d0c6a + 35372bf commit a6c6a77

File tree

6 files changed

+42
-15
lines changed

6 files changed

+42
-15
lines changed

setup.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,15 @@
44

55
setup(
66
name='upcloud-api',
7-
version='0.3.6',
7+
version='0.3.7',
88
description='UpCloud API Client',
99
author='Elias Nygren',
1010
author_email='[email protected]',
1111
maintainer='Elias Nygren',
1212
maintainer_email='[email protected]',
1313
url='https://github.com/UpCloudLtd/upcloud-python-api',
1414
packages=['upcloud_api', 'upcloud_api.cloud_manager'],
15-
download='https://github.com/UpCloudLtd/upcloud-python-api/tarball/v0.3.6',
15+
download='https://github.com/UpCloudLtd/upcloud-python-api/tarball/v0.3.7',
1616
license='MIT',
1717
install_requires=[
1818
'requests>=2.6.0',

test/test_server_creation.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,8 @@ def test_server_prepare_post_body_optional_attributes(self):
106106
vnc_password='my-passwd',
107107
password_delivery='email',
108108
login_user=login_user_block('upclouduser', ['this-is-a-SSH-key']),
109-
avoid_host='12345678'
109+
avoid_host='12345678',
110+
user_data='https://my.script.com/some_script.py'
110111
)
111112

112113
body = server.prepare_post_body()
@@ -125,6 +126,7 @@ def test_server_prepare_post_body_optional_attributes(self):
125126
}
126127
}
127128
assert body['server']['avoid_host'] == '12345678'
129+
assert body['server']['user_data'] == 'https://my.script.com/some_script.py'
128130

129131
@responses.activate
130132
def test_create_server(self, manager):

upcloud_api/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
from __future__ import unicode_literals
88
from __future__ import absolute_import
99

10-
__version__ = '0.3.6'
10+
__version__ = '0.3.7'
1111
__author__ = 'Elias Nygren'
1212
__author_email__ = '[email protected]'
1313
__license__ = 'MIT'

upcloud_api/ip_address.py

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ class IP_address(object):
1515
ptr_record and server are present only if /server/uuid endpoint was used.
1616
"""
1717

18-
def __init__(self, access, address, cloud_manager, family='IPv4',
18+
def __init__(self, access, cloud_manager, address=None, family='IPv4',
1919
ptr_record=None, server=None, *args, **kwargs):
2020
"""
2121
Initialize IP address with at least access and address.
@@ -73,8 +73,18 @@ def family(self): # noqa
7373
return self._family
7474

7575
@staticmethod
76-
def _create_ip_address_objs(IP_addrs, cloud_manager):
77-
IP_objs = list()
78-
for ip_addr in IP_addrs['ip_address']:
79-
IP_objs.append(IP_address(cloud_manager=cloud_manager, **ip_addr))
80-
return IP_objs
76+
def _create_ip_address_objs(ip_addresses, cloud_manager):
77+
78+
# ip-addresses might be provided as a flat array or as a following dict:
79+
# {'ip_addresses': {'ip_address': [...]}} || {'ip_address': [...]}
80+
81+
if 'ip_addresses' in ip_addresses:
82+
ip_addresses = ip_addresses['ip_addresses']
83+
84+
if 'ip_address' in ip_addresses:
85+
ip_addresses = ip_addresses['ip_address']
86+
87+
ip_address_objs = list()
88+
for ip_addr in ip_addresses:
89+
ip_address_objs.append(IP_address(cloud_manager=cloud_manager, **ip_addr))
90+
return ip_address_objs

upcloud_api/server.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ class Server(object):
4747
optional_fields = [
4848
'plan', 'core_number', 'memory_amount', 'boot_order', 'firewall', 'nic_model',
4949
'timezone', 'video_model', 'vnc_password', 'password_delivery', 'avoid_host',
50-
'login_user'
50+
'login_user', 'user_data'
5151
]
5252

5353
def __init__(self, server=None, **kwargs):
@@ -465,7 +465,7 @@ def _self_destruct():
465465
# first destroy server
466466
try_it_n_times(operation=self.destroy,
467467
expected_error_codes=['SERVER_STATE_ILLEGAL'],
468-
custom_error='stopping server failed')
468+
custom_error='destroying server failed')
469469

470470
# storages may be deleted instantly after server DELETE
471471
for storage in self.storage_devices:
@@ -481,7 +481,10 @@ def _self_destruct():
481481
self._wait_for_state_change(['stopped', 'started'])
482482

483483
if self.state == 'started':
484-
self.stop()
484+
try_it_n_times(operation=self.stop,
485+
expected_error_codes=['SERVER_STATE_ILLEGAL'],
486+
custom_error='stopping server failed')
487+
485488
self._wait_for_state_change(['stopped'])
486489

487490
if self.state == 'stopped':

upcloud_api/storage.py

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -112,12 +112,24 @@ def prepare_post_body(self, storage_title=None, storage_title_id=None):
112112

113113
@staticmethod
114114
def _create_storage_objs(storages, cloud_manager):
115-
if 'storage' in storages:
116-
storages = storages['storage']
115+
116+
# storages might be provided as a flat array or as a following dict:
117+
# {'storage_devices': {'storage_device': [...]}} || {'storage_device': [...]}
118+
119+
if 'storage_devices' in storages:
120+
storages = storages['storage_devices']
117121

118122
if 'storage_device' in storages:
119123
storages = storages['storage_device']
120124

125+
# or {'storages': {'storage': [...]}} || {'storage': [...]}
126+
127+
if 'storages' in storages:
128+
storages = storages['storages']
129+
130+
if 'storage' in storages:
131+
storages = storages['storage']
132+
121133
storage_objs = list()
122134
for storage in storages:
123135
storage_objs.append(Storage(cloud_manager=cloud_manager, **storage))

0 commit comments

Comments
 (0)