@@ -23,8 +23,9 @@ import (
2323var cloudConfigFS embed.FS
2424
2525const (
26- SSHUserName = "devpod"
27- SSHPort = "22"
26+ SSHUserName = "devpod"
27+ SSHPort = "22"
28+ ubuntuImageID = "117e8764-41c2-405f-aece-b53aa08b28cc"
2829)
2930
3031type Stackit struct {
@@ -128,32 +129,28 @@ func statusFromPowerStateString(state string) client.Status {
128129 return client .StatusNotFound
129130}
130131
131- func (s * Stackit ) Create (ctx context.Context , projectID , machineId string , publicKey []byte ) error {
132- availabilityZone := "eu01-1"
133- machineType := "g1.1"
134- imageID := "117e8764-41c2-405f-aece-b53aa08b28cc"
135- username := "devpod"
132+ func (s * Stackit ) Create (ctx context.Context , options * options.Options , publicKey []byte ) error {
136133 sshPublicKey := string (publicKey )
137134
138- network , err := s .createNetwork (ctx , projectID , machineId )
135+ network , err := s .createNetwork (ctx , options . ProjectID , options . MachineID )
139136 if err != nil {
140137 return err
141138 }
142139
143- userdata , err := generateUserData (username , sshPublicKey )
140+ userdata , err := generateUserData (sshPublicKey )
144141 if err != nil {
145142 return err
146143 }
147144
148145 createServerPayload := iaas.CreateServerPayload {
149- Name : & machineId ,
150- AvailabilityZone : & availabilityZone ,
151- MachineType : & machineType ,
146+ Name : & options . MachineID ,
147+ AvailabilityZone : & options . ClientOptions . Region ,
148+ MachineType : & options . Flavor ,
152149 BootVolume : & iaas.CreateServerPayloadBootVolume {
153150 DeleteOnTermination : utils .Ptr (true ),
154151 Size : utils .Ptr (int64 (64 )),
155152 Source : & iaas.BootVolumeSource {
156- Id : & imageID ,
153+ Id : utils . Ptr ( ubuntuImageID ) ,
157154 Type : utils .Ptr ("image" ),
158155 },
159156 },
@@ -165,31 +162,31 @@ func (s *Stackit) Create(ctx context.Context, projectID, machineId string, publi
165162 UserData : & userdata ,
166163 }
167164
168- server , err := s .client .CreateServer (ctx , projectID ).CreateServerPayload (createServerPayload ).Execute ()
165+ server , err := s .client .CreateServer (ctx , options . ProjectID ).CreateServerPayload (createServerPayload ).Execute ()
169166 if err != nil {
170167 return err
171168 }
172169
173- server , err = wait .CreateServerWaitHandler (ctx , s .client , projectID , * server .Id ).WaitWithContext (ctx )
170+ server , err = wait .CreateServerWaitHandler (ctx , s .client , options . ProjectID , * server .Id ).WaitWithContext (ctx )
174171 if err != nil {
175172 return err
176173 }
177174
178- publicIP , err := s .client .CreatePublicIP (ctx , projectID ).CreatePublicIPPayload (iaas.CreatePublicIPPayload {}).Execute ()
175+ publicIP , err := s .client .CreatePublicIP (ctx , options . ProjectID ).CreatePublicIPPayload (iaas.CreatePublicIPPayload {}).Execute ()
179176 if err != nil {
180177 return err
181178 }
182179
183- err = s .client .AddPublicIpToServer (ctx , projectID , * server .Id , * publicIP .Id ).Execute ()
180+ err = s .client .AddPublicIpToServer (ctx , options . ProjectID , * server .Id , * publicIP .Id ).Execute ()
184181 if err != nil {
185182 return err
186183 }
187184
188185 createSecurityGroupPayload := iaas.CreateSecurityGroupPayload {
189- Name : utils . Ptr ( machineId ) ,
186+ Name : & options . MachineID ,
190187 }
191188
192- securityGroup , err := s .client .CreateSecurityGroup (ctx , projectID ).CreateSecurityGroupPayload (createSecurityGroupPayload ).Execute ()
189+ securityGroup , err := s .client .CreateSecurityGroup (ctx , options . ProjectID ).CreateSecurityGroupPayload (createSecurityGroupPayload ).Execute ()
193190 if err != nil {
194191 return err
195192 }
@@ -206,22 +203,22 @@ func (s *Stackit) Create(ctx context.Context, projectID, machineId string, publi
206203 },
207204 }
208205
209- securityGroupRule , err := s .client .CreateSecurityGroupRule (ctx , projectID , * securityGroup .Id ).CreateSecurityGroupRulePayload (createSecurityGroupRulePayload ).Execute ()
206+ securityGroupRule , err := s .client .CreateSecurityGroupRule (ctx , options . ProjectID , * securityGroup .Id ).CreateSecurityGroupRulePayload (createSecurityGroupRulePayload ).Execute ()
210207 if err != nil {
211208 return err
212209 }
213210
214211 fmt .Println (* securityGroupRule )
215212
216- err = s .client .AddSecurityGroupToServer (ctx , projectID , * server .Id , * securityGroup .Id ).Execute ()
213+ err = s .client .AddSecurityGroupToServer (ctx , options . ProjectID , * server .Id , * securityGroup .Id ).Execute ()
217214 if err != nil {
218215 return err
219216 }
220217
221218 return nil
222219}
223220
224- func generateUserData (username string , publicKey string ) (string , error ) {
221+ func generateUserData (publicKey string ) (string , error ) {
225222 t , err := template .New ("cloud-config.yaml" ).ParseFS (cloudConfigFS , "cloud-config.yaml" )
226223 if err != nil {
227224 return "" , err
@@ -230,7 +227,7 @@ func generateUserData(username string, publicKey string) (string, error) {
230227 output := new (bytes.Buffer )
231228 if err := t .Execute (output , map [string ]string {
232229 "PublicKey" : publicKey ,
233- "Username" : username ,
230+ "Username" : SSHUserName ,
234231 }); err != nil {
235232 return "" , err
236233 }
0 commit comments