MCPcopy Create free account
hub / github.com/devnullvoid/pvetui / executeLXCBootstrapViaPCT

Function executeLXCBootstrapViaPCT

internal/ui/plugins/ansible/plugin.go:1585–1624  ·  view source on GitHub ↗
(
	ctx context.Context,
	host coreansible.InventoryHost,
	nodeByName map[string]coreansible.InventoryHost,
	nodeSSHUser string,
	script string,
	stream func(string),
)

Source from the content-addressed store, hash-verified

1583}
1584
1585func executeLXCBootstrapViaPCT(
1586 ctx context.Context,
1587 host coreansible.InventoryHost,
1588 nodeByName map[string]coreansible.InventoryHost,
1589 nodeSSHUser string,
1590 script string,
1591 stream func(string),
1592) (string, error) {
1593 vmidRaw := strings.TrimSpace(host.Vars["pvetui_guest_id"])
1594 nodeName := strings.TrimSpace(host.Vars["pvetui_node"])
1595 if vmidRaw == "" || nodeName == "" {
1596 return "", fmt.Errorf("missing guest VMID/node metadata for pct exec fallback")
1597 }
1598 vmid, err := strconv.Atoi(vmidRaw)
1599 if err != nil || vmid <= 0 {
1600 return "", fmt.Errorf("invalid guest VMID %q for pct exec fallback", vmidRaw)
1601 }
1602
1603 nodeHost, ok := nodeByName[nodeName]
1604 if !ok {
1605 return "", fmt.Errorf("node %q not found in inventory for pct exec fallback", nodeName)
1606 }
1607 nodeTarget := strings.TrimSpace(nodeHost.Vars["ansible_host"])
1608 nodeUser := strings.TrimSpace(nodeSSHUser)
1609 nodePassword := ""
1610 nodeKeyPath := ""
1611 if nodeTarget == "" || nodeUser == "" {
1612 return "", fmt.Errorf("missing ansible_host or SSH user on node %q for pct exec fallback", nodeName)
1613 }
1614 if net.ParseIP(nodeTarget) == nil {
1615 return "", fmt.Errorf("node %q target %q is not an IP address for pct exec fallback", nodeName, nodeTarget)
1616 }
1617
1618 pctCmd := fmt.Sprintf("pct exec %d -- sh -s", vmid)
1619 if !strings.EqualFold(nodeUser, "root") {
1620 pctCmd = "sudo -n " + pctCmd
1621 }
1622 ansibleLogger().Debug("direct bootstrap pct fallback command: %s", pctCmd)
1623 return executeSSHScript(ctx, nodeUser, nodeTarget, nodePassword, nodeKeyPath, pctCmd, script, stream)
1624}
1625
1626func (p *Plugin) executeQEMUBootstrapViaGuestAgent(
1627 ctx context.Context,

Callers 1

Calls 3

ansibleLoggerFunction · 0.85
executeSSHScriptFunction · 0.85
DebugMethod · 0.65

Tested by

no test coverage detected