Giter VIP home page Giter VIP logo

Comments (2)

pawandubey avatar pawandubey commented on August 9, 2024 3

Hey @bpg Thanks for the response! I took a deeper look into the current state of the API just now.

It does look like there is now an API for importing VM disks, but there are some rough edges it seems given what another person ran into while implementing the feature in the Telmate provider: Telmate/terraform-provider-proxmox#605 (comment)

Apart from that it still seems like creating snippets is not yet supported in the API.

So overall, there probably won't be a way to support all of the features with the token yet. I think it might be possible to remove the VM disk limitation now with some effort, but that should be tracked in a separate issue.

I'll close this issue for now, and maybe come back to it if/when the API matures. Thank you for this project nonetheless!

from terraform-provider-proxmox.

bpg avatar bpg commented on August 9, 2024

Hey @pawandubey! This is a reasonable request for sure, and I'd love to see token-based auth supported by the provider.
Unfortunately, this can't be easily implemented, as we heavily dependent on ability to execute PVE commands over ssh. Particularly, in one key area -- the VM disks import:

commands = append(
commands,
`set -e`,
fmt.Sprintf(`datastore_id_image="%s"`, fileIDParts[0]),
fmt.Sprintf(`datastore_id_target="%s"`, datastoreID),
fmt.Sprintf(`disk_index="%d"`, i),
fmt.Sprintf(`disk_options="%s"`, diskOptions),
fmt.Sprintf(`disk_size="%d"`, size),
fmt.Sprintf(`disk_interface="%s"`, diskInterface),
fmt.Sprintf(`file_path="%s"`, filePath),
fmt.Sprintf(`file_path_tmp="%s"`, filePathTmp),
fmt.Sprintf(`vm_id="%d"`, vmID),
`getdsi() { local nr='^([A-Za-z0-9_-]+): ([A-Za-z0-9_-]+)$'; local pr='^[[:space:]]+path[[:space:]]+([^[:space:]]+)$'; local dn=""; local dt=""; while IFS='' read -r l || [[ -n "$l" ]]; do if [[ "$l" =~ $nr ]]; then dt="${BASH_REMATCH[1]}"; dn="${BASH_REMATCH[2]}"; elif [[ "$l" =~ $pr ]] && [[ "$dn" == "$1" ]]; then echo "${BASH_REMATCH[1]};${dt}"; break; fi; done < /etc/pve/storage.cfg; }`,
`dsi_image="$(getdsi "$datastore_id_image")"`,
`dsp_image="$(echo "$dsi_image" | cut -d ";" -f 1)"`,
`dst_image="$(echo "$dsi_image" | cut -d ";" -f 2)"`,
`if [[ -z "$dsp_image" ]]; then echo "Failed to determine the path for datastore '${datastore_id_image}' (${dsi_image})"; exit 1; fi`,
`dsi_target="$(getdsi "$datastore_id_target")"`,
`dsp_target="$(echo "$dsi_target" | cut -d ";" -f 1)"`,
`cp "${dsp_image}${file_path}" "$file_path_tmp"`,
`qemu-img resize "$file_path_tmp" "${disk_size}G"`,
`imported_disk="$(qm importdisk "$vm_id" "$file_path_tmp" "$datastore_id_target" -format qcow2 | grep "unused0" | cut -d ":" -f 3 | cut -d "'" -f 1)"`,
`disk_id="${datastore_id_target}:$([[ -n "$dsp_target" ]] && echo "${vm_id}/" || echo "")$imported_disk$([[ -n "$dsp_target" ]] && echo ".qcow2" || echo "")${disk_options}"`,
`qm set "$vm_id" "-${disk_interface}" "$disk_id"`,
`rm -f "$file_path_tmp"`,
)
importedDiskCount++
}
// Execute the commands on the node and wait for the result.
// This is a highly experimental approach to disk imports and is not recommended by Proxmox.
if len(commands) > 0 {
err = veClient.ExecuteNodeCommands(ctx, nodeName, commands)
if err != nil {
return diag.FromErr(err)
}
}

I don't know all details why this specific approach of dealing with disks was chosen by the original plugin authors, probably due to the lack of some specific functionality from the PVE REST API.
This limitation is also indirectly mentioned in the Known Issues section of the README, I guess we need to clarify this better.

from terraform-provider-proxmox.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.