@@ -225,7 +225,7 @@ func registerWithMAAS(maasEndpoint, maasAPIKey, systemID, nodeIP, trustPassword,
225225 profile := "ds"
226226 // Non-interactive login (idempotent)
227227 _ = runCmd ("maas" , []string {"login" , profile , maasEndpoint , maasAPIKey })
228- args := []string {profile , "vm-hosts" , "create" , "type=lxd" , fmt .Sprintf ("power_address=%s" , wantHost ), fmt .Sprintf ("password=%s" , trustPassword ), fmt .Sprintf ("name=%s" , hostName )}
228+ args := []string {profile , "vm-hosts" , "create" , "type=lxd" , fmt .Sprintf ("power_address=%s" , wantHost ), fmt .Sprintf ("password=%s" , trustPassword ), fmt .Sprintf ("name=%s" , hostName ), "project=maas" }
229229 // Do not pass zone/pool on create
230230 if err := runCmd ("maas" , args ); err != nil {
231231 return fmt .Errorf ("maas cli create failed: %w" , err )
@@ -242,6 +242,8 @@ func registerWithMAAS(maasEndpoint, maasAPIKey, systemID, nodeIP, trustPassword,
242242 if trustPassword != "" {
243243 params .Set ("password" , trustPassword )
244244 }
245+ // Set only project to 'maas' per request
246+ params .Set ("project" , "maas" )
245247 if _ , err := client .VMHosts ().Create (ctx , params ); err != nil {
246248 return fmt .Errorf ("create vm host: %w" , err )
247249 }
@@ -414,12 +416,18 @@ func main() {
414416 }
415417
416418 if actionStr == "register" || actionStr == "both" {
417- // Build a stable host name using MAAS system-id
419+ // Build a stable host name using MAAS system-id and node hostname
418420 systemID , sErr := extractSystemIDFromNodeName (nodeName )
419421 if sErr != nil {
420422 log .Fatalf ("Failed to extract system ID from node name: %v" , sErr )
421423 }
422- hostName := fmt .Sprintf ("lxd-host-%s" , systemID )
424+ hn := nodeName
425+ if hn == "" {
426+ if osHN , _ := os .Hostname (); osHN != "" {
427+ hn = osHN
428+ }
429+ }
430+ hostName := fmt .Sprintf ("lxd-host-%s-%s" , hn , systemID )
423431 if err := registerWithMAAS (maasEndpoint , maasAPIKey , systemID , nodeIP , trustPassword , zone , resourcePool , hostName ); err != nil {
424432 log .Fatalf ("Failed to register LXD host in MAAS: %v" , err )
425433 }
0 commit comments