go mod vendor
This commit is contained in:
parent
b725b9cab8
commit
629a8aec15
|
@ -13,6 +13,7 @@ import (
|
|||
"mime/multipart"
|
||||
"net"
|
||||
"net/http"
|
||||
"os"
|
||||
"regexp"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
@ -722,7 +723,28 @@ func (c *Client) DeleteVMDisks(
|
|||
}
|
||||
|
||||
func (c *Client) Upload(node string, storage string, contentType string, filename string, file io.Reader) error {
|
||||
body, mimetype, err := createUploadBody(contentType, filename, file)
|
||||
var doStreamingIO bool
|
||||
var fileSize int64
|
||||
var contentLength int64
|
||||
|
||||
if f, ok := file.(*os.File); ok {
|
||||
doStreamingIO = true
|
||||
fileInfo, err := f.Stat()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
fileSize = fileInfo.Size()
|
||||
}
|
||||
|
||||
var body io.Reader
|
||||
var mimetype string
|
||||
var err error
|
||||
|
||||
if doStreamingIO {
|
||||
body, mimetype, contentLength, err = createStreamedUploadBody(contentType, filename, fileSize, file)
|
||||
} else {
|
||||
body, mimetype, err = createUploadBody(contentType, filename, file)
|
||||
}
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
@ -735,6 +757,10 @@ func (c *Client) Upload(node string, storage string, contentType string, filenam
|
|||
req.Header.Add("Content-Type", mimetype)
|
||||
req.Header.Add("Accept", "application/json")
|
||||
|
||||
if doStreamingIO {
|
||||
req.ContentLength = contentLength
|
||||
}
|
||||
|
||||
resp, err := c.session.Do(req)
|
||||
if err != nil {
|
||||
return err
|
||||
|
@ -780,6 +806,38 @@ func createUploadBody(contentType string, filename string, r io.Reader) (io.Read
|
|||
return &buf, w.FormDataContentType(), nil
|
||||
}
|
||||
|
||||
// createStreamedUploadBody - Use MultiReader to create the multipart body from the file reader,
|
||||
// avoiding allocation of large files in memory before upload (useful e.g. for Windows ISOs).
|
||||
func createStreamedUploadBody(contentType string, filename string, fileSize int64, r io.Reader) (io.Reader, string, int64, error) {
|
||||
var buf bytes.Buffer
|
||||
w := multipart.NewWriter(&buf)
|
||||
|
||||
err := w.WriteField("content", contentType)
|
||||
if err != nil {
|
||||
return nil, "", 0, err
|
||||
}
|
||||
|
||||
_, err = w.CreateFormFile("filename", filename)
|
||||
if err != nil {
|
||||
return nil, "", 0, err
|
||||
}
|
||||
|
||||
headerSize := buf.Len()
|
||||
|
||||
err = w.Close()
|
||||
if err != nil {
|
||||
return nil, "", 0, err
|
||||
}
|
||||
|
||||
mr := io.MultiReader(bytes.NewReader(buf.Bytes()[:headerSize]),
|
||||
r,
|
||||
bytes.NewReader(buf.Bytes()[headerSize:]))
|
||||
|
||||
contentLength := int64(buf.Len()) + fileSize
|
||||
|
||||
return mr, w.FormDataContentType(), contentLength, nil
|
||||
}
|
||||
|
||||
// getStorageAndVolumeName - Extract disk storage and disk volume, since disk name is saved
|
||||
// in Proxmox with its storage.
|
||||
func getStorageAndVolumeName(
|
||||
|
|
|
@ -313,7 +313,9 @@ func (config configLxc) CreateLxc(vmr *VmRef, client *Client) (err error) {
|
|||
// comma separated list of "key=value" pairs
|
||||
featuresParam := QemuDeviceParam{}
|
||||
featuresParam = featuresParam.createDeviceParam(config.Features, nil)
|
||||
paramMap["features"] = strings.Join(featuresParam, ",")
|
||||
if len(featuresParam) > 0 {
|
||||
paramMap["features"] = strings.Join(featuresParam, ",")
|
||||
}
|
||||
|
||||
// build list of mountpoints
|
||||
// this does the same as for the feature list
|
||||
|
|
|
@ -38,6 +38,7 @@ type ConfigQemu struct {
|
|||
QemuVcpus int `json:"vcpus"`
|
||||
QemuCpu string `json:"cpu"`
|
||||
QemuNuma bool `json:"numa"`
|
||||
QemuKVM bool `json:"kvm"`
|
||||
Hotplug string `json:"hotplug"`
|
||||
QemuIso string `json:"iso"`
|
||||
FullClone *int `json:"fullclone"`
|
||||
|
@ -94,6 +95,7 @@ func (config ConfigQemu) CreateVm(vmr *VmRef, client *Client) (err error) {
|
|||
"cores": config.QemuCores,
|
||||
"cpu": config.QemuCpu,
|
||||
"numa": config.QemuNuma,
|
||||
"kvm": config.QemuKVM,
|
||||
"hotplug": config.Hotplug,
|
||||
"memory": config.Memory,
|
||||
"boot": config.Boot,
|
||||
|
@ -107,11 +109,11 @@ func (config ConfigQemu) CreateVm(vmr *VmRef, client *Client) (err error) {
|
|||
if config.Balloon >= 1 {
|
||||
params["balloon"] = config.Balloon
|
||||
}
|
||||
|
||||
|
||||
if config.QemuVcpus >= 1 {
|
||||
params["vcpus"] = config.QemuVcpus
|
||||
}
|
||||
|
||||
|
||||
if vmr.pool != "" {
|
||||
params["pool"] = vmr.pool
|
||||
}
|
||||
|
@ -214,6 +216,7 @@ func (config ConfigQemu) UpdateConfig(vmr *VmRef, client *Client) (err error) {
|
|||
"cores": config.QemuCores,
|
||||
"cpu": config.QemuCpu,
|
||||
"numa": config.QemuNuma,
|
||||
"kvm": config.QemuKVM,
|
||||
"hotplug": config.Hotplug,
|
||||
"memory": config.Memory,
|
||||
"boot": config.Boot,
|
||||
|
@ -231,13 +234,13 @@ func (config ConfigQemu) UpdateConfig(vmr *VmRef, client *Client) (err error) {
|
|||
} else {
|
||||
deleteParams = append(deleteParams, "balloon")
|
||||
}
|
||||
|
||||
|
||||
if config.QemuVcpus >= 1 {
|
||||
configParams["vcpus"] = config.QemuVcpus
|
||||
} else {
|
||||
deleteParams = append(deleteParams, "vcpus")
|
||||
}
|
||||
|
||||
|
||||
if config.BootDisk != "" {
|
||||
configParams["bootdisk"] = config.BootDisk
|
||||
}
|
||||
|
@ -307,11 +310,11 @@ func (config ConfigQemu) UpdateConfig(vmr *VmRef, client *Client) (err error) {
|
|||
if config.Ipconfig2 != "" {
|
||||
configParams["ipconfig2"] = config.Ipconfig2
|
||||
}
|
||||
|
||||
|
||||
if len(deleteParams) > 0 {
|
||||
configParams["delete"] = strings.Join(deleteParams, ", ")
|
||||
}
|
||||
|
||||
|
||||
_, err = client.SetVmConfig(vmr, configParams)
|
||||
if err != nil {
|
||||
log.Print(err)
|
||||
|
@ -326,7 +329,7 @@ func (config ConfigQemu) UpdateConfig(vmr *VmRef, client *Client) (err error) {
|
|||
}
|
||||
|
||||
func NewConfigQemuFromJson(io io.Reader) (config *ConfigQemu, err error) {
|
||||
config = &ConfigQemu{QemuVlanTag: -1}
|
||||
config = &ConfigQemu{QemuVlanTag: -1, QemuKVM: true}
|
||||
err = json.NewDecoder(io).Decode(config)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
|
@ -449,6 +452,10 @@ func NewConfigQemuFromApi(vmr *VmRef, client *Client) (config *ConfigQemu, err e
|
|||
if _, isSet := vmConfig["bootdisk"]; isSet {
|
||||
bootdisk = vmConfig["bootdisk"].(string)
|
||||
}
|
||||
kvm := true
|
||||
if _, isSet := vmConfig["kvm"]; isSet {
|
||||
kvm = Itob(int(vmConfig["kvm"].(float64)))
|
||||
}
|
||||
scsihw := "lsi"
|
||||
if _, isSet := vmConfig["scsihw"]; isSet {
|
||||
scsihw = vmConfig["scsihw"].(string)
|
||||
|
@ -470,6 +477,7 @@ func NewConfigQemuFromApi(vmr *VmRef, client *Client) (config *ConfigQemu, err e
|
|||
QemuSockets: int(sockets),
|
||||
QemuCpu: cpu,
|
||||
QemuNuma: numa,
|
||||
QemuKVM: kvm,
|
||||
Hotplug: hotplug,
|
||||
QemuVlanTag: -1,
|
||||
Boot: boot,
|
||||
|
@ -481,12 +489,12 @@ func NewConfigQemuFromApi(vmr *VmRef, client *Client) (config *ConfigQemu, err e
|
|||
QemuNetworks: QemuDevices{},
|
||||
QemuSerials: QemuDevices{},
|
||||
}
|
||||
|
||||
|
||||
if balloon >= 1 {
|
||||
config.Balloon = int(balloon);
|
||||
config.Balloon = int(balloon)
|
||||
}
|
||||
if vcpus >= 1 {
|
||||
config.QemuVcpus = int(vcpus);
|
||||
config.QemuVcpus = int(vcpus)
|
||||
}
|
||||
|
||||
if vmConfig["ide2"] != nil {
|
||||
|
|
|
@ -65,7 +65,9 @@ func ParamsToBody(params map[string]interface{}) (body []byte) {
|
|||
default:
|
||||
v = fmt.Sprintf("%v", intrV)
|
||||
}
|
||||
vals.Set(k, v)
|
||||
if v != "" {
|
||||
vals.Set(k, v)
|
||||
}
|
||||
}
|
||||
body = bytes.NewBufferString(vals.Encode()).Bytes()
|
||||
return
|
||||
|
|
|
@ -69,7 +69,7 @@ github.com/NaverCloudPlatform/ncloud-sdk-go-v2/services/server
|
|||
github.com/PuerkitoBio/goquery
|
||||
# github.com/StackExchange/wmi v0.0.0-20190523213315-cbe66965904d
|
||||
github.com/StackExchange/wmi
|
||||
# github.com/Telmate/proxmox-api-go v0.0.0-20200225212220-a29566462efd
|
||||
# github.com/Telmate/proxmox-api-go v0.0.0-20200715182505-ec97c70ba887
|
||||
github.com/Telmate/proxmox-api-go/proxmox
|
||||
# github.com/agext/levenshtein v1.2.1
|
||||
github.com/agext/levenshtein
|
||||
|
|
Loading…
Reference in New Issue