@@ -73,57 +73,68 @@ You must take this into account in your automations.
7373``` python
7474
7575import upcloud_api
76- from upcloud_api import Server, Storage, ZONE
76+ from upcloud_api import Server, Storage, ZONE , login_user_block
7777
7878manager = upcloud_api.CloudManager(' api_user' , ' password' )
79- manager.authenticate() # test credentials
79+ manager.authenticate()
80+
81+
82+ login_user = login_user_block(
83+ username = ' theuser' ,
84+ ssh_keys = [' ssh-rsa AAAAB3NzaC1yc2EAA[...]ptshi44x user@some.host' ],
85+ create_password = False
86+ )
8087
8188cluster = {
8289 ' web1' : Server(
83- core_number = 1 , # CPU cores
84- memory_amount = 512 , # RAM in MB
85- hostname = ' web1.example.com' ,
86- zone = ZONE .London, # ZONE.Helsinki and ZONE.Chicago available also
87- storage_devices = [
90+ core_number = 1 , # CPU cores
91+ memory_amount = 512 , # RAM in MB
92+ hostname = ' web1.example.com' ,
93+ zone = ZONE .London, # ZONE.Helsinki and ZONE.Chicago available also
94+ storage_devices = [
8895 # OS: Ubuntu 14.04 from template
8996 # default tier: maxIOPS, the 100k IOPS storage backend
90- Storage(os = ' Ubuntu 14.04' , size = 10 ),
97+ Storage(os = ' Ubuntu 14.04' , size = 10 ),
9198 # secondary storage, hdd for reduced cost
92- Storage(size = 100 , tier = ' hdd' )
93- ]
99+ Storage(size = 100 , tier = ' hdd' )
100+ ],
101+ login_user = login_user # user and ssh-keys
94102 ),
95103 ' web2' : Server(
96- core_number = 1 ,
97- memory_amount = 512 ,
98- hostname = ' web2.example.com' ,
99- zone = ZONE .London,
100- storage_devices = [
101- Storage(os = ' Ubuntu 14.04' , size = 10 ),
102- Storage(size = 100 , tier = ' hdd' ),
103- ]
104+ core_number = 1 ,
105+ memory_amount = 512 ,
106+ hostname = ' web2.example.com' ,
107+ zone = ZONE .London,
108+ storage_devices = [
109+ Storage(os = ' Ubuntu 14.04' , size = 10 ),
110+ Storage(size = 100 , tier = ' hdd' ),
111+ ],
112+ login_user = login_user
104113 ),
105114 ' db' : Server(
106- plan = ' 2xCPU-2GB' # use a preconfigured plan, instead of custom
107- hostname = ' db.example.com' ,
108- zone = ZONE .London,
109- storage_devices = [
110- Storage(os = ' Ubuntu 14.04' , size = 10 ),
111- Storage(size = 100 ),
112- ]
115+ plan = ' 2xCPU-2GB' , # use a preconfigured plan, instead of custom
116+ hostname = ' db.example.com' ,
117+ zone = ZONE .London,
118+ storage_devices = [
119+ Storage(os = ' Ubuntu 14.04' , size = 10 ),
120+ Storage(size = 100 ),
121+ ],
122+ login_user = login_user
113123 ),
114124 ' lb' : Server(
115- core_number = 2 ,
116- memory_amount = 1024 ,
117- hostname = ' balancer.example.com' ,
118- zone = ZONE .London,
119- storage_devices = [
120- Storage(os = ' Ubuntu 14.04' , size = 10 )
121- ]
125+ core_number = 2 ,
126+ memory_amount = 1024 ,
127+ hostname = ' balancer.example.com' ,
128+ zone = ZONE .London,
129+ storage_devices = [
130+ Storage(os = ' Ubuntu 14.04' , size = 10 )
131+ ],
132+ login_user = login_user
122133 )
123134}
124135
125136for server in cluster:
126- manager.create_server(cluster[server]) # automatically populates the Server objects with data from API
137+ manager.create_server(cluster[server]) # automatically populates the Server objects with data from API
127138
128139```
129140
@@ -161,7 +172,7 @@ server.ensure_started()
161172### Upgrade a Server
162173``` python
163174
164- server = cluster[" web1" ]
175+ server = cluster[' web1' ]
165176server.shutdown()
166177server.core_number = 4
167178server.memory_amount = 4096
0 commit comments