12
12
Do not edit the class manually.
13
13
""" # noqa: E501 docstring might be too long
14
14
15
+ import os
16
+
15
17
16
18
class HostConfiguration :
17
19
def __init__ (
@@ -23,7 +25,14 @@ def __init__(
23
25
server_operation_variables = None ,
24
26
ignore_operation_servers = False ,
25
27
) -> None :
26
- """Constructor"""
28
+ print (
29
+ "WARNING: STACKIT will move to a new way of specifying regions, where the region is provided\n " ,
30
+ "as a function argument instead of being set in the client configuration.\n "
31
+ "Once all services have migrated, the methods to specify the region in the client configuration "
32
+ "will be removed." ,
33
+ )
34
+ """Constructor
35
+ """
27
36
self ._base_path = "https://iaas.api.eu01.stackit.cloud"
28
37
"""Default Base url
29
38
"""
@@ -65,6 +74,7 @@ def get_host_from_settings(self, index, variables=None, servers=None):
65
74
:param index: array index of the host settings
66
75
:param variables: hash of variable and the corresponding value
67
76
:param servers: an array of host settings or None
77
+ :error: if a region is given for a global url
68
78
:return: URL based on host settings
69
79
"""
70
80
if index is None :
@@ -83,8 +93,25 @@ def get_host_from_settings(self, index, variables=None, servers=None):
83
93
84
94
url = server ["url" ]
85
95
96
+ # check if environment variable was provided for region
97
+ # if nothing was set this is None
98
+ region_env = os .environ .get ("STACKIT_REGION" )
99
+
86
100
# go through variables and replace placeholders
87
101
for variable_name , variable in server .get ("variables" , {}).items ():
102
+ # If a region is provided by the user for a global url
103
+ # return an error (except for providing via environment variable).
104
+ # The region is provided as a function argument instead of being set in the client configuration.
105
+ if (
106
+ variable_name == "region"
107
+ and (variable ["default_value" ] == "global" or variable ["default_value" ] == "" )
108
+ and region_env is None
109
+ and variables .get (variable_name ) is not None
110
+ ):
111
+ raise ValueError (
112
+ "this API does not support setting a region in the the client configuration, "
113
+ "please check if the region can be specified as a function parameter"
114
+ )
88
115
used_value = variables .get (variable_name , variable ["default_value" ])
89
116
90
117
if "enum_values" in variable and used_value not in variable ["enum_values" ]:
0 commit comments