Skip to content

Add IBMi support for Power-Access-Cloud#44

Open
vikasbolla wants to merge 1 commit intoIBM:mainfrom
vikasbolla:add_ibmi_support
Open

Add IBMi support for Power-Access-Cloud#44
vikasbolla wants to merge 1 commit intoIBM:mainfrom
vikasbolla:add_ibmi_support

Conversation

@vikasbolla
Copy link
Collaborator

  • Added a Cloud init script, which creates a User Profile and handles configuration required for ssh-key based authentication.

@vikasbolla vikasbolla force-pushed the add_ibmi_support branch 5 times, most recently from 5373f89 to a59c42a Compare March 3, 2026 09:30
Signed-off-by: Vikas <vikas.satyanarayana.bolla@ibm.com>
Copy link
Member

@Prajyot-Parab Prajyot-Parab left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/lgtm
/hold for @mkumatag

memory := float64(vmSpec.Capacity.Memory)
processors, _ := strconv.ParseFloat(vmSpec.Capacity.CPU, 64)
var userData string
if strings.HasPrefix(vmSpec.Image, IbmiImagePrefix) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

for the long run - introduce some filed like os

return nil
}

func getUserData(sshKeys []string, username string) string {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

make use of text/template package like below(refer only template logic)

package main

import (
	_ "embed"
	"flag"
	"fmt"
	"os"
	"text/template"
)

//go:embed cloud-init-template.txt
var cloudInitTemplate string

// Config holds the template variables
type Config struct {
	Username string
	Keys     string
}

func main() {
	// Define command-line flags
	username := flag.String("username", "", "Username for the cloud-init configuration (required)")
	keys := flag.String("keys", "", "SSH public keys (required)")
	output := flag.String("output", "", "Output file path (optional, defaults to stdout)")
	flag.Parse()

	// Validate required parameters
	if *username == "" {
		fmt.Fprintln(os.Stderr, "Error: -username is required")
		flag.Usage()
		os.Exit(1)
	}

	if *keys == "" {
		fmt.Fprintln(os.Stderr, "Error: -keys is required")
		flag.Usage()
		os.Exit(1)
	}

	// Create config with provided values
	config := Config{
		Username: *username,
		Keys:     *keys,
	}

	// Parse the embedded template
	tmpl, err := template.New("cloud-init").Parse(cloudInitTemplate)
	if err != nil {
		fmt.Fprintf(os.Stderr, "Error parsing template: %v\n", err)
		os.Exit(1)
	}

	// Determine output destination
	var writer *os.File
	if *output != "" {
		writer, err = os.Create(*output)
		if err != nil {
			fmt.Fprintf(os.Stderr, "Error creating output file: %v\n", err)
			os.Exit(1)
		}
		defer writer.Close()
	} else {
		writer = os.Stdout
	}

	// Execute template with config values
	err = tmpl.Execute(writer, config)
	if err != nil {
		fmt.Fprintf(os.Stderr, "Error executing template: %v\n", err)
		os.Exit(1)
	}

	// Print success message if writing to file
	if *output != "" {
		fmt.Fprintf(os.Stderr, "Cloud-init configuration successfully written to: %s\n", *output)
	}
}

// Made with Bob

}

// Fallback to raw script if template reading fails for some reason
return fmt.Sprintf(`#cloud-config
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no need to fallback, it will not fail..

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants