Skip to content

Commit

Permalink
add hostname in cloud-init metadata (#70)
Browse files Browse the repository at this point in the history
  • Loading branch information
tuxtof authored Aug 25, 2023
1 parent dcacd92 commit a817855
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 1 deletion.
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ replace github.com/docker/docker => github.com/docker/engine v17.12.0-ce-rc1.0.2

require (
github.com/docker/machine v0.16.2
github.com/google/uuid v1.3.1
github.com/nutanix-cloud-native/prism-go-client v0.2.0
github.com/sirupsen/logrus v1.9.3
gopkg.in/yaml.v3 v3.0.1
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,8 @@ github.com/google/go-cmp v0.5.7/go.mod h1:n+brtR0CgQNWTVd5ZUFpTBC8YFBDLK/h/bpaJ8
github.com/google/go-cmp v0.5.8 h1:e6P7q2lk1O+qJJb4BtCQXlK8vWEO8V1ZeuEdJNOqZyg=
github.com/google/go-cmp v0.5.8/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
github.com/google/uuid v1.1.2/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
github.com/google/uuid v1.3.1 h1:KjJaJ9iWZ3jOFZIf1Lqf4laDRCasjl0BCmnEGxkdLb4=
github.com/google/uuid v1.3.1/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
github.com/grpc-ecosystem/grpc-gateway v1.16.0/go.mod h1:BDjrQk3hbvj6Nolgz8mAMFbcEtjT1g+wF4CSlocrBnw=
github.com/hashicorp/errwrap v1.0.0/go.mod h1:YH+1FKiLXxHSkmPseP+kNlulaMuP3n2brvKWEqk/Jc4=
github.com/hashicorp/go-checkpoint v0.5.0/go.mod h1:7nfLNL10NsxqO4iWuW6tWW0HjZuDrwkBuEQsVcpCOgg=
Expand Down
11 changes: 10 additions & 1 deletion machine/driver/driver.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (
"github.com/docker/machine/libmachine/mcnflag"
"github.com/docker/machine/libmachine/ssh"
"github.com/docker/machine/libmachine/state"
"github.com/google/uuid"
"github.com/nutanix/docker-machine/utils"
log "github.com/sirupsen/logrus"
"gopkg.in/yaml.v3"
Expand Down Expand Up @@ -387,8 +388,16 @@ func (d *NutanixDriver) Create() error {
userdata = []byte("#cloud-config\r\nusers:\r\n - name: root\r\n ssh_authorized_keys:\r\n - " + string(pubKey))
}

// Generate metadata for the VM
specUUID := uuid.New()
cloudMetadata := fmt.Sprintf("{\"hostname\": \"%s\", \"uuid\": \"%s\"}", name, specUUID)

// Encode the metadata by base64
metadataEncoded := base64.StdEncoding.EncodeToString([]byte(cloudMetadata))

cloudInit := &v3.GuestCustomizationCloudInit{
UserData: utils.StringPtr(base64.StdEncoding.EncodeToString(userdata)),
MetaData: utils.StringPtr(metadataEncoded),
}

guestCustomization := &v3.GuestCustomization{
Expand All @@ -399,7 +408,7 @@ func (d *NutanixDriver) Create() error {

metadata.Kind = utils.StringPtr("vm")
spec.Name = utils.StringPtr(name)
spec.Description = utils.StringPtr("VM created by docker-image")
spec.Description = utils.StringPtr("VM created by Nutanix Rancher Node Driver")
res.PowerState = utils.StringPtr("ON")
spec.Resources = res
request.Metadata = metadata
Expand Down

0 comments on commit a817855

Please sign in to comment.