Skip to content

Commit 6d19183

Browse files
author
Elias Nygren
committed
allow custom OS by specifying the UUID to Storage
1 parent 868e0c1 commit 6d19183

1 file changed

Lines changed: 9 additions & 5 deletions

File tree

upcloud/tools.py

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import re
12

23
def assignIfExists(opts, default=None, **kwargs):
34
"""
@@ -31,14 +32,17 @@ class OperatingSystems:
3132
@classmethod
3233
def get_OS_UUID(cls, os):
3334
"""
34-
Validate Storage OS, return the public template UUID for server creation (Server.prepate_post_body)
35+
Validate Storage OS, return the public template UUID for server creation (Server.prepate_post_body).
36+
If the OS is a custom OS UUID, don't validate against templates.
3537
"""
3638

3739
if os in cls.templates:
3840
return cls.templates[os]
39-
else:
40-
raise Exception('Invalid OS -- valid options are: "CentOS 6.5", "CentOS 7.0", "Debian 7.8", "Ubuntu 12.04", "Ubuntu 14.04", "Windows 2003", "Windows 2008", "Windows 2012"')
4141

42+
uuid_regexp = '^[0-9a-z]{8}-[0-9a-z]{4}-[0-9a-z]{4}-[0-9a-z]{4}-[0-9a-z]{12}$'
43+
if re.search(uuid_regexp, os):
44+
return os
4245

43-
44-
46+
raise Exception('Invalid OS -- valid options are: "CentOS 6.5", "CentOS 7.0"',
47+
'"Debian 7.8", "Ubuntu 12.04", "Ubuntu 14.04", "Windows 2003"',
48+
'"Windows 2008", "Windows 2012"')

0 commit comments

Comments
 (0)