Skip to content

Commit

Permalink
upload image only to dedicated PE Cluster
Browse files Browse the repository at this point in the history
  • Loading branch information
wolfganghuse committed Jul 18, 2022
1 parent 70e74a0 commit 13f5845
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 6 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -58,4 +58,4 @@ Temporary Items
.apdisk

### VisualStudioCode ###
.vscode/*
.vscode/*
28 changes: 24 additions & 4 deletions builder/nutanix/driver.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ type Driver interface {
//GetImage(string) (*nutanixImage, error)
GetHost(string) (*nutanixHost, error)
PowerOff(string) error
UploadImage(string) (*nutanixImage, error)
UploadImage(string, VmConfig) (*nutanixImage, error)
DeleteImage(string) error
SaveVMDisk(string, string) (*nutanixImage, error)
WaitForShutdown(string, <-chan struct{}) bool
Expand Down Expand Up @@ -423,8 +423,8 @@ func (d *NutanixDriver) Delete(vmUUID string) error {
return nil
}

//UploadImage (string) (*nutanixImage, error)
func (d *NutanixDriver) UploadImage(imagePath string) (*nutanixImage, error) {
//UploadImage (string, VmConfig) (*nutanixImage, error)
func (d *NutanixDriver) UploadImage(imagePath string, vm VmConfig) (*nutanixImage, error) {
configCreds := client.Credentials{
URL: fmt.Sprintf("%s:%d", d.ClusterConfig.Endpoint, d.ClusterConfig.Port),
Endpoint: d.ClusterConfig.Endpoint,
Expand All @@ -441,10 +441,29 @@ func (d *NutanixDriver) UploadImage(imagePath string) (*nutanixImage, error) {

_, file := path.Split(imagePath)

cluster := &v3.ClusterIntentResponse{}
if vm.ClusterUUID != "" {
cluster, err = conn.V3.GetCluster(vm.ClusterUUID)
if err != nil {
return nil, fmt.Errorf("cluster not found %s", vm.ClusterUUID)
}
} else if vm.ClusterName != "" {
cluster, err = findClusterByName(conn, vm.ClusterName)
if err != nil {
return nil, fmt.Errorf("subnet not found %s", vm.ClusterName)
}
}


refvalue := BuildReferenceValue(*cluster.Metadata.UUID, "cluster")
InitialPlacementRef := []*v3.ReferenceValues {refvalue}
req := &v3.ImageIntentInput{
Spec: &v3.Image{
Name: &file,
Resources: &v3.ImageResources{},
Resources: &v3.ImageResources{
ImageType: StringPtr("ISO_IMAGE"),
InitialPlacementRefList: InitialPlacementRef,
},
},
Metadata: &v3.Metadata{
Kind: StringPtr("image"),
Expand Down Expand Up @@ -617,6 +636,7 @@ func (d *NutanixDriver) SaveVMDisk(diskUUID string, imageName string) (*nutanixI
if err != nil {
return nil, err
}

req := &v3.ImageIntentInput{
Spec: &v3.Image{
Name: &imageName,
Expand Down
2 changes: 1 addition & 1 deletion builder/nutanix/step_build_vm.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ func (s *stepBuildVM) Run(ctx context.Context, state multistep.StateBag) multist
if cdPathRaw, ok := state.GetOk("cd_path"); ok {
cdFilesPath := cdPathRaw.(string)
log.Println("cdrom found, "+cdFilesPath)
cdfilesImage, err := d.UploadImage(cdFilesPath)
cdfilesImage, err := d.UploadImage(cdFilesPath, config.VmConfig)
if err != nil {
ui.Error("Error uploading image"+ err.Error())
return multistep.ActionHalt
Expand Down
8 changes: 8 additions & 0 deletions builder/nutanix/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,11 @@ func BuildReference(uuid, kind string) *v3.Reference {
UUID: StringPtr(uuid),
}
}

// BuildReferenceValue create referencevalue from defined object
func BuildReferenceValue(uuid, kind string) *v3.ReferenceValues {
return &v3.ReferenceValues{
Kind: kind,
UUID: uuid,
}
}

0 comments on commit 13f5845

Please sign in to comment.