diff --git a/builder/azure/arm/authenticate_devicewflow.go b/builder/azure/arm/authenticate_devicewflow.go index 48a6d2f69..b859a3066 100644 --- a/builder/azure/arm/authenticate_devicewflow.go +++ b/builder/azure/arm/authenticate_devicewflow.go @@ -10,7 +10,11 @@ import ( ) func NewDeviceFlowOAuthTokenProvider(env azure.Environment, say func(string), tenantID string) oAuthTokenProvider { - return &deviceflowOauthTokenProvider{} + return &deviceflowOauthTokenProvider{ + env: env, + say: say, + tenantID: tenantID, + } } type deviceflowOauthTokenProvider struct { diff --git a/builder/azure/arm/clientconfig.go b/builder/azure/arm/clientconfig.go index 69dfffbea..f178b8b50 100644 --- a/builder/azure/arm/clientconfig.go +++ b/builder/azure/arm/clientconfig.go @@ -155,8 +155,7 @@ func (c ClientConfig) useDeviceLogin() bool { c.ClientID == "" && c.ClientSecret == "" && c.ClientJWT == "" && - c.ClientCertPath == "" && - c.TenantID == "" + c.ClientCertPath == "" } func (c ClientConfig) useMSI() bool { diff --git a/builder/azure/arm/clientconfig_test.go b/builder/azure/arm/clientconfig_test.go index f9fafd2f2..3ae8af6f0 100644 --- a/builder/azure/arm/clientconfig_test.go +++ b/builder/azure/arm/clientconfig_test.go @@ -268,11 +268,18 @@ func getCloud() *azure.Environment { // tests for assertRequiredParametersSet func Test_ClientConfig_CanUseDeviceCode(t *testing.T) { - cfg := emptyClientConfig() - cfg.SubscriptionID = "12345" - // TenantID is optional - - assertValid(t, cfg) + // TenantID is optional, but Builder will look up tenant ID before requesting + t.Run("without TenantID", func(t *testing.T) { + cfg := emptyClientConfig() + cfg.SubscriptionID = "12345" + assertValid(t, cfg) + }) + t.Run("with TenantID", func(t *testing.T) { + cfg := emptyClientConfig() + cfg.SubscriptionID = "12345" + cfg.TenantID = "12345" + assertValid(t, cfg) + }) } func assertValid(t *testing.T, cfg ClientConfig) { diff --git a/command/plugin.go b/command/plugin.go index 825f06683..2d2272640 100644 --- a/command/plugin.go +++ b/command/plugin.go @@ -41,7 +41,7 @@ import ( profitbricksbuilder "github.com/hashicorp/packer/builder/profitbricks" qemubuilder "github.com/hashicorp/packer/builder/qemu" scalewaybuilder "github.com/hashicorp/packer/builder/scaleway" - tencentcloudbuilder "github.com/hashicorp/packer/builder/tencentcloud/cvm" + tencentcloudcvmbuilder "github.com/hashicorp/packer/builder/tencentcloud/cvm" tritonbuilder "github.com/hashicorp/packer/builder/triton" virtualboxisobuilder "github.com/hashicorp/packer/builder/virtualbox/iso" virtualboxovfbuilder "github.com/hashicorp/packer/builder/virtualbox/ovf" @@ -114,7 +114,7 @@ var Builders = map[string]packer.Builder{ "profitbricks": new(profitbricksbuilder.Builder), "qemu": new(qemubuilder.Builder), "scaleway": new(scalewaybuilder.Builder), - "tencentcloud-cvm": new(tencentcloudbuilder.Builder), + "tencentcloud-cvm": new(tencentcloudcvmbuilder.Builder), "triton": new(tritonbuilder.Builder), "virtualbox-iso": new(virtualboxisobuilder.Builder), "virtualbox-ovf": new(virtualboxovfbuilder.Builder), diff --git a/common/bootcommand/boot_command.go b/common/bootcommand/boot_command.go index 95133f334..1447a4337 100644 --- a/common/bootcommand/boot_command.go +++ b/common/bootcommand/boot_command.go @@ -1190,7 +1190,6 @@ func newParser(filename string, b []byte, opts ...Option) *parser { Stats: &stats, // start rule is rule [0] unless an alternate entrypoint is specified entrypoint: g.rules[0].name, - emptyState: make(storeDict), } p.setOptions(opts) @@ -1279,9 +1278,6 @@ type parser struct { choiceNoMatch string // recovery expression stack, keeps track of the currently available recovery expression, these are traversed in reverse recoveryStack []map[string]interface{} - - // emptyState contains an empty storeDict, which is used to optimize cloneState if global "state" store is not used. - emptyState storeDict } // push a variable set on the vstack. @@ -1455,13 +1451,6 @@ func (p *parser) cloneState() storeDict { defer p.out(p.in("cloneState")) } - if len(p.cur.state) == 0 { - if len(p.emptyState) > 0 { - p.emptyState = make(storeDict) - } - return p.emptyState - } - state := make(storeDict, len(p.cur.state)) for k, v := range p.cur.state { if c, ok := v.(Cloner); ok { diff --git a/common/powershell/hyperv/hyperv.go b/common/powershell/hyperv/hyperv.go index cd06780bb..fbdba92c4 100644 --- a/common/powershell/hyperv/hyperv.go +++ b/common/powershell/hyperv/hyperv.go @@ -242,13 +242,13 @@ func getCreateVMScript(opts *scriptOptions) (string, error) { } var tpl = template.Must(template.New("createVM").Parse(` -$vhdPath = Join-Path -Path {{ .Path }} -ChildPath {{ .VHDX }} +$vhdPath = Join-Path -Path "{{ .Path }}" -ChildPath "{{ .VHDX }}" {{ if ne .HardDrivePath "" -}} {{- if .DiffDisks -}} - Hyper-V\New-VHD -Path $vhdPath -ParentPath {{ .HardDrivePath }} -Differencing -BlockSizeBytes {{ .VHDBlockSizeBytes }} + Hyper-V\New-VHD -Path $vhdPath -ParentPath "{{ .HardDrivePath }}" -Differencing -BlockSizeBytes {{ .VHDBlockSizeBytes }} {{- else -}} - Copy-Item -Path {{ .HardDrivePath }} -Destination $vhdPath + Copy-Item -Path "{{ .HardDrivePath }}" -Destination $vhdPath {{- end -}} {{- else -}} {{- if .FixedVHD -}} @@ -258,7 +258,7 @@ $vhdPath = Join-Path -Path {{ .Path }} -ChildPath {{ .VHDX }} {{- end -}} {{- end }} -Hyper-V\New-VM -Name {{ .VMName }} -Path {{ .Path }} -MemoryStartupBytes {{ .MemoryStartupBytes }} -VHDPath $vhdPath -SwitchName {{ .SwitchName }} +Hyper-V\New-VM -Name "{{ .VMName }}" -Path "{{ .Path }}" -MemoryStartupBytes {{ .MemoryStartupBytes }} -VHDPath $vhdPath -SwitchName "{{ .SwitchName }}" {{- if eq .Generation 2}} -Generation {{ .Generation }} {{- end -}} {{- if ne .Version ""}} -Version {{ .Version }} {{- end -}} `)) diff --git a/common/powershell/hyperv/hyperv_test.go b/common/powershell/hyperv/hyperv_test.go index b4cca857e..d5a14661b 100644 --- a/common/powershell/hyperv/hyperv_test.go +++ b/common/powershell/hyperv/hyperv_test.go @@ -26,9 +26,9 @@ func Test_getCreateVMScript(t *testing.T) { t.Fatalf("Error: %s", err.Error()) } - expected := `$vhdPath = Join-Path -Path C://mypath -ChildPath myvm.vhd -Hyper-V\New-VHD -Path $vhdPath -ParentPath C://harddrivepath -Differencing -BlockSizeBytes 10 -Hyper-V\New-VM -Name myvm -Path C://mypath -MemoryStartupBytes 1024 -VHDPath $vhdPath -SwitchName hyperv-vmx-switch -Version 5.0` + expected := `$vhdPath = Join-Path -Path "C://mypath" -ChildPath "myvm.vhd" +Hyper-V\New-VHD -Path $vhdPath -ParentPath "C://harddrivepath" -Differencing -BlockSizeBytes 10 +Hyper-V\New-VM -Name "myvm" -Path "C://mypath" -MemoryStartupBytes 1024 -VHDPath $vhdPath -SwitchName "hyperv-vmx-switch" -Version 5.0` if ok := strings.Compare(scriptString, expected); ok != 0 { t.Fatalf("EXPECTED: \n%s\n\n RECEIVED: \n%s\n\n", expected, scriptString) } @@ -48,9 +48,9 @@ Hyper-V\New-VM -Name myvm -Path C://mypath -MemoryStartupBytes 1024 -VHDPath $vh t.Fatalf("Error: %s", err.Error()) } - expected = `$vhdPath = Join-Path -Path C://mypath -ChildPath myvm.vhdx -Hyper-V\New-VHD -Path $vhdPath -ParentPath C://harddrivepath -Differencing -BlockSizeBytes 10 -Hyper-V\New-VM -Name myvm -Path C://mypath -MemoryStartupBytes 1024 -VHDPath $vhdPath -SwitchName hyperv-vmx-switch -Generation 2 -Version 5.0` + expected = `$vhdPath = Join-Path -Path "C://mypath" -ChildPath "myvm.vhdx" +Hyper-V\New-VHD -Path $vhdPath -ParentPath "C://harddrivepath" -Differencing -BlockSizeBytes 10 +Hyper-V\New-VM -Name "myvm" -Path "C://mypath" -MemoryStartupBytes 1024 -VHDPath $vhdPath -SwitchName "hyperv-vmx-switch" -Generation 2 -Version 5.0` if ok := strings.Compare(scriptString, expected); ok != 0 { t.Fatalf("EXPECTED: \n%s\n\n RECEIVED: \n%s\n\n", expected, scriptString) } @@ -63,9 +63,9 @@ Hyper-V\New-VM -Name myvm -Path C://mypath -MemoryStartupBytes 1024 -VHDPath $vh t.Fatalf("Error: %s", err.Error()) } - expected = `$vhdPath = Join-Path -Path C://mypath -ChildPath myvm.vhdx -Hyper-V\New-VHD -Path $vhdPath -ParentPath C://harddrivepath -Differencing -BlockSizeBytes 10 -Hyper-V\New-VM -Name myvm -Path C://mypath -MemoryStartupBytes 1024 -VHDPath $vhdPath -SwitchName hyperv-vmx-switch -Version 5.0` + expected = `$vhdPath = Join-Path -Path "C://mypath" -ChildPath "myvm.vhdx" +Hyper-V\New-VHD -Path $vhdPath -ParentPath "C://harddrivepath" -Differencing -BlockSizeBytes 10 +Hyper-V\New-VM -Name "myvm" -Path "C://mypath" -MemoryStartupBytes 1024 -VHDPath $vhdPath -SwitchName "hyperv-vmx-switch" -Version 5.0` if ok := strings.Compare(scriptString, expected); ok != 0 { t.Fatalf("EXPECTED: \n%s\n\n RECEIVED: \n%s\n\n", expected, scriptString) } @@ -86,9 +86,9 @@ Hyper-V\New-VM -Name myvm -Path C://mypath -MemoryStartupBytes 1024 -VHDPath $vh if err != nil { t.Fatalf("Error: %s", err.Error()) } - expected = `$vhdPath = Join-Path -Path C://mypath -ChildPath myvm.vhdx -Hyper-V\New-VHD -Path $vhdPath -ParentPath C://harddrivepath -Differencing -BlockSizeBytes 10 -Hyper-V\New-VM -Name myvm -Path C://mypath -MemoryStartupBytes 1024 -VHDPath $vhdPath -SwitchName hyperv-vmx-switch` + expected = `$vhdPath = Join-Path -Path "C://mypath" -ChildPath "myvm.vhdx" +Hyper-V\New-VHD -Path $vhdPath -ParentPath "C://harddrivepath" -Differencing -BlockSizeBytes 10 +Hyper-V\New-VM -Name "myvm" -Path "C://mypath" -MemoryStartupBytes 1024 -VHDPath $vhdPath -SwitchName "hyperv-vmx-switch"` if ok := strings.Compare(scriptString, expected); ok != 0 { t.Fatalf("EXPECTED: \n%s\n\n RECEIVED: \n%s\n\n", expected, scriptString) } @@ -98,9 +98,9 @@ Hyper-V\New-VM -Name myvm -Path C://mypath -MemoryStartupBytes 1024 -VHDPath $vh if err != nil { t.Fatalf("Error: %s", err.Error()) } - expected = `$vhdPath = Join-Path -Path C://mypath -ChildPath myvm.vhdx -Copy-Item -Path C://harddrivepath -Destination $vhdPath -Hyper-V\New-VM -Name myvm -Path C://mypath -MemoryStartupBytes 1024 -VHDPath $vhdPath -SwitchName hyperv-vmx-switch` + expected = `$vhdPath = Join-Path -Path "C://mypath" -ChildPath "myvm.vhdx" +Copy-Item -Path "C://harddrivepath" -Destination $vhdPath +Hyper-V\New-VM -Name "myvm" -Path "C://mypath" -MemoryStartupBytes 1024 -VHDPath $vhdPath -SwitchName "hyperv-vmx-switch"` if ok := strings.Compare(scriptString, expected); ok != 0 { t.Fatalf("EXPECTED: \n%s\n\n RECEIVED: \n%s\n\n", expected, scriptString) } @@ -110,9 +110,9 @@ Hyper-V\New-VM -Name myvm -Path C://mypath -MemoryStartupBytes 1024 -VHDPath $vh if err != nil { t.Fatalf("Error: %s", err.Error()) } - expected = `$vhdPath = Join-Path -Path C://mypath -ChildPath myvm.vhdx + expected = `$vhdPath = Join-Path -Path "C://mypath" -ChildPath "myvm.vhdx" Hyper-V\New-VHD -Path $vhdPath -SizeBytes 8192 -BlockSizeBytes 10 -Hyper-V\New-VM -Name myvm -Path C://mypath -MemoryStartupBytes 1024 -VHDPath $vhdPath -SwitchName hyperv-vmx-switch` +Hyper-V\New-VM -Name "myvm" -Path "C://mypath" -MemoryStartupBytes 1024 -VHDPath $vhdPath -SwitchName "hyperv-vmx-switch"` if ok := strings.Compare(scriptString, expected); ok != 0 { t.Fatalf("EXPECTED: \n%s\n\n RECEIVED: \n%s\n\n", expected, scriptString) } @@ -122,9 +122,9 @@ Hyper-V\New-VM -Name myvm -Path C://mypath -MemoryStartupBytes 1024 -VHDPath $vh if err != nil { t.Fatalf("Error: %s", err.Error()) } - expected = `$vhdPath = Join-Path -Path C://mypath -ChildPath myvm.vhd + expected = `$vhdPath = Join-Path -Path "C://mypath" -ChildPath "myvm.vhd" Hyper-V\New-VHD -Path $vhdPath -Fixed -SizeBytes 8192 -Hyper-V\New-VM -Name myvm -Path C://mypath -MemoryStartupBytes 1024 -VHDPath $vhdPath -SwitchName hyperv-vmx-switch` +Hyper-V\New-VM -Name "myvm" -Path "C://mypath" -MemoryStartupBytes 1024 -VHDPath $vhdPath -SwitchName "hyperv-vmx-switch"` if ok := strings.Compare(scriptString, expected); ok != 0 { t.Fatalf("EXPECTED: \n%s\n\n RECEIVED: \n%s\n\n", expected, scriptString) } diff --git a/go.mod b/go.mod index 41f1c719b..f312b25b3 100644 --- a/go.mod +++ b/go.mod @@ -160,7 +160,7 @@ require ( github.com/ugorji/go v0.0.0-20151218193438-646ae4a518c1 github.com/ulikunitz/xz v0.0.0-20180703112113-636d36a76670 github.com/vmware/govmomi v0.0.0-20170707011325-c2105a174311 - github.com/xanzy/go-cloudstack v2.1.4+incompatible + github.com/xanzy/go-cloudstack v2.4.1+incompatible golang.org/x/crypto v0.0.0-20180322175230-88942b9c40a4 golang.org/x/net v0.0.0-20181201002055-351d144fa1fc golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be diff --git a/go.sum b/go.sum index f6890eb5e..41e83c1a6 100644 --- a/go.sum +++ b/go.sum @@ -356,8 +356,8 @@ github.com/ulikunitz/xz v0.0.0-20180703112113-636d36a76670 h1:HQWT4ta3wW5GZ790Ga github.com/ulikunitz/xz v0.0.0-20180703112113-636d36a76670/go.mod h1:2bypXElzHzzJZwzH67Y6wb67pO62Rzfn7BSiF4ABRW8= github.com/vmware/govmomi v0.0.0-20170707011325-c2105a174311 h1:s5pyxd5S6wRs2WpEE0xRfWUF46Wbz44h203KnbX0ecI= github.com/vmware/govmomi v0.0.0-20170707011325-c2105a174311/go.mod h1:URlwyTFZX72RmxtxuaFL2Uj3fD1JTvZdx59bHWk6aFU= -github.com/xanzy/go-cloudstack v2.1.4+incompatible h1:5c72sRFakVv8wH/HsQFg+xr37CmNQU2UbJfaBjW5f0c= -github.com/xanzy/go-cloudstack v2.1.4+incompatible/go.mod h1:s3eL3z5pNXF5FVybcT+LIVdId8pYn709yv6v5mrkrQE= +github.com/xanzy/go-cloudstack v2.4.1+incompatible h1:Oc4xa2+I94h1g/QJ+nHoq597nJz2KXzxuQx/weOx0AU= +github.com/xanzy/go-cloudstack v2.4.1+incompatible/go.mod h1:s3eL3z5pNXF5FVybcT+LIVdId8pYn709yv6v5mrkrQE= golang.org/x/crypto v0.0.0-20180322175230-88942b9c40a4 h1:AJCW0rhPjFKEAoValWpqnRKxX8YV0Xvqfw+dOexCTPc= golang.org/x/crypto v0.0.0-20180322175230-88942b9c40a4/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4= golang.org/x/lint v0.0.0-20181026193005-c67002cb31c3/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE= diff --git a/provisioner/ansible/provisioner.go b/provisioner/ansible/provisioner.go index 4b9df4e7f..9979fbd2a 100644 --- a/provisioner/ansible/provisioner.go +++ b/provisioner/ansible/provisioner.go @@ -51,7 +51,7 @@ type Config struct { EmptyGroups []string `mapstructure:"empty_groups"` HostAlias string `mapstructure:"host_alias"` User string `mapstructure:"user"` - LocalPort string `mapstructure:"local_port"` + LocalPort uint `mapstructure:"local_port"` SSHHostKeyFile string `mapstructure:"ssh_host_key_file"` SSHAuthorizedKeyFile string `mapstructure:"ssh_authorized_key_file"` SFTPCmd string `mapstructure:"sftp_command"` @@ -130,12 +130,8 @@ func (p *Provisioner) Prepare(raws ...interface{}) error { p.config.AnsibleEnvVars = append(p.config.AnsibleEnvVars, "ANSIBLE_SCP_IF_SSH=True") } - if len(p.config.LocalPort) > 0 { - if _, err := strconv.ParseUint(p.config.LocalPort, 10, 16); err != nil { - errs = packer.MultiErrorAppend(errs, fmt.Errorf("local_port: %s must be a valid port", p.config.LocalPort)) - } - } else { - p.config.LocalPort = "0" + if p.config.LocalPort > 65535 { + errs = packer.MultiErrorAppend(errs, fmt.Errorf("local_port: %d must be a valid port", p.config.LocalPort)) } if len(p.config.InventoryDirectory) > 0 { @@ -256,11 +252,8 @@ func (p *Provisioner) Provision(ui packer.Ui, comm packer.Communicator) error { config.AddHostKey(hostSigner) localListener, err := func() (net.Listener, error) { - port, err := strconv.ParseUint(p.config.LocalPort, 10, 16) - if err != nil { - return nil, err - } + port := p.config.LocalPort tries := 1 if port != 0 { tries = 10 @@ -272,11 +265,17 @@ func (p *Provisioner) Provision(ui packer.Ui, comm packer.Communicator) error { ui.Say(err.Error()) continue } - _, p.config.LocalPort, err = net.SplitHostPort(l.Addr().String()) + _, portStr, err := net.SplitHostPort(l.Addr().String()) if err != nil { ui.Say(err.Error()) continue } + portUint64, err := strconv.ParseUint(portStr, 10, 0) + if err != nil { + ui.Say(err.Error()) + continue + } + p.config.LocalPort = uint(portUint64) return l, nil } return nil, errors.New("Error setting up SSH proxy connection") @@ -304,10 +303,10 @@ func (p *Provisioner) Provision(ui packer.Ui, comm packer.Communicator) error { } defer os.Remove(tf.Name()) - host := fmt.Sprintf("%s ansible_host=127.0.0.1 ansible_user=%s ansible_port=%s\n", + host := fmt.Sprintf("%s ansible_host=127.0.0.1 ansible_user=%s ansible_port=%d\n", p.config.HostAlias, p.config.User, p.config.LocalPort) if p.ansibleMajVersion < 2 { - host = fmt.Sprintf("%s ansible_ssh_host=127.0.0.1 ansible_ssh_user=%s ansible_ssh_port=%s\n", + host = fmt.Sprintf("%s ansible_ssh_host=127.0.0.1 ansible_ssh_user=%s ansible_ssh_port=%d\n", p.config.HostAlias, p.config.User, p.config.LocalPort) } diff --git a/provisioner/ansible/provisioner_test.go b/provisioner/ansible/provisioner_test.go index 3386b74cb..099f72bcc 100644 --- a/provisioner/ansible/provisioner_test.go +++ b/provisioner/ansible/provisioner_test.go @@ -245,13 +245,13 @@ func TestProvisionerPrepare_LocalPort(t *testing.T) { config["ssh_authorized_key_file"] = publickey_file.Name() config["playbook_file"] = playbook_file.Name() - config["local_port"] = "65537" + config["local_port"] = uint(65537) err = p.Prepare(config) if err == nil { t.Fatal("should have error") } - config["local_port"] = "22222" + config["local_port"] = uint(22222) err = p.Prepare(config) if err != nil { t.Fatalf("err: %s", err) diff --git a/scripts/build.sh b/scripts/build.sh index 5e24244d7..cf44e0713 100755 --- a/scripts/build.sh +++ b/scripts/build.sh @@ -12,8 +12,11 @@ set -e function validateToolPresence { local TOOLNAME=$1 - which ${TOOLNAME} >/dev/null || echo "${TOOLNAME} is not on the path. Exiting..." - exit 1 + which ${TOOLNAME} >/dev/null + if [ $? -ne 0 ]; then + echo "${TOOLNAME} is not on the path. Exiting..." + exit 1 + fi } # Validates that all used tools are present; exits when any is not found @@ -84,6 +87,7 @@ function convertPathOnCygwin() { esac } +validatePreconditions enterPackerSourceDir ensureOutputStructure cleanOutputDirs diff --git a/vendor/github.com/xanzy/go-cloudstack/cloudstack/APIDiscoveryService.go b/vendor/github.com/xanzy/go-cloudstack/cloudstack/APIDiscoveryService.go index 490d36d65..030f034eb 100644 --- a/vendor/github.com/xanzy/go-cloudstack/cloudstack/APIDiscoveryService.go +++ b/vendor/github.com/xanzy/go-cloudstack/cloudstack/APIDiscoveryService.go @@ -1,5 +1,5 @@ // -// Copyright 2016, Sander van Harmelen +// Copyright 2018, Sander van Harmelen // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -63,6 +63,7 @@ func (s *APIDiscoveryService) ListApis(p *ListApisParams) (*ListApisResponse, er if err := json.Unmarshal(resp, &r); err != nil { return nil, err } + return &r, nil } @@ -72,25 +73,29 @@ type ListApisResponse struct { } type Api struct { - Description string `json:"description,omitempty"` - Isasync bool `json:"isasync,omitempty"` - Name string `json:"name,omitempty"` - Params []struct { - Description string `json:"description,omitempty"` - Length int `json:"length,omitempty"` - Name string `json:"name,omitempty"` - Related string `json:"related,omitempty"` - Required bool `json:"required,omitempty"` - Since string `json:"since,omitempty"` - Type string `json:"type,omitempty"` - } `json:"params,omitempty"` - Related string `json:"related,omitempty"` - Response []struct { - Description string `json:"description,omitempty"` - Name string `json:"name,omitempty"` - Response []string `json:"response,omitempty"` - Type string `json:"type,omitempty"` - } `json:"response,omitempty"` - Since string `json:"since,omitempty"` - Type string `json:"type,omitempty"` + Description string `json:"description"` + Isasync bool `json:"isasync"` + Name string `json:"name"` + Params []ApiParams `json:"params"` + Related string `json:"related"` + Response []ApiResponse `json:"response"` + Since string `json:"since"` + Type string `json:"type"` +} + +type ApiResponse struct { + Description string `json:"description"` + Name string `json:"name"` + Response []interface{} `json:"response"` + Type string `json:"type"` +} + +type ApiParams struct { + Description string `json:"description"` + Length int `json:"length"` + Name string `json:"name"` + Related string `json:"related"` + Required bool `json:"required"` + Since string `json:"since"` + Type string `json:"type"` } diff --git a/vendor/github.com/xanzy/go-cloudstack/cloudstack/AccountService.go b/vendor/github.com/xanzy/go-cloudstack/cloudstack/AccountService.go index 28b50b66a..ef82b7680 100644 --- a/vendor/github.com/xanzy/go-cloudstack/cloudstack/AccountService.go +++ b/vendor/github.com/xanzy/go-cloudstack/cloudstack/AccountService.go @@ -1,5 +1,5 @@ // -// Copyright 2016, Sander van Harmelen +// Copyright 2018, Sander van Harmelen // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -24,6 +24,96 @@ import ( "strings" ) +type AddAccountToProjectParams struct { + p map[string]interface{} +} + +func (p *AddAccountToProjectParams) toURLValues() url.Values { + u := url.Values{} + if p.p == nil { + return u + } + if v, found := p.p["account"]; found { + u.Set("account", v.(string)) + } + if v, found := p.p["email"]; found { + u.Set("email", v.(string)) + } + if v, found := p.p["projectid"]; found { + u.Set("projectid", v.(string)) + } + return u +} + +func (p *AddAccountToProjectParams) SetAccount(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["account"] = v + return +} + +func (p *AddAccountToProjectParams) SetEmail(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["email"] = v + return +} + +func (p *AddAccountToProjectParams) SetProjectid(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["projectid"] = v + return +} + +// You should always use this function to get a new AddAccountToProjectParams instance, +// as then you are sure you have configured all required params +func (s *AccountService) NewAddAccountToProjectParams(projectid string) *AddAccountToProjectParams { + p := &AddAccountToProjectParams{} + p.p = make(map[string]interface{}) + p.p["projectid"] = projectid + return p +} + +// Adds account to a project +func (s *AccountService) AddAccountToProject(p *AddAccountToProjectParams) (*AddAccountToProjectResponse, error) { + resp, err := s.cs.newRequest("addAccountToProject", p.toURLValues()) + if err != nil { + return nil, err + } + + var r AddAccountToProjectResponse + if err := json.Unmarshal(resp, &r); err != nil { + return nil, err + } + + // If we have a async client, we need to wait for the async result + if s.cs.async { + b, err := s.cs.GetAsyncJobResult(r.JobID, s.cs.timeout) + if err != nil { + if err == AsyncTimeoutErr { + return &r, err + } + return nil, err + } + + if err := json.Unmarshal(b, &r); err != nil { + return nil, err + } + } + + return &r, nil +} + +type AddAccountToProjectResponse struct { + JobID string `json:"jobid"` + Displaytext string `json:"displaytext"` + Success bool `json:"success"` +} + type CreateAccountParams struct { p map[string]interface{} } @@ -69,6 +159,9 @@ func (p *CreateAccountParams) toURLValues() url.Values { if v, found := p.p["password"]; found { u.Set("password", v.(string)) } + if v, found := p.p["roleid"]; found { + u.Set("roleid", v.(string)) + } if v, found := p.p["timezone"]; found { u.Set("timezone", v.(string)) } @@ -161,6 +254,14 @@ func (p *CreateAccountParams) SetPassword(v string) { return } +func (p *CreateAccountParams) SetRoleid(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["roleid"] = v + return +} + func (p *CreateAccountParams) SetTimezone(v string) { if p.p == nil { p.p = make(map[string]interface{}) @@ -187,10 +288,9 @@ func (p *CreateAccountParams) SetUsername(v string) { // You should always use this function to get a new CreateAccountParams instance, // as then you are sure you have configured all required params -func (s *AccountService) NewCreateAccountParams(accounttype int, email string, firstname string, lastname string, password string, username string) *CreateAccountParams { +func (s *AccountService) NewCreateAccountParams(email string, firstname string, lastname string, password string, username string) *CreateAccountParams { p := &CreateAccountParams{} p.p = make(map[string]interface{}) - p.p["accounttype"] = accounttype p.p["email"] = email p.p["firstname"] = firstname p.p["lastname"] = lastname @@ -206,85 +306,99 @@ func (s *AccountService) CreateAccount(p *CreateAccountParams) (*CreateAccountRe return nil, err } + if resp, err = getRawValue(resp); err != nil { + return nil, err + } + var r CreateAccountResponse if err := json.Unmarshal(resp, &r); err != nil { return nil, err } + return &r, nil } type CreateAccountResponse struct { - Accountdetails map[string]string `json:"accountdetails,omitempty"` - Accounttype int `json:"accounttype,omitempty"` - Cpuavailable string `json:"cpuavailable,omitempty"` - Cpulimit string `json:"cpulimit,omitempty"` - Cputotal int64 `json:"cputotal,omitempty"` - Defaultzoneid string `json:"defaultzoneid,omitempty"` - Domain string `json:"domain,omitempty"` - Domainid string `json:"domainid,omitempty"` - Groups []string `json:"groups,omitempty"` - Id string `json:"id,omitempty"` - Ipavailable string `json:"ipavailable,omitempty"` - Iplimit string `json:"iplimit,omitempty"` - Iptotal int64 `json:"iptotal,omitempty"` - Iscleanuprequired bool `json:"iscleanuprequired,omitempty"` - Isdefault bool `json:"isdefault,omitempty"` - Memoryavailable string `json:"memoryavailable,omitempty"` - Memorylimit string `json:"memorylimit,omitempty"` - Memorytotal int64 `json:"memorytotal,omitempty"` - Name string `json:"name,omitempty"` - Networkavailable string `json:"networkavailable,omitempty"` - Networkdomain string `json:"networkdomain,omitempty"` - Networklimit string `json:"networklimit,omitempty"` - Networktotal int64 `json:"networktotal,omitempty"` - Primarystorageavailable string `json:"primarystorageavailable,omitempty"` - Primarystoragelimit string `json:"primarystoragelimit,omitempty"` - Primarystoragetotal int64 `json:"primarystoragetotal,omitempty"` - Projectavailable string `json:"projectavailable,omitempty"` - Projectlimit string `json:"projectlimit,omitempty"` - Projecttotal int64 `json:"projecttotal,omitempty"` - Receivedbytes int64 `json:"receivedbytes,omitempty"` - Secondarystorageavailable string `json:"secondarystorageavailable,omitempty"` - Secondarystoragelimit string `json:"secondarystoragelimit,omitempty"` - Secondarystoragetotal int64 `json:"secondarystoragetotal,omitempty"` - Sentbytes int64 `json:"sentbytes,omitempty"` - Snapshotavailable string `json:"snapshotavailable,omitempty"` - Snapshotlimit string `json:"snapshotlimit,omitempty"` - Snapshottotal int64 `json:"snapshottotal,omitempty"` - State string `json:"state,omitempty"` - Templateavailable string `json:"templateavailable,omitempty"` - Templatelimit string `json:"templatelimit,omitempty"` - Templatetotal int64 `json:"templatetotal,omitempty"` - User []struct { - Account string `json:"account,omitempty"` - Accountid string `json:"accountid,omitempty"` - Accounttype int `json:"accounttype,omitempty"` - Apikey string `json:"apikey,omitempty"` - Created string `json:"created,omitempty"` - Domain string `json:"domain,omitempty"` - Domainid string `json:"domainid,omitempty"` - Email string `json:"email,omitempty"` - Firstname string `json:"firstname,omitempty"` - Id string `json:"id,omitempty"` - Iscallerchilddomain bool `json:"iscallerchilddomain,omitempty"` - Isdefault bool `json:"isdefault,omitempty"` - Lastname string `json:"lastname,omitempty"` - Secretkey string `json:"secretkey,omitempty"` - State string `json:"state,omitempty"` - Timezone string `json:"timezone,omitempty"` - Username string `json:"username,omitempty"` - } `json:"user,omitempty"` - Vmavailable string `json:"vmavailable,omitempty"` - Vmlimit string `json:"vmlimit,omitempty"` - Vmrunning int `json:"vmrunning,omitempty"` - Vmstopped int `json:"vmstopped,omitempty"` - Vmtotal int64 `json:"vmtotal,omitempty"` - Volumeavailable string `json:"volumeavailable,omitempty"` - Volumelimit string `json:"volumelimit,omitempty"` - Volumetotal int64 `json:"volumetotal,omitempty"` - Vpcavailable string `json:"vpcavailable,omitempty"` - Vpclimit string `json:"vpclimit,omitempty"` - Vpctotal int64 `json:"vpctotal,omitempty"` + Accountdetails map[string]string `json:"accountdetails"` + Accounttype int `json:"accounttype"` + Cpuavailable string `json:"cpuavailable"` + Cpulimit string `json:"cpulimit"` + Cputotal int64 `json:"cputotal"` + Defaultzoneid string `json:"defaultzoneid"` + Domain string `json:"domain"` + Domainid string `json:"domainid"` + Groups []string `json:"groups"` + Id string `json:"id"` + Ipavailable string `json:"ipavailable"` + Iplimit string `json:"iplimit"` + Iptotal int64 `json:"iptotal"` + Iscleanuprequired bool `json:"iscleanuprequired"` + Isdefault bool `json:"isdefault"` + Memoryavailable string `json:"memoryavailable"` + Memorylimit string `json:"memorylimit"` + Memorytotal int64 `json:"memorytotal"` + Name string `json:"name"` + Networkavailable string `json:"networkavailable"` + Networkdomain string `json:"networkdomain"` + Networklimit string `json:"networklimit"` + Networktotal int64 `json:"networktotal"` + Primarystorageavailable string `json:"primarystorageavailable"` + Primarystoragelimit string `json:"primarystoragelimit"` + Primarystoragetotal int64 `json:"primarystoragetotal"` + Projectavailable string `json:"projectavailable"` + Projectlimit string `json:"projectlimit"` + Projecttotal int64 `json:"projecttotal"` + Receivedbytes int64 `json:"receivedbytes"` + Roleid string `json:"roleid"` + Rolename string `json:"rolename"` + Roletype string `json:"roletype"` + Secondarystorageavailable string `json:"secondarystorageavailable"` + Secondarystoragelimit string `json:"secondarystoragelimit"` + Secondarystoragetotal float64 `json:"secondarystoragetotal"` + Sentbytes int64 `json:"sentbytes"` + Snapshotavailable string `json:"snapshotavailable"` + Snapshotlimit string `json:"snapshotlimit"` + Snapshottotal int64 `json:"snapshottotal"` + State string `json:"state"` + Templateavailable string `json:"templateavailable"` + Templatelimit string `json:"templatelimit"` + Templatetotal int64 `json:"templatetotal"` + User []CreateAccountResponseUser `json:"user"` + Vmavailable string `json:"vmavailable"` + Vmlimit string `json:"vmlimit"` + Vmrunning int `json:"vmrunning"` + Vmstopped int `json:"vmstopped"` + Vmtotal int64 `json:"vmtotal"` + Volumeavailable string `json:"volumeavailable"` + Volumelimit string `json:"volumelimit"` + Volumetotal int64 `json:"volumetotal"` + Vpcavailable string `json:"vpcavailable"` + Vpclimit string `json:"vpclimit"` + Vpctotal int64 `json:"vpctotal"` +} + +type CreateAccountResponseUser struct { + Account string `json:"account"` + Accountid string `json:"accountid"` + Accounttype int `json:"accounttype"` + Apikey string `json:"apikey"` + Created string `json:"created"` + Domain string `json:"domain"` + Domainid string `json:"domainid"` + Email string `json:"email"` + Firstname string `json:"firstname"` + Id string `json:"id"` + Iscallerchilddomain bool `json:"iscallerchilddomain"` + Isdefault bool `json:"isdefault"` + Lastname string `json:"lastname"` + Roleid string `json:"roleid"` + Rolename string `json:"rolename"` + Roletype string `json:"roletype"` + Secretkey string `json:"secretkey"` + State string `json:"state"` + Timezone string `json:"timezone"` + Username string `json:"username"` + Usersource string `json:"usersource"` } type DeleteAccountParams struct { @@ -345,20 +459,21 @@ func (s *AccountService) DeleteAccount(p *DeleteAccountParams) (*DeleteAccountRe return nil, err } } + return &r, nil } type DeleteAccountResponse struct { - JobID string `json:"jobid,omitempty"` - Displaytext string `json:"displaytext,omitempty"` - Success bool `json:"success,omitempty"` + JobID string `json:"jobid"` + Displaytext string `json:"displaytext"` + Success bool `json:"success"` } -type UpdateAccountParams struct { +type DeleteAccountFromProjectParams struct { p map[string]interface{} } -func (p *UpdateAccountParams) toURLValues() url.Values { +func (p *DeleteAccountFromProjectParams) toURLValues() url.Values { u := url.Values{} if p.p == nil { return u @@ -366,30 +481,13 @@ func (p *UpdateAccountParams) toURLValues() url.Values { if v, found := p.p["account"]; found { u.Set("account", v.(string)) } - if v, found := p.p["accountdetails"]; found { - i := 0 - for k, vv := range v.(map[string]string) { - u.Set(fmt.Sprintf("accountdetails[%d].key", i), k) - u.Set(fmt.Sprintf("accountdetails[%d].value", i), vv) - i++ - } - } - if v, found := p.p["domainid"]; found { - u.Set("domainid", v.(string)) - } - if v, found := p.p["id"]; found { - u.Set("id", v.(string)) - } - if v, found := p.p["networkdomain"]; found { - u.Set("networkdomain", v.(string)) - } - if v, found := p.p["newname"]; found { - u.Set("newname", v.(string)) + if v, found := p.p["projectid"]; found { + u.Set("projectid", v.(string)) } return u } -func (p *UpdateAccountParams) SetAccount(v string) { +func (p *DeleteAccountFromProjectParams) SetAccount(v string) { if p.p == nil { p.p = make(map[string]interface{}) } @@ -397,141 +495,58 @@ func (p *UpdateAccountParams) SetAccount(v string) { return } -func (p *UpdateAccountParams) SetAccountdetails(v map[string]string) { +func (p *DeleteAccountFromProjectParams) SetProjectid(v string) { if p.p == nil { p.p = make(map[string]interface{}) } - p.p["accountdetails"] = v + p.p["projectid"] = v return } -func (p *UpdateAccountParams) SetDomainid(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["domainid"] = v - return -} - -func (p *UpdateAccountParams) SetId(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["id"] = v - return -} - -func (p *UpdateAccountParams) SetNetworkdomain(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["networkdomain"] = v - return -} - -func (p *UpdateAccountParams) SetNewname(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["newname"] = v - return -} - -// You should always use this function to get a new UpdateAccountParams instance, +// You should always use this function to get a new DeleteAccountFromProjectParams instance, // as then you are sure you have configured all required params -func (s *AccountService) NewUpdateAccountParams(newname string) *UpdateAccountParams { - p := &UpdateAccountParams{} +func (s *AccountService) NewDeleteAccountFromProjectParams(account string, projectid string) *DeleteAccountFromProjectParams { + p := &DeleteAccountFromProjectParams{} p.p = make(map[string]interface{}) - p.p["newname"] = newname + p.p["account"] = account + p.p["projectid"] = projectid return p } -// Updates account information for the authenticated user -func (s *AccountService) UpdateAccount(p *UpdateAccountParams) (*UpdateAccountResponse, error) { - resp, err := s.cs.newRequest("updateAccount", p.toURLValues()) +// Deletes account from the project +func (s *AccountService) DeleteAccountFromProject(p *DeleteAccountFromProjectParams) (*DeleteAccountFromProjectResponse, error) { + resp, err := s.cs.newRequest("deleteAccountFromProject", p.toURLValues()) if err != nil { return nil, err } - var r UpdateAccountResponse + var r DeleteAccountFromProjectResponse if err := json.Unmarshal(resp, &r); err != nil { return nil, err } + + // If we have a async client, we need to wait for the async result + if s.cs.async { + b, err := s.cs.GetAsyncJobResult(r.JobID, s.cs.timeout) + if err != nil { + if err == AsyncTimeoutErr { + return &r, err + } + return nil, err + } + + if err := json.Unmarshal(b, &r); err != nil { + return nil, err + } + } + return &r, nil } -type UpdateAccountResponse struct { - Accountdetails map[string]string `json:"accountdetails,omitempty"` - Accounttype int `json:"accounttype,omitempty"` - Cpuavailable string `json:"cpuavailable,omitempty"` - Cpulimit string `json:"cpulimit,omitempty"` - Cputotal int64 `json:"cputotal,omitempty"` - Defaultzoneid string `json:"defaultzoneid,omitempty"` - Domain string `json:"domain,omitempty"` - Domainid string `json:"domainid,omitempty"` - Groups []string `json:"groups,omitempty"` - Id string `json:"id,omitempty"` - Ipavailable string `json:"ipavailable,omitempty"` - Iplimit string `json:"iplimit,omitempty"` - Iptotal int64 `json:"iptotal,omitempty"` - Iscleanuprequired bool `json:"iscleanuprequired,omitempty"` - Isdefault bool `json:"isdefault,omitempty"` - Memoryavailable string `json:"memoryavailable,omitempty"` - Memorylimit string `json:"memorylimit,omitempty"` - Memorytotal int64 `json:"memorytotal,omitempty"` - Name string `json:"name,omitempty"` - Networkavailable string `json:"networkavailable,omitempty"` - Networkdomain string `json:"networkdomain,omitempty"` - Networklimit string `json:"networklimit,omitempty"` - Networktotal int64 `json:"networktotal,omitempty"` - Primarystorageavailable string `json:"primarystorageavailable,omitempty"` - Primarystoragelimit string `json:"primarystoragelimit,omitempty"` - Primarystoragetotal int64 `json:"primarystoragetotal,omitempty"` - Projectavailable string `json:"projectavailable,omitempty"` - Projectlimit string `json:"projectlimit,omitempty"` - Projecttotal int64 `json:"projecttotal,omitempty"` - Receivedbytes int64 `json:"receivedbytes,omitempty"` - Secondarystorageavailable string `json:"secondarystorageavailable,omitempty"` - Secondarystoragelimit string `json:"secondarystoragelimit,omitempty"` - Secondarystoragetotal int64 `json:"secondarystoragetotal,omitempty"` - Sentbytes int64 `json:"sentbytes,omitempty"` - Snapshotavailable string `json:"snapshotavailable,omitempty"` - Snapshotlimit string `json:"snapshotlimit,omitempty"` - Snapshottotal int64 `json:"snapshottotal,omitempty"` - State string `json:"state,omitempty"` - Templateavailable string `json:"templateavailable,omitempty"` - Templatelimit string `json:"templatelimit,omitempty"` - Templatetotal int64 `json:"templatetotal,omitempty"` - User []struct { - Account string `json:"account,omitempty"` - Accountid string `json:"accountid,omitempty"` - Accounttype int `json:"accounttype,omitempty"` - Apikey string `json:"apikey,omitempty"` - Created string `json:"created,omitempty"` - Domain string `json:"domain,omitempty"` - Domainid string `json:"domainid,omitempty"` - Email string `json:"email,omitempty"` - Firstname string `json:"firstname,omitempty"` - Id string `json:"id,omitempty"` - Iscallerchilddomain bool `json:"iscallerchilddomain,omitempty"` - Isdefault bool `json:"isdefault,omitempty"` - Lastname string `json:"lastname,omitempty"` - Secretkey string `json:"secretkey,omitempty"` - State string `json:"state,omitempty"` - Timezone string `json:"timezone,omitempty"` - Username string `json:"username,omitempty"` - } `json:"user,omitempty"` - Vmavailable string `json:"vmavailable,omitempty"` - Vmlimit string `json:"vmlimit,omitempty"` - Vmrunning int `json:"vmrunning,omitempty"` - Vmstopped int `json:"vmstopped,omitempty"` - Vmtotal int64 `json:"vmtotal,omitempty"` - Volumeavailable string `json:"volumeavailable,omitempty"` - Volumelimit string `json:"volumelimit,omitempty"` - Volumetotal int64 `json:"volumetotal,omitempty"` - Vpcavailable string `json:"vpcavailable,omitempty"` - Vpclimit string `json:"vpclimit,omitempty"` - Vpctotal int64 `json:"vpctotal,omitempty"` +type DeleteAccountFromProjectResponse struct { + JobID string `json:"jobid"` + Displaytext string `json:"displaytext"` + Success bool `json:"success"` } type DisableAccountParams struct { @@ -631,82 +646,92 @@ func (s *AccountService) DisableAccount(p *DisableAccountParams) (*DisableAccoun return nil, err } } + return &r, nil } type DisableAccountResponse struct { - JobID string `json:"jobid,omitempty"` - Accountdetails map[string]string `json:"accountdetails,omitempty"` - Accounttype int `json:"accounttype,omitempty"` - Cpuavailable string `json:"cpuavailable,omitempty"` - Cpulimit string `json:"cpulimit,omitempty"` - Cputotal int64 `json:"cputotal,omitempty"` - Defaultzoneid string `json:"defaultzoneid,omitempty"` - Domain string `json:"domain,omitempty"` - Domainid string `json:"domainid,omitempty"` - Groups []string `json:"groups,omitempty"` - Id string `json:"id,omitempty"` - Ipavailable string `json:"ipavailable,omitempty"` - Iplimit string `json:"iplimit,omitempty"` - Iptotal int64 `json:"iptotal,omitempty"` - Iscleanuprequired bool `json:"iscleanuprequired,omitempty"` - Isdefault bool `json:"isdefault,omitempty"` - Memoryavailable string `json:"memoryavailable,omitempty"` - Memorylimit string `json:"memorylimit,omitempty"` - Memorytotal int64 `json:"memorytotal,omitempty"` - Name string `json:"name,omitempty"` - Networkavailable string `json:"networkavailable,omitempty"` - Networkdomain string `json:"networkdomain,omitempty"` - Networklimit string `json:"networklimit,omitempty"` - Networktotal int64 `json:"networktotal,omitempty"` - Primarystorageavailable string `json:"primarystorageavailable,omitempty"` - Primarystoragelimit string `json:"primarystoragelimit,omitempty"` - Primarystoragetotal int64 `json:"primarystoragetotal,omitempty"` - Projectavailable string `json:"projectavailable,omitempty"` - Projectlimit string `json:"projectlimit,omitempty"` - Projecttotal int64 `json:"projecttotal,omitempty"` - Receivedbytes int64 `json:"receivedbytes,omitempty"` - Secondarystorageavailable string `json:"secondarystorageavailable,omitempty"` - Secondarystoragelimit string `json:"secondarystoragelimit,omitempty"` - Secondarystoragetotal int64 `json:"secondarystoragetotal,omitempty"` - Sentbytes int64 `json:"sentbytes,omitempty"` - Snapshotavailable string `json:"snapshotavailable,omitempty"` - Snapshotlimit string `json:"snapshotlimit,omitempty"` - Snapshottotal int64 `json:"snapshottotal,omitempty"` - State string `json:"state,omitempty"` - Templateavailable string `json:"templateavailable,omitempty"` - Templatelimit string `json:"templatelimit,omitempty"` - Templatetotal int64 `json:"templatetotal,omitempty"` - User []struct { - Account string `json:"account,omitempty"` - Accountid string `json:"accountid,omitempty"` - Accounttype int `json:"accounttype,omitempty"` - Apikey string `json:"apikey,omitempty"` - Created string `json:"created,omitempty"` - Domain string `json:"domain,omitempty"` - Domainid string `json:"domainid,omitempty"` - Email string `json:"email,omitempty"` - Firstname string `json:"firstname,omitempty"` - Id string `json:"id,omitempty"` - Iscallerchilddomain bool `json:"iscallerchilddomain,omitempty"` - Isdefault bool `json:"isdefault,omitempty"` - Lastname string `json:"lastname,omitempty"` - Secretkey string `json:"secretkey,omitempty"` - State string `json:"state,omitempty"` - Timezone string `json:"timezone,omitempty"` - Username string `json:"username,omitempty"` - } `json:"user,omitempty"` - Vmavailable string `json:"vmavailable,omitempty"` - Vmlimit string `json:"vmlimit,omitempty"` - Vmrunning int `json:"vmrunning,omitempty"` - Vmstopped int `json:"vmstopped,omitempty"` - Vmtotal int64 `json:"vmtotal,omitempty"` - Volumeavailable string `json:"volumeavailable,omitempty"` - Volumelimit string `json:"volumelimit,omitempty"` - Volumetotal int64 `json:"volumetotal,omitempty"` - Vpcavailable string `json:"vpcavailable,omitempty"` - Vpclimit string `json:"vpclimit,omitempty"` - Vpctotal int64 `json:"vpctotal,omitempty"` + JobID string `json:"jobid"` + Accountdetails map[string]string `json:"accountdetails"` + Accounttype int `json:"accounttype"` + Cpuavailable string `json:"cpuavailable"` + Cpulimit string `json:"cpulimit"` + Cputotal int64 `json:"cputotal"` + Defaultzoneid string `json:"defaultzoneid"` + Domain string `json:"domain"` + Domainid string `json:"domainid"` + Groups []string `json:"groups"` + Id string `json:"id"` + Ipavailable string `json:"ipavailable"` + Iplimit string `json:"iplimit"` + Iptotal int64 `json:"iptotal"` + Iscleanuprequired bool `json:"iscleanuprequired"` + Isdefault bool `json:"isdefault"` + Memoryavailable string `json:"memoryavailable"` + Memorylimit string `json:"memorylimit"` + Memorytotal int64 `json:"memorytotal"` + Name string `json:"name"` + Networkavailable string `json:"networkavailable"` + Networkdomain string `json:"networkdomain"` + Networklimit string `json:"networklimit"` + Networktotal int64 `json:"networktotal"` + Primarystorageavailable string `json:"primarystorageavailable"` + Primarystoragelimit string `json:"primarystoragelimit"` + Primarystoragetotal int64 `json:"primarystoragetotal"` + Projectavailable string `json:"projectavailable"` + Projectlimit string `json:"projectlimit"` + Projecttotal int64 `json:"projecttotal"` + Receivedbytes int64 `json:"receivedbytes"` + Roleid string `json:"roleid"` + Rolename string `json:"rolename"` + Roletype string `json:"roletype"` + Secondarystorageavailable string `json:"secondarystorageavailable"` + Secondarystoragelimit string `json:"secondarystoragelimit"` + Secondarystoragetotal float64 `json:"secondarystoragetotal"` + Sentbytes int64 `json:"sentbytes"` + Snapshotavailable string `json:"snapshotavailable"` + Snapshotlimit string `json:"snapshotlimit"` + Snapshottotal int64 `json:"snapshottotal"` + State string `json:"state"` + Templateavailable string `json:"templateavailable"` + Templatelimit string `json:"templatelimit"` + Templatetotal int64 `json:"templatetotal"` + User []DisableAccountResponseUser `json:"user"` + Vmavailable string `json:"vmavailable"` + Vmlimit string `json:"vmlimit"` + Vmrunning int `json:"vmrunning"` + Vmstopped int `json:"vmstopped"` + Vmtotal int64 `json:"vmtotal"` + Volumeavailable string `json:"volumeavailable"` + Volumelimit string `json:"volumelimit"` + Volumetotal int64 `json:"volumetotal"` + Vpcavailable string `json:"vpcavailable"` + Vpclimit string `json:"vpclimit"` + Vpctotal int64 `json:"vpctotal"` +} + +type DisableAccountResponseUser struct { + Account string `json:"account"` + Accountid string `json:"accountid"` + Accounttype int `json:"accounttype"` + Apikey string `json:"apikey"` + Created string `json:"created"` + Domain string `json:"domain"` + Domainid string `json:"domainid"` + Email string `json:"email"` + Firstname string `json:"firstname"` + Id string `json:"id"` + Iscallerchilddomain bool `json:"iscallerchilddomain"` + Isdefault bool `json:"isdefault"` + Lastname string `json:"lastname"` + Roleid string `json:"roleid"` + Rolename string `json:"rolename"` + Roletype string `json:"roletype"` + Secretkey string `json:"secretkey"` + State string `json:"state"` + Timezone string `json:"timezone"` + Username string `json:"username"` + Usersource string `json:"usersource"` } type EnableAccountParams struct { @@ -773,213 +798,154 @@ func (s *AccountService) EnableAccount(p *EnableAccountParams) (*EnableAccountRe if err := json.Unmarshal(resp, &r); err != nil { return nil, err } + return &r, nil } type EnableAccountResponse struct { - Accountdetails map[string]string `json:"accountdetails,omitempty"` - Accounttype int `json:"accounttype,omitempty"` - Cpuavailable string `json:"cpuavailable,omitempty"` - Cpulimit string `json:"cpulimit,omitempty"` - Cputotal int64 `json:"cputotal,omitempty"` - Defaultzoneid string `json:"defaultzoneid,omitempty"` - Domain string `json:"domain,omitempty"` - Domainid string `json:"domainid,omitempty"` - Groups []string `json:"groups,omitempty"` - Id string `json:"id,omitempty"` - Ipavailable string `json:"ipavailable,omitempty"` - Iplimit string `json:"iplimit,omitempty"` - Iptotal int64 `json:"iptotal,omitempty"` - Iscleanuprequired bool `json:"iscleanuprequired,omitempty"` - Isdefault bool `json:"isdefault,omitempty"` - Memoryavailable string `json:"memoryavailable,omitempty"` - Memorylimit string `json:"memorylimit,omitempty"` - Memorytotal int64 `json:"memorytotal,omitempty"` - Name string `json:"name,omitempty"` - Networkavailable string `json:"networkavailable,omitempty"` - Networkdomain string `json:"networkdomain,omitempty"` - Networklimit string `json:"networklimit,omitempty"` - Networktotal int64 `json:"networktotal,omitempty"` - Primarystorageavailable string `json:"primarystorageavailable,omitempty"` - Primarystoragelimit string `json:"primarystoragelimit,omitempty"` - Primarystoragetotal int64 `json:"primarystoragetotal,omitempty"` - Projectavailable string `json:"projectavailable,omitempty"` - Projectlimit string `json:"projectlimit,omitempty"` - Projecttotal int64 `json:"projecttotal,omitempty"` - Receivedbytes int64 `json:"receivedbytes,omitempty"` - Secondarystorageavailable string `json:"secondarystorageavailable,omitempty"` - Secondarystoragelimit string `json:"secondarystoragelimit,omitempty"` - Secondarystoragetotal int64 `json:"secondarystoragetotal,omitempty"` - Sentbytes int64 `json:"sentbytes,omitempty"` - Snapshotavailable string `json:"snapshotavailable,omitempty"` - Snapshotlimit string `json:"snapshotlimit,omitempty"` - Snapshottotal int64 `json:"snapshottotal,omitempty"` - State string `json:"state,omitempty"` - Templateavailable string `json:"templateavailable,omitempty"` - Templatelimit string `json:"templatelimit,omitempty"` - Templatetotal int64 `json:"templatetotal,omitempty"` - User []struct { - Account string `json:"account,omitempty"` - Accountid string `json:"accountid,omitempty"` - Accounttype int `json:"accounttype,omitempty"` - Apikey string `json:"apikey,omitempty"` - Created string `json:"created,omitempty"` - Domain string `json:"domain,omitempty"` - Domainid string `json:"domainid,omitempty"` - Email string `json:"email,omitempty"` - Firstname string `json:"firstname,omitempty"` - Id string `json:"id,omitempty"` - Iscallerchilddomain bool `json:"iscallerchilddomain,omitempty"` - Isdefault bool `json:"isdefault,omitempty"` - Lastname string `json:"lastname,omitempty"` - Secretkey string `json:"secretkey,omitempty"` - State string `json:"state,omitempty"` - Timezone string `json:"timezone,omitempty"` - Username string `json:"username,omitempty"` - } `json:"user,omitempty"` - Vmavailable string `json:"vmavailable,omitempty"` - Vmlimit string `json:"vmlimit,omitempty"` - Vmrunning int `json:"vmrunning,omitempty"` - Vmstopped int `json:"vmstopped,omitempty"` - Vmtotal int64 `json:"vmtotal,omitempty"` - Volumeavailable string `json:"volumeavailable,omitempty"` - Volumelimit string `json:"volumelimit,omitempty"` - Volumetotal int64 `json:"volumetotal,omitempty"` - Vpcavailable string `json:"vpcavailable,omitempty"` - Vpclimit string `json:"vpclimit,omitempty"` - Vpctotal int64 `json:"vpctotal,omitempty"` + Accountdetails map[string]string `json:"accountdetails"` + Accounttype int `json:"accounttype"` + Cpuavailable string `json:"cpuavailable"` + Cpulimit string `json:"cpulimit"` + Cputotal int64 `json:"cputotal"` + Defaultzoneid string `json:"defaultzoneid"` + Domain string `json:"domain"` + Domainid string `json:"domainid"` + Groups []string `json:"groups"` + Id string `json:"id"` + Ipavailable string `json:"ipavailable"` + Iplimit string `json:"iplimit"` + Iptotal int64 `json:"iptotal"` + Iscleanuprequired bool `json:"iscleanuprequired"` + Isdefault bool `json:"isdefault"` + Memoryavailable string `json:"memoryavailable"` + Memorylimit string `json:"memorylimit"` + Memorytotal int64 `json:"memorytotal"` + Name string `json:"name"` + Networkavailable string `json:"networkavailable"` + Networkdomain string `json:"networkdomain"` + Networklimit string `json:"networklimit"` + Networktotal int64 `json:"networktotal"` + Primarystorageavailable string `json:"primarystorageavailable"` + Primarystoragelimit string `json:"primarystoragelimit"` + Primarystoragetotal int64 `json:"primarystoragetotal"` + Projectavailable string `json:"projectavailable"` + Projectlimit string `json:"projectlimit"` + Projecttotal int64 `json:"projecttotal"` + Receivedbytes int64 `json:"receivedbytes"` + Roleid string `json:"roleid"` + Rolename string `json:"rolename"` + Roletype string `json:"roletype"` + Secondarystorageavailable string `json:"secondarystorageavailable"` + Secondarystoragelimit string `json:"secondarystoragelimit"` + Secondarystoragetotal float64 `json:"secondarystoragetotal"` + Sentbytes int64 `json:"sentbytes"` + Snapshotavailable string `json:"snapshotavailable"` + Snapshotlimit string `json:"snapshotlimit"` + Snapshottotal int64 `json:"snapshottotal"` + State string `json:"state"` + Templateavailable string `json:"templateavailable"` + Templatelimit string `json:"templatelimit"` + Templatetotal int64 `json:"templatetotal"` + User []EnableAccountResponseUser `json:"user"` + Vmavailable string `json:"vmavailable"` + Vmlimit string `json:"vmlimit"` + Vmrunning int `json:"vmrunning"` + Vmstopped int `json:"vmstopped"` + Vmtotal int64 `json:"vmtotal"` + Volumeavailable string `json:"volumeavailable"` + Volumelimit string `json:"volumelimit"` + Volumetotal int64 `json:"volumetotal"` + Vpcavailable string `json:"vpcavailable"` + Vpclimit string `json:"vpclimit"` + Vpctotal int64 `json:"vpctotal"` } -type LockAccountParams struct { +type EnableAccountResponseUser struct { + Account string `json:"account"` + Accountid string `json:"accountid"` + Accounttype int `json:"accounttype"` + Apikey string `json:"apikey"` + Created string `json:"created"` + Domain string `json:"domain"` + Domainid string `json:"domainid"` + Email string `json:"email"` + Firstname string `json:"firstname"` + Id string `json:"id"` + Iscallerchilddomain bool `json:"iscallerchilddomain"` + Isdefault bool `json:"isdefault"` + Lastname string `json:"lastname"` + Roleid string `json:"roleid"` + Rolename string `json:"rolename"` + Roletype string `json:"roletype"` + Secretkey string `json:"secretkey"` + State string `json:"state"` + Timezone string `json:"timezone"` + Username string `json:"username"` + Usersource string `json:"usersource"` +} + +type GetSolidFireAccountIdParams struct { p map[string]interface{} } -func (p *LockAccountParams) toURLValues() url.Values { +func (p *GetSolidFireAccountIdParams) toURLValues() url.Values { u := url.Values{} if p.p == nil { return u } - if v, found := p.p["account"]; found { - u.Set("account", v.(string)) + if v, found := p.p["accountid"]; found { + u.Set("accountid", v.(string)) } - if v, found := p.p["domainid"]; found { - u.Set("domainid", v.(string)) + if v, found := p.p["storageid"]; found { + u.Set("storageid", v.(string)) } return u } -func (p *LockAccountParams) SetAccount(v string) { +func (p *GetSolidFireAccountIdParams) SetAccountid(v string) { if p.p == nil { p.p = make(map[string]interface{}) } - p.p["account"] = v + p.p["accountid"] = v return } -func (p *LockAccountParams) SetDomainid(v string) { +func (p *GetSolidFireAccountIdParams) SetStorageid(v string) { if p.p == nil { p.p = make(map[string]interface{}) } - p.p["domainid"] = v + p.p["storageid"] = v return } -// You should always use this function to get a new LockAccountParams instance, +// You should always use this function to get a new GetSolidFireAccountIdParams instance, // as then you are sure you have configured all required params -func (s *AccountService) NewLockAccountParams(account string, domainid string) *LockAccountParams { - p := &LockAccountParams{} +func (s *AccountService) NewGetSolidFireAccountIdParams(accountid string, storageid string) *GetSolidFireAccountIdParams { + p := &GetSolidFireAccountIdParams{} p.p = make(map[string]interface{}) - p.p["account"] = account - p.p["domainid"] = domainid + p.p["accountid"] = accountid + p.p["storageid"] = storageid return p } -// This deprecated function used to locks an account. Look for the API DisableAccount instead -func (s *AccountService) LockAccount(p *LockAccountParams) (*LockAccountResponse, error) { - resp, err := s.cs.newRequest("lockAccount", p.toURLValues()) +// Get SolidFire Account ID +func (s *AccountService) GetSolidFireAccountId(p *GetSolidFireAccountIdParams) (*GetSolidFireAccountIdResponse, error) { + resp, err := s.cs.newRequest("getSolidFireAccountId", p.toURLValues()) if err != nil { return nil, err } - var r LockAccountResponse + var r GetSolidFireAccountIdResponse if err := json.Unmarshal(resp, &r); err != nil { return nil, err } + return &r, nil } -type LockAccountResponse struct { - Accountdetails map[string]string `json:"accountdetails,omitempty"` - Accounttype int `json:"accounttype,omitempty"` - Cpuavailable string `json:"cpuavailable,omitempty"` - Cpulimit string `json:"cpulimit,omitempty"` - Cputotal int64 `json:"cputotal,omitempty"` - Defaultzoneid string `json:"defaultzoneid,omitempty"` - Domain string `json:"domain,omitempty"` - Domainid string `json:"domainid,omitempty"` - Groups []string `json:"groups,omitempty"` - Id string `json:"id,omitempty"` - Ipavailable string `json:"ipavailable,omitempty"` - Iplimit string `json:"iplimit,omitempty"` - Iptotal int64 `json:"iptotal,omitempty"` - Iscleanuprequired bool `json:"iscleanuprequired,omitempty"` - Isdefault bool `json:"isdefault,omitempty"` - Memoryavailable string `json:"memoryavailable,omitempty"` - Memorylimit string `json:"memorylimit,omitempty"` - Memorytotal int64 `json:"memorytotal,omitempty"` - Name string `json:"name,omitempty"` - Networkavailable string `json:"networkavailable,omitempty"` - Networkdomain string `json:"networkdomain,omitempty"` - Networklimit string `json:"networklimit,omitempty"` - Networktotal int64 `json:"networktotal,omitempty"` - Primarystorageavailable string `json:"primarystorageavailable,omitempty"` - Primarystoragelimit string `json:"primarystoragelimit,omitempty"` - Primarystoragetotal int64 `json:"primarystoragetotal,omitempty"` - Projectavailable string `json:"projectavailable,omitempty"` - Projectlimit string `json:"projectlimit,omitempty"` - Projecttotal int64 `json:"projecttotal,omitempty"` - Receivedbytes int64 `json:"receivedbytes,omitempty"` - Secondarystorageavailable string `json:"secondarystorageavailable,omitempty"` - Secondarystoragelimit string `json:"secondarystoragelimit,omitempty"` - Secondarystoragetotal int64 `json:"secondarystoragetotal,omitempty"` - Sentbytes int64 `json:"sentbytes,omitempty"` - Snapshotavailable string `json:"snapshotavailable,omitempty"` - Snapshotlimit string `json:"snapshotlimit,omitempty"` - Snapshottotal int64 `json:"snapshottotal,omitempty"` - State string `json:"state,omitempty"` - Templateavailable string `json:"templateavailable,omitempty"` - Templatelimit string `json:"templatelimit,omitempty"` - Templatetotal int64 `json:"templatetotal,omitempty"` - User []struct { - Account string `json:"account,omitempty"` - Accountid string `json:"accountid,omitempty"` - Accounttype int `json:"accounttype,omitempty"` - Apikey string `json:"apikey,omitempty"` - Created string `json:"created,omitempty"` - Domain string `json:"domain,omitempty"` - Domainid string `json:"domainid,omitempty"` - Email string `json:"email,omitempty"` - Firstname string `json:"firstname,omitempty"` - Id string `json:"id,omitempty"` - Iscallerchilddomain bool `json:"iscallerchilddomain,omitempty"` - Isdefault bool `json:"isdefault,omitempty"` - Lastname string `json:"lastname,omitempty"` - Secretkey string `json:"secretkey,omitempty"` - State string `json:"state,omitempty"` - Timezone string `json:"timezone,omitempty"` - Username string `json:"username,omitempty"` - } `json:"user,omitempty"` - Vmavailable string `json:"vmavailable,omitempty"` - Vmlimit string `json:"vmlimit,omitempty"` - Vmrunning int `json:"vmrunning,omitempty"` - Vmstopped int `json:"vmstopped,omitempty"` - Vmtotal int64 `json:"vmtotal,omitempty"` - Volumeavailable string `json:"volumeavailable,omitempty"` - Volumelimit string `json:"volumelimit,omitempty"` - Volumetotal int64 `json:"volumetotal,omitempty"` - Vpcavailable string `json:"vpcavailable,omitempty"` - Vpclimit string `json:"vpclimit,omitempty"` - Vpctotal int64 `json:"vpctotal,omitempty"` +type GetSolidFireAccountIdResponse struct { + SolidFireAccountId int64 `json:"solidFireAccountId"` } type ListAccountsParams struct { @@ -1136,7 +1102,7 @@ func (s *AccountService) GetAccountID(name string, opts ...OptionFunc) (string, p.p["name"] = name - for _, fn := range opts { + for _, fn := range append(s.cs.options, opts...) { if err := fn(s.cs, p); err != nil { return "", -1, err } @@ -1186,7 +1152,7 @@ func (s *AccountService) GetAccountByID(id string, opts ...OptionFunc) (*Account p.p["id"] = id - for _, fn := range opts { + for _, fn := range append(s.cs.options, opts...) { if err := fn(s.cs, p); err != nil { return nil, -1, err } @@ -1223,6 +1189,7 @@ func (s *AccountService) ListAccounts(p *ListAccountsParams) (*ListAccountsRespo if err := json.Unmarshal(resp, &r); err != nil { return nil, err } + return &r, nil } @@ -1232,410 +1199,86 @@ type ListAccountsResponse struct { } type Account struct { - Accountdetails map[string]string `json:"accountdetails,omitempty"` - Accounttype int `json:"accounttype,omitempty"` - Cpuavailable string `json:"cpuavailable,omitempty"` - Cpulimit string `json:"cpulimit,omitempty"` - Cputotal int64 `json:"cputotal,omitempty"` - Defaultzoneid string `json:"defaultzoneid,omitempty"` - Domain string `json:"domain,omitempty"` - Domainid string `json:"domainid,omitempty"` - Groups []string `json:"groups,omitempty"` - Id string `json:"id,omitempty"` - Ipavailable string `json:"ipavailable,omitempty"` - Iplimit string `json:"iplimit,omitempty"` - Iptotal int64 `json:"iptotal,omitempty"` - Iscleanuprequired bool `json:"iscleanuprequired,omitempty"` - Isdefault bool `json:"isdefault,omitempty"` - Memoryavailable string `json:"memoryavailable,omitempty"` - Memorylimit string `json:"memorylimit,omitempty"` - Memorytotal int64 `json:"memorytotal,omitempty"` - Name string `json:"name,omitempty"` - Networkavailable string `json:"networkavailable,omitempty"` - Networkdomain string `json:"networkdomain,omitempty"` - Networklimit string `json:"networklimit,omitempty"` - Networktotal int64 `json:"networktotal,omitempty"` - Primarystorageavailable string `json:"primarystorageavailable,omitempty"` - Primarystoragelimit string `json:"primarystoragelimit,omitempty"` - Primarystoragetotal int64 `json:"primarystoragetotal,omitempty"` - Projectavailable string `json:"projectavailable,omitempty"` - Projectlimit string `json:"projectlimit,omitempty"` - Projecttotal int64 `json:"projecttotal,omitempty"` - Receivedbytes int64 `json:"receivedbytes,omitempty"` - Secondarystorageavailable string `json:"secondarystorageavailable,omitempty"` - Secondarystoragelimit string `json:"secondarystoragelimit,omitempty"` - Secondarystoragetotal int64 `json:"secondarystoragetotal,omitempty"` - Sentbytes int64 `json:"sentbytes,omitempty"` - Snapshotavailable string `json:"snapshotavailable,omitempty"` - Snapshotlimit string `json:"snapshotlimit,omitempty"` - Snapshottotal int64 `json:"snapshottotal,omitempty"` - State string `json:"state,omitempty"` - Templateavailable string `json:"templateavailable,omitempty"` - Templatelimit string `json:"templatelimit,omitempty"` - Templatetotal int64 `json:"templatetotal,omitempty"` - User []struct { - Account string `json:"account,omitempty"` - Accountid string `json:"accountid,omitempty"` - Accounttype int `json:"accounttype,omitempty"` - Apikey string `json:"apikey,omitempty"` - Created string `json:"created,omitempty"` - Domain string `json:"domain,omitempty"` - Domainid string `json:"domainid,omitempty"` - Email string `json:"email,omitempty"` - Firstname string `json:"firstname,omitempty"` - Id string `json:"id,omitempty"` - Iscallerchilddomain bool `json:"iscallerchilddomain,omitempty"` - Isdefault bool `json:"isdefault,omitempty"` - Lastname string `json:"lastname,omitempty"` - Secretkey string `json:"secretkey,omitempty"` - State string `json:"state,omitempty"` - Timezone string `json:"timezone,omitempty"` - Username string `json:"username,omitempty"` - } `json:"user,omitempty"` - Vmavailable string `json:"vmavailable,omitempty"` - Vmlimit string `json:"vmlimit,omitempty"` - Vmrunning int `json:"vmrunning,omitempty"` - Vmstopped int `json:"vmstopped,omitempty"` - Vmtotal int64 `json:"vmtotal,omitempty"` - Volumeavailable string `json:"volumeavailable,omitempty"` - Volumelimit string `json:"volumelimit,omitempty"` - Volumetotal int64 `json:"volumetotal,omitempty"` - Vpcavailable string `json:"vpcavailable,omitempty"` - Vpclimit string `json:"vpclimit,omitempty"` - Vpctotal int64 `json:"vpctotal,omitempty"` + Accountdetails map[string]string `json:"accountdetails"` + Accounttype int `json:"accounttype"` + Cpuavailable string `json:"cpuavailable"` + Cpulimit string `json:"cpulimit"` + Cputotal int64 `json:"cputotal"` + Defaultzoneid string `json:"defaultzoneid"` + Domain string `json:"domain"` + Domainid string `json:"domainid"` + Groups []string `json:"groups"` + Id string `json:"id"` + Ipavailable string `json:"ipavailable"` + Iplimit string `json:"iplimit"` + Iptotal int64 `json:"iptotal"` + Iscleanuprequired bool `json:"iscleanuprequired"` + Isdefault bool `json:"isdefault"` + Memoryavailable string `json:"memoryavailable"` + Memorylimit string `json:"memorylimit"` + Memorytotal int64 `json:"memorytotal"` + Name string `json:"name"` + Networkavailable string `json:"networkavailable"` + Networkdomain string `json:"networkdomain"` + Networklimit string `json:"networklimit"` + Networktotal int64 `json:"networktotal"` + Primarystorageavailable string `json:"primarystorageavailable"` + Primarystoragelimit string `json:"primarystoragelimit"` + Primarystoragetotal int64 `json:"primarystoragetotal"` + Projectavailable string `json:"projectavailable"` + Projectlimit string `json:"projectlimit"` + Projecttotal int64 `json:"projecttotal"` + Receivedbytes int64 `json:"receivedbytes"` + Roleid string `json:"roleid"` + Rolename string `json:"rolename"` + Roletype string `json:"roletype"` + Secondarystorageavailable string `json:"secondarystorageavailable"` + Secondarystoragelimit string `json:"secondarystoragelimit"` + Secondarystoragetotal float64 `json:"secondarystoragetotal"` + Sentbytes int64 `json:"sentbytes"` + Snapshotavailable string `json:"snapshotavailable"` + Snapshotlimit string `json:"snapshotlimit"` + Snapshottotal int64 `json:"snapshottotal"` + State string `json:"state"` + Templateavailable string `json:"templateavailable"` + Templatelimit string `json:"templatelimit"` + Templatetotal int64 `json:"templatetotal"` + User []AccountUser `json:"user"` + Vmavailable string `json:"vmavailable"` + Vmlimit string `json:"vmlimit"` + Vmrunning int `json:"vmrunning"` + Vmstopped int `json:"vmstopped"` + Vmtotal int64 `json:"vmtotal"` + Volumeavailable string `json:"volumeavailable"` + Volumelimit string `json:"volumelimit"` + Volumetotal int64 `json:"volumetotal"` + Vpcavailable string `json:"vpcavailable"` + Vpclimit string `json:"vpclimit"` + Vpctotal int64 `json:"vpctotal"` } -type MarkDefaultZoneForAccountParams struct { - p map[string]interface{} -} - -func (p *MarkDefaultZoneForAccountParams) toURLValues() url.Values { - u := url.Values{} - if p.p == nil { - return u - } - if v, found := p.p["account"]; found { - u.Set("account", v.(string)) - } - if v, found := p.p["domainid"]; found { - u.Set("domainid", v.(string)) - } - if v, found := p.p["zoneid"]; found { - u.Set("zoneid", v.(string)) - } - return u -} - -func (p *MarkDefaultZoneForAccountParams) SetAccount(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["account"] = v - return -} - -func (p *MarkDefaultZoneForAccountParams) SetDomainid(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["domainid"] = v - return -} - -func (p *MarkDefaultZoneForAccountParams) SetZoneid(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["zoneid"] = v - return -} - -// You should always use this function to get a new MarkDefaultZoneForAccountParams instance, -// as then you are sure you have configured all required params -func (s *AccountService) NewMarkDefaultZoneForAccountParams(account string, domainid string, zoneid string) *MarkDefaultZoneForAccountParams { - p := &MarkDefaultZoneForAccountParams{} - p.p = make(map[string]interface{}) - p.p["account"] = account - p.p["domainid"] = domainid - p.p["zoneid"] = zoneid - return p -} - -// Marks a default zone for this account -func (s *AccountService) MarkDefaultZoneForAccount(p *MarkDefaultZoneForAccountParams) (*MarkDefaultZoneForAccountResponse, error) { - resp, err := s.cs.newRequest("markDefaultZoneForAccount", p.toURLValues()) - if err != nil { - return nil, err - } - - var r MarkDefaultZoneForAccountResponse - if err := json.Unmarshal(resp, &r); err != nil { - return nil, err - } - - // If we have a async client, we need to wait for the async result - if s.cs.async { - b, err := s.cs.GetAsyncJobResult(r.JobID, s.cs.timeout) - if err != nil { - if err == AsyncTimeoutErr { - return &r, err - } - return nil, err - } - - b, err = getRawValue(b) - if err != nil { - return nil, err - } - - if err := json.Unmarshal(b, &r); err != nil { - return nil, err - } - } - return &r, nil -} - -type MarkDefaultZoneForAccountResponse struct { - JobID string `json:"jobid,omitempty"` - Accountdetails map[string]string `json:"accountdetails,omitempty"` - Accounttype int `json:"accounttype,omitempty"` - Cpuavailable string `json:"cpuavailable,omitempty"` - Cpulimit string `json:"cpulimit,omitempty"` - Cputotal int64 `json:"cputotal,omitempty"` - Defaultzoneid string `json:"defaultzoneid,omitempty"` - Domain string `json:"domain,omitempty"` - Domainid string `json:"domainid,omitempty"` - Groups []string `json:"groups,omitempty"` - Id string `json:"id,omitempty"` - Ipavailable string `json:"ipavailable,omitempty"` - Iplimit string `json:"iplimit,omitempty"` - Iptotal int64 `json:"iptotal,omitempty"` - Iscleanuprequired bool `json:"iscleanuprequired,omitempty"` - Isdefault bool `json:"isdefault,omitempty"` - Memoryavailable string `json:"memoryavailable,omitempty"` - Memorylimit string `json:"memorylimit,omitempty"` - Memorytotal int64 `json:"memorytotal,omitempty"` - Name string `json:"name,omitempty"` - Networkavailable string `json:"networkavailable,omitempty"` - Networkdomain string `json:"networkdomain,omitempty"` - Networklimit string `json:"networklimit,omitempty"` - Networktotal int64 `json:"networktotal,omitempty"` - Primarystorageavailable string `json:"primarystorageavailable,omitempty"` - Primarystoragelimit string `json:"primarystoragelimit,omitempty"` - Primarystoragetotal int64 `json:"primarystoragetotal,omitempty"` - Projectavailable string `json:"projectavailable,omitempty"` - Projectlimit string `json:"projectlimit,omitempty"` - Projecttotal int64 `json:"projecttotal,omitempty"` - Receivedbytes int64 `json:"receivedbytes,omitempty"` - Secondarystorageavailable string `json:"secondarystorageavailable,omitempty"` - Secondarystoragelimit string `json:"secondarystoragelimit,omitempty"` - Secondarystoragetotal int64 `json:"secondarystoragetotal,omitempty"` - Sentbytes int64 `json:"sentbytes,omitempty"` - Snapshotavailable string `json:"snapshotavailable,omitempty"` - Snapshotlimit string `json:"snapshotlimit,omitempty"` - Snapshottotal int64 `json:"snapshottotal,omitempty"` - State string `json:"state,omitempty"` - Templateavailable string `json:"templateavailable,omitempty"` - Templatelimit string `json:"templatelimit,omitempty"` - Templatetotal int64 `json:"templatetotal,omitempty"` - User []struct { - Account string `json:"account,omitempty"` - Accountid string `json:"accountid,omitempty"` - Accounttype int `json:"accounttype,omitempty"` - Apikey string `json:"apikey,omitempty"` - Created string `json:"created,omitempty"` - Domain string `json:"domain,omitempty"` - Domainid string `json:"domainid,omitempty"` - Email string `json:"email,omitempty"` - Firstname string `json:"firstname,omitempty"` - Id string `json:"id,omitempty"` - Iscallerchilddomain bool `json:"iscallerchilddomain,omitempty"` - Isdefault bool `json:"isdefault,omitempty"` - Lastname string `json:"lastname,omitempty"` - Secretkey string `json:"secretkey,omitempty"` - State string `json:"state,omitempty"` - Timezone string `json:"timezone,omitempty"` - Username string `json:"username,omitempty"` - } `json:"user,omitempty"` - Vmavailable string `json:"vmavailable,omitempty"` - Vmlimit string `json:"vmlimit,omitempty"` - Vmrunning int `json:"vmrunning,omitempty"` - Vmstopped int `json:"vmstopped,omitempty"` - Vmtotal int64 `json:"vmtotal,omitempty"` - Volumeavailable string `json:"volumeavailable,omitempty"` - Volumelimit string `json:"volumelimit,omitempty"` - Volumetotal int64 `json:"volumetotal,omitempty"` - Vpcavailable string `json:"vpcavailable,omitempty"` - Vpclimit string `json:"vpclimit,omitempty"` - Vpctotal int64 `json:"vpctotal,omitempty"` -} - -type AddAccountToProjectParams struct { - p map[string]interface{} -} - -func (p *AddAccountToProjectParams) toURLValues() url.Values { - u := url.Values{} - if p.p == nil { - return u - } - if v, found := p.p["account"]; found { - u.Set("account", v.(string)) - } - if v, found := p.p["email"]; found { - u.Set("email", v.(string)) - } - if v, found := p.p["projectid"]; found { - u.Set("projectid", v.(string)) - } - return u -} - -func (p *AddAccountToProjectParams) SetAccount(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["account"] = v - return -} - -func (p *AddAccountToProjectParams) SetEmail(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["email"] = v - return -} - -func (p *AddAccountToProjectParams) SetProjectid(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["projectid"] = v - return -} - -// You should always use this function to get a new AddAccountToProjectParams instance, -// as then you are sure you have configured all required params -func (s *AccountService) NewAddAccountToProjectParams(projectid string) *AddAccountToProjectParams { - p := &AddAccountToProjectParams{} - p.p = make(map[string]interface{}) - p.p["projectid"] = projectid - return p -} - -// Adds account to a project -func (s *AccountService) AddAccountToProject(p *AddAccountToProjectParams) (*AddAccountToProjectResponse, error) { - resp, err := s.cs.newRequest("addAccountToProject", p.toURLValues()) - if err != nil { - return nil, err - } - - var r AddAccountToProjectResponse - if err := json.Unmarshal(resp, &r); err != nil { - return nil, err - } - - // If we have a async client, we need to wait for the async result - if s.cs.async { - b, err := s.cs.GetAsyncJobResult(r.JobID, s.cs.timeout) - if err != nil { - if err == AsyncTimeoutErr { - return &r, err - } - return nil, err - } - - if err := json.Unmarshal(b, &r); err != nil { - return nil, err - } - } - return &r, nil -} - -type AddAccountToProjectResponse struct { - JobID string `json:"jobid,omitempty"` - Displaytext string `json:"displaytext,omitempty"` - Success bool `json:"success,omitempty"` -} - -type DeleteAccountFromProjectParams struct { - p map[string]interface{} -} - -func (p *DeleteAccountFromProjectParams) toURLValues() url.Values { - u := url.Values{} - if p.p == nil { - return u - } - if v, found := p.p["account"]; found { - u.Set("account", v.(string)) - } - if v, found := p.p["projectid"]; found { - u.Set("projectid", v.(string)) - } - return u -} - -func (p *DeleteAccountFromProjectParams) SetAccount(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["account"] = v - return -} - -func (p *DeleteAccountFromProjectParams) SetProjectid(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["projectid"] = v - return -} - -// You should always use this function to get a new DeleteAccountFromProjectParams instance, -// as then you are sure you have configured all required params -func (s *AccountService) NewDeleteAccountFromProjectParams(account string, projectid string) *DeleteAccountFromProjectParams { - p := &DeleteAccountFromProjectParams{} - p.p = make(map[string]interface{}) - p.p["account"] = account - p.p["projectid"] = projectid - return p -} - -// Deletes account from the project -func (s *AccountService) DeleteAccountFromProject(p *DeleteAccountFromProjectParams) (*DeleteAccountFromProjectResponse, error) { - resp, err := s.cs.newRequest("deleteAccountFromProject", p.toURLValues()) - if err != nil { - return nil, err - } - - var r DeleteAccountFromProjectResponse - if err := json.Unmarshal(resp, &r); err != nil { - return nil, err - } - - // If we have a async client, we need to wait for the async result - if s.cs.async { - b, err := s.cs.GetAsyncJobResult(r.JobID, s.cs.timeout) - if err != nil { - if err == AsyncTimeoutErr { - return &r, err - } - return nil, err - } - - if err := json.Unmarshal(b, &r); err != nil { - return nil, err - } - } - return &r, nil -} - -type DeleteAccountFromProjectResponse struct { - JobID string `json:"jobid,omitempty"` - Displaytext string `json:"displaytext,omitempty"` - Success bool `json:"success,omitempty"` +type AccountUser struct { + Account string `json:"account"` + Accountid string `json:"accountid"` + Accounttype int `json:"accounttype"` + Apikey string `json:"apikey"` + Created string `json:"created"` + Domain string `json:"domain"` + Domainid string `json:"domainid"` + Email string `json:"email"` + Firstname string `json:"firstname"` + Id string `json:"id"` + Iscallerchilddomain bool `json:"iscallerchilddomain"` + Isdefault bool `json:"isdefault"` + Lastname string `json:"lastname"` + Roleid string `json:"roleid"` + Rolename string `json:"rolename"` + Roletype string `json:"roletype"` + Secretkey string `json:"secretkey"` + State string `json:"state"` + Timezone string `json:"timezone"` + Username string `json:"username"` + Usersource string `json:"usersource"` } type ListProjectAccountsParams struct { @@ -1735,7 +1378,7 @@ func (s *AccountService) GetProjectAccountID(keyword string, projectid string, o p.p["keyword"] = keyword p.p["projectid"] = projectid - for _, fn := range opts { + for _, fn := range append(s.cs.options, opts...) { if err := fn(s.cs, p); err != nil { return "", -1, err } @@ -1775,6 +1418,7 @@ func (s *AccountService) ListProjectAccounts(p *ListProjectAccountsParams) (*Lis if err := json.Unmarshal(resp, &r); err != nil { return nil, err } + return &r, nil } @@ -1784,120 +1428,568 @@ type ListProjectAccountsResponse struct { } type ProjectAccount struct { - Account string `json:"account,omitempty"` - Cpuavailable string `json:"cpuavailable,omitempty"` - Cpulimit string `json:"cpulimit,omitempty"` - Cputotal int64 `json:"cputotal,omitempty"` - Displaytext string `json:"displaytext,omitempty"` - Domain string `json:"domain,omitempty"` - Domainid string `json:"domainid,omitempty"` - Id string `json:"id,omitempty"` - Ipavailable string `json:"ipavailable,omitempty"` - Iplimit string `json:"iplimit,omitempty"` - Iptotal int64 `json:"iptotal,omitempty"` - Memoryavailable string `json:"memoryavailable,omitempty"` - Memorylimit string `json:"memorylimit,omitempty"` - Memorytotal int64 `json:"memorytotal,omitempty"` - Name string `json:"name,omitempty"` - Networkavailable string `json:"networkavailable,omitempty"` - Networklimit string `json:"networklimit,omitempty"` - Networktotal int64 `json:"networktotal,omitempty"` - Primarystorageavailable string `json:"primarystorageavailable,omitempty"` - Primarystoragelimit string `json:"primarystoragelimit,omitempty"` - Primarystoragetotal int64 `json:"primarystoragetotal,omitempty"` - Secondarystorageavailable string `json:"secondarystorageavailable,omitempty"` - Secondarystoragelimit string `json:"secondarystoragelimit,omitempty"` - Secondarystoragetotal int64 `json:"secondarystoragetotal,omitempty"` - Snapshotavailable string `json:"snapshotavailable,omitempty"` - Snapshotlimit string `json:"snapshotlimit,omitempty"` - Snapshottotal int64 `json:"snapshottotal,omitempty"` - State string `json:"state,omitempty"` - Tags []struct { - Account string `json:"account,omitempty"` - Customer string `json:"customer,omitempty"` - Domain string `json:"domain,omitempty"` - Domainid string `json:"domainid,omitempty"` - Key string `json:"key,omitempty"` - Project string `json:"project,omitempty"` - Projectid string `json:"projectid,omitempty"` - Resourceid string `json:"resourceid,omitempty"` - Resourcetype string `json:"resourcetype,omitempty"` - Value string `json:"value,omitempty"` - } `json:"tags,omitempty"` - Templateavailable string `json:"templateavailable,omitempty"` - Templatelimit string `json:"templatelimit,omitempty"` - Templatetotal int64 `json:"templatetotal,omitempty"` - Vmavailable string `json:"vmavailable,omitempty"` - Vmlimit string `json:"vmlimit,omitempty"` - Vmrunning int `json:"vmrunning,omitempty"` - Vmstopped int `json:"vmstopped,omitempty"` - Vmtotal int64 `json:"vmtotal,omitempty"` - Volumeavailable string `json:"volumeavailable,omitempty"` - Volumelimit string `json:"volumelimit,omitempty"` - Volumetotal int64 `json:"volumetotal,omitempty"` - Vpcavailable string `json:"vpcavailable,omitempty"` - Vpclimit string `json:"vpclimit,omitempty"` - Vpctotal int64 `json:"vpctotal,omitempty"` + Account string `json:"account"` + Cpuavailable string `json:"cpuavailable"` + Cpulimit string `json:"cpulimit"` + Cputotal int64 `json:"cputotal"` + Displaytext string `json:"displaytext"` + Domain string `json:"domain"` + Domainid string `json:"domainid"` + Id string `json:"id"` + Ipavailable string `json:"ipavailable"` + Iplimit string `json:"iplimit"` + Iptotal int64 `json:"iptotal"` + Memoryavailable string `json:"memoryavailable"` + Memorylimit string `json:"memorylimit"` + Memorytotal int64 `json:"memorytotal"` + Name string `json:"name"` + Networkavailable string `json:"networkavailable"` + Networklimit string `json:"networklimit"` + Networktotal int64 `json:"networktotal"` + Primarystorageavailable string `json:"primarystorageavailable"` + Primarystoragelimit string `json:"primarystoragelimit"` + Primarystoragetotal int64 `json:"primarystoragetotal"` + Projectaccountname string `json:"projectaccountname"` + Secondarystorageavailable string `json:"secondarystorageavailable"` + Secondarystoragelimit string `json:"secondarystoragelimit"` + Secondarystoragetotal float64 `json:"secondarystoragetotal"` + Snapshotavailable string `json:"snapshotavailable"` + Snapshotlimit string `json:"snapshotlimit"` + Snapshottotal int64 `json:"snapshottotal"` + State string `json:"state"` + Tags []Tags `json:"tags"` + Templateavailable string `json:"templateavailable"` + Templatelimit string `json:"templatelimit"` + Templatetotal int64 `json:"templatetotal"` + Vmavailable string `json:"vmavailable"` + Vmlimit string `json:"vmlimit"` + Vmrunning int `json:"vmrunning"` + Vmstopped int `json:"vmstopped"` + Vmtotal int64 `json:"vmtotal"` + Volumeavailable string `json:"volumeavailable"` + Volumelimit string `json:"volumelimit"` + Volumetotal int64 `json:"volumetotal"` + Vpcavailable string `json:"vpcavailable"` + Vpclimit string `json:"vpclimit"` + Vpctotal int64 `json:"vpctotal"` } -type GetSolidFireAccountIdParams struct { +type Tags struct { + Account string `json:"account"` + Customer string `json:"customer"` + Domain string `json:"domain"` + Domainid string `json:"domainid"` + Key string `json:"key"` + Project string `json:"project"` + Projectid string `json:"projectid"` + Resourceid string `json:"resourceid"` + Resourcetype string `json:"resourcetype"` + Value string `json:"value"` +} + +type LockAccountParams struct { p map[string]interface{} } -func (p *GetSolidFireAccountIdParams) toURLValues() url.Values { +func (p *LockAccountParams) toURLValues() url.Values { u := url.Values{} if p.p == nil { return u } - if v, found := p.p["accountid"]; found { - u.Set("accountid", v.(string)) + if v, found := p.p["account"]; found { + u.Set("account", v.(string)) } - if v, found := p.p["storageid"]; found { - u.Set("storageid", v.(string)) + if v, found := p.p["domainid"]; found { + u.Set("domainid", v.(string)) } return u } -func (p *GetSolidFireAccountIdParams) SetAccountid(v string) { +func (p *LockAccountParams) SetAccount(v string) { if p.p == nil { p.p = make(map[string]interface{}) } - p.p["accountid"] = v + p.p["account"] = v return } -func (p *GetSolidFireAccountIdParams) SetStorageid(v string) { +func (p *LockAccountParams) SetDomainid(v string) { if p.p == nil { p.p = make(map[string]interface{}) } - p.p["storageid"] = v + p.p["domainid"] = v return } -// You should always use this function to get a new GetSolidFireAccountIdParams instance, +// You should always use this function to get a new LockAccountParams instance, // as then you are sure you have configured all required params -func (s *AccountService) NewGetSolidFireAccountIdParams(accountid string, storageid string) *GetSolidFireAccountIdParams { - p := &GetSolidFireAccountIdParams{} +func (s *AccountService) NewLockAccountParams(account string, domainid string) *LockAccountParams { + p := &LockAccountParams{} p.p = make(map[string]interface{}) - p.p["accountid"] = accountid - p.p["storageid"] = storageid + p.p["account"] = account + p.p["domainid"] = domainid return p } -// Get SolidFire Account ID -func (s *AccountService) GetSolidFireAccountId(p *GetSolidFireAccountIdParams) (*GetSolidFireAccountIdResponse, error) { - resp, err := s.cs.newRequest("getSolidFireAccountId", p.toURLValues()) +// This deprecated function used to locks an account. Look for the API DisableAccount instead +func (s *AccountService) LockAccount(p *LockAccountParams) (*LockAccountResponse, error) { + resp, err := s.cs.newRequest("lockAccount", p.toURLValues()) if err != nil { return nil, err } - var r GetSolidFireAccountIdResponse + var r LockAccountResponse if err := json.Unmarshal(resp, &r); err != nil { return nil, err } + return &r, nil } -type GetSolidFireAccountIdResponse struct { - SolidFireAccountId int64 `json:"solidFireAccountId,omitempty"` +type LockAccountResponse struct { + Accountdetails map[string]string `json:"accountdetails"` + Accounttype int `json:"accounttype"` + Cpuavailable string `json:"cpuavailable"` + Cpulimit string `json:"cpulimit"` + Cputotal int64 `json:"cputotal"` + Defaultzoneid string `json:"defaultzoneid"` + Domain string `json:"domain"` + Domainid string `json:"domainid"` + Groups []string `json:"groups"` + Id string `json:"id"` + Ipavailable string `json:"ipavailable"` + Iplimit string `json:"iplimit"` + Iptotal int64 `json:"iptotal"` + Iscleanuprequired bool `json:"iscleanuprequired"` + Isdefault bool `json:"isdefault"` + Memoryavailable string `json:"memoryavailable"` + Memorylimit string `json:"memorylimit"` + Memorytotal int64 `json:"memorytotal"` + Name string `json:"name"` + Networkavailable string `json:"networkavailable"` + Networkdomain string `json:"networkdomain"` + Networklimit string `json:"networklimit"` + Networktotal int64 `json:"networktotal"` + Primarystorageavailable string `json:"primarystorageavailable"` + Primarystoragelimit string `json:"primarystoragelimit"` + Primarystoragetotal int64 `json:"primarystoragetotal"` + Projectavailable string `json:"projectavailable"` + Projectlimit string `json:"projectlimit"` + Projecttotal int64 `json:"projecttotal"` + Receivedbytes int64 `json:"receivedbytes"` + Roleid string `json:"roleid"` + Rolename string `json:"rolename"` + Roletype string `json:"roletype"` + Secondarystorageavailable string `json:"secondarystorageavailable"` + Secondarystoragelimit string `json:"secondarystoragelimit"` + Secondarystoragetotal float64 `json:"secondarystoragetotal"` + Sentbytes int64 `json:"sentbytes"` + Snapshotavailable string `json:"snapshotavailable"` + Snapshotlimit string `json:"snapshotlimit"` + Snapshottotal int64 `json:"snapshottotal"` + State string `json:"state"` + Templateavailable string `json:"templateavailable"` + Templatelimit string `json:"templatelimit"` + Templatetotal int64 `json:"templatetotal"` + User []LockAccountResponseUser `json:"user"` + Vmavailable string `json:"vmavailable"` + Vmlimit string `json:"vmlimit"` + Vmrunning int `json:"vmrunning"` + Vmstopped int `json:"vmstopped"` + Vmtotal int64 `json:"vmtotal"` + Volumeavailable string `json:"volumeavailable"` + Volumelimit string `json:"volumelimit"` + Volumetotal int64 `json:"volumetotal"` + Vpcavailable string `json:"vpcavailable"` + Vpclimit string `json:"vpclimit"` + Vpctotal int64 `json:"vpctotal"` +} + +type LockAccountResponseUser struct { + Account string `json:"account"` + Accountid string `json:"accountid"` + Accounttype int `json:"accounttype"` + Apikey string `json:"apikey"` + Created string `json:"created"` + Domain string `json:"domain"` + Domainid string `json:"domainid"` + Email string `json:"email"` + Firstname string `json:"firstname"` + Id string `json:"id"` + Iscallerchilddomain bool `json:"iscallerchilddomain"` + Isdefault bool `json:"isdefault"` + Lastname string `json:"lastname"` + Roleid string `json:"roleid"` + Rolename string `json:"rolename"` + Roletype string `json:"roletype"` + Secretkey string `json:"secretkey"` + State string `json:"state"` + Timezone string `json:"timezone"` + Username string `json:"username"` + Usersource string `json:"usersource"` +} + +type MarkDefaultZoneForAccountParams struct { + p map[string]interface{} +} + +func (p *MarkDefaultZoneForAccountParams) toURLValues() url.Values { + u := url.Values{} + if p.p == nil { + return u + } + if v, found := p.p["account"]; found { + u.Set("account", v.(string)) + } + if v, found := p.p["domainid"]; found { + u.Set("domainid", v.(string)) + } + if v, found := p.p["zoneid"]; found { + u.Set("zoneid", v.(string)) + } + return u +} + +func (p *MarkDefaultZoneForAccountParams) SetAccount(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["account"] = v + return +} + +func (p *MarkDefaultZoneForAccountParams) SetDomainid(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["domainid"] = v + return +} + +func (p *MarkDefaultZoneForAccountParams) SetZoneid(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["zoneid"] = v + return +} + +// You should always use this function to get a new MarkDefaultZoneForAccountParams instance, +// as then you are sure you have configured all required params +func (s *AccountService) NewMarkDefaultZoneForAccountParams(account string, domainid string, zoneid string) *MarkDefaultZoneForAccountParams { + p := &MarkDefaultZoneForAccountParams{} + p.p = make(map[string]interface{}) + p.p["account"] = account + p.p["domainid"] = domainid + p.p["zoneid"] = zoneid + return p +} + +// Marks a default zone for this account +func (s *AccountService) MarkDefaultZoneForAccount(p *MarkDefaultZoneForAccountParams) (*MarkDefaultZoneForAccountResponse, error) { + resp, err := s.cs.newRequest("markDefaultZoneForAccount", p.toURLValues()) + if err != nil { + return nil, err + } + + var r MarkDefaultZoneForAccountResponse + if err := json.Unmarshal(resp, &r); err != nil { + return nil, err + } + + // If we have a async client, we need to wait for the async result + if s.cs.async { + b, err := s.cs.GetAsyncJobResult(r.JobID, s.cs.timeout) + if err != nil { + if err == AsyncTimeoutErr { + return &r, err + } + return nil, err + } + + b, err = getRawValue(b) + if err != nil { + return nil, err + } + + if err := json.Unmarshal(b, &r); err != nil { + return nil, err + } + } + + return &r, nil +} + +type MarkDefaultZoneForAccountResponse struct { + JobID string `json:"jobid"` + Accountdetails map[string]string `json:"accountdetails"` + Accounttype int `json:"accounttype"` + Cpuavailable string `json:"cpuavailable"` + Cpulimit string `json:"cpulimit"` + Cputotal int64 `json:"cputotal"` + Defaultzoneid string `json:"defaultzoneid"` + Domain string `json:"domain"` + Domainid string `json:"domainid"` + Groups []string `json:"groups"` + Id string `json:"id"` + Ipavailable string `json:"ipavailable"` + Iplimit string `json:"iplimit"` + Iptotal int64 `json:"iptotal"` + Iscleanuprequired bool `json:"iscleanuprequired"` + Isdefault bool `json:"isdefault"` + Memoryavailable string `json:"memoryavailable"` + Memorylimit string `json:"memorylimit"` + Memorytotal int64 `json:"memorytotal"` + Name string `json:"name"` + Networkavailable string `json:"networkavailable"` + Networkdomain string `json:"networkdomain"` + Networklimit string `json:"networklimit"` + Networktotal int64 `json:"networktotal"` + Primarystorageavailable string `json:"primarystorageavailable"` + Primarystoragelimit string `json:"primarystoragelimit"` + Primarystoragetotal int64 `json:"primarystoragetotal"` + Projectavailable string `json:"projectavailable"` + Projectlimit string `json:"projectlimit"` + Projecttotal int64 `json:"projecttotal"` + Receivedbytes int64 `json:"receivedbytes"` + Roleid string `json:"roleid"` + Rolename string `json:"rolename"` + Roletype string `json:"roletype"` + Secondarystorageavailable string `json:"secondarystorageavailable"` + Secondarystoragelimit string `json:"secondarystoragelimit"` + Secondarystoragetotal float64 `json:"secondarystoragetotal"` + Sentbytes int64 `json:"sentbytes"` + Snapshotavailable string `json:"snapshotavailable"` + Snapshotlimit string `json:"snapshotlimit"` + Snapshottotal int64 `json:"snapshottotal"` + State string `json:"state"` + Templateavailable string `json:"templateavailable"` + Templatelimit string `json:"templatelimit"` + Templatetotal int64 `json:"templatetotal"` + User []MarkDefaultZoneForAccountResponseUser `json:"user"` + Vmavailable string `json:"vmavailable"` + Vmlimit string `json:"vmlimit"` + Vmrunning int `json:"vmrunning"` + Vmstopped int `json:"vmstopped"` + Vmtotal int64 `json:"vmtotal"` + Volumeavailable string `json:"volumeavailable"` + Volumelimit string `json:"volumelimit"` + Volumetotal int64 `json:"volumetotal"` + Vpcavailable string `json:"vpcavailable"` + Vpclimit string `json:"vpclimit"` + Vpctotal int64 `json:"vpctotal"` +} + +type MarkDefaultZoneForAccountResponseUser struct { + Account string `json:"account"` + Accountid string `json:"accountid"` + Accounttype int `json:"accounttype"` + Apikey string `json:"apikey"` + Created string `json:"created"` + Domain string `json:"domain"` + Domainid string `json:"domainid"` + Email string `json:"email"` + Firstname string `json:"firstname"` + Id string `json:"id"` + Iscallerchilddomain bool `json:"iscallerchilddomain"` + Isdefault bool `json:"isdefault"` + Lastname string `json:"lastname"` + Roleid string `json:"roleid"` + Rolename string `json:"rolename"` + Roletype string `json:"roletype"` + Secretkey string `json:"secretkey"` + State string `json:"state"` + Timezone string `json:"timezone"` + Username string `json:"username"` + Usersource string `json:"usersource"` +} + +type UpdateAccountParams struct { + p map[string]interface{} +} + +func (p *UpdateAccountParams) toURLValues() url.Values { + u := url.Values{} + if p.p == nil { + return u + } + if v, found := p.p["account"]; found { + u.Set("account", v.(string)) + } + if v, found := p.p["accountdetails"]; found { + i := 0 + for k, vv := range v.(map[string]string) { + u.Set(fmt.Sprintf("accountdetails[%d].key", i), k) + u.Set(fmt.Sprintf("accountdetails[%d].value", i), vv) + i++ + } + } + if v, found := p.p["domainid"]; found { + u.Set("domainid", v.(string)) + } + if v, found := p.p["id"]; found { + u.Set("id", v.(string)) + } + if v, found := p.p["networkdomain"]; found { + u.Set("networkdomain", v.(string)) + } + if v, found := p.p["newname"]; found { + u.Set("newname", v.(string)) + } + return u +} + +func (p *UpdateAccountParams) SetAccount(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["account"] = v + return +} + +func (p *UpdateAccountParams) SetAccountdetails(v map[string]string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["accountdetails"] = v + return +} + +func (p *UpdateAccountParams) SetDomainid(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["domainid"] = v + return +} + +func (p *UpdateAccountParams) SetId(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["id"] = v + return +} + +func (p *UpdateAccountParams) SetNetworkdomain(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["networkdomain"] = v + return +} + +func (p *UpdateAccountParams) SetNewname(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["newname"] = v + return +} + +// You should always use this function to get a new UpdateAccountParams instance, +// as then you are sure you have configured all required params +func (s *AccountService) NewUpdateAccountParams(newname string) *UpdateAccountParams { + p := &UpdateAccountParams{} + p.p = make(map[string]interface{}) + p.p["newname"] = newname + return p +} + +// Updates account information for the authenticated user +func (s *AccountService) UpdateAccount(p *UpdateAccountParams) (*UpdateAccountResponse, error) { + resp, err := s.cs.newRequest("updateAccount", p.toURLValues()) + if err != nil { + return nil, err + } + + var r UpdateAccountResponse + if err := json.Unmarshal(resp, &r); err != nil { + return nil, err + } + + return &r, nil +} + +type UpdateAccountResponse struct { + Accountdetails map[string]string `json:"accountdetails"` + Accounttype int `json:"accounttype"` + Cpuavailable string `json:"cpuavailable"` + Cpulimit string `json:"cpulimit"` + Cputotal int64 `json:"cputotal"` + Defaultzoneid string `json:"defaultzoneid"` + Domain string `json:"domain"` + Domainid string `json:"domainid"` + Groups []string `json:"groups"` + Id string `json:"id"` + Ipavailable string `json:"ipavailable"` + Iplimit string `json:"iplimit"` + Iptotal int64 `json:"iptotal"` + Iscleanuprequired bool `json:"iscleanuprequired"` + Isdefault bool `json:"isdefault"` + Memoryavailable string `json:"memoryavailable"` + Memorylimit string `json:"memorylimit"` + Memorytotal int64 `json:"memorytotal"` + Name string `json:"name"` + Networkavailable string `json:"networkavailable"` + Networkdomain string `json:"networkdomain"` + Networklimit string `json:"networklimit"` + Networktotal int64 `json:"networktotal"` + Primarystorageavailable string `json:"primarystorageavailable"` + Primarystoragelimit string `json:"primarystoragelimit"` + Primarystoragetotal int64 `json:"primarystoragetotal"` + Projectavailable string `json:"projectavailable"` + Projectlimit string `json:"projectlimit"` + Projecttotal int64 `json:"projecttotal"` + Receivedbytes int64 `json:"receivedbytes"` + Roleid string `json:"roleid"` + Rolename string `json:"rolename"` + Roletype string `json:"roletype"` + Secondarystorageavailable string `json:"secondarystorageavailable"` + Secondarystoragelimit string `json:"secondarystoragelimit"` + Secondarystoragetotal float64 `json:"secondarystoragetotal"` + Sentbytes int64 `json:"sentbytes"` + Snapshotavailable string `json:"snapshotavailable"` + Snapshotlimit string `json:"snapshotlimit"` + Snapshottotal int64 `json:"snapshottotal"` + State string `json:"state"` + Templateavailable string `json:"templateavailable"` + Templatelimit string `json:"templatelimit"` + Templatetotal int64 `json:"templatetotal"` + User []UpdateAccountResponseUser `json:"user"` + Vmavailable string `json:"vmavailable"` + Vmlimit string `json:"vmlimit"` + Vmrunning int `json:"vmrunning"` + Vmstopped int `json:"vmstopped"` + Vmtotal int64 `json:"vmtotal"` + Volumeavailable string `json:"volumeavailable"` + Volumelimit string `json:"volumelimit"` + Volumetotal int64 `json:"volumetotal"` + Vpcavailable string `json:"vpcavailable"` + Vpclimit string `json:"vpclimit"` + Vpctotal int64 `json:"vpctotal"` +} + +type UpdateAccountResponseUser struct { + Account string `json:"account"` + Accountid string `json:"accountid"` + Accounttype int `json:"accounttype"` + Apikey string `json:"apikey"` + Created string `json:"created"` + Domain string `json:"domain"` + Domainid string `json:"domainid"` + Email string `json:"email"` + Firstname string `json:"firstname"` + Id string `json:"id"` + Iscallerchilddomain bool `json:"iscallerchilddomain"` + Isdefault bool `json:"isdefault"` + Lastname string `json:"lastname"` + Roleid string `json:"roleid"` + Rolename string `json:"rolename"` + Roletype string `json:"roletype"` + Secretkey string `json:"secretkey"` + State string `json:"state"` + Timezone string `json:"timezone"` + Username string `json:"username"` + Usersource string `json:"usersource"` } diff --git a/vendor/github.com/xanzy/go-cloudstack/cloudstack/AddressService.go b/vendor/github.com/xanzy/go-cloudstack/cloudstack/AddressService.go index 9ffc6d9b8..d0a61fc8e 100644 --- a/vendor/github.com/xanzy/go-cloudstack/cloudstack/AddressService.go +++ b/vendor/github.com/xanzy/go-cloudstack/cloudstack/AddressService.go @@ -1,5 +1,5 @@ // -// Copyright 2016, Sander van Harmelen +// Copyright 2018, Sander van Harmelen // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -177,52 +177,42 @@ func (s *AddressService) AssociateIpAddress(p *AssociateIpAddressParams) (*Assoc return nil, err } } + return &r, nil } type AssociateIpAddressResponse struct { - JobID string `json:"jobid,omitempty"` - Account string `json:"account,omitempty"` - Allocated string `json:"allocated,omitempty"` - Associatednetworkid string `json:"associatednetworkid,omitempty"` - Associatednetworkname string `json:"associatednetworkname,omitempty"` - Domain string `json:"domain,omitempty"` - Domainid string `json:"domainid,omitempty"` - Fordisplay bool `json:"fordisplay,omitempty"` - Forvirtualnetwork bool `json:"forvirtualnetwork,omitempty"` - Id string `json:"id,omitempty"` - Ipaddress string `json:"ipaddress,omitempty"` - Isportable bool `json:"isportable,omitempty"` - Issourcenat bool `json:"issourcenat,omitempty"` - Isstaticnat bool `json:"isstaticnat,omitempty"` - Issystem bool `json:"issystem,omitempty"` - Networkid string `json:"networkid,omitempty"` - Physicalnetworkid string `json:"physicalnetworkid,omitempty"` - Project string `json:"project,omitempty"` - Projectid string `json:"projectid,omitempty"` - Purpose string `json:"purpose,omitempty"` - State string `json:"state,omitempty"` - Tags []struct { - Account string `json:"account,omitempty"` - Customer string `json:"customer,omitempty"` - Domain string `json:"domain,omitempty"` - Domainid string `json:"domainid,omitempty"` - Key string `json:"key,omitempty"` - Project string `json:"project,omitempty"` - Projectid string `json:"projectid,omitempty"` - Resourceid string `json:"resourceid,omitempty"` - Resourcetype string `json:"resourcetype,omitempty"` - Value string `json:"value,omitempty"` - } `json:"tags,omitempty"` - Virtualmachinedisplayname string `json:"virtualmachinedisplayname,omitempty"` - Virtualmachineid string `json:"virtualmachineid,omitempty"` - Virtualmachinename string `json:"virtualmachinename,omitempty"` - Vlanid string `json:"vlanid,omitempty"` - Vlanname string `json:"vlanname,omitempty"` - Vmipaddress string `json:"vmipaddress,omitempty"` - Vpcid string `json:"vpcid,omitempty"` - Zoneid string `json:"zoneid,omitempty"` - Zonename string `json:"zonename,omitempty"` + JobID string `json:"jobid"` + Account string `json:"account"` + Allocated string `json:"allocated"` + Associatednetworkid string `json:"associatednetworkid"` + Associatednetworkname string `json:"associatednetworkname"` + Domain string `json:"domain"` + Domainid string `json:"domainid"` + Fordisplay bool `json:"fordisplay"` + Forvirtualnetwork bool `json:"forvirtualnetwork"` + Id string `json:"id"` + Ipaddress string `json:"ipaddress"` + Isportable bool `json:"isportable"` + Issourcenat bool `json:"issourcenat"` + Isstaticnat bool `json:"isstaticnat"` + Issystem bool `json:"issystem"` + Networkid string `json:"networkid"` + Physicalnetworkid string `json:"physicalnetworkid"` + Project string `json:"project"` + Projectid string `json:"projectid"` + Purpose string `json:"purpose"` + State string `json:"state"` + Tags []Tags `json:"tags"` + Virtualmachinedisplayname string `json:"virtualmachinedisplayname"` + Virtualmachineid string `json:"virtualmachineid"` + Virtualmachinename string `json:"virtualmachinename"` + Vlanid string `json:"vlanid"` + Vlanname string `json:"vlanname"` + Vmipaddress string `json:"vmipaddress"` + Vpcid string `json:"vpcid"` + Zoneid string `json:"zoneid"` + Zonename string `json:"zonename"` } type DisassociateIpAddressParams struct { @@ -283,13 +273,14 @@ func (s *AddressService) DisassociateIpAddress(p *DisassociateIpAddressParams) ( return nil, err } } + return &r, nil } type DisassociateIpAddressResponse struct { - JobID string `json:"jobid,omitempty"` - Displaytext string `json:"displaytext,omitempty"` - Success bool `json:"success,omitempty"` + JobID string `json:"jobid"` + Displaytext string `json:"displaytext"` + Success bool `json:"success"` } type ListPublicIpAddressesParams struct { @@ -587,7 +578,7 @@ func (s *AddressService) GetPublicIpAddressByID(id string, opts ...OptionFunc) ( p.p["id"] = id - for _, fn := range opts { + for _, fn := range append(s.cs.options, opts...) { if err := fn(s.cs, p); err != nil { return nil, -1, err } @@ -624,6 +615,7 @@ func (s *AddressService) ListPublicIpAddresses(p *ListPublicIpAddressesParams) ( if err := json.Unmarshal(resp, &r); err != nil { return nil, err } + return &r, nil } @@ -633,47 +625,36 @@ type ListPublicIpAddressesResponse struct { } type PublicIpAddress struct { - Account string `json:"account,omitempty"` - Allocated string `json:"allocated,omitempty"` - Associatednetworkid string `json:"associatednetworkid,omitempty"` - Associatednetworkname string `json:"associatednetworkname,omitempty"` - Domain string `json:"domain,omitempty"` - Domainid string `json:"domainid,omitempty"` - Fordisplay bool `json:"fordisplay,omitempty"` - Forvirtualnetwork bool `json:"forvirtualnetwork,omitempty"` - Id string `json:"id,omitempty"` - Ipaddress string `json:"ipaddress,omitempty"` - Isportable bool `json:"isportable,omitempty"` - Issourcenat bool `json:"issourcenat,omitempty"` - Isstaticnat bool `json:"isstaticnat,omitempty"` - Issystem bool `json:"issystem,omitempty"` - Networkid string `json:"networkid,omitempty"` - Physicalnetworkid string `json:"physicalnetworkid,omitempty"` - Project string `json:"project,omitempty"` - Projectid string `json:"projectid,omitempty"` - Purpose string `json:"purpose,omitempty"` - State string `json:"state,omitempty"` - Tags []struct { - Account string `json:"account,omitempty"` - Customer string `json:"customer,omitempty"` - Domain string `json:"domain,omitempty"` - Domainid string `json:"domainid,omitempty"` - Key string `json:"key,omitempty"` - Project string `json:"project,omitempty"` - Projectid string `json:"projectid,omitempty"` - Resourceid string `json:"resourceid,omitempty"` - Resourcetype string `json:"resourcetype,omitempty"` - Value string `json:"value,omitempty"` - } `json:"tags,omitempty"` - Virtualmachinedisplayname string `json:"virtualmachinedisplayname,omitempty"` - Virtualmachineid string `json:"virtualmachineid,omitempty"` - Virtualmachinename string `json:"virtualmachinename,omitempty"` - Vlanid string `json:"vlanid,omitempty"` - Vlanname string `json:"vlanname,omitempty"` - Vmipaddress string `json:"vmipaddress,omitempty"` - Vpcid string `json:"vpcid,omitempty"` - Zoneid string `json:"zoneid,omitempty"` - Zonename string `json:"zonename,omitempty"` + Account string `json:"account"` + Allocated string `json:"allocated"` + Associatednetworkid string `json:"associatednetworkid"` + Associatednetworkname string `json:"associatednetworkname"` + Domain string `json:"domain"` + Domainid string `json:"domainid"` + Fordisplay bool `json:"fordisplay"` + Forvirtualnetwork bool `json:"forvirtualnetwork"` + Id string `json:"id"` + Ipaddress string `json:"ipaddress"` + Isportable bool `json:"isportable"` + Issourcenat bool `json:"issourcenat"` + Isstaticnat bool `json:"isstaticnat"` + Issystem bool `json:"issystem"` + Networkid string `json:"networkid"` + Physicalnetworkid string `json:"physicalnetworkid"` + Project string `json:"project"` + Projectid string `json:"projectid"` + Purpose string `json:"purpose"` + State string `json:"state"` + Tags []Tags `json:"tags"` + Virtualmachinedisplayname string `json:"virtualmachinedisplayname"` + Virtualmachineid string `json:"virtualmachineid"` + Virtualmachinename string `json:"virtualmachinename"` + Vlanid string `json:"vlanid"` + Vlanname string `json:"vlanname"` + Vmipaddress string `json:"vmipaddress"` + Vpcid string `json:"vpcid"` + Zoneid string `json:"zoneid"` + Zonename string `json:"zonename"` } type UpdateIpAddressParams struct { @@ -762,50 +743,40 @@ func (s *AddressService) UpdateIpAddress(p *UpdateIpAddressParams) (*UpdateIpAdd return nil, err } } + return &r, nil } type UpdateIpAddressResponse struct { - JobID string `json:"jobid,omitempty"` - Account string `json:"account,omitempty"` - Allocated string `json:"allocated,omitempty"` - Associatednetworkid string `json:"associatednetworkid,omitempty"` - Associatednetworkname string `json:"associatednetworkname,omitempty"` - Domain string `json:"domain,omitempty"` - Domainid string `json:"domainid,omitempty"` - Fordisplay bool `json:"fordisplay,omitempty"` - Forvirtualnetwork bool `json:"forvirtualnetwork,omitempty"` - Id string `json:"id,omitempty"` - Ipaddress string `json:"ipaddress,omitempty"` - Isportable bool `json:"isportable,omitempty"` - Issourcenat bool `json:"issourcenat,omitempty"` - Isstaticnat bool `json:"isstaticnat,omitempty"` - Issystem bool `json:"issystem,omitempty"` - Networkid string `json:"networkid,omitempty"` - Physicalnetworkid string `json:"physicalnetworkid,omitempty"` - Project string `json:"project,omitempty"` - Projectid string `json:"projectid,omitempty"` - Purpose string `json:"purpose,omitempty"` - State string `json:"state,omitempty"` - Tags []struct { - Account string `json:"account,omitempty"` - Customer string `json:"customer,omitempty"` - Domain string `json:"domain,omitempty"` - Domainid string `json:"domainid,omitempty"` - Key string `json:"key,omitempty"` - Project string `json:"project,omitempty"` - Projectid string `json:"projectid,omitempty"` - Resourceid string `json:"resourceid,omitempty"` - Resourcetype string `json:"resourcetype,omitempty"` - Value string `json:"value,omitempty"` - } `json:"tags,omitempty"` - Virtualmachinedisplayname string `json:"virtualmachinedisplayname,omitempty"` - Virtualmachineid string `json:"virtualmachineid,omitempty"` - Virtualmachinename string `json:"virtualmachinename,omitempty"` - Vlanid string `json:"vlanid,omitempty"` - Vlanname string `json:"vlanname,omitempty"` - Vmipaddress string `json:"vmipaddress,omitempty"` - Vpcid string `json:"vpcid,omitempty"` - Zoneid string `json:"zoneid,omitempty"` - Zonename string `json:"zonename,omitempty"` + JobID string `json:"jobid"` + Account string `json:"account"` + Allocated string `json:"allocated"` + Associatednetworkid string `json:"associatednetworkid"` + Associatednetworkname string `json:"associatednetworkname"` + Domain string `json:"domain"` + Domainid string `json:"domainid"` + Fordisplay bool `json:"fordisplay"` + Forvirtualnetwork bool `json:"forvirtualnetwork"` + Id string `json:"id"` + Ipaddress string `json:"ipaddress"` + Isportable bool `json:"isportable"` + Issourcenat bool `json:"issourcenat"` + Isstaticnat bool `json:"isstaticnat"` + Issystem bool `json:"issystem"` + Networkid string `json:"networkid"` + Physicalnetworkid string `json:"physicalnetworkid"` + Project string `json:"project"` + Projectid string `json:"projectid"` + Purpose string `json:"purpose"` + State string `json:"state"` + Tags []Tags `json:"tags"` + Virtualmachinedisplayname string `json:"virtualmachinedisplayname"` + Virtualmachineid string `json:"virtualmachineid"` + Virtualmachinename string `json:"virtualmachinename"` + Vlanid string `json:"vlanid"` + Vlanname string `json:"vlanname"` + Vmipaddress string `json:"vmipaddress"` + Vpcid string `json:"vpcid"` + Zoneid string `json:"zoneid"` + Zonename string `json:"zonename"` } diff --git a/vendor/github.com/xanzy/go-cloudstack/cloudstack/AffinityGroupService.go b/vendor/github.com/xanzy/go-cloudstack/cloudstack/AffinityGroupService.go index 48f1b0f93..d81b54d05 100644 --- a/vendor/github.com/xanzy/go-cloudstack/cloudstack/AffinityGroupService.go +++ b/vendor/github.com/xanzy/go-cloudstack/cloudstack/AffinityGroupService.go @@ -1,5 +1,5 @@ // -// Copyright 2016, Sander van Harmelen +// Copyright 2018, Sander van Harmelen // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -143,21 +143,22 @@ func (s *AffinityGroupService) CreateAffinityGroup(p *CreateAffinityGroupParams) return nil, err } } + return &r, nil } type CreateAffinityGroupResponse struct { - JobID string `json:"jobid,omitempty"` - Account string `json:"account,omitempty"` - Description string `json:"description,omitempty"` - Domain string `json:"domain,omitempty"` - Domainid string `json:"domainid,omitempty"` - Id string `json:"id,omitempty"` - Name string `json:"name,omitempty"` - Project string `json:"project,omitempty"` - Projectid string `json:"projectid,omitempty"` - Type string `json:"type,omitempty"` - VirtualmachineIds []string `json:"virtualmachineIds,omitempty"` + JobID string `json:"jobid"` + Account string `json:"account"` + Description string `json:"description"` + Domain string `json:"domain"` + Domainid string `json:"domainid"` + Id string `json:"id"` + Name string `json:"name"` + Project string `json:"project"` + Projectid string `json:"projectid"` + Type string `json:"type"` + VirtualmachineIds []string `json:"virtualmachineIds"` } type DeleteAffinityGroupParams struct { @@ -261,13 +262,93 @@ func (s *AffinityGroupService) DeleteAffinityGroup(p *DeleteAffinityGroupParams) return nil, err } } + return &r, nil } type DeleteAffinityGroupResponse struct { - JobID string `json:"jobid,omitempty"` - Displaytext string `json:"displaytext,omitempty"` - Success bool `json:"success,omitempty"` + JobID string `json:"jobid"` + Displaytext string `json:"displaytext"` + Success bool `json:"success"` +} + +type ListAffinityGroupTypesParams struct { + p map[string]interface{} +} + +func (p *ListAffinityGroupTypesParams) toURLValues() url.Values { + u := url.Values{} + if p.p == nil { + return u + } + if v, found := p.p["keyword"]; found { + u.Set("keyword", v.(string)) + } + if v, found := p.p["page"]; found { + vv := strconv.Itoa(v.(int)) + u.Set("page", vv) + } + if v, found := p.p["pagesize"]; found { + vv := strconv.Itoa(v.(int)) + u.Set("pagesize", vv) + } + return u +} + +func (p *ListAffinityGroupTypesParams) SetKeyword(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["keyword"] = v + return +} + +func (p *ListAffinityGroupTypesParams) SetPage(v int) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["page"] = v + return +} + +func (p *ListAffinityGroupTypesParams) SetPagesize(v int) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["pagesize"] = v + return +} + +// You should always use this function to get a new ListAffinityGroupTypesParams instance, +// as then you are sure you have configured all required params +func (s *AffinityGroupService) NewListAffinityGroupTypesParams() *ListAffinityGroupTypesParams { + p := &ListAffinityGroupTypesParams{} + p.p = make(map[string]interface{}) + return p +} + +// Lists affinity group types available +func (s *AffinityGroupService) ListAffinityGroupTypes(p *ListAffinityGroupTypesParams) (*ListAffinityGroupTypesResponse, error) { + resp, err := s.cs.newRequest("listAffinityGroupTypes", p.toURLValues()) + if err != nil { + return nil, err + } + + var r ListAffinityGroupTypesResponse + if err := json.Unmarshal(resp, &r); err != nil { + return nil, err + } + + return &r, nil +} + +type ListAffinityGroupTypesResponse struct { + Count int `json:"count"` + AffinityGroupTypes []*AffinityGroupType `json:"affinitygrouptype"` +} + +type AffinityGroupType struct { + Type string `json:"type"` } type ListAffinityGroupsParams struct { @@ -433,7 +514,7 @@ func (s *AffinityGroupService) GetAffinityGroupID(name string, opts ...OptionFun p.p["name"] = name - for _, fn := range opts { + for _, fn := range append(s.cs.options, opts...) { if err := fn(s.cs, p); err != nil { return "", -1, err } @@ -487,7 +568,7 @@ func (s *AffinityGroupService) GetAffinityGroupByID(id string, opts ...OptionFun p.p["id"] = id - for _, fn := range opts { + for _, fn := range append(s.cs.options, opts...) { if err := fn(s.cs, p); err != nil { return nil, -1, err } @@ -528,6 +609,7 @@ func (s *AffinityGroupService) ListAffinityGroups(p *ListAffinityGroupsParams) ( if err := json.Unmarshal(resp, &r); err != nil { return nil, err } + return &r, nil } @@ -537,16 +619,16 @@ type ListAffinityGroupsResponse struct { } type AffinityGroup struct { - Account string `json:"account,omitempty"` - Description string `json:"description,omitempty"` - Domain string `json:"domain,omitempty"` - Domainid string `json:"domainid,omitempty"` - Id string `json:"id,omitempty"` - Name string `json:"name,omitempty"` - Project string `json:"project,omitempty"` - Projectid string `json:"projectid,omitempty"` - Type string `json:"type,omitempty"` - VirtualmachineIds []string `json:"virtualmachineIds,omitempty"` + Account string `json:"account"` + Description string `json:"description"` + Domain string `json:"domain"` + Domainid string `json:"domainid"` + Id string `json:"id"` + Name string `json:"name"` + Project string `json:"project"` + Projectid string `json:"projectid"` + Type string `json:"type"` + VirtualmachineIds []string `json:"virtualmachineIds"` } type UpdateVMAffinityGroupParams struct { @@ -636,260 +718,114 @@ func (s *AffinityGroupService) UpdateVMAffinityGroup(p *UpdateVMAffinityGroupPar return nil, err } } + return &r, nil } type UpdateVMAffinityGroupResponse struct { - JobID string `json:"jobid,omitempty"` - Account string `json:"account,omitempty"` - Affinitygroup []struct { - Account string `json:"account,omitempty"` - Description string `json:"description,omitempty"` - Domain string `json:"domain,omitempty"` - Domainid string `json:"domainid,omitempty"` - Id string `json:"id,omitempty"` - Name string `json:"name,omitempty"` - Project string `json:"project,omitempty"` - Projectid string `json:"projectid,omitempty"` - Type string `json:"type,omitempty"` - VirtualmachineIds []string `json:"virtualmachineIds,omitempty"` - } `json:"affinitygroup,omitempty"` - Cpunumber int `json:"cpunumber,omitempty"` - Cpuspeed int `json:"cpuspeed,omitempty"` - Cpuused string `json:"cpuused,omitempty"` - Created string `json:"created,omitempty"` - Details map[string]string `json:"details,omitempty"` - Diskioread int64 `json:"diskioread,omitempty"` - Diskiowrite int64 `json:"diskiowrite,omitempty"` - Diskkbsread int64 `json:"diskkbsread,omitempty"` - Diskkbswrite int64 `json:"diskkbswrite,omitempty"` - Diskofferingid string `json:"diskofferingid,omitempty"` - Diskofferingname string `json:"diskofferingname,omitempty"` - Displayname string `json:"displayname,omitempty"` - Displayvm bool `json:"displayvm,omitempty"` - Domain string `json:"domain,omitempty"` - Domainid string `json:"domainid,omitempty"` - Forvirtualnetwork bool `json:"forvirtualnetwork,omitempty"` - Group string `json:"group,omitempty"` - Groupid string `json:"groupid,omitempty"` - Guestosid string `json:"guestosid,omitempty"` - Haenable bool `json:"haenable,omitempty"` - Hostid string `json:"hostid,omitempty"` - Hostname string `json:"hostname,omitempty"` - Hypervisor string `json:"hypervisor,omitempty"` - Id string `json:"id,omitempty"` - Instancename string `json:"instancename,omitempty"` - Isdynamicallyscalable bool `json:"isdynamicallyscalable,omitempty"` - Isodisplaytext string `json:"isodisplaytext,omitempty"` - Isoid string `json:"isoid,omitempty"` - Isoname string `json:"isoname,omitempty"` - Keypair string `json:"keypair,omitempty"` - Memory int `json:"memory,omitempty"` - Name string `json:"name,omitempty"` - Networkkbsread int64 `json:"networkkbsread,omitempty"` - Networkkbswrite int64 `json:"networkkbswrite,omitempty"` - Nic []struct { - Broadcasturi string `json:"broadcasturi,omitempty"` - Deviceid string `json:"deviceid,omitempty"` - Gateway string `json:"gateway,omitempty"` - Id string `json:"id,omitempty"` - Ip6address string `json:"ip6address,omitempty"` - Ip6cidr string `json:"ip6cidr,omitempty"` - Ip6gateway string `json:"ip6gateway,omitempty"` - Ipaddress string `json:"ipaddress,omitempty"` - Isdefault bool `json:"isdefault,omitempty"` - Isolationuri string `json:"isolationuri,omitempty"` - Macaddress string `json:"macaddress,omitempty"` - Netmask string `json:"netmask,omitempty"` - Networkid string `json:"networkid,omitempty"` - Networkname string `json:"networkname,omitempty"` - Secondaryip []struct { - Id string `json:"id,omitempty"` - Ipaddress string `json:"ipaddress,omitempty"` - } `json:"secondaryip,omitempty"` - Traffictype string `json:"traffictype,omitempty"` - Type string `json:"type,omitempty"` - Virtualmachineid string `json:"virtualmachineid,omitempty"` - } `json:"nic,omitempty"` - Ostypeid int64 `json:"ostypeid,omitempty"` - Password string `json:"password,omitempty"` - Passwordenabled bool `json:"passwordenabled,omitempty"` - Project string `json:"project,omitempty"` - Projectid string `json:"projectid,omitempty"` - Publicip string `json:"publicip,omitempty"` - Publicipid string `json:"publicipid,omitempty"` - Rootdeviceid int64 `json:"rootdeviceid,omitempty"` - Rootdevicetype string `json:"rootdevicetype,omitempty"` - Securitygroup []struct { - Account string `json:"account,omitempty"` - Description string `json:"description,omitempty"` - Domain string `json:"domain,omitempty"` - Domainid string `json:"domainid,omitempty"` - Egressrule []struct { - Account string `json:"account,omitempty"` - Cidr string `json:"cidr,omitempty"` - Endport int `json:"endport,omitempty"` - Icmpcode int `json:"icmpcode,omitempty"` - Icmptype int `json:"icmptype,omitempty"` - Protocol string `json:"protocol,omitempty"` - Ruleid string `json:"ruleid,omitempty"` - Securitygroupname string `json:"securitygroupname,omitempty"` - Startport int `json:"startport,omitempty"` - Tags []struct { - Account string `json:"account,omitempty"` - Customer string `json:"customer,omitempty"` - Domain string `json:"domain,omitempty"` - Domainid string `json:"domainid,omitempty"` - Key string `json:"key,omitempty"` - Project string `json:"project,omitempty"` - Projectid string `json:"projectid,omitempty"` - Resourceid string `json:"resourceid,omitempty"` - Resourcetype string `json:"resourcetype,omitempty"` - Value string `json:"value,omitempty"` - } `json:"tags,omitempty"` - } `json:"egressrule,omitempty"` - Id string `json:"id,omitempty"` - Ingressrule []struct { - Account string `json:"account,omitempty"` - Cidr string `json:"cidr,omitempty"` - Endport int `json:"endport,omitempty"` - Icmpcode int `json:"icmpcode,omitempty"` - Icmptype int `json:"icmptype,omitempty"` - Protocol string `json:"protocol,omitempty"` - Ruleid string `json:"ruleid,omitempty"` - Securitygroupname string `json:"securitygroupname,omitempty"` - Startport int `json:"startport,omitempty"` - Tags []struct { - Account string `json:"account,omitempty"` - Customer string `json:"customer,omitempty"` - Domain string `json:"domain,omitempty"` - Domainid string `json:"domainid,omitempty"` - Key string `json:"key,omitempty"` - Project string `json:"project,omitempty"` - Projectid string `json:"projectid,omitempty"` - Resourceid string `json:"resourceid,omitempty"` - Resourcetype string `json:"resourcetype,omitempty"` - Value string `json:"value,omitempty"` - } `json:"tags,omitempty"` - } `json:"ingressrule,omitempty"` - Name string `json:"name,omitempty"` - Project string `json:"project,omitempty"` - Projectid string `json:"projectid,omitempty"` - Tags []struct { - Account string `json:"account,omitempty"` - Customer string `json:"customer,omitempty"` - Domain string `json:"domain,omitempty"` - Domainid string `json:"domainid,omitempty"` - Key string `json:"key,omitempty"` - Project string `json:"project,omitempty"` - Projectid string `json:"projectid,omitempty"` - Resourceid string `json:"resourceid,omitempty"` - Resourcetype string `json:"resourcetype,omitempty"` - Value string `json:"value,omitempty"` - } `json:"tags,omitempty"` - Virtualmachinecount int `json:"virtualmachinecount,omitempty"` - Virtualmachineids []string `json:"virtualmachineids,omitempty"` - } `json:"securitygroup,omitempty"` - Serviceofferingid string `json:"serviceofferingid,omitempty"` - Serviceofferingname string `json:"serviceofferingname,omitempty"` - Servicestate string `json:"servicestate,omitempty"` - State string `json:"state,omitempty"` - Tags []struct { - Account string `json:"account,omitempty"` - Customer string `json:"customer,omitempty"` - Domain string `json:"domain,omitempty"` - Domainid string `json:"domainid,omitempty"` - Key string `json:"key,omitempty"` - Project string `json:"project,omitempty"` - Projectid string `json:"projectid,omitempty"` - Resourceid string `json:"resourceid,omitempty"` - Resourcetype string `json:"resourcetype,omitempty"` - Value string `json:"value,omitempty"` - } `json:"tags,omitempty"` - Templatedisplaytext string `json:"templatedisplaytext,omitempty"` - Templateid string `json:"templateid,omitempty"` - Templatename string `json:"templatename,omitempty"` - Userid string `json:"userid,omitempty"` - Username string `json:"username,omitempty"` - Vgpu string `json:"vgpu,omitempty"` - Zoneid string `json:"zoneid,omitempty"` - Zonename string `json:"zonename,omitempty"` + JobID string `json:"jobid"` + Account string `json:"account"` + Affinitygroup []UpdateVMAffinityGroupResponseAffinitygroup `json:"affinitygroup"` + Cpunumber int `json:"cpunumber"` + Cpuspeed int `json:"cpuspeed"` + Cpuused string `json:"cpuused"` + Created string `json:"created"` + Details map[string]string `json:"details"` + Diskioread int64 `json:"diskioread"` + Diskiowrite int64 `json:"diskiowrite"` + Diskkbsread int64 `json:"diskkbsread"` + Diskkbswrite int64 `json:"diskkbswrite"` + Diskofferingid string `json:"diskofferingid"` + Diskofferingname string `json:"diskofferingname"` + Displayname string `json:"displayname"` + Displayvm bool `json:"displayvm"` + Domain string `json:"domain"` + Domainid string `json:"domainid"` + Forvirtualnetwork bool `json:"forvirtualnetwork"` + Group string `json:"group"` + Groupid string `json:"groupid"` + Guestosid string `json:"guestosid"` + Haenable bool `json:"haenable"` + Hostid string `json:"hostid"` + Hostname string `json:"hostname"` + Hypervisor string `json:"hypervisor"` + Id string `json:"id"` + Instancename string `json:"instancename"` + Isdynamicallyscalable bool `json:"isdynamicallyscalable"` + Isodisplaytext string `json:"isodisplaytext"` + Isoid string `json:"isoid"` + Isoname string `json:"isoname"` + Keypair string `json:"keypair"` + Memory int `json:"memory"` + Memoryintfreekbs int64 `json:"memoryintfreekbs"` + Memorykbs int64 `json:"memorykbs"` + Memorytargetkbs int64 `json:"memorytargetkbs"` + Name string `json:"name"` + Networkkbsread int64 `json:"networkkbsread"` + Networkkbswrite int64 `json:"networkkbswrite"` + Nic []Nic `json:"nic"` + Ostypeid int64 `json:"ostypeid"` + Password string `json:"password"` + Passwordenabled bool `json:"passwordenabled"` + Project string `json:"project"` + Projectid string `json:"projectid"` + Publicip string `json:"publicip"` + Publicipid string `json:"publicipid"` + Rootdeviceid int64 `json:"rootdeviceid"` + Rootdevicetype string `json:"rootdevicetype"` + Securitygroup []UpdateVMAffinityGroupResponseSecuritygroup `json:"securitygroup"` + Serviceofferingid string `json:"serviceofferingid"` + Serviceofferingname string `json:"serviceofferingname"` + Servicestate string `json:"servicestate"` + State string `json:"state"` + Templatedisplaytext string `json:"templatedisplaytext"` + Templateid string `json:"templateid"` + Templatename string `json:"templatename"` + Userid string `json:"userid"` + Username string `json:"username"` + Vgpu string `json:"vgpu"` + Zoneid string `json:"zoneid"` + Zonename string `json:"zonename"` } -type ListAffinityGroupTypesParams struct { - p map[string]interface{} +type UpdateVMAffinityGroupResponseSecuritygroup struct { + Account string `json:"account"` + Description string `json:"description"` + Domain string `json:"domain"` + Domainid string `json:"domainid"` + Egressrule []UpdateVMAffinityGroupResponseSecuritygroupRule `json:"egressrule"` + Id string `json:"id"` + Ingressrule []UpdateVMAffinityGroupResponseSecuritygroupRule `json:"ingressrule"` + Name string `json:"name"` + Project string `json:"project"` + Projectid string `json:"projectid"` + Tags []Tags `json:"tags"` + Virtualmachinecount int `json:"virtualmachinecount"` + Virtualmachineids []interface{} `json:"virtualmachineids"` } -func (p *ListAffinityGroupTypesParams) toURLValues() url.Values { - u := url.Values{} - if p.p == nil { - return u - } - if v, found := p.p["keyword"]; found { - u.Set("keyword", v.(string)) - } - if v, found := p.p["page"]; found { - vv := strconv.Itoa(v.(int)) - u.Set("page", vv) - } - if v, found := p.p["pagesize"]; found { - vv := strconv.Itoa(v.(int)) - u.Set("pagesize", vv) - } - return u +type UpdateVMAffinityGroupResponseSecuritygroupRule struct { + Account string `json:"account"` + Cidr string `json:"cidr"` + Endport int `json:"endport"` + Icmpcode int `json:"icmpcode"` + Icmptype int `json:"icmptype"` + Protocol string `json:"protocol"` + Ruleid string `json:"ruleid"` + Securitygroupname string `json:"securitygroupname"` + Startport int `json:"startport"` + Tags []Tags `json:"tags"` } -func (p *ListAffinityGroupTypesParams) SetKeyword(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["keyword"] = v - return -} - -func (p *ListAffinityGroupTypesParams) SetPage(v int) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["page"] = v - return -} - -func (p *ListAffinityGroupTypesParams) SetPagesize(v int) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["pagesize"] = v - return -} - -// You should always use this function to get a new ListAffinityGroupTypesParams instance, -// as then you are sure you have configured all required params -func (s *AffinityGroupService) NewListAffinityGroupTypesParams() *ListAffinityGroupTypesParams { - p := &ListAffinityGroupTypesParams{} - p.p = make(map[string]interface{}) - return p -} - -// Lists affinity group types available -func (s *AffinityGroupService) ListAffinityGroupTypes(p *ListAffinityGroupTypesParams) (*ListAffinityGroupTypesResponse, error) { - resp, err := s.cs.newRequest("listAffinityGroupTypes", p.toURLValues()) - if err != nil { - return nil, err - } - - var r ListAffinityGroupTypesResponse - if err := json.Unmarshal(resp, &r); err != nil { - return nil, err - } - return &r, nil -} - -type ListAffinityGroupTypesResponse struct { - Count int `json:"count"` - AffinityGroupTypes []*AffinityGroupType `json:"affinitygrouptype"` -} - -type AffinityGroupType struct { - Type string `json:"type,omitempty"` +type UpdateVMAffinityGroupResponseAffinitygroup struct { + Account string `json:"account"` + Description string `json:"description"` + Domain string `json:"domain"` + Domainid string `json:"domainid"` + Id string `json:"id"` + Name string `json:"name"` + Project string `json:"project"` + Projectid string `json:"projectid"` + Type string `json:"type"` + VirtualmachineIds []string `json:"virtualmachineIds"` } diff --git a/vendor/github.com/xanzy/go-cloudstack/cloudstack/AlertService.go b/vendor/github.com/xanzy/go-cloudstack/cloudstack/AlertService.go index dc73a2177..e6fb54118 100644 --- a/vendor/github.com/xanzy/go-cloudstack/cloudstack/AlertService.go +++ b/vendor/github.com/xanzy/go-cloudstack/cloudstack/AlertService.go @@ -1,5 +1,5 @@ // -// Copyright 2016, Sander van Harmelen +// Copyright 2018, Sander van Harmelen // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -24,204 +24,6 @@ import ( "strings" ) -type ListAlertsParams struct { - p map[string]interface{} -} - -func (p *ListAlertsParams) toURLValues() url.Values { - u := url.Values{} - if p.p == nil { - return u - } - if v, found := p.p["id"]; found { - u.Set("id", v.(string)) - } - if v, found := p.p["keyword"]; found { - u.Set("keyword", v.(string)) - } - if v, found := p.p["name"]; found { - u.Set("name", v.(string)) - } - if v, found := p.p["page"]; found { - vv := strconv.Itoa(v.(int)) - u.Set("page", vv) - } - if v, found := p.p["pagesize"]; found { - vv := strconv.Itoa(v.(int)) - u.Set("pagesize", vv) - } - if v, found := p.p["type"]; found { - u.Set("type", v.(string)) - } - return u -} - -func (p *ListAlertsParams) SetId(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["id"] = v - return -} - -func (p *ListAlertsParams) SetKeyword(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["keyword"] = v - return -} - -func (p *ListAlertsParams) SetName(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["name"] = v - return -} - -func (p *ListAlertsParams) SetPage(v int) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["page"] = v - return -} - -func (p *ListAlertsParams) SetPagesize(v int) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["pagesize"] = v - return -} - -func (p *ListAlertsParams) SetType(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["type"] = v - return -} - -// You should always use this function to get a new ListAlertsParams instance, -// as then you are sure you have configured all required params -func (s *AlertService) NewListAlertsParams() *ListAlertsParams { - p := &ListAlertsParams{} - p.p = make(map[string]interface{}) - return p -} - -// This is a courtesy helper function, which in some cases may not work as expected! -func (s *AlertService) GetAlertID(name string, opts ...OptionFunc) (string, int, error) { - p := &ListAlertsParams{} - p.p = make(map[string]interface{}) - - p.p["name"] = name - - for _, fn := range opts { - if err := fn(s.cs, p); err != nil { - return "", -1, err - } - } - - l, err := s.ListAlerts(p) - if err != nil { - return "", -1, err - } - - if l.Count == 0 { - return "", l.Count, fmt.Errorf("No match found for %s: %+v", name, l) - } - - if l.Count == 1 { - return l.Alerts[0].Id, l.Count, nil - } - - if l.Count > 1 { - for _, v := range l.Alerts { - if v.Name == name { - return v.Id, l.Count, nil - } - } - } - return "", l.Count, fmt.Errorf("Could not find an exact match for %s: %+v", name, l) -} - -// This is a courtesy helper function, which in some cases may not work as expected! -func (s *AlertService) GetAlertByName(name string, opts ...OptionFunc) (*Alert, int, error) { - id, count, err := s.GetAlertID(name, opts...) - if err != nil { - return nil, count, err - } - - r, count, err := s.GetAlertByID(id, opts...) - if err != nil { - return nil, count, err - } - return r, count, nil -} - -// This is a courtesy helper function, which in some cases may not work as expected! -func (s *AlertService) GetAlertByID(id string, opts ...OptionFunc) (*Alert, int, error) { - p := &ListAlertsParams{} - p.p = make(map[string]interface{}) - - p.p["id"] = id - - for _, fn := range opts { - if err := fn(s.cs, p); err != nil { - return nil, -1, err - } - } - - l, err := s.ListAlerts(p) - if err != nil { - if strings.Contains(err.Error(), fmt.Sprintf( - "Invalid parameter id value=%s due to incorrect long value format, "+ - "or entity does not exist", id)) { - return nil, 0, fmt.Errorf("No match found for %s: %+v", id, l) - } - return nil, -1, err - } - - if l.Count == 0 { - return nil, l.Count, fmt.Errorf("No match found for %s: %+v", id, l) - } - - if l.Count == 1 { - return l.Alerts[0], l.Count, nil - } - return nil, l.Count, fmt.Errorf("There is more then one result for Alert UUID: %s!", id) -} - -// Lists all alerts. -func (s *AlertService) ListAlerts(p *ListAlertsParams) (*ListAlertsResponse, error) { - resp, err := s.cs.newRequest("listAlerts", p.toURLValues()) - if err != nil { - return nil, err - } - - var r ListAlertsResponse - if err := json.Unmarshal(resp, &r); err != nil { - return nil, err - } - return &r, nil -} - -type ListAlertsResponse struct { - Count int `json:"count"` - Alerts []*Alert `json:"alert"` -} - -type Alert struct { - Description string `json:"description,omitempty"` - Id string `json:"id,omitempty"` - Name string `json:"name,omitempty"` - Sent string `json:"sent,omitempty"` - Type int `json:"type,omitempty"` -} - type ArchiveAlertsParams struct { p map[string]interface{} } @@ -298,12 +100,32 @@ func (s *AlertService) ArchiveAlerts(p *ArchiveAlertsParams) (*ArchiveAlertsResp if err := json.Unmarshal(resp, &r); err != nil { return nil, err } + return &r, nil } type ArchiveAlertsResponse struct { - Displaytext string `json:"displaytext,omitempty"` - Success string `json:"success,omitempty"` + Displaytext string `json:"displaytext"` + Success bool `json:"success"` +} + +func (r *ArchiveAlertsResponse) UnmarshalJSON(b []byte) error { + var m map[string]interface{} + err := json.Unmarshal(b, &m) + if err != nil { + return err + } + + if success, ok := m["success"].(string); ok { + m["success"] = success == "true" + b, err = json.Marshal(m) + if err != nil { + return err + } + } + + type alias ArchiveAlertsResponse + return json.Unmarshal(b, (*alias)(r)) } type DeleteAlertsParams struct { @@ -382,12 +204,32 @@ func (s *AlertService) DeleteAlerts(p *DeleteAlertsParams) (*DeleteAlertsRespons if err := json.Unmarshal(resp, &r); err != nil { return nil, err } + return &r, nil } type DeleteAlertsResponse struct { - Displaytext string `json:"displaytext,omitempty"` - Success string `json:"success,omitempty"` + Displaytext string `json:"displaytext"` + Success bool `json:"success"` +} + +func (r *DeleteAlertsResponse) UnmarshalJSON(b []byte) error { + var m map[string]interface{} + err := json.Unmarshal(b, &m) + if err != nil { + return err + } + + if success, ok := m["success"].(string); ok { + m["success"] = success == "true" + b, err = json.Marshal(m) + if err != nil { + return err + } + } + + type alias DeleteAlertsResponse + return json.Unmarshal(b, (*alias)(r)) } type GenerateAlertParams struct { @@ -495,11 +337,211 @@ func (s *AlertService) GenerateAlert(p *GenerateAlertParams) (*GenerateAlertResp return nil, err } } + return &r, nil } type GenerateAlertResponse struct { - JobID string `json:"jobid,omitempty"` - Displaytext string `json:"displaytext,omitempty"` - Success bool `json:"success,omitempty"` + JobID string `json:"jobid"` + Displaytext string `json:"displaytext"` + Success bool `json:"success"` +} + +type ListAlertsParams struct { + p map[string]interface{} +} + +func (p *ListAlertsParams) toURLValues() url.Values { + u := url.Values{} + if p.p == nil { + return u + } + if v, found := p.p["id"]; found { + u.Set("id", v.(string)) + } + if v, found := p.p["keyword"]; found { + u.Set("keyword", v.(string)) + } + if v, found := p.p["name"]; found { + u.Set("name", v.(string)) + } + if v, found := p.p["page"]; found { + vv := strconv.Itoa(v.(int)) + u.Set("page", vv) + } + if v, found := p.p["pagesize"]; found { + vv := strconv.Itoa(v.(int)) + u.Set("pagesize", vv) + } + if v, found := p.p["type"]; found { + u.Set("type", v.(string)) + } + return u +} + +func (p *ListAlertsParams) SetId(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["id"] = v + return +} + +func (p *ListAlertsParams) SetKeyword(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["keyword"] = v + return +} + +func (p *ListAlertsParams) SetName(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["name"] = v + return +} + +func (p *ListAlertsParams) SetPage(v int) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["page"] = v + return +} + +func (p *ListAlertsParams) SetPagesize(v int) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["pagesize"] = v + return +} + +func (p *ListAlertsParams) SetType(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["type"] = v + return +} + +// You should always use this function to get a new ListAlertsParams instance, +// as then you are sure you have configured all required params +func (s *AlertService) NewListAlertsParams() *ListAlertsParams { + p := &ListAlertsParams{} + p.p = make(map[string]interface{}) + return p +} + +// This is a courtesy helper function, which in some cases may not work as expected! +func (s *AlertService) GetAlertID(name string, opts ...OptionFunc) (string, int, error) { + p := &ListAlertsParams{} + p.p = make(map[string]interface{}) + + p.p["name"] = name + + for _, fn := range append(s.cs.options, opts...) { + if err := fn(s.cs, p); err != nil { + return "", -1, err + } + } + + l, err := s.ListAlerts(p) + if err != nil { + return "", -1, err + } + + if l.Count == 0 { + return "", l.Count, fmt.Errorf("No match found for %s: %+v", name, l) + } + + if l.Count == 1 { + return l.Alerts[0].Id, l.Count, nil + } + + if l.Count > 1 { + for _, v := range l.Alerts { + if v.Name == name { + return v.Id, l.Count, nil + } + } + } + return "", l.Count, fmt.Errorf("Could not find an exact match for %s: %+v", name, l) +} + +// This is a courtesy helper function, which in some cases may not work as expected! +func (s *AlertService) GetAlertByName(name string, opts ...OptionFunc) (*Alert, int, error) { + id, count, err := s.GetAlertID(name, opts...) + if err != nil { + return nil, count, err + } + + r, count, err := s.GetAlertByID(id, opts...) + if err != nil { + return nil, count, err + } + return r, count, nil +} + +// This is a courtesy helper function, which in some cases may not work as expected! +func (s *AlertService) GetAlertByID(id string, opts ...OptionFunc) (*Alert, int, error) { + p := &ListAlertsParams{} + p.p = make(map[string]interface{}) + + p.p["id"] = id + + for _, fn := range append(s.cs.options, opts...) { + if err := fn(s.cs, p); err != nil { + return nil, -1, err + } + } + + l, err := s.ListAlerts(p) + if err != nil { + if strings.Contains(err.Error(), fmt.Sprintf( + "Invalid parameter id value=%s due to incorrect long value format, "+ + "or entity does not exist", id)) { + return nil, 0, fmt.Errorf("No match found for %s: %+v", id, l) + } + return nil, -1, err + } + + if l.Count == 0 { + return nil, l.Count, fmt.Errorf("No match found for %s: %+v", id, l) + } + + if l.Count == 1 { + return l.Alerts[0], l.Count, nil + } + return nil, l.Count, fmt.Errorf("There is more then one result for Alert UUID: %s!", id) +} + +// Lists all alerts. +func (s *AlertService) ListAlerts(p *ListAlertsParams) (*ListAlertsResponse, error) { + resp, err := s.cs.newRequest("listAlerts", p.toURLValues()) + if err != nil { + return nil, err + } + + var r ListAlertsResponse + if err := json.Unmarshal(resp, &r); err != nil { + return nil, err + } + + return &r, nil +} + +type ListAlertsResponse struct { + Count int `json:"count"` + Alerts []*Alert `json:"alert"` +} + +type Alert struct { + Description string `json:"description"` + Id string `json:"id"` + Name string `json:"name"` + Sent string `json:"sent"` + Type int `json:"type"` } diff --git a/vendor/github.com/xanzy/go-cloudstack/cloudstack/AsyncjobService.go b/vendor/github.com/xanzy/go-cloudstack/cloudstack/AsyncjobService.go index b3e1fd89a..93c1fa049 100644 --- a/vendor/github.com/xanzy/go-cloudstack/cloudstack/AsyncjobService.go +++ b/vendor/github.com/xanzy/go-cloudstack/cloudstack/AsyncjobService.go @@ -1,5 +1,5 @@ // -// Copyright 2016, Sander van Harmelen +// Copyright 2018, Sander van Harmelen // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -23,76 +23,6 @@ import ( "time" ) -type QueryAsyncJobResultParams struct { - p map[string]interface{} -} - -func (p *QueryAsyncJobResultParams) toURLValues() url.Values { - u := url.Values{} - if p.p == nil { - return u - } - if v, found := p.p["jobid"]; found { - u.Set("jobid", v.(string)) - } - return u -} - -func (p *QueryAsyncJobResultParams) SetJobid(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["jobid"] = v - return -} - -// You should always use this function to get a new QueryAsyncJobResultParams instance, -// as then you are sure you have configured all required params -func (s *AsyncjobService) NewQueryAsyncJobResultParams(jobid string) *QueryAsyncJobResultParams { - p := &QueryAsyncJobResultParams{} - p.p = make(map[string]interface{}) - p.p["jobid"] = jobid - return p -} - -// Retrieves the current status of asynchronous job. -func (s *AsyncjobService) QueryAsyncJobResult(p *QueryAsyncJobResultParams) (*QueryAsyncJobResultResponse, error) { - var resp json.RawMessage - var err error - - // We should be able to retry on failure as this call is idempotent - for i := 0; i < 3; i++ { - resp, err = s.cs.newRequest("queryAsyncJobResult", p.toURLValues()) - if err == nil { - break - } - time.Sleep(500 * time.Millisecond) - } - if err != nil { - return nil, err - } - - var r QueryAsyncJobResultResponse - if err := json.Unmarshal(resp, &r); err != nil { - return nil, err - } - return &r, nil -} - -type QueryAsyncJobResultResponse struct { - Accountid string `json:"accountid,omitempty"` - Cmd string `json:"cmd,omitempty"` - Created string `json:"created,omitempty"` - Jobinstanceid string `json:"jobinstanceid,omitempty"` - Jobinstancetype string `json:"jobinstancetype,omitempty"` - Jobprocstatus int `json:"jobprocstatus,omitempty"` - Jobresult json.RawMessage `json:"jobresult,omitempty"` - Jobresultcode int `json:"jobresultcode,omitempty"` - Jobresulttype string `json:"jobresulttype,omitempty"` - Jobstatus int `json:"jobstatus,omitempty"` - Userid string `json:"userid,omitempty"` -} - type ListAsyncJobsParams struct { p map[string]interface{} } @@ -216,6 +146,7 @@ func (s *AsyncjobService) ListAsyncJobs(p *ListAsyncJobsParams) (*ListAsyncJobsR if err := json.Unmarshal(resp, &r); err != nil { return nil, err } + return &r, nil } @@ -225,15 +156,86 @@ type ListAsyncJobsResponse struct { } type AsyncJob struct { - Accountid string `json:"accountid,omitempty"` - Cmd string `json:"cmd,omitempty"` - Created string `json:"created,omitempty"` - Jobinstanceid string `json:"jobinstanceid,omitempty"` - Jobinstancetype string `json:"jobinstancetype,omitempty"` - Jobprocstatus int `json:"jobprocstatus,omitempty"` - Jobresult json.RawMessage `json:"jobresult,omitempty"` - Jobresultcode int `json:"jobresultcode,omitempty"` - Jobresulttype string `json:"jobresulttype,omitempty"` - Jobstatus int `json:"jobstatus,omitempty"` - Userid string `json:"userid,omitempty"` + Accountid string `json:"accountid"` + Cmd string `json:"cmd"` + Created string `json:"created"` + Jobinstanceid string `json:"jobinstanceid"` + Jobinstancetype string `json:"jobinstancetype"` + Jobprocstatus int `json:"jobprocstatus"` + Jobresult json.RawMessage `json:"jobresult"` + Jobresultcode int `json:"jobresultcode"` + Jobresulttype string `json:"jobresulttype"` + Jobstatus int `json:"jobstatus"` + Userid string `json:"userid"` +} + +type QueryAsyncJobResultParams struct { + p map[string]interface{} +} + +func (p *QueryAsyncJobResultParams) toURLValues() url.Values { + u := url.Values{} + if p.p == nil { + return u + } + if v, found := p.p["jobid"]; found { + u.Set("jobid", v.(string)) + } + return u +} + +func (p *QueryAsyncJobResultParams) SetJobID(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["jobid"] = v + return +} + +// You should always use this function to get a new QueryAsyncJobResultParams instance, +// as then you are sure you have configured all required params +func (s *AsyncjobService) NewQueryAsyncJobResultParams(jobid string) *QueryAsyncJobResultParams { + p := &QueryAsyncJobResultParams{} + p.p = make(map[string]interface{}) + p.p["jobid"] = jobid + return p +} + +// Retrieves the current status of asynchronous job. +func (s *AsyncjobService) QueryAsyncJobResult(p *QueryAsyncJobResultParams) (*QueryAsyncJobResultResponse, error) { + var resp json.RawMessage + var err error + + // We should be able to retry on failure as this call is idempotent + for i := 0; i < 3; i++ { + resp, err = s.cs.newRequest("queryAsyncJobResult", p.toURLValues()) + if err == nil { + break + } + time.Sleep(500 * time.Millisecond) + } + if err != nil { + return nil, err + } + + var r QueryAsyncJobResultResponse + if err := json.Unmarshal(resp, &r); err != nil { + return nil, err + } + + return &r, nil +} + +type QueryAsyncJobResultResponse struct { + Accountid string `json:"accountid"` + Cmd string `json:"cmd"` + Created string `json:"created"` + Jobinstanceid string `json:"jobinstanceid"` + Jobinstancetype string `json:"jobinstancetype"` + Jobprocstatus int `json:"jobprocstatus"` + Jobresult json.RawMessage `json:"jobresult"` + Jobresultcode int `json:"jobresultcode"` + Jobresulttype string `json:"jobresulttype"` + Jobstatus int `json:"jobstatus"` + Userid string `json:"userid"` } diff --git a/vendor/github.com/xanzy/go-cloudstack/cloudstack/AuthenticationService.go b/vendor/github.com/xanzy/go-cloudstack/cloudstack/AuthenticationService.go index b97e70cfa..7842d049a 100644 --- a/vendor/github.com/xanzy/go-cloudstack/cloudstack/AuthenticationService.go +++ b/vendor/github.com/xanzy/go-cloudstack/cloudstack/AuthenticationService.go @@ -1,5 +1,5 @@ // -// Copyright 2016, Sander van Harmelen +// Copyright 2018, Sander van Harmelen // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -100,21 +100,23 @@ func (s *AuthenticationService) Login(p *LoginParams) (*LoginResponse, error) { if err := json.Unmarshal(resp, &r); err != nil { return nil, err } + return &r, nil } type LoginResponse struct { - Account string `json:"account,omitempty"` - Domainid string `json:"domainid,omitempty"` - Firstname string `json:"firstname,omitempty"` - Lastname string `json:"lastname,omitempty"` - Registered string `json:"registered,omitempty"` - Sessionkey string `json:"sessionkey,omitempty"` - Timeout int `json:"timeout,omitempty"` - Timezone string `json:"timezone,omitempty"` - Type string `json:"type,omitempty"` - Userid string `json:"userid,omitempty"` - Username string `json:"username,omitempty"` + Account string `json:"account"` + Domainid string `json:"domainid"` + Firstname string `json:"firstname"` + Lastname string `json:"lastname"` + Registered string `json:"registered"` + Sessionkey string `json:"sessionkey"` + Timeout int `json:"timeout"` + Timezone string `json:"timezone"` + Timezoneoffset string `json:"timezoneoffset"` + Type string `json:"type"` + Userid string `json:"userid"` + Username string `json:"username"` } type LogoutParams struct { @@ -148,9 +150,10 @@ func (s *AuthenticationService) Logout(p *LogoutParams) (*LogoutResponse, error) if err := json.Unmarshal(resp, &r); err != nil { return nil, err } + return &r, nil } type LogoutResponse struct { - Description string `json:"description,omitempty"` + Description string `json:"description"` } diff --git a/vendor/github.com/xanzy/go-cloudstack/cloudstack/AutoScaleService.go b/vendor/github.com/xanzy/go-cloudstack/cloudstack/AutoScaleService.go index 27e328616..fd18f87e7 100644 --- a/vendor/github.com/xanzy/go-cloudstack/cloudstack/AutoScaleService.go +++ b/vendor/github.com/xanzy/go-cloudstack/cloudstack/AutoScaleService.go @@ -1,5 +1,5 @@ // -// Copyright 2016, Sander van Harmelen +// Copyright 2018, Sander van Harmelen // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -24,232 +24,6 @@ import ( "strings" ) -type CreateCounterParams struct { - p map[string]interface{} -} - -func (p *CreateCounterParams) toURLValues() url.Values { - u := url.Values{} - if p.p == nil { - return u - } - if v, found := p.p["name"]; found { - u.Set("name", v.(string)) - } - if v, found := p.p["source"]; found { - u.Set("source", v.(string)) - } - if v, found := p.p["value"]; found { - u.Set("value", v.(string)) - } - return u -} - -func (p *CreateCounterParams) SetName(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["name"] = v - return -} - -func (p *CreateCounterParams) SetSource(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["source"] = v - return -} - -func (p *CreateCounterParams) SetValue(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["value"] = v - return -} - -// You should always use this function to get a new CreateCounterParams instance, -// as then you are sure you have configured all required params -func (s *AutoScaleService) NewCreateCounterParams(name string, source string, value string) *CreateCounterParams { - p := &CreateCounterParams{} - p.p = make(map[string]interface{}) - p.p["name"] = name - p.p["source"] = source - p.p["value"] = value - return p -} - -// Adds metric counter -func (s *AutoScaleService) CreateCounter(p *CreateCounterParams) (*CreateCounterResponse, error) { - resp, err := s.cs.newRequest("createCounter", p.toURLValues()) - if err != nil { - return nil, err - } - - var r CreateCounterResponse - if err := json.Unmarshal(resp, &r); err != nil { - return nil, err - } - - // If we have a async client, we need to wait for the async result - if s.cs.async { - b, err := s.cs.GetAsyncJobResult(r.JobID, s.cs.timeout) - if err != nil { - if err == AsyncTimeoutErr { - return &r, err - } - return nil, err - } - - b, err = getRawValue(b) - if err != nil { - return nil, err - } - - if err := json.Unmarshal(b, &r); err != nil { - return nil, err - } - } - return &r, nil -} - -type CreateCounterResponse struct { - JobID string `json:"jobid,omitempty"` - Id string `json:"id,omitempty"` - Name string `json:"name,omitempty"` - Source string `json:"source,omitempty"` - Value string `json:"value,omitempty"` - Zoneid string `json:"zoneid,omitempty"` -} - -type CreateConditionParams struct { - p map[string]interface{} -} - -func (p *CreateConditionParams) toURLValues() url.Values { - u := url.Values{} - if p.p == nil { - return u - } - if v, found := p.p["account"]; found { - u.Set("account", v.(string)) - } - if v, found := p.p["counterid"]; found { - u.Set("counterid", v.(string)) - } - if v, found := p.p["domainid"]; found { - u.Set("domainid", v.(string)) - } - if v, found := p.p["relationaloperator"]; found { - u.Set("relationaloperator", v.(string)) - } - if v, found := p.p["threshold"]; found { - vv := strconv.FormatInt(v.(int64), 10) - u.Set("threshold", vv) - } - return u -} - -func (p *CreateConditionParams) SetAccount(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["account"] = v - return -} - -func (p *CreateConditionParams) SetCounterid(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["counterid"] = v - return -} - -func (p *CreateConditionParams) SetDomainid(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["domainid"] = v - return -} - -func (p *CreateConditionParams) SetRelationaloperator(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["relationaloperator"] = v - return -} - -func (p *CreateConditionParams) SetThreshold(v int64) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["threshold"] = v - return -} - -// You should always use this function to get a new CreateConditionParams instance, -// as then you are sure you have configured all required params -func (s *AutoScaleService) NewCreateConditionParams(counterid string, relationaloperator string, threshold int64) *CreateConditionParams { - p := &CreateConditionParams{} - p.p = make(map[string]interface{}) - p.p["counterid"] = counterid - p.p["relationaloperator"] = relationaloperator - p.p["threshold"] = threshold - return p -} - -// Creates a condition -func (s *AutoScaleService) CreateCondition(p *CreateConditionParams) (*CreateConditionResponse, error) { - resp, err := s.cs.newRequest("createCondition", p.toURLValues()) - if err != nil { - return nil, err - } - - var r CreateConditionResponse - if err := json.Unmarshal(resp, &r); err != nil { - return nil, err - } - - // If we have a async client, we need to wait for the async result - if s.cs.async { - b, err := s.cs.GetAsyncJobResult(r.JobID, s.cs.timeout) - if err != nil { - if err == AsyncTimeoutErr { - return &r, err - } - return nil, err - } - - b, err = getRawValue(b) - if err != nil { - return nil, err - } - - if err := json.Unmarshal(b, &r); err != nil { - return nil, err - } - } - return &r, nil -} - -type CreateConditionResponse struct { - JobID string `json:"jobid,omitempty"` - Account string `json:"account,omitempty"` - Counter []string `json:"counter,omitempty"` - Domain string `json:"domain,omitempty"` - Domainid string `json:"domainid,omitempty"` - Id string `json:"id,omitempty"` - Project string `json:"project,omitempty"` - Projectid string `json:"projectid,omitempty"` - Relationaloperator string `json:"relationaloperator,omitempty"` - Threshold int64 `json:"threshold,omitempty"` - Zoneid string `json:"zoneid,omitempty"` -} - type CreateAutoScalePolicyParams struct { p map[string]interface{} } @@ -351,190 +125,22 @@ func (s *AutoScaleService) CreateAutoScalePolicy(p *CreateAutoScalePolicyParams) return nil, err } } + return &r, nil } type CreateAutoScalePolicyResponse struct { - JobID string `json:"jobid,omitempty"` - Account string `json:"account,omitempty"` - Action string `json:"action,omitempty"` - Conditions []string `json:"conditions,omitempty"` - Domain string `json:"domain,omitempty"` - Domainid string `json:"domainid,omitempty"` - Duration int `json:"duration,omitempty"` - Id string `json:"id,omitempty"` - Project string `json:"project,omitempty"` - Projectid string `json:"projectid,omitempty"` - Quiettime int `json:"quiettime,omitempty"` -} - -type CreateAutoScaleVmProfileParams struct { - p map[string]interface{} -} - -func (p *CreateAutoScaleVmProfileParams) toURLValues() url.Values { - u := url.Values{} - if p.p == nil { - return u - } - if v, found := p.p["autoscaleuserid"]; found { - u.Set("autoscaleuserid", v.(string)) - } - if v, found := p.p["counterparam"]; found { - i := 0 - for k, vv := range v.(map[string]string) { - u.Set(fmt.Sprintf("counterparam[%d].key", i), k) - u.Set(fmt.Sprintf("counterparam[%d].value", i), vv) - i++ - } - } - if v, found := p.p["destroyvmgraceperiod"]; found { - vv := strconv.Itoa(v.(int)) - u.Set("destroyvmgraceperiod", vv) - } - if v, found := p.p["fordisplay"]; found { - vv := strconv.FormatBool(v.(bool)) - u.Set("fordisplay", vv) - } - if v, found := p.p["otherdeployparams"]; found { - u.Set("otherdeployparams", v.(string)) - } - if v, found := p.p["serviceofferingid"]; found { - u.Set("serviceofferingid", v.(string)) - } - if v, found := p.p["templateid"]; found { - u.Set("templateid", v.(string)) - } - if v, found := p.p["zoneid"]; found { - u.Set("zoneid", v.(string)) - } - return u -} - -func (p *CreateAutoScaleVmProfileParams) SetAutoscaleuserid(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["autoscaleuserid"] = v - return -} - -func (p *CreateAutoScaleVmProfileParams) SetCounterparam(v map[string]string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["counterparam"] = v - return -} - -func (p *CreateAutoScaleVmProfileParams) SetDestroyvmgraceperiod(v int) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["destroyvmgraceperiod"] = v - return -} - -func (p *CreateAutoScaleVmProfileParams) SetFordisplay(v bool) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["fordisplay"] = v - return -} - -func (p *CreateAutoScaleVmProfileParams) SetOtherdeployparams(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["otherdeployparams"] = v - return -} - -func (p *CreateAutoScaleVmProfileParams) SetServiceofferingid(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["serviceofferingid"] = v - return -} - -func (p *CreateAutoScaleVmProfileParams) SetTemplateid(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["templateid"] = v - return -} - -func (p *CreateAutoScaleVmProfileParams) SetZoneid(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["zoneid"] = v - return -} - -// You should always use this function to get a new CreateAutoScaleVmProfileParams instance, -// as then you are sure you have configured all required params -func (s *AutoScaleService) NewCreateAutoScaleVmProfileParams(serviceofferingid string, templateid string, zoneid string) *CreateAutoScaleVmProfileParams { - p := &CreateAutoScaleVmProfileParams{} - p.p = make(map[string]interface{}) - p.p["serviceofferingid"] = serviceofferingid - p.p["templateid"] = templateid - p.p["zoneid"] = zoneid - return p -} - -// Creates a profile that contains information about the virtual machine which will be provisioned automatically by autoscale feature. -func (s *AutoScaleService) CreateAutoScaleVmProfile(p *CreateAutoScaleVmProfileParams) (*CreateAutoScaleVmProfileResponse, error) { - resp, err := s.cs.newRequest("createAutoScaleVmProfile", p.toURLValues()) - if err != nil { - return nil, err - } - - var r CreateAutoScaleVmProfileResponse - if err := json.Unmarshal(resp, &r); err != nil { - return nil, err - } - - // If we have a async client, we need to wait for the async result - if s.cs.async { - b, err := s.cs.GetAsyncJobResult(r.JobID, s.cs.timeout) - if err != nil { - if err == AsyncTimeoutErr { - return &r, err - } - return nil, err - } - - b, err = getRawValue(b) - if err != nil { - return nil, err - } - - if err := json.Unmarshal(b, &r); err != nil { - return nil, err - } - } - return &r, nil -} - -type CreateAutoScaleVmProfileResponse struct { - JobID string `json:"jobid,omitempty"` - Account string `json:"account,omitempty"` - Autoscaleuserid string `json:"autoscaleuserid,omitempty"` - Destroyvmgraceperiod int `json:"destroyvmgraceperiod,omitempty"` - Domain string `json:"domain,omitempty"` - Domainid string `json:"domainid,omitempty"` - Fordisplay bool `json:"fordisplay,omitempty"` - Id string `json:"id,omitempty"` - Otherdeployparams string `json:"otherdeployparams,omitempty"` - Project string `json:"project,omitempty"` - Projectid string `json:"projectid,omitempty"` - Serviceofferingid string `json:"serviceofferingid,omitempty"` - Templateid string `json:"templateid,omitempty"` - Zoneid string `json:"zoneid,omitempty"` + JobID string `json:"jobid"` + Account string `json:"account"` + Action string `json:"action"` + Conditions []string `json:"conditions"` + Domain string `json:"domain"` + Domainid string `json:"domainid"` + Duration int `json:"duration"` + Id string `json:"id"` + Project string `json:"project"` + Projectid string `json:"projectid"` + Quiettime int `json:"quiettime"` } type CreateAutoScaleVmGroupParams struct { @@ -688,68 +294,155 @@ func (s *AutoScaleService) CreateAutoScaleVmGroup(p *CreateAutoScaleVmGroupParam return nil, err } } + return &r, nil } type CreateAutoScaleVmGroupResponse struct { - JobID string `json:"jobid,omitempty"` - Account string `json:"account,omitempty"` - Domain string `json:"domain,omitempty"` - Domainid string `json:"domainid,omitempty"` - Fordisplay bool `json:"fordisplay,omitempty"` - Id string `json:"id,omitempty"` - Interval int `json:"interval,omitempty"` - Lbruleid string `json:"lbruleid,omitempty"` - Maxmembers int `json:"maxmembers,omitempty"` - Minmembers int `json:"minmembers,omitempty"` - Project string `json:"project,omitempty"` - Projectid string `json:"projectid,omitempty"` - Scaledownpolicies []string `json:"scaledownpolicies,omitempty"` - Scaleuppolicies []string `json:"scaleuppolicies,omitempty"` - State string `json:"state,omitempty"` - Vmprofileid string `json:"vmprofileid,omitempty"` + JobID string `json:"jobid"` + Account string `json:"account"` + Domain string `json:"domain"` + Domainid string `json:"domainid"` + Fordisplay bool `json:"fordisplay"` + Id string `json:"id"` + Interval int `json:"interval"` + Lbruleid string `json:"lbruleid"` + Maxmembers int `json:"maxmembers"` + Minmembers int `json:"minmembers"` + Project string `json:"project"` + Projectid string `json:"projectid"` + Scaledownpolicies []string `json:"scaledownpolicies"` + Scaleuppolicies []string `json:"scaleuppolicies"` + State string `json:"state"` + Vmprofileid string `json:"vmprofileid"` } -type DeleteCounterParams struct { +type CreateAutoScaleVmProfileParams struct { p map[string]interface{} } -func (p *DeleteCounterParams) toURLValues() url.Values { +func (p *CreateAutoScaleVmProfileParams) toURLValues() url.Values { u := url.Values{} if p.p == nil { return u } - if v, found := p.p["id"]; found { - u.Set("id", v.(string)) + if v, found := p.p["autoscaleuserid"]; found { + u.Set("autoscaleuserid", v.(string)) + } + if v, found := p.p["counterparam"]; found { + i := 0 + for k, vv := range v.(map[string]string) { + u.Set(fmt.Sprintf("counterparam[%d].key", i), k) + u.Set(fmt.Sprintf("counterparam[%d].value", i), vv) + i++ + } + } + if v, found := p.p["destroyvmgraceperiod"]; found { + vv := strconv.Itoa(v.(int)) + u.Set("destroyvmgraceperiod", vv) + } + if v, found := p.p["fordisplay"]; found { + vv := strconv.FormatBool(v.(bool)) + u.Set("fordisplay", vv) + } + if v, found := p.p["otherdeployparams"]; found { + u.Set("otherdeployparams", v.(string)) + } + if v, found := p.p["serviceofferingid"]; found { + u.Set("serviceofferingid", v.(string)) + } + if v, found := p.p["templateid"]; found { + u.Set("templateid", v.(string)) + } + if v, found := p.p["zoneid"]; found { + u.Set("zoneid", v.(string)) } return u } -func (p *DeleteCounterParams) SetId(v string) { +func (p *CreateAutoScaleVmProfileParams) SetAutoscaleuserid(v string) { if p.p == nil { p.p = make(map[string]interface{}) } - p.p["id"] = v + p.p["autoscaleuserid"] = v return } -// You should always use this function to get a new DeleteCounterParams instance, +func (p *CreateAutoScaleVmProfileParams) SetCounterparam(v map[string]string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["counterparam"] = v + return +} + +func (p *CreateAutoScaleVmProfileParams) SetDestroyvmgraceperiod(v int) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["destroyvmgraceperiod"] = v + return +} + +func (p *CreateAutoScaleVmProfileParams) SetFordisplay(v bool) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["fordisplay"] = v + return +} + +func (p *CreateAutoScaleVmProfileParams) SetOtherdeployparams(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["otherdeployparams"] = v + return +} + +func (p *CreateAutoScaleVmProfileParams) SetServiceofferingid(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["serviceofferingid"] = v + return +} + +func (p *CreateAutoScaleVmProfileParams) SetTemplateid(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["templateid"] = v + return +} + +func (p *CreateAutoScaleVmProfileParams) SetZoneid(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["zoneid"] = v + return +} + +// You should always use this function to get a new CreateAutoScaleVmProfileParams instance, // as then you are sure you have configured all required params -func (s *AutoScaleService) NewDeleteCounterParams(id string) *DeleteCounterParams { - p := &DeleteCounterParams{} +func (s *AutoScaleService) NewCreateAutoScaleVmProfileParams(serviceofferingid string, templateid string, zoneid string) *CreateAutoScaleVmProfileParams { + p := &CreateAutoScaleVmProfileParams{} p.p = make(map[string]interface{}) - p.p["id"] = id + p.p["serviceofferingid"] = serviceofferingid + p.p["templateid"] = templateid + p.p["zoneid"] = zoneid return p } -// Deletes a counter -func (s *AutoScaleService) DeleteCounter(p *DeleteCounterParams) (*DeleteCounterResponse, error) { - resp, err := s.cs.newRequest("deleteCounter", p.toURLValues()) +// Creates a profile that contains information about the virtual machine which will be provisioned automatically by autoscale feature. +func (s *AutoScaleService) CreateAutoScaleVmProfile(p *CreateAutoScaleVmProfileParams) (*CreateAutoScaleVmProfileResponse, error) { + resp, err := s.cs.newRequest("createAutoScaleVmProfile", p.toURLValues()) if err != nil { return nil, err } - var r DeleteCounterResponse + var r CreateAutoScaleVmProfileResponse if err := json.Unmarshal(resp, &r); err != nil { return nil, err } @@ -764,59 +457,123 @@ func (s *AutoScaleService) DeleteCounter(p *DeleteCounterParams) (*DeleteCounter return nil, err } + b, err = getRawValue(b) + if err != nil { + return nil, err + } + if err := json.Unmarshal(b, &r); err != nil { return nil, err } } + return &r, nil } -type DeleteCounterResponse struct { - JobID string `json:"jobid,omitempty"` - Displaytext string `json:"displaytext,omitempty"` - Success bool `json:"success,omitempty"` +type CreateAutoScaleVmProfileResponse struct { + JobID string `json:"jobid"` + Account string `json:"account"` + Autoscaleuserid string `json:"autoscaleuserid"` + Destroyvmgraceperiod int `json:"destroyvmgraceperiod"` + Domain string `json:"domain"` + Domainid string `json:"domainid"` + Fordisplay bool `json:"fordisplay"` + Id string `json:"id"` + Otherdeployparams string `json:"otherdeployparams"` + Project string `json:"project"` + Projectid string `json:"projectid"` + Serviceofferingid string `json:"serviceofferingid"` + Templateid string `json:"templateid"` + Zoneid string `json:"zoneid"` } -type DeleteConditionParams struct { +type CreateConditionParams struct { p map[string]interface{} } -func (p *DeleteConditionParams) toURLValues() url.Values { +func (p *CreateConditionParams) toURLValues() url.Values { u := url.Values{} if p.p == nil { return u } - if v, found := p.p["id"]; found { - u.Set("id", v.(string)) + if v, found := p.p["account"]; found { + u.Set("account", v.(string)) + } + if v, found := p.p["counterid"]; found { + u.Set("counterid", v.(string)) + } + if v, found := p.p["domainid"]; found { + u.Set("domainid", v.(string)) + } + if v, found := p.p["relationaloperator"]; found { + u.Set("relationaloperator", v.(string)) + } + if v, found := p.p["threshold"]; found { + vv := strconv.FormatInt(v.(int64), 10) + u.Set("threshold", vv) } return u } -func (p *DeleteConditionParams) SetId(v string) { +func (p *CreateConditionParams) SetAccount(v string) { if p.p == nil { p.p = make(map[string]interface{}) } - p.p["id"] = v + p.p["account"] = v return } -// You should always use this function to get a new DeleteConditionParams instance, +func (p *CreateConditionParams) SetCounterid(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["counterid"] = v + return +} + +func (p *CreateConditionParams) SetDomainid(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["domainid"] = v + return +} + +func (p *CreateConditionParams) SetRelationaloperator(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["relationaloperator"] = v + return +} + +func (p *CreateConditionParams) SetThreshold(v int64) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["threshold"] = v + return +} + +// You should always use this function to get a new CreateConditionParams instance, // as then you are sure you have configured all required params -func (s *AutoScaleService) NewDeleteConditionParams(id string) *DeleteConditionParams { - p := &DeleteConditionParams{} +func (s *AutoScaleService) NewCreateConditionParams(counterid string, relationaloperator string, threshold int64) *CreateConditionParams { + p := &CreateConditionParams{} p.p = make(map[string]interface{}) - p.p["id"] = id + p.p["counterid"] = counterid + p.p["relationaloperator"] = relationaloperator + p.p["threshold"] = threshold return p } -// Removes a condition -func (s *AutoScaleService) DeleteCondition(p *DeleteConditionParams) (*DeleteConditionResponse, error) { - resp, err := s.cs.newRequest("deleteCondition", p.toURLValues()) +// Creates a condition +func (s *AutoScaleService) CreateCondition(p *CreateConditionParams) (*CreateConditionResponse, error) { + resp, err := s.cs.newRequest("createCondition", p.toURLValues()) if err != nil { return nil, err } - var r DeleteConditionResponse + var r CreateConditionResponse if err := json.Unmarshal(resp, &r); err != nil { return nil, err } @@ -831,17 +588,131 @@ func (s *AutoScaleService) DeleteCondition(p *DeleteConditionParams) (*DeleteCon return nil, err } + b, err = getRawValue(b) + if err != nil { + return nil, err + } + if err := json.Unmarshal(b, &r); err != nil { return nil, err } } + return &r, nil } -type DeleteConditionResponse struct { - JobID string `json:"jobid,omitempty"` - Displaytext string `json:"displaytext,omitempty"` - Success bool `json:"success,omitempty"` +type CreateConditionResponse struct { + JobID string `json:"jobid"` + Account string `json:"account"` + Counter []string `json:"counter"` + Domain string `json:"domain"` + Domainid string `json:"domainid"` + Id string `json:"id"` + Project string `json:"project"` + Projectid string `json:"projectid"` + Relationaloperator string `json:"relationaloperator"` + Threshold int64 `json:"threshold"` + Zoneid string `json:"zoneid"` +} + +type CreateCounterParams struct { + p map[string]interface{} +} + +func (p *CreateCounterParams) toURLValues() url.Values { + u := url.Values{} + if p.p == nil { + return u + } + if v, found := p.p["name"]; found { + u.Set("name", v.(string)) + } + if v, found := p.p["source"]; found { + u.Set("source", v.(string)) + } + if v, found := p.p["value"]; found { + u.Set("value", v.(string)) + } + return u +} + +func (p *CreateCounterParams) SetName(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["name"] = v + return +} + +func (p *CreateCounterParams) SetSource(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["source"] = v + return +} + +func (p *CreateCounterParams) SetValue(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["value"] = v + return +} + +// You should always use this function to get a new CreateCounterParams instance, +// as then you are sure you have configured all required params +func (s *AutoScaleService) NewCreateCounterParams(name string, source string, value string) *CreateCounterParams { + p := &CreateCounterParams{} + p.p = make(map[string]interface{}) + p.p["name"] = name + p.p["source"] = source + p.p["value"] = value + return p +} + +// Adds metric counter +func (s *AutoScaleService) CreateCounter(p *CreateCounterParams) (*CreateCounterResponse, error) { + resp, err := s.cs.newRequest("createCounter", p.toURLValues()) + if err != nil { + return nil, err + } + + var r CreateCounterResponse + if err := json.Unmarshal(resp, &r); err != nil { + return nil, err + } + + // If we have a async client, we need to wait for the async result + if s.cs.async { + b, err := s.cs.GetAsyncJobResult(r.JobID, s.cs.timeout) + if err != nil { + if err == AsyncTimeoutErr { + return &r, err + } + return nil, err + } + + b, err = getRawValue(b) + if err != nil { + return nil, err + } + + if err := json.Unmarshal(b, &r); err != nil { + return nil, err + } + } + + return &r, nil +} + +type CreateCounterResponse struct { + JobID string `json:"jobid"` + Id string `json:"id"` + Name string `json:"name"` + Source string `json:"source"` + Value string `json:"value"` + Zoneid string `json:"zoneid"` } type DeleteAutoScalePolicyParams struct { @@ -902,80 +773,14 @@ func (s *AutoScaleService) DeleteAutoScalePolicy(p *DeleteAutoScalePolicyParams) return nil, err } } + return &r, nil } type DeleteAutoScalePolicyResponse struct { - JobID string `json:"jobid,omitempty"` - Displaytext string `json:"displaytext,omitempty"` - Success bool `json:"success,omitempty"` -} - -type DeleteAutoScaleVmProfileParams struct { - p map[string]interface{} -} - -func (p *DeleteAutoScaleVmProfileParams) toURLValues() url.Values { - u := url.Values{} - if p.p == nil { - return u - } - if v, found := p.p["id"]; found { - u.Set("id", v.(string)) - } - return u -} - -func (p *DeleteAutoScaleVmProfileParams) SetId(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["id"] = v - return -} - -// You should always use this function to get a new DeleteAutoScaleVmProfileParams instance, -// as then you are sure you have configured all required params -func (s *AutoScaleService) NewDeleteAutoScaleVmProfileParams(id string) *DeleteAutoScaleVmProfileParams { - p := &DeleteAutoScaleVmProfileParams{} - p.p = make(map[string]interface{}) - p.p["id"] = id - return p -} - -// Deletes a autoscale vm profile. -func (s *AutoScaleService) DeleteAutoScaleVmProfile(p *DeleteAutoScaleVmProfileParams) (*DeleteAutoScaleVmProfileResponse, error) { - resp, err := s.cs.newRequest("deleteAutoScaleVmProfile", p.toURLValues()) - if err != nil { - return nil, err - } - - var r DeleteAutoScaleVmProfileResponse - if err := json.Unmarshal(resp, &r); err != nil { - return nil, err - } - - // If we have a async client, we need to wait for the async result - if s.cs.async { - b, err := s.cs.GetAsyncJobResult(r.JobID, s.cs.timeout) - if err != nil { - if err == AsyncTimeoutErr { - return &r, err - } - return nil, err - } - - if err := json.Unmarshal(b, &r); err != nil { - return nil, err - } - } - return &r, nil -} - -type DeleteAutoScaleVmProfileResponse struct { - JobID string `json:"jobid,omitempty"` - Displaytext string `json:"displaytext,omitempty"` - Success bool `json:"success,omitempty"` + JobID string `json:"jobid"` + Displaytext string `json:"displaytext"` + Success bool `json:"success"` } type DeleteAutoScaleVmGroupParams struct { @@ -1036,20 +841,21 @@ func (s *AutoScaleService) DeleteAutoScaleVmGroup(p *DeleteAutoScaleVmGroupParam return nil, err } } + return &r, nil } type DeleteAutoScaleVmGroupResponse struct { - JobID string `json:"jobid,omitempty"` - Displaytext string `json:"displaytext,omitempty"` - Success bool `json:"success,omitempty"` + JobID string `json:"jobid"` + Displaytext string `json:"displaytext"` + Success bool `json:"success"` } -type ListCountersParams struct { +type DeleteAutoScaleVmProfileParams struct { p map[string]interface{} } -func (p *ListCountersParams) toURLValues() url.Values { +func (p *DeleteAutoScaleVmProfileParams) toURLValues() url.Values { u := url.Values{} if p.p == nil { return u @@ -1057,27 +863,10 @@ func (p *ListCountersParams) toURLValues() url.Values { if v, found := p.p["id"]; found { u.Set("id", v.(string)) } - if v, found := p.p["keyword"]; found { - u.Set("keyword", v.(string)) - } - if v, found := p.p["name"]; found { - u.Set("name", v.(string)) - } - if v, found := p.p["page"]; found { - vv := strconv.Itoa(v.(int)) - u.Set("page", vv) - } - if v, found := p.p["pagesize"]; found { - vv := strconv.Itoa(v.(int)) - u.Set("pagesize", vv) - } - if v, found := p.p["source"]; found { - u.Set("source", v.(string)) - } return u } -func (p *ListCountersParams) SetId(v string) { +func (p *DeleteAutoScaleVmProfileParams) SetId(v string) { if p.p == nil { p.p = make(map[string]interface{}) } @@ -1085,235 +874,67 @@ func (p *ListCountersParams) SetId(v string) { return } -func (p *ListCountersParams) SetKeyword(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["keyword"] = v - return -} - -func (p *ListCountersParams) SetName(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["name"] = v - return -} - -func (p *ListCountersParams) SetPage(v int) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["page"] = v - return -} - -func (p *ListCountersParams) SetPagesize(v int) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["pagesize"] = v - return -} - -func (p *ListCountersParams) SetSource(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["source"] = v - return -} - -// You should always use this function to get a new ListCountersParams instance, +// You should always use this function to get a new DeleteAutoScaleVmProfileParams instance, // as then you are sure you have configured all required params -func (s *AutoScaleService) NewListCountersParams() *ListCountersParams { - p := &ListCountersParams{} +func (s *AutoScaleService) NewDeleteAutoScaleVmProfileParams(id string) *DeleteAutoScaleVmProfileParams { + p := &DeleteAutoScaleVmProfileParams{} p.p = make(map[string]interface{}) + p.p["id"] = id return p } -// This is a courtesy helper function, which in some cases may not work as expected! -func (s *AutoScaleService) GetCounterID(name string, opts ...OptionFunc) (string, int, error) { - p := &ListCountersParams{} - p.p = make(map[string]interface{}) - - p.p["name"] = name - - for _, fn := range opts { - if err := fn(s.cs, p); err != nil { - return "", -1, err - } - } - - l, err := s.ListCounters(p) +// Deletes a autoscale vm profile. +func (s *AutoScaleService) DeleteAutoScaleVmProfile(p *DeleteAutoScaleVmProfileParams) (*DeleteAutoScaleVmProfileResponse, error) { + resp, err := s.cs.newRequest("deleteAutoScaleVmProfile", p.toURLValues()) if err != nil { - return "", -1, err + return nil, err } - if l.Count == 0 { - return "", l.Count, fmt.Errorf("No match found for %s: %+v", name, l) + var r DeleteAutoScaleVmProfileResponse + if err := json.Unmarshal(resp, &r); err != nil { + return nil, err } - if l.Count == 1 { - return l.Counters[0].Id, l.Count, nil - } - - if l.Count > 1 { - for _, v := range l.Counters { - if v.Name == name { - return v.Id, l.Count, nil + // If we have a async client, we need to wait for the async result + if s.cs.async { + b, err := s.cs.GetAsyncJobResult(r.JobID, s.cs.timeout) + if err != nil { + if err == AsyncTimeoutErr { + return &r, err } + return nil, err } - } - return "", l.Count, fmt.Errorf("Could not find an exact match for %s: %+v", name, l) -} -// This is a courtesy helper function, which in some cases may not work as expected! -func (s *AutoScaleService) GetCounterByName(name string, opts ...OptionFunc) (*Counter, int, error) { - id, count, err := s.GetCounterID(name, opts...) - if err != nil { - return nil, count, err - } - - r, count, err := s.GetCounterByID(id, opts...) - if err != nil { - return nil, count, err - } - return r, count, nil -} - -// This is a courtesy helper function, which in some cases may not work as expected! -func (s *AutoScaleService) GetCounterByID(id string, opts ...OptionFunc) (*Counter, int, error) { - p := &ListCountersParams{} - p.p = make(map[string]interface{}) - - p.p["id"] = id - - for _, fn := range opts { - if err := fn(s.cs, p); err != nil { - return nil, -1, err + if err := json.Unmarshal(b, &r); err != nil { + return nil, err } } - l, err := s.ListCounters(p) - if err != nil { - if strings.Contains(err.Error(), fmt.Sprintf( - "Invalid parameter id value=%s due to incorrect long value format, "+ - "or entity does not exist", id)) { - return nil, 0, fmt.Errorf("No match found for %s: %+v", id, l) - } - return nil, -1, err - } - - if l.Count == 0 { - return nil, l.Count, fmt.Errorf("No match found for %s: %+v", id, l) - } - - if l.Count == 1 { - return l.Counters[0], l.Count, nil - } - return nil, l.Count, fmt.Errorf("There is more then one result for Counter UUID: %s!", id) -} - -// List the counters -func (s *AutoScaleService) ListCounters(p *ListCountersParams) (*ListCountersResponse, error) { - resp, err := s.cs.newRequest("listCounters", p.toURLValues()) - if err != nil { - return nil, err - } - - var r ListCountersResponse - if err := json.Unmarshal(resp, &r); err != nil { - return nil, err - } return &r, nil } -type ListCountersResponse struct { - Count int `json:"count"` - Counters []*Counter `json:"counter"` +type DeleteAutoScaleVmProfileResponse struct { + JobID string `json:"jobid"` + Displaytext string `json:"displaytext"` + Success bool `json:"success"` } -type Counter struct { - Id string `json:"id,omitempty"` - Name string `json:"name,omitempty"` - Source string `json:"source,omitempty"` - Value string `json:"value,omitempty"` - Zoneid string `json:"zoneid,omitempty"` -} - -type ListConditionsParams struct { +type DeleteConditionParams struct { p map[string]interface{} } -func (p *ListConditionsParams) toURLValues() url.Values { +func (p *DeleteConditionParams) toURLValues() url.Values { u := url.Values{} if p.p == nil { return u } - if v, found := p.p["account"]; found { - u.Set("account", v.(string)) - } - if v, found := p.p["counterid"]; found { - u.Set("counterid", v.(string)) - } - if v, found := p.p["domainid"]; found { - u.Set("domainid", v.(string)) - } if v, found := p.p["id"]; found { u.Set("id", v.(string)) } - if v, found := p.p["isrecursive"]; found { - vv := strconv.FormatBool(v.(bool)) - u.Set("isrecursive", vv) - } - if v, found := p.p["keyword"]; found { - u.Set("keyword", v.(string)) - } - if v, found := p.p["listall"]; found { - vv := strconv.FormatBool(v.(bool)) - u.Set("listall", vv) - } - if v, found := p.p["page"]; found { - vv := strconv.Itoa(v.(int)) - u.Set("page", vv) - } - if v, found := p.p["pagesize"]; found { - vv := strconv.Itoa(v.(int)) - u.Set("pagesize", vv) - } - if v, found := p.p["policyid"]; found { - u.Set("policyid", v.(string)) - } return u } -func (p *ListConditionsParams) SetAccount(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["account"] = v - return -} - -func (p *ListConditionsParams) SetCounterid(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["counterid"] = v - return -} - -func (p *ListConditionsParams) SetDomainid(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["domainid"] = v - return -} - -func (p *ListConditionsParams) SetId(v string) { +func (p *DeleteConditionParams) SetId(v string) { if p.p == nil { p.p = make(map[string]interface{}) } @@ -1321,125 +942,289 @@ func (p *ListConditionsParams) SetId(v string) { return } -func (p *ListConditionsParams) SetIsrecursive(v bool) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["isrecursive"] = v - return -} - -func (p *ListConditionsParams) SetKeyword(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["keyword"] = v - return -} - -func (p *ListConditionsParams) SetListall(v bool) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["listall"] = v - return -} - -func (p *ListConditionsParams) SetPage(v int) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["page"] = v - return -} - -func (p *ListConditionsParams) SetPagesize(v int) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["pagesize"] = v - return -} - -func (p *ListConditionsParams) SetPolicyid(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["policyid"] = v - return -} - -// You should always use this function to get a new ListConditionsParams instance, +// You should always use this function to get a new DeleteConditionParams instance, // as then you are sure you have configured all required params -func (s *AutoScaleService) NewListConditionsParams() *ListConditionsParams { - p := &ListConditionsParams{} +func (s *AutoScaleService) NewDeleteConditionParams(id string) *DeleteConditionParams { + p := &DeleteConditionParams{} p.p = make(map[string]interface{}) + p.p["id"] = id return p } -// This is a courtesy helper function, which in some cases may not work as expected! -func (s *AutoScaleService) GetConditionByID(id string, opts ...OptionFunc) (*Condition, int, error) { - p := &ListConditionsParams{} - p.p = make(map[string]interface{}) - - p.p["id"] = id - - for _, fn := range opts { - if err := fn(s.cs, p); err != nil { - return nil, -1, err - } - } - - l, err := s.ListConditions(p) - if err != nil { - if strings.Contains(err.Error(), fmt.Sprintf( - "Invalid parameter id value=%s due to incorrect long value format, "+ - "or entity does not exist", id)) { - return nil, 0, fmt.Errorf("No match found for %s: %+v", id, l) - } - return nil, -1, err - } - - if l.Count == 0 { - return nil, l.Count, fmt.Errorf("No match found for %s: %+v", id, l) - } - - if l.Count == 1 { - return l.Conditions[0], l.Count, nil - } - return nil, l.Count, fmt.Errorf("There is more then one result for Condition UUID: %s!", id) -} - -// List Conditions for the specific user -func (s *AutoScaleService) ListConditions(p *ListConditionsParams) (*ListConditionsResponse, error) { - resp, err := s.cs.newRequest("listConditions", p.toURLValues()) +// Removes a condition +func (s *AutoScaleService) DeleteCondition(p *DeleteConditionParams) (*DeleteConditionResponse, error) { + resp, err := s.cs.newRequest("deleteCondition", p.toURLValues()) if err != nil { return nil, err } - var r ListConditionsResponse + var r DeleteConditionResponse if err := json.Unmarshal(resp, &r); err != nil { return nil, err } + + // If we have a async client, we need to wait for the async result + if s.cs.async { + b, err := s.cs.GetAsyncJobResult(r.JobID, s.cs.timeout) + if err != nil { + if err == AsyncTimeoutErr { + return &r, err + } + return nil, err + } + + if err := json.Unmarshal(b, &r); err != nil { + return nil, err + } + } + return &r, nil } -type ListConditionsResponse struct { - Count int `json:"count"` - Conditions []*Condition `json:"condition"` +type DeleteConditionResponse struct { + JobID string `json:"jobid"` + Displaytext string `json:"displaytext"` + Success bool `json:"success"` } -type Condition struct { - Account string `json:"account,omitempty"` - Counter []string `json:"counter,omitempty"` - Domain string `json:"domain,omitempty"` - Domainid string `json:"domainid,omitempty"` - Id string `json:"id,omitempty"` - Project string `json:"project,omitempty"` - Projectid string `json:"projectid,omitempty"` - Relationaloperator string `json:"relationaloperator,omitempty"` - Threshold int64 `json:"threshold,omitempty"` - Zoneid string `json:"zoneid,omitempty"` +type DeleteCounterParams struct { + p map[string]interface{} +} + +func (p *DeleteCounterParams) toURLValues() url.Values { + u := url.Values{} + if p.p == nil { + return u + } + if v, found := p.p["id"]; found { + u.Set("id", v.(string)) + } + return u +} + +func (p *DeleteCounterParams) SetId(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["id"] = v + return +} + +// You should always use this function to get a new DeleteCounterParams instance, +// as then you are sure you have configured all required params +func (s *AutoScaleService) NewDeleteCounterParams(id string) *DeleteCounterParams { + p := &DeleteCounterParams{} + p.p = make(map[string]interface{}) + p.p["id"] = id + return p +} + +// Deletes a counter +func (s *AutoScaleService) DeleteCounter(p *DeleteCounterParams) (*DeleteCounterResponse, error) { + resp, err := s.cs.newRequest("deleteCounter", p.toURLValues()) + if err != nil { + return nil, err + } + + var r DeleteCounterResponse + if err := json.Unmarshal(resp, &r); err != nil { + return nil, err + } + + // If we have a async client, we need to wait for the async result + if s.cs.async { + b, err := s.cs.GetAsyncJobResult(r.JobID, s.cs.timeout) + if err != nil { + if err == AsyncTimeoutErr { + return &r, err + } + return nil, err + } + + if err := json.Unmarshal(b, &r); err != nil { + return nil, err + } + } + + return &r, nil +} + +type DeleteCounterResponse struct { + JobID string `json:"jobid"` + Displaytext string `json:"displaytext"` + Success bool `json:"success"` +} + +type DisableAutoScaleVmGroupParams struct { + p map[string]interface{} +} + +func (p *DisableAutoScaleVmGroupParams) toURLValues() url.Values { + u := url.Values{} + if p.p == nil { + return u + } + if v, found := p.p["id"]; found { + u.Set("id", v.(string)) + } + return u +} + +func (p *DisableAutoScaleVmGroupParams) SetId(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["id"] = v + return +} + +// You should always use this function to get a new DisableAutoScaleVmGroupParams instance, +// as then you are sure you have configured all required params +func (s *AutoScaleService) NewDisableAutoScaleVmGroupParams(id string) *DisableAutoScaleVmGroupParams { + p := &DisableAutoScaleVmGroupParams{} + p.p = make(map[string]interface{}) + p.p["id"] = id + return p +} + +// Disables an AutoScale Vm Group +func (s *AutoScaleService) DisableAutoScaleVmGroup(p *DisableAutoScaleVmGroupParams) (*DisableAutoScaleVmGroupResponse, error) { + resp, err := s.cs.newRequest("disableAutoScaleVmGroup", p.toURLValues()) + if err != nil { + return nil, err + } + + var r DisableAutoScaleVmGroupResponse + if err := json.Unmarshal(resp, &r); err != nil { + return nil, err + } + + // If we have a async client, we need to wait for the async result + if s.cs.async { + b, err := s.cs.GetAsyncJobResult(r.JobID, s.cs.timeout) + if err != nil { + if err == AsyncTimeoutErr { + return &r, err + } + return nil, err + } + + b, err = getRawValue(b) + if err != nil { + return nil, err + } + + if err := json.Unmarshal(b, &r); err != nil { + return nil, err + } + } + + return &r, nil +} + +type DisableAutoScaleVmGroupResponse struct { + JobID string `json:"jobid"` + Account string `json:"account"` + Domain string `json:"domain"` + Domainid string `json:"domainid"` + Fordisplay bool `json:"fordisplay"` + Id string `json:"id"` + Interval int `json:"interval"` + Lbruleid string `json:"lbruleid"` + Maxmembers int `json:"maxmembers"` + Minmembers int `json:"minmembers"` + Project string `json:"project"` + Projectid string `json:"projectid"` + Scaledownpolicies []string `json:"scaledownpolicies"` + Scaleuppolicies []string `json:"scaleuppolicies"` + State string `json:"state"` + Vmprofileid string `json:"vmprofileid"` +} + +type EnableAutoScaleVmGroupParams struct { + p map[string]interface{} +} + +func (p *EnableAutoScaleVmGroupParams) toURLValues() url.Values { + u := url.Values{} + if p.p == nil { + return u + } + if v, found := p.p["id"]; found { + u.Set("id", v.(string)) + } + return u +} + +func (p *EnableAutoScaleVmGroupParams) SetId(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["id"] = v + return +} + +// You should always use this function to get a new EnableAutoScaleVmGroupParams instance, +// as then you are sure you have configured all required params +func (s *AutoScaleService) NewEnableAutoScaleVmGroupParams(id string) *EnableAutoScaleVmGroupParams { + p := &EnableAutoScaleVmGroupParams{} + p.p = make(map[string]interface{}) + p.p["id"] = id + return p +} + +// Enables an AutoScale Vm Group +func (s *AutoScaleService) EnableAutoScaleVmGroup(p *EnableAutoScaleVmGroupParams) (*EnableAutoScaleVmGroupResponse, error) { + resp, err := s.cs.newRequest("enableAutoScaleVmGroup", p.toURLValues()) + if err != nil { + return nil, err + } + + var r EnableAutoScaleVmGroupResponse + if err := json.Unmarshal(resp, &r); err != nil { + return nil, err + } + + // If we have a async client, we need to wait for the async result + if s.cs.async { + b, err := s.cs.GetAsyncJobResult(r.JobID, s.cs.timeout) + if err != nil { + if err == AsyncTimeoutErr { + return &r, err + } + return nil, err + } + + b, err = getRawValue(b) + if err != nil { + return nil, err + } + + if err := json.Unmarshal(b, &r); err != nil { + return nil, err + } + } + + return &r, nil +} + +type EnableAutoScaleVmGroupResponse struct { + JobID string `json:"jobid"` + Account string `json:"account"` + Domain string `json:"domain"` + Domainid string `json:"domainid"` + Fordisplay bool `json:"fordisplay"` + Id string `json:"id"` + Interval int `json:"interval"` + Lbruleid string `json:"lbruleid"` + Maxmembers int `json:"maxmembers"` + Minmembers int `json:"minmembers"` + Project string `json:"project"` + Projectid string `json:"projectid"` + Scaledownpolicies []string `json:"scaledownpolicies"` + Scaleuppolicies []string `json:"scaleuppolicies"` + State string `json:"state"` + Vmprofileid string `json:"vmprofileid"` } type ListAutoScalePoliciesParams struct { @@ -1594,7 +1379,7 @@ func (s *AutoScaleService) GetAutoScalePolicyByID(id string, opts ...OptionFunc) p.p["id"] = id - for _, fn := range opts { + for _, fn := range append(s.cs.options, opts...) { if err := fn(s.cs, p); err != nil { return nil, -1, err } @@ -1631,6 +1416,7 @@ func (s *AutoScaleService) ListAutoScalePolicies(p *ListAutoScalePoliciesParams) if err := json.Unmarshal(resp, &r); err != nil { return nil, err } + return &r, nil } @@ -1640,263 +1426,16 @@ type ListAutoScalePoliciesResponse struct { } type AutoScalePolicy struct { - Account string `json:"account,omitempty"` - Action string `json:"action,omitempty"` - Conditions []string `json:"conditions,omitempty"` - Domain string `json:"domain,omitempty"` - Domainid string `json:"domainid,omitempty"` - Duration int `json:"duration,omitempty"` - Id string `json:"id,omitempty"` - Project string `json:"project,omitempty"` - Projectid string `json:"projectid,omitempty"` - Quiettime int `json:"quiettime,omitempty"` -} - -type ListAutoScaleVmProfilesParams struct { - p map[string]interface{} -} - -func (p *ListAutoScaleVmProfilesParams) toURLValues() url.Values { - u := url.Values{} - if p.p == nil { - return u - } - if v, found := p.p["account"]; found { - u.Set("account", v.(string)) - } - if v, found := p.p["domainid"]; found { - u.Set("domainid", v.(string)) - } - if v, found := p.p["fordisplay"]; found { - vv := strconv.FormatBool(v.(bool)) - u.Set("fordisplay", vv) - } - if v, found := p.p["id"]; found { - u.Set("id", v.(string)) - } - if v, found := p.p["isrecursive"]; found { - vv := strconv.FormatBool(v.(bool)) - u.Set("isrecursive", vv) - } - if v, found := p.p["keyword"]; found { - u.Set("keyword", v.(string)) - } - if v, found := p.p["listall"]; found { - vv := strconv.FormatBool(v.(bool)) - u.Set("listall", vv) - } - if v, found := p.p["otherdeployparams"]; found { - u.Set("otherdeployparams", v.(string)) - } - if v, found := p.p["page"]; found { - vv := strconv.Itoa(v.(int)) - u.Set("page", vv) - } - if v, found := p.p["pagesize"]; found { - vv := strconv.Itoa(v.(int)) - u.Set("pagesize", vv) - } - if v, found := p.p["projectid"]; found { - u.Set("projectid", v.(string)) - } - if v, found := p.p["serviceofferingid"]; found { - u.Set("serviceofferingid", v.(string)) - } - if v, found := p.p["templateid"]; found { - u.Set("templateid", v.(string)) - } - if v, found := p.p["zoneid"]; found { - u.Set("zoneid", v.(string)) - } - return u -} - -func (p *ListAutoScaleVmProfilesParams) SetAccount(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["account"] = v - return -} - -func (p *ListAutoScaleVmProfilesParams) SetDomainid(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["domainid"] = v - return -} - -func (p *ListAutoScaleVmProfilesParams) SetFordisplay(v bool) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["fordisplay"] = v - return -} - -func (p *ListAutoScaleVmProfilesParams) SetId(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["id"] = v - return -} - -func (p *ListAutoScaleVmProfilesParams) SetIsrecursive(v bool) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["isrecursive"] = v - return -} - -func (p *ListAutoScaleVmProfilesParams) SetKeyword(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["keyword"] = v - return -} - -func (p *ListAutoScaleVmProfilesParams) SetListall(v bool) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["listall"] = v - return -} - -func (p *ListAutoScaleVmProfilesParams) SetOtherdeployparams(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["otherdeployparams"] = v - return -} - -func (p *ListAutoScaleVmProfilesParams) SetPage(v int) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["page"] = v - return -} - -func (p *ListAutoScaleVmProfilesParams) SetPagesize(v int) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["pagesize"] = v - return -} - -func (p *ListAutoScaleVmProfilesParams) SetProjectid(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["projectid"] = v - return -} - -func (p *ListAutoScaleVmProfilesParams) SetServiceofferingid(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["serviceofferingid"] = v - return -} - -func (p *ListAutoScaleVmProfilesParams) SetTemplateid(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["templateid"] = v - return -} - -func (p *ListAutoScaleVmProfilesParams) SetZoneid(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["zoneid"] = v - return -} - -// You should always use this function to get a new ListAutoScaleVmProfilesParams instance, -// as then you are sure you have configured all required params -func (s *AutoScaleService) NewListAutoScaleVmProfilesParams() *ListAutoScaleVmProfilesParams { - p := &ListAutoScaleVmProfilesParams{} - p.p = make(map[string]interface{}) - return p -} - -// This is a courtesy helper function, which in some cases may not work as expected! -func (s *AutoScaleService) GetAutoScaleVmProfileByID(id string, opts ...OptionFunc) (*AutoScaleVmProfile, int, error) { - p := &ListAutoScaleVmProfilesParams{} - p.p = make(map[string]interface{}) - - p.p["id"] = id - - for _, fn := range opts { - if err := fn(s.cs, p); err != nil { - return nil, -1, err - } - } - - l, err := s.ListAutoScaleVmProfiles(p) - if err != nil { - if strings.Contains(err.Error(), fmt.Sprintf( - "Invalid parameter id value=%s due to incorrect long value format, "+ - "or entity does not exist", id)) { - return nil, 0, fmt.Errorf("No match found for %s: %+v", id, l) - } - return nil, -1, err - } - - if l.Count == 0 { - return nil, l.Count, fmt.Errorf("No match found for %s: %+v", id, l) - } - - if l.Count == 1 { - return l.AutoScaleVmProfiles[0], l.Count, nil - } - return nil, l.Count, fmt.Errorf("There is more then one result for AutoScaleVmProfile UUID: %s!", id) -} - -// Lists autoscale vm profiles. -func (s *AutoScaleService) ListAutoScaleVmProfiles(p *ListAutoScaleVmProfilesParams) (*ListAutoScaleVmProfilesResponse, error) { - resp, err := s.cs.newRequest("listAutoScaleVmProfiles", p.toURLValues()) - if err != nil { - return nil, err - } - - var r ListAutoScaleVmProfilesResponse - if err := json.Unmarshal(resp, &r); err != nil { - return nil, err - } - return &r, nil -} - -type ListAutoScaleVmProfilesResponse struct { - Count int `json:"count"` - AutoScaleVmProfiles []*AutoScaleVmProfile `json:"autoscalevmprofile"` -} - -type AutoScaleVmProfile struct { - Account string `json:"account,omitempty"` - Autoscaleuserid string `json:"autoscaleuserid,omitempty"` - Destroyvmgraceperiod int `json:"destroyvmgraceperiod,omitempty"` - Domain string `json:"domain,omitempty"` - Domainid string `json:"domainid,omitempty"` - Fordisplay bool `json:"fordisplay,omitempty"` - Id string `json:"id,omitempty"` - Otherdeployparams string `json:"otherdeployparams,omitempty"` - Project string `json:"project,omitempty"` - Projectid string `json:"projectid,omitempty"` - Serviceofferingid string `json:"serviceofferingid,omitempty"` - Templateid string `json:"templateid,omitempty"` - Zoneid string `json:"zoneid,omitempty"` + Account string `json:"account"` + Action string `json:"action"` + Conditions []string `json:"conditions"` + Domain string `json:"domain"` + Domainid string `json:"domainid"` + Duration int `json:"duration"` + Id string `json:"id"` + Project string `json:"project"` + Projectid string `json:"projectid"` + Quiettime int `json:"quiettime"` } type ListAutoScaleVmGroupsParams struct { @@ -2085,7 +1624,7 @@ func (s *AutoScaleService) GetAutoScaleVmGroupByID(id string, opts ...OptionFunc p.p["id"] = id - for _, fn := range opts { + for _, fn := range append(s.cs.options, opts...) { if err := fn(s.cs, p); err != nil { return nil, -1, err } @@ -2122,6 +1661,7 @@ func (s *AutoScaleService) ListAutoScaleVmGroups(p *ListAutoScaleVmGroupsParams) if err := json.Unmarshal(resp, &r); err != nil { return nil, err } + return &r, nil } @@ -2131,39 +1671,107 @@ type ListAutoScaleVmGroupsResponse struct { } type AutoScaleVmGroup struct { - Account string `json:"account,omitempty"` - Domain string `json:"domain,omitempty"` - Domainid string `json:"domainid,omitempty"` - Fordisplay bool `json:"fordisplay,omitempty"` - Id string `json:"id,omitempty"` - Interval int `json:"interval,omitempty"` - Lbruleid string `json:"lbruleid,omitempty"` - Maxmembers int `json:"maxmembers,omitempty"` - Minmembers int `json:"minmembers,omitempty"` - Project string `json:"project,omitempty"` - Projectid string `json:"projectid,omitempty"` - Scaledownpolicies []string `json:"scaledownpolicies,omitempty"` - Scaleuppolicies []string `json:"scaleuppolicies,omitempty"` - State string `json:"state,omitempty"` - Vmprofileid string `json:"vmprofileid,omitempty"` + Account string `json:"account"` + Domain string `json:"domain"` + Domainid string `json:"domainid"` + Fordisplay bool `json:"fordisplay"` + Id string `json:"id"` + Interval int `json:"interval"` + Lbruleid string `json:"lbruleid"` + Maxmembers int `json:"maxmembers"` + Minmembers int `json:"minmembers"` + Project string `json:"project"` + Projectid string `json:"projectid"` + Scaledownpolicies []string `json:"scaledownpolicies"` + Scaleuppolicies []string `json:"scaleuppolicies"` + State string `json:"state"` + Vmprofileid string `json:"vmprofileid"` } -type EnableAutoScaleVmGroupParams struct { +type ListAutoScaleVmProfilesParams struct { p map[string]interface{} } -func (p *EnableAutoScaleVmGroupParams) toURLValues() url.Values { +func (p *ListAutoScaleVmProfilesParams) toURLValues() url.Values { u := url.Values{} if p.p == nil { return u } + if v, found := p.p["account"]; found { + u.Set("account", v.(string)) + } + if v, found := p.p["domainid"]; found { + u.Set("domainid", v.(string)) + } + if v, found := p.p["fordisplay"]; found { + vv := strconv.FormatBool(v.(bool)) + u.Set("fordisplay", vv) + } if v, found := p.p["id"]; found { u.Set("id", v.(string)) } + if v, found := p.p["isrecursive"]; found { + vv := strconv.FormatBool(v.(bool)) + u.Set("isrecursive", vv) + } + if v, found := p.p["keyword"]; found { + u.Set("keyword", v.(string)) + } + if v, found := p.p["listall"]; found { + vv := strconv.FormatBool(v.(bool)) + u.Set("listall", vv) + } + if v, found := p.p["otherdeployparams"]; found { + u.Set("otherdeployparams", v.(string)) + } + if v, found := p.p["page"]; found { + vv := strconv.Itoa(v.(int)) + u.Set("page", vv) + } + if v, found := p.p["pagesize"]; found { + vv := strconv.Itoa(v.(int)) + u.Set("pagesize", vv) + } + if v, found := p.p["projectid"]; found { + u.Set("projectid", v.(string)) + } + if v, found := p.p["serviceofferingid"]; found { + u.Set("serviceofferingid", v.(string)) + } + if v, found := p.p["templateid"]; found { + u.Set("templateid", v.(string)) + } + if v, found := p.p["zoneid"]; found { + u.Set("zoneid", v.(string)) + } return u } -func (p *EnableAutoScaleVmGroupParams) SetId(v string) { +func (p *ListAutoScaleVmProfilesParams) SetAccount(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["account"] = v + return +} + +func (p *ListAutoScaleVmProfilesParams) SetDomainid(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["domainid"] = v + return +} + +func (p *ListAutoScaleVmProfilesParams) SetFordisplay(v bool) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["fordisplay"] = v + return +} + +func (p *ListAutoScaleVmProfilesParams) SetId(v string) { if p.p == nil { p.p = make(map[string]interface{}) } @@ -2171,84 +1779,234 @@ func (p *EnableAutoScaleVmGroupParams) SetId(v string) { return } -// You should always use this function to get a new EnableAutoScaleVmGroupParams instance, +func (p *ListAutoScaleVmProfilesParams) SetIsrecursive(v bool) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["isrecursive"] = v + return +} + +func (p *ListAutoScaleVmProfilesParams) SetKeyword(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["keyword"] = v + return +} + +func (p *ListAutoScaleVmProfilesParams) SetListall(v bool) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["listall"] = v + return +} + +func (p *ListAutoScaleVmProfilesParams) SetOtherdeployparams(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["otherdeployparams"] = v + return +} + +func (p *ListAutoScaleVmProfilesParams) SetPage(v int) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["page"] = v + return +} + +func (p *ListAutoScaleVmProfilesParams) SetPagesize(v int) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["pagesize"] = v + return +} + +func (p *ListAutoScaleVmProfilesParams) SetProjectid(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["projectid"] = v + return +} + +func (p *ListAutoScaleVmProfilesParams) SetServiceofferingid(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["serviceofferingid"] = v + return +} + +func (p *ListAutoScaleVmProfilesParams) SetTemplateid(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["templateid"] = v + return +} + +func (p *ListAutoScaleVmProfilesParams) SetZoneid(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["zoneid"] = v + return +} + +// You should always use this function to get a new ListAutoScaleVmProfilesParams instance, // as then you are sure you have configured all required params -func (s *AutoScaleService) NewEnableAutoScaleVmGroupParams(id string) *EnableAutoScaleVmGroupParams { - p := &EnableAutoScaleVmGroupParams{} +func (s *AutoScaleService) NewListAutoScaleVmProfilesParams() *ListAutoScaleVmProfilesParams { + p := &ListAutoScaleVmProfilesParams{} p.p = make(map[string]interface{}) - p.p["id"] = id return p } -// Enables an AutoScale Vm Group -func (s *AutoScaleService) EnableAutoScaleVmGroup(p *EnableAutoScaleVmGroupParams) (*EnableAutoScaleVmGroupResponse, error) { - resp, err := s.cs.newRequest("enableAutoScaleVmGroup", p.toURLValues()) +// This is a courtesy helper function, which in some cases may not work as expected! +func (s *AutoScaleService) GetAutoScaleVmProfileByID(id string, opts ...OptionFunc) (*AutoScaleVmProfile, int, error) { + p := &ListAutoScaleVmProfilesParams{} + p.p = make(map[string]interface{}) + + p.p["id"] = id + + for _, fn := range append(s.cs.options, opts...) { + if err := fn(s.cs, p); err != nil { + return nil, -1, err + } + } + + l, err := s.ListAutoScaleVmProfiles(p) + if err != nil { + if strings.Contains(err.Error(), fmt.Sprintf( + "Invalid parameter id value=%s due to incorrect long value format, "+ + "or entity does not exist", id)) { + return nil, 0, fmt.Errorf("No match found for %s: %+v", id, l) + } + return nil, -1, err + } + + if l.Count == 0 { + return nil, l.Count, fmt.Errorf("No match found for %s: %+v", id, l) + } + + if l.Count == 1 { + return l.AutoScaleVmProfiles[0], l.Count, nil + } + return nil, l.Count, fmt.Errorf("There is more then one result for AutoScaleVmProfile UUID: %s!", id) +} + +// Lists autoscale vm profiles. +func (s *AutoScaleService) ListAutoScaleVmProfiles(p *ListAutoScaleVmProfilesParams) (*ListAutoScaleVmProfilesResponse, error) { + resp, err := s.cs.newRequest("listAutoScaleVmProfiles", p.toURLValues()) if err != nil { return nil, err } - var r EnableAutoScaleVmGroupResponse + var r ListAutoScaleVmProfilesResponse if err := json.Unmarshal(resp, &r); err != nil { return nil, err } - // If we have a async client, we need to wait for the async result - if s.cs.async { - b, err := s.cs.GetAsyncJobResult(r.JobID, s.cs.timeout) - if err != nil { - if err == AsyncTimeoutErr { - return &r, err - } - return nil, err - } - - b, err = getRawValue(b) - if err != nil { - return nil, err - } - - if err := json.Unmarshal(b, &r); err != nil { - return nil, err - } - } return &r, nil } -type EnableAutoScaleVmGroupResponse struct { - JobID string `json:"jobid,omitempty"` - Account string `json:"account,omitempty"` - Domain string `json:"domain,omitempty"` - Domainid string `json:"domainid,omitempty"` - Fordisplay bool `json:"fordisplay,omitempty"` - Id string `json:"id,omitempty"` - Interval int `json:"interval,omitempty"` - Lbruleid string `json:"lbruleid,omitempty"` - Maxmembers int `json:"maxmembers,omitempty"` - Minmembers int `json:"minmembers,omitempty"` - Project string `json:"project,omitempty"` - Projectid string `json:"projectid,omitempty"` - Scaledownpolicies []string `json:"scaledownpolicies,omitempty"` - Scaleuppolicies []string `json:"scaleuppolicies,omitempty"` - State string `json:"state,omitempty"` - Vmprofileid string `json:"vmprofileid,omitempty"` +type ListAutoScaleVmProfilesResponse struct { + Count int `json:"count"` + AutoScaleVmProfiles []*AutoScaleVmProfile `json:"autoscalevmprofile"` } -type DisableAutoScaleVmGroupParams struct { +type AutoScaleVmProfile struct { + Account string `json:"account"` + Autoscaleuserid string `json:"autoscaleuserid"` + Destroyvmgraceperiod int `json:"destroyvmgraceperiod"` + Domain string `json:"domain"` + Domainid string `json:"domainid"` + Fordisplay bool `json:"fordisplay"` + Id string `json:"id"` + Otherdeployparams string `json:"otherdeployparams"` + Project string `json:"project"` + Projectid string `json:"projectid"` + Serviceofferingid string `json:"serviceofferingid"` + Templateid string `json:"templateid"` + Zoneid string `json:"zoneid"` +} + +type ListConditionsParams struct { p map[string]interface{} } -func (p *DisableAutoScaleVmGroupParams) toURLValues() url.Values { +func (p *ListConditionsParams) toURLValues() url.Values { u := url.Values{} if p.p == nil { return u } + if v, found := p.p["account"]; found { + u.Set("account", v.(string)) + } + if v, found := p.p["counterid"]; found { + u.Set("counterid", v.(string)) + } + if v, found := p.p["domainid"]; found { + u.Set("domainid", v.(string)) + } if v, found := p.p["id"]; found { u.Set("id", v.(string)) } + if v, found := p.p["isrecursive"]; found { + vv := strconv.FormatBool(v.(bool)) + u.Set("isrecursive", vv) + } + if v, found := p.p["keyword"]; found { + u.Set("keyword", v.(string)) + } + if v, found := p.p["listall"]; found { + vv := strconv.FormatBool(v.(bool)) + u.Set("listall", vv) + } + if v, found := p.p["page"]; found { + vv := strconv.Itoa(v.(int)) + u.Set("page", vv) + } + if v, found := p.p["pagesize"]; found { + vv := strconv.Itoa(v.(int)) + u.Set("pagesize", vv) + } + if v, found := p.p["policyid"]; found { + u.Set("policyid", v.(string)) + } return u } -func (p *DisableAutoScaleVmGroupParams) SetId(v string) { +func (p *ListConditionsParams) SetAccount(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["account"] = v + return +} + +func (p *ListConditionsParams) SetCounterid(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["counterid"] = v + return +} + +func (p *ListConditionsParams) SetDomainid(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["domainid"] = v + return +} + +func (p *ListConditionsParams) SetId(v string) { if p.p == nil { p.p = make(map[string]interface{}) } @@ -2256,66 +2014,325 @@ func (p *DisableAutoScaleVmGroupParams) SetId(v string) { return } -// You should always use this function to get a new DisableAutoScaleVmGroupParams instance, +func (p *ListConditionsParams) SetIsrecursive(v bool) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["isrecursive"] = v + return +} + +func (p *ListConditionsParams) SetKeyword(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["keyword"] = v + return +} + +func (p *ListConditionsParams) SetListall(v bool) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["listall"] = v + return +} + +func (p *ListConditionsParams) SetPage(v int) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["page"] = v + return +} + +func (p *ListConditionsParams) SetPagesize(v int) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["pagesize"] = v + return +} + +func (p *ListConditionsParams) SetPolicyid(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["policyid"] = v + return +} + +// You should always use this function to get a new ListConditionsParams instance, // as then you are sure you have configured all required params -func (s *AutoScaleService) NewDisableAutoScaleVmGroupParams(id string) *DisableAutoScaleVmGroupParams { - p := &DisableAutoScaleVmGroupParams{} +func (s *AutoScaleService) NewListConditionsParams() *ListConditionsParams { + p := &ListConditionsParams{} p.p = make(map[string]interface{}) - p.p["id"] = id return p } -// Disables an AutoScale Vm Group -func (s *AutoScaleService) DisableAutoScaleVmGroup(p *DisableAutoScaleVmGroupParams) (*DisableAutoScaleVmGroupResponse, error) { - resp, err := s.cs.newRequest("disableAutoScaleVmGroup", p.toURLValues()) +// This is a courtesy helper function, which in some cases may not work as expected! +func (s *AutoScaleService) GetConditionByID(id string, opts ...OptionFunc) (*Condition, int, error) { + p := &ListConditionsParams{} + p.p = make(map[string]interface{}) + + p.p["id"] = id + + for _, fn := range append(s.cs.options, opts...) { + if err := fn(s.cs, p); err != nil { + return nil, -1, err + } + } + + l, err := s.ListConditions(p) + if err != nil { + if strings.Contains(err.Error(), fmt.Sprintf( + "Invalid parameter id value=%s due to incorrect long value format, "+ + "or entity does not exist", id)) { + return nil, 0, fmt.Errorf("No match found for %s: %+v", id, l) + } + return nil, -1, err + } + + if l.Count == 0 { + return nil, l.Count, fmt.Errorf("No match found for %s: %+v", id, l) + } + + if l.Count == 1 { + return l.Conditions[0], l.Count, nil + } + return nil, l.Count, fmt.Errorf("There is more then one result for Condition UUID: %s!", id) +} + +// List Conditions for the specific user +func (s *AutoScaleService) ListConditions(p *ListConditionsParams) (*ListConditionsResponse, error) { + resp, err := s.cs.newRequest("listConditions", p.toURLValues()) if err != nil { return nil, err } - var r DisableAutoScaleVmGroupResponse + var r ListConditionsResponse if err := json.Unmarshal(resp, &r); err != nil { return nil, err } - // If we have a async client, we need to wait for the async result - if s.cs.async { - b, err := s.cs.GetAsyncJobResult(r.JobID, s.cs.timeout) - if err != nil { - if err == AsyncTimeoutErr { - return &r, err - } - return nil, err - } - - b, err = getRawValue(b) - if err != nil { - return nil, err - } - - if err := json.Unmarshal(b, &r); err != nil { - return nil, err - } - } return &r, nil } -type DisableAutoScaleVmGroupResponse struct { - JobID string `json:"jobid,omitempty"` - Account string `json:"account,omitempty"` - Domain string `json:"domain,omitempty"` - Domainid string `json:"domainid,omitempty"` - Fordisplay bool `json:"fordisplay,omitempty"` - Id string `json:"id,omitempty"` - Interval int `json:"interval,omitempty"` - Lbruleid string `json:"lbruleid,omitempty"` - Maxmembers int `json:"maxmembers,omitempty"` - Minmembers int `json:"minmembers,omitempty"` - Project string `json:"project,omitempty"` - Projectid string `json:"projectid,omitempty"` - Scaledownpolicies []string `json:"scaledownpolicies,omitempty"` - Scaleuppolicies []string `json:"scaleuppolicies,omitempty"` - State string `json:"state,omitempty"` - Vmprofileid string `json:"vmprofileid,omitempty"` +type ListConditionsResponse struct { + Count int `json:"count"` + Conditions []*Condition `json:"condition"` +} + +type Condition struct { + Account string `json:"account"` + Counter []string `json:"counter"` + Domain string `json:"domain"` + Domainid string `json:"domainid"` + Id string `json:"id"` + Project string `json:"project"` + Projectid string `json:"projectid"` + Relationaloperator string `json:"relationaloperator"` + Threshold int64 `json:"threshold"` + Zoneid string `json:"zoneid"` +} + +type ListCountersParams struct { + p map[string]interface{} +} + +func (p *ListCountersParams) toURLValues() url.Values { + u := url.Values{} + if p.p == nil { + return u + } + if v, found := p.p["id"]; found { + u.Set("id", v.(string)) + } + if v, found := p.p["keyword"]; found { + u.Set("keyword", v.(string)) + } + if v, found := p.p["name"]; found { + u.Set("name", v.(string)) + } + if v, found := p.p["page"]; found { + vv := strconv.Itoa(v.(int)) + u.Set("page", vv) + } + if v, found := p.p["pagesize"]; found { + vv := strconv.Itoa(v.(int)) + u.Set("pagesize", vv) + } + if v, found := p.p["source"]; found { + u.Set("source", v.(string)) + } + return u +} + +func (p *ListCountersParams) SetId(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["id"] = v + return +} + +func (p *ListCountersParams) SetKeyword(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["keyword"] = v + return +} + +func (p *ListCountersParams) SetName(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["name"] = v + return +} + +func (p *ListCountersParams) SetPage(v int) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["page"] = v + return +} + +func (p *ListCountersParams) SetPagesize(v int) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["pagesize"] = v + return +} + +func (p *ListCountersParams) SetSource(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["source"] = v + return +} + +// You should always use this function to get a new ListCountersParams instance, +// as then you are sure you have configured all required params +func (s *AutoScaleService) NewListCountersParams() *ListCountersParams { + p := &ListCountersParams{} + p.p = make(map[string]interface{}) + return p +} + +// This is a courtesy helper function, which in some cases may not work as expected! +func (s *AutoScaleService) GetCounterID(name string, opts ...OptionFunc) (string, int, error) { + p := &ListCountersParams{} + p.p = make(map[string]interface{}) + + p.p["name"] = name + + for _, fn := range append(s.cs.options, opts...) { + if err := fn(s.cs, p); err != nil { + return "", -1, err + } + } + + l, err := s.ListCounters(p) + if err != nil { + return "", -1, err + } + + if l.Count == 0 { + return "", l.Count, fmt.Errorf("No match found for %s: %+v", name, l) + } + + if l.Count == 1 { + return l.Counters[0].Id, l.Count, nil + } + + if l.Count > 1 { + for _, v := range l.Counters { + if v.Name == name { + return v.Id, l.Count, nil + } + } + } + return "", l.Count, fmt.Errorf("Could not find an exact match for %s: %+v", name, l) +} + +// This is a courtesy helper function, which in some cases may not work as expected! +func (s *AutoScaleService) GetCounterByName(name string, opts ...OptionFunc) (*Counter, int, error) { + id, count, err := s.GetCounterID(name, opts...) + if err != nil { + return nil, count, err + } + + r, count, err := s.GetCounterByID(id, opts...) + if err != nil { + return nil, count, err + } + return r, count, nil +} + +// This is a courtesy helper function, which in some cases may not work as expected! +func (s *AutoScaleService) GetCounterByID(id string, opts ...OptionFunc) (*Counter, int, error) { + p := &ListCountersParams{} + p.p = make(map[string]interface{}) + + p.p["id"] = id + + for _, fn := range append(s.cs.options, opts...) { + if err := fn(s.cs, p); err != nil { + return nil, -1, err + } + } + + l, err := s.ListCounters(p) + if err != nil { + if strings.Contains(err.Error(), fmt.Sprintf( + "Invalid parameter id value=%s due to incorrect long value format, "+ + "or entity does not exist", id)) { + return nil, 0, fmt.Errorf("No match found for %s: %+v", id, l) + } + return nil, -1, err + } + + if l.Count == 0 { + return nil, l.Count, fmt.Errorf("No match found for %s: %+v", id, l) + } + + if l.Count == 1 { + return l.Counters[0], l.Count, nil + } + return nil, l.Count, fmt.Errorf("There is more then one result for Counter UUID: %s!", id) +} + +// List the counters +func (s *AutoScaleService) ListCounters(p *ListCountersParams) (*ListCountersResponse, error) { + resp, err := s.cs.newRequest("listCounters", p.toURLValues()) + if err != nil { + return nil, err + } + + var r ListCountersResponse + if err := json.Unmarshal(resp, &r); err != nil { + return nil, err + } + + return &r, nil +} + +type ListCountersResponse struct { + Count int `json:"count"` + Counters []*Counter `json:"counter"` +} + +type Counter struct { + Id string `json:"id"` + Name string `json:"name"` + Source string `json:"source"` + Value string `json:"value"` + Zoneid string `json:"zoneid"` } type UpdateAutoScalePolicyParams struct { @@ -2417,177 +2434,22 @@ func (s *AutoScaleService) UpdateAutoScalePolicy(p *UpdateAutoScalePolicyParams) return nil, err } } + return &r, nil } type UpdateAutoScalePolicyResponse struct { - JobID string `json:"jobid,omitempty"` - Account string `json:"account,omitempty"` - Action string `json:"action,omitempty"` - Conditions []string `json:"conditions,omitempty"` - Domain string `json:"domain,omitempty"` - Domainid string `json:"domainid,omitempty"` - Duration int `json:"duration,omitempty"` - Id string `json:"id,omitempty"` - Project string `json:"project,omitempty"` - Projectid string `json:"projectid,omitempty"` - Quiettime int `json:"quiettime,omitempty"` -} - -type UpdateAutoScaleVmProfileParams struct { - p map[string]interface{} -} - -func (p *UpdateAutoScaleVmProfileParams) toURLValues() url.Values { - u := url.Values{} - if p.p == nil { - return u - } - if v, found := p.p["autoscaleuserid"]; found { - u.Set("autoscaleuserid", v.(string)) - } - if v, found := p.p["counterparam"]; found { - i := 0 - for k, vv := range v.(map[string]string) { - u.Set(fmt.Sprintf("counterparam[%d].key", i), k) - u.Set(fmt.Sprintf("counterparam[%d].value", i), vv) - i++ - } - } - if v, found := p.p["customid"]; found { - u.Set("customid", v.(string)) - } - if v, found := p.p["destroyvmgraceperiod"]; found { - vv := strconv.Itoa(v.(int)) - u.Set("destroyvmgraceperiod", vv) - } - if v, found := p.p["fordisplay"]; found { - vv := strconv.FormatBool(v.(bool)) - u.Set("fordisplay", vv) - } - if v, found := p.p["id"]; found { - u.Set("id", v.(string)) - } - if v, found := p.p["templateid"]; found { - u.Set("templateid", v.(string)) - } - return u -} - -func (p *UpdateAutoScaleVmProfileParams) SetAutoscaleuserid(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["autoscaleuserid"] = v - return -} - -func (p *UpdateAutoScaleVmProfileParams) SetCounterparam(v map[string]string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["counterparam"] = v - return -} - -func (p *UpdateAutoScaleVmProfileParams) SetCustomid(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["customid"] = v - return -} - -func (p *UpdateAutoScaleVmProfileParams) SetDestroyvmgraceperiod(v int) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["destroyvmgraceperiod"] = v - return -} - -func (p *UpdateAutoScaleVmProfileParams) SetFordisplay(v bool) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["fordisplay"] = v - return -} - -func (p *UpdateAutoScaleVmProfileParams) SetId(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["id"] = v - return -} - -func (p *UpdateAutoScaleVmProfileParams) SetTemplateid(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["templateid"] = v - return -} - -// You should always use this function to get a new UpdateAutoScaleVmProfileParams instance, -// as then you are sure you have configured all required params -func (s *AutoScaleService) NewUpdateAutoScaleVmProfileParams(id string) *UpdateAutoScaleVmProfileParams { - p := &UpdateAutoScaleVmProfileParams{} - p.p = make(map[string]interface{}) - p.p["id"] = id - return p -} - -// Updates an existing autoscale vm profile. -func (s *AutoScaleService) UpdateAutoScaleVmProfile(p *UpdateAutoScaleVmProfileParams) (*UpdateAutoScaleVmProfileResponse, error) { - resp, err := s.cs.newRequest("updateAutoScaleVmProfile", p.toURLValues()) - if err != nil { - return nil, err - } - - var r UpdateAutoScaleVmProfileResponse - if err := json.Unmarshal(resp, &r); err != nil { - return nil, err - } - - // If we have a async client, we need to wait for the async result - if s.cs.async { - b, err := s.cs.GetAsyncJobResult(r.JobID, s.cs.timeout) - if err != nil { - if err == AsyncTimeoutErr { - return &r, err - } - return nil, err - } - - b, err = getRawValue(b) - if err != nil { - return nil, err - } - - if err := json.Unmarshal(b, &r); err != nil { - return nil, err - } - } - return &r, nil -} - -type UpdateAutoScaleVmProfileResponse struct { - JobID string `json:"jobid,omitempty"` - Account string `json:"account,omitempty"` - Autoscaleuserid string `json:"autoscaleuserid,omitempty"` - Destroyvmgraceperiod int `json:"destroyvmgraceperiod,omitempty"` - Domain string `json:"domain,omitempty"` - Domainid string `json:"domainid,omitempty"` - Fordisplay bool `json:"fordisplay,omitempty"` - Id string `json:"id,omitempty"` - Otherdeployparams string `json:"otherdeployparams,omitempty"` - Project string `json:"project,omitempty"` - Projectid string `json:"projectid,omitempty"` - Serviceofferingid string `json:"serviceofferingid,omitempty"` - Templateid string `json:"templateid,omitempty"` - Zoneid string `json:"zoneid,omitempty"` + JobID string `json:"jobid"` + Account string `json:"account"` + Action string `json:"action"` + Conditions []string `json:"conditions"` + Domain string `json:"domain"` + Domainid string `json:"domainid"` + Duration int `json:"duration"` + Id string `json:"id"` + Project string `json:"project"` + Projectid string `json:"projectid"` + Quiettime int `json:"quiettime"` } type UpdateAutoScaleVmGroupParams struct { @@ -2736,24 +2598,182 @@ func (s *AutoScaleService) UpdateAutoScaleVmGroup(p *UpdateAutoScaleVmGroupParam return nil, err } } + return &r, nil } type UpdateAutoScaleVmGroupResponse struct { - JobID string `json:"jobid,omitempty"` - Account string `json:"account,omitempty"` - Domain string `json:"domain,omitempty"` - Domainid string `json:"domainid,omitempty"` - Fordisplay bool `json:"fordisplay,omitempty"` - Id string `json:"id,omitempty"` - Interval int `json:"interval,omitempty"` - Lbruleid string `json:"lbruleid,omitempty"` - Maxmembers int `json:"maxmembers,omitempty"` - Minmembers int `json:"minmembers,omitempty"` - Project string `json:"project,omitempty"` - Projectid string `json:"projectid,omitempty"` - Scaledownpolicies []string `json:"scaledownpolicies,omitempty"` - Scaleuppolicies []string `json:"scaleuppolicies,omitempty"` - State string `json:"state,omitempty"` - Vmprofileid string `json:"vmprofileid,omitempty"` + JobID string `json:"jobid"` + Account string `json:"account"` + Domain string `json:"domain"` + Domainid string `json:"domainid"` + Fordisplay bool `json:"fordisplay"` + Id string `json:"id"` + Interval int `json:"interval"` + Lbruleid string `json:"lbruleid"` + Maxmembers int `json:"maxmembers"` + Minmembers int `json:"minmembers"` + Project string `json:"project"` + Projectid string `json:"projectid"` + Scaledownpolicies []string `json:"scaledownpolicies"` + Scaleuppolicies []string `json:"scaleuppolicies"` + State string `json:"state"` + Vmprofileid string `json:"vmprofileid"` +} + +type UpdateAutoScaleVmProfileParams struct { + p map[string]interface{} +} + +func (p *UpdateAutoScaleVmProfileParams) toURLValues() url.Values { + u := url.Values{} + if p.p == nil { + return u + } + if v, found := p.p["autoscaleuserid"]; found { + u.Set("autoscaleuserid", v.(string)) + } + if v, found := p.p["counterparam"]; found { + i := 0 + for k, vv := range v.(map[string]string) { + u.Set(fmt.Sprintf("counterparam[%d].key", i), k) + u.Set(fmt.Sprintf("counterparam[%d].value", i), vv) + i++ + } + } + if v, found := p.p["customid"]; found { + u.Set("customid", v.(string)) + } + if v, found := p.p["destroyvmgraceperiod"]; found { + vv := strconv.Itoa(v.(int)) + u.Set("destroyvmgraceperiod", vv) + } + if v, found := p.p["fordisplay"]; found { + vv := strconv.FormatBool(v.(bool)) + u.Set("fordisplay", vv) + } + if v, found := p.p["id"]; found { + u.Set("id", v.(string)) + } + if v, found := p.p["templateid"]; found { + u.Set("templateid", v.(string)) + } + return u +} + +func (p *UpdateAutoScaleVmProfileParams) SetAutoscaleuserid(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["autoscaleuserid"] = v + return +} + +func (p *UpdateAutoScaleVmProfileParams) SetCounterparam(v map[string]string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["counterparam"] = v + return +} + +func (p *UpdateAutoScaleVmProfileParams) SetCustomid(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["customid"] = v + return +} + +func (p *UpdateAutoScaleVmProfileParams) SetDestroyvmgraceperiod(v int) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["destroyvmgraceperiod"] = v + return +} + +func (p *UpdateAutoScaleVmProfileParams) SetFordisplay(v bool) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["fordisplay"] = v + return +} + +func (p *UpdateAutoScaleVmProfileParams) SetId(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["id"] = v + return +} + +func (p *UpdateAutoScaleVmProfileParams) SetTemplateid(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["templateid"] = v + return +} + +// You should always use this function to get a new UpdateAutoScaleVmProfileParams instance, +// as then you are sure you have configured all required params +func (s *AutoScaleService) NewUpdateAutoScaleVmProfileParams(id string) *UpdateAutoScaleVmProfileParams { + p := &UpdateAutoScaleVmProfileParams{} + p.p = make(map[string]interface{}) + p.p["id"] = id + return p +} + +// Updates an existing autoscale vm profile. +func (s *AutoScaleService) UpdateAutoScaleVmProfile(p *UpdateAutoScaleVmProfileParams) (*UpdateAutoScaleVmProfileResponse, error) { + resp, err := s.cs.newRequest("updateAutoScaleVmProfile", p.toURLValues()) + if err != nil { + return nil, err + } + + var r UpdateAutoScaleVmProfileResponse + if err := json.Unmarshal(resp, &r); err != nil { + return nil, err + } + + // If we have a async client, we need to wait for the async result + if s.cs.async { + b, err := s.cs.GetAsyncJobResult(r.JobID, s.cs.timeout) + if err != nil { + if err == AsyncTimeoutErr { + return &r, err + } + return nil, err + } + + b, err = getRawValue(b) + if err != nil { + return nil, err + } + + if err := json.Unmarshal(b, &r); err != nil { + return nil, err + } + } + + return &r, nil +} + +type UpdateAutoScaleVmProfileResponse struct { + JobID string `json:"jobid"` + Account string `json:"account"` + Autoscaleuserid string `json:"autoscaleuserid"` + Destroyvmgraceperiod int `json:"destroyvmgraceperiod"` + Domain string `json:"domain"` + Domainid string `json:"domainid"` + Fordisplay bool `json:"fordisplay"` + Id string `json:"id"` + Otherdeployparams string `json:"otherdeployparams"` + Project string `json:"project"` + Projectid string `json:"projectid"` + Serviceofferingid string `json:"serviceofferingid"` + Templateid string `json:"templateid"` + Zoneid string `json:"zoneid"` } diff --git a/vendor/github.com/xanzy/go-cloudstack/cloudstack/BaremetalService.go b/vendor/github.com/xanzy/go-cloudstack/cloudstack/BaremetalService.go index c1b7eaaba..2b8b9f20d 100644 --- a/vendor/github.com/xanzy/go-cloudstack/cloudstack/BaremetalService.go +++ b/vendor/github.com/xanzy/go-cloudstack/cloudstack/BaremetalService.go @@ -1,5 +1,5 @@ // -// Copyright 2016, Sander van Harmelen +// Copyright 2018, Sander van Harmelen // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -22,6 +22,130 @@ import ( "strconv" ) +type AddBaremetalDhcpParams struct { + p map[string]interface{} +} + +func (p *AddBaremetalDhcpParams) toURLValues() url.Values { + u := url.Values{} + if p.p == nil { + return u + } + if v, found := p.p["dhcpservertype"]; found { + u.Set("dhcpservertype", v.(string)) + } + if v, found := p.p["password"]; found { + u.Set("password", v.(string)) + } + if v, found := p.p["physicalnetworkid"]; found { + u.Set("physicalnetworkid", v.(string)) + } + if v, found := p.p["url"]; found { + u.Set("url", v.(string)) + } + if v, found := p.p["username"]; found { + u.Set("username", v.(string)) + } + return u +} + +func (p *AddBaremetalDhcpParams) SetDhcpservertype(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["dhcpservertype"] = v + return +} + +func (p *AddBaremetalDhcpParams) SetPassword(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["password"] = v + return +} + +func (p *AddBaremetalDhcpParams) SetPhysicalnetworkid(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["physicalnetworkid"] = v + return +} + +func (p *AddBaremetalDhcpParams) SetUrl(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["url"] = v + return +} + +func (p *AddBaremetalDhcpParams) SetUsername(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["username"] = v + return +} + +// You should always use this function to get a new AddBaremetalDhcpParams instance, +// as then you are sure you have configured all required params +func (s *BaremetalService) NewAddBaremetalDhcpParams(dhcpservertype string, password string, physicalnetworkid string, url string, username string) *AddBaremetalDhcpParams { + p := &AddBaremetalDhcpParams{} + p.p = make(map[string]interface{}) + p.p["dhcpservertype"] = dhcpservertype + p.p["password"] = password + p.p["physicalnetworkid"] = physicalnetworkid + p.p["url"] = url + p.p["username"] = username + return p +} + +// adds a baremetal dhcp server +func (s *BaremetalService) AddBaremetalDhcp(p *AddBaremetalDhcpParams) (*AddBaremetalDhcpResponse, error) { + resp, err := s.cs.newRequest("addBaremetalDhcp", p.toURLValues()) + if err != nil { + return nil, err + } + + var r AddBaremetalDhcpResponse + if err := json.Unmarshal(resp, &r); err != nil { + return nil, err + } + + // If we have a async client, we need to wait for the async result + if s.cs.async { + b, err := s.cs.GetAsyncJobResult(r.JobID, s.cs.timeout) + if err != nil { + if err == AsyncTimeoutErr { + return &r, err + } + return nil, err + } + + b, err = getRawValue(b) + if err != nil { + return nil, err + } + + if err := json.Unmarshal(b, &r); err != nil { + return nil, err + } + } + + return &r, nil +} + +type AddBaremetalDhcpResponse struct { + JobID string `json:"jobid"` + Dhcpservertype string `json:"dhcpservertype"` + Id string `json:"id"` + Physicalnetworkid string `json:"physicalnetworkid"` + Provider string `json:"provider"` + Url string `json:"url"` +} + type AddBaremetalPxeKickStartServerParams struct { p map[string]interface{} } @@ -156,12 +280,13 @@ func (s *BaremetalService) AddBaremetalPxeKickStartServer(p *AddBaremetalPxeKick return nil, err } } + return &r, nil } type AddBaremetalPxeKickStartServerResponse struct { - JobID string `json:"jobid,omitempty"` - Tftpdir string `json:"tftpdir,omitempty"` + JobID string `json:"jobid"` + Tftpdir string `json:"tftpdir"` } type AddBaremetalPxePingServerParams struct { @@ -344,104 +469,57 @@ func (s *BaremetalService) AddBaremetalPxePingServer(p *AddBaremetalPxePingServe return nil, err } } + return &r, nil } type AddBaremetalPxePingServerResponse struct { - JobID string `json:"jobid,omitempty"` - Pingdir string `json:"pingdir,omitempty"` - Pingstorageserverip string `json:"pingstorageserverip,omitempty"` - Tftpdir string `json:"tftpdir,omitempty"` + JobID string `json:"jobid"` + Pingdir string `json:"pingdir"` + Pingstorageserverip string `json:"pingstorageserverip"` + Tftpdir string `json:"tftpdir"` } -type AddBaremetalDhcpParams struct { +type AddBaremetalRctParams struct { p map[string]interface{} } -func (p *AddBaremetalDhcpParams) toURLValues() url.Values { +func (p *AddBaremetalRctParams) toURLValues() url.Values { u := url.Values{} if p.p == nil { return u } - if v, found := p.p["dhcpservertype"]; found { - u.Set("dhcpservertype", v.(string)) - } - if v, found := p.p["password"]; found { - u.Set("password", v.(string)) - } - if v, found := p.p["physicalnetworkid"]; found { - u.Set("physicalnetworkid", v.(string)) - } - if v, found := p.p["url"]; found { - u.Set("url", v.(string)) - } - if v, found := p.p["username"]; found { - u.Set("username", v.(string)) + if v, found := p.p["baremetalrcturl"]; found { + u.Set("baremetalrcturl", v.(string)) } return u } -func (p *AddBaremetalDhcpParams) SetDhcpservertype(v string) { +func (p *AddBaremetalRctParams) SetBaremetalrcturl(v string) { if p.p == nil { p.p = make(map[string]interface{}) } - p.p["dhcpservertype"] = v + p.p["baremetalrcturl"] = v return } -func (p *AddBaremetalDhcpParams) SetPassword(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["password"] = v - return -} - -func (p *AddBaremetalDhcpParams) SetPhysicalnetworkid(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["physicalnetworkid"] = v - return -} - -func (p *AddBaremetalDhcpParams) SetUrl(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["url"] = v - return -} - -func (p *AddBaremetalDhcpParams) SetUsername(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["username"] = v - return -} - -// You should always use this function to get a new AddBaremetalDhcpParams instance, +// You should always use this function to get a new AddBaremetalRctParams instance, // as then you are sure you have configured all required params -func (s *BaremetalService) NewAddBaremetalDhcpParams(dhcpservertype string, password string, physicalnetworkid string, url string, username string) *AddBaremetalDhcpParams { - p := &AddBaremetalDhcpParams{} +func (s *BaremetalService) NewAddBaremetalRctParams(baremetalrcturl string) *AddBaremetalRctParams { + p := &AddBaremetalRctParams{} p.p = make(map[string]interface{}) - p.p["dhcpservertype"] = dhcpservertype - p.p["password"] = password - p.p["physicalnetworkid"] = physicalnetworkid - p.p["url"] = url - p.p["username"] = username + p.p["baremetalrcturl"] = baremetalrcturl return p } -// adds a baremetal dhcp server -func (s *BaremetalService) AddBaremetalDhcp(p *AddBaremetalDhcpParams) (*AddBaremetalDhcpResponse, error) { - resp, err := s.cs.newRequest("addBaremetalDhcp", p.toURLValues()) +// adds baremetal rack configuration text +func (s *BaremetalService) AddBaremetalRct(p *AddBaremetalRctParams) (*AddBaremetalRctResponse, error) { + resp, err := s.cs.newRequest("addBaremetalRct", p.toURLValues()) if err != nil { return nil, err } - var r AddBaremetalDhcpResponse + var r AddBaremetalRctResponse if err := json.Unmarshal(resp, &r); err != nil { return nil, err } @@ -465,16 +543,82 @@ func (s *BaremetalService) AddBaremetalDhcp(p *AddBaremetalDhcpParams) (*AddBare return nil, err } } + return &r, nil } -type AddBaremetalDhcpResponse struct { - JobID string `json:"jobid,omitempty"` - Dhcpservertype string `json:"dhcpservertype,omitempty"` - Id string `json:"id,omitempty"` - Physicalnetworkid string `json:"physicalnetworkid,omitempty"` - Provider string `json:"provider,omitempty"` - Url string `json:"url,omitempty"` +type AddBaremetalRctResponse struct { + JobID string `json:"jobid"` + Id string `json:"id"` + Url string `json:"url"` +} + +type DeleteBaremetalRctParams struct { + p map[string]interface{} +} + +func (p *DeleteBaremetalRctParams) toURLValues() url.Values { + u := url.Values{} + if p.p == nil { + return u + } + if v, found := p.p["id"]; found { + u.Set("id", v.(string)) + } + return u +} + +func (p *DeleteBaremetalRctParams) SetId(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["id"] = v + return +} + +// You should always use this function to get a new DeleteBaremetalRctParams instance, +// as then you are sure you have configured all required params +func (s *BaremetalService) NewDeleteBaremetalRctParams(id string) *DeleteBaremetalRctParams { + p := &DeleteBaremetalRctParams{} + p.p = make(map[string]interface{}) + p.p["id"] = id + return p +} + +// deletes baremetal rack configuration text +func (s *BaremetalService) DeleteBaremetalRct(p *DeleteBaremetalRctParams) (*DeleteBaremetalRctResponse, error) { + resp, err := s.cs.newRequest("deleteBaremetalRct", p.toURLValues()) + if err != nil { + return nil, err + } + + var r DeleteBaremetalRctResponse + if err := json.Unmarshal(resp, &r); err != nil { + return nil, err + } + + // If we have a async client, we need to wait for the async result + if s.cs.async { + b, err := s.cs.GetAsyncJobResult(r.JobID, s.cs.timeout) + if err != nil { + if err == AsyncTimeoutErr { + return &r, err + } + return nil, err + } + + if err := json.Unmarshal(b, &r); err != nil { + return nil, err + } + } + + return &r, nil +} + +type DeleteBaremetalRctResponse struct { + JobID string `json:"jobid"` + Displaytext string `json:"displaytext"` + Success bool `json:"success"` } type ListBaremetalDhcpParams struct { @@ -578,6 +722,7 @@ func (s *BaremetalService) ListBaremetalDhcp(p *ListBaremetalDhcpParams) (*ListB if err := json.Unmarshal(resp, &r); err != nil { return nil, err } + return &r, nil } @@ -587,11 +732,11 @@ type ListBaremetalDhcpResponse struct { } type BaremetalDhcp struct { - Dhcpservertype string `json:"dhcpservertype,omitempty"` - Id string `json:"id,omitempty"` - Physicalnetworkid string `json:"physicalnetworkid,omitempty"` - Provider string `json:"provider,omitempty"` - Url string `json:"url,omitempty"` + Dhcpservertype string `json:"dhcpservertype"` + Id string `json:"id"` + Physicalnetworkid string `json:"physicalnetworkid"` + Provider string `json:"provider"` + Url string `json:"url"` } type ListBaremetalPxeServersParams struct { @@ -684,6 +829,7 @@ func (s *BaremetalService) ListBaremetalPxeServers(p *ListBaremetalPxeServersPar if err := json.Unmarshal(resp, &r); err != nil { return nil, err } + return &r, nil } @@ -693,149 +839,10 @@ type ListBaremetalPxeServersResponse struct { } type BaremetalPxeServer struct { - Id string `json:"id,omitempty"` - Physicalnetworkid string `json:"physicalnetworkid,omitempty"` - Provider string `json:"provider,omitempty"` - Url string `json:"url,omitempty"` -} - -type AddBaremetalRctParams struct { - p map[string]interface{} -} - -func (p *AddBaremetalRctParams) toURLValues() url.Values { - u := url.Values{} - if p.p == nil { - return u - } - if v, found := p.p["baremetalrcturl"]; found { - u.Set("baremetalrcturl", v.(string)) - } - return u -} - -func (p *AddBaremetalRctParams) SetBaremetalrcturl(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["baremetalrcturl"] = v - return -} - -// You should always use this function to get a new AddBaremetalRctParams instance, -// as then you are sure you have configured all required params -func (s *BaremetalService) NewAddBaremetalRctParams(baremetalrcturl string) *AddBaremetalRctParams { - p := &AddBaremetalRctParams{} - p.p = make(map[string]interface{}) - p.p["baremetalrcturl"] = baremetalrcturl - return p -} - -// adds baremetal rack configuration text -func (s *BaremetalService) AddBaremetalRct(p *AddBaremetalRctParams) (*AddBaremetalRctResponse, error) { - resp, err := s.cs.newRequest("addBaremetalRct", p.toURLValues()) - if err != nil { - return nil, err - } - - var r AddBaremetalRctResponse - if err := json.Unmarshal(resp, &r); err != nil { - return nil, err - } - - // If we have a async client, we need to wait for the async result - if s.cs.async { - b, err := s.cs.GetAsyncJobResult(r.JobID, s.cs.timeout) - if err != nil { - if err == AsyncTimeoutErr { - return &r, err - } - return nil, err - } - - b, err = getRawValue(b) - if err != nil { - return nil, err - } - - if err := json.Unmarshal(b, &r); err != nil { - return nil, err - } - } - return &r, nil -} - -type AddBaremetalRctResponse struct { - JobID string `json:"jobid,omitempty"` - Id string `json:"id,omitempty"` - Url string `json:"url,omitempty"` -} - -type DeleteBaremetalRctParams struct { - p map[string]interface{} -} - -func (p *DeleteBaremetalRctParams) toURLValues() url.Values { - u := url.Values{} - if p.p == nil { - return u - } - if v, found := p.p["id"]; found { - u.Set("id", v.(string)) - } - return u -} - -func (p *DeleteBaremetalRctParams) SetId(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["id"] = v - return -} - -// You should always use this function to get a new DeleteBaremetalRctParams instance, -// as then you are sure you have configured all required params -func (s *BaremetalService) NewDeleteBaremetalRctParams(id string) *DeleteBaremetalRctParams { - p := &DeleteBaremetalRctParams{} - p.p = make(map[string]interface{}) - p.p["id"] = id - return p -} - -// deletes baremetal rack configuration text -func (s *BaremetalService) DeleteBaremetalRct(p *DeleteBaremetalRctParams) (*DeleteBaremetalRctResponse, error) { - resp, err := s.cs.newRequest("deleteBaremetalRct", p.toURLValues()) - if err != nil { - return nil, err - } - - var r DeleteBaremetalRctResponse - if err := json.Unmarshal(resp, &r); err != nil { - return nil, err - } - - // If we have a async client, we need to wait for the async result - if s.cs.async { - b, err := s.cs.GetAsyncJobResult(r.JobID, s.cs.timeout) - if err != nil { - if err == AsyncTimeoutErr { - return &r, err - } - return nil, err - } - - if err := json.Unmarshal(b, &r); err != nil { - return nil, err - } - } - return &r, nil -} - -type DeleteBaremetalRctResponse struct { - JobID string `json:"jobid,omitempty"` - Displaytext string `json:"displaytext,omitempty"` - Success bool `json:"success,omitempty"` + Id string `json:"id"` + Physicalnetworkid string `json:"physicalnetworkid"` + Provider string `json:"provider"` + Url string `json:"url"` } type ListBaremetalRctParams struct { @@ -904,6 +911,7 @@ func (s *BaremetalService) ListBaremetalRct(p *ListBaremetalRctParams) (*ListBar if err := json.Unmarshal(resp, &r); err != nil { return nil, err } + return &r, nil } @@ -913,6 +921,74 @@ type ListBaremetalRctResponse struct { } type BaremetalRct struct { - Id string `json:"id,omitempty"` - Url string `json:"url,omitempty"` + Id string `json:"id"` + Url string `json:"url"` +} + +type NotifyBaremetalProvisionDoneParams struct { + p map[string]interface{} +} + +func (p *NotifyBaremetalProvisionDoneParams) toURLValues() url.Values { + u := url.Values{} + if p.p == nil { + return u + } + if v, found := p.p["mac"]; found { + u.Set("mac", v.(string)) + } + return u +} + +func (p *NotifyBaremetalProvisionDoneParams) SetMac(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["mac"] = v + return +} + +// You should always use this function to get a new NotifyBaremetalProvisionDoneParams instance, +// as then you are sure you have configured all required params +func (s *BaremetalService) NewNotifyBaremetalProvisionDoneParams(mac string) *NotifyBaremetalProvisionDoneParams { + p := &NotifyBaremetalProvisionDoneParams{} + p.p = make(map[string]interface{}) + p.p["mac"] = mac + return p +} + +// Notify provision has been done on a host. This api is for baremetal virtual router service, not for end user +func (s *BaremetalService) NotifyBaremetalProvisionDone(p *NotifyBaremetalProvisionDoneParams) (*NotifyBaremetalProvisionDoneResponse, error) { + resp, err := s.cs.newRequest("notifyBaremetalProvisionDone", p.toURLValues()) + if err != nil { + return nil, err + } + + var r NotifyBaremetalProvisionDoneResponse + if err := json.Unmarshal(resp, &r); err != nil { + return nil, err + } + + // If we have a async client, we need to wait for the async result + if s.cs.async { + b, err := s.cs.GetAsyncJobResult(r.JobID, s.cs.timeout) + if err != nil { + if err == AsyncTimeoutErr { + return &r, err + } + return nil, err + } + + if err := json.Unmarshal(b, &r); err != nil { + return nil, err + } + } + + return &r, nil +} + +type NotifyBaremetalProvisionDoneResponse struct { + JobID string `json:"jobid"` + Displaytext string `json:"displaytext"` + Success bool `json:"success"` } diff --git a/vendor/github.com/xanzy/go-cloudstack/cloudstack/BigSwitchBCFService.go b/vendor/github.com/xanzy/go-cloudstack/cloudstack/BigSwitchBCFService.go new file mode 100644 index 000000000..e85b20730 --- /dev/null +++ b/vendor/github.com/xanzy/go-cloudstack/cloudstack/BigSwitchBCFService.go @@ -0,0 +1,327 @@ +// +// Copyright 2018, Sander van Harmelen +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// + +package cloudstack + +import ( + "encoding/json" + "net/url" + "strconv" +) + +type AddBigSwitchBcfDeviceParams struct { + p map[string]interface{} +} + +func (p *AddBigSwitchBcfDeviceParams) toURLValues() url.Values { + u := url.Values{} + if p.p == nil { + return u + } + if v, found := p.p["hostname"]; found { + u.Set("hostname", v.(string)) + } + if v, found := p.p["nat"]; found { + vv := strconv.FormatBool(v.(bool)) + u.Set("nat", vv) + } + if v, found := p.p["password"]; found { + u.Set("password", v.(string)) + } + if v, found := p.p["physicalnetworkid"]; found { + u.Set("physicalnetworkid", v.(string)) + } + if v, found := p.p["username"]; found { + u.Set("username", v.(string)) + } + return u +} + +func (p *AddBigSwitchBcfDeviceParams) SetHostname(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["hostname"] = v + return +} + +func (p *AddBigSwitchBcfDeviceParams) SetNat(v bool) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["nat"] = v + return +} + +func (p *AddBigSwitchBcfDeviceParams) SetPassword(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["password"] = v + return +} + +func (p *AddBigSwitchBcfDeviceParams) SetPhysicalnetworkid(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["physicalnetworkid"] = v + return +} + +func (p *AddBigSwitchBcfDeviceParams) SetUsername(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["username"] = v + return +} + +// You should always use this function to get a new AddBigSwitchBcfDeviceParams instance, +// as then you are sure you have configured all required params +func (s *BigSwitchBCFService) NewAddBigSwitchBcfDeviceParams(hostname string, nat bool, password string, physicalnetworkid string, username string) *AddBigSwitchBcfDeviceParams { + p := &AddBigSwitchBcfDeviceParams{} + p.p = make(map[string]interface{}) + p.p["hostname"] = hostname + p.p["nat"] = nat + p.p["password"] = password + p.p["physicalnetworkid"] = physicalnetworkid + p.p["username"] = username + return p +} + +// Adds a BigSwitch BCF Controller device +func (s *BigSwitchBCFService) AddBigSwitchBcfDevice(p *AddBigSwitchBcfDeviceParams) (*AddBigSwitchBcfDeviceResponse, error) { + resp, err := s.cs.newRequest("addBigSwitchBcfDevice", p.toURLValues()) + if err != nil { + return nil, err + } + + var r AddBigSwitchBcfDeviceResponse + if err := json.Unmarshal(resp, &r); err != nil { + return nil, err + } + + // If we have a async client, we need to wait for the async result + if s.cs.async { + b, err := s.cs.GetAsyncJobResult(r.JobID, s.cs.timeout) + if err != nil { + if err == AsyncTimeoutErr { + return &r, err + } + return nil, err + } + + b, err = getRawValue(b) + if err != nil { + return nil, err + } + + if err := json.Unmarshal(b, &r); err != nil { + return nil, err + } + } + + return &r, nil +} + +type AddBigSwitchBcfDeviceResponse struct { + JobID string `json:"jobid"` + Bcfdeviceid string `json:"bcfdeviceid"` + Bigswitchdevicename string `json:"bigswitchdevicename"` + Hostname string `json:"hostname"` + Nat bool `json:"nat"` + Password string `json:"password"` + Physicalnetworkid string `json:"physicalnetworkid"` + Provider string `json:"provider"` + Username string `json:"username"` +} + +type DeleteBigSwitchBcfDeviceParams struct { + p map[string]interface{} +} + +func (p *DeleteBigSwitchBcfDeviceParams) toURLValues() url.Values { + u := url.Values{} + if p.p == nil { + return u + } + if v, found := p.p["bcfdeviceid"]; found { + u.Set("bcfdeviceid", v.(string)) + } + return u +} + +func (p *DeleteBigSwitchBcfDeviceParams) SetBcfdeviceid(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["bcfdeviceid"] = v + return +} + +// You should always use this function to get a new DeleteBigSwitchBcfDeviceParams instance, +// as then you are sure you have configured all required params +func (s *BigSwitchBCFService) NewDeleteBigSwitchBcfDeviceParams(bcfdeviceid string) *DeleteBigSwitchBcfDeviceParams { + p := &DeleteBigSwitchBcfDeviceParams{} + p.p = make(map[string]interface{}) + p.p["bcfdeviceid"] = bcfdeviceid + return p +} + +// delete a BigSwitch BCF Controller device +func (s *BigSwitchBCFService) DeleteBigSwitchBcfDevice(p *DeleteBigSwitchBcfDeviceParams) (*DeleteBigSwitchBcfDeviceResponse, error) { + resp, err := s.cs.newRequest("deleteBigSwitchBcfDevice", p.toURLValues()) + if err != nil { + return nil, err + } + + var r DeleteBigSwitchBcfDeviceResponse + if err := json.Unmarshal(resp, &r); err != nil { + return nil, err + } + + // If we have a async client, we need to wait for the async result + if s.cs.async { + b, err := s.cs.GetAsyncJobResult(r.JobID, s.cs.timeout) + if err != nil { + if err == AsyncTimeoutErr { + return &r, err + } + return nil, err + } + + if err := json.Unmarshal(b, &r); err != nil { + return nil, err + } + } + + return &r, nil +} + +type DeleteBigSwitchBcfDeviceResponse struct { + JobID string `json:"jobid"` + Displaytext string `json:"displaytext"` + Success bool `json:"success"` +} + +type ListBigSwitchBcfDevicesParams struct { + p map[string]interface{} +} + +func (p *ListBigSwitchBcfDevicesParams) toURLValues() url.Values { + u := url.Values{} + if p.p == nil { + return u + } + if v, found := p.p["bcfdeviceid"]; found { + u.Set("bcfdeviceid", v.(string)) + } + if v, found := p.p["keyword"]; found { + u.Set("keyword", v.(string)) + } + if v, found := p.p["page"]; found { + vv := strconv.Itoa(v.(int)) + u.Set("page", vv) + } + if v, found := p.p["pagesize"]; found { + vv := strconv.Itoa(v.(int)) + u.Set("pagesize", vv) + } + if v, found := p.p["physicalnetworkid"]; found { + u.Set("physicalnetworkid", v.(string)) + } + return u +} + +func (p *ListBigSwitchBcfDevicesParams) SetBcfdeviceid(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["bcfdeviceid"] = v + return +} + +func (p *ListBigSwitchBcfDevicesParams) SetKeyword(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["keyword"] = v + return +} + +func (p *ListBigSwitchBcfDevicesParams) SetPage(v int) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["page"] = v + return +} + +func (p *ListBigSwitchBcfDevicesParams) SetPagesize(v int) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["pagesize"] = v + return +} + +func (p *ListBigSwitchBcfDevicesParams) SetPhysicalnetworkid(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["physicalnetworkid"] = v + return +} + +// You should always use this function to get a new ListBigSwitchBcfDevicesParams instance, +// as then you are sure you have configured all required params +func (s *BigSwitchBCFService) NewListBigSwitchBcfDevicesParams() *ListBigSwitchBcfDevicesParams { + p := &ListBigSwitchBcfDevicesParams{} + p.p = make(map[string]interface{}) + return p +} + +// Lists BigSwitch BCF Controller devices +func (s *BigSwitchBCFService) ListBigSwitchBcfDevices(p *ListBigSwitchBcfDevicesParams) (*ListBigSwitchBcfDevicesResponse, error) { + resp, err := s.cs.newRequest("listBigSwitchBcfDevices", p.toURLValues()) + if err != nil { + return nil, err + } + + var r ListBigSwitchBcfDevicesResponse + if err := json.Unmarshal(resp, &r); err != nil { + return nil, err + } + + return &r, nil +} + +type ListBigSwitchBcfDevicesResponse struct { + Count int `json:"count"` + BigSwitchBcfDevices []*BigSwitchBcfDevice `json:"bigswitchbcfdevice"` +} + +type BigSwitchBcfDevice struct { + Bcfdeviceid string `json:"bcfdeviceid"` + Bigswitchdevicename string `json:"bigswitchdevicename"` + Hostname string `json:"hostname"` + Nat bool `json:"nat"` + Password string `json:"password"` + Physicalnetworkid string `json:"physicalnetworkid"` + Provider string `json:"provider"` + Username string `json:"username"` +} diff --git a/vendor/github.com/xanzy/go-cloudstack/cloudstack/BrocadeVCSService.go b/vendor/github.com/xanzy/go-cloudstack/cloudstack/BrocadeVCSService.go new file mode 100644 index 000000000..297476709 --- /dev/null +++ b/vendor/github.com/xanzy/go-cloudstack/cloudstack/BrocadeVCSService.go @@ -0,0 +1,508 @@ +// +// Copyright 2018, Sander van Harmelen +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// + +package cloudstack + +import ( + "encoding/json" + "fmt" + "net/url" + "strconv" +) + +type AddBrocadeVcsDeviceParams struct { + p map[string]interface{} +} + +func (p *AddBrocadeVcsDeviceParams) toURLValues() url.Values { + u := url.Values{} + if p.p == nil { + return u + } + if v, found := p.p["hostname"]; found { + u.Set("hostname", v.(string)) + } + if v, found := p.p["password"]; found { + u.Set("password", v.(string)) + } + if v, found := p.p["physicalnetworkid"]; found { + u.Set("physicalnetworkid", v.(string)) + } + if v, found := p.p["username"]; found { + u.Set("username", v.(string)) + } + return u +} + +func (p *AddBrocadeVcsDeviceParams) SetHostname(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["hostname"] = v + return +} + +func (p *AddBrocadeVcsDeviceParams) SetPassword(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["password"] = v + return +} + +func (p *AddBrocadeVcsDeviceParams) SetPhysicalnetworkid(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["physicalnetworkid"] = v + return +} + +func (p *AddBrocadeVcsDeviceParams) SetUsername(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["username"] = v + return +} + +// You should always use this function to get a new AddBrocadeVcsDeviceParams instance, +// as then you are sure you have configured all required params +func (s *BrocadeVCSService) NewAddBrocadeVcsDeviceParams(hostname string, password string, physicalnetworkid string, username string) *AddBrocadeVcsDeviceParams { + p := &AddBrocadeVcsDeviceParams{} + p.p = make(map[string]interface{}) + p.p["hostname"] = hostname + p.p["password"] = password + p.p["physicalnetworkid"] = physicalnetworkid + p.p["username"] = username + return p +} + +// Adds a Brocade VCS Switch +func (s *BrocadeVCSService) AddBrocadeVcsDevice(p *AddBrocadeVcsDeviceParams) (*AddBrocadeVcsDeviceResponse, error) { + resp, err := s.cs.newRequest("addBrocadeVcsDevice", p.toURLValues()) + if err != nil { + return nil, err + } + + var r AddBrocadeVcsDeviceResponse + if err := json.Unmarshal(resp, &r); err != nil { + return nil, err + } + + // If we have a async client, we need to wait for the async result + if s.cs.async { + b, err := s.cs.GetAsyncJobResult(r.JobID, s.cs.timeout) + if err != nil { + if err == AsyncTimeoutErr { + return &r, err + } + return nil, err + } + + b, err = getRawValue(b) + if err != nil { + return nil, err + } + + if err := json.Unmarshal(b, &r); err != nil { + return nil, err + } + } + + return &r, nil +} + +type AddBrocadeVcsDeviceResponse struct { + JobID string `json:"jobid"` + Brocadedevicename string `json:"brocadedevicename"` + Hostname string `json:"hostname"` + Physicalnetworkid string `json:"physicalnetworkid"` + Provider string `json:"provider"` + Vcsdeviceid string `json:"vcsdeviceid"` +} + +type DeleteBrocadeVcsDeviceParams struct { + p map[string]interface{} +} + +func (p *DeleteBrocadeVcsDeviceParams) toURLValues() url.Values { + u := url.Values{} + if p.p == nil { + return u + } + if v, found := p.p["vcsdeviceid"]; found { + u.Set("vcsdeviceid", v.(string)) + } + return u +} + +func (p *DeleteBrocadeVcsDeviceParams) SetVcsdeviceid(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["vcsdeviceid"] = v + return +} + +// You should always use this function to get a new DeleteBrocadeVcsDeviceParams instance, +// as then you are sure you have configured all required params +func (s *BrocadeVCSService) NewDeleteBrocadeVcsDeviceParams(vcsdeviceid string) *DeleteBrocadeVcsDeviceParams { + p := &DeleteBrocadeVcsDeviceParams{} + p.p = make(map[string]interface{}) + p.p["vcsdeviceid"] = vcsdeviceid + return p +} + +// delete a Brocade VCS Switch +func (s *BrocadeVCSService) DeleteBrocadeVcsDevice(p *DeleteBrocadeVcsDeviceParams) (*DeleteBrocadeVcsDeviceResponse, error) { + resp, err := s.cs.newRequest("deleteBrocadeVcsDevice", p.toURLValues()) + if err != nil { + return nil, err + } + + var r DeleteBrocadeVcsDeviceResponse + if err := json.Unmarshal(resp, &r); err != nil { + return nil, err + } + + // If we have a async client, we need to wait for the async result + if s.cs.async { + b, err := s.cs.GetAsyncJobResult(r.JobID, s.cs.timeout) + if err != nil { + if err == AsyncTimeoutErr { + return &r, err + } + return nil, err + } + + if err := json.Unmarshal(b, &r); err != nil { + return nil, err + } + } + + return &r, nil +} + +type DeleteBrocadeVcsDeviceResponse struct { + JobID string `json:"jobid"` + Displaytext string `json:"displaytext"` + Success bool `json:"success"` +} + +type ListBrocadeVcsDeviceNetworksParams struct { + p map[string]interface{} +} + +func (p *ListBrocadeVcsDeviceNetworksParams) toURLValues() url.Values { + u := url.Values{} + if p.p == nil { + return u + } + if v, found := p.p["keyword"]; found { + u.Set("keyword", v.(string)) + } + if v, found := p.p["page"]; found { + vv := strconv.Itoa(v.(int)) + u.Set("page", vv) + } + if v, found := p.p["pagesize"]; found { + vv := strconv.Itoa(v.(int)) + u.Set("pagesize", vv) + } + if v, found := p.p["vcsdeviceid"]; found { + u.Set("vcsdeviceid", v.(string)) + } + return u +} + +func (p *ListBrocadeVcsDeviceNetworksParams) SetKeyword(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["keyword"] = v + return +} + +func (p *ListBrocadeVcsDeviceNetworksParams) SetPage(v int) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["page"] = v + return +} + +func (p *ListBrocadeVcsDeviceNetworksParams) SetPagesize(v int) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["pagesize"] = v + return +} + +func (p *ListBrocadeVcsDeviceNetworksParams) SetVcsdeviceid(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["vcsdeviceid"] = v + return +} + +// You should always use this function to get a new ListBrocadeVcsDeviceNetworksParams instance, +// as then you are sure you have configured all required params +func (s *BrocadeVCSService) NewListBrocadeVcsDeviceNetworksParams(vcsdeviceid string) *ListBrocadeVcsDeviceNetworksParams { + p := &ListBrocadeVcsDeviceNetworksParams{} + p.p = make(map[string]interface{}) + p.p["vcsdeviceid"] = vcsdeviceid + return p +} + +// This is a courtesy helper function, which in some cases may not work as expected! +func (s *BrocadeVCSService) GetBrocadeVcsDeviceNetworkID(keyword string, vcsdeviceid string, opts ...OptionFunc) (string, int, error) { + p := &ListBrocadeVcsDeviceNetworksParams{} + p.p = make(map[string]interface{}) + + p.p["keyword"] = keyword + p.p["vcsdeviceid"] = vcsdeviceid + + for _, fn := range append(s.cs.options, opts...) { + if err := fn(s.cs, p); err != nil { + return "", -1, err + } + } + + l, err := s.ListBrocadeVcsDeviceNetworks(p) + if err != nil { + return "", -1, err + } + + if l.Count == 0 { + return "", l.Count, fmt.Errorf("No match found for %s: %+v", keyword, l) + } + + if l.Count == 1 { + return l.BrocadeVcsDeviceNetworks[0].Id, l.Count, nil + } + + if l.Count > 1 { + for _, v := range l.BrocadeVcsDeviceNetworks { + if v.Name == keyword { + return v.Id, l.Count, nil + } + } + } + return "", l.Count, fmt.Errorf("Could not find an exact match for %s: %+v", keyword, l) +} + +// lists network that are using a brocade vcs switch +func (s *BrocadeVCSService) ListBrocadeVcsDeviceNetworks(p *ListBrocadeVcsDeviceNetworksParams) (*ListBrocadeVcsDeviceNetworksResponse, error) { + resp, err := s.cs.newRequest("listBrocadeVcsDeviceNetworks", p.toURLValues()) + if err != nil { + return nil, err + } + + var r ListBrocadeVcsDeviceNetworksResponse + if err := json.Unmarshal(resp, &r); err != nil { + return nil, err + } + + return &r, nil +} + +type ListBrocadeVcsDeviceNetworksResponse struct { + Count int `json:"count"` + BrocadeVcsDeviceNetworks []*BrocadeVcsDeviceNetwork `json:"brocadevcsdevicenetwork"` +} + +type BrocadeVcsDeviceNetwork struct { + Account string `json:"account"` + Aclid string `json:"aclid"` + Acltype string `json:"acltype"` + Broadcastdomaintype string `json:"broadcastdomaintype"` + Broadcasturi string `json:"broadcasturi"` + Canusefordeploy bool `json:"canusefordeploy"` + Cidr string `json:"cidr"` + Displaynetwork bool `json:"displaynetwork"` + Displaytext string `json:"displaytext"` + Dns1 string `json:"dns1"` + Dns2 string `json:"dns2"` + Domain string `json:"domain"` + Domainid string `json:"domainid"` + Externalid string `json:"externalid"` + Gateway string `json:"gateway"` + Id string `json:"id"` + Ip6cidr string `json:"ip6cidr"` + Ip6gateway string `json:"ip6gateway"` + Isdefault bool `json:"isdefault"` + Ispersistent bool `json:"ispersistent"` + Issystem bool `json:"issystem"` + Name string `json:"name"` + Netmask string `json:"netmask"` + Networkcidr string `json:"networkcidr"` + Networkdomain string `json:"networkdomain"` + Networkofferingavailability string `json:"networkofferingavailability"` + Networkofferingconservemode bool `json:"networkofferingconservemode"` + Networkofferingdisplaytext string `json:"networkofferingdisplaytext"` + Networkofferingid string `json:"networkofferingid"` + Networkofferingname string `json:"networkofferingname"` + Physicalnetworkid string `json:"physicalnetworkid"` + Project string `json:"project"` + Projectid string `json:"projectid"` + Redundantrouter bool `json:"redundantrouter"` + Related string `json:"related"` + Reservediprange string `json:"reservediprange"` + Restartrequired bool `json:"restartrequired"` + Service []BrocadeVcsDeviceNetworkService `json:"service"` + Specifyipranges bool `json:"specifyipranges"` + State string `json:"state"` + Strechedl2subnet bool `json:"strechedl2subnet"` + Subdomainaccess bool `json:"subdomainaccess"` + Tags []Tags `json:"tags"` + Traffictype string `json:"traffictype"` + Type string `json:"type"` + Vlan string `json:"vlan"` + Vpcid string `json:"vpcid"` + Zoneid string `json:"zoneid"` + Zonename string `json:"zonename"` + Zonesnetworkspans []interface{} `json:"zonesnetworkspans"` +} + +type BrocadeVcsDeviceNetworkService struct { + Capability []BrocadeVcsDeviceNetworkServiceCapability `json:"capability"` + Name string `json:"name"` + Provider []BrocadeVcsDeviceNetworkServiceProvider `json:"provider"` +} + +type BrocadeVcsDeviceNetworkServiceProvider struct { + Canenableindividualservice bool `json:"canenableindividualservice"` + Destinationphysicalnetworkid string `json:"destinationphysicalnetworkid"` + Id string `json:"id"` + Name string `json:"name"` + Physicalnetworkid string `json:"physicalnetworkid"` + Servicelist []string `json:"servicelist"` + State string `json:"state"` +} + +type BrocadeVcsDeviceNetworkServiceCapability struct { + Canchooseservicecapability bool `json:"canchooseservicecapability"` + Name string `json:"name"` + Value string `json:"value"` +} + +type ListBrocadeVcsDevicesParams struct { + p map[string]interface{} +} + +func (p *ListBrocadeVcsDevicesParams) toURLValues() url.Values { + u := url.Values{} + if p.p == nil { + return u + } + if v, found := p.p["keyword"]; found { + u.Set("keyword", v.(string)) + } + if v, found := p.p["page"]; found { + vv := strconv.Itoa(v.(int)) + u.Set("page", vv) + } + if v, found := p.p["pagesize"]; found { + vv := strconv.Itoa(v.(int)) + u.Set("pagesize", vv) + } + if v, found := p.p["physicalnetworkid"]; found { + u.Set("physicalnetworkid", v.(string)) + } + if v, found := p.p["vcsdeviceid"]; found { + u.Set("vcsdeviceid", v.(string)) + } + return u +} + +func (p *ListBrocadeVcsDevicesParams) SetKeyword(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["keyword"] = v + return +} + +func (p *ListBrocadeVcsDevicesParams) SetPage(v int) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["page"] = v + return +} + +func (p *ListBrocadeVcsDevicesParams) SetPagesize(v int) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["pagesize"] = v + return +} + +func (p *ListBrocadeVcsDevicesParams) SetPhysicalnetworkid(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["physicalnetworkid"] = v + return +} + +func (p *ListBrocadeVcsDevicesParams) SetVcsdeviceid(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["vcsdeviceid"] = v + return +} + +// You should always use this function to get a new ListBrocadeVcsDevicesParams instance, +// as then you are sure you have configured all required params +func (s *BrocadeVCSService) NewListBrocadeVcsDevicesParams() *ListBrocadeVcsDevicesParams { + p := &ListBrocadeVcsDevicesParams{} + p.p = make(map[string]interface{}) + return p +} + +// Lists Brocade VCS Switches +func (s *BrocadeVCSService) ListBrocadeVcsDevices(p *ListBrocadeVcsDevicesParams) (*ListBrocadeVcsDevicesResponse, error) { + resp, err := s.cs.newRequest("listBrocadeVcsDevices", p.toURLValues()) + if err != nil { + return nil, err + } + + var r ListBrocadeVcsDevicesResponse + if err := json.Unmarshal(resp, &r); err != nil { + return nil, err + } + + return &r, nil +} + +type ListBrocadeVcsDevicesResponse struct { + Count int `json:"count"` + BrocadeVcsDevices []*BrocadeVcsDevice `json:"brocadevcsdevice"` +} + +type BrocadeVcsDevice struct { + Brocadedevicename string `json:"brocadedevicename"` + Hostname string `json:"hostname"` + Physicalnetworkid string `json:"physicalnetworkid"` + Provider string `json:"provider"` + Vcsdeviceid string `json:"vcsdeviceid"` +} diff --git a/vendor/github.com/xanzy/go-cloudstack/cloudstack/CertificateService.go b/vendor/github.com/xanzy/go-cloudstack/cloudstack/CertificateService.go index a13fcdfc2..196b961e4 100644 --- a/vendor/github.com/xanzy/go-cloudstack/cloudstack/CertificateService.go +++ b/vendor/github.com/xanzy/go-cloudstack/cloudstack/CertificateService.go @@ -1,5 +1,5 @@ // -// Copyright 2016, Sander van Harmelen +// Copyright 2018, Sander van Harmelen // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -131,10 +131,11 @@ func (s *CertificateService) UploadCustomCertificate(p *UploadCustomCertificateP return nil, err } } + return &r, nil } type UploadCustomCertificateResponse struct { - JobID string `json:"jobid,omitempty"` - Message string `json:"message,omitempty"` + JobID string `json:"jobid"` + Message string `json:"message"` } diff --git a/vendor/github.com/xanzy/go-cloudstack/cloudstack/CloudIdentifierService.go b/vendor/github.com/xanzy/go-cloudstack/cloudstack/CloudIdentifierService.go index 99eeba2c8..40d70aa92 100644 --- a/vendor/github.com/xanzy/go-cloudstack/cloudstack/CloudIdentifierService.go +++ b/vendor/github.com/xanzy/go-cloudstack/cloudstack/CloudIdentifierService.go @@ -1,5 +1,5 @@ // -// Copyright 2016, Sander van Harmelen +// Copyright 2018, Sander van Harmelen // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -64,11 +64,12 @@ func (s *CloudIdentifierService) GetCloudIdentifier(p *GetCloudIdentifierParams) if err := json.Unmarshal(resp, &r); err != nil { return nil, err } + return &r, nil } type GetCloudIdentifierResponse struct { - Cloudidentifier string `json:"cloudidentifier,omitempty"` - Signature string `json:"signature,omitempty"` - Userid string `json:"userid,omitempty"` + Cloudidentifier string `json:"cloudidentifier"` + Signature string `json:"signature"` + Userid string `json:"userid"` } diff --git a/vendor/github.com/xanzy/go-cloudstack/cloudstack/ClusterService.go b/vendor/github.com/xanzy/go-cloudstack/cloudstack/ClusterService.go index 0ba05b4d9..8ad5cfce3 100644 --- a/vendor/github.com/xanzy/go-cloudstack/cloudstack/ClusterService.go +++ b/vendor/github.com/xanzy/go-cloudstack/cloudstack/ClusterService.go @@ -1,5 +1,5 @@ // -// Copyright 2016, Sander van Harmelen +// Copyright 2018, Sander van Harmelen // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -269,35 +269,141 @@ func (s *ClusterService) AddCluster(p *AddClusterParams) (*AddClusterResponse, e if err := json.Unmarshal(resp, &r); err != nil { return nil, err } + return &r, nil } type AddClusterResponse struct { - Allocationstate string `json:"allocationstate,omitempty"` - Capacity []struct { - Capacitytotal int64 `json:"capacitytotal,omitempty"` - Capacityused int64 `json:"capacityused,omitempty"` - Clusterid string `json:"clusterid,omitempty"` - Clustername string `json:"clustername,omitempty"` - Percentused string `json:"percentused,omitempty"` - Podid string `json:"podid,omitempty"` - Podname string `json:"podname,omitempty"` - Type int `json:"type,omitempty"` - Zoneid string `json:"zoneid,omitempty"` - Zonename string `json:"zonename,omitempty"` - } `json:"capacity,omitempty"` - Clustertype string `json:"clustertype,omitempty"` - Cpuovercommitratio string `json:"cpuovercommitratio,omitempty"` - Hypervisortype string `json:"hypervisortype,omitempty"` - Id string `json:"id,omitempty"` - Managedstate string `json:"managedstate,omitempty"` - Memoryovercommitratio string `json:"memoryovercommitratio,omitempty"` - Name string `json:"name,omitempty"` - Ovm3vip string `json:"ovm3vip,omitempty"` - Podid string `json:"podid,omitempty"` - Podname string `json:"podname,omitempty"` - Zoneid string `json:"zoneid,omitempty"` - Zonename string `json:"zonename,omitempty"` + Allocationstate string `json:"allocationstate"` + Capacity []AddClusterResponseCapacity `json:"capacity"` + Clustertype string `json:"clustertype"` + Cpuovercommitratio string `json:"cpuovercommitratio"` + Hypervisortype string `json:"hypervisortype"` + Id string `json:"id"` + Managedstate string `json:"managedstate"` + Memoryovercommitratio string `json:"memoryovercommitratio"` + Name string `json:"name"` + Ovm3vip string `json:"ovm3vip"` + Podid string `json:"podid"` + Podname string `json:"podname"` + Resourcedetails map[string]string `json:"resourcedetails"` + Zoneid string `json:"zoneid"` + Zonename string `json:"zonename"` +} + +type AddClusterResponseCapacity struct { + Capacityallocated int64 `json:"capacityallocated"` + Capacitytotal int64 `json:"capacitytotal"` + Capacityused int64 `json:"capacityused"` + Clusterid string `json:"clusterid"` + Clustername string `json:"clustername"` + Name string `json:"name"` + Percentused string `json:"percentused"` + Podid string `json:"podid"` + Podname string `json:"podname"` + Type int `json:"type"` + Zoneid string `json:"zoneid"` + Zonename string `json:"zonename"` +} + +type DedicateClusterParams struct { + p map[string]interface{} +} + +func (p *DedicateClusterParams) toURLValues() url.Values { + u := url.Values{} + if p.p == nil { + return u + } + if v, found := p.p["account"]; found { + u.Set("account", v.(string)) + } + if v, found := p.p["clusterid"]; found { + u.Set("clusterid", v.(string)) + } + if v, found := p.p["domainid"]; found { + u.Set("domainid", v.(string)) + } + return u +} + +func (p *DedicateClusterParams) SetAccount(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["account"] = v + return +} + +func (p *DedicateClusterParams) SetClusterid(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["clusterid"] = v + return +} + +func (p *DedicateClusterParams) SetDomainid(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["domainid"] = v + return +} + +// You should always use this function to get a new DedicateClusterParams instance, +// as then you are sure you have configured all required params +func (s *ClusterService) NewDedicateClusterParams(clusterid string, domainid string) *DedicateClusterParams { + p := &DedicateClusterParams{} + p.p = make(map[string]interface{}) + p.p["clusterid"] = clusterid + p.p["domainid"] = domainid + return p +} + +// Dedicate an existing cluster +func (s *ClusterService) DedicateCluster(p *DedicateClusterParams) (*DedicateClusterResponse, error) { + resp, err := s.cs.newRequest("dedicateCluster", p.toURLValues()) + if err != nil { + return nil, err + } + + var r DedicateClusterResponse + if err := json.Unmarshal(resp, &r); err != nil { + return nil, err + } + + // If we have a async client, we need to wait for the async result + if s.cs.async { + b, err := s.cs.GetAsyncJobResult(r.JobID, s.cs.timeout) + if err != nil { + if err == AsyncTimeoutErr { + return &r, err + } + return nil, err + } + + b, err = getRawValue(b) + if err != nil { + return nil, err + } + + if err := json.Unmarshal(b, &r); err != nil { + return nil, err + } + } + + return &r, nil +} + +type DedicateClusterResponse struct { + JobID string `json:"jobid"` + Accountid string `json:"accountid"` + Affinitygroupid string `json:"affinitygroupid"` + Clusterid string `json:"clusterid"` + Clustername string `json:"clustername"` + Domainid string `json:"domainid"` + Id string `json:"id"` } type DeleteClusterParams struct { @@ -343,141 +449,196 @@ func (s *ClusterService) DeleteCluster(p *DeleteClusterParams) (*DeleteClusterRe if err := json.Unmarshal(resp, &r); err != nil { return nil, err } + return &r, nil } type DeleteClusterResponse struct { - Displaytext string `json:"displaytext,omitempty"` - Success string `json:"success,omitempty"` + Displaytext string `json:"displaytext"` + Success bool `json:"success"` } -type UpdateClusterParams struct { +func (r *DeleteClusterResponse) UnmarshalJSON(b []byte) error { + var m map[string]interface{} + err := json.Unmarshal(b, &m) + if err != nil { + return err + } + + if success, ok := m["success"].(string); ok { + m["success"] = success == "true" + b, err = json.Marshal(m) + if err != nil { + return err + } + } + + type alias DeleteClusterResponse + return json.Unmarshal(b, (*alias)(r)) +} + +type DisableOutOfBandManagementForClusterParams struct { p map[string]interface{} } -func (p *UpdateClusterParams) toURLValues() url.Values { +func (p *DisableOutOfBandManagementForClusterParams) toURLValues() url.Values { u := url.Values{} if p.p == nil { return u } - if v, found := p.p["allocationstate"]; found { - u.Set("allocationstate", v.(string)) - } - if v, found := p.p["clustername"]; found { - u.Set("clustername", v.(string)) - } - if v, found := p.p["clustertype"]; found { - u.Set("clustertype", v.(string)) - } - if v, found := p.p["hypervisor"]; found { - u.Set("hypervisor", v.(string)) - } - if v, found := p.p["id"]; found { - u.Set("id", v.(string)) - } - if v, found := p.p["managedstate"]; found { - u.Set("managedstate", v.(string)) + if v, found := p.p["clusterid"]; found { + u.Set("clusterid", v.(string)) } return u } -func (p *UpdateClusterParams) SetAllocationstate(v string) { +func (p *DisableOutOfBandManagementForClusterParams) SetClusterid(v string) { if p.p == nil { p.p = make(map[string]interface{}) } - p.p["allocationstate"] = v + p.p["clusterid"] = v return } -func (p *UpdateClusterParams) SetClustername(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["clustername"] = v - return -} - -func (p *UpdateClusterParams) SetClustertype(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["clustertype"] = v - return -} - -func (p *UpdateClusterParams) SetHypervisor(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["hypervisor"] = v - return -} - -func (p *UpdateClusterParams) SetId(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["id"] = v - return -} - -func (p *UpdateClusterParams) SetManagedstate(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["managedstate"] = v - return -} - -// You should always use this function to get a new UpdateClusterParams instance, +// You should always use this function to get a new DisableOutOfBandManagementForClusterParams instance, // as then you are sure you have configured all required params -func (s *ClusterService) NewUpdateClusterParams(id string) *UpdateClusterParams { - p := &UpdateClusterParams{} +func (s *ClusterService) NewDisableOutOfBandManagementForClusterParams(clusterid string) *DisableOutOfBandManagementForClusterParams { + p := &DisableOutOfBandManagementForClusterParams{} p.p = make(map[string]interface{}) - p.p["id"] = id + p.p["clusterid"] = clusterid return p } -// Updates an existing cluster -func (s *ClusterService) UpdateCluster(p *UpdateClusterParams) (*UpdateClusterResponse, error) { - resp, err := s.cs.newRequest("updateCluster", p.toURLValues()) +// Disables out-of-band management for a cluster +func (s *ClusterService) DisableOutOfBandManagementForCluster(p *DisableOutOfBandManagementForClusterParams) (*DisableOutOfBandManagementForClusterResponse, error) { + resp, err := s.cs.newRequest("disableOutOfBandManagementForCluster", p.toURLValues()) if err != nil { return nil, err } - var r UpdateClusterResponse + var r DisableOutOfBandManagementForClusterResponse if err := json.Unmarshal(resp, &r); err != nil { return nil, err } + + // If we have a async client, we need to wait for the async result + if s.cs.async { + b, err := s.cs.GetAsyncJobResult(r.JobID, s.cs.timeout) + if err != nil { + if err == AsyncTimeoutErr { + return &r, err + } + return nil, err + } + + b, err = getRawValue(b) + if err != nil { + return nil, err + } + + if err := json.Unmarshal(b, &r); err != nil { + return nil, err + } + } + return &r, nil } -type UpdateClusterResponse struct { - Allocationstate string `json:"allocationstate,omitempty"` - Capacity []struct { - Capacitytotal int64 `json:"capacitytotal,omitempty"` - Capacityused int64 `json:"capacityused,omitempty"` - Clusterid string `json:"clusterid,omitempty"` - Clustername string `json:"clustername,omitempty"` - Percentused string `json:"percentused,omitempty"` - Podid string `json:"podid,omitempty"` - Podname string `json:"podname,omitempty"` - Type int `json:"type,omitempty"` - Zoneid string `json:"zoneid,omitempty"` - Zonename string `json:"zonename,omitempty"` - } `json:"capacity,omitempty"` - Clustertype string `json:"clustertype,omitempty"` - Cpuovercommitratio string `json:"cpuovercommitratio,omitempty"` - Hypervisortype string `json:"hypervisortype,omitempty"` - Id string `json:"id,omitempty"` - Managedstate string `json:"managedstate,omitempty"` - Memoryovercommitratio string `json:"memoryovercommitratio,omitempty"` - Name string `json:"name,omitempty"` - Ovm3vip string `json:"ovm3vip,omitempty"` - Podid string `json:"podid,omitempty"` - Podname string `json:"podname,omitempty"` - Zoneid string `json:"zoneid,omitempty"` - Zonename string `json:"zonename,omitempty"` +type DisableOutOfBandManagementForClusterResponse struct { + JobID string `json:"jobid"` + Action string `json:"action"` + Address string `json:"address"` + Description string `json:"description"` + Driver string `json:"driver"` + Enabled bool `json:"enabled"` + Hostid string `json:"hostid"` + Password string `json:"password"` + Port string `json:"port"` + Powerstate string `json:"powerstate"` + Status bool `json:"status"` + Username string `json:"username"` +} + +type EnableOutOfBandManagementForClusterParams struct { + p map[string]interface{} +} + +func (p *EnableOutOfBandManagementForClusterParams) toURLValues() url.Values { + u := url.Values{} + if p.p == nil { + return u + } + if v, found := p.p["clusterid"]; found { + u.Set("clusterid", v.(string)) + } + return u +} + +func (p *EnableOutOfBandManagementForClusterParams) SetClusterid(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["clusterid"] = v + return +} + +// You should always use this function to get a new EnableOutOfBandManagementForClusterParams instance, +// as then you are sure you have configured all required params +func (s *ClusterService) NewEnableOutOfBandManagementForClusterParams(clusterid string) *EnableOutOfBandManagementForClusterParams { + p := &EnableOutOfBandManagementForClusterParams{} + p.p = make(map[string]interface{}) + p.p["clusterid"] = clusterid + return p +} + +// Enables out-of-band management for a cluster +func (s *ClusterService) EnableOutOfBandManagementForCluster(p *EnableOutOfBandManagementForClusterParams) (*EnableOutOfBandManagementForClusterResponse, error) { + resp, err := s.cs.newRequest("enableOutOfBandManagementForCluster", p.toURLValues()) + if err != nil { + return nil, err + } + + var r EnableOutOfBandManagementForClusterResponse + if err := json.Unmarshal(resp, &r); err != nil { + return nil, err + } + + // If we have a async client, we need to wait for the async result + if s.cs.async { + b, err := s.cs.GetAsyncJobResult(r.JobID, s.cs.timeout) + if err != nil { + if err == AsyncTimeoutErr { + return &r, err + } + return nil, err + } + + b, err = getRawValue(b) + if err != nil { + return nil, err + } + + if err := json.Unmarshal(b, &r); err != nil { + return nil, err + } + } + + return &r, nil +} + +type EnableOutOfBandManagementForClusterResponse struct { + JobID string `json:"jobid"` + Action string `json:"action"` + Address string `json:"address"` + Description string `json:"description"` + Driver string `json:"driver"` + Enabled bool `json:"enabled"` + Hostid string `json:"hostid"` + Password string `json:"password"` + Port string `json:"port"` + Powerstate string `json:"powerstate"` + Status bool `json:"status"` + Username string `json:"username"` } type ListClustersParams struct { @@ -642,7 +803,7 @@ func (s *ClusterService) GetClusterID(name string, opts ...OptionFunc) (string, p.p["name"] = name - for _, fn := range opts { + for _, fn := range append(s.cs.options, opts...) { if err := fn(s.cs, p); err != nil { return "", -1, err } @@ -692,7 +853,7 @@ func (s *ClusterService) GetClusterByID(id string, opts ...OptionFunc) (*Cluster p.p["id"] = id - for _, fn := range opts { + for _, fn := range append(s.cs.options, opts...) { if err := fn(s.cs, p); err != nil { return nil, -1, err } @@ -729,6 +890,7 @@ func (s *ClusterService) ListClusters(p *ListClustersParams) (*ListClustersRespo if err := json.Unmarshal(resp, &r); err != nil { return nil, err } + return &r, nil } @@ -738,197 +900,36 @@ type ListClustersResponse struct { } type Cluster struct { - Allocationstate string `json:"allocationstate,omitempty"` - Capacity []struct { - Capacitytotal int64 `json:"capacitytotal,omitempty"` - Capacityused int64 `json:"capacityused,omitempty"` - Clusterid string `json:"clusterid,omitempty"` - Clustername string `json:"clustername,omitempty"` - Percentused string `json:"percentused,omitempty"` - Podid string `json:"podid,omitempty"` - Podname string `json:"podname,omitempty"` - Type int `json:"type,omitempty"` - Zoneid string `json:"zoneid,omitempty"` - Zonename string `json:"zonename,omitempty"` - } `json:"capacity,omitempty"` - Clustertype string `json:"clustertype,omitempty"` - Cpuovercommitratio string `json:"cpuovercommitratio,omitempty"` - Hypervisortype string `json:"hypervisortype,omitempty"` - Id string `json:"id,omitempty"` - Managedstate string `json:"managedstate,omitempty"` - Memoryovercommitratio string `json:"memoryovercommitratio,omitempty"` - Name string `json:"name,omitempty"` - Ovm3vip string `json:"ovm3vip,omitempty"` - Podid string `json:"podid,omitempty"` - Podname string `json:"podname,omitempty"` - Zoneid string `json:"zoneid,omitempty"` - Zonename string `json:"zonename,omitempty"` + Allocationstate string `json:"allocationstate"` + Capacity []ClusterCapacity `json:"capacity"` + Clustertype string `json:"clustertype"` + Cpuovercommitratio string `json:"cpuovercommitratio"` + Hypervisortype string `json:"hypervisortype"` + Id string `json:"id"` + Managedstate string `json:"managedstate"` + Memoryovercommitratio string `json:"memoryovercommitratio"` + Name string `json:"name"` + Ovm3vip string `json:"ovm3vip"` + Podid string `json:"podid"` + Podname string `json:"podname"` + Resourcedetails map[string]string `json:"resourcedetails"` + Zoneid string `json:"zoneid"` + Zonename string `json:"zonename"` } -type DedicateClusterParams struct { - p map[string]interface{} -} - -func (p *DedicateClusterParams) toURLValues() url.Values { - u := url.Values{} - if p.p == nil { - return u - } - if v, found := p.p["account"]; found { - u.Set("account", v.(string)) - } - if v, found := p.p["clusterid"]; found { - u.Set("clusterid", v.(string)) - } - if v, found := p.p["domainid"]; found { - u.Set("domainid", v.(string)) - } - return u -} - -func (p *DedicateClusterParams) SetAccount(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["account"] = v - return -} - -func (p *DedicateClusterParams) SetClusterid(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["clusterid"] = v - return -} - -func (p *DedicateClusterParams) SetDomainid(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["domainid"] = v - return -} - -// You should always use this function to get a new DedicateClusterParams instance, -// as then you are sure you have configured all required params -func (s *ClusterService) NewDedicateClusterParams(clusterid string, domainid string) *DedicateClusterParams { - p := &DedicateClusterParams{} - p.p = make(map[string]interface{}) - p.p["clusterid"] = clusterid - p.p["domainid"] = domainid - return p -} - -// Dedicate an existing cluster -func (s *ClusterService) DedicateCluster(p *DedicateClusterParams) (*DedicateClusterResponse, error) { - resp, err := s.cs.newRequest("dedicateCluster", p.toURLValues()) - if err != nil { - return nil, err - } - - var r DedicateClusterResponse - if err := json.Unmarshal(resp, &r); err != nil { - return nil, err - } - - // If we have a async client, we need to wait for the async result - if s.cs.async { - b, err := s.cs.GetAsyncJobResult(r.JobID, s.cs.timeout) - if err != nil { - if err == AsyncTimeoutErr { - return &r, err - } - return nil, err - } - - b, err = getRawValue(b) - if err != nil { - return nil, err - } - - if err := json.Unmarshal(b, &r); err != nil { - return nil, err - } - } - return &r, nil -} - -type DedicateClusterResponse struct { - JobID string `json:"jobid,omitempty"` - Accountid string `json:"accountid,omitempty"` - Affinitygroupid string `json:"affinitygroupid,omitempty"` - Clusterid string `json:"clusterid,omitempty"` - Clustername string `json:"clustername,omitempty"` - Domainid string `json:"domainid,omitempty"` - Id string `json:"id,omitempty"` -} - -type ReleaseDedicatedClusterParams struct { - p map[string]interface{} -} - -func (p *ReleaseDedicatedClusterParams) toURLValues() url.Values { - u := url.Values{} - if p.p == nil { - return u - } - if v, found := p.p["clusterid"]; found { - u.Set("clusterid", v.(string)) - } - return u -} - -func (p *ReleaseDedicatedClusterParams) SetClusterid(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["clusterid"] = v - return -} - -// You should always use this function to get a new ReleaseDedicatedClusterParams instance, -// as then you are sure you have configured all required params -func (s *ClusterService) NewReleaseDedicatedClusterParams(clusterid string) *ReleaseDedicatedClusterParams { - p := &ReleaseDedicatedClusterParams{} - p.p = make(map[string]interface{}) - p.p["clusterid"] = clusterid - return p -} - -// Release the dedication for cluster -func (s *ClusterService) ReleaseDedicatedCluster(p *ReleaseDedicatedClusterParams) (*ReleaseDedicatedClusterResponse, error) { - resp, err := s.cs.newRequest("releaseDedicatedCluster", p.toURLValues()) - if err != nil { - return nil, err - } - - var r ReleaseDedicatedClusterResponse - if err := json.Unmarshal(resp, &r); err != nil { - return nil, err - } - - // If we have a async client, we need to wait for the async result - if s.cs.async { - b, err := s.cs.GetAsyncJobResult(r.JobID, s.cs.timeout) - if err != nil { - if err == AsyncTimeoutErr { - return &r, err - } - return nil, err - } - - if err := json.Unmarshal(b, &r); err != nil { - return nil, err - } - } - return &r, nil -} - -type ReleaseDedicatedClusterResponse struct { - JobID string `json:"jobid,omitempty"` - Displaytext string `json:"displaytext,omitempty"` - Success bool `json:"success,omitempty"` +type ClusterCapacity struct { + Capacityallocated int64 `json:"capacityallocated"` + Capacitytotal int64 `json:"capacitytotal"` + Capacityused int64 `json:"capacityused"` + Clusterid string `json:"clusterid"` + Clustername string `json:"clustername"` + Name string `json:"name"` + Percentused string `json:"percentused"` + Podid string `json:"podid"` + Podname string `json:"podname"` + Type int `json:"type"` + Zoneid string `json:"zoneid"` + Zonename string `json:"zonename"` } type ListDedicatedClustersParams struct { @@ -1041,6 +1042,7 @@ func (s *ClusterService) ListDedicatedClusters(p *ListDedicatedClustersParams) ( if err := json.Unmarshal(resp, &r); err != nil { return nil, err } + return &r, nil } @@ -1050,10 +1052,213 @@ type ListDedicatedClustersResponse struct { } type DedicatedCluster struct { - Accountid string `json:"accountid,omitempty"` - Affinitygroupid string `json:"affinitygroupid,omitempty"` - Clusterid string `json:"clusterid,omitempty"` - Clustername string `json:"clustername,omitempty"` - Domainid string `json:"domainid,omitempty"` - Id string `json:"id,omitempty"` + Accountid string `json:"accountid"` + Affinitygroupid string `json:"affinitygroupid"` + Clusterid string `json:"clusterid"` + Clustername string `json:"clustername"` + Domainid string `json:"domainid"` + Id string `json:"id"` +} + +type ReleaseDedicatedClusterParams struct { + p map[string]interface{} +} + +func (p *ReleaseDedicatedClusterParams) toURLValues() url.Values { + u := url.Values{} + if p.p == nil { + return u + } + if v, found := p.p["clusterid"]; found { + u.Set("clusterid", v.(string)) + } + return u +} + +func (p *ReleaseDedicatedClusterParams) SetClusterid(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["clusterid"] = v + return +} + +// You should always use this function to get a new ReleaseDedicatedClusterParams instance, +// as then you are sure you have configured all required params +func (s *ClusterService) NewReleaseDedicatedClusterParams(clusterid string) *ReleaseDedicatedClusterParams { + p := &ReleaseDedicatedClusterParams{} + p.p = make(map[string]interface{}) + p.p["clusterid"] = clusterid + return p +} + +// Release the dedication for cluster +func (s *ClusterService) ReleaseDedicatedCluster(p *ReleaseDedicatedClusterParams) (*ReleaseDedicatedClusterResponse, error) { + resp, err := s.cs.newRequest("releaseDedicatedCluster", p.toURLValues()) + if err != nil { + return nil, err + } + + var r ReleaseDedicatedClusterResponse + if err := json.Unmarshal(resp, &r); err != nil { + return nil, err + } + + // If we have a async client, we need to wait for the async result + if s.cs.async { + b, err := s.cs.GetAsyncJobResult(r.JobID, s.cs.timeout) + if err != nil { + if err == AsyncTimeoutErr { + return &r, err + } + return nil, err + } + + if err := json.Unmarshal(b, &r); err != nil { + return nil, err + } + } + + return &r, nil +} + +type ReleaseDedicatedClusterResponse struct { + JobID string `json:"jobid"` + Displaytext string `json:"displaytext"` + Success bool `json:"success"` +} + +type UpdateClusterParams struct { + p map[string]interface{} +} + +func (p *UpdateClusterParams) toURLValues() url.Values { + u := url.Values{} + if p.p == nil { + return u + } + if v, found := p.p["allocationstate"]; found { + u.Set("allocationstate", v.(string)) + } + if v, found := p.p["clustername"]; found { + u.Set("clustername", v.(string)) + } + if v, found := p.p["clustertype"]; found { + u.Set("clustertype", v.(string)) + } + if v, found := p.p["hypervisor"]; found { + u.Set("hypervisor", v.(string)) + } + if v, found := p.p["id"]; found { + u.Set("id", v.(string)) + } + if v, found := p.p["managedstate"]; found { + u.Set("managedstate", v.(string)) + } + return u +} + +func (p *UpdateClusterParams) SetAllocationstate(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["allocationstate"] = v + return +} + +func (p *UpdateClusterParams) SetClustername(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["clustername"] = v + return +} + +func (p *UpdateClusterParams) SetClustertype(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["clustertype"] = v + return +} + +func (p *UpdateClusterParams) SetHypervisor(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["hypervisor"] = v + return +} + +func (p *UpdateClusterParams) SetId(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["id"] = v + return +} + +func (p *UpdateClusterParams) SetManagedstate(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["managedstate"] = v + return +} + +// You should always use this function to get a new UpdateClusterParams instance, +// as then you are sure you have configured all required params +func (s *ClusterService) NewUpdateClusterParams(id string) *UpdateClusterParams { + p := &UpdateClusterParams{} + p.p = make(map[string]interface{}) + p.p["id"] = id + return p +} + +// Updates an existing cluster +func (s *ClusterService) UpdateCluster(p *UpdateClusterParams) (*UpdateClusterResponse, error) { + resp, err := s.cs.newRequest("updateCluster", p.toURLValues()) + if err != nil { + return nil, err + } + + var r UpdateClusterResponse + if err := json.Unmarshal(resp, &r); err != nil { + return nil, err + } + + return &r, nil +} + +type UpdateClusterResponse struct { + Allocationstate string `json:"allocationstate"` + Capacity []UpdateClusterResponseCapacity `json:"capacity"` + Clustertype string `json:"clustertype"` + Cpuovercommitratio string `json:"cpuovercommitratio"` + Hypervisortype string `json:"hypervisortype"` + Id string `json:"id"` + Managedstate string `json:"managedstate"` + Memoryovercommitratio string `json:"memoryovercommitratio"` + Name string `json:"name"` + Ovm3vip string `json:"ovm3vip"` + Podid string `json:"podid"` + Podname string `json:"podname"` + Resourcedetails map[string]string `json:"resourcedetails"` + Zoneid string `json:"zoneid"` + Zonename string `json:"zonename"` +} + +type UpdateClusterResponseCapacity struct { + Capacityallocated int64 `json:"capacityallocated"` + Capacitytotal int64 `json:"capacitytotal"` + Capacityused int64 `json:"capacityused"` + Clusterid string `json:"clusterid"` + Clustername string `json:"clustername"` + Name string `json:"name"` + Percentused string `json:"percentused"` + Podid string `json:"podid"` + Podname string `json:"podname"` + Type int `json:"type"` + Zoneid string `json:"zoneid"` + Zonename string `json:"zonename"` } diff --git a/vendor/github.com/xanzy/go-cloudstack/cloudstack/ConfigurationService.go b/vendor/github.com/xanzy/go-cloudstack/cloudstack/ConfigurationService.go index b4a6a7b1b..2f87a3cbe 100644 --- a/vendor/github.com/xanzy/go-cloudstack/cloudstack/ConfigurationService.go +++ b/vendor/github.com/xanzy/go-cloudstack/cloudstack/ConfigurationService.go @@ -1,5 +1,5 @@ // -// Copyright 2016, Sander van Harmelen +// Copyright 2018, Sander van Harmelen // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -22,114 +22,62 @@ import ( "strconv" ) -type UpdateConfigurationParams struct { +type ListCapabilitiesParams struct { p map[string]interface{} } -func (p *UpdateConfigurationParams) toURLValues() url.Values { +func (p *ListCapabilitiesParams) toURLValues() url.Values { u := url.Values{} if p.p == nil { return u } - if v, found := p.p["accountid"]; found { - u.Set("accountid", v.(string)) - } - if v, found := p.p["clusterid"]; found { - u.Set("clusterid", v.(string)) - } - if v, found := p.p["name"]; found { - u.Set("name", v.(string)) - } - if v, found := p.p["storageid"]; found { - u.Set("storageid", v.(string)) - } - if v, found := p.p["value"]; found { - u.Set("value", v.(string)) - } - if v, found := p.p["zoneid"]; found { - u.Set("zoneid", v.(string)) - } return u } -func (p *UpdateConfigurationParams) SetAccountid(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["accountid"] = v - return -} - -func (p *UpdateConfigurationParams) SetClusterid(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["clusterid"] = v - return -} - -func (p *UpdateConfigurationParams) SetName(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["name"] = v - return -} - -func (p *UpdateConfigurationParams) SetStorageid(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["storageid"] = v - return -} - -func (p *UpdateConfigurationParams) SetValue(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["value"] = v - return -} - -func (p *UpdateConfigurationParams) SetZoneid(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["zoneid"] = v - return -} - -// You should always use this function to get a new UpdateConfigurationParams instance, +// You should always use this function to get a new ListCapabilitiesParams instance, // as then you are sure you have configured all required params -func (s *ConfigurationService) NewUpdateConfigurationParams(name string) *UpdateConfigurationParams { - p := &UpdateConfigurationParams{} +func (s *ConfigurationService) NewListCapabilitiesParams() *ListCapabilitiesParams { + p := &ListCapabilitiesParams{} p.p = make(map[string]interface{}) - p.p["name"] = name return p } -// Updates a configuration. -func (s *ConfigurationService) UpdateConfiguration(p *UpdateConfigurationParams) (*UpdateConfigurationResponse, error) { - resp, err := s.cs.newRequest("updateConfiguration", p.toURLValues()) +// Lists capabilities +func (s *ConfigurationService) ListCapabilities(p *ListCapabilitiesParams) (*ListCapabilitiesResponse, error) { + resp, err := s.cs.newRequest("listCapabilities", p.toURLValues()) if err != nil { return nil, err } - var r UpdateConfigurationResponse + var r ListCapabilitiesResponse if err := json.Unmarshal(resp, &r); err != nil { return nil, err } + return &r, nil } -type UpdateConfigurationResponse struct { - Category string `json:"category,omitempty"` - Description string `json:"description,omitempty"` - Id int64 `json:"id,omitempty"` - Name string `json:"name,omitempty"` - Scope string `json:"scope,omitempty"` - Value string `json:"value,omitempty"` +type ListCapabilitiesResponse struct { + Count int `json:"count"` + Capabilities []*Capability `json:"capability"` +} + +type Capability struct { + Allowusercreateprojects bool `json:"allowusercreateprojects"` + Allowuserexpungerecovervm bool `json:"allowuserexpungerecovervm"` + Allowuserviewdestroyedvm bool `json:"allowuserviewdestroyedvm"` + Apilimitinterval int `json:"apilimitinterval"` + Apilimitmax int `json:"apilimitmax"` + Cloudstackversion string `json:"cloudstackversion"` + Customdiskofferingmaxsize int64 `json:"customdiskofferingmaxsize"` + Customdiskofferingminsize int64 `json:"customdiskofferingminsize"` + Dynamicrolesenabled bool `json:"dynamicrolesenabled"` + Kvmsnapshotenabled bool `json:"kvmsnapshotenabled"` + Projectinviterequired bool `json:"projectinviterequired"` + Regionsecondaryenabled bool `json:"regionsecondaryenabled"` + Securitygroupsenabled bool `json:"securitygroupsenabled"` + SupportELB string `json:"supportELB"` + Userpublictemplateenabled bool `json:"userpublictemplateenabled"` } type ListConfigurationsParams struct { @@ -150,6 +98,12 @@ func (p *ListConfigurationsParams) toURLValues() url.Values { if v, found := p.p["clusterid"]; found { u.Set("clusterid", v.(string)) } + if v, found := p.p["domainid"]; found { + u.Set("domainid", v.(string)) + } + if v, found := p.p["imagestoreuuid"]; found { + u.Set("imagestoreuuid", v.(string)) + } if v, found := p.p["keyword"]; found { u.Set("keyword", v.(string)) } @@ -197,6 +151,22 @@ func (p *ListConfigurationsParams) SetClusterid(v string) { return } +func (p *ListConfigurationsParams) SetDomainid(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["domainid"] = v + return +} + +func (p *ListConfigurationsParams) SetImagestoreuuid(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["imagestoreuuid"] = v + return +} + func (p *ListConfigurationsParams) SetKeyword(v string) { if p.p == nil { p.p = make(map[string]interface{}) @@ -264,6 +234,7 @@ func (s *ConfigurationService) ListConfigurations(p *ListConfigurationsParams) ( if err := json.Unmarshal(resp, &r); err != nil { return nil, err } + return &r, nil } @@ -273,68 +244,12 @@ type ListConfigurationsResponse struct { } type Configuration struct { - Category string `json:"category,omitempty"` - Description string `json:"description,omitempty"` - Id int64 `json:"id,omitempty"` - Name string `json:"name,omitempty"` - Scope string `json:"scope,omitempty"` - Value string `json:"value,omitempty"` -} - -type ListCapabilitiesParams struct { - p map[string]interface{} -} - -func (p *ListCapabilitiesParams) toURLValues() url.Values { - u := url.Values{} - if p.p == nil { - return u - } - return u -} - -// You should always use this function to get a new ListCapabilitiesParams instance, -// as then you are sure you have configured all required params -func (s *ConfigurationService) NewListCapabilitiesParams() *ListCapabilitiesParams { - p := &ListCapabilitiesParams{} - p.p = make(map[string]interface{}) - return p -} - -// Lists capabilities -func (s *ConfigurationService) ListCapabilities(p *ListCapabilitiesParams) (*ListCapabilitiesResponse, error) { - resp, err := s.cs.newRequest("listCapabilities", p.toURLValues()) - if err != nil { - return nil, err - } - - var r ListCapabilitiesResponse - if err := json.Unmarshal(resp, &r); err != nil { - return nil, err - } - return &r, nil -} - -type ListCapabilitiesResponse struct { - Count int `json:"count"` - Capabilities []*Capability `json:"capability"` -} - -type Capability struct { - Allowusercreateprojects bool `json:"allowusercreateprojects,omitempty"` - Allowuserexpungerecovervm bool `json:"allowuserexpungerecovervm,omitempty"` - Allowuserviewdestroyedvm bool `json:"allowuserviewdestroyedvm,omitempty"` - Apilimitinterval int `json:"apilimitinterval,omitempty"` - Apilimitmax int `json:"apilimitmax,omitempty"` - Cloudstackversion string `json:"cloudstackversion,omitempty"` - Customdiskofferingmaxsize int64 `json:"customdiskofferingmaxsize,omitempty"` - Customdiskofferingminsize int64 `json:"customdiskofferingminsize,omitempty"` - Kvmsnapshotenabled bool `json:"kvmsnapshotenabled,omitempty"` - Projectinviterequired bool `json:"projectinviterequired,omitempty"` - Regionsecondaryenabled bool `json:"regionsecondaryenabled,omitempty"` - Securitygroupsenabled bool `json:"securitygroupsenabled,omitempty"` - SupportELB string `json:"supportELB,omitempty"` - Userpublictemplateenabled bool `json:"userpublictemplateenabled,omitempty"` + Category string `json:"category"` + Description string `json:"description"` + Id int64 `json:"id"` + Name string `json:"name"` + Scope string `json:"scope"` + Value string `json:"value"` } type ListDeploymentPlannersParams struct { @@ -403,6 +318,7 @@ func (s *ConfigurationService) ListDeploymentPlanners(p *ListDeploymentPlannersP if err := json.Unmarshal(resp, &r); err != nil { return nil, err } + return &r, nil } @@ -412,222 +328,138 @@ type ListDeploymentPlannersResponse struct { } type DeploymentPlanner struct { - Name string `json:"name,omitempty"` + Name string `json:"name"` } -type ListLdapConfigurationsParams struct { +type UpdateConfigurationParams struct { p map[string]interface{} } -func (p *ListLdapConfigurationsParams) toURLValues() url.Values { +func (p *UpdateConfigurationParams) toURLValues() url.Values { u := url.Values{} if p.p == nil { return u } - if v, found := p.p["hostname"]; found { - u.Set("hostname", v.(string)) + if v, found := p.p["accountid"]; found { + u.Set("accountid", v.(string)) } - if v, found := p.p["keyword"]; found { - u.Set("keyword", v.(string)) + if v, found := p.p["clusterid"]; found { + u.Set("clusterid", v.(string)) } - if v, found := p.p["page"]; found { - vv := strconv.Itoa(v.(int)) - u.Set("page", vv) + if v, found := p.p["domainid"]; found { + u.Set("domainid", v.(string)) } - if v, found := p.p["pagesize"]; found { - vv := strconv.Itoa(v.(int)) - u.Set("pagesize", vv) + if v, found := p.p["imagestoreuuid"]; found { + u.Set("imagestoreuuid", v.(string)) } - if v, found := p.p["port"]; found { - vv := strconv.Itoa(v.(int)) - u.Set("port", vv) + if v, found := p.p["name"]; found { + u.Set("name", v.(string)) + } + if v, found := p.p["storageid"]; found { + u.Set("storageid", v.(string)) + } + if v, found := p.p["value"]; found { + u.Set("value", v.(string)) + } + if v, found := p.p["zoneid"]; found { + u.Set("zoneid", v.(string)) } return u } -func (p *ListLdapConfigurationsParams) SetHostname(v string) { +func (p *UpdateConfigurationParams) SetAccountid(v string) { if p.p == nil { p.p = make(map[string]interface{}) } - p.p["hostname"] = v + p.p["accountid"] = v return } -func (p *ListLdapConfigurationsParams) SetKeyword(v string) { +func (p *UpdateConfigurationParams) SetClusterid(v string) { if p.p == nil { p.p = make(map[string]interface{}) } - p.p["keyword"] = v + p.p["clusterid"] = v return } -func (p *ListLdapConfigurationsParams) SetPage(v int) { +func (p *UpdateConfigurationParams) SetDomainid(v string) { if p.p == nil { p.p = make(map[string]interface{}) } - p.p["page"] = v + p.p["domainid"] = v return } -func (p *ListLdapConfigurationsParams) SetPagesize(v int) { +func (p *UpdateConfigurationParams) SetImagestoreuuid(v string) { if p.p == nil { p.p = make(map[string]interface{}) } - p.p["pagesize"] = v + p.p["imagestoreuuid"] = v return } -func (p *ListLdapConfigurationsParams) SetPort(v int) { +func (p *UpdateConfigurationParams) SetName(v string) { if p.p == nil { p.p = make(map[string]interface{}) } - p.p["port"] = v + p.p["name"] = v return } -// You should always use this function to get a new ListLdapConfigurationsParams instance, +func (p *UpdateConfigurationParams) SetStorageid(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["storageid"] = v + return +} + +func (p *UpdateConfigurationParams) SetValue(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["value"] = v + return +} + +func (p *UpdateConfigurationParams) SetZoneid(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["zoneid"] = v + return +} + +// You should always use this function to get a new UpdateConfigurationParams instance, // as then you are sure you have configured all required params -func (s *ConfigurationService) NewListLdapConfigurationsParams() *ListLdapConfigurationsParams { - p := &ListLdapConfigurationsParams{} +func (s *ConfigurationService) NewUpdateConfigurationParams(name string) *UpdateConfigurationParams { + p := &UpdateConfigurationParams{} p.p = make(map[string]interface{}) + p.p["name"] = name return p } -// Lists all LDAP configurations -func (s *ConfigurationService) ListLdapConfigurations(p *ListLdapConfigurationsParams) (*ListLdapConfigurationsResponse, error) { - resp, err := s.cs.newRequest("listLdapConfigurations", p.toURLValues()) +// Updates a configuration. +func (s *ConfigurationService) UpdateConfiguration(p *UpdateConfigurationParams) (*UpdateConfigurationResponse, error) { + resp, err := s.cs.newRequest("updateConfiguration", p.toURLValues()) if err != nil { return nil, err } - var r ListLdapConfigurationsResponse + var r UpdateConfigurationResponse if err := json.Unmarshal(resp, &r); err != nil { return nil, err } + return &r, nil } -type ListLdapConfigurationsResponse struct { - Count int `json:"count"` - LdapConfigurations []*LdapConfiguration `json:"ldapconfiguration"` -} - -type LdapConfiguration struct { - Hostname string `json:"hostname,omitempty"` - Port int `json:"port,omitempty"` -} - -type AddLdapConfigurationParams struct { - p map[string]interface{} -} - -func (p *AddLdapConfigurationParams) toURLValues() url.Values { - u := url.Values{} - if p.p == nil { - return u - } - if v, found := p.p["hostname"]; found { - u.Set("hostname", v.(string)) - } - if v, found := p.p["port"]; found { - vv := strconv.Itoa(v.(int)) - u.Set("port", vv) - } - return u -} - -func (p *AddLdapConfigurationParams) SetHostname(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["hostname"] = v - return -} - -func (p *AddLdapConfigurationParams) SetPort(v int) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["port"] = v - return -} - -// You should always use this function to get a new AddLdapConfigurationParams instance, -// as then you are sure you have configured all required params -func (s *ConfigurationService) NewAddLdapConfigurationParams(hostname string, port int) *AddLdapConfigurationParams { - p := &AddLdapConfigurationParams{} - p.p = make(map[string]interface{}) - p.p["hostname"] = hostname - p.p["port"] = port - return p -} - -// Add a new Ldap Configuration -func (s *ConfigurationService) AddLdapConfiguration(p *AddLdapConfigurationParams) (*AddLdapConfigurationResponse, error) { - resp, err := s.cs.newRequest("addLdapConfiguration", p.toURLValues()) - if err != nil { - return nil, err - } - - var r AddLdapConfigurationResponse - if err := json.Unmarshal(resp, &r); err != nil { - return nil, err - } - return &r, nil -} - -type AddLdapConfigurationResponse struct { - Hostname string `json:"hostname,omitempty"` - Port int `json:"port,omitempty"` -} - -type DeleteLdapConfigurationParams struct { - p map[string]interface{} -} - -func (p *DeleteLdapConfigurationParams) toURLValues() url.Values { - u := url.Values{} - if p.p == nil { - return u - } - if v, found := p.p["hostname"]; found { - u.Set("hostname", v.(string)) - } - return u -} - -func (p *DeleteLdapConfigurationParams) SetHostname(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["hostname"] = v - return -} - -// You should always use this function to get a new DeleteLdapConfigurationParams instance, -// as then you are sure you have configured all required params -func (s *ConfigurationService) NewDeleteLdapConfigurationParams(hostname string) *DeleteLdapConfigurationParams { - p := &DeleteLdapConfigurationParams{} - p.p = make(map[string]interface{}) - p.p["hostname"] = hostname - return p -} - -// Remove an Ldap Configuration -func (s *ConfigurationService) DeleteLdapConfiguration(p *DeleteLdapConfigurationParams) (*DeleteLdapConfigurationResponse, error) { - resp, err := s.cs.newRequest("deleteLdapConfiguration", p.toURLValues()) - if err != nil { - return nil, err - } - - var r DeleteLdapConfigurationResponse - if err := json.Unmarshal(resp, &r); err != nil { - return nil, err - } - return &r, nil -} - -type DeleteLdapConfigurationResponse struct { - Hostname string `json:"hostname,omitempty"` - Port int `json:"port,omitempty"` +type UpdateConfigurationResponse struct { + Category string `json:"category"` + Description string `json:"description"` + Id int64 `json:"id"` + Name string `json:"name"` + Scope string `json:"scope"` + Value string `json:"value"` } diff --git a/vendor/github.com/xanzy/go-cloudstack/cloudstack/CustomService.go b/vendor/github.com/xanzy/go-cloudstack/cloudstack/CustomService.go new file mode 100644 index 000000000..5e5c3b487 --- /dev/null +++ b/vendor/github.com/xanzy/go-cloudstack/cloudstack/CustomService.go @@ -0,0 +1,77 @@ +// +// Copyright 2018, Sander van Harmelen +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// + +package cloudstack + +import ( + "encoding/json" + "fmt" + "net/url" + "strconv" + "strings" +) + +type CustomServiceParams struct { + p map[string]interface{} +} + +func (p *CustomServiceParams) toURLValues() url.Values { + u := url.Values{} + if p.p == nil { + return u + } + + for k, v := range p.p { + switch t := v.(type) { + case bool: + u.Set(k, strconv.FormatBool(t)) + case int: + u.Set(k, strconv.Itoa(t)) + case int64: + vv := strconv.FormatInt(t, 10) + u.Set(k, vv) + case string: + u.Set(k, t) + case []string: + u.Set(k, strings.Join(t, ", ")) + case map[string]string: + i := 0 + for kk, vv := range t { + u.Set(fmt.Sprintf("%s[%d].%s", k, i, kk), vv) + i++ + } + } + } + + return u +} + +func (p *CustomServiceParams) SetParam(param string, v interface{}) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p[param] = v + return +} + +func (s *CustomService) CustomRequest(api string, p *CustomServiceParams, result interface{}) error { + resp, err := s.cs.newRequest(api, p.toURLValues()) + if err != nil { + return err + } + + return json.Unmarshal(resp, result) +} diff --git a/vendor/github.com/xanzy/go-cloudstack/cloudstack/DiskOfferingService.go b/vendor/github.com/xanzy/go-cloudstack/cloudstack/DiskOfferingService.go index ee85a07e3..9e529ee16 100644 --- a/vendor/github.com/xanzy/go-cloudstack/cloudstack/DiskOfferingService.go +++ b/vendor/github.com/xanzy/go-cloudstack/cloudstack/DiskOfferingService.go @@ -1,5 +1,5 @@ // -// Copyright 2016, Sander van Harmelen +// Copyright 2018, Sander van Harmelen // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -255,147 +255,32 @@ func (s *DiskOfferingService) CreateDiskOffering(p *CreateDiskOfferingParams) (* if err := json.Unmarshal(resp, &r); err != nil { return nil, err } + return &r, nil } type CreateDiskOfferingResponse struct { - CacheMode string `json:"cacheMode,omitempty"` - Created string `json:"created,omitempty"` - DiskBytesReadRate int64 `json:"diskBytesReadRate,omitempty"` - DiskBytesWriteRate int64 `json:"diskBytesWriteRate,omitempty"` - DiskIopsReadRate int64 `json:"diskIopsReadRate,omitempty"` - DiskIopsWriteRate int64 `json:"diskIopsWriteRate,omitempty"` - Disksize int64 `json:"disksize,omitempty"` - Displayoffering bool `json:"displayoffering,omitempty"` - Displaytext string `json:"displaytext,omitempty"` - Domain string `json:"domain,omitempty"` - Domainid string `json:"domainid,omitempty"` - Hypervisorsnapshotreserve int `json:"hypervisorsnapshotreserve,omitempty"` - Id string `json:"id,omitempty"` - Iscustomized bool `json:"iscustomized,omitempty"` - Iscustomizediops bool `json:"iscustomizediops,omitempty"` - Maxiops int64 `json:"maxiops,omitempty"` - Miniops int64 `json:"miniops,omitempty"` - Name string `json:"name,omitempty"` - Provisioningtype string `json:"provisioningtype,omitempty"` - Storagetype string `json:"storagetype,omitempty"` - Tags string `json:"tags,omitempty"` -} - -type UpdateDiskOfferingParams struct { - p map[string]interface{} -} - -func (p *UpdateDiskOfferingParams) toURLValues() url.Values { - u := url.Values{} - if p.p == nil { - return u - } - if v, found := p.p["displayoffering"]; found { - vv := strconv.FormatBool(v.(bool)) - u.Set("displayoffering", vv) - } - if v, found := p.p["displaytext"]; found { - u.Set("displaytext", v.(string)) - } - if v, found := p.p["id"]; found { - u.Set("id", v.(string)) - } - if v, found := p.p["name"]; found { - u.Set("name", v.(string)) - } - if v, found := p.p["sortkey"]; found { - vv := strconv.Itoa(v.(int)) - u.Set("sortkey", vv) - } - return u -} - -func (p *UpdateDiskOfferingParams) SetDisplayoffering(v bool) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["displayoffering"] = v - return -} - -func (p *UpdateDiskOfferingParams) SetDisplaytext(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["displaytext"] = v - return -} - -func (p *UpdateDiskOfferingParams) SetId(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["id"] = v - return -} - -func (p *UpdateDiskOfferingParams) SetName(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["name"] = v - return -} - -func (p *UpdateDiskOfferingParams) SetSortkey(v int) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["sortkey"] = v - return -} - -// You should always use this function to get a new UpdateDiskOfferingParams instance, -// as then you are sure you have configured all required params -func (s *DiskOfferingService) NewUpdateDiskOfferingParams(id string) *UpdateDiskOfferingParams { - p := &UpdateDiskOfferingParams{} - p.p = make(map[string]interface{}) - p.p["id"] = id - return p -} - -// Updates a disk offering. -func (s *DiskOfferingService) UpdateDiskOffering(p *UpdateDiskOfferingParams) (*UpdateDiskOfferingResponse, error) { - resp, err := s.cs.newRequest("updateDiskOffering", p.toURLValues()) - if err != nil { - return nil, err - } - - var r UpdateDiskOfferingResponse - if err := json.Unmarshal(resp, &r); err != nil { - return nil, err - } - return &r, nil -} - -type UpdateDiskOfferingResponse struct { - CacheMode string `json:"cacheMode,omitempty"` - Created string `json:"created,omitempty"` - DiskBytesReadRate int64 `json:"diskBytesReadRate,omitempty"` - DiskBytesWriteRate int64 `json:"diskBytesWriteRate,omitempty"` - DiskIopsReadRate int64 `json:"diskIopsReadRate,omitempty"` - DiskIopsWriteRate int64 `json:"diskIopsWriteRate,omitempty"` - Disksize int64 `json:"disksize,omitempty"` - Displayoffering bool `json:"displayoffering,omitempty"` - Displaytext string `json:"displaytext,omitempty"` - Domain string `json:"domain,omitempty"` - Domainid string `json:"domainid,omitempty"` - Hypervisorsnapshotreserve int `json:"hypervisorsnapshotreserve,omitempty"` - Id string `json:"id,omitempty"` - Iscustomized bool `json:"iscustomized,omitempty"` - Iscustomizediops bool `json:"iscustomizediops,omitempty"` - Maxiops int64 `json:"maxiops,omitempty"` - Miniops int64 `json:"miniops,omitempty"` - Name string `json:"name,omitempty"` - Provisioningtype string `json:"provisioningtype,omitempty"` - Storagetype string `json:"storagetype,omitempty"` - Tags string `json:"tags,omitempty"` + CacheMode string `json:"cacheMode"` + Created string `json:"created"` + DiskBytesReadRate int64 `json:"diskBytesReadRate"` + DiskBytesWriteRate int64 `json:"diskBytesWriteRate"` + DiskIopsReadRate int64 `json:"diskIopsReadRate"` + DiskIopsWriteRate int64 `json:"diskIopsWriteRate"` + Disksize int64 `json:"disksize"` + Displayoffering bool `json:"displayoffering"` + Displaytext string `json:"displaytext"` + Domain string `json:"domain"` + Domainid string `json:"domainid"` + Hypervisorsnapshotreserve int `json:"hypervisorsnapshotreserve"` + Id string `json:"id"` + Iscustomized bool `json:"iscustomized"` + Iscustomizediops bool `json:"iscustomizediops"` + Maxiops int64 `json:"maxiops"` + Miniops int64 `json:"miniops"` + Name string `json:"name"` + Provisioningtype string `json:"provisioningtype"` + Storagetype string `json:"storagetype"` + Tags string `json:"tags"` } type DeleteDiskOfferingParams struct { @@ -441,12 +326,32 @@ func (s *DiskOfferingService) DeleteDiskOffering(p *DeleteDiskOfferingParams) (* if err := json.Unmarshal(resp, &r); err != nil { return nil, err } + return &r, nil } type DeleteDiskOfferingResponse struct { - Displaytext string `json:"displaytext,omitempty"` - Success string `json:"success,omitempty"` + Displaytext string `json:"displaytext"` + Success bool `json:"success"` +} + +func (r *DeleteDiskOfferingResponse) UnmarshalJSON(b []byte) error { + var m map[string]interface{} + err := json.Unmarshal(b, &m) + if err != nil { + return err + } + + if success, ok := m["success"].(string); ok { + m["success"] = success == "true" + b, err = json.Marshal(m) + if err != nil { + return err + } + } + + type alias DeleteDiskOfferingResponse + return json.Unmarshal(b, (*alias)(r)) } type ListDiskOfferingsParams struct { @@ -568,7 +473,7 @@ func (s *DiskOfferingService) GetDiskOfferingID(name string, opts ...OptionFunc) p.p["name"] = name - for _, fn := range opts { + for _, fn := range append(s.cs.options, opts...) { if err := fn(s.cs, p); err != nil { return "", -1, err } @@ -618,7 +523,7 @@ func (s *DiskOfferingService) GetDiskOfferingByID(id string, opts ...OptionFunc) p.p["id"] = id - for _, fn := range opts { + for _, fn := range append(s.cs.options, opts...) { if err := fn(s.cs, p); err != nil { return nil, -1, err } @@ -655,6 +560,7 @@ func (s *DiskOfferingService) ListDiskOfferings(p *ListDiskOfferingsParams) (*Li if err := json.Unmarshal(resp, &r); err != nil { return nil, err } + return &r, nil } @@ -664,25 +570,142 @@ type ListDiskOfferingsResponse struct { } type DiskOffering struct { - CacheMode string `json:"cacheMode,omitempty"` - Created string `json:"created,omitempty"` - DiskBytesReadRate int64 `json:"diskBytesReadRate,omitempty"` - DiskBytesWriteRate int64 `json:"diskBytesWriteRate,omitempty"` - DiskIopsReadRate int64 `json:"diskIopsReadRate,omitempty"` - DiskIopsWriteRate int64 `json:"diskIopsWriteRate,omitempty"` - Disksize int64 `json:"disksize,omitempty"` - Displayoffering bool `json:"displayoffering,omitempty"` - Displaytext string `json:"displaytext,omitempty"` - Domain string `json:"domain,omitempty"` - Domainid string `json:"domainid,omitempty"` - Hypervisorsnapshotreserve int `json:"hypervisorsnapshotreserve,omitempty"` - Id string `json:"id,omitempty"` - Iscustomized bool `json:"iscustomized,omitempty"` - Iscustomizediops bool `json:"iscustomizediops,omitempty"` - Maxiops int64 `json:"maxiops,omitempty"` - Miniops int64 `json:"miniops,omitempty"` - Name string `json:"name,omitempty"` - Provisioningtype string `json:"provisioningtype,omitempty"` - Storagetype string `json:"storagetype,omitempty"` - Tags string `json:"tags,omitempty"` + CacheMode string `json:"cacheMode"` + Created string `json:"created"` + DiskBytesReadRate int64 `json:"diskBytesReadRate"` + DiskBytesWriteRate int64 `json:"diskBytesWriteRate"` + DiskIopsReadRate int64 `json:"diskIopsReadRate"` + DiskIopsWriteRate int64 `json:"diskIopsWriteRate"` + Disksize int64 `json:"disksize"` + Displayoffering bool `json:"displayoffering"` + Displaytext string `json:"displaytext"` + Domain string `json:"domain"` + Domainid string `json:"domainid"` + Hypervisorsnapshotreserve int `json:"hypervisorsnapshotreserve"` + Id string `json:"id"` + Iscustomized bool `json:"iscustomized"` + Iscustomizediops bool `json:"iscustomizediops"` + Maxiops int64 `json:"maxiops"` + Miniops int64 `json:"miniops"` + Name string `json:"name"` + Provisioningtype string `json:"provisioningtype"` + Storagetype string `json:"storagetype"` + Tags string `json:"tags"` +} + +type UpdateDiskOfferingParams struct { + p map[string]interface{} +} + +func (p *UpdateDiskOfferingParams) toURLValues() url.Values { + u := url.Values{} + if p.p == nil { + return u + } + if v, found := p.p["displayoffering"]; found { + vv := strconv.FormatBool(v.(bool)) + u.Set("displayoffering", vv) + } + if v, found := p.p["displaytext"]; found { + u.Set("displaytext", v.(string)) + } + if v, found := p.p["id"]; found { + u.Set("id", v.(string)) + } + if v, found := p.p["name"]; found { + u.Set("name", v.(string)) + } + if v, found := p.p["sortkey"]; found { + vv := strconv.Itoa(v.(int)) + u.Set("sortkey", vv) + } + return u +} + +func (p *UpdateDiskOfferingParams) SetDisplayoffering(v bool) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["displayoffering"] = v + return +} + +func (p *UpdateDiskOfferingParams) SetDisplaytext(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["displaytext"] = v + return +} + +func (p *UpdateDiskOfferingParams) SetId(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["id"] = v + return +} + +func (p *UpdateDiskOfferingParams) SetName(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["name"] = v + return +} + +func (p *UpdateDiskOfferingParams) SetSortkey(v int) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["sortkey"] = v + return +} + +// You should always use this function to get a new UpdateDiskOfferingParams instance, +// as then you are sure you have configured all required params +func (s *DiskOfferingService) NewUpdateDiskOfferingParams(id string) *UpdateDiskOfferingParams { + p := &UpdateDiskOfferingParams{} + p.p = make(map[string]interface{}) + p.p["id"] = id + return p +} + +// Updates a disk offering. +func (s *DiskOfferingService) UpdateDiskOffering(p *UpdateDiskOfferingParams) (*UpdateDiskOfferingResponse, error) { + resp, err := s.cs.newRequest("updateDiskOffering", p.toURLValues()) + if err != nil { + return nil, err + } + + var r UpdateDiskOfferingResponse + if err := json.Unmarshal(resp, &r); err != nil { + return nil, err + } + + return &r, nil +} + +type UpdateDiskOfferingResponse struct { + CacheMode string `json:"cacheMode"` + Created string `json:"created"` + DiskBytesReadRate int64 `json:"diskBytesReadRate"` + DiskBytesWriteRate int64 `json:"diskBytesWriteRate"` + DiskIopsReadRate int64 `json:"diskIopsReadRate"` + DiskIopsWriteRate int64 `json:"diskIopsWriteRate"` + Disksize int64 `json:"disksize"` + Displayoffering bool `json:"displayoffering"` + Displaytext string `json:"displaytext"` + Domain string `json:"domain"` + Domainid string `json:"domainid"` + Hypervisorsnapshotreserve int `json:"hypervisorsnapshotreserve"` + Id string `json:"id"` + Iscustomized bool `json:"iscustomized"` + Iscustomizediops bool `json:"iscustomizediops"` + Maxiops int64 `json:"maxiops"` + Miniops int64 `json:"miniops"` + Name string `json:"name"` + Provisioningtype string `json:"provisioningtype"` + Storagetype string `json:"storagetype"` + Tags string `json:"tags"` } diff --git a/vendor/github.com/xanzy/go-cloudstack/cloudstack/DomainService.go b/vendor/github.com/xanzy/go-cloudstack/cloudstack/DomainService.go index e21afbd82..5aff9933e 100644 --- a/vendor/github.com/xanzy/go-cloudstack/cloudstack/DomainService.go +++ b/vendor/github.com/xanzy/go-cloudstack/cloudstack/DomainService.go @@ -1,5 +1,5 @@ // -// Copyright 2016, Sander van Harmelen +// Copyright 2018, Sander van Harmelen // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -100,171 +100,56 @@ func (s *DomainService) CreateDomain(p *CreateDomainParams) (*CreateDomainRespon if err := json.Unmarshal(resp, &r); err != nil { return nil, err } + return &r, nil } type CreateDomainResponse struct { - Cpuavailable string `json:"cpuavailable,omitempty"` - Cpulimit string `json:"cpulimit,omitempty"` - Cputotal int64 `json:"cputotal,omitempty"` - Haschild bool `json:"haschild,omitempty"` - Id string `json:"id,omitempty"` - Ipavailable string `json:"ipavailable,omitempty"` - Iplimit string `json:"iplimit,omitempty"` - Iptotal int64 `json:"iptotal,omitempty"` - Level int `json:"level,omitempty"` - Memoryavailable string `json:"memoryavailable,omitempty"` - Memorylimit string `json:"memorylimit,omitempty"` - Memorytotal int64 `json:"memorytotal,omitempty"` - Name string `json:"name,omitempty"` - Networkavailable string `json:"networkavailable,omitempty"` - Networkdomain string `json:"networkdomain,omitempty"` - Networklimit string `json:"networklimit,omitempty"` - Networktotal int64 `json:"networktotal,omitempty"` - Parentdomainid string `json:"parentdomainid,omitempty"` - Parentdomainname string `json:"parentdomainname,omitempty"` - Path string `json:"path,omitempty"` - Primarystorageavailable string `json:"primarystorageavailable,omitempty"` - Primarystoragelimit string `json:"primarystoragelimit,omitempty"` - Primarystoragetotal int64 `json:"primarystoragetotal,omitempty"` - Projectavailable string `json:"projectavailable,omitempty"` - Projectlimit string `json:"projectlimit,omitempty"` - Projecttotal int64 `json:"projecttotal,omitempty"` - Secondarystorageavailable string `json:"secondarystorageavailable,omitempty"` - Secondarystoragelimit string `json:"secondarystoragelimit,omitempty"` - Secondarystoragetotal int64 `json:"secondarystoragetotal,omitempty"` - Snapshotavailable string `json:"snapshotavailable,omitempty"` - Snapshotlimit string `json:"snapshotlimit,omitempty"` - Snapshottotal int64 `json:"snapshottotal,omitempty"` - State string `json:"state,omitempty"` - Templateavailable string `json:"templateavailable,omitempty"` - Templatelimit string `json:"templatelimit,omitempty"` - Templatetotal int64 `json:"templatetotal,omitempty"` - Vmavailable string `json:"vmavailable,omitempty"` - Vmlimit string `json:"vmlimit,omitempty"` - Vmtotal int64 `json:"vmtotal,omitempty"` - Volumeavailable string `json:"volumeavailable,omitempty"` - Volumelimit string `json:"volumelimit,omitempty"` - Volumetotal int64 `json:"volumetotal,omitempty"` - Vpcavailable string `json:"vpcavailable,omitempty"` - Vpclimit string `json:"vpclimit,omitempty"` - Vpctotal int64 `json:"vpctotal,omitempty"` -} - -type UpdateDomainParams struct { - p map[string]interface{} -} - -func (p *UpdateDomainParams) toURLValues() url.Values { - u := url.Values{} - if p.p == nil { - return u - } - if v, found := p.p["id"]; found { - u.Set("id", v.(string)) - } - if v, found := p.p["name"]; found { - u.Set("name", v.(string)) - } - if v, found := p.p["networkdomain"]; found { - u.Set("networkdomain", v.(string)) - } - return u -} - -func (p *UpdateDomainParams) SetId(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["id"] = v - return -} - -func (p *UpdateDomainParams) SetName(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["name"] = v - return -} - -func (p *UpdateDomainParams) SetNetworkdomain(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["networkdomain"] = v - return -} - -// You should always use this function to get a new UpdateDomainParams instance, -// as then you are sure you have configured all required params -func (s *DomainService) NewUpdateDomainParams(id string) *UpdateDomainParams { - p := &UpdateDomainParams{} - p.p = make(map[string]interface{}) - p.p["id"] = id - return p -} - -// Updates a domain with a new name -func (s *DomainService) UpdateDomain(p *UpdateDomainParams) (*UpdateDomainResponse, error) { - resp, err := s.cs.newRequest("updateDomain", p.toURLValues()) - if err != nil { - return nil, err - } - - var r UpdateDomainResponse - if err := json.Unmarshal(resp, &r); err != nil { - return nil, err - } - return &r, nil -} - -type UpdateDomainResponse struct { - Cpuavailable string `json:"cpuavailable,omitempty"` - Cpulimit string `json:"cpulimit,omitempty"` - Cputotal int64 `json:"cputotal,omitempty"` - Haschild bool `json:"haschild,omitempty"` - Id string `json:"id,omitempty"` - Ipavailable string `json:"ipavailable,omitempty"` - Iplimit string `json:"iplimit,omitempty"` - Iptotal int64 `json:"iptotal,omitempty"` - Level int `json:"level,omitempty"` - Memoryavailable string `json:"memoryavailable,omitempty"` - Memorylimit string `json:"memorylimit,omitempty"` - Memorytotal int64 `json:"memorytotal,omitempty"` - Name string `json:"name,omitempty"` - Networkavailable string `json:"networkavailable,omitempty"` - Networkdomain string `json:"networkdomain,omitempty"` - Networklimit string `json:"networklimit,omitempty"` - Networktotal int64 `json:"networktotal,omitempty"` - Parentdomainid string `json:"parentdomainid,omitempty"` - Parentdomainname string `json:"parentdomainname,omitempty"` - Path string `json:"path,omitempty"` - Primarystorageavailable string `json:"primarystorageavailable,omitempty"` - Primarystoragelimit string `json:"primarystoragelimit,omitempty"` - Primarystoragetotal int64 `json:"primarystoragetotal,omitempty"` - Projectavailable string `json:"projectavailable,omitempty"` - Projectlimit string `json:"projectlimit,omitempty"` - Projecttotal int64 `json:"projecttotal,omitempty"` - Secondarystorageavailable string `json:"secondarystorageavailable,omitempty"` - Secondarystoragelimit string `json:"secondarystoragelimit,omitempty"` - Secondarystoragetotal int64 `json:"secondarystoragetotal,omitempty"` - Snapshotavailable string `json:"snapshotavailable,omitempty"` - Snapshotlimit string `json:"snapshotlimit,omitempty"` - Snapshottotal int64 `json:"snapshottotal,omitempty"` - State string `json:"state,omitempty"` - Templateavailable string `json:"templateavailable,omitempty"` - Templatelimit string `json:"templatelimit,omitempty"` - Templatetotal int64 `json:"templatetotal,omitempty"` - Vmavailable string `json:"vmavailable,omitempty"` - Vmlimit string `json:"vmlimit,omitempty"` - Vmtotal int64 `json:"vmtotal,omitempty"` - Volumeavailable string `json:"volumeavailable,omitempty"` - Volumelimit string `json:"volumelimit,omitempty"` - Volumetotal int64 `json:"volumetotal,omitempty"` - Vpcavailable string `json:"vpcavailable,omitempty"` - Vpclimit string `json:"vpclimit,omitempty"` - Vpctotal int64 `json:"vpctotal,omitempty"` + Cpuavailable string `json:"cpuavailable"` + Cpulimit string `json:"cpulimit"` + Cputotal int64 `json:"cputotal"` + Haschild bool `json:"haschild"` + Id string `json:"id"` + Ipavailable string `json:"ipavailable"` + Iplimit string `json:"iplimit"` + Iptotal int64 `json:"iptotal"` + Level int `json:"level"` + Memoryavailable string `json:"memoryavailable"` + Memorylimit string `json:"memorylimit"` + Memorytotal int64 `json:"memorytotal"` + Name string `json:"name"` + Networkavailable string `json:"networkavailable"` + Networkdomain string `json:"networkdomain"` + Networklimit string `json:"networklimit"` + Networktotal int64 `json:"networktotal"` + Parentdomainid string `json:"parentdomainid"` + Parentdomainname string `json:"parentdomainname"` + Path string `json:"path"` + Primarystorageavailable string `json:"primarystorageavailable"` + Primarystoragelimit string `json:"primarystoragelimit"` + Primarystoragetotal int64 `json:"primarystoragetotal"` + Projectavailable string `json:"projectavailable"` + Projectlimit string `json:"projectlimit"` + Projecttotal int64 `json:"projecttotal"` + Secondarystorageavailable string `json:"secondarystorageavailable"` + Secondarystoragelimit string `json:"secondarystoragelimit"` + Secondarystoragetotal float64 `json:"secondarystoragetotal"` + Snapshotavailable string `json:"snapshotavailable"` + Snapshotlimit string `json:"snapshotlimit"` + Snapshottotal int64 `json:"snapshottotal"` + State string `json:"state"` + Templateavailable string `json:"templateavailable"` + Templatelimit string `json:"templatelimit"` + Templatetotal int64 `json:"templatetotal"` + Vmavailable string `json:"vmavailable"` + Vmlimit string `json:"vmlimit"` + Vmtotal int64 `json:"vmtotal"` + Volumeavailable string `json:"volumeavailable"` + Volumelimit string `json:"volumelimit"` + Volumetotal int64 `json:"volumetotal"` + Vpcavailable string `json:"vpcavailable"` + Vpclimit string `json:"vpclimit"` + Vpctotal int64 `json:"vpctotal"` } type DeleteDomainParams struct { @@ -337,264 +222,14 @@ func (s *DomainService) DeleteDomain(p *DeleteDomainParams) (*DeleteDomainRespon return nil, err } } + return &r, nil } type DeleteDomainResponse struct { - JobID string `json:"jobid,omitempty"` - Displaytext string `json:"displaytext,omitempty"` - Success bool `json:"success,omitempty"` -} - -type ListDomainsParams struct { - p map[string]interface{} -} - -func (p *ListDomainsParams) toURLValues() url.Values { - u := url.Values{} - if p.p == nil { - return u - } - if v, found := p.p["id"]; found { - u.Set("id", v.(string)) - } - if v, found := p.p["keyword"]; found { - u.Set("keyword", v.(string)) - } - if v, found := p.p["level"]; found { - vv := strconv.Itoa(v.(int)) - u.Set("level", vv) - } - if v, found := p.p["listall"]; found { - vv := strconv.FormatBool(v.(bool)) - u.Set("listall", vv) - } - if v, found := p.p["name"]; found { - u.Set("name", v.(string)) - } - if v, found := p.p["page"]; found { - vv := strconv.Itoa(v.(int)) - u.Set("page", vv) - } - if v, found := p.p["pagesize"]; found { - vv := strconv.Itoa(v.(int)) - u.Set("pagesize", vv) - } - return u -} - -func (p *ListDomainsParams) SetId(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["id"] = v - return -} - -func (p *ListDomainsParams) SetKeyword(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["keyword"] = v - return -} - -func (p *ListDomainsParams) SetLevel(v int) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["level"] = v - return -} - -func (p *ListDomainsParams) SetListall(v bool) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["listall"] = v - return -} - -func (p *ListDomainsParams) SetName(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["name"] = v - return -} - -func (p *ListDomainsParams) SetPage(v int) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["page"] = v - return -} - -func (p *ListDomainsParams) SetPagesize(v int) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["pagesize"] = v - return -} - -// You should always use this function to get a new ListDomainsParams instance, -// as then you are sure you have configured all required params -func (s *DomainService) NewListDomainsParams() *ListDomainsParams { - p := &ListDomainsParams{} - p.p = make(map[string]interface{}) - return p -} - -// This is a courtesy helper function, which in some cases may not work as expected! -func (s *DomainService) GetDomainID(name string, opts ...OptionFunc) (string, int, error) { - p := &ListDomainsParams{} - p.p = make(map[string]interface{}) - - p.p["name"] = name - - for _, fn := range opts { - if err := fn(s.cs, p); err != nil { - return "", -1, err - } - } - - l, err := s.ListDomains(p) - if err != nil { - return "", -1, err - } - - if l.Count == 0 { - return "", l.Count, fmt.Errorf("No match found for %s: %+v", name, l) - } - - if l.Count == 1 { - return l.Domains[0].Id, l.Count, nil - } - - if l.Count > 1 { - for _, v := range l.Domains { - if v.Name == name { - return v.Id, l.Count, nil - } - } - } - return "", l.Count, fmt.Errorf("Could not find an exact match for %s: %+v", name, l) -} - -// This is a courtesy helper function, which in some cases may not work as expected! -func (s *DomainService) GetDomainByName(name string, opts ...OptionFunc) (*Domain, int, error) { - id, count, err := s.GetDomainID(name, opts...) - if err != nil { - return nil, count, err - } - - r, count, err := s.GetDomainByID(id, opts...) - if err != nil { - return nil, count, err - } - return r, count, nil -} - -// This is a courtesy helper function, which in some cases may not work as expected! -func (s *DomainService) GetDomainByID(id string, opts ...OptionFunc) (*Domain, int, error) { - p := &ListDomainsParams{} - p.p = make(map[string]interface{}) - - p.p["id"] = id - - for _, fn := range opts { - if err := fn(s.cs, p); err != nil { - return nil, -1, err - } - } - - l, err := s.ListDomains(p) - if err != nil { - if strings.Contains(err.Error(), fmt.Sprintf( - "Invalid parameter id value=%s due to incorrect long value format, "+ - "or entity does not exist", id)) { - return nil, 0, fmt.Errorf("No match found for %s: %+v", id, l) - } - return nil, -1, err - } - - if l.Count == 0 { - return nil, l.Count, fmt.Errorf("No match found for %s: %+v", id, l) - } - - if l.Count == 1 { - return l.Domains[0], l.Count, nil - } - return nil, l.Count, fmt.Errorf("There is more then one result for Domain UUID: %s!", id) -} - -// Lists domains and provides detailed information for listed domains -func (s *DomainService) ListDomains(p *ListDomainsParams) (*ListDomainsResponse, error) { - resp, err := s.cs.newRequest("listDomains", p.toURLValues()) - if err != nil { - return nil, err - } - - var r ListDomainsResponse - if err := json.Unmarshal(resp, &r); err != nil { - return nil, err - } - return &r, nil -} - -type ListDomainsResponse struct { - Count int `json:"count"` - Domains []*Domain `json:"domain"` -} - -type Domain struct { - Cpuavailable string `json:"cpuavailable,omitempty"` - Cpulimit string `json:"cpulimit,omitempty"` - Cputotal int64 `json:"cputotal,omitempty"` - Haschild bool `json:"haschild,omitempty"` - Id string `json:"id,omitempty"` - Ipavailable string `json:"ipavailable,omitempty"` - Iplimit string `json:"iplimit,omitempty"` - Iptotal int64 `json:"iptotal,omitempty"` - Level int `json:"level,omitempty"` - Memoryavailable string `json:"memoryavailable,omitempty"` - Memorylimit string `json:"memorylimit,omitempty"` - Memorytotal int64 `json:"memorytotal,omitempty"` - Name string `json:"name,omitempty"` - Networkavailable string `json:"networkavailable,omitempty"` - Networkdomain string `json:"networkdomain,omitempty"` - Networklimit string `json:"networklimit,omitempty"` - Networktotal int64 `json:"networktotal,omitempty"` - Parentdomainid string `json:"parentdomainid,omitempty"` - Parentdomainname string `json:"parentdomainname,omitempty"` - Path string `json:"path,omitempty"` - Primarystorageavailable string `json:"primarystorageavailable,omitempty"` - Primarystoragelimit string `json:"primarystoragelimit,omitempty"` - Primarystoragetotal int64 `json:"primarystoragetotal,omitempty"` - Projectavailable string `json:"projectavailable,omitempty"` - Projectlimit string `json:"projectlimit,omitempty"` - Projecttotal int64 `json:"projecttotal,omitempty"` - Secondarystorageavailable string `json:"secondarystorageavailable,omitempty"` - Secondarystoragelimit string `json:"secondarystoragelimit,omitempty"` - Secondarystoragetotal int64 `json:"secondarystoragetotal,omitempty"` - Snapshotavailable string `json:"snapshotavailable,omitempty"` - Snapshotlimit string `json:"snapshotlimit,omitempty"` - Snapshottotal int64 `json:"snapshottotal,omitempty"` - State string `json:"state,omitempty"` - Templateavailable string `json:"templateavailable,omitempty"` - Templatelimit string `json:"templatelimit,omitempty"` - Templatetotal int64 `json:"templatetotal,omitempty"` - Vmavailable string `json:"vmavailable,omitempty"` - Vmlimit string `json:"vmlimit,omitempty"` - Vmtotal int64 `json:"vmtotal,omitempty"` - Volumeavailable string `json:"volumeavailable,omitempty"` - Volumelimit string `json:"volumelimit,omitempty"` - Volumetotal int64 `json:"volumetotal,omitempty"` - Vpcavailable string `json:"vpcavailable,omitempty"` - Vpclimit string `json:"vpclimit,omitempty"` - Vpctotal int64 `json:"vpctotal,omitempty"` + JobID string `json:"jobid"` + Displaytext string `json:"displaytext"` + Success bool `json:"success"` } type ListDomainChildrenParams struct { @@ -705,7 +340,7 @@ func (s *DomainService) GetDomainChildrenID(name string, opts ...OptionFunc) (st p.p["name"] = name - for _, fn := range opts { + for _, fn := range append(s.cs.options, opts...) { if err := fn(s.cs, p); err != nil { return "", -1, err } @@ -755,7 +390,7 @@ func (s *DomainService) GetDomainChildrenByID(id string, opts ...OptionFunc) (*D p.p["id"] = id - for _, fn := range opts { + for _, fn := range append(s.cs.options, opts...) { if err := fn(s.cs, p); err != nil { return nil, -1, err } @@ -792,6 +427,7 @@ func (s *DomainService) ListDomainChildren(p *ListDomainChildrenParams) (*ListDo if err := json.Unmarshal(resp, &r); err != nil { return nil, err } + return &r, nil } @@ -801,106 +437,135 @@ type ListDomainChildrenResponse struct { } type DomainChildren struct { - Cpuavailable string `json:"cpuavailable,omitempty"` - Cpulimit string `json:"cpulimit,omitempty"` - Cputotal int64 `json:"cputotal,omitempty"` - Haschild bool `json:"haschild,omitempty"` - Id string `json:"id,omitempty"` - Ipavailable string `json:"ipavailable,omitempty"` - Iplimit string `json:"iplimit,omitempty"` - Iptotal int64 `json:"iptotal,omitempty"` - Level int `json:"level,omitempty"` - Memoryavailable string `json:"memoryavailable,omitempty"` - Memorylimit string `json:"memorylimit,omitempty"` - Memorytotal int64 `json:"memorytotal,omitempty"` - Name string `json:"name,omitempty"` - Networkavailable string `json:"networkavailable,omitempty"` - Networkdomain string `json:"networkdomain,omitempty"` - Networklimit string `json:"networklimit,omitempty"` - Networktotal int64 `json:"networktotal,omitempty"` - Parentdomainid string `json:"parentdomainid,omitempty"` - Parentdomainname string `json:"parentdomainname,omitempty"` - Path string `json:"path,omitempty"` - Primarystorageavailable string `json:"primarystorageavailable,omitempty"` - Primarystoragelimit string `json:"primarystoragelimit,omitempty"` - Primarystoragetotal int64 `json:"primarystoragetotal,omitempty"` - Projectavailable string `json:"projectavailable,omitempty"` - Projectlimit string `json:"projectlimit,omitempty"` - Projecttotal int64 `json:"projecttotal,omitempty"` - Secondarystorageavailable string `json:"secondarystorageavailable,omitempty"` - Secondarystoragelimit string `json:"secondarystoragelimit,omitempty"` - Secondarystoragetotal int64 `json:"secondarystoragetotal,omitempty"` - Snapshotavailable string `json:"snapshotavailable,omitempty"` - Snapshotlimit string `json:"snapshotlimit,omitempty"` - Snapshottotal int64 `json:"snapshottotal,omitempty"` - State string `json:"state,omitempty"` - Templateavailable string `json:"templateavailable,omitempty"` - Templatelimit string `json:"templatelimit,omitempty"` - Templatetotal int64 `json:"templatetotal,omitempty"` - Vmavailable string `json:"vmavailable,omitempty"` - Vmlimit string `json:"vmlimit,omitempty"` - Vmtotal int64 `json:"vmtotal,omitempty"` - Volumeavailable string `json:"volumeavailable,omitempty"` - Volumelimit string `json:"volumelimit,omitempty"` - Volumetotal int64 `json:"volumetotal,omitempty"` - Vpcavailable string `json:"vpcavailable,omitempty"` - Vpclimit string `json:"vpclimit,omitempty"` - Vpctotal int64 `json:"vpctotal,omitempty"` + Cpuavailable string `json:"cpuavailable"` + Cpulimit string `json:"cpulimit"` + Cputotal int64 `json:"cputotal"` + Haschild bool `json:"haschild"` + Id string `json:"id"` + Ipavailable string `json:"ipavailable"` + Iplimit string `json:"iplimit"` + Iptotal int64 `json:"iptotal"` + Level int `json:"level"` + Memoryavailable string `json:"memoryavailable"` + Memorylimit string `json:"memorylimit"` + Memorytotal int64 `json:"memorytotal"` + Name string `json:"name"` + Networkavailable string `json:"networkavailable"` + Networkdomain string `json:"networkdomain"` + Networklimit string `json:"networklimit"` + Networktotal int64 `json:"networktotal"` + Parentdomainid string `json:"parentdomainid"` + Parentdomainname string `json:"parentdomainname"` + Path string `json:"path"` + Primarystorageavailable string `json:"primarystorageavailable"` + Primarystoragelimit string `json:"primarystoragelimit"` + Primarystoragetotal int64 `json:"primarystoragetotal"` + Projectavailable string `json:"projectavailable"` + Projectlimit string `json:"projectlimit"` + Projecttotal int64 `json:"projecttotal"` + Secondarystorageavailable string `json:"secondarystorageavailable"` + Secondarystoragelimit string `json:"secondarystoragelimit"` + Secondarystoragetotal float64 `json:"secondarystoragetotal"` + Snapshotavailable string `json:"snapshotavailable"` + Snapshotlimit string `json:"snapshotlimit"` + Snapshottotal int64 `json:"snapshottotal"` + State string `json:"state"` + Templateavailable string `json:"templateavailable"` + Templatelimit string `json:"templatelimit"` + Templatetotal int64 `json:"templatetotal"` + Vmavailable string `json:"vmavailable"` + Vmlimit string `json:"vmlimit"` + Vmtotal int64 `json:"vmtotal"` + Volumeavailable string `json:"volumeavailable"` + Volumelimit string `json:"volumelimit"` + Volumetotal int64 `json:"volumetotal"` + Vpcavailable string `json:"vpcavailable"` + Vpclimit string `json:"vpclimit"` + Vpctotal int64 `json:"vpctotal"` } -type LinkDomainToLdapParams struct { +type ListDomainsParams struct { p map[string]interface{} } -func (p *LinkDomainToLdapParams) toURLValues() url.Values { +func (p *ListDomainsParams) toURLValues() url.Values { u := url.Values{} if p.p == nil { return u } - if v, found := p.p["accounttype"]; found { + if v, found := p.p["details"]; found { + vv := strings.Join(v.([]string), ",") + u.Set("details", vv) + } + if v, found := p.p["id"]; found { + u.Set("id", v.(string)) + } + if v, found := p.p["keyword"]; found { + u.Set("keyword", v.(string)) + } + if v, found := p.p["level"]; found { vv := strconv.Itoa(v.(int)) - u.Set("accounttype", vv) + u.Set("level", vv) } - if v, found := p.p["admin"]; found { - u.Set("admin", v.(string)) - } - if v, found := p.p["domainid"]; found { - u.Set("domainid", v.(string)) + if v, found := p.p["listall"]; found { + vv := strconv.FormatBool(v.(bool)) + u.Set("listall", vv) } if v, found := p.p["name"]; found { u.Set("name", v.(string)) } - if v, found := p.p["type"]; found { - u.Set("type", v.(string)) + if v, found := p.p["page"]; found { + vv := strconv.Itoa(v.(int)) + u.Set("page", vv) + } + if v, found := p.p["pagesize"]; found { + vv := strconv.Itoa(v.(int)) + u.Set("pagesize", vv) } return u } -func (p *LinkDomainToLdapParams) SetAccounttype(v int) { +func (p *ListDomainsParams) SetDetails(v []string) { if p.p == nil { p.p = make(map[string]interface{}) } - p.p["accounttype"] = v + p.p["details"] = v return } -func (p *LinkDomainToLdapParams) SetAdmin(v string) { +func (p *ListDomainsParams) SetId(v string) { if p.p == nil { p.p = make(map[string]interface{}) } - p.p["admin"] = v + p.p["id"] = v return } -func (p *LinkDomainToLdapParams) SetDomainid(v string) { +func (p *ListDomainsParams) SetKeyword(v string) { if p.p == nil { p.p = make(map[string]interface{}) } - p.p["domainid"] = v + p.p["keyword"] = v return } -func (p *LinkDomainToLdapParams) SetName(v string) { +func (p *ListDomainsParams) SetLevel(v int) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["level"] = v + return +} + +func (p *ListDomainsParams) SetListall(v bool) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["listall"] = v + return +} + +func (p *ListDomainsParams) SetName(v string) { if p.p == nil { p.p = make(map[string]interface{}) } @@ -908,44 +573,294 @@ func (p *LinkDomainToLdapParams) SetName(v string) { return } -func (p *LinkDomainToLdapParams) SetType(v string) { +func (p *ListDomainsParams) SetPage(v int) { if p.p == nil { p.p = make(map[string]interface{}) } - p.p["type"] = v + p.p["page"] = v return } -// You should always use this function to get a new LinkDomainToLdapParams instance, +func (p *ListDomainsParams) SetPagesize(v int) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["pagesize"] = v + return +} + +// You should always use this function to get a new ListDomainsParams instance, // as then you are sure you have configured all required params -func (s *DomainService) NewLinkDomainToLdapParams(accounttype int, domainid string, name string, domainType string) *LinkDomainToLdapParams { - p := &LinkDomainToLdapParams{} +func (s *DomainService) NewListDomainsParams() *ListDomainsParams { + p := &ListDomainsParams{} p.p = make(map[string]interface{}) - p.p["accounttype"] = accounttype - p.p["domainid"] = domainid - p.p["name"] = name - p.p["type"] = domainType return p } -// link an existing cloudstack domain to group or OU in ldap -func (s *DomainService) LinkDomainToLdap(p *LinkDomainToLdapParams) (*LinkDomainToLdapResponse, error) { - resp, err := s.cs.newRequest("linkDomainToLdap", p.toURLValues()) +// This is a courtesy helper function, which in some cases may not work as expected! +func (s *DomainService) GetDomainID(name string, opts ...OptionFunc) (string, int, error) { + p := &ListDomainsParams{} + p.p = make(map[string]interface{}) + + p.p["name"] = name + + for _, fn := range append(s.cs.options, opts...) { + if err := fn(s.cs, p); err != nil { + return "", -1, err + } + } + + l, err := s.ListDomains(p) + if err != nil { + return "", -1, err + } + + if l.Count == 0 { + return "", l.Count, fmt.Errorf("No match found for %s: %+v", name, l) + } + + if l.Count == 1 { + return l.Domains[0].Id, l.Count, nil + } + + if l.Count > 1 { + for _, v := range l.Domains { + if v.Name == name { + return v.Id, l.Count, nil + } + } + } + return "", l.Count, fmt.Errorf("Could not find an exact match for %s: %+v", name, l) +} + +// This is a courtesy helper function, which in some cases may not work as expected! +func (s *DomainService) GetDomainByName(name string, opts ...OptionFunc) (*Domain, int, error) { + id, count, err := s.GetDomainID(name, opts...) + if err != nil { + return nil, count, err + } + + r, count, err := s.GetDomainByID(id, opts...) + if err != nil { + return nil, count, err + } + return r, count, nil +} + +// This is a courtesy helper function, which in some cases may not work as expected! +func (s *DomainService) GetDomainByID(id string, opts ...OptionFunc) (*Domain, int, error) { + p := &ListDomainsParams{} + p.p = make(map[string]interface{}) + + p.p["id"] = id + + for _, fn := range append(s.cs.options, opts...) { + if err := fn(s.cs, p); err != nil { + return nil, -1, err + } + } + + l, err := s.ListDomains(p) + if err != nil { + if strings.Contains(err.Error(), fmt.Sprintf( + "Invalid parameter id value=%s due to incorrect long value format, "+ + "or entity does not exist", id)) { + return nil, 0, fmt.Errorf("No match found for %s: %+v", id, l) + } + return nil, -1, err + } + + if l.Count == 0 { + return nil, l.Count, fmt.Errorf("No match found for %s: %+v", id, l) + } + + if l.Count == 1 { + return l.Domains[0], l.Count, nil + } + return nil, l.Count, fmt.Errorf("There is more then one result for Domain UUID: %s!", id) +} + +// Lists domains and provides detailed information for listed domains +func (s *DomainService) ListDomains(p *ListDomainsParams) (*ListDomainsResponse, error) { + resp, err := s.cs.newRequest("listDomains", p.toURLValues()) if err != nil { return nil, err } - var r LinkDomainToLdapResponse + var r ListDomainsResponse if err := json.Unmarshal(resp, &r); err != nil { return nil, err } + return &r, nil } -type LinkDomainToLdapResponse struct { - Accountid string `json:"accountid,omitempty"` - Accounttype int `json:"accounttype,omitempty"` - Domainid int64 `json:"domainid,omitempty"` - Name string `json:"name,omitempty"` - Type string `json:"type,omitempty"` +type ListDomainsResponse struct { + Count int `json:"count"` + Domains []*Domain `json:"domain"` +} + +type Domain struct { + Cpuavailable string `json:"cpuavailable"` + Cpulimit string `json:"cpulimit"` + Cputotal int64 `json:"cputotal"` + Haschild bool `json:"haschild"` + Id string `json:"id"` + Ipavailable string `json:"ipavailable"` + Iplimit string `json:"iplimit"` + Iptotal int64 `json:"iptotal"` + Level int `json:"level"` + Memoryavailable string `json:"memoryavailable"` + Memorylimit string `json:"memorylimit"` + Memorytotal int64 `json:"memorytotal"` + Name string `json:"name"` + Networkavailable string `json:"networkavailable"` + Networkdomain string `json:"networkdomain"` + Networklimit string `json:"networklimit"` + Networktotal int64 `json:"networktotal"` + Parentdomainid string `json:"parentdomainid"` + Parentdomainname string `json:"parentdomainname"` + Path string `json:"path"` + Primarystorageavailable string `json:"primarystorageavailable"` + Primarystoragelimit string `json:"primarystoragelimit"` + Primarystoragetotal int64 `json:"primarystoragetotal"` + Projectavailable string `json:"projectavailable"` + Projectlimit string `json:"projectlimit"` + Projecttotal int64 `json:"projecttotal"` + Secondarystorageavailable string `json:"secondarystorageavailable"` + Secondarystoragelimit string `json:"secondarystoragelimit"` + Secondarystoragetotal float64 `json:"secondarystoragetotal"` + Snapshotavailable string `json:"snapshotavailable"` + Snapshotlimit string `json:"snapshotlimit"` + Snapshottotal int64 `json:"snapshottotal"` + State string `json:"state"` + Templateavailable string `json:"templateavailable"` + Templatelimit string `json:"templatelimit"` + Templatetotal int64 `json:"templatetotal"` + Vmavailable string `json:"vmavailable"` + Vmlimit string `json:"vmlimit"` + Vmtotal int64 `json:"vmtotal"` + Volumeavailable string `json:"volumeavailable"` + Volumelimit string `json:"volumelimit"` + Volumetotal int64 `json:"volumetotal"` + Vpcavailable string `json:"vpcavailable"` + Vpclimit string `json:"vpclimit"` + Vpctotal int64 `json:"vpctotal"` +} + +type UpdateDomainParams struct { + p map[string]interface{} +} + +func (p *UpdateDomainParams) toURLValues() url.Values { + u := url.Values{} + if p.p == nil { + return u + } + if v, found := p.p["id"]; found { + u.Set("id", v.(string)) + } + if v, found := p.p["name"]; found { + u.Set("name", v.(string)) + } + if v, found := p.p["networkdomain"]; found { + u.Set("networkdomain", v.(string)) + } + return u +} + +func (p *UpdateDomainParams) SetId(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["id"] = v + return +} + +func (p *UpdateDomainParams) SetName(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["name"] = v + return +} + +func (p *UpdateDomainParams) SetNetworkdomain(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["networkdomain"] = v + return +} + +// You should always use this function to get a new UpdateDomainParams instance, +// as then you are sure you have configured all required params +func (s *DomainService) NewUpdateDomainParams(id string) *UpdateDomainParams { + p := &UpdateDomainParams{} + p.p = make(map[string]interface{}) + p.p["id"] = id + return p +} + +// Updates a domain with a new name +func (s *DomainService) UpdateDomain(p *UpdateDomainParams) (*UpdateDomainResponse, error) { + resp, err := s.cs.newRequest("updateDomain", p.toURLValues()) + if err != nil { + return nil, err + } + + var r UpdateDomainResponse + if err := json.Unmarshal(resp, &r); err != nil { + return nil, err + } + + return &r, nil +} + +type UpdateDomainResponse struct { + Cpuavailable string `json:"cpuavailable"` + Cpulimit string `json:"cpulimit"` + Cputotal int64 `json:"cputotal"` + Haschild bool `json:"haschild"` + Id string `json:"id"` + Ipavailable string `json:"ipavailable"` + Iplimit string `json:"iplimit"` + Iptotal int64 `json:"iptotal"` + Level int `json:"level"` + Memoryavailable string `json:"memoryavailable"` + Memorylimit string `json:"memorylimit"` + Memorytotal int64 `json:"memorytotal"` + Name string `json:"name"` + Networkavailable string `json:"networkavailable"` + Networkdomain string `json:"networkdomain"` + Networklimit string `json:"networklimit"` + Networktotal int64 `json:"networktotal"` + Parentdomainid string `json:"parentdomainid"` + Parentdomainname string `json:"parentdomainname"` + Path string `json:"path"` + Primarystorageavailable string `json:"primarystorageavailable"` + Primarystoragelimit string `json:"primarystoragelimit"` + Primarystoragetotal int64 `json:"primarystoragetotal"` + Projectavailable string `json:"projectavailable"` + Projectlimit string `json:"projectlimit"` + Projecttotal int64 `json:"projecttotal"` + Secondarystorageavailable string `json:"secondarystorageavailable"` + Secondarystoragelimit string `json:"secondarystoragelimit"` + Secondarystoragetotal float64 `json:"secondarystoragetotal"` + Snapshotavailable string `json:"snapshotavailable"` + Snapshotlimit string `json:"snapshotlimit"` + Snapshottotal int64 `json:"snapshottotal"` + State string `json:"state"` + Templateavailable string `json:"templateavailable"` + Templatelimit string `json:"templatelimit"` + Templatetotal int64 `json:"templatetotal"` + Vmavailable string `json:"vmavailable"` + Vmlimit string `json:"vmlimit"` + Vmtotal int64 `json:"vmtotal"` + Volumeavailable string `json:"volumeavailable"` + Volumelimit string `json:"volumelimit"` + Volumetotal int64 `json:"volumetotal"` + Vpcavailable string `json:"vpcavailable"` + Vpclimit string `json:"vpclimit"` + Vpctotal int64 `json:"vpctotal"` } diff --git a/vendor/github.com/xanzy/go-cloudstack/cloudstack/EventService.go b/vendor/github.com/xanzy/go-cloudstack/cloudstack/EventService.go index 84a8b9273..f1cd41c2a 100644 --- a/vendor/github.com/xanzy/go-cloudstack/cloudstack/EventService.go +++ b/vendor/github.com/xanzy/go-cloudstack/cloudstack/EventService.go @@ -1,5 +1,5 @@ // -// Copyright 2016, Sander van Harmelen +// Copyright 2018, Sander van Harmelen // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -24,6 +24,258 @@ import ( "strings" ) +type ArchiveEventsParams struct { + p map[string]interface{} +} + +func (p *ArchiveEventsParams) toURLValues() url.Values { + u := url.Values{} + if p.p == nil { + return u + } + if v, found := p.p["enddate"]; found { + u.Set("enddate", v.(string)) + } + if v, found := p.p["ids"]; found { + vv := strings.Join(v.([]string), ",") + u.Set("ids", vv) + } + if v, found := p.p["startdate"]; found { + u.Set("startdate", v.(string)) + } + if v, found := p.p["type"]; found { + u.Set("type", v.(string)) + } + return u +} + +func (p *ArchiveEventsParams) SetEnddate(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["enddate"] = v + return +} + +func (p *ArchiveEventsParams) SetIds(v []string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["ids"] = v + return +} + +func (p *ArchiveEventsParams) SetStartdate(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["startdate"] = v + return +} + +func (p *ArchiveEventsParams) SetType(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["type"] = v + return +} + +// You should always use this function to get a new ArchiveEventsParams instance, +// as then you are sure you have configured all required params +func (s *EventService) NewArchiveEventsParams() *ArchiveEventsParams { + p := &ArchiveEventsParams{} + p.p = make(map[string]interface{}) + return p +} + +// Archive one or more events. +func (s *EventService) ArchiveEvents(p *ArchiveEventsParams) (*ArchiveEventsResponse, error) { + resp, err := s.cs.newRequest("archiveEvents", p.toURLValues()) + if err != nil { + return nil, err + } + + var r ArchiveEventsResponse + if err := json.Unmarshal(resp, &r); err != nil { + return nil, err + } + + return &r, nil +} + +type ArchiveEventsResponse struct { + Displaytext string `json:"displaytext"` + Success bool `json:"success"` +} + +func (r *ArchiveEventsResponse) UnmarshalJSON(b []byte) error { + var m map[string]interface{} + err := json.Unmarshal(b, &m) + if err != nil { + return err + } + + if success, ok := m["success"].(string); ok { + m["success"] = success == "true" + b, err = json.Marshal(m) + if err != nil { + return err + } + } + + type alias ArchiveEventsResponse + return json.Unmarshal(b, (*alias)(r)) +} + +type DeleteEventsParams struct { + p map[string]interface{} +} + +func (p *DeleteEventsParams) toURLValues() url.Values { + u := url.Values{} + if p.p == nil { + return u + } + if v, found := p.p["enddate"]; found { + u.Set("enddate", v.(string)) + } + if v, found := p.p["ids"]; found { + vv := strings.Join(v.([]string), ",") + u.Set("ids", vv) + } + if v, found := p.p["startdate"]; found { + u.Set("startdate", v.(string)) + } + if v, found := p.p["type"]; found { + u.Set("type", v.(string)) + } + return u +} + +func (p *DeleteEventsParams) SetEnddate(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["enddate"] = v + return +} + +func (p *DeleteEventsParams) SetIds(v []string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["ids"] = v + return +} + +func (p *DeleteEventsParams) SetStartdate(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["startdate"] = v + return +} + +func (p *DeleteEventsParams) SetType(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["type"] = v + return +} + +// You should always use this function to get a new DeleteEventsParams instance, +// as then you are sure you have configured all required params +func (s *EventService) NewDeleteEventsParams() *DeleteEventsParams { + p := &DeleteEventsParams{} + p.p = make(map[string]interface{}) + return p +} + +// Delete one or more events. +func (s *EventService) DeleteEvents(p *DeleteEventsParams) (*DeleteEventsResponse, error) { + resp, err := s.cs.newRequest("deleteEvents", p.toURLValues()) + if err != nil { + return nil, err + } + + var r DeleteEventsResponse + if err := json.Unmarshal(resp, &r); err != nil { + return nil, err + } + + return &r, nil +} + +type DeleteEventsResponse struct { + Displaytext string `json:"displaytext"` + Success bool `json:"success"` +} + +func (r *DeleteEventsResponse) UnmarshalJSON(b []byte) error { + var m map[string]interface{} + err := json.Unmarshal(b, &m) + if err != nil { + return err + } + + if success, ok := m["success"].(string); ok { + m["success"] = success == "true" + b, err = json.Marshal(m) + if err != nil { + return err + } + } + + type alias DeleteEventsResponse + return json.Unmarshal(b, (*alias)(r)) +} + +type ListEventTypesParams struct { + p map[string]interface{} +} + +func (p *ListEventTypesParams) toURLValues() url.Values { + u := url.Values{} + if p.p == nil { + return u + } + return u +} + +// You should always use this function to get a new ListEventTypesParams instance, +// as then you are sure you have configured all required params +func (s *EventService) NewListEventTypesParams() *ListEventTypesParams { + p := &ListEventTypesParams{} + p.p = make(map[string]interface{}) + return p +} + +// List Event Types +func (s *EventService) ListEventTypes(p *ListEventTypesParams) (*ListEventTypesResponse, error) { + resp, err := s.cs.newRequest("listEventTypes", p.toURLValues()) + if err != nil { + return nil, err + } + + var r ListEventTypesResponse + if err := json.Unmarshal(resp, &r); err != nil { + return nil, err + } + + return &r, nil +} + +type ListEventTypesResponse struct { + Count int `json:"count"` + EventTypes []*EventType `json:"eventtype"` +} + +type EventType struct { + Name string `json:"name"` +} + type ListEventsParams struct { p map[string]interface{} } @@ -81,6 +333,9 @@ func (p *ListEventsParams) toURLValues() url.Values { if v, found := p.p["startdate"]; found { u.Set("startdate", v.(string)) } + if v, found := p.p["startid"]; found { + u.Set("startid", v.(string)) + } if v, found := p.p["type"]; found { u.Set("type", v.(string)) } @@ -199,6 +454,14 @@ func (p *ListEventsParams) SetStartdate(v string) { return } +func (p *ListEventsParams) SetStartid(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["startid"] = v + return +} + func (p *ListEventsParams) SetType(v string) { if p.p == nil { p.p = make(map[string]interface{}) @@ -222,7 +485,7 @@ func (s *EventService) GetEventByID(id string, opts ...OptionFunc) (*Event, int, p.p["id"] = id - for _, fn := range opts { + for _, fn := range append(s.cs.options, opts...) { if err := fn(s.cs, p); err != nil { return nil, -1, err } @@ -259,6 +522,7 @@ func (s *EventService) ListEvents(p *ListEventsParams) (*ListEventsResponse, err if err := json.Unmarshal(resp, &r); err != nil { return nil, err } + return &r, nil } @@ -268,228 +532,17 @@ type ListEventsResponse struct { } type Event struct { - Account string `json:"account,omitempty"` - Created string `json:"created,omitempty"` - Description string `json:"description,omitempty"` - Domain string `json:"domain,omitempty"` - Domainid string `json:"domainid,omitempty"` - Id string `json:"id,omitempty"` - Level string `json:"level,omitempty"` - Parentid string `json:"parentid,omitempty"` - Project string `json:"project,omitempty"` - Projectid string `json:"projectid,omitempty"` - State string `json:"state,omitempty"` - Type string `json:"type,omitempty"` - Username string `json:"username,omitempty"` -} - -type ListEventTypesParams struct { - p map[string]interface{} -} - -func (p *ListEventTypesParams) toURLValues() url.Values { - u := url.Values{} - if p.p == nil { - return u - } - return u -} - -// You should always use this function to get a new ListEventTypesParams instance, -// as then you are sure you have configured all required params -func (s *EventService) NewListEventTypesParams() *ListEventTypesParams { - p := &ListEventTypesParams{} - p.p = make(map[string]interface{}) - return p -} - -// List Event Types -func (s *EventService) ListEventTypes(p *ListEventTypesParams) (*ListEventTypesResponse, error) { - resp, err := s.cs.newRequest("listEventTypes", p.toURLValues()) - if err != nil { - return nil, err - } - - var r ListEventTypesResponse - if err := json.Unmarshal(resp, &r); err != nil { - return nil, err - } - return &r, nil -} - -type ListEventTypesResponse struct { - Count int `json:"count"` - EventTypes []*EventType `json:"eventtype"` -} - -type EventType struct { - Name string `json:"name,omitempty"` -} - -type ArchiveEventsParams struct { - p map[string]interface{} -} - -func (p *ArchiveEventsParams) toURLValues() url.Values { - u := url.Values{} - if p.p == nil { - return u - } - if v, found := p.p["enddate"]; found { - u.Set("enddate", v.(string)) - } - if v, found := p.p["ids"]; found { - vv := strings.Join(v.([]string), ",") - u.Set("ids", vv) - } - if v, found := p.p["startdate"]; found { - u.Set("startdate", v.(string)) - } - if v, found := p.p["type"]; found { - u.Set("type", v.(string)) - } - return u -} - -func (p *ArchiveEventsParams) SetEnddate(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["enddate"] = v - return -} - -func (p *ArchiveEventsParams) SetIds(v []string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["ids"] = v - return -} - -func (p *ArchiveEventsParams) SetStartdate(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["startdate"] = v - return -} - -func (p *ArchiveEventsParams) SetType(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["type"] = v - return -} - -// You should always use this function to get a new ArchiveEventsParams instance, -// as then you are sure you have configured all required params -func (s *EventService) NewArchiveEventsParams() *ArchiveEventsParams { - p := &ArchiveEventsParams{} - p.p = make(map[string]interface{}) - return p -} - -// Archive one or more events. -func (s *EventService) ArchiveEvents(p *ArchiveEventsParams) (*ArchiveEventsResponse, error) { - resp, err := s.cs.newRequest("archiveEvents", p.toURLValues()) - if err != nil { - return nil, err - } - - var r ArchiveEventsResponse - if err := json.Unmarshal(resp, &r); err != nil { - return nil, err - } - return &r, nil -} - -type ArchiveEventsResponse struct { - Displaytext string `json:"displaytext,omitempty"` - Success string `json:"success,omitempty"` -} - -type DeleteEventsParams struct { - p map[string]interface{} -} - -func (p *DeleteEventsParams) toURLValues() url.Values { - u := url.Values{} - if p.p == nil { - return u - } - if v, found := p.p["enddate"]; found { - u.Set("enddate", v.(string)) - } - if v, found := p.p["ids"]; found { - vv := strings.Join(v.([]string), ",") - u.Set("ids", vv) - } - if v, found := p.p["startdate"]; found { - u.Set("startdate", v.(string)) - } - if v, found := p.p["type"]; found { - u.Set("type", v.(string)) - } - return u -} - -func (p *DeleteEventsParams) SetEnddate(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["enddate"] = v - return -} - -func (p *DeleteEventsParams) SetIds(v []string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["ids"] = v - return -} - -func (p *DeleteEventsParams) SetStartdate(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["startdate"] = v - return -} - -func (p *DeleteEventsParams) SetType(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["type"] = v - return -} - -// You should always use this function to get a new DeleteEventsParams instance, -// as then you are sure you have configured all required params -func (s *EventService) NewDeleteEventsParams() *DeleteEventsParams { - p := &DeleteEventsParams{} - p.p = make(map[string]interface{}) - return p -} - -// Delete one or more events. -func (s *EventService) DeleteEvents(p *DeleteEventsParams) (*DeleteEventsResponse, error) { - resp, err := s.cs.newRequest("deleteEvents", p.toURLValues()) - if err != nil { - return nil, err - } - - var r DeleteEventsResponse - if err := json.Unmarshal(resp, &r); err != nil { - return nil, err - } - return &r, nil -} - -type DeleteEventsResponse struct { - Displaytext string `json:"displaytext,omitempty"` - Success string `json:"success,omitempty"` + Account string `json:"account"` + Created string `json:"created"` + Description string `json:"description"` + Domain string `json:"domain"` + Domainid string `json:"domainid"` + Id string `json:"id"` + Level string `json:"level"` + Parentid string `json:"parentid"` + Project string `json:"project"` + Projectid string `json:"projectid"` + State string `json:"state"` + Type string `json:"type"` + Username string `json:"username"` } diff --git a/vendor/github.com/xanzy/go-cloudstack/cloudstack/ExtFirewallService.go b/vendor/github.com/xanzy/go-cloudstack/cloudstack/ExtFirewallService.go new file mode 100644 index 000000000..4676b3edc --- /dev/null +++ b/vendor/github.com/xanzy/go-cloudstack/cloudstack/ExtFirewallService.go @@ -0,0 +1,17 @@ +// +// Copyright 2018, Sander van Harmelen +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// + +package cloudstack diff --git a/vendor/github.com/xanzy/go-cloudstack/cloudstack/ExtLoadBalancerService.go b/vendor/github.com/xanzy/go-cloudstack/cloudstack/ExtLoadBalancerService.go new file mode 100644 index 000000000..4676b3edc --- /dev/null +++ b/vendor/github.com/xanzy/go-cloudstack/cloudstack/ExtLoadBalancerService.go @@ -0,0 +1,17 @@ +// +// Copyright 2018, Sander van Harmelen +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// + +package cloudstack diff --git a/vendor/github.com/xanzy/go-cloudstack/cloudstack/ExternalDeviceService.go b/vendor/github.com/xanzy/go-cloudstack/cloudstack/ExternalDeviceService.go new file mode 100644 index 000000000..4676b3edc --- /dev/null +++ b/vendor/github.com/xanzy/go-cloudstack/cloudstack/ExternalDeviceService.go @@ -0,0 +1,17 @@ +// +// Copyright 2018, Sander van Harmelen +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// + +package cloudstack diff --git a/vendor/github.com/xanzy/go-cloudstack/cloudstack/FirewallService.go b/vendor/github.com/xanzy/go-cloudstack/cloudstack/FirewallService.go index 2a7ddbe18..4c4f85b6b 100644 --- a/vendor/github.com/xanzy/go-cloudstack/cloudstack/FirewallService.go +++ b/vendor/github.com/xanzy/go-cloudstack/cloudstack/FirewallService.go @@ -1,5 +1,5 @@ // -// Copyright 2016, Sander van Harmelen +// Copyright 2018, Sander van Harmelen // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -74,84 +74,324 @@ func convertFirewallServiceListResponse(b []byte) ([]byte, error) { return json.Marshal(rawList) } -type ListPortForwardingRulesParams struct { +type AddPaloAltoFirewallParams struct { p map[string]interface{} } -func (p *ListPortForwardingRulesParams) toURLValues() url.Values { +func (p *AddPaloAltoFirewallParams) toURLValues() url.Values { u := url.Values{} if p.p == nil { return u } - if v, found := p.p["account"]; found { - u.Set("account", v.(string)) + if v, found := p.p["networkdevicetype"]; found { + u.Set("networkdevicetype", v.(string)) } - if v, found := p.p["domainid"]; found { - u.Set("domainid", v.(string)) + if v, found := p.p["password"]; found { + u.Set("password", v.(string)) + } + if v, found := p.p["physicalnetworkid"]; found { + u.Set("physicalnetworkid", v.(string)) + } + if v, found := p.p["url"]; found { + u.Set("url", v.(string)) + } + if v, found := p.p["username"]; found { + u.Set("username", v.(string)) + } + return u +} + +func (p *AddPaloAltoFirewallParams) SetNetworkdevicetype(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["networkdevicetype"] = v + return +} + +func (p *AddPaloAltoFirewallParams) SetPassword(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["password"] = v + return +} + +func (p *AddPaloAltoFirewallParams) SetPhysicalnetworkid(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["physicalnetworkid"] = v + return +} + +func (p *AddPaloAltoFirewallParams) SetUrl(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["url"] = v + return +} + +func (p *AddPaloAltoFirewallParams) SetUsername(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["username"] = v + return +} + +// You should always use this function to get a new AddPaloAltoFirewallParams instance, +// as then you are sure you have configured all required params +func (s *FirewallService) NewAddPaloAltoFirewallParams(networkdevicetype string, password string, physicalnetworkid string, url string, username string) *AddPaloAltoFirewallParams { + p := &AddPaloAltoFirewallParams{} + p.p = make(map[string]interface{}) + p.p["networkdevicetype"] = networkdevicetype + p.p["password"] = password + p.p["physicalnetworkid"] = physicalnetworkid + p.p["url"] = url + p.p["username"] = username + return p +} + +// Adds a Palo Alto firewall device +func (s *FirewallService) AddPaloAltoFirewall(p *AddPaloAltoFirewallParams) (*AddPaloAltoFirewallResponse, error) { + resp, err := s.cs.newRequest("addPaloAltoFirewall", p.toURLValues()) + if err != nil { + return nil, err + } + + var r AddPaloAltoFirewallResponse + if err := json.Unmarshal(resp, &r); err != nil { + return nil, err + } + + // If we have a async client, we need to wait for the async result + if s.cs.async { + b, err := s.cs.GetAsyncJobResult(r.JobID, s.cs.timeout) + if err != nil { + if err == AsyncTimeoutErr { + return &r, err + } + return nil, err + } + + b, err = getRawValue(b) + if err != nil { + return nil, err + } + + b, err = convertFirewallServiceResponse(b) + if err != nil { + return nil, err + } + + if err := json.Unmarshal(b, &r); err != nil { + return nil, err + } + } + + return &r, nil +} + +type AddPaloAltoFirewallResponse struct { + JobID string `json:"jobid"` + Fwdevicecapacity int64 `json:"fwdevicecapacity"` + Fwdeviceid string `json:"fwdeviceid"` + Fwdevicename string `json:"fwdevicename"` + Fwdevicestate string `json:"fwdevicestate"` + Ipaddress string `json:"ipaddress"` + Numretries string `json:"numretries"` + Physicalnetworkid string `json:"physicalnetworkid"` + Privateinterface string `json:"privateinterface"` + Privatezone string `json:"privatezone"` + Provider string `json:"provider"` + Publicinterface string `json:"publicinterface"` + Publiczone string `json:"publiczone"` + Timeout string `json:"timeout"` + Usageinterface string `json:"usageinterface"` + Username string `json:"username"` + Zoneid string `json:"zoneid"` +} + +type ConfigurePaloAltoFirewallParams struct { + p map[string]interface{} +} + +func (p *ConfigurePaloAltoFirewallParams) toURLValues() url.Values { + u := url.Values{} + if p.p == nil { + return u + } + if v, found := p.p["fwdevicecapacity"]; found { + vv := strconv.FormatInt(v.(int64), 10) + u.Set("fwdevicecapacity", vv) + } + if v, found := p.p["fwdeviceid"]; found { + u.Set("fwdeviceid", v.(string)) + } + return u +} + +func (p *ConfigurePaloAltoFirewallParams) SetFwdevicecapacity(v int64) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["fwdevicecapacity"] = v + return +} + +func (p *ConfigurePaloAltoFirewallParams) SetFwdeviceid(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["fwdeviceid"] = v + return +} + +// You should always use this function to get a new ConfigurePaloAltoFirewallParams instance, +// as then you are sure you have configured all required params +func (s *FirewallService) NewConfigurePaloAltoFirewallParams(fwdeviceid string) *ConfigurePaloAltoFirewallParams { + p := &ConfigurePaloAltoFirewallParams{} + p.p = make(map[string]interface{}) + p.p["fwdeviceid"] = fwdeviceid + return p +} + +// Configures a Palo Alto firewall device +func (s *FirewallService) ConfigurePaloAltoFirewall(p *ConfigurePaloAltoFirewallParams) (*PaloAltoFirewallResponse, error) { + resp, err := s.cs.newRequest("configurePaloAltoFirewall", p.toURLValues()) + if err != nil { + return nil, err + } + + var r PaloAltoFirewallResponse + if err := json.Unmarshal(resp, &r); err != nil { + return nil, err + } + + // If we have a async client, we need to wait for the async result + if s.cs.async { + b, err := s.cs.GetAsyncJobResult(r.JobID, s.cs.timeout) + if err != nil { + if err == AsyncTimeoutErr { + return &r, err + } + return nil, err + } + + b, err = getRawValue(b) + if err != nil { + return nil, err + } + + b, err = convertFirewallServiceResponse(b) + if err != nil { + return nil, err + } + + if err := json.Unmarshal(b, &r); err != nil { + return nil, err + } + } + + return &r, nil +} + +type PaloAltoFirewallResponse struct { + JobID string `json:"jobid"` + Fwdevicecapacity int64 `json:"fwdevicecapacity"` + Fwdeviceid string `json:"fwdeviceid"` + Fwdevicename string `json:"fwdevicename"` + Fwdevicestate string `json:"fwdevicestate"` + Ipaddress string `json:"ipaddress"` + Numretries string `json:"numretries"` + Physicalnetworkid string `json:"physicalnetworkid"` + Privateinterface string `json:"privateinterface"` + Privatezone string `json:"privatezone"` + Provider string `json:"provider"` + Publicinterface string `json:"publicinterface"` + Publiczone string `json:"publiczone"` + Timeout string `json:"timeout"` + Usageinterface string `json:"usageinterface"` + Username string `json:"username"` + Zoneid string `json:"zoneid"` +} + +type CreateEgressFirewallRuleParams struct { + p map[string]interface{} +} + +func (p *CreateEgressFirewallRuleParams) toURLValues() url.Values { + u := url.Values{} + if p.p == nil { + return u + } + if v, found := p.p["cidrlist"]; found { + vv := strings.Join(v.([]string), ",") + u.Set("cidrlist", vv) + } + if v, found := p.p["destcidrlist"]; found { + vv := strings.Join(v.([]string), ",") + u.Set("destcidrlist", vv) + } + if v, found := p.p["endport"]; found { + vv := strconv.Itoa(v.(int)) + u.Set("endport", vv) } if v, found := p.p["fordisplay"]; found { vv := strconv.FormatBool(v.(bool)) u.Set("fordisplay", vv) } - if v, found := p.p["id"]; found { - u.Set("id", v.(string)) + if v, found := p.p["icmpcode"]; found { + vv := strconv.Itoa(v.(int)) + u.Set("icmpcode", vv) } - if v, found := p.p["ipaddressid"]; found { - u.Set("ipaddressid", v.(string)) - } - if v, found := p.p["isrecursive"]; found { - vv := strconv.FormatBool(v.(bool)) - u.Set("isrecursive", vv) - } - if v, found := p.p["keyword"]; found { - u.Set("keyword", v.(string)) - } - if v, found := p.p["listall"]; found { - vv := strconv.FormatBool(v.(bool)) - u.Set("listall", vv) + if v, found := p.p["icmptype"]; found { + vv := strconv.Itoa(v.(int)) + u.Set("icmptype", vv) } if v, found := p.p["networkid"]; found { u.Set("networkid", v.(string)) } - if v, found := p.p["page"]; found { + if v, found := p.p["protocol"]; found { + u.Set("protocol", v.(string)) + } + if v, found := p.p["startport"]; found { vv := strconv.Itoa(v.(int)) - u.Set("page", vv) + u.Set("startport", vv) } - if v, found := p.p["pagesize"]; found { - vv := strconv.Itoa(v.(int)) - u.Set("pagesize", vv) - } - if v, found := p.p["projectid"]; found { - u.Set("projectid", v.(string)) - } - if v, found := p.p["tags"]; found { - i := 0 - for k, vv := range v.(map[string]string) { - u.Set(fmt.Sprintf("tags[%d].key", i), k) - u.Set(fmt.Sprintf("tags[%d].value", i), vv) - i++ - } + if v, found := p.p["type"]; found { + u.Set("type", v.(string)) } return u } -func (p *ListPortForwardingRulesParams) SetAccount(v string) { +func (p *CreateEgressFirewallRuleParams) SetCidrlist(v []string) { if p.p == nil { p.p = make(map[string]interface{}) } - p.p["account"] = v + p.p["cidrlist"] = v return } -func (p *ListPortForwardingRulesParams) SetDomainid(v string) { +func (p *CreateEgressFirewallRuleParams) SetDestcidrlist(v []string) { if p.p == nil { p.p = make(map[string]interface{}) } - p.p["domainid"] = v + p.p["destcidrlist"] = v return } -func (p *ListPortForwardingRulesParams) SetFordisplay(v bool) { +func (p *CreateEgressFirewallRuleParams) SetEndport(v int) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["endport"] = v + return +} + +func (p *CreateEgressFirewallRuleParams) SetFordisplay(v bool) { if p.p == nil { p.p = make(map[string]interface{}) } @@ -159,47 +399,23 @@ func (p *ListPortForwardingRulesParams) SetFordisplay(v bool) { return } -func (p *ListPortForwardingRulesParams) SetId(v string) { +func (p *CreateEgressFirewallRuleParams) SetIcmpcode(v int) { if p.p == nil { p.p = make(map[string]interface{}) } - p.p["id"] = v + p.p["icmpcode"] = v return } -func (p *ListPortForwardingRulesParams) SetIpaddressid(v string) { +func (p *CreateEgressFirewallRuleParams) SetIcmptype(v int) { if p.p == nil { p.p = make(map[string]interface{}) } - p.p["ipaddressid"] = v + p.p["icmptype"] = v return } -func (p *ListPortForwardingRulesParams) SetIsrecursive(v bool) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["isrecursive"] = v - return -} - -func (p *ListPortForwardingRulesParams) SetKeyword(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["keyword"] = v - return -} - -func (p *ListPortForwardingRulesParams) SetListall(v bool) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["listall"] = v - return -} - -func (p *ListPortForwardingRulesParams) SetNetworkid(v string) { +func (p *CreateEgressFirewallRuleParams) SetNetworkid(v string) { if p.p == nil { p.p = make(map[string]interface{}) } @@ -207,132 +423,281 @@ func (p *ListPortForwardingRulesParams) SetNetworkid(v string) { return } -func (p *ListPortForwardingRulesParams) SetPage(v int) { +func (p *CreateEgressFirewallRuleParams) SetProtocol(v string) { if p.p == nil { p.p = make(map[string]interface{}) } - p.p["page"] = v + p.p["protocol"] = v return } -func (p *ListPortForwardingRulesParams) SetPagesize(v int) { +func (p *CreateEgressFirewallRuleParams) SetStartport(v int) { if p.p == nil { p.p = make(map[string]interface{}) } - p.p["pagesize"] = v + p.p["startport"] = v return } -func (p *ListPortForwardingRulesParams) SetProjectid(v string) { +func (p *CreateEgressFirewallRuleParams) SetType(v string) { if p.p == nil { p.p = make(map[string]interface{}) } - p.p["projectid"] = v + p.p["type"] = v return } -func (p *ListPortForwardingRulesParams) SetTags(v map[string]string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["tags"] = v - return -} - -// You should always use this function to get a new ListPortForwardingRulesParams instance, +// You should always use this function to get a new CreateEgressFirewallRuleParams instance, // as then you are sure you have configured all required params -func (s *FirewallService) NewListPortForwardingRulesParams() *ListPortForwardingRulesParams { - p := &ListPortForwardingRulesParams{} +func (s *FirewallService) NewCreateEgressFirewallRuleParams(networkid string, protocol string) *CreateEgressFirewallRuleParams { + p := &CreateEgressFirewallRuleParams{} p.p = make(map[string]interface{}) + p.p["networkid"] = networkid + p.p["protocol"] = protocol return p } -// This is a courtesy helper function, which in some cases may not work as expected! -func (s *FirewallService) GetPortForwardingRuleByID(id string, opts ...OptionFunc) (*PortForwardingRule, int, error) { - p := &ListPortForwardingRulesParams{} - p.p = make(map[string]interface{}) - - p.p["id"] = id - - for _, fn := range opts { - if err := fn(s.cs, p); err != nil { - return nil, -1, err - } - } - - l, err := s.ListPortForwardingRules(p) - if err != nil { - if strings.Contains(err.Error(), fmt.Sprintf( - "Invalid parameter id value=%s due to incorrect long value format, "+ - "or entity does not exist", id)) { - return nil, 0, fmt.Errorf("No match found for %s: %+v", id, l) - } - return nil, -1, err - } - - if l.Count == 0 { - return nil, l.Count, fmt.Errorf("No match found for %s: %+v", id, l) - } - - if l.Count == 1 { - return l.PortForwardingRules[0], l.Count, nil - } - return nil, l.Count, fmt.Errorf("There is more then one result for PortForwardingRule UUID: %s!", id) -} - -// Lists all port forwarding rules for an IP address. -func (s *FirewallService) ListPortForwardingRules(p *ListPortForwardingRulesParams) (*ListPortForwardingRulesResponse, error) { - resp, err := s.cs.newRequest("listPortForwardingRules", p.toURLValues()) +// Creates a egress firewall rule for a given network +func (s *FirewallService) CreateEgressFirewallRule(p *CreateEgressFirewallRuleParams) (*CreateEgressFirewallRuleResponse, error) { + resp, err := s.cs.newRequest("createEgressFirewallRule", p.toURLValues()) if err != nil { return nil, err } - resp, err = convertFirewallServiceResponse(resp) - if err != nil { - return nil, err - } - - var r ListPortForwardingRulesResponse + var r CreateEgressFirewallRuleResponse if err := json.Unmarshal(resp, &r); err != nil { return nil, err } + + // If we have a async client, we need to wait for the async result + if s.cs.async { + b, err := s.cs.GetAsyncJobResult(r.JobID, s.cs.timeout) + if err != nil { + if err == AsyncTimeoutErr { + return &r, err + } + return nil, err + } + + b, err = getRawValue(b) + if err != nil { + return nil, err + } + + b, err = convertFirewallServiceResponse(b) + if err != nil { + return nil, err + } + + if err := json.Unmarshal(b, &r); err != nil { + return nil, err + } + } + return &r, nil } -type ListPortForwardingRulesResponse struct { - Count int `json:"count"` - PortForwardingRules []*PortForwardingRule `json:"portforwardingrule"` +type CreateEgressFirewallRuleResponse struct { + JobID string `json:"jobid"` + Cidrlist string `json:"cidrlist"` + Destcidrlist string `json:"destcidrlist"` + Endport int `json:"endport"` + Fordisplay bool `json:"fordisplay"` + Icmpcode int `json:"icmpcode"` + Icmptype int `json:"icmptype"` + Id string `json:"id"` + Ipaddress string `json:"ipaddress"` + Ipaddressid string `json:"ipaddressid"` + Networkid string `json:"networkid"` + Protocol string `json:"protocol"` + Startport int `json:"startport"` + State string `json:"state"` + Tags []Tags `json:"tags"` } -type PortForwardingRule struct { - Cidrlist string `json:"cidrlist,omitempty"` - Fordisplay bool `json:"fordisplay,omitempty"` - Id string `json:"id,omitempty"` - Ipaddress string `json:"ipaddress,omitempty"` - Ipaddressid string `json:"ipaddressid,omitempty"` - Networkid string `json:"networkid,omitempty"` - Privateendport string `json:"privateendport,omitempty"` - Privateport string `json:"privateport,omitempty"` - Protocol string `json:"protocol,omitempty"` - Publicendport string `json:"publicendport,omitempty"` - Publicport string `json:"publicport,omitempty"` - State string `json:"state,omitempty"` - Tags []struct { - Account string `json:"account,omitempty"` - Customer string `json:"customer,omitempty"` - Domain string `json:"domain,omitempty"` - Domainid string `json:"domainid,omitempty"` - Key string `json:"key,omitempty"` - Project string `json:"project,omitempty"` - Projectid string `json:"projectid,omitempty"` - Resourceid string `json:"resourceid,omitempty"` - Resourcetype string `json:"resourcetype,omitempty"` - Value string `json:"value,omitempty"` - } `json:"tags,omitempty"` - Virtualmachinedisplayname string `json:"virtualmachinedisplayname,omitempty"` - Virtualmachineid string `json:"virtualmachineid,omitempty"` - Virtualmachinename string `json:"virtualmachinename,omitempty"` - Vmguestip string `json:"vmguestip,omitempty"` +type CreateFirewallRuleParams struct { + p map[string]interface{} +} + +func (p *CreateFirewallRuleParams) toURLValues() url.Values { + u := url.Values{} + if p.p == nil { + return u + } + if v, found := p.p["cidrlist"]; found { + vv := strings.Join(v.([]string), ",") + u.Set("cidrlist", vv) + } + if v, found := p.p["endport"]; found { + vv := strconv.Itoa(v.(int)) + u.Set("endport", vv) + } + if v, found := p.p["fordisplay"]; found { + vv := strconv.FormatBool(v.(bool)) + u.Set("fordisplay", vv) + } + if v, found := p.p["icmpcode"]; found { + vv := strconv.Itoa(v.(int)) + u.Set("icmpcode", vv) + } + if v, found := p.p["icmptype"]; found { + vv := strconv.Itoa(v.(int)) + u.Set("icmptype", vv) + } + if v, found := p.p["ipaddressid"]; found { + u.Set("ipaddressid", v.(string)) + } + if v, found := p.p["protocol"]; found { + u.Set("protocol", v.(string)) + } + if v, found := p.p["startport"]; found { + vv := strconv.Itoa(v.(int)) + u.Set("startport", vv) + } + if v, found := p.p["type"]; found { + u.Set("type", v.(string)) + } + return u +} + +func (p *CreateFirewallRuleParams) SetCidrlist(v []string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["cidrlist"] = v + return +} + +func (p *CreateFirewallRuleParams) SetEndport(v int) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["endport"] = v + return +} + +func (p *CreateFirewallRuleParams) SetFordisplay(v bool) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["fordisplay"] = v + return +} + +func (p *CreateFirewallRuleParams) SetIcmpcode(v int) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["icmpcode"] = v + return +} + +func (p *CreateFirewallRuleParams) SetIcmptype(v int) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["icmptype"] = v + return +} + +func (p *CreateFirewallRuleParams) SetIpaddressid(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["ipaddressid"] = v + return +} + +func (p *CreateFirewallRuleParams) SetProtocol(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["protocol"] = v + return +} + +func (p *CreateFirewallRuleParams) SetStartport(v int) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["startport"] = v + return +} + +func (p *CreateFirewallRuleParams) SetType(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["type"] = v + return +} + +// You should always use this function to get a new CreateFirewallRuleParams instance, +// as then you are sure you have configured all required params +func (s *FirewallService) NewCreateFirewallRuleParams(ipaddressid string, protocol string) *CreateFirewallRuleParams { + p := &CreateFirewallRuleParams{} + p.p = make(map[string]interface{}) + p.p["ipaddressid"] = ipaddressid + p.p["protocol"] = protocol + return p +} + +// Creates a firewall rule for a given IP address +func (s *FirewallService) CreateFirewallRule(p *CreateFirewallRuleParams) (*CreateFirewallRuleResponse, error) { + resp, err := s.cs.newRequest("createFirewallRule", p.toURLValues()) + if err != nil { + return nil, err + } + + var r CreateFirewallRuleResponse + if err := json.Unmarshal(resp, &r); err != nil { + return nil, err + } + + // If we have a async client, we need to wait for the async result + if s.cs.async { + b, err := s.cs.GetAsyncJobResult(r.JobID, s.cs.timeout) + if err != nil { + if err == AsyncTimeoutErr { + return &r, err + } + return nil, err + } + + b, err = getRawValue(b) + if err != nil { + return nil, err + } + + b, err = convertFirewallServiceResponse(b) + if err != nil { + return nil, err + } + + if err := json.Unmarshal(b, &r); err != nil { + return nil, err + } + } + + return &r, nil +} + +type CreateFirewallRuleResponse struct { + JobID string `json:"jobid"` + Cidrlist string `json:"cidrlist"` + Destcidrlist string `json:"destcidrlist"` + Endport int `json:"endport"` + Fordisplay bool `json:"fordisplay"` + Icmpcode int `json:"icmpcode"` + Icmptype int `json:"icmptype"` + Id string `json:"id"` + Ipaddress string `json:"ipaddress"` + Ipaddressid string `json:"ipaddressid"` + Networkid string `json:"networkid"` + Protocol string `json:"protocol"` + Startport int `json:"startport"` + State string `json:"state"` + Tags []Tags `json:"tags"` } type CreatePortForwardingRuleParams struct { @@ -506,11 +871,6 @@ func (s *FirewallService) CreatePortForwardingRule(p *CreatePortForwardingRulePa return nil, err } - resp, err = convertFirewallServiceResponse(resp) - if err != nil { - return nil, err - } - var r CreatePortForwardingRuleResponse if err := json.Unmarshal(resp, &r); err != nil { return nil, err @@ -540,1140 +900,29 @@ func (s *FirewallService) CreatePortForwardingRule(p *CreatePortForwardingRulePa return nil, err } } + return &r, nil } type CreatePortForwardingRuleResponse struct { - JobID string `json:"jobid,omitempty"` - Cidrlist string `json:"cidrlist,omitempty"` - Fordisplay bool `json:"fordisplay,omitempty"` - Id string `json:"id,omitempty"` - Ipaddress string `json:"ipaddress,omitempty"` - Ipaddressid string `json:"ipaddressid,omitempty"` - Networkid string `json:"networkid,omitempty"` - Privateendport string `json:"privateendport,omitempty"` - Privateport string `json:"privateport,omitempty"` - Protocol string `json:"protocol,omitempty"` - Publicendport string `json:"publicendport,omitempty"` - Publicport string `json:"publicport,omitempty"` - State string `json:"state,omitempty"` - Tags []struct { - Account string `json:"account,omitempty"` - Customer string `json:"customer,omitempty"` - Domain string `json:"domain,omitempty"` - Domainid string `json:"domainid,omitempty"` - Key string `json:"key,omitempty"` - Project string `json:"project,omitempty"` - Projectid string `json:"projectid,omitempty"` - Resourceid string `json:"resourceid,omitempty"` - Resourcetype string `json:"resourcetype,omitempty"` - Value string `json:"value,omitempty"` - } `json:"tags,omitempty"` - Virtualmachinedisplayname string `json:"virtualmachinedisplayname,omitempty"` - Virtualmachineid string `json:"virtualmachineid,omitempty"` - Virtualmachinename string `json:"virtualmachinename,omitempty"` - Vmguestip string `json:"vmguestip,omitempty"` -} - -type DeletePortForwardingRuleParams struct { - p map[string]interface{} -} - -func (p *DeletePortForwardingRuleParams) toURLValues() url.Values { - u := url.Values{} - if p.p == nil { - return u - } - if v, found := p.p["id"]; found { - u.Set("id", v.(string)) - } - return u -} - -func (p *DeletePortForwardingRuleParams) SetId(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["id"] = v - return -} - -// You should always use this function to get a new DeletePortForwardingRuleParams instance, -// as then you are sure you have configured all required params -func (s *FirewallService) NewDeletePortForwardingRuleParams(id string) *DeletePortForwardingRuleParams { - p := &DeletePortForwardingRuleParams{} - p.p = make(map[string]interface{}) - p.p["id"] = id - return p -} - -// Deletes a port forwarding rule -func (s *FirewallService) DeletePortForwardingRule(p *DeletePortForwardingRuleParams) (*DeletePortForwardingRuleResponse, error) { - resp, err := s.cs.newRequest("deletePortForwardingRule", p.toURLValues()) - if err != nil { - return nil, err - } - - resp, err = convertFirewallServiceResponse(resp) - if err != nil { - return nil, err - } - - var r DeletePortForwardingRuleResponse - if err := json.Unmarshal(resp, &r); err != nil { - return nil, err - } - - // If we have a async client, we need to wait for the async result - if s.cs.async { - b, err := s.cs.GetAsyncJobResult(r.JobID, s.cs.timeout) - if err != nil { - if err == AsyncTimeoutErr { - return &r, err - } - return nil, err - } - - b, err = convertFirewallServiceResponse(b) - if err != nil { - return nil, err - } - - if err := json.Unmarshal(b, &r); err != nil { - return nil, err - } - } - return &r, nil -} - -type DeletePortForwardingRuleResponse struct { - JobID string `json:"jobid,omitempty"` - Displaytext string `json:"displaytext,omitempty"` - Success bool `json:"success,omitempty"` -} - -type UpdatePortForwardingRuleParams struct { - p map[string]interface{} -} - -func (p *UpdatePortForwardingRuleParams) toURLValues() url.Values { - u := url.Values{} - if p.p == nil { - return u - } - if v, found := p.p["customid"]; found { - u.Set("customid", v.(string)) - } - if v, found := p.p["fordisplay"]; found { - vv := strconv.FormatBool(v.(bool)) - u.Set("fordisplay", vv) - } - if v, found := p.p["id"]; found { - u.Set("id", v.(string)) - } - if v, found := p.p["privateport"]; found { - vv := strconv.Itoa(v.(int)) - u.Set("privateport", vv) - } - if v, found := p.p["virtualmachineid"]; found { - u.Set("virtualmachineid", v.(string)) - } - if v, found := p.p["vmguestip"]; found { - u.Set("vmguestip", v.(string)) - } - return u -} - -func (p *UpdatePortForwardingRuleParams) SetCustomid(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["customid"] = v - return -} - -func (p *UpdatePortForwardingRuleParams) SetFordisplay(v bool) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["fordisplay"] = v - return -} - -func (p *UpdatePortForwardingRuleParams) SetId(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["id"] = v - return -} - -func (p *UpdatePortForwardingRuleParams) SetPrivateport(v int) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["privateport"] = v - return -} - -func (p *UpdatePortForwardingRuleParams) SetVirtualmachineid(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["virtualmachineid"] = v - return -} - -func (p *UpdatePortForwardingRuleParams) SetVmguestip(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["vmguestip"] = v - return -} - -// You should always use this function to get a new UpdatePortForwardingRuleParams instance, -// as then you are sure you have configured all required params -func (s *FirewallService) NewUpdatePortForwardingRuleParams(id string) *UpdatePortForwardingRuleParams { - p := &UpdatePortForwardingRuleParams{} - p.p = make(map[string]interface{}) - p.p["id"] = id - return p -} - -// Updates a port forwarding rule. Only the private port and the virtual machine can be updated. -func (s *FirewallService) UpdatePortForwardingRule(p *UpdatePortForwardingRuleParams) (*UpdatePortForwardingRuleResponse, error) { - resp, err := s.cs.newRequest("updatePortForwardingRule", p.toURLValues()) - if err != nil { - return nil, err - } - - resp, err = convertFirewallServiceResponse(resp) - if err != nil { - return nil, err - } - - var r UpdatePortForwardingRuleResponse - if err := json.Unmarshal(resp, &r); err != nil { - return nil, err - } - - // If we have a async client, we need to wait for the async result - if s.cs.async { - b, err := s.cs.GetAsyncJobResult(r.JobID, s.cs.timeout) - if err != nil { - if err == AsyncTimeoutErr { - return &r, err - } - return nil, err - } - - b, err = getRawValue(b) - if err != nil { - return nil, err - } - - b, err = convertFirewallServiceResponse(b) - if err != nil { - return nil, err - } - - if err := json.Unmarshal(b, &r); err != nil { - return nil, err - } - } - return &r, nil -} - -type UpdatePortForwardingRuleResponse struct { - JobID string `json:"jobid,omitempty"` - Cidrlist string `json:"cidrlist,omitempty"` - Fordisplay bool `json:"fordisplay,omitempty"` - Id string `json:"id,omitempty"` - Ipaddress string `json:"ipaddress,omitempty"` - Ipaddressid string `json:"ipaddressid,omitempty"` - Networkid string `json:"networkid,omitempty"` - Privateendport string `json:"privateendport,omitempty"` - Privateport string `json:"privateport,omitempty"` - Protocol string `json:"protocol,omitempty"` - Publicendport string `json:"publicendport,omitempty"` - Publicport string `json:"publicport,omitempty"` - State string `json:"state,omitempty"` - Tags []struct { - Account string `json:"account,omitempty"` - Customer string `json:"customer,omitempty"` - Domain string `json:"domain,omitempty"` - Domainid string `json:"domainid,omitempty"` - Key string `json:"key,omitempty"` - Project string `json:"project,omitempty"` - Projectid string `json:"projectid,omitempty"` - Resourceid string `json:"resourceid,omitempty"` - Resourcetype string `json:"resourcetype,omitempty"` - Value string `json:"value,omitempty"` - } `json:"tags,omitempty"` - Virtualmachinedisplayname string `json:"virtualmachinedisplayname,omitempty"` - Virtualmachineid string `json:"virtualmachineid,omitempty"` - Virtualmachinename string `json:"virtualmachinename,omitempty"` - Vmguestip string `json:"vmguestip,omitempty"` -} - -type CreateFirewallRuleParams struct { - p map[string]interface{} -} - -func (p *CreateFirewallRuleParams) toURLValues() url.Values { - u := url.Values{} - if p.p == nil { - return u - } - if v, found := p.p["cidrlist"]; found { - vv := strings.Join(v.([]string), ",") - u.Set("cidrlist", vv) - } - if v, found := p.p["endport"]; found { - vv := strconv.Itoa(v.(int)) - u.Set("endport", vv) - } - if v, found := p.p["fordisplay"]; found { - vv := strconv.FormatBool(v.(bool)) - u.Set("fordisplay", vv) - } - if v, found := p.p["icmpcode"]; found { - vv := strconv.Itoa(v.(int)) - u.Set("icmpcode", vv) - } - if v, found := p.p["icmptype"]; found { - vv := strconv.Itoa(v.(int)) - u.Set("icmptype", vv) - } - if v, found := p.p["ipaddressid"]; found { - u.Set("ipaddressid", v.(string)) - } - if v, found := p.p["protocol"]; found { - u.Set("protocol", v.(string)) - } - if v, found := p.p["startport"]; found { - vv := strconv.Itoa(v.(int)) - u.Set("startport", vv) - } - if v, found := p.p["type"]; found { - u.Set("type", v.(string)) - } - return u -} - -func (p *CreateFirewallRuleParams) SetCidrlist(v []string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["cidrlist"] = v - return -} - -func (p *CreateFirewallRuleParams) SetEndport(v int) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["endport"] = v - return -} - -func (p *CreateFirewallRuleParams) SetFordisplay(v bool) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["fordisplay"] = v - return -} - -func (p *CreateFirewallRuleParams) SetIcmpcode(v int) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["icmpcode"] = v - return -} - -func (p *CreateFirewallRuleParams) SetIcmptype(v int) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["icmptype"] = v - return -} - -func (p *CreateFirewallRuleParams) SetIpaddressid(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["ipaddressid"] = v - return -} - -func (p *CreateFirewallRuleParams) SetProtocol(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["protocol"] = v - return -} - -func (p *CreateFirewallRuleParams) SetStartport(v int) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["startport"] = v - return -} - -func (p *CreateFirewallRuleParams) SetType(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["type"] = v - return -} - -// You should always use this function to get a new CreateFirewallRuleParams instance, -// as then you are sure you have configured all required params -func (s *FirewallService) NewCreateFirewallRuleParams(ipaddressid string, protocol string) *CreateFirewallRuleParams { - p := &CreateFirewallRuleParams{} - p.p = make(map[string]interface{}) - p.p["ipaddressid"] = ipaddressid - p.p["protocol"] = protocol - return p -} - -// Creates a firewall rule for a given IP address -func (s *FirewallService) CreateFirewallRule(p *CreateFirewallRuleParams) (*CreateFirewallRuleResponse, error) { - resp, err := s.cs.newRequest("createFirewallRule", p.toURLValues()) - if err != nil { - return nil, err - } - - resp, err = convertFirewallServiceResponse(resp) - if err != nil { - return nil, err - } - - var r CreateFirewallRuleResponse - if err := json.Unmarshal(resp, &r); err != nil { - return nil, err - } - - // If we have a async client, we need to wait for the async result - if s.cs.async { - b, err := s.cs.GetAsyncJobResult(r.JobID, s.cs.timeout) - if err != nil { - if err == AsyncTimeoutErr { - return &r, err - } - return nil, err - } - - b, err = getRawValue(b) - if err != nil { - return nil, err - } - - b, err = convertFirewallServiceResponse(b) - if err != nil { - return nil, err - } - - if err := json.Unmarshal(b, &r); err != nil { - return nil, err - } - } - return &r, nil -} - -type CreateFirewallRuleResponse struct { - JobID string `json:"jobid,omitempty"` - Cidrlist string `json:"cidrlist,omitempty"` - Endport int `json:"endport,omitempty"` - Fordisplay bool `json:"fordisplay,omitempty"` - Icmpcode int `json:"icmpcode,omitempty"` - Icmptype int `json:"icmptype,omitempty"` - Id string `json:"id,omitempty"` - Ipaddress string `json:"ipaddress,omitempty"` - Ipaddressid string `json:"ipaddressid,omitempty"` - Networkid string `json:"networkid,omitempty"` - Protocol string `json:"protocol,omitempty"` - Startport int `json:"startport,omitempty"` - State string `json:"state,omitempty"` - Tags []struct { - Account string `json:"account,omitempty"` - Customer string `json:"customer,omitempty"` - Domain string `json:"domain,omitempty"` - Domainid string `json:"domainid,omitempty"` - Key string `json:"key,omitempty"` - Project string `json:"project,omitempty"` - Projectid string `json:"projectid,omitempty"` - Resourceid string `json:"resourceid,omitempty"` - Resourcetype string `json:"resourcetype,omitempty"` - Value string `json:"value,omitempty"` - } `json:"tags,omitempty"` -} - -type DeleteFirewallRuleParams struct { - p map[string]interface{} -} - -func (p *DeleteFirewallRuleParams) toURLValues() url.Values { - u := url.Values{} - if p.p == nil { - return u - } - if v, found := p.p["id"]; found { - u.Set("id", v.(string)) - } - return u -} - -func (p *DeleteFirewallRuleParams) SetId(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["id"] = v - return -} - -// You should always use this function to get a new DeleteFirewallRuleParams instance, -// as then you are sure you have configured all required params -func (s *FirewallService) NewDeleteFirewallRuleParams(id string) *DeleteFirewallRuleParams { - p := &DeleteFirewallRuleParams{} - p.p = make(map[string]interface{}) - p.p["id"] = id - return p -} - -// Deletes a firewall rule -func (s *FirewallService) DeleteFirewallRule(p *DeleteFirewallRuleParams) (*DeleteFirewallRuleResponse, error) { - resp, err := s.cs.newRequest("deleteFirewallRule", p.toURLValues()) - if err != nil { - return nil, err - } - - resp, err = convertFirewallServiceResponse(resp) - if err != nil { - return nil, err - } - - var r DeleteFirewallRuleResponse - if err := json.Unmarshal(resp, &r); err != nil { - return nil, err - } - - // If we have a async client, we need to wait for the async result - if s.cs.async { - b, err := s.cs.GetAsyncJobResult(r.JobID, s.cs.timeout) - if err != nil { - if err == AsyncTimeoutErr { - return &r, err - } - return nil, err - } - - b, err = convertFirewallServiceResponse(b) - if err != nil { - return nil, err - } - - if err := json.Unmarshal(b, &r); err != nil { - return nil, err - } - } - return &r, nil -} - -type DeleteFirewallRuleResponse struct { - JobID string `json:"jobid,omitempty"` - Displaytext string `json:"displaytext,omitempty"` - Success bool `json:"success,omitempty"` -} - -type ListFirewallRulesParams struct { - p map[string]interface{} -} - -func (p *ListFirewallRulesParams) toURLValues() url.Values { - u := url.Values{} - if p.p == nil { - return u - } - if v, found := p.p["account"]; found { - u.Set("account", v.(string)) - } - if v, found := p.p["domainid"]; found { - u.Set("domainid", v.(string)) - } - if v, found := p.p["fordisplay"]; found { - vv := strconv.FormatBool(v.(bool)) - u.Set("fordisplay", vv) - } - if v, found := p.p["id"]; found { - u.Set("id", v.(string)) - } - if v, found := p.p["ipaddressid"]; found { - u.Set("ipaddressid", v.(string)) - } - if v, found := p.p["isrecursive"]; found { - vv := strconv.FormatBool(v.(bool)) - u.Set("isrecursive", vv) - } - if v, found := p.p["keyword"]; found { - u.Set("keyword", v.(string)) - } - if v, found := p.p["listall"]; found { - vv := strconv.FormatBool(v.(bool)) - u.Set("listall", vv) - } - if v, found := p.p["networkid"]; found { - u.Set("networkid", v.(string)) - } - if v, found := p.p["page"]; found { - vv := strconv.Itoa(v.(int)) - u.Set("page", vv) - } - if v, found := p.p["pagesize"]; found { - vv := strconv.Itoa(v.(int)) - u.Set("pagesize", vv) - } - if v, found := p.p["projectid"]; found { - u.Set("projectid", v.(string)) - } - if v, found := p.p["tags"]; found { - i := 0 - for k, vv := range v.(map[string]string) { - u.Set(fmt.Sprintf("tags[%d].key", i), k) - u.Set(fmt.Sprintf("tags[%d].value", i), vv) - i++ - } - } - return u -} - -func (p *ListFirewallRulesParams) SetAccount(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["account"] = v - return -} - -func (p *ListFirewallRulesParams) SetDomainid(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["domainid"] = v - return -} - -func (p *ListFirewallRulesParams) SetFordisplay(v bool) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["fordisplay"] = v - return -} - -func (p *ListFirewallRulesParams) SetId(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["id"] = v - return -} - -func (p *ListFirewallRulesParams) SetIpaddressid(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["ipaddressid"] = v - return -} - -func (p *ListFirewallRulesParams) SetIsrecursive(v bool) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["isrecursive"] = v - return -} - -func (p *ListFirewallRulesParams) SetKeyword(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["keyword"] = v - return -} - -func (p *ListFirewallRulesParams) SetListall(v bool) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["listall"] = v - return -} - -func (p *ListFirewallRulesParams) SetNetworkid(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["networkid"] = v - return -} - -func (p *ListFirewallRulesParams) SetPage(v int) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["page"] = v - return -} - -func (p *ListFirewallRulesParams) SetPagesize(v int) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["pagesize"] = v - return -} - -func (p *ListFirewallRulesParams) SetProjectid(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["projectid"] = v - return -} - -func (p *ListFirewallRulesParams) SetTags(v map[string]string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["tags"] = v - return -} - -// You should always use this function to get a new ListFirewallRulesParams instance, -// as then you are sure you have configured all required params -func (s *FirewallService) NewListFirewallRulesParams() *ListFirewallRulesParams { - p := &ListFirewallRulesParams{} - p.p = make(map[string]interface{}) - return p -} - -// This is a courtesy helper function, which in some cases may not work as expected! -func (s *FirewallService) GetFirewallRuleByID(id string, opts ...OptionFunc) (*FirewallRule, int, error) { - p := &ListFirewallRulesParams{} - p.p = make(map[string]interface{}) - - p.p["id"] = id - - for _, fn := range opts { - if err := fn(s.cs, p); err != nil { - return nil, -1, err - } - } - - l, err := s.ListFirewallRules(p) - if err != nil { - if strings.Contains(err.Error(), fmt.Sprintf( - "Invalid parameter id value=%s due to incorrect long value format, "+ - "or entity does not exist", id)) { - return nil, 0, fmt.Errorf("No match found for %s: %+v", id, l) - } - return nil, -1, err - } - - if l.Count == 0 { - return nil, l.Count, fmt.Errorf("No match found for %s: %+v", id, l) - } - - if l.Count == 1 { - return l.FirewallRules[0], l.Count, nil - } - return nil, l.Count, fmt.Errorf("There is more then one result for FirewallRule UUID: %s!", id) -} - -// Lists all firewall rules for an IP address. -func (s *FirewallService) ListFirewallRules(p *ListFirewallRulesParams) (*ListFirewallRulesResponse, error) { - resp, err := s.cs.newRequest("listFirewallRules", p.toURLValues()) - if err != nil { - return nil, err - } - - resp, err = convertFirewallServiceResponse(resp) - if err != nil { - return nil, err - } - - var r ListFirewallRulesResponse - if err := json.Unmarshal(resp, &r); err != nil { - return nil, err - } - return &r, nil -} - -type ListFirewallRulesResponse struct { - Count int `json:"count"` - FirewallRules []*FirewallRule `json:"firewallrule"` -} - -type FirewallRule struct { - Cidrlist string `json:"cidrlist,omitempty"` - Endport int `json:"endport,omitempty"` - Fordisplay bool `json:"fordisplay,omitempty"` - Icmpcode int `json:"icmpcode,omitempty"` - Icmptype int `json:"icmptype,omitempty"` - Id string `json:"id,omitempty"` - Ipaddress string `json:"ipaddress,omitempty"` - Ipaddressid string `json:"ipaddressid,omitempty"` - Networkid string `json:"networkid,omitempty"` - Protocol string `json:"protocol,omitempty"` - Startport int `json:"startport,omitempty"` - State string `json:"state,omitempty"` - Tags []struct { - Account string `json:"account,omitempty"` - Customer string `json:"customer,omitempty"` - Domain string `json:"domain,omitempty"` - Domainid string `json:"domainid,omitempty"` - Key string `json:"key,omitempty"` - Project string `json:"project,omitempty"` - Projectid string `json:"projectid,omitempty"` - Resourceid string `json:"resourceid,omitempty"` - Resourcetype string `json:"resourcetype,omitempty"` - Value string `json:"value,omitempty"` - } `json:"tags,omitempty"` -} - -type UpdateFirewallRuleParams struct { - p map[string]interface{} -} - -func (p *UpdateFirewallRuleParams) toURLValues() url.Values { - u := url.Values{} - if p.p == nil { - return u - } - if v, found := p.p["customid"]; found { - u.Set("customid", v.(string)) - } - if v, found := p.p["fordisplay"]; found { - vv := strconv.FormatBool(v.(bool)) - u.Set("fordisplay", vv) - } - if v, found := p.p["id"]; found { - u.Set("id", v.(string)) - } - return u -} - -func (p *UpdateFirewallRuleParams) SetCustomid(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["customid"] = v - return -} - -func (p *UpdateFirewallRuleParams) SetFordisplay(v bool) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["fordisplay"] = v - return -} - -func (p *UpdateFirewallRuleParams) SetId(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["id"] = v - return -} - -// You should always use this function to get a new UpdateFirewallRuleParams instance, -// as then you are sure you have configured all required params -func (s *FirewallService) NewUpdateFirewallRuleParams(id string) *UpdateFirewallRuleParams { - p := &UpdateFirewallRuleParams{} - p.p = make(map[string]interface{}) - p.p["id"] = id - return p -} - -// Updates firewall rule -func (s *FirewallService) UpdateFirewallRule(p *UpdateFirewallRuleParams) (*UpdateFirewallRuleResponse, error) { - resp, err := s.cs.newRequest("updateFirewallRule", p.toURLValues()) - if err != nil { - return nil, err - } - - resp, err = convertFirewallServiceResponse(resp) - if err != nil { - return nil, err - } - - var r UpdateFirewallRuleResponse - if err := json.Unmarshal(resp, &r); err != nil { - return nil, err - } - - // If we have a async client, we need to wait for the async result - if s.cs.async { - b, err := s.cs.GetAsyncJobResult(r.JobID, s.cs.timeout) - if err != nil { - if err == AsyncTimeoutErr { - return &r, err - } - return nil, err - } - - b, err = getRawValue(b) - if err != nil { - return nil, err - } - - b, err = convertFirewallServiceResponse(b) - if err != nil { - return nil, err - } - - if err := json.Unmarshal(b, &r); err != nil { - return nil, err - } - } - return &r, nil -} - -type UpdateFirewallRuleResponse struct { - JobID string `json:"jobid,omitempty"` - Cidrlist string `json:"cidrlist,omitempty"` - Endport int `json:"endport,omitempty"` - Fordisplay bool `json:"fordisplay,omitempty"` - Icmpcode int `json:"icmpcode,omitempty"` - Icmptype int `json:"icmptype,omitempty"` - Id string `json:"id,omitempty"` - Ipaddress string `json:"ipaddress,omitempty"` - Ipaddressid string `json:"ipaddressid,omitempty"` - Networkid string `json:"networkid,omitempty"` - Protocol string `json:"protocol,omitempty"` - Startport int `json:"startport,omitempty"` - State string `json:"state,omitempty"` - Tags []struct { - Account string `json:"account,omitempty"` - Customer string `json:"customer,omitempty"` - Domain string `json:"domain,omitempty"` - Domainid string `json:"domainid,omitempty"` - Key string `json:"key,omitempty"` - Project string `json:"project,omitempty"` - Projectid string `json:"projectid,omitempty"` - Resourceid string `json:"resourceid,omitempty"` - Resourcetype string `json:"resourcetype,omitempty"` - Value string `json:"value,omitempty"` - } `json:"tags,omitempty"` -} - -type CreateEgressFirewallRuleParams struct { - p map[string]interface{} -} - -func (p *CreateEgressFirewallRuleParams) toURLValues() url.Values { - u := url.Values{} - if p.p == nil { - return u - } - if v, found := p.p["cidrlist"]; found { - vv := strings.Join(v.([]string), ",") - u.Set("cidrlist", vv) - } - if v, found := p.p["endport"]; found { - vv := strconv.Itoa(v.(int)) - u.Set("endport", vv) - } - if v, found := p.p["fordisplay"]; found { - vv := strconv.FormatBool(v.(bool)) - u.Set("fordisplay", vv) - } - if v, found := p.p["icmpcode"]; found { - vv := strconv.Itoa(v.(int)) - u.Set("icmpcode", vv) - } - if v, found := p.p["icmptype"]; found { - vv := strconv.Itoa(v.(int)) - u.Set("icmptype", vv) - } - if v, found := p.p["networkid"]; found { - u.Set("networkid", v.(string)) - } - if v, found := p.p["protocol"]; found { - u.Set("protocol", v.(string)) - } - if v, found := p.p["startport"]; found { - vv := strconv.Itoa(v.(int)) - u.Set("startport", vv) - } - if v, found := p.p["type"]; found { - u.Set("type", v.(string)) - } - return u -} - -func (p *CreateEgressFirewallRuleParams) SetCidrlist(v []string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["cidrlist"] = v - return -} - -func (p *CreateEgressFirewallRuleParams) SetEndport(v int) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["endport"] = v - return -} - -func (p *CreateEgressFirewallRuleParams) SetFordisplay(v bool) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["fordisplay"] = v - return -} - -func (p *CreateEgressFirewallRuleParams) SetIcmpcode(v int) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["icmpcode"] = v - return -} - -func (p *CreateEgressFirewallRuleParams) SetIcmptype(v int) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["icmptype"] = v - return -} - -func (p *CreateEgressFirewallRuleParams) SetNetworkid(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["networkid"] = v - return -} - -func (p *CreateEgressFirewallRuleParams) SetProtocol(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["protocol"] = v - return -} - -func (p *CreateEgressFirewallRuleParams) SetStartport(v int) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["startport"] = v - return -} - -func (p *CreateEgressFirewallRuleParams) SetType(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["type"] = v - return -} - -// You should always use this function to get a new CreateEgressFirewallRuleParams instance, -// as then you are sure you have configured all required params -func (s *FirewallService) NewCreateEgressFirewallRuleParams(networkid string, protocol string) *CreateEgressFirewallRuleParams { - p := &CreateEgressFirewallRuleParams{} - p.p = make(map[string]interface{}) - p.p["networkid"] = networkid - p.p["protocol"] = protocol - return p -} - -// Creates a egress firewall rule for a given network -func (s *FirewallService) CreateEgressFirewallRule(p *CreateEgressFirewallRuleParams) (*CreateEgressFirewallRuleResponse, error) { - resp, err := s.cs.newRequest("createEgressFirewallRule", p.toURLValues()) - if err != nil { - return nil, err - } - - resp, err = convertFirewallServiceResponse(resp) - if err != nil { - return nil, err - } - - var r CreateEgressFirewallRuleResponse - if err := json.Unmarshal(resp, &r); err != nil { - return nil, err - } - - // If we have a async client, we need to wait for the async result - if s.cs.async { - b, err := s.cs.GetAsyncJobResult(r.JobID, s.cs.timeout) - if err != nil { - if err == AsyncTimeoutErr { - return &r, err - } - return nil, err - } - - b, err = getRawValue(b) - if err != nil { - return nil, err - } - - b, err = convertFirewallServiceResponse(b) - if err != nil { - return nil, err - } - - if err := json.Unmarshal(b, &r); err != nil { - return nil, err - } - } - return &r, nil -} - -type CreateEgressFirewallRuleResponse struct { - JobID string `json:"jobid,omitempty"` - Cidrlist string `json:"cidrlist,omitempty"` - Endport int `json:"endport,omitempty"` - Fordisplay bool `json:"fordisplay,omitempty"` - Icmpcode int `json:"icmpcode,omitempty"` - Icmptype int `json:"icmptype,omitempty"` - Id string `json:"id,omitempty"` - Ipaddress string `json:"ipaddress,omitempty"` - Ipaddressid string `json:"ipaddressid,omitempty"` - Networkid string `json:"networkid,omitempty"` - Protocol string `json:"protocol,omitempty"` - Startport int `json:"startport,omitempty"` - State string `json:"state,omitempty"` - Tags []struct { - Account string `json:"account,omitempty"` - Customer string `json:"customer,omitempty"` - Domain string `json:"domain,omitempty"` - Domainid string `json:"domainid,omitempty"` - Key string `json:"key,omitempty"` - Project string `json:"project,omitempty"` - Projectid string `json:"projectid,omitempty"` - Resourceid string `json:"resourceid,omitempty"` - Resourcetype string `json:"resourcetype,omitempty"` - Value string `json:"value,omitempty"` - } `json:"tags,omitempty"` + JobID string `json:"jobid"` + Cidrlist string `json:"cidrlist"` + Fordisplay bool `json:"fordisplay"` + Id string `json:"id"` + Ipaddress string `json:"ipaddress"` + Ipaddressid string `json:"ipaddressid"` + Networkid string `json:"networkid"` + Privateendport string `json:"privateendport"` + Privateport string `json:"privateport"` + Protocol string `json:"protocol"` + Publicendport string `json:"publicendport"` + Publicport string `json:"publicport"` + State string `json:"state"` + Tags []Tags `json:"tags"` + Virtualmachinedisplayname string `json:"virtualmachinedisplayname"` + Virtualmachineid string `json:"virtualmachineid"` + Virtualmachinename string `json:"virtualmachinename"` + Vmguestip string `json:"vmguestip"` } type DeleteEgressFirewallRuleParams struct { @@ -1715,11 +964,6 @@ func (s *FirewallService) DeleteEgressFirewallRule(p *DeleteEgressFirewallRulePa return nil, err } - resp, err = convertFirewallServiceResponse(resp) - if err != nil { - return nil, err - } - var r DeleteEgressFirewallRuleResponse if err := json.Unmarshal(resp, &r); err != nil { return nil, err @@ -1744,13 +988,233 @@ func (s *FirewallService) DeleteEgressFirewallRule(p *DeleteEgressFirewallRulePa return nil, err } } + return &r, nil } type DeleteEgressFirewallRuleResponse struct { - JobID string `json:"jobid,omitempty"` - Displaytext string `json:"displaytext,omitempty"` - Success bool `json:"success,omitempty"` + JobID string `json:"jobid"` + Displaytext string `json:"displaytext"` + Success bool `json:"success"` +} + +type DeleteFirewallRuleParams struct { + p map[string]interface{} +} + +func (p *DeleteFirewallRuleParams) toURLValues() url.Values { + u := url.Values{} + if p.p == nil { + return u + } + if v, found := p.p["id"]; found { + u.Set("id", v.(string)) + } + return u +} + +func (p *DeleteFirewallRuleParams) SetId(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["id"] = v + return +} + +// You should always use this function to get a new DeleteFirewallRuleParams instance, +// as then you are sure you have configured all required params +func (s *FirewallService) NewDeleteFirewallRuleParams(id string) *DeleteFirewallRuleParams { + p := &DeleteFirewallRuleParams{} + p.p = make(map[string]interface{}) + p.p["id"] = id + return p +} + +// Deletes a firewall rule +func (s *FirewallService) DeleteFirewallRule(p *DeleteFirewallRuleParams) (*DeleteFirewallRuleResponse, error) { + resp, err := s.cs.newRequest("deleteFirewallRule", p.toURLValues()) + if err != nil { + return nil, err + } + + var r DeleteFirewallRuleResponse + if err := json.Unmarshal(resp, &r); err != nil { + return nil, err + } + + // If we have a async client, we need to wait for the async result + if s.cs.async { + b, err := s.cs.GetAsyncJobResult(r.JobID, s.cs.timeout) + if err != nil { + if err == AsyncTimeoutErr { + return &r, err + } + return nil, err + } + + b, err = convertFirewallServiceResponse(b) + if err != nil { + return nil, err + } + + if err := json.Unmarshal(b, &r); err != nil { + return nil, err + } + } + + return &r, nil +} + +type DeleteFirewallRuleResponse struct { + JobID string `json:"jobid"` + Displaytext string `json:"displaytext"` + Success bool `json:"success"` +} + +type DeletePaloAltoFirewallParams struct { + p map[string]interface{} +} + +func (p *DeletePaloAltoFirewallParams) toURLValues() url.Values { + u := url.Values{} + if p.p == nil { + return u + } + if v, found := p.p["fwdeviceid"]; found { + u.Set("fwdeviceid", v.(string)) + } + return u +} + +func (p *DeletePaloAltoFirewallParams) SetFwdeviceid(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["fwdeviceid"] = v + return +} + +// You should always use this function to get a new DeletePaloAltoFirewallParams instance, +// as then you are sure you have configured all required params +func (s *FirewallService) NewDeletePaloAltoFirewallParams(fwdeviceid string) *DeletePaloAltoFirewallParams { + p := &DeletePaloAltoFirewallParams{} + p.p = make(map[string]interface{}) + p.p["fwdeviceid"] = fwdeviceid + return p +} + +// delete a Palo Alto firewall device +func (s *FirewallService) DeletePaloAltoFirewall(p *DeletePaloAltoFirewallParams) (*DeletePaloAltoFirewallResponse, error) { + resp, err := s.cs.newRequest("deletePaloAltoFirewall", p.toURLValues()) + if err != nil { + return nil, err + } + + var r DeletePaloAltoFirewallResponse + if err := json.Unmarshal(resp, &r); err != nil { + return nil, err + } + + // If we have a async client, we need to wait for the async result + if s.cs.async { + b, err := s.cs.GetAsyncJobResult(r.JobID, s.cs.timeout) + if err != nil { + if err == AsyncTimeoutErr { + return &r, err + } + return nil, err + } + + b, err = convertFirewallServiceResponse(b) + if err != nil { + return nil, err + } + + if err := json.Unmarshal(b, &r); err != nil { + return nil, err + } + } + + return &r, nil +} + +type DeletePaloAltoFirewallResponse struct { + JobID string `json:"jobid"` + Displaytext string `json:"displaytext"` + Success bool `json:"success"` +} + +type DeletePortForwardingRuleParams struct { + p map[string]interface{} +} + +func (p *DeletePortForwardingRuleParams) toURLValues() url.Values { + u := url.Values{} + if p.p == nil { + return u + } + if v, found := p.p["id"]; found { + u.Set("id", v.(string)) + } + return u +} + +func (p *DeletePortForwardingRuleParams) SetId(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["id"] = v + return +} + +// You should always use this function to get a new DeletePortForwardingRuleParams instance, +// as then you are sure you have configured all required params +func (s *FirewallService) NewDeletePortForwardingRuleParams(id string) *DeletePortForwardingRuleParams { + p := &DeletePortForwardingRuleParams{} + p.p = make(map[string]interface{}) + p.p["id"] = id + return p +} + +// Deletes a port forwarding rule +func (s *FirewallService) DeletePortForwardingRule(p *DeletePortForwardingRuleParams) (*DeletePortForwardingRuleResponse, error) { + resp, err := s.cs.newRequest("deletePortForwardingRule", p.toURLValues()) + if err != nil { + return nil, err + } + + var r DeletePortForwardingRuleResponse + if err := json.Unmarshal(resp, &r); err != nil { + return nil, err + } + + // If we have a async client, we need to wait for the async result + if s.cs.async { + b, err := s.cs.GetAsyncJobResult(r.JobID, s.cs.timeout) + if err != nil { + if err == AsyncTimeoutErr { + return &r, err + } + return nil, err + } + + b, err = convertFirewallServiceResponse(b) + if err != nil { + return nil, err + } + + if err := json.Unmarshal(b, &r); err != nil { + return nil, err + } + } + + return &r, nil +} + +type DeletePortForwardingRuleResponse struct { + JobID string `json:"jobid"` + Displaytext string `json:"displaytext"` + Success bool `json:"success"` } type ListEgressFirewallRulesParams struct { @@ -1933,7 +1397,7 @@ func (s *FirewallService) GetEgressFirewallRuleByID(id string, opts ...OptionFun p.p["id"] = id - for _, fn := range opts { + for _, fn := range append(s.cs.options, opts...) { if err := fn(s.cs, p); err != nil { return nil, -1, err } @@ -1975,6 +1439,7 @@ func (s *FirewallService) ListEgressFirewallRules(p *ListEgressFirewallRulesPara if err := json.Unmarshal(resp, &r); err != nil { return nil, err } + return &r, nil } @@ -1984,43 +1449,36 @@ type ListEgressFirewallRulesResponse struct { } type EgressFirewallRule struct { - Cidrlist string `json:"cidrlist,omitempty"` - Endport int `json:"endport,omitempty"` - Fordisplay bool `json:"fordisplay,omitempty"` - Icmpcode int `json:"icmpcode,omitempty"` - Icmptype int `json:"icmptype,omitempty"` - Id string `json:"id,omitempty"` - Ipaddress string `json:"ipaddress,omitempty"` - Ipaddressid string `json:"ipaddressid,omitempty"` - Networkid string `json:"networkid,omitempty"` - Protocol string `json:"protocol,omitempty"` - Startport int `json:"startport,omitempty"` - State string `json:"state,omitempty"` - Tags []struct { - Account string `json:"account,omitempty"` - Customer string `json:"customer,omitempty"` - Domain string `json:"domain,omitempty"` - Domainid string `json:"domainid,omitempty"` - Key string `json:"key,omitempty"` - Project string `json:"project,omitempty"` - Projectid string `json:"projectid,omitempty"` - Resourceid string `json:"resourceid,omitempty"` - Resourcetype string `json:"resourcetype,omitempty"` - Value string `json:"value,omitempty"` - } `json:"tags,omitempty"` + Cidrlist string `json:"cidrlist"` + Destcidrlist string `json:"destcidrlist"` + Endport int `json:"endport"` + Fordisplay bool `json:"fordisplay"` + Icmpcode int `json:"icmpcode"` + Icmptype int `json:"icmptype"` + Id string `json:"id"` + Ipaddress string `json:"ipaddress"` + Ipaddressid string `json:"ipaddressid"` + Networkid string `json:"networkid"` + Protocol string `json:"protocol"` + Startport int `json:"startport"` + State string `json:"state"` + Tags []Tags `json:"tags"` } -type UpdateEgressFirewallRuleParams struct { +type ListFirewallRulesParams struct { p map[string]interface{} } -func (p *UpdateEgressFirewallRuleParams) toURLValues() url.Values { +func (p *ListFirewallRulesParams) toURLValues() url.Values { u := url.Values{} if p.p == nil { return u } - if v, found := p.p["customid"]; found { - u.Set("customid", v.(string)) + if v, found := p.p["account"]; found { + u.Set("account", v.(string)) + } + if v, found := p.p["domainid"]; found { + u.Set("domainid", v.(string)) } if v, found := p.p["fordisplay"]; found { vv := strconv.FormatBool(v.(bool)) @@ -2029,18 +1487,62 @@ func (p *UpdateEgressFirewallRuleParams) toURLValues() url.Values { if v, found := p.p["id"]; found { u.Set("id", v.(string)) } + if v, found := p.p["ipaddressid"]; found { + u.Set("ipaddressid", v.(string)) + } + if v, found := p.p["isrecursive"]; found { + vv := strconv.FormatBool(v.(bool)) + u.Set("isrecursive", vv) + } + if v, found := p.p["keyword"]; found { + u.Set("keyword", v.(string)) + } + if v, found := p.p["listall"]; found { + vv := strconv.FormatBool(v.(bool)) + u.Set("listall", vv) + } + if v, found := p.p["networkid"]; found { + u.Set("networkid", v.(string)) + } + if v, found := p.p["page"]; found { + vv := strconv.Itoa(v.(int)) + u.Set("page", vv) + } + if v, found := p.p["pagesize"]; found { + vv := strconv.Itoa(v.(int)) + u.Set("pagesize", vv) + } + if v, found := p.p["projectid"]; found { + u.Set("projectid", v.(string)) + } + if v, found := p.p["tags"]; found { + i := 0 + for k, vv := range v.(map[string]string) { + u.Set(fmt.Sprintf("tags[%d].key", i), k) + u.Set(fmt.Sprintf("tags[%d].value", i), vv) + i++ + } + } return u } -func (p *UpdateEgressFirewallRuleParams) SetCustomid(v string) { +func (p *ListFirewallRulesParams) SetAccount(v string) { if p.p == nil { p.p = make(map[string]interface{}) } - p.p["customid"] = v + p.p["account"] = v return } -func (p *UpdateEgressFirewallRuleParams) SetFordisplay(v bool) { +func (p *ListFirewallRulesParams) SetDomainid(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["domainid"] = v + return +} + +func (p *ListFirewallRulesParams) SetFordisplay(v bool) { if p.p == nil { p.p = make(map[string]interface{}) } @@ -2048,7 +1550,7 @@ func (p *UpdateEgressFirewallRuleParams) SetFordisplay(v bool) { return } -func (p *UpdateEgressFirewallRuleParams) SetId(v string) { +func (p *ListFirewallRulesParams) SetId(v string) { if p.p == nil { p.p = make(map[string]interface{}) } @@ -2056,18 +1558,122 @@ func (p *UpdateEgressFirewallRuleParams) SetId(v string) { return } -// You should always use this function to get a new UpdateEgressFirewallRuleParams instance, +func (p *ListFirewallRulesParams) SetIpaddressid(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["ipaddressid"] = v + return +} + +func (p *ListFirewallRulesParams) SetIsrecursive(v bool) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["isrecursive"] = v + return +} + +func (p *ListFirewallRulesParams) SetKeyword(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["keyword"] = v + return +} + +func (p *ListFirewallRulesParams) SetListall(v bool) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["listall"] = v + return +} + +func (p *ListFirewallRulesParams) SetNetworkid(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["networkid"] = v + return +} + +func (p *ListFirewallRulesParams) SetPage(v int) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["page"] = v + return +} + +func (p *ListFirewallRulesParams) SetPagesize(v int) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["pagesize"] = v + return +} + +func (p *ListFirewallRulesParams) SetProjectid(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["projectid"] = v + return +} + +func (p *ListFirewallRulesParams) SetTags(v map[string]string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["tags"] = v + return +} + +// You should always use this function to get a new ListFirewallRulesParams instance, // as then you are sure you have configured all required params -func (s *FirewallService) NewUpdateEgressFirewallRuleParams(id string) *UpdateEgressFirewallRuleParams { - p := &UpdateEgressFirewallRuleParams{} +func (s *FirewallService) NewListFirewallRulesParams() *ListFirewallRulesParams { + p := &ListFirewallRulesParams{} p.p = make(map[string]interface{}) + return p +} + +// This is a courtesy helper function, which in some cases may not work as expected! +func (s *FirewallService) GetFirewallRuleByID(id string, opts ...OptionFunc) (*FirewallRule, int, error) { + p := &ListFirewallRulesParams{} + p.p = make(map[string]interface{}) + p.p["id"] = id - return p + + for _, fn := range append(s.cs.options, opts...) { + if err := fn(s.cs, p); err != nil { + return nil, -1, err + } + } + + l, err := s.ListFirewallRules(p) + if err != nil { + if strings.Contains(err.Error(), fmt.Sprintf( + "Invalid parameter id value=%s due to incorrect long value format, "+ + "or entity does not exist", id)) { + return nil, 0, fmt.Errorf("No match found for %s: %+v", id, l) + } + return nil, -1, err + } + + if l.Count == 0 { + return nil, l.Count, fmt.Errorf("No match found for %s: %+v", id, l) + } + + if l.Count == 1 { + return l.FirewallRules[0], l.Count, nil + } + return nil, l.Count, fmt.Errorf("There is more then one result for FirewallRule UUID: %s!", id) } -// Updates egress firewall rule -func (s *FirewallService) UpdateEgressFirewallRule(p *UpdateEgressFirewallRuleParams) (*UpdateEgressFirewallRuleResponse, error) { - resp, err := s.cs.newRequest("updateEgressFirewallRule", p.toURLValues()) +// Lists all firewall rules for an IP address. +func (s *FirewallService) ListFirewallRules(p *ListFirewallRulesParams) (*ListFirewallRulesResponse, error) { + resp, err := s.cs.newRequest("listFirewallRules", p.toURLValues()) if err != nil { return nil, err } @@ -2077,393 +1683,34 @@ func (s *FirewallService) UpdateEgressFirewallRule(p *UpdateEgressFirewallRulePa return nil, err } - var r UpdateEgressFirewallRuleResponse + var r ListFirewallRulesResponse if err := json.Unmarshal(resp, &r); err != nil { return nil, err } - // If we have a async client, we need to wait for the async result - if s.cs.async { - b, err := s.cs.GetAsyncJobResult(r.JobID, s.cs.timeout) - if err != nil { - if err == AsyncTimeoutErr { - return &r, err - } - return nil, err - } - - b, err = getRawValue(b) - if err != nil { - return nil, err - } - - b, err = convertFirewallServiceResponse(b) - if err != nil { - return nil, err - } - - if err := json.Unmarshal(b, &r); err != nil { - return nil, err - } - } return &r, nil } -type UpdateEgressFirewallRuleResponse struct { - JobID string `json:"jobid,omitempty"` - Cidrlist string `json:"cidrlist,omitempty"` - Endport int `json:"endport,omitempty"` - Fordisplay bool `json:"fordisplay,omitempty"` - Icmpcode int `json:"icmpcode,omitempty"` - Icmptype int `json:"icmptype,omitempty"` - Id string `json:"id,omitempty"` - Ipaddress string `json:"ipaddress,omitempty"` - Ipaddressid string `json:"ipaddressid,omitempty"` - Networkid string `json:"networkid,omitempty"` - Protocol string `json:"protocol,omitempty"` - Startport int `json:"startport,omitempty"` - State string `json:"state,omitempty"` - Tags []struct { - Account string `json:"account,omitempty"` - Customer string `json:"customer,omitempty"` - Domain string `json:"domain,omitempty"` - Domainid string `json:"domainid,omitempty"` - Key string `json:"key,omitempty"` - Project string `json:"project,omitempty"` - Projectid string `json:"projectid,omitempty"` - Resourceid string `json:"resourceid,omitempty"` - Resourcetype string `json:"resourcetype,omitempty"` - Value string `json:"value,omitempty"` - } `json:"tags,omitempty"` +type ListFirewallRulesResponse struct { + Count int `json:"count"` + FirewallRules []*FirewallRule `json:"firewallrule"` } -type AddPaloAltoFirewallParams struct { - p map[string]interface{} -} - -func (p *AddPaloAltoFirewallParams) toURLValues() url.Values { - u := url.Values{} - if p.p == nil { - return u - } - if v, found := p.p["networkdevicetype"]; found { - u.Set("networkdevicetype", v.(string)) - } - if v, found := p.p["password"]; found { - u.Set("password", v.(string)) - } - if v, found := p.p["physicalnetworkid"]; found { - u.Set("physicalnetworkid", v.(string)) - } - if v, found := p.p["url"]; found { - u.Set("url", v.(string)) - } - if v, found := p.p["username"]; found { - u.Set("username", v.(string)) - } - return u -} - -func (p *AddPaloAltoFirewallParams) SetNetworkdevicetype(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["networkdevicetype"] = v - return -} - -func (p *AddPaloAltoFirewallParams) SetPassword(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["password"] = v - return -} - -func (p *AddPaloAltoFirewallParams) SetPhysicalnetworkid(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["physicalnetworkid"] = v - return -} - -func (p *AddPaloAltoFirewallParams) SetUrl(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["url"] = v - return -} - -func (p *AddPaloAltoFirewallParams) SetUsername(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["username"] = v - return -} - -// You should always use this function to get a new AddPaloAltoFirewallParams instance, -// as then you are sure you have configured all required params -func (s *FirewallService) NewAddPaloAltoFirewallParams(networkdevicetype string, password string, physicalnetworkid string, url string, username string) *AddPaloAltoFirewallParams { - p := &AddPaloAltoFirewallParams{} - p.p = make(map[string]interface{}) - p.p["networkdevicetype"] = networkdevicetype - p.p["password"] = password - p.p["physicalnetworkid"] = physicalnetworkid - p.p["url"] = url - p.p["username"] = username - return p -} - -// Adds a Palo Alto firewall device -func (s *FirewallService) AddPaloAltoFirewall(p *AddPaloAltoFirewallParams) (*AddPaloAltoFirewallResponse, error) { - resp, err := s.cs.newRequest("addPaloAltoFirewall", p.toURLValues()) - if err != nil { - return nil, err - } - - resp, err = convertFirewallServiceResponse(resp) - if err != nil { - return nil, err - } - - var r AddPaloAltoFirewallResponse - if err := json.Unmarshal(resp, &r); err != nil { - return nil, err - } - - // If we have a async client, we need to wait for the async result - if s.cs.async { - b, err := s.cs.GetAsyncJobResult(r.JobID, s.cs.timeout) - if err != nil { - if err == AsyncTimeoutErr { - return &r, err - } - return nil, err - } - - b, err = getRawValue(b) - if err != nil { - return nil, err - } - - b, err = convertFirewallServiceResponse(b) - if err != nil { - return nil, err - } - - if err := json.Unmarshal(b, &r); err != nil { - return nil, err - } - } - return &r, nil -} - -type AddPaloAltoFirewallResponse struct { - JobID string `json:"jobid,omitempty"` - Fwdevicecapacity int64 `json:"fwdevicecapacity,omitempty"` - Fwdeviceid string `json:"fwdeviceid,omitempty"` - Fwdevicename string `json:"fwdevicename,omitempty"` - Fwdevicestate string `json:"fwdevicestate,omitempty"` - Ipaddress string `json:"ipaddress,omitempty"` - Numretries string `json:"numretries,omitempty"` - Physicalnetworkid string `json:"physicalnetworkid,omitempty"` - Privateinterface string `json:"privateinterface,omitempty"` - Privatezone string `json:"privatezone,omitempty"` - Provider string `json:"provider,omitempty"` - Publicinterface string `json:"publicinterface,omitempty"` - Publiczone string `json:"publiczone,omitempty"` - Timeout string `json:"timeout,omitempty"` - Usageinterface string `json:"usageinterface,omitempty"` - Username string `json:"username,omitempty"` - Zoneid string `json:"zoneid,omitempty"` -} - -type DeletePaloAltoFirewallParams struct { - p map[string]interface{} -} - -func (p *DeletePaloAltoFirewallParams) toURLValues() url.Values { - u := url.Values{} - if p.p == nil { - return u - } - if v, found := p.p["fwdeviceid"]; found { - u.Set("fwdeviceid", v.(string)) - } - return u -} - -func (p *DeletePaloAltoFirewallParams) SetFwdeviceid(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["fwdeviceid"] = v - return -} - -// You should always use this function to get a new DeletePaloAltoFirewallParams instance, -// as then you are sure you have configured all required params -func (s *FirewallService) NewDeletePaloAltoFirewallParams(fwdeviceid string) *DeletePaloAltoFirewallParams { - p := &DeletePaloAltoFirewallParams{} - p.p = make(map[string]interface{}) - p.p["fwdeviceid"] = fwdeviceid - return p -} - -// delete a Palo Alto firewall device -func (s *FirewallService) DeletePaloAltoFirewall(p *DeletePaloAltoFirewallParams) (*DeletePaloAltoFirewallResponse, error) { - resp, err := s.cs.newRequest("deletePaloAltoFirewall", p.toURLValues()) - if err != nil { - return nil, err - } - - resp, err = convertFirewallServiceResponse(resp) - if err != nil { - return nil, err - } - - var r DeletePaloAltoFirewallResponse - if err := json.Unmarshal(resp, &r); err != nil { - return nil, err - } - - // If we have a async client, we need to wait for the async result - if s.cs.async { - b, err := s.cs.GetAsyncJobResult(r.JobID, s.cs.timeout) - if err != nil { - if err == AsyncTimeoutErr { - return &r, err - } - return nil, err - } - - b, err = convertFirewallServiceResponse(b) - if err != nil { - return nil, err - } - - if err := json.Unmarshal(b, &r); err != nil { - return nil, err - } - } - return &r, nil -} - -type DeletePaloAltoFirewallResponse struct { - JobID string `json:"jobid,omitempty"` - Displaytext string `json:"displaytext,omitempty"` - Success bool `json:"success,omitempty"` -} - -type ConfigurePaloAltoFirewallParams struct { - p map[string]interface{} -} - -func (p *ConfigurePaloAltoFirewallParams) toURLValues() url.Values { - u := url.Values{} - if p.p == nil { - return u - } - if v, found := p.p["fwdevicecapacity"]; found { - vv := strconv.FormatInt(v.(int64), 10) - u.Set("fwdevicecapacity", vv) - } - if v, found := p.p["fwdeviceid"]; found { - u.Set("fwdeviceid", v.(string)) - } - return u -} - -func (p *ConfigurePaloAltoFirewallParams) SetFwdevicecapacity(v int64) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["fwdevicecapacity"] = v - return -} - -func (p *ConfigurePaloAltoFirewallParams) SetFwdeviceid(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["fwdeviceid"] = v - return -} - -// You should always use this function to get a new ConfigurePaloAltoFirewallParams instance, -// as then you are sure you have configured all required params -func (s *FirewallService) NewConfigurePaloAltoFirewallParams(fwdeviceid string) *ConfigurePaloAltoFirewallParams { - p := &ConfigurePaloAltoFirewallParams{} - p.p = make(map[string]interface{}) - p.p["fwdeviceid"] = fwdeviceid - return p -} - -// Configures a Palo Alto firewall device -func (s *FirewallService) ConfigurePaloAltoFirewall(p *ConfigurePaloAltoFirewallParams) (*ConfigurePaloAltoFirewallResponse, error) { - resp, err := s.cs.newRequest("configurePaloAltoFirewall", p.toURLValues()) - if err != nil { - return nil, err - } - - resp, err = convertFirewallServiceResponse(resp) - if err != nil { - return nil, err - } - - var r ConfigurePaloAltoFirewallResponse - if err := json.Unmarshal(resp, &r); err != nil { - return nil, err - } - - // If we have a async client, we need to wait for the async result - if s.cs.async { - b, err := s.cs.GetAsyncJobResult(r.JobID, s.cs.timeout) - if err != nil { - if err == AsyncTimeoutErr { - return &r, err - } - return nil, err - } - - b, err = getRawValue(b) - if err != nil { - return nil, err - } - - b, err = convertFirewallServiceResponse(b) - if err != nil { - return nil, err - } - - if err := json.Unmarshal(b, &r); err != nil { - return nil, err - } - } - return &r, nil -} - -type ConfigurePaloAltoFirewallResponse struct { - JobID string `json:"jobid,omitempty"` - Fwdevicecapacity int64 `json:"fwdevicecapacity,omitempty"` - Fwdeviceid string `json:"fwdeviceid,omitempty"` - Fwdevicename string `json:"fwdevicename,omitempty"` - Fwdevicestate string `json:"fwdevicestate,omitempty"` - Ipaddress string `json:"ipaddress,omitempty"` - Numretries string `json:"numretries,omitempty"` - Physicalnetworkid string `json:"physicalnetworkid,omitempty"` - Privateinterface string `json:"privateinterface,omitempty"` - Privatezone string `json:"privatezone,omitempty"` - Provider string `json:"provider,omitempty"` - Publicinterface string `json:"publicinterface,omitempty"` - Publiczone string `json:"publiczone,omitempty"` - Timeout string `json:"timeout,omitempty"` - Usageinterface string `json:"usageinterface,omitempty"` - Username string `json:"username,omitempty"` - Zoneid string `json:"zoneid,omitempty"` +type FirewallRule struct { + Cidrlist string `json:"cidrlist"` + Destcidrlist string `json:"destcidrlist"` + Endport int `json:"endport"` + Fordisplay bool `json:"fordisplay"` + Icmpcode int `json:"icmpcode"` + Icmptype int `json:"icmptype"` + Id string `json:"id"` + Ipaddress string `json:"ipaddress"` + Ipaddressid string `json:"ipaddressid"` + Networkid string `json:"networkid"` + Protocol string `json:"protocol"` + Startport int `json:"startport"` + State string `json:"state"` + Tags []Tags `json:"tags"` } type ListPaloAltoFirewallsParams struct { @@ -2559,6 +1806,7 @@ func (s *FirewallService) ListPaloAltoFirewalls(p *ListPaloAltoFirewallsParams) if err := json.Unmarshal(resp, &r); err != nil { return nil, err } + return &r, nil } @@ -2568,20 +1816,659 @@ type ListPaloAltoFirewallsResponse struct { } type PaloAltoFirewall struct { - Fwdevicecapacity int64 `json:"fwdevicecapacity,omitempty"` - Fwdeviceid string `json:"fwdeviceid,omitempty"` - Fwdevicename string `json:"fwdevicename,omitempty"` - Fwdevicestate string `json:"fwdevicestate,omitempty"` - Ipaddress string `json:"ipaddress,omitempty"` - Numretries string `json:"numretries,omitempty"` - Physicalnetworkid string `json:"physicalnetworkid,omitempty"` - Privateinterface string `json:"privateinterface,omitempty"` - Privatezone string `json:"privatezone,omitempty"` - Provider string `json:"provider,omitempty"` - Publicinterface string `json:"publicinterface,omitempty"` - Publiczone string `json:"publiczone,omitempty"` - Timeout string `json:"timeout,omitempty"` - Usageinterface string `json:"usageinterface,omitempty"` - Username string `json:"username,omitempty"` - Zoneid string `json:"zoneid,omitempty"` + Fwdevicecapacity int64 `json:"fwdevicecapacity"` + Fwdeviceid string `json:"fwdeviceid"` + Fwdevicename string `json:"fwdevicename"` + Fwdevicestate string `json:"fwdevicestate"` + Ipaddress string `json:"ipaddress"` + Numretries string `json:"numretries"` + Physicalnetworkid string `json:"physicalnetworkid"` + Privateinterface string `json:"privateinterface"` + Privatezone string `json:"privatezone"` + Provider string `json:"provider"` + Publicinterface string `json:"publicinterface"` + Publiczone string `json:"publiczone"` + Timeout string `json:"timeout"` + Usageinterface string `json:"usageinterface"` + Username string `json:"username"` + Zoneid string `json:"zoneid"` +} + +type ListPortForwardingRulesParams struct { + p map[string]interface{} +} + +func (p *ListPortForwardingRulesParams) toURLValues() url.Values { + u := url.Values{} + if p.p == nil { + return u + } + if v, found := p.p["account"]; found { + u.Set("account", v.(string)) + } + if v, found := p.p["domainid"]; found { + u.Set("domainid", v.(string)) + } + if v, found := p.p["fordisplay"]; found { + vv := strconv.FormatBool(v.(bool)) + u.Set("fordisplay", vv) + } + if v, found := p.p["id"]; found { + u.Set("id", v.(string)) + } + if v, found := p.p["ipaddressid"]; found { + u.Set("ipaddressid", v.(string)) + } + if v, found := p.p["isrecursive"]; found { + vv := strconv.FormatBool(v.(bool)) + u.Set("isrecursive", vv) + } + if v, found := p.p["keyword"]; found { + u.Set("keyword", v.(string)) + } + if v, found := p.p["listall"]; found { + vv := strconv.FormatBool(v.(bool)) + u.Set("listall", vv) + } + if v, found := p.p["networkid"]; found { + u.Set("networkid", v.(string)) + } + if v, found := p.p["page"]; found { + vv := strconv.Itoa(v.(int)) + u.Set("page", vv) + } + if v, found := p.p["pagesize"]; found { + vv := strconv.Itoa(v.(int)) + u.Set("pagesize", vv) + } + if v, found := p.p["projectid"]; found { + u.Set("projectid", v.(string)) + } + if v, found := p.p["tags"]; found { + i := 0 + for k, vv := range v.(map[string]string) { + u.Set(fmt.Sprintf("tags[%d].key", i), k) + u.Set(fmt.Sprintf("tags[%d].value", i), vv) + i++ + } + } + return u +} + +func (p *ListPortForwardingRulesParams) SetAccount(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["account"] = v + return +} + +func (p *ListPortForwardingRulesParams) SetDomainid(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["domainid"] = v + return +} + +func (p *ListPortForwardingRulesParams) SetFordisplay(v bool) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["fordisplay"] = v + return +} + +func (p *ListPortForwardingRulesParams) SetId(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["id"] = v + return +} + +func (p *ListPortForwardingRulesParams) SetIpaddressid(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["ipaddressid"] = v + return +} + +func (p *ListPortForwardingRulesParams) SetIsrecursive(v bool) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["isrecursive"] = v + return +} + +func (p *ListPortForwardingRulesParams) SetKeyword(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["keyword"] = v + return +} + +func (p *ListPortForwardingRulesParams) SetListall(v bool) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["listall"] = v + return +} + +func (p *ListPortForwardingRulesParams) SetNetworkid(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["networkid"] = v + return +} + +func (p *ListPortForwardingRulesParams) SetPage(v int) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["page"] = v + return +} + +func (p *ListPortForwardingRulesParams) SetPagesize(v int) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["pagesize"] = v + return +} + +func (p *ListPortForwardingRulesParams) SetProjectid(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["projectid"] = v + return +} + +func (p *ListPortForwardingRulesParams) SetTags(v map[string]string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["tags"] = v + return +} + +// You should always use this function to get a new ListPortForwardingRulesParams instance, +// as then you are sure you have configured all required params +func (s *FirewallService) NewListPortForwardingRulesParams() *ListPortForwardingRulesParams { + p := &ListPortForwardingRulesParams{} + p.p = make(map[string]interface{}) + return p +} + +// This is a courtesy helper function, which in some cases may not work as expected! +func (s *FirewallService) GetPortForwardingRuleByID(id string, opts ...OptionFunc) (*PortForwardingRule, int, error) { + p := &ListPortForwardingRulesParams{} + p.p = make(map[string]interface{}) + + p.p["id"] = id + + for _, fn := range append(s.cs.options, opts...) { + if err := fn(s.cs, p); err != nil { + return nil, -1, err + } + } + + l, err := s.ListPortForwardingRules(p) + if err != nil { + if strings.Contains(err.Error(), fmt.Sprintf( + "Invalid parameter id value=%s due to incorrect long value format, "+ + "or entity does not exist", id)) { + return nil, 0, fmt.Errorf("No match found for %s: %+v", id, l) + } + return nil, -1, err + } + + if l.Count == 0 { + return nil, l.Count, fmt.Errorf("No match found for %s: %+v", id, l) + } + + if l.Count == 1 { + return l.PortForwardingRules[0], l.Count, nil + } + return nil, l.Count, fmt.Errorf("There is more then one result for PortForwardingRule UUID: %s!", id) +} + +// Lists all port forwarding rules for an IP address. +func (s *FirewallService) ListPortForwardingRules(p *ListPortForwardingRulesParams) (*ListPortForwardingRulesResponse, error) { + resp, err := s.cs.newRequest("listPortForwardingRules", p.toURLValues()) + if err != nil { + return nil, err + } + + resp, err = convertFirewallServiceResponse(resp) + if err != nil { + return nil, err + } + + var r ListPortForwardingRulesResponse + if err := json.Unmarshal(resp, &r); err != nil { + return nil, err + } + + return &r, nil +} + +type ListPortForwardingRulesResponse struct { + Count int `json:"count"` + PortForwardingRules []*PortForwardingRule `json:"portforwardingrule"` +} + +type PortForwardingRule struct { + Cidrlist string `json:"cidrlist"` + Fordisplay bool `json:"fordisplay"` + Id string `json:"id"` + Ipaddress string `json:"ipaddress"` + Ipaddressid string `json:"ipaddressid"` + Networkid string `json:"networkid"` + Privateendport string `json:"privateendport"` + Privateport string `json:"privateport"` + Protocol string `json:"protocol"` + Publicendport string `json:"publicendport"` + Publicport string `json:"publicport"` + State string `json:"state"` + Tags []Tags `json:"tags"` + Virtualmachinedisplayname string `json:"virtualmachinedisplayname"` + Virtualmachineid string `json:"virtualmachineid"` + Virtualmachinename string `json:"virtualmachinename"` + Vmguestip string `json:"vmguestip"` +} + +type UpdateEgressFirewallRuleParams struct { + p map[string]interface{} +} + +func (p *UpdateEgressFirewallRuleParams) toURLValues() url.Values { + u := url.Values{} + if p.p == nil { + return u + } + if v, found := p.p["customid"]; found { + u.Set("customid", v.(string)) + } + if v, found := p.p["fordisplay"]; found { + vv := strconv.FormatBool(v.(bool)) + u.Set("fordisplay", vv) + } + if v, found := p.p["id"]; found { + u.Set("id", v.(string)) + } + return u +} + +func (p *UpdateEgressFirewallRuleParams) SetCustomid(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["customid"] = v + return +} + +func (p *UpdateEgressFirewallRuleParams) SetFordisplay(v bool) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["fordisplay"] = v + return +} + +func (p *UpdateEgressFirewallRuleParams) SetId(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["id"] = v + return +} + +// You should always use this function to get a new UpdateEgressFirewallRuleParams instance, +// as then you are sure you have configured all required params +func (s *FirewallService) NewUpdateEgressFirewallRuleParams(id string) *UpdateEgressFirewallRuleParams { + p := &UpdateEgressFirewallRuleParams{} + p.p = make(map[string]interface{}) + p.p["id"] = id + return p +} + +// Updates egress firewall rule +func (s *FirewallService) UpdateEgressFirewallRule(p *UpdateEgressFirewallRuleParams) (*UpdateEgressFirewallRuleResponse, error) { + resp, err := s.cs.newRequest("updateEgressFirewallRule", p.toURLValues()) + if err != nil { + return nil, err + } + + var r UpdateEgressFirewallRuleResponse + if err := json.Unmarshal(resp, &r); err != nil { + return nil, err + } + + // If we have a async client, we need to wait for the async result + if s.cs.async { + b, err := s.cs.GetAsyncJobResult(r.JobID, s.cs.timeout) + if err != nil { + if err == AsyncTimeoutErr { + return &r, err + } + return nil, err + } + + b, err = getRawValue(b) + if err != nil { + return nil, err + } + + b, err = convertFirewallServiceResponse(b) + if err != nil { + return nil, err + } + + if err := json.Unmarshal(b, &r); err != nil { + return nil, err + } + } + + return &r, nil +} + +type UpdateEgressFirewallRuleResponse struct { + JobID string `json:"jobid"` + Cidrlist string `json:"cidrlist"` + Destcidrlist string `json:"destcidrlist"` + Endport int `json:"endport"` + Fordisplay bool `json:"fordisplay"` + Icmpcode int `json:"icmpcode"` + Icmptype int `json:"icmptype"` + Id string `json:"id"` + Ipaddress string `json:"ipaddress"` + Ipaddressid string `json:"ipaddressid"` + Networkid string `json:"networkid"` + Protocol string `json:"protocol"` + Startport int `json:"startport"` + State string `json:"state"` + Tags []Tags `json:"tags"` +} + +type UpdateFirewallRuleParams struct { + p map[string]interface{} +} + +func (p *UpdateFirewallRuleParams) toURLValues() url.Values { + u := url.Values{} + if p.p == nil { + return u + } + if v, found := p.p["customid"]; found { + u.Set("customid", v.(string)) + } + if v, found := p.p["fordisplay"]; found { + vv := strconv.FormatBool(v.(bool)) + u.Set("fordisplay", vv) + } + if v, found := p.p["id"]; found { + u.Set("id", v.(string)) + } + return u +} + +func (p *UpdateFirewallRuleParams) SetCustomid(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["customid"] = v + return +} + +func (p *UpdateFirewallRuleParams) SetFordisplay(v bool) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["fordisplay"] = v + return +} + +func (p *UpdateFirewallRuleParams) SetId(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["id"] = v + return +} + +// You should always use this function to get a new UpdateFirewallRuleParams instance, +// as then you are sure you have configured all required params +func (s *FirewallService) NewUpdateFirewallRuleParams(id string) *UpdateFirewallRuleParams { + p := &UpdateFirewallRuleParams{} + p.p = make(map[string]interface{}) + p.p["id"] = id + return p +} + +// Updates firewall rule +func (s *FirewallService) UpdateFirewallRule(p *UpdateFirewallRuleParams) (*UpdateFirewallRuleResponse, error) { + resp, err := s.cs.newRequest("updateFirewallRule", p.toURLValues()) + if err != nil { + return nil, err + } + + var r UpdateFirewallRuleResponse + if err := json.Unmarshal(resp, &r); err != nil { + return nil, err + } + + // If we have a async client, we need to wait for the async result + if s.cs.async { + b, err := s.cs.GetAsyncJobResult(r.JobID, s.cs.timeout) + if err != nil { + if err == AsyncTimeoutErr { + return &r, err + } + return nil, err + } + + b, err = getRawValue(b) + if err != nil { + return nil, err + } + + b, err = convertFirewallServiceResponse(b) + if err != nil { + return nil, err + } + + if err := json.Unmarshal(b, &r); err != nil { + return nil, err + } + } + + return &r, nil +} + +type UpdateFirewallRuleResponse struct { + JobID string `json:"jobid"` + Cidrlist string `json:"cidrlist"` + Destcidrlist string `json:"destcidrlist"` + Endport int `json:"endport"` + Fordisplay bool `json:"fordisplay"` + Icmpcode int `json:"icmpcode"` + Icmptype int `json:"icmptype"` + Id string `json:"id"` + Ipaddress string `json:"ipaddress"` + Ipaddressid string `json:"ipaddressid"` + Networkid string `json:"networkid"` + Protocol string `json:"protocol"` + Startport int `json:"startport"` + State string `json:"state"` + Tags []Tags `json:"tags"` +} + +type UpdatePortForwardingRuleParams struct { + p map[string]interface{} +} + +func (p *UpdatePortForwardingRuleParams) toURLValues() url.Values { + u := url.Values{} + if p.p == nil { + return u + } + if v, found := p.p["customid"]; found { + u.Set("customid", v.(string)) + } + if v, found := p.p["fordisplay"]; found { + vv := strconv.FormatBool(v.(bool)) + u.Set("fordisplay", vv) + } + if v, found := p.p["id"]; found { + u.Set("id", v.(string)) + } + if v, found := p.p["privateendport"]; found { + vv := strconv.Itoa(v.(int)) + u.Set("privateendport", vv) + } + if v, found := p.p["privateport"]; found { + vv := strconv.Itoa(v.(int)) + u.Set("privateport", vv) + } + if v, found := p.p["virtualmachineid"]; found { + u.Set("virtualmachineid", v.(string)) + } + if v, found := p.p["vmguestip"]; found { + u.Set("vmguestip", v.(string)) + } + return u +} + +func (p *UpdatePortForwardingRuleParams) SetCustomid(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["customid"] = v + return +} + +func (p *UpdatePortForwardingRuleParams) SetFordisplay(v bool) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["fordisplay"] = v + return +} + +func (p *UpdatePortForwardingRuleParams) SetId(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["id"] = v + return +} + +func (p *UpdatePortForwardingRuleParams) SetPrivateendport(v int) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["privateendport"] = v + return +} + +func (p *UpdatePortForwardingRuleParams) SetPrivateport(v int) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["privateport"] = v + return +} + +func (p *UpdatePortForwardingRuleParams) SetVirtualmachineid(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["virtualmachineid"] = v + return +} + +func (p *UpdatePortForwardingRuleParams) SetVmguestip(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["vmguestip"] = v + return +} + +// You should always use this function to get a new UpdatePortForwardingRuleParams instance, +// as then you are sure you have configured all required params +func (s *FirewallService) NewUpdatePortForwardingRuleParams(id string) *UpdatePortForwardingRuleParams { + p := &UpdatePortForwardingRuleParams{} + p.p = make(map[string]interface{}) + p.p["id"] = id + return p +} + +// Updates a port forwarding rule. Only the private port and the virtual machine can be updated. +func (s *FirewallService) UpdatePortForwardingRule(p *UpdatePortForwardingRuleParams) (*UpdatePortForwardingRuleResponse, error) { + resp, err := s.cs.newRequest("updatePortForwardingRule", p.toURLValues()) + if err != nil { + return nil, err + } + + var r UpdatePortForwardingRuleResponse + if err := json.Unmarshal(resp, &r); err != nil { + return nil, err + } + + // If we have a async client, we need to wait for the async result + if s.cs.async { + b, err := s.cs.GetAsyncJobResult(r.JobID, s.cs.timeout) + if err != nil { + if err == AsyncTimeoutErr { + return &r, err + } + return nil, err + } + + b, err = getRawValue(b) + if err != nil { + return nil, err + } + + b, err = convertFirewallServiceResponse(b) + if err != nil { + return nil, err + } + + if err := json.Unmarshal(b, &r); err != nil { + return nil, err + } + } + + return &r, nil +} + +type UpdatePortForwardingRuleResponse struct { + JobID string `json:"jobid"` + Cidrlist string `json:"cidrlist"` + Fordisplay bool `json:"fordisplay"` + Id string `json:"id"` + Ipaddress string `json:"ipaddress"` + Ipaddressid string `json:"ipaddressid"` + Networkid string `json:"networkid"` + Privateendport string `json:"privateendport"` + Privateport string `json:"privateport"` + Protocol string `json:"protocol"` + Publicendport string `json:"publicendport"` + Publicport string `json:"publicport"` + State string `json:"state"` + Tags []Tags `json:"tags"` + Virtualmachinedisplayname string `json:"virtualmachinedisplayname"` + Virtualmachineid string `json:"virtualmachineid"` + Virtualmachinename string `json:"virtualmachinename"` + Vmguestip string `json:"vmguestip"` } diff --git a/vendor/github.com/xanzy/go-cloudstack/cloudstack/GuestOSService.go b/vendor/github.com/xanzy/go-cloudstack/cloudstack/GuestOSService.go index 2f7810044..9e6a67236 100644 --- a/vendor/github.com/xanzy/go-cloudstack/cloudstack/GuestOSService.go +++ b/vendor/github.com/xanzy/go-cloudstack/cloudstack/GuestOSService.go @@ -1,5 +1,5 @@ // -// Copyright 2016, Sander van Harmelen +// Copyright 2018, Sander van Harmelen // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -24,337 +24,6 @@ import ( "strings" ) -type ListOsTypesParams struct { - p map[string]interface{} -} - -func (p *ListOsTypesParams) toURLValues() url.Values { - u := url.Values{} - if p.p == nil { - return u - } - if v, found := p.p["description"]; found { - u.Set("description", v.(string)) - } - if v, found := p.p["id"]; found { - u.Set("id", v.(string)) - } - if v, found := p.p["keyword"]; found { - u.Set("keyword", v.(string)) - } - if v, found := p.p["oscategoryid"]; found { - u.Set("oscategoryid", v.(string)) - } - if v, found := p.p["page"]; found { - vv := strconv.Itoa(v.(int)) - u.Set("page", vv) - } - if v, found := p.p["pagesize"]; found { - vv := strconv.Itoa(v.(int)) - u.Set("pagesize", vv) - } - return u -} - -func (p *ListOsTypesParams) SetDescription(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["description"] = v - return -} - -func (p *ListOsTypesParams) SetId(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["id"] = v - return -} - -func (p *ListOsTypesParams) SetKeyword(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["keyword"] = v - return -} - -func (p *ListOsTypesParams) SetOscategoryid(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["oscategoryid"] = v - return -} - -func (p *ListOsTypesParams) SetPage(v int) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["page"] = v - return -} - -func (p *ListOsTypesParams) SetPagesize(v int) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["pagesize"] = v - return -} - -// You should always use this function to get a new ListOsTypesParams instance, -// as then you are sure you have configured all required params -func (s *GuestOSService) NewListOsTypesParams() *ListOsTypesParams { - p := &ListOsTypesParams{} - p.p = make(map[string]interface{}) - return p -} - -// This is a courtesy helper function, which in some cases may not work as expected! -func (s *GuestOSService) GetOsTypeByID(id string, opts ...OptionFunc) (*OsType, int, error) { - p := &ListOsTypesParams{} - p.p = make(map[string]interface{}) - - p.p["id"] = id - - for _, fn := range opts { - if err := fn(s.cs, p); err != nil { - return nil, -1, err - } - } - - l, err := s.ListOsTypes(p) - if err != nil { - if strings.Contains(err.Error(), fmt.Sprintf( - "Invalid parameter id value=%s due to incorrect long value format, "+ - "or entity does not exist", id)) { - return nil, 0, fmt.Errorf("No match found for %s: %+v", id, l) - } - return nil, -1, err - } - - if l.Count == 0 { - return nil, l.Count, fmt.Errorf("No match found for %s: %+v", id, l) - } - - if l.Count == 1 { - return l.OsTypes[0], l.Count, nil - } - return nil, l.Count, fmt.Errorf("There is more then one result for OsType UUID: %s!", id) -} - -// Lists all supported OS types for this cloud. -func (s *GuestOSService) ListOsTypes(p *ListOsTypesParams) (*ListOsTypesResponse, error) { - resp, err := s.cs.newRequest("listOsTypes", p.toURLValues()) - if err != nil { - return nil, err - } - - var r ListOsTypesResponse - if err := json.Unmarshal(resp, &r); err != nil { - return nil, err - } - return &r, nil -} - -type ListOsTypesResponse struct { - Count int `json:"count"` - OsTypes []*OsType `json:"ostype"` -} - -type OsType struct { - Description string `json:"description,omitempty"` - Id string `json:"id,omitempty"` - Isuserdefined string `json:"isuserdefined,omitempty"` - Oscategoryid string `json:"oscategoryid,omitempty"` -} - -type ListOsCategoriesParams struct { - p map[string]interface{} -} - -func (p *ListOsCategoriesParams) toURLValues() url.Values { - u := url.Values{} - if p.p == nil { - return u - } - if v, found := p.p["id"]; found { - u.Set("id", v.(string)) - } - if v, found := p.p["keyword"]; found { - u.Set("keyword", v.(string)) - } - if v, found := p.p["name"]; found { - u.Set("name", v.(string)) - } - if v, found := p.p["page"]; found { - vv := strconv.Itoa(v.(int)) - u.Set("page", vv) - } - if v, found := p.p["pagesize"]; found { - vv := strconv.Itoa(v.(int)) - u.Set("pagesize", vv) - } - return u -} - -func (p *ListOsCategoriesParams) SetId(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["id"] = v - return -} - -func (p *ListOsCategoriesParams) SetKeyword(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["keyword"] = v - return -} - -func (p *ListOsCategoriesParams) SetName(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["name"] = v - return -} - -func (p *ListOsCategoriesParams) SetPage(v int) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["page"] = v - return -} - -func (p *ListOsCategoriesParams) SetPagesize(v int) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["pagesize"] = v - return -} - -// You should always use this function to get a new ListOsCategoriesParams instance, -// as then you are sure you have configured all required params -func (s *GuestOSService) NewListOsCategoriesParams() *ListOsCategoriesParams { - p := &ListOsCategoriesParams{} - p.p = make(map[string]interface{}) - return p -} - -// This is a courtesy helper function, which in some cases may not work as expected! -func (s *GuestOSService) GetOsCategoryID(name string, opts ...OptionFunc) (string, int, error) { - p := &ListOsCategoriesParams{} - p.p = make(map[string]interface{}) - - p.p["name"] = name - - for _, fn := range opts { - if err := fn(s.cs, p); err != nil { - return "", -1, err - } - } - - l, err := s.ListOsCategories(p) - if err != nil { - return "", -1, err - } - - if l.Count == 0 { - return "", l.Count, fmt.Errorf("No match found for %s: %+v", name, l) - } - - if l.Count == 1 { - return l.OsCategories[0].Id, l.Count, nil - } - - if l.Count > 1 { - for _, v := range l.OsCategories { - if v.Name == name { - return v.Id, l.Count, nil - } - } - } - return "", l.Count, fmt.Errorf("Could not find an exact match for %s: %+v", name, l) -} - -// This is a courtesy helper function, which in some cases may not work as expected! -func (s *GuestOSService) GetOsCategoryByName(name string, opts ...OptionFunc) (*OsCategory, int, error) { - id, count, err := s.GetOsCategoryID(name, opts...) - if err != nil { - return nil, count, err - } - - r, count, err := s.GetOsCategoryByID(id, opts...) - if err != nil { - return nil, count, err - } - return r, count, nil -} - -// This is a courtesy helper function, which in some cases may not work as expected! -func (s *GuestOSService) GetOsCategoryByID(id string, opts ...OptionFunc) (*OsCategory, int, error) { - p := &ListOsCategoriesParams{} - p.p = make(map[string]interface{}) - - p.p["id"] = id - - for _, fn := range opts { - if err := fn(s.cs, p); err != nil { - return nil, -1, err - } - } - - l, err := s.ListOsCategories(p) - if err != nil { - if strings.Contains(err.Error(), fmt.Sprintf( - "Invalid parameter id value=%s due to incorrect long value format, "+ - "or entity does not exist", id)) { - return nil, 0, fmt.Errorf("No match found for %s: %+v", id, l) - } - return nil, -1, err - } - - if l.Count == 0 { - return nil, l.Count, fmt.Errorf("No match found for %s: %+v", id, l) - } - - if l.Count == 1 { - return l.OsCategories[0], l.Count, nil - } - return nil, l.Count, fmt.Errorf("There is more then one result for OsCategory UUID: %s!", id) -} - -// Lists all supported OS categories for this cloud. -func (s *GuestOSService) ListOsCategories(p *ListOsCategoriesParams) (*ListOsCategoriesResponse, error) { - resp, err := s.cs.newRequest("listOsCategories", p.toURLValues()) - if err != nil { - return nil, err - } - - var r ListOsCategoriesResponse - if err := json.Unmarshal(resp, &r); err != nil { - return nil, err - } - return &r, nil -} - -type ListOsCategoriesResponse struct { - Count int `json:"count"` - OsCategories []*OsCategory `json:"oscategory"` -} - -type OsCategory struct { - Id string `json:"id,omitempty"` - Name string `json:"name,omitempty"` -} - type AddGuestOsParams struct { p map[string]interface{} } @@ -364,6 +33,13 @@ func (p *AddGuestOsParams) toURLValues() url.Values { if p.p == nil { return u } + if v, found := p.p["details"]; found { + i := 0 + for k, vv := range v.(map[string]string) { + u.Set(fmt.Sprintf("details[%d].%s", i, k), vv) + i++ + } + } if v, found := p.p["name"]; found { u.Set("name", v.(string)) } @@ -376,6 +52,14 @@ func (p *AddGuestOsParams) toURLValues() url.Values { return u } +func (p *AddGuestOsParams) SetDetails(v map[string]string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["details"] = v + return +} + func (p *AddGuestOsParams) SetName(v string) { if p.p == nil { p.p = make(map[string]interface{}) @@ -402,9 +86,10 @@ func (p *AddGuestOsParams) SetOsdisplayname(v string) { // You should always use this function to get a new AddGuestOsParams instance, // as then you are sure you have configured all required params -func (s *GuestOSService) NewAddGuestOsParams(oscategoryid string, osdisplayname string) *AddGuestOsParams { +func (s *GuestOSService) NewAddGuestOsParams(details map[string]string, oscategoryid string, osdisplayname string) *AddGuestOsParams { p := &AddGuestOsParams{} p.p = make(map[string]interface{}) + p.p["details"] = details p.p["oscategoryid"] = oscategoryid p.p["osdisplayname"] = osdisplayname return p @@ -441,329 +126,16 @@ func (s *GuestOSService) AddGuestOs(p *AddGuestOsParams) (*AddGuestOsResponse, e return nil, err } } + return &r, nil } type AddGuestOsResponse struct { - JobID string `json:"jobid,omitempty"` - Description string `json:"description,omitempty"` - Id string `json:"id,omitempty"` - Isuserdefined string `json:"isuserdefined,omitempty"` - Oscategoryid string `json:"oscategoryid,omitempty"` -} - -type UpdateGuestOsParams struct { - p map[string]interface{} -} - -func (p *UpdateGuestOsParams) toURLValues() url.Values { - u := url.Values{} - if p.p == nil { - return u - } - if v, found := p.p["id"]; found { - u.Set("id", v.(string)) - } - if v, found := p.p["osdisplayname"]; found { - u.Set("osdisplayname", v.(string)) - } - return u -} - -func (p *UpdateGuestOsParams) SetId(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["id"] = v - return -} - -func (p *UpdateGuestOsParams) SetOsdisplayname(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["osdisplayname"] = v - return -} - -// You should always use this function to get a new UpdateGuestOsParams instance, -// as then you are sure you have configured all required params -func (s *GuestOSService) NewUpdateGuestOsParams(id string, osdisplayname string) *UpdateGuestOsParams { - p := &UpdateGuestOsParams{} - p.p = make(map[string]interface{}) - p.p["id"] = id - p.p["osdisplayname"] = osdisplayname - return p -} - -// Updates the information about Guest OS -func (s *GuestOSService) UpdateGuestOs(p *UpdateGuestOsParams) (*UpdateGuestOsResponse, error) { - resp, err := s.cs.newRequest("updateGuestOs", p.toURLValues()) - if err != nil { - return nil, err - } - - var r UpdateGuestOsResponse - if err := json.Unmarshal(resp, &r); err != nil { - return nil, err - } - - // If we have a async client, we need to wait for the async result - if s.cs.async { - b, err := s.cs.GetAsyncJobResult(r.JobID, s.cs.timeout) - if err != nil { - if err == AsyncTimeoutErr { - return &r, err - } - return nil, err - } - - b, err = getRawValue(b) - if err != nil { - return nil, err - } - - if err := json.Unmarshal(b, &r); err != nil { - return nil, err - } - } - return &r, nil -} - -type UpdateGuestOsResponse struct { - JobID string `json:"jobid,omitempty"` - Description string `json:"description,omitempty"` - Id string `json:"id,omitempty"` - Isuserdefined string `json:"isuserdefined,omitempty"` - Oscategoryid string `json:"oscategoryid,omitempty"` -} - -type RemoveGuestOsParams struct { - p map[string]interface{} -} - -func (p *RemoveGuestOsParams) toURLValues() url.Values { - u := url.Values{} - if p.p == nil { - return u - } - if v, found := p.p["id"]; found { - u.Set("id", v.(string)) - } - return u -} - -func (p *RemoveGuestOsParams) SetId(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["id"] = v - return -} - -// You should always use this function to get a new RemoveGuestOsParams instance, -// as then you are sure you have configured all required params -func (s *GuestOSService) NewRemoveGuestOsParams(id string) *RemoveGuestOsParams { - p := &RemoveGuestOsParams{} - p.p = make(map[string]interface{}) - p.p["id"] = id - return p -} - -// Removes a Guest OS from listing. -func (s *GuestOSService) RemoveGuestOs(p *RemoveGuestOsParams) (*RemoveGuestOsResponse, error) { - resp, err := s.cs.newRequest("removeGuestOs", p.toURLValues()) - if err != nil { - return nil, err - } - - var r RemoveGuestOsResponse - if err := json.Unmarshal(resp, &r); err != nil { - return nil, err - } - - // If we have a async client, we need to wait for the async result - if s.cs.async { - b, err := s.cs.GetAsyncJobResult(r.JobID, s.cs.timeout) - if err != nil { - if err == AsyncTimeoutErr { - return &r, err - } - return nil, err - } - - if err := json.Unmarshal(b, &r); err != nil { - return nil, err - } - } - return &r, nil -} - -type RemoveGuestOsResponse struct { - JobID string `json:"jobid,omitempty"` - Displaytext string `json:"displaytext,omitempty"` - Success bool `json:"success,omitempty"` -} - -type ListGuestOsMappingParams struct { - p map[string]interface{} -} - -func (p *ListGuestOsMappingParams) toURLValues() url.Values { - u := url.Values{} - if p.p == nil { - return u - } - if v, found := p.p["hypervisor"]; found { - u.Set("hypervisor", v.(string)) - } - if v, found := p.p["hypervisorversion"]; found { - u.Set("hypervisorversion", v.(string)) - } - if v, found := p.p["id"]; found { - u.Set("id", v.(string)) - } - if v, found := p.p["keyword"]; found { - u.Set("keyword", v.(string)) - } - if v, found := p.p["ostypeid"]; found { - u.Set("ostypeid", v.(string)) - } - if v, found := p.p["page"]; found { - vv := strconv.Itoa(v.(int)) - u.Set("page", vv) - } - if v, found := p.p["pagesize"]; found { - vv := strconv.Itoa(v.(int)) - u.Set("pagesize", vv) - } - return u -} - -func (p *ListGuestOsMappingParams) SetHypervisor(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["hypervisor"] = v - return -} - -func (p *ListGuestOsMappingParams) SetHypervisorversion(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["hypervisorversion"] = v - return -} - -func (p *ListGuestOsMappingParams) SetId(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["id"] = v - return -} - -func (p *ListGuestOsMappingParams) SetKeyword(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["keyword"] = v - return -} - -func (p *ListGuestOsMappingParams) SetOstypeid(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["ostypeid"] = v - return -} - -func (p *ListGuestOsMappingParams) SetPage(v int) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["page"] = v - return -} - -func (p *ListGuestOsMappingParams) SetPagesize(v int) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["pagesize"] = v - return -} - -// You should always use this function to get a new ListGuestOsMappingParams instance, -// as then you are sure you have configured all required params -func (s *GuestOSService) NewListGuestOsMappingParams() *ListGuestOsMappingParams { - p := &ListGuestOsMappingParams{} - p.p = make(map[string]interface{}) - return p -} - -// This is a courtesy helper function, which in some cases may not work as expected! -func (s *GuestOSService) GetGuestOsMappingByID(id string, opts ...OptionFunc) (*GuestOsMapping, int, error) { - p := &ListGuestOsMappingParams{} - p.p = make(map[string]interface{}) - - p.p["id"] = id - - for _, fn := range opts { - if err := fn(s.cs, p); err != nil { - return nil, -1, err - } - } - - l, err := s.ListGuestOsMapping(p) - if err != nil { - if strings.Contains(err.Error(), fmt.Sprintf( - "Invalid parameter id value=%s due to incorrect long value format, "+ - "or entity does not exist", id)) { - return nil, 0, fmt.Errorf("No match found for %s: %+v", id, l) - } - return nil, -1, err - } - - if l.Count == 0 { - return nil, l.Count, fmt.Errorf("No match found for %s: %+v", id, l) - } - - if l.Count == 1 { - return l.GuestOsMapping[0], l.Count, nil - } - return nil, l.Count, fmt.Errorf("There is more then one result for GuestOsMapping UUID: %s!", id) -} - -// Lists all available OS mappings for given hypervisor -func (s *GuestOSService) ListGuestOsMapping(p *ListGuestOsMappingParams) (*ListGuestOsMappingResponse, error) { - resp, err := s.cs.newRequest("listGuestOsMapping", p.toURLValues()) - if err != nil { - return nil, err - } - - var r ListGuestOsMappingResponse - if err := json.Unmarshal(resp, &r); err != nil { - return nil, err - } - return &r, nil -} - -type ListGuestOsMappingResponse struct { - Count int `json:"count"` - GuestOsMapping []*GuestOsMapping `json:"guestosmapping"` -} - -type GuestOsMapping struct { - Hypervisor string `json:"hypervisor,omitempty"` - Hypervisorversion string `json:"hypervisorversion,omitempty"` - Id string `json:"id,omitempty"` - Isuserdefined string `json:"isuserdefined,omitempty"` - Osdisplayname string `json:"osdisplayname,omitempty"` - Osnameforhypervisor string `json:"osnameforhypervisor,omitempty"` - Ostypeid string `json:"ostypeid,omitempty"` + JobID string `json:"jobid"` + Description string `json:"description"` + Id string `json:"id"` + Isuserdefined bool `json:"isuserdefined"` + Oscategoryid string `json:"oscategoryid"` } type AddGuestOsMappingParams struct { @@ -875,18 +247,753 @@ func (s *GuestOSService) AddGuestOsMapping(p *AddGuestOsMappingParams) (*AddGues return nil, err } } + return &r, nil } type AddGuestOsMappingResponse struct { - JobID string `json:"jobid,omitempty"` - Hypervisor string `json:"hypervisor,omitempty"` - Hypervisorversion string `json:"hypervisorversion,omitempty"` - Id string `json:"id,omitempty"` - Isuserdefined string `json:"isuserdefined,omitempty"` - Osdisplayname string `json:"osdisplayname,omitempty"` - Osnameforhypervisor string `json:"osnameforhypervisor,omitempty"` - Ostypeid string `json:"ostypeid,omitempty"` + JobID string `json:"jobid"` + Hypervisor string `json:"hypervisor"` + Hypervisorversion string `json:"hypervisorversion"` + Id string `json:"id"` + Isuserdefined string `json:"isuserdefined"` + Osdisplayname string `json:"osdisplayname"` + Osnameforhypervisor string `json:"osnameforhypervisor"` + Ostypeid string `json:"ostypeid"` +} + +type ListGuestOsMappingParams struct { + p map[string]interface{} +} + +func (p *ListGuestOsMappingParams) toURLValues() url.Values { + u := url.Values{} + if p.p == nil { + return u + } + if v, found := p.p["hypervisor"]; found { + u.Set("hypervisor", v.(string)) + } + if v, found := p.p["hypervisorversion"]; found { + u.Set("hypervisorversion", v.(string)) + } + if v, found := p.p["id"]; found { + u.Set("id", v.(string)) + } + if v, found := p.p["keyword"]; found { + u.Set("keyword", v.(string)) + } + if v, found := p.p["ostypeid"]; found { + u.Set("ostypeid", v.(string)) + } + if v, found := p.p["page"]; found { + vv := strconv.Itoa(v.(int)) + u.Set("page", vv) + } + if v, found := p.p["pagesize"]; found { + vv := strconv.Itoa(v.(int)) + u.Set("pagesize", vv) + } + return u +} + +func (p *ListGuestOsMappingParams) SetHypervisor(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["hypervisor"] = v + return +} + +func (p *ListGuestOsMappingParams) SetHypervisorversion(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["hypervisorversion"] = v + return +} + +func (p *ListGuestOsMappingParams) SetId(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["id"] = v + return +} + +func (p *ListGuestOsMappingParams) SetKeyword(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["keyword"] = v + return +} + +func (p *ListGuestOsMappingParams) SetOstypeid(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["ostypeid"] = v + return +} + +func (p *ListGuestOsMappingParams) SetPage(v int) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["page"] = v + return +} + +func (p *ListGuestOsMappingParams) SetPagesize(v int) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["pagesize"] = v + return +} + +// You should always use this function to get a new ListGuestOsMappingParams instance, +// as then you are sure you have configured all required params +func (s *GuestOSService) NewListGuestOsMappingParams() *ListGuestOsMappingParams { + p := &ListGuestOsMappingParams{} + p.p = make(map[string]interface{}) + return p +} + +// This is a courtesy helper function, which in some cases may not work as expected! +func (s *GuestOSService) GetGuestOsMappingByID(id string, opts ...OptionFunc) (*GuestOsMapping, int, error) { + p := &ListGuestOsMappingParams{} + p.p = make(map[string]interface{}) + + p.p["id"] = id + + for _, fn := range append(s.cs.options, opts...) { + if err := fn(s.cs, p); err != nil { + return nil, -1, err + } + } + + l, err := s.ListGuestOsMapping(p) + if err != nil { + if strings.Contains(err.Error(), fmt.Sprintf( + "Invalid parameter id value=%s due to incorrect long value format, "+ + "or entity does not exist", id)) { + return nil, 0, fmt.Errorf("No match found for %s: %+v", id, l) + } + return nil, -1, err + } + + if l.Count == 0 { + return nil, l.Count, fmt.Errorf("No match found for %s: %+v", id, l) + } + + if l.Count == 1 { + return l.GuestOsMapping[0], l.Count, nil + } + return nil, l.Count, fmt.Errorf("There is more then one result for GuestOsMapping UUID: %s!", id) +} + +// Lists all available OS mappings for given hypervisor +func (s *GuestOSService) ListGuestOsMapping(p *ListGuestOsMappingParams) (*ListGuestOsMappingResponse, error) { + resp, err := s.cs.newRequest("listGuestOsMapping", p.toURLValues()) + if err != nil { + return nil, err + } + + var r ListGuestOsMappingResponse + if err := json.Unmarshal(resp, &r); err != nil { + return nil, err + } + + return &r, nil +} + +type ListGuestOsMappingResponse struct { + Count int `json:"count"` + GuestOsMapping []*GuestOsMapping `json:"guestosmapping"` +} + +type GuestOsMapping struct { + Hypervisor string `json:"hypervisor"` + Hypervisorversion string `json:"hypervisorversion"` + Id string `json:"id"` + Isuserdefined string `json:"isuserdefined"` + Osdisplayname string `json:"osdisplayname"` + Osnameforhypervisor string `json:"osnameforhypervisor"` + Ostypeid string `json:"ostypeid"` +} + +type ListOsCategoriesParams struct { + p map[string]interface{} +} + +func (p *ListOsCategoriesParams) toURLValues() url.Values { + u := url.Values{} + if p.p == nil { + return u + } + if v, found := p.p["id"]; found { + u.Set("id", v.(string)) + } + if v, found := p.p["keyword"]; found { + u.Set("keyword", v.(string)) + } + if v, found := p.p["name"]; found { + u.Set("name", v.(string)) + } + if v, found := p.p["page"]; found { + vv := strconv.Itoa(v.(int)) + u.Set("page", vv) + } + if v, found := p.p["pagesize"]; found { + vv := strconv.Itoa(v.(int)) + u.Set("pagesize", vv) + } + return u +} + +func (p *ListOsCategoriesParams) SetId(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["id"] = v + return +} + +func (p *ListOsCategoriesParams) SetKeyword(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["keyword"] = v + return +} + +func (p *ListOsCategoriesParams) SetName(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["name"] = v + return +} + +func (p *ListOsCategoriesParams) SetPage(v int) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["page"] = v + return +} + +func (p *ListOsCategoriesParams) SetPagesize(v int) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["pagesize"] = v + return +} + +// You should always use this function to get a new ListOsCategoriesParams instance, +// as then you are sure you have configured all required params +func (s *GuestOSService) NewListOsCategoriesParams() *ListOsCategoriesParams { + p := &ListOsCategoriesParams{} + p.p = make(map[string]interface{}) + return p +} + +// This is a courtesy helper function, which in some cases may not work as expected! +func (s *GuestOSService) GetOsCategoryID(name string, opts ...OptionFunc) (string, int, error) { + p := &ListOsCategoriesParams{} + p.p = make(map[string]interface{}) + + p.p["name"] = name + + for _, fn := range append(s.cs.options, opts...) { + if err := fn(s.cs, p); err != nil { + return "", -1, err + } + } + + l, err := s.ListOsCategories(p) + if err != nil { + return "", -1, err + } + + if l.Count == 0 { + return "", l.Count, fmt.Errorf("No match found for %s: %+v", name, l) + } + + if l.Count == 1 { + return l.OsCategories[0].Id, l.Count, nil + } + + if l.Count > 1 { + for _, v := range l.OsCategories { + if v.Name == name { + return v.Id, l.Count, nil + } + } + } + return "", l.Count, fmt.Errorf("Could not find an exact match for %s: %+v", name, l) +} + +// This is a courtesy helper function, which in some cases may not work as expected! +func (s *GuestOSService) GetOsCategoryByName(name string, opts ...OptionFunc) (*OsCategory, int, error) { + id, count, err := s.GetOsCategoryID(name, opts...) + if err != nil { + return nil, count, err + } + + r, count, err := s.GetOsCategoryByID(id, opts...) + if err != nil { + return nil, count, err + } + return r, count, nil +} + +// This is a courtesy helper function, which in some cases may not work as expected! +func (s *GuestOSService) GetOsCategoryByID(id string, opts ...OptionFunc) (*OsCategory, int, error) { + p := &ListOsCategoriesParams{} + p.p = make(map[string]interface{}) + + p.p["id"] = id + + for _, fn := range append(s.cs.options, opts...) { + if err := fn(s.cs, p); err != nil { + return nil, -1, err + } + } + + l, err := s.ListOsCategories(p) + if err != nil { + if strings.Contains(err.Error(), fmt.Sprintf( + "Invalid parameter id value=%s due to incorrect long value format, "+ + "or entity does not exist", id)) { + return nil, 0, fmt.Errorf("No match found for %s: %+v", id, l) + } + return nil, -1, err + } + + if l.Count == 0 { + return nil, l.Count, fmt.Errorf("No match found for %s: %+v", id, l) + } + + if l.Count == 1 { + return l.OsCategories[0], l.Count, nil + } + return nil, l.Count, fmt.Errorf("There is more then one result for OsCategory UUID: %s!", id) +} + +// Lists all supported OS categories for this cloud. +func (s *GuestOSService) ListOsCategories(p *ListOsCategoriesParams) (*ListOsCategoriesResponse, error) { + resp, err := s.cs.newRequest("listOsCategories", p.toURLValues()) + if err != nil { + return nil, err + } + + var r ListOsCategoriesResponse + if err := json.Unmarshal(resp, &r); err != nil { + return nil, err + } + + return &r, nil +} + +type ListOsCategoriesResponse struct { + Count int `json:"count"` + OsCategories []*OsCategory `json:"oscategory"` +} + +type OsCategory struct { + Id string `json:"id"` + Name string `json:"name"` +} + +type ListOsTypesParams struct { + p map[string]interface{} +} + +func (p *ListOsTypesParams) toURLValues() url.Values { + u := url.Values{} + if p.p == nil { + return u + } + if v, found := p.p["description"]; found { + u.Set("description", v.(string)) + } + if v, found := p.p["id"]; found { + u.Set("id", v.(string)) + } + if v, found := p.p["keyword"]; found { + u.Set("keyword", v.(string)) + } + if v, found := p.p["oscategoryid"]; found { + u.Set("oscategoryid", v.(string)) + } + if v, found := p.p["page"]; found { + vv := strconv.Itoa(v.(int)) + u.Set("page", vv) + } + if v, found := p.p["pagesize"]; found { + vv := strconv.Itoa(v.(int)) + u.Set("pagesize", vv) + } + return u +} + +func (p *ListOsTypesParams) SetDescription(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["description"] = v + return +} + +func (p *ListOsTypesParams) SetId(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["id"] = v + return +} + +func (p *ListOsTypesParams) SetKeyword(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["keyword"] = v + return +} + +func (p *ListOsTypesParams) SetOscategoryid(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["oscategoryid"] = v + return +} + +func (p *ListOsTypesParams) SetPage(v int) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["page"] = v + return +} + +func (p *ListOsTypesParams) SetPagesize(v int) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["pagesize"] = v + return +} + +// You should always use this function to get a new ListOsTypesParams instance, +// as then you are sure you have configured all required params +func (s *GuestOSService) NewListOsTypesParams() *ListOsTypesParams { + p := &ListOsTypesParams{} + p.p = make(map[string]interface{}) + return p +} + +// This is a courtesy helper function, which in some cases may not work as expected! +func (s *GuestOSService) GetOsTypeByID(id string, opts ...OptionFunc) (*OsType, int, error) { + p := &ListOsTypesParams{} + p.p = make(map[string]interface{}) + + p.p["id"] = id + + for _, fn := range append(s.cs.options, opts...) { + if err := fn(s.cs, p); err != nil { + return nil, -1, err + } + } + + l, err := s.ListOsTypes(p) + if err != nil { + if strings.Contains(err.Error(), fmt.Sprintf( + "Invalid parameter id value=%s due to incorrect long value format, "+ + "or entity does not exist", id)) { + return nil, 0, fmt.Errorf("No match found for %s: %+v", id, l) + } + return nil, -1, err + } + + if l.Count == 0 { + return nil, l.Count, fmt.Errorf("No match found for %s: %+v", id, l) + } + + if l.Count == 1 { + return l.OsTypes[0], l.Count, nil + } + return nil, l.Count, fmt.Errorf("There is more then one result for OsType UUID: %s!", id) +} + +// Lists all supported OS types for this cloud. +func (s *GuestOSService) ListOsTypes(p *ListOsTypesParams) (*ListOsTypesResponse, error) { + resp, err := s.cs.newRequest("listOsTypes", p.toURLValues()) + if err != nil { + return nil, err + } + + var r ListOsTypesResponse + if err := json.Unmarshal(resp, &r); err != nil { + return nil, err + } + + return &r, nil +} + +type ListOsTypesResponse struct { + Count int `json:"count"` + OsTypes []*OsType `json:"ostype"` +} + +type OsType struct { + Description string `json:"description"` + Id string `json:"id"` + Isuserdefined bool `json:"isuserdefined"` + Oscategoryid string `json:"oscategoryid"` +} + +type RemoveGuestOsParams struct { + p map[string]interface{} +} + +func (p *RemoveGuestOsParams) toURLValues() url.Values { + u := url.Values{} + if p.p == nil { + return u + } + if v, found := p.p["id"]; found { + u.Set("id", v.(string)) + } + return u +} + +func (p *RemoveGuestOsParams) SetId(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["id"] = v + return +} + +// You should always use this function to get a new RemoveGuestOsParams instance, +// as then you are sure you have configured all required params +func (s *GuestOSService) NewRemoveGuestOsParams(id string) *RemoveGuestOsParams { + p := &RemoveGuestOsParams{} + p.p = make(map[string]interface{}) + p.p["id"] = id + return p +} + +// Removes a Guest OS from listing. +func (s *GuestOSService) RemoveGuestOs(p *RemoveGuestOsParams) (*RemoveGuestOsResponse, error) { + resp, err := s.cs.newRequest("removeGuestOs", p.toURLValues()) + if err != nil { + return nil, err + } + + var r RemoveGuestOsResponse + if err := json.Unmarshal(resp, &r); err != nil { + return nil, err + } + + // If we have a async client, we need to wait for the async result + if s.cs.async { + b, err := s.cs.GetAsyncJobResult(r.JobID, s.cs.timeout) + if err != nil { + if err == AsyncTimeoutErr { + return &r, err + } + return nil, err + } + + if err := json.Unmarshal(b, &r); err != nil { + return nil, err + } + } + + return &r, nil +} + +type RemoveGuestOsResponse struct { + JobID string `json:"jobid"` + Displaytext string `json:"displaytext"` + Success bool `json:"success"` +} + +type RemoveGuestOsMappingParams struct { + p map[string]interface{} +} + +func (p *RemoveGuestOsMappingParams) toURLValues() url.Values { + u := url.Values{} + if p.p == nil { + return u + } + if v, found := p.p["id"]; found { + u.Set("id", v.(string)) + } + return u +} + +func (p *RemoveGuestOsMappingParams) SetId(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["id"] = v + return +} + +// You should always use this function to get a new RemoveGuestOsMappingParams instance, +// as then you are sure you have configured all required params +func (s *GuestOSService) NewRemoveGuestOsMappingParams(id string) *RemoveGuestOsMappingParams { + p := &RemoveGuestOsMappingParams{} + p.p = make(map[string]interface{}) + p.p["id"] = id + return p +} + +// Removes a Guest OS Mapping. +func (s *GuestOSService) RemoveGuestOsMapping(p *RemoveGuestOsMappingParams) (*RemoveGuestOsMappingResponse, error) { + resp, err := s.cs.newRequest("removeGuestOsMapping", p.toURLValues()) + if err != nil { + return nil, err + } + + var r RemoveGuestOsMappingResponse + if err := json.Unmarshal(resp, &r); err != nil { + return nil, err + } + + // If we have a async client, we need to wait for the async result + if s.cs.async { + b, err := s.cs.GetAsyncJobResult(r.JobID, s.cs.timeout) + if err != nil { + if err == AsyncTimeoutErr { + return &r, err + } + return nil, err + } + + if err := json.Unmarshal(b, &r); err != nil { + return nil, err + } + } + + return &r, nil +} + +type RemoveGuestOsMappingResponse struct { + JobID string `json:"jobid"` + Displaytext string `json:"displaytext"` + Success bool `json:"success"` +} + +type UpdateGuestOsParams struct { + p map[string]interface{} +} + +func (p *UpdateGuestOsParams) toURLValues() url.Values { + u := url.Values{} + if p.p == nil { + return u + } + if v, found := p.p["details"]; found { + i := 0 + for k, vv := range v.(map[string]string) { + u.Set(fmt.Sprintf("details[%d].%s", i, k), vv) + i++ + } + } + if v, found := p.p["id"]; found { + u.Set("id", v.(string)) + } + if v, found := p.p["osdisplayname"]; found { + u.Set("osdisplayname", v.(string)) + } + return u +} + +func (p *UpdateGuestOsParams) SetDetails(v map[string]string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["details"] = v + return +} + +func (p *UpdateGuestOsParams) SetId(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["id"] = v + return +} + +func (p *UpdateGuestOsParams) SetOsdisplayname(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["osdisplayname"] = v + return +} + +// You should always use this function to get a new UpdateGuestOsParams instance, +// as then you are sure you have configured all required params +func (s *GuestOSService) NewUpdateGuestOsParams(details map[string]string, id string, osdisplayname string) *UpdateGuestOsParams { + p := &UpdateGuestOsParams{} + p.p = make(map[string]interface{}) + p.p["details"] = details + p.p["id"] = id + p.p["osdisplayname"] = osdisplayname + return p +} + +// Updates the information about Guest OS +func (s *GuestOSService) UpdateGuestOs(p *UpdateGuestOsParams) (*UpdateGuestOsResponse, error) { + resp, err := s.cs.newRequest("updateGuestOs", p.toURLValues()) + if err != nil { + return nil, err + } + + var r UpdateGuestOsResponse + if err := json.Unmarshal(resp, &r); err != nil { + return nil, err + } + + // If we have a async client, we need to wait for the async result + if s.cs.async { + b, err := s.cs.GetAsyncJobResult(r.JobID, s.cs.timeout) + if err != nil { + if err == AsyncTimeoutErr { + return &r, err + } + return nil, err + } + + b, err = getRawValue(b) + if err != nil { + return nil, err + } + + if err := json.Unmarshal(b, &r); err != nil { + return nil, err + } + } + + return &r, nil +} + +type UpdateGuestOsResponse struct { + JobID string `json:"jobid"` + Description string `json:"description"` + Id string `json:"id"` + Isuserdefined bool `json:"isuserdefined"` + Oscategoryid string `json:"oscategoryid"` } type UpdateGuestOsMappingParams struct { @@ -964,83 +1071,17 @@ func (s *GuestOSService) UpdateGuestOsMapping(p *UpdateGuestOsMappingParams) (*U return nil, err } } + return &r, nil } type UpdateGuestOsMappingResponse struct { - JobID string `json:"jobid,omitempty"` - Hypervisor string `json:"hypervisor,omitempty"` - Hypervisorversion string `json:"hypervisorversion,omitempty"` - Id string `json:"id,omitempty"` - Isuserdefined string `json:"isuserdefined,omitempty"` - Osdisplayname string `json:"osdisplayname,omitempty"` - Osnameforhypervisor string `json:"osnameforhypervisor,omitempty"` - Ostypeid string `json:"ostypeid,omitempty"` -} - -type RemoveGuestOsMappingParams struct { - p map[string]interface{} -} - -func (p *RemoveGuestOsMappingParams) toURLValues() url.Values { - u := url.Values{} - if p.p == nil { - return u - } - if v, found := p.p["id"]; found { - u.Set("id", v.(string)) - } - return u -} - -func (p *RemoveGuestOsMappingParams) SetId(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["id"] = v - return -} - -// You should always use this function to get a new RemoveGuestOsMappingParams instance, -// as then you are sure you have configured all required params -func (s *GuestOSService) NewRemoveGuestOsMappingParams(id string) *RemoveGuestOsMappingParams { - p := &RemoveGuestOsMappingParams{} - p.p = make(map[string]interface{}) - p.p["id"] = id - return p -} - -// Removes a Guest OS Mapping. -func (s *GuestOSService) RemoveGuestOsMapping(p *RemoveGuestOsMappingParams) (*RemoveGuestOsMappingResponse, error) { - resp, err := s.cs.newRequest("removeGuestOsMapping", p.toURLValues()) - if err != nil { - return nil, err - } - - var r RemoveGuestOsMappingResponse - if err := json.Unmarshal(resp, &r); err != nil { - return nil, err - } - - // If we have a async client, we need to wait for the async result - if s.cs.async { - b, err := s.cs.GetAsyncJobResult(r.JobID, s.cs.timeout) - if err != nil { - if err == AsyncTimeoutErr { - return &r, err - } - return nil, err - } - - if err := json.Unmarshal(b, &r); err != nil { - return nil, err - } - } - return &r, nil -} - -type RemoveGuestOsMappingResponse struct { - JobID string `json:"jobid,omitempty"` - Displaytext string `json:"displaytext,omitempty"` - Success bool `json:"success,omitempty"` + JobID string `json:"jobid"` + Hypervisor string `json:"hypervisor"` + Hypervisorversion string `json:"hypervisorversion"` + Id string `json:"id"` + Isuserdefined string `json:"isuserdefined"` + Osdisplayname string `json:"osdisplayname"` + Osnameforhypervisor string `json:"osnameforhypervisor"` + Ostypeid string `json:"ostypeid"` } diff --git a/vendor/github.com/xanzy/go-cloudstack/cloudstack/HostService.go b/vendor/github.com/xanzy/go-cloudstack/cloudstack/HostService.go index 4306b5a9d..a5e6f3590 100644 --- a/vendor/github.com/xanzy/go-cloudstack/cloudstack/HostService.go +++ b/vendor/github.com/xanzy/go-cloudstack/cloudstack/HostService.go @@ -1,5 +1,5 @@ // -// Copyright 2016, Sander van Harmelen +// Copyright 2018, Sander van Harmelen // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -24,1658 +24,6 @@ import ( "strings" ) -type AddHostParams struct { - p map[string]interface{} -} - -func (p *AddHostParams) toURLValues() url.Values { - u := url.Values{} - if p.p == nil { - return u - } - if v, found := p.p["allocationstate"]; found { - u.Set("allocationstate", v.(string)) - } - if v, found := p.p["clusterid"]; found { - u.Set("clusterid", v.(string)) - } - if v, found := p.p["clustername"]; found { - u.Set("clustername", v.(string)) - } - if v, found := p.p["hosttags"]; found { - vv := strings.Join(v.([]string), ",") - u.Set("hosttags", vv) - } - if v, found := p.p["hypervisor"]; found { - u.Set("hypervisor", v.(string)) - } - if v, found := p.p["password"]; found { - u.Set("password", v.(string)) - } - if v, found := p.p["podid"]; found { - u.Set("podid", v.(string)) - } - if v, found := p.p["url"]; found { - u.Set("url", v.(string)) - } - if v, found := p.p["username"]; found { - u.Set("username", v.(string)) - } - if v, found := p.p["zoneid"]; found { - u.Set("zoneid", v.(string)) - } - return u -} - -func (p *AddHostParams) SetAllocationstate(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["allocationstate"] = v - return -} - -func (p *AddHostParams) SetClusterid(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["clusterid"] = v - return -} - -func (p *AddHostParams) SetClustername(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["clustername"] = v - return -} - -func (p *AddHostParams) SetHosttags(v []string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["hosttags"] = v - return -} - -func (p *AddHostParams) SetHypervisor(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["hypervisor"] = v - return -} - -func (p *AddHostParams) SetPassword(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["password"] = v - return -} - -func (p *AddHostParams) SetPodid(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["podid"] = v - return -} - -func (p *AddHostParams) SetUrl(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["url"] = v - return -} - -func (p *AddHostParams) SetUsername(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["username"] = v - return -} - -func (p *AddHostParams) SetZoneid(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["zoneid"] = v - return -} - -// You should always use this function to get a new AddHostParams instance, -// as then you are sure you have configured all required params -func (s *HostService) NewAddHostParams(hypervisor string, password string, podid string, url string, username string, zoneid string) *AddHostParams { - p := &AddHostParams{} - p.p = make(map[string]interface{}) - p.p["hypervisor"] = hypervisor - p.p["password"] = password - p.p["podid"] = podid - p.p["url"] = url - p.p["username"] = username - p.p["zoneid"] = zoneid - return p -} - -// Adds a new host. -func (s *HostService) AddHost(p *AddHostParams) (*AddHostResponse, error) { - resp, err := s.cs.newRequest("addHost", p.toURLValues()) - if err != nil { - return nil, err - } - - var r AddHostResponse - if err := json.Unmarshal(resp, &r); err != nil { - return nil, err - } - return &r, nil -} - -type AddHostResponse struct { - Averageload int64 `json:"averageload,omitempty"` - Capabilities string `json:"capabilities,omitempty"` - Clusterid string `json:"clusterid,omitempty"` - Clustername string `json:"clustername,omitempty"` - Clustertype string `json:"clustertype,omitempty"` - Cpuallocated string `json:"cpuallocated,omitempty"` - Cpunumber int `json:"cpunumber,omitempty"` - Cpusockets int `json:"cpusockets,omitempty"` - Cpuspeed int64 `json:"cpuspeed,omitempty"` - Cpuused string `json:"cpuused,omitempty"` - Cpuwithoverprovisioning string `json:"cpuwithoverprovisioning,omitempty"` - Created string `json:"created,omitempty"` - Details map[string]string `json:"details,omitempty"` - Disconnected string `json:"disconnected,omitempty"` - Disksizeallocated int64 `json:"disksizeallocated,omitempty"` - Disksizetotal int64 `json:"disksizetotal,omitempty"` - Events string `json:"events,omitempty"` - Gpugroup []struct { - Gpugroupname string `json:"gpugroupname,omitempty"` - Vgpu []struct { - Maxcapacity int64 `json:"maxcapacity,omitempty"` - Maxheads int64 `json:"maxheads,omitempty"` - Maxresolutionx int64 `json:"maxresolutionx,omitempty"` - Maxresolutiony int64 `json:"maxresolutiony,omitempty"` - Maxvgpuperpgpu int64 `json:"maxvgpuperpgpu,omitempty"` - Remainingcapacity int64 `json:"remainingcapacity,omitempty"` - Vgputype string `json:"vgputype,omitempty"` - Videoram int64 `json:"videoram,omitempty"` - } `json:"vgpu,omitempty"` - } `json:"gpugroup,omitempty"` - Hahost bool `json:"hahost,omitempty"` - Hasenoughcapacity bool `json:"hasenoughcapacity,omitempty"` - Hosttags string `json:"hosttags,omitempty"` - Hypervisor string `json:"hypervisor,omitempty"` - Hypervisorversion string `json:"hypervisorversion,omitempty"` - Id string `json:"id,omitempty"` - Ipaddress string `json:"ipaddress,omitempty"` - Islocalstorageactive bool `json:"islocalstorageactive,omitempty"` - Lastpinged string `json:"lastpinged,omitempty"` - Managementserverid int64 `json:"managementserverid,omitempty"` - Memoryallocated int64 `json:"memoryallocated,omitempty"` - Memorytotal int64 `json:"memorytotal,omitempty"` - Memoryused int64 `json:"memoryused,omitempty"` - Name string `json:"name,omitempty"` - Networkkbsread int64 `json:"networkkbsread,omitempty"` - Networkkbswrite int64 `json:"networkkbswrite,omitempty"` - Oscategoryid string `json:"oscategoryid,omitempty"` - Oscategoryname string `json:"oscategoryname,omitempty"` - Podid string `json:"podid,omitempty"` - Podname string `json:"podname,omitempty"` - Removed string `json:"removed,omitempty"` - Resourcestate string `json:"resourcestate,omitempty"` - State string `json:"state,omitempty"` - Suitableformigration bool `json:"suitableformigration,omitempty"` - Type string `json:"type,omitempty"` - Version string `json:"version,omitempty"` - Zoneid string `json:"zoneid,omitempty"` - Zonename string `json:"zonename,omitempty"` -} - -type ReconnectHostParams struct { - p map[string]interface{} -} - -func (p *ReconnectHostParams) toURLValues() url.Values { - u := url.Values{} - if p.p == nil { - return u - } - if v, found := p.p["id"]; found { - u.Set("id", v.(string)) - } - return u -} - -func (p *ReconnectHostParams) SetId(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["id"] = v - return -} - -// You should always use this function to get a new ReconnectHostParams instance, -// as then you are sure you have configured all required params -func (s *HostService) NewReconnectHostParams(id string) *ReconnectHostParams { - p := &ReconnectHostParams{} - p.p = make(map[string]interface{}) - p.p["id"] = id - return p -} - -// Reconnects a host. -func (s *HostService) ReconnectHost(p *ReconnectHostParams) (*ReconnectHostResponse, error) { - resp, err := s.cs.newRequest("reconnectHost", p.toURLValues()) - if err != nil { - return nil, err - } - - var r ReconnectHostResponse - if err := json.Unmarshal(resp, &r); err != nil { - return nil, err - } - - // If we have a async client, we need to wait for the async result - if s.cs.async { - b, err := s.cs.GetAsyncJobResult(r.JobID, s.cs.timeout) - if err != nil { - if err == AsyncTimeoutErr { - return &r, err - } - return nil, err - } - - b, err = getRawValue(b) - if err != nil { - return nil, err - } - - if err := json.Unmarshal(b, &r); err != nil { - return nil, err - } - } - return &r, nil -} - -type ReconnectHostResponse struct { - JobID string `json:"jobid,omitempty"` - Averageload int64 `json:"averageload,omitempty"` - Capabilities string `json:"capabilities,omitempty"` - Clusterid string `json:"clusterid,omitempty"` - Clustername string `json:"clustername,omitempty"` - Clustertype string `json:"clustertype,omitempty"` - Cpuallocated string `json:"cpuallocated,omitempty"` - Cpunumber int `json:"cpunumber,omitempty"` - Cpusockets int `json:"cpusockets,omitempty"` - Cpuspeed int64 `json:"cpuspeed,omitempty"` - Cpuused string `json:"cpuused,omitempty"` - Cpuwithoverprovisioning string `json:"cpuwithoverprovisioning,omitempty"` - Created string `json:"created,omitempty"` - Details map[string]string `json:"details,omitempty"` - Disconnected string `json:"disconnected,omitempty"` - Disksizeallocated int64 `json:"disksizeallocated,omitempty"` - Disksizetotal int64 `json:"disksizetotal,omitempty"` - Events string `json:"events,omitempty"` - Gpugroup []struct { - Gpugroupname string `json:"gpugroupname,omitempty"` - Vgpu []struct { - Maxcapacity int64 `json:"maxcapacity,omitempty"` - Maxheads int64 `json:"maxheads,omitempty"` - Maxresolutionx int64 `json:"maxresolutionx,omitempty"` - Maxresolutiony int64 `json:"maxresolutiony,omitempty"` - Maxvgpuperpgpu int64 `json:"maxvgpuperpgpu,omitempty"` - Remainingcapacity int64 `json:"remainingcapacity,omitempty"` - Vgputype string `json:"vgputype,omitempty"` - Videoram int64 `json:"videoram,omitempty"` - } `json:"vgpu,omitempty"` - } `json:"gpugroup,omitempty"` - Hahost bool `json:"hahost,omitempty"` - Hasenoughcapacity bool `json:"hasenoughcapacity,omitempty"` - Hosttags string `json:"hosttags,omitempty"` - Hypervisor string `json:"hypervisor,omitempty"` - Hypervisorversion string `json:"hypervisorversion,omitempty"` - Id string `json:"id,omitempty"` - Ipaddress string `json:"ipaddress,omitempty"` - Islocalstorageactive bool `json:"islocalstorageactive,omitempty"` - Lastpinged string `json:"lastpinged,omitempty"` - Managementserverid int64 `json:"managementserverid,omitempty"` - Memoryallocated int64 `json:"memoryallocated,omitempty"` - Memorytotal int64 `json:"memorytotal,omitempty"` - Memoryused int64 `json:"memoryused,omitempty"` - Name string `json:"name,omitempty"` - Networkkbsread int64 `json:"networkkbsread,omitempty"` - Networkkbswrite int64 `json:"networkkbswrite,omitempty"` - Oscategoryid string `json:"oscategoryid,omitempty"` - Oscategoryname string `json:"oscategoryname,omitempty"` - Podid string `json:"podid,omitempty"` - Podname string `json:"podname,omitempty"` - Removed string `json:"removed,omitempty"` - Resourcestate string `json:"resourcestate,omitempty"` - State string `json:"state,omitempty"` - Suitableformigration bool `json:"suitableformigration,omitempty"` - Type string `json:"type,omitempty"` - Version string `json:"version,omitempty"` - Zoneid string `json:"zoneid,omitempty"` - Zonename string `json:"zonename,omitempty"` -} - -type UpdateHostParams struct { - p map[string]interface{} -} - -func (p *UpdateHostParams) toURLValues() url.Values { - u := url.Values{} - if p.p == nil { - return u - } - if v, found := p.p["allocationstate"]; found { - u.Set("allocationstate", v.(string)) - } - if v, found := p.p["hosttags"]; found { - vv := strings.Join(v.([]string), ",") - u.Set("hosttags", vv) - } - if v, found := p.p["id"]; found { - u.Set("id", v.(string)) - } - if v, found := p.p["oscategoryid"]; found { - u.Set("oscategoryid", v.(string)) - } - if v, found := p.p["url"]; found { - u.Set("url", v.(string)) - } - return u -} - -func (p *UpdateHostParams) SetAllocationstate(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["allocationstate"] = v - return -} - -func (p *UpdateHostParams) SetHosttags(v []string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["hosttags"] = v - return -} - -func (p *UpdateHostParams) SetId(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["id"] = v - return -} - -func (p *UpdateHostParams) SetOscategoryid(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["oscategoryid"] = v - return -} - -func (p *UpdateHostParams) SetUrl(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["url"] = v - return -} - -// You should always use this function to get a new UpdateHostParams instance, -// as then you are sure you have configured all required params -func (s *HostService) NewUpdateHostParams(id string) *UpdateHostParams { - p := &UpdateHostParams{} - p.p = make(map[string]interface{}) - p.p["id"] = id - return p -} - -// Updates a host. -func (s *HostService) UpdateHost(p *UpdateHostParams) (*UpdateHostResponse, error) { - resp, err := s.cs.newRequest("updateHost", p.toURLValues()) - if err != nil { - return nil, err - } - - var r UpdateHostResponse - if err := json.Unmarshal(resp, &r); err != nil { - return nil, err - } - return &r, nil -} - -type UpdateHostResponse struct { - Averageload int64 `json:"averageload,omitempty"` - Capabilities string `json:"capabilities,omitempty"` - Clusterid string `json:"clusterid,omitempty"` - Clustername string `json:"clustername,omitempty"` - Clustertype string `json:"clustertype,omitempty"` - Cpuallocated string `json:"cpuallocated,omitempty"` - Cpunumber int `json:"cpunumber,omitempty"` - Cpusockets int `json:"cpusockets,omitempty"` - Cpuspeed int64 `json:"cpuspeed,omitempty"` - Cpuused string `json:"cpuused,omitempty"` - Cpuwithoverprovisioning string `json:"cpuwithoverprovisioning,omitempty"` - Created string `json:"created,omitempty"` - Details map[string]string `json:"details,omitempty"` - Disconnected string `json:"disconnected,omitempty"` - Disksizeallocated int64 `json:"disksizeallocated,omitempty"` - Disksizetotal int64 `json:"disksizetotal,omitempty"` - Events string `json:"events,omitempty"` - Gpugroup []struct { - Gpugroupname string `json:"gpugroupname,omitempty"` - Vgpu []struct { - Maxcapacity int64 `json:"maxcapacity,omitempty"` - Maxheads int64 `json:"maxheads,omitempty"` - Maxresolutionx int64 `json:"maxresolutionx,omitempty"` - Maxresolutiony int64 `json:"maxresolutiony,omitempty"` - Maxvgpuperpgpu int64 `json:"maxvgpuperpgpu,omitempty"` - Remainingcapacity int64 `json:"remainingcapacity,omitempty"` - Vgputype string `json:"vgputype,omitempty"` - Videoram int64 `json:"videoram,omitempty"` - } `json:"vgpu,omitempty"` - } `json:"gpugroup,omitempty"` - Hahost bool `json:"hahost,omitempty"` - Hasenoughcapacity bool `json:"hasenoughcapacity,omitempty"` - Hosttags string `json:"hosttags,omitempty"` - Hypervisor string `json:"hypervisor,omitempty"` - Hypervisorversion string `json:"hypervisorversion,omitempty"` - Id string `json:"id,omitempty"` - Ipaddress string `json:"ipaddress,omitempty"` - Islocalstorageactive bool `json:"islocalstorageactive,omitempty"` - Lastpinged string `json:"lastpinged,omitempty"` - Managementserverid int64 `json:"managementserverid,omitempty"` - Memoryallocated int64 `json:"memoryallocated,omitempty"` - Memorytotal int64 `json:"memorytotal,omitempty"` - Memoryused int64 `json:"memoryused,omitempty"` - Name string `json:"name,omitempty"` - Networkkbsread int64 `json:"networkkbsread,omitempty"` - Networkkbswrite int64 `json:"networkkbswrite,omitempty"` - Oscategoryid string `json:"oscategoryid,omitempty"` - Oscategoryname string `json:"oscategoryname,omitempty"` - Podid string `json:"podid,omitempty"` - Podname string `json:"podname,omitempty"` - Removed string `json:"removed,omitempty"` - Resourcestate string `json:"resourcestate,omitempty"` - State string `json:"state,omitempty"` - Suitableformigration bool `json:"suitableformigration,omitempty"` - Type string `json:"type,omitempty"` - Version string `json:"version,omitempty"` - Zoneid string `json:"zoneid,omitempty"` - Zonename string `json:"zonename,omitempty"` -} - -type DeleteHostParams struct { - p map[string]interface{} -} - -func (p *DeleteHostParams) toURLValues() url.Values { - u := url.Values{} - if p.p == nil { - return u - } - if v, found := p.p["forced"]; found { - vv := strconv.FormatBool(v.(bool)) - u.Set("forced", vv) - } - if v, found := p.p["forcedestroylocalstorage"]; found { - vv := strconv.FormatBool(v.(bool)) - u.Set("forcedestroylocalstorage", vv) - } - if v, found := p.p["id"]; found { - u.Set("id", v.(string)) - } - return u -} - -func (p *DeleteHostParams) SetForced(v bool) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["forced"] = v - return -} - -func (p *DeleteHostParams) SetForcedestroylocalstorage(v bool) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["forcedestroylocalstorage"] = v - return -} - -func (p *DeleteHostParams) SetId(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["id"] = v - return -} - -// You should always use this function to get a new DeleteHostParams instance, -// as then you are sure you have configured all required params -func (s *HostService) NewDeleteHostParams(id string) *DeleteHostParams { - p := &DeleteHostParams{} - p.p = make(map[string]interface{}) - p.p["id"] = id - return p -} - -// Deletes a host. -func (s *HostService) DeleteHost(p *DeleteHostParams) (*DeleteHostResponse, error) { - resp, err := s.cs.newRequest("deleteHost", p.toURLValues()) - if err != nil { - return nil, err - } - - var r DeleteHostResponse - if err := json.Unmarshal(resp, &r); err != nil { - return nil, err - } - return &r, nil -} - -type DeleteHostResponse struct { - Displaytext string `json:"displaytext,omitempty"` - Success string `json:"success,omitempty"` -} - -type PrepareHostForMaintenanceParams struct { - p map[string]interface{} -} - -func (p *PrepareHostForMaintenanceParams) toURLValues() url.Values { - u := url.Values{} - if p.p == nil { - return u - } - if v, found := p.p["id"]; found { - u.Set("id", v.(string)) - } - return u -} - -func (p *PrepareHostForMaintenanceParams) SetId(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["id"] = v - return -} - -// You should always use this function to get a new PrepareHostForMaintenanceParams instance, -// as then you are sure you have configured all required params -func (s *HostService) NewPrepareHostForMaintenanceParams(id string) *PrepareHostForMaintenanceParams { - p := &PrepareHostForMaintenanceParams{} - p.p = make(map[string]interface{}) - p.p["id"] = id - return p -} - -// Prepares a host for maintenance. -func (s *HostService) PrepareHostForMaintenance(p *PrepareHostForMaintenanceParams) (*PrepareHostForMaintenanceResponse, error) { - resp, err := s.cs.newRequest("prepareHostForMaintenance", p.toURLValues()) - if err != nil { - return nil, err - } - - var r PrepareHostForMaintenanceResponse - if err := json.Unmarshal(resp, &r); err != nil { - return nil, err - } - - // If we have a async client, we need to wait for the async result - if s.cs.async { - b, err := s.cs.GetAsyncJobResult(r.JobID, s.cs.timeout) - if err != nil { - if err == AsyncTimeoutErr { - return &r, err - } - return nil, err - } - - b, err = getRawValue(b) - if err != nil { - return nil, err - } - - if err := json.Unmarshal(b, &r); err != nil { - return nil, err - } - } - return &r, nil -} - -type PrepareHostForMaintenanceResponse struct { - JobID string `json:"jobid,omitempty"` - Averageload int64 `json:"averageload,omitempty"` - Capabilities string `json:"capabilities,omitempty"` - Clusterid string `json:"clusterid,omitempty"` - Clustername string `json:"clustername,omitempty"` - Clustertype string `json:"clustertype,omitempty"` - Cpuallocated string `json:"cpuallocated,omitempty"` - Cpunumber int `json:"cpunumber,omitempty"` - Cpusockets int `json:"cpusockets,omitempty"` - Cpuspeed int64 `json:"cpuspeed,omitempty"` - Cpuused string `json:"cpuused,omitempty"` - Cpuwithoverprovisioning string `json:"cpuwithoverprovisioning,omitempty"` - Created string `json:"created,omitempty"` - Details map[string]string `json:"details,omitempty"` - Disconnected string `json:"disconnected,omitempty"` - Disksizeallocated int64 `json:"disksizeallocated,omitempty"` - Disksizetotal int64 `json:"disksizetotal,omitempty"` - Events string `json:"events,omitempty"` - Gpugroup []struct { - Gpugroupname string `json:"gpugroupname,omitempty"` - Vgpu []struct { - Maxcapacity int64 `json:"maxcapacity,omitempty"` - Maxheads int64 `json:"maxheads,omitempty"` - Maxresolutionx int64 `json:"maxresolutionx,omitempty"` - Maxresolutiony int64 `json:"maxresolutiony,omitempty"` - Maxvgpuperpgpu int64 `json:"maxvgpuperpgpu,omitempty"` - Remainingcapacity int64 `json:"remainingcapacity,omitempty"` - Vgputype string `json:"vgputype,omitempty"` - Videoram int64 `json:"videoram,omitempty"` - } `json:"vgpu,omitempty"` - } `json:"gpugroup,omitempty"` - Hahost bool `json:"hahost,omitempty"` - Hasenoughcapacity bool `json:"hasenoughcapacity,omitempty"` - Hosttags string `json:"hosttags,omitempty"` - Hypervisor string `json:"hypervisor,omitempty"` - Hypervisorversion string `json:"hypervisorversion,omitempty"` - Id string `json:"id,omitempty"` - Ipaddress string `json:"ipaddress,omitempty"` - Islocalstorageactive bool `json:"islocalstorageactive,omitempty"` - Lastpinged string `json:"lastpinged,omitempty"` - Managementserverid int64 `json:"managementserverid,omitempty"` - Memoryallocated int64 `json:"memoryallocated,omitempty"` - Memorytotal int64 `json:"memorytotal,omitempty"` - Memoryused int64 `json:"memoryused,omitempty"` - Name string `json:"name,omitempty"` - Networkkbsread int64 `json:"networkkbsread,omitempty"` - Networkkbswrite int64 `json:"networkkbswrite,omitempty"` - Oscategoryid string `json:"oscategoryid,omitempty"` - Oscategoryname string `json:"oscategoryname,omitempty"` - Podid string `json:"podid,omitempty"` - Podname string `json:"podname,omitempty"` - Removed string `json:"removed,omitempty"` - Resourcestate string `json:"resourcestate,omitempty"` - State string `json:"state,omitempty"` - Suitableformigration bool `json:"suitableformigration,omitempty"` - Type string `json:"type,omitempty"` - Version string `json:"version,omitempty"` - Zoneid string `json:"zoneid,omitempty"` - Zonename string `json:"zonename,omitempty"` -} - -type CancelHostMaintenanceParams struct { - p map[string]interface{} -} - -func (p *CancelHostMaintenanceParams) toURLValues() url.Values { - u := url.Values{} - if p.p == nil { - return u - } - if v, found := p.p["id"]; found { - u.Set("id", v.(string)) - } - return u -} - -func (p *CancelHostMaintenanceParams) SetId(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["id"] = v - return -} - -// You should always use this function to get a new CancelHostMaintenanceParams instance, -// as then you are sure you have configured all required params -func (s *HostService) NewCancelHostMaintenanceParams(id string) *CancelHostMaintenanceParams { - p := &CancelHostMaintenanceParams{} - p.p = make(map[string]interface{}) - p.p["id"] = id - return p -} - -// Cancels host maintenance. -func (s *HostService) CancelHostMaintenance(p *CancelHostMaintenanceParams) (*CancelHostMaintenanceResponse, error) { - resp, err := s.cs.newRequest("cancelHostMaintenance", p.toURLValues()) - if err != nil { - return nil, err - } - - var r CancelHostMaintenanceResponse - if err := json.Unmarshal(resp, &r); err != nil { - return nil, err - } - - // If we have a async client, we need to wait for the async result - if s.cs.async { - b, err := s.cs.GetAsyncJobResult(r.JobID, s.cs.timeout) - if err != nil { - if err == AsyncTimeoutErr { - return &r, err - } - return nil, err - } - - b, err = getRawValue(b) - if err != nil { - return nil, err - } - - if err := json.Unmarshal(b, &r); err != nil { - return nil, err - } - } - return &r, nil -} - -type CancelHostMaintenanceResponse struct { - JobID string `json:"jobid,omitempty"` - Averageload int64 `json:"averageload,omitempty"` - Capabilities string `json:"capabilities,omitempty"` - Clusterid string `json:"clusterid,omitempty"` - Clustername string `json:"clustername,omitempty"` - Clustertype string `json:"clustertype,omitempty"` - Cpuallocated string `json:"cpuallocated,omitempty"` - Cpunumber int `json:"cpunumber,omitempty"` - Cpusockets int `json:"cpusockets,omitempty"` - Cpuspeed int64 `json:"cpuspeed,omitempty"` - Cpuused string `json:"cpuused,omitempty"` - Cpuwithoverprovisioning string `json:"cpuwithoverprovisioning,omitempty"` - Created string `json:"created,omitempty"` - Details map[string]string `json:"details,omitempty"` - Disconnected string `json:"disconnected,omitempty"` - Disksizeallocated int64 `json:"disksizeallocated,omitempty"` - Disksizetotal int64 `json:"disksizetotal,omitempty"` - Events string `json:"events,omitempty"` - Gpugroup []struct { - Gpugroupname string `json:"gpugroupname,omitempty"` - Vgpu []struct { - Maxcapacity int64 `json:"maxcapacity,omitempty"` - Maxheads int64 `json:"maxheads,omitempty"` - Maxresolutionx int64 `json:"maxresolutionx,omitempty"` - Maxresolutiony int64 `json:"maxresolutiony,omitempty"` - Maxvgpuperpgpu int64 `json:"maxvgpuperpgpu,omitempty"` - Remainingcapacity int64 `json:"remainingcapacity,omitempty"` - Vgputype string `json:"vgputype,omitempty"` - Videoram int64 `json:"videoram,omitempty"` - } `json:"vgpu,omitempty"` - } `json:"gpugroup,omitempty"` - Hahost bool `json:"hahost,omitempty"` - Hasenoughcapacity bool `json:"hasenoughcapacity,omitempty"` - Hosttags string `json:"hosttags,omitempty"` - Hypervisor string `json:"hypervisor,omitempty"` - Hypervisorversion string `json:"hypervisorversion,omitempty"` - Id string `json:"id,omitempty"` - Ipaddress string `json:"ipaddress,omitempty"` - Islocalstorageactive bool `json:"islocalstorageactive,omitempty"` - Lastpinged string `json:"lastpinged,omitempty"` - Managementserverid int64 `json:"managementserverid,omitempty"` - Memoryallocated int64 `json:"memoryallocated,omitempty"` - Memorytotal int64 `json:"memorytotal,omitempty"` - Memoryused int64 `json:"memoryused,omitempty"` - Name string `json:"name,omitempty"` - Networkkbsread int64 `json:"networkkbsread,omitempty"` - Networkkbswrite int64 `json:"networkkbswrite,omitempty"` - Oscategoryid string `json:"oscategoryid,omitempty"` - Oscategoryname string `json:"oscategoryname,omitempty"` - Podid string `json:"podid,omitempty"` - Podname string `json:"podname,omitempty"` - Removed string `json:"removed,omitempty"` - Resourcestate string `json:"resourcestate,omitempty"` - State string `json:"state,omitempty"` - Suitableformigration bool `json:"suitableformigration,omitempty"` - Type string `json:"type,omitempty"` - Version string `json:"version,omitempty"` - Zoneid string `json:"zoneid,omitempty"` - Zonename string `json:"zonename,omitempty"` -} - -type ListHostsParams struct { - p map[string]interface{} -} - -func (p *ListHostsParams) toURLValues() url.Values { - u := url.Values{} - if p.p == nil { - return u - } - if v, found := p.p["clusterid"]; found { - u.Set("clusterid", v.(string)) - } - if v, found := p.p["details"]; found { - vv := strings.Join(v.([]string), ",") - u.Set("details", vv) - } - if v, found := p.p["hahost"]; found { - vv := strconv.FormatBool(v.(bool)) - u.Set("hahost", vv) - } - if v, found := p.p["hypervisor"]; found { - u.Set("hypervisor", v.(string)) - } - if v, found := p.p["id"]; found { - u.Set("id", v.(string)) - } - if v, found := p.p["keyword"]; found { - u.Set("keyword", v.(string)) - } - if v, found := p.p["name"]; found { - u.Set("name", v.(string)) - } - if v, found := p.p["page"]; found { - vv := strconv.Itoa(v.(int)) - u.Set("page", vv) - } - if v, found := p.p["pagesize"]; found { - vv := strconv.Itoa(v.(int)) - u.Set("pagesize", vv) - } - if v, found := p.p["podid"]; found { - u.Set("podid", v.(string)) - } - if v, found := p.p["resourcestate"]; found { - u.Set("resourcestate", v.(string)) - } - if v, found := p.p["state"]; found { - u.Set("state", v.(string)) - } - if v, found := p.p["type"]; found { - u.Set("type", v.(string)) - } - if v, found := p.p["virtualmachineid"]; found { - u.Set("virtualmachineid", v.(string)) - } - if v, found := p.p["zoneid"]; found { - u.Set("zoneid", v.(string)) - } - return u -} - -func (p *ListHostsParams) SetClusterid(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["clusterid"] = v - return -} - -func (p *ListHostsParams) SetDetails(v []string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["details"] = v - return -} - -func (p *ListHostsParams) SetHahost(v bool) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["hahost"] = v - return -} - -func (p *ListHostsParams) SetHypervisor(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["hypervisor"] = v - return -} - -func (p *ListHostsParams) SetId(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["id"] = v - return -} - -func (p *ListHostsParams) SetKeyword(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["keyword"] = v - return -} - -func (p *ListHostsParams) SetName(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["name"] = v - return -} - -func (p *ListHostsParams) SetPage(v int) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["page"] = v - return -} - -func (p *ListHostsParams) SetPagesize(v int) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["pagesize"] = v - return -} - -func (p *ListHostsParams) SetPodid(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["podid"] = v - return -} - -func (p *ListHostsParams) SetResourcestate(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["resourcestate"] = v - return -} - -func (p *ListHostsParams) SetState(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["state"] = v - return -} - -func (p *ListHostsParams) SetType(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["type"] = v - return -} - -func (p *ListHostsParams) SetVirtualmachineid(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["virtualmachineid"] = v - return -} - -func (p *ListHostsParams) SetZoneid(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["zoneid"] = v - return -} - -// You should always use this function to get a new ListHostsParams instance, -// as then you are sure you have configured all required params -func (s *HostService) NewListHostsParams() *ListHostsParams { - p := &ListHostsParams{} - p.p = make(map[string]interface{}) - return p -} - -// This is a courtesy helper function, which in some cases may not work as expected! -func (s *HostService) GetHostID(name string, opts ...OptionFunc) (string, int, error) { - p := &ListHostsParams{} - p.p = make(map[string]interface{}) - - p.p["name"] = name - - for _, fn := range opts { - if err := fn(s.cs, p); err != nil { - return "", -1, err - } - } - - l, err := s.ListHosts(p) - if err != nil { - return "", -1, err - } - - if l.Count == 0 { - return "", l.Count, fmt.Errorf("No match found for %s: %+v", name, l) - } - - if l.Count == 1 { - return l.Hosts[0].Id, l.Count, nil - } - - if l.Count > 1 { - for _, v := range l.Hosts { - if v.Name == name { - return v.Id, l.Count, nil - } - } - } - return "", l.Count, fmt.Errorf("Could not find an exact match for %s: %+v", name, l) -} - -// This is a courtesy helper function, which in some cases may not work as expected! -func (s *HostService) GetHostByName(name string, opts ...OptionFunc) (*Host, int, error) { - id, count, err := s.GetHostID(name, opts...) - if err != nil { - return nil, count, err - } - - r, count, err := s.GetHostByID(id, opts...) - if err != nil { - return nil, count, err - } - return r, count, nil -} - -// This is a courtesy helper function, which in some cases may not work as expected! -func (s *HostService) GetHostByID(id string, opts ...OptionFunc) (*Host, int, error) { - p := &ListHostsParams{} - p.p = make(map[string]interface{}) - - p.p["id"] = id - - for _, fn := range opts { - if err := fn(s.cs, p); err != nil { - return nil, -1, err - } - } - - l, err := s.ListHosts(p) - if err != nil { - if strings.Contains(err.Error(), fmt.Sprintf( - "Invalid parameter id value=%s due to incorrect long value format, "+ - "or entity does not exist", id)) { - return nil, 0, fmt.Errorf("No match found for %s: %+v", id, l) - } - return nil, -1, err - } - - if l.Count == 0 { - return nil, l.Count, fmt.Errorf("No match found for %s: %+v", id, l) - } - - if l.Count == 1 { - return l.Hosts[0], l.Count, nil - } - return nil, l.Count, fmt.Errorf("There is more then one result for Host UUID: %s!", id) -} - -// Lists hosts. -func (s *HostService) ListHosts(p *ListHostsParams) (*ListHostsResponse, error) { - resp, err := s.cs.newRequest("listHosts", p.toURLValues()) - if err != nil { - return nil, err - } - - var r ListHostsResponse - if err := json.Unmarshal(resp, &r); err != nil { - return nil, err - } - return &r, nil -} - -type ListHostsResponse struct { - Count int `json:"count"` - Hosts []*Host `json:"host"` -} - -type Host struct { - Averageload int64 `json:"averageload,omitempty"` - Capabilities string `json:"capabilities,omitempty"` - Clusterid string `json:"clusterid,omitempty"` - Clustername string `json:"clustername,omitempty"` - Clustertype string `json:"clustertype,omitempty"` - Cpuallocated string `json:"cpuallocated,omitempty"` - Cpunumber int `json:"cpunumber,omitempty"` - Cpusockets int `json:"cpusockets,omitempty"` - Cpuspeed int64 `json:"cpuspeed,omitempty"` - Cpuused string `json:"cpuused,omitempty"` - Cpuwithoverprovisioning string `json:"cpuwithoverprovisioning,omitempty"` - Created string `json:"created,omitempty"` - Details map[string]string `json:"details,omitempty"` - Disconnected string `json:"disconnected,omitempty"` - Disksizeallocated int64 `json:"disksizeallocated,omitempty"` - Disksizetotal int64 `json:"disksizetotal,omitempty"` - Events string `json:"events,omitempty"` - Gpugroup []struct { - Gpugroupname string `json:"gpugroupname,omitempty"` - Vgpu []struct { - Maxcapacity int64 `json:"maxcapacity,omitempty"` - Maxheads int64 `json:"maxheads,omitempty"` - Maxresolutionx int64 `json:"maxresolutionx,omitempty"` - Maxresolutiony int64 `json:"maxresolutiony,omitempty"` - Maxvgpuperpgpu int64 `json:"maxvgpuperpgpu,omitempty"` - Remainingcapacity int64 `json:"remainingcapacity,omitempty"` - Vgputype string `json:"vgputype,omitempty"` - Videoram int64 `json:"videoram,omitempty"` - } `json:"vgpu,omitempty"` - } `json:"gpugroup,omitempty"` - Hahost bool `json:"hahost,omitempty"` - Hasenoughcapacity bool `json:"hasenoughcapacity,omitempty"` - Hosttags string `json:"hosttags,omitempty"` - Hypervisor string `json:"hypervisor,omitempty"` - Hypervisorversion string `json:"hypervisorversion,omitempty"` - Id string `json:"id,omitempty"` - Ipaddress string `json:"ipaddress,omitempty"` - Islocalstorageactive bool `json:"islocalstorageactive,omitempty"` - Lastpinged string `json:"lastpinged,omitempty"` - Managementserverid int64 `json:"managementserverid,omitempty"` - Memoryallocated int64 `json:"memoryallocated,omitempty"` - Memorytotal int64 `json:"memorytotal,omitempty"` - Memoryused int64 `json:"memoryused,omitempty"` - Name string `json:"name,omitempty"` - Networkkbsread int64 `json:"networkkbsread,omitempty"` - Networkkbswrite int64 `json:"networkkbswrite,omitempty"` - Oscategoryid string `json:"oscategoryid,omitempty"` - Oscategoryname string `json:"oscategoryname,omitempty"` - Podid string `json:"podid,omitempty"` - Podname string `json:"podname,omitempty"` - Removed string `json:"removed,omitempty"` - Resourcestate string `json:"resourcestate,omitempty"` - State string `json:"state,omitempty"` - Suitableformigration bool `json:"suitableformigration,omitempty"` - Type string `json:"type,omitempty"` - Version string `json:"version,omitempty"` - Zoneid string `json:"zoneid,omitempty"` - Zonename string `json:"zonename,omitempty"` -} - -type ListHostTagsParams struct { - p map[string]interface{} -} - -func (p *ListHostTagsParams) toURLValues() url.Values { - u := url.Values{} - if p.p == nil { - return u - } - if v, found := p.p["keyword"]; found { - u.Set("keyword", v.(string)) - } - if v, found := p.p["page"]; found { - vv := strconv.Itoa(v.(int)) - u.Set("page", vv) - } - if v, found := p.p["pagesize"]; found { - vv := strconv.Itoa(v.(int)) - u.Set("pagesize", vv) - } - return u -} - -func (p *ListHostTagsParams) SetKeyword(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["keyword"] = v - return -} - -func (p *ListHostTagsParams) SetPage(v int) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["page"] = v - return -} - -func (p *ListHostTagsParams) SetPagesize(v int) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["pagesize"] = v - return -} - -// You should always use this function to get a new ListHostTagsParams instance, -// as then you are sure you have configured all required params -func (s *HostService) NewListHostTagsParams() *ListHostTagsParams { - p := &ListHostTagsParams{} - p.p = make(map[string]interface{}) - return p -} - -// This is a courtesy helper function, which in some cases may not work as expected! -func (s *HostService) GetHostTagID(keyword string, opts ...OptionFunc) (string, int, error) { - p := &ListHostTagsParams{} - p.p = make(map[string]interface{}) - - p.p["keyword"] = keyword - - for _, fn := range opts { - if err := fn(s.cs, p); err != nil { - return "", -1, err - } - } - - l, err := s.ListHostTags(p) - if err != nil { - return "", -1, err - } - - if l.Count == 0 { - return "", l.Count, fmt.Errorf("No match found for %s: %+v", keyword, l) - } - - if l.Count == 1 { - return l.HostTags[0].Id, l.Count, nil - } - - if l.Count > 1 { - for _, v := range l.HostTags { - if v.Name == keyword { - return v.Id, l.Count, nil - } - } - } - return "", l.Count, fmt.Errorf("Could not find an exact match for %s: %+v", keyword, l) -} - -// Lists host tags -func (s *HostService) ListHostTags(p *ListHostTagsParams) (*ListHostTagsResponse, error) { - resp, err := s.cs.newRequest("listHostTags", p.toURLValues()) - if err != nil { - return nil, err - } - - var r ListHostTagsResponse - if err := json.Unmarshal(resp, &r); err != nil { - return nil, err - } - return &r, nil -} - -type ListHostTagsResponse struct { - Count int `json:"count"` - HostTags []*HostTag `json:"hosttag"` -} - -type HostTag struct { - Hostid int64 `json:"hostid,omitempty"` - Id string `json:"id,omitempty"` - Name string `json:"name,omitempty"` -} - -type FindHostsForMigrationParams struct { - p map[string]interface{} -} - -func (p *FindHostsForMigrationParams) toURLValues() url.Values { - u := url.Values{} - if p.p == nil { - return u - } - if v, found := p.p["keyword"]; found { - u.Set("keyword", v.(string)) - } - if v, found := p.p["page"]; found { - vv := strconv.Itoa(v.(int)) - u.Set("page", vv) - } - if v, found := p.p["pagesize"]; found { - vv := strconv.Itoa(v.(int)) - u.Set("pagesize", vv) - } - if v, found := p.p["virtualmachineid"]; found { - u.Set("virtualmachineid", v.(string)) - } - return u -} - -func (p *FindHostsForMigrationParams) SetKeyword(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["keyword"] = v - return -} - -func (p *FindHostsForMigrationParams) SetPage(v int) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["page"] = v - return -} - -func (p *FindHostsForMigrationParams) SetPagesize(v int) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["pagesize"] = v - return -} - -func (p *FindHostsForMigrationParams) SetVirtualmachineid(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["virtualmachineid"] = v - return -} - -// You should always use this function to get a new FindHostsForMigrationParams instance, -// as then you are sure you have configured all required params -func (s *HostService) NewFindHostsForMigrationParams(virtualmachineid string) *FindHostsForMigrationParams { - p := &FindHostsForMigrationParams{} - p.p = make(map[string]interface{}) - p.p["virtualmachineid"] = virtualmachineid - return p -} - -// Find hosts suitable for migrating a virtual machine. -func (s *HostService) FindHostsForMigration(p *FindHostsForMigrationParams) (*FindHostsForMigrationResponse, error) { - resp, err := s.cs.newRequest("findHostsForMigration", p.toURLValues()) - if err != nil { - return nil, err - } - - var r FindHostsForMigrationResponse - if err := json.Unmarshal(resp, &r); err != nil { - return nil, err - } - return &r, nil -} - -type FindHostsForMigrationResponse struct { - Averageload int64 `json:"averageload,omitempty"` - Capabilities string `json:"capabilities,omitempty"` - Clusterid string `json:"clusterid,omitempty"` - Clustername string `json:"clustername,omitempty"` - Clustertype string `json:"clustertype,omitempty"` - Cpuallocated string `json:"cpuallocated,omitempty"` - Cpunumber int `json:"cpunumber,omitempty"` - Cpuspeed int64 `json:"cpuspeed,omitempty"` - Cpuused string `json:"cpuused,omitempty"` - Cpuwithoverprovisioning string `json:"cpuwithoverprovisioning,omitempty"` - Created string `json:"created,omitempty"` - Disconnected string `json:"disconnected,omitempty"` - Disksizeallocated int64 `json:"disksizeallocated,omitempty"` - Disksizetotal int64 `json:"disksizetotal,omitempty"` - Events string `json:"events,omitempty"` - Hahost bool `json:"hahost,omitempty"` - Hasenoughcapacity bool `json:"hasenoughcapacity,omitempty"` - Hosttags string `json:"hosttags,omitempty"` - Hypervisor string `json:"hypervisor,omitempty"` - Hypervisorversion string `json:"hypervisorversion,omitempty"` - Id string `json:"id,omitempty"` - Ipaddress string `json:"ipaddress,omitempty"` - Islocalstorageactive bool `json:"islocalstorageactive,omitempty"` - Lastpinged string `json:"lastpinged,omitempty"` - Managementserverid int64 `json:"managementserverid,omitempty"` - Memoryallocated int64 `json:"memoryallocated,omitempty"` - Memorytotal int64 `json:"memorytotal,omitempty"` - Memoryused int64 `json:"memoryused,omitempty"` - Name string `json:"name,omitempty"` - Networkkbsread int64 `json:"networkkbsread,omitempty"` - Networkkbswrite int64 `json:"networkkbswrite,omitempty"` - Oscategoryid string `json:"oscategoryid,omitempty"` - Oscategoryname string `json:"oscategoryname,omitempty"` - Podid string `json:"podid,omitempty"` - Podname string `json:"podname,omitempty"` - Removed string `json:"removed,omitempty"` - RequiresStorageMotion bool `json:"requiresStorageMotion,omitempty"` - Resourcestate string `json:"resourcestate,omitempty"` - State string `json:"state,omitempty"` - Suitableformigration bool `json:"suitableformigration,omitempty"` - Type string `json:"type,omitempty"` - Version string `json:"version,omitempty"` - Zoneid string `json:"zoneid,omitempty"` - Zonename string `json:"zonename,omitempty"` -} - -type AddSecondaryStorageParams struct { - p map[string]interface{} -} - -func (p *AddSecondaryStorageParams) toURLValues() url.Values { - u := url.Values{} - if p.p == nil { - return u - } - if v, found := p.p["url"]; found { - u.Set("url", v.(string)) - } - if v, found := p.p["zoneid"]; found { - u.Set("zoneid", v.(string)) - } - return u -} - -func (p *AddSecondaryStorageParams) SetUrl(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["url"] = v - return -} - -func (p *AddSecondaryStorageParams) SetZoneid(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["zoneid"] = v - return -} - -// You should always use this function to get a new AddSecondaryStorageParams instance, -// as then you are sure you have configured all required params -func (s *HostService) NewAddSecondaryStorageParams(url string) *AddSecondaryStorageParams { - p := &AddSecondaryStorageParams{} - p.p = make(map[string]interface{}) - p.p["url"] = url - return p -} - -// Adds secondary storage. -func (s *HostService) AddSecondaryStorage(p *AddSecondaryStorageParams) (*AddSecondaryStorageResponse, error) { - resp, err := s.cs.newRequest("addSecondaryStorage", p.toURLValues()) - if err != nil { - return nil, err - } - - var r AddSecondaryStorageResponse - if err := json.Unmarshal(resp, &r); err != nil { - return nil, err - } - return &r, nil -} - -type AddSecondaryStorageResponse struct { - Details []string `json:"details,omitempty"` - Id string `json:"id,omitempty"` - Name string `json:"name,omitempty"` - Protocol string `json:"protocol,omitempty"` - Providername string `json:"providername,omitempty"` - Scope string `json:"scope,omitempty"` - Url string `json:"url,omitempty"` - Zoneid string `json:"zoneid,omitempty"` - Zonename string `json:"zonename,omitempty"` -} - -type UpdateHostPasswordParams struct { - p map[string]interface{} -} - -func (p *UpdateHostPasswordParams) toURLValues() url.Values { - u := url.Values{} - if p.p == nil { - return u - } - if v, found := p.p["clusterid"]; found { - u.Set("clusterid", v.(string)) - } - if v, found := p.p["hostid"]; found { - u.Set("hostid", v.(string)) - } - if v, found := p.p["password"]; found { - u.Set("password", v.(string)) - } - if v, found := p.p["update_passwd_on_host"]; found { - vv := strconv.FormatBool(v.(bool)) - u.Set("update_passwd_on_host", vv) - } - if v, found := p.p["username"]; found { - u.Set("username", v.(string)) - } - return u -} - -func (p *UpdateHostPasswordParams) SetClusterid(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["clusterid"] = v - return -} - -func (p *UpdateHostPasswordParams) SetHostid(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["hostid"] = v - return -} - -func (p *UpdateHostPasswordParams) SetPassword(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["password"] = v - return -} - -func (p *UpdateHostPasswordParams) SetUpdate_passwd_on_host(v bool) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["update_passwd_on_host"] = v - return -} - -func (p *UpdateHostPasswordParams) SetUsername(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["username"] = v - return -} - -// You should always use this function to get a new UpdateHostPasswordParams instance, -// as then you are sure you have configured all required params -func (s *HostService) NewUpdateHostPasswordParams(password string, username string) *UpdateHostPasswordParams { - p := &UpdateHostPasswordParams{} - p.p = make(map[string]interface{}) - p.p["password"] = password - p.p["username"] = username - return p -} - -// Update password of a host/pool on management server. -func (s *HostService) UpdateHostPassword(p *UpdateHostPasswordParams) (*UpdateHostPasswordResponse, error) { - resp, err := s.cs.newRequest("updateHostPassword", p.toURLValues()) - if err != nil { - return nil, err - } - - var r UpdateHostPasswordResponse - if err := json.Unmarshal(resp, &r); err != nil { - return nil, err - } - return &r, nil -} - -type UpdateHostPasswordResponse struct { - Displaytext string `json:"displaytext,omitempty"` - Success string `json:"success,omitempty"` -} - -type ReleaseHostReservationParams struct { - p map[string]interface{} -} - -func (p *ReleaseHostReservationParams) toURLValues() url.Values { - u := url.Values{} - if p.p == nil { - return u - } - if v, found := p.p["id"]; found { - u.Set("id", v.(string)) - } - return u -} - -func (p *ReleaseHostReservationParams) SetId(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["id"] = v - return -} - -// You should always use this function to get a new ReleaseHostReservationParams instance, -// as then you are sure you have configured all required params -func (s *HostService) NewReleaseHostReservationParams(id string) *ReleaseHostReservationParams { - p := &ReleaseHostReservationParams{} - p.p = make(map[string]interface{}) - p.p["id"] = id - return p -} - -// Releases host reservation. -func (s *HostService) ReleaseHostReservation(p *ReleaseHostReservationParams) (*ReleaseHostReservationResponse, error) { - resp, err := s.cs.newRequest("releaseHostReservation", p.toURLValues()) - if err != nil { - return nil, err - } - - var r ReleaseHostReservationResponse - if err := json.Unmarshal(resp, &r); err != nil { - return nil, err - } - - // If we have a async client, we need to wait for the async result - if s.cs.async { - b, err := s.cs.GetAsyncJobResult(r.JobID, s.cs.timeout) - if err != nil { - if err == AsyncTimeoutErr { - return &r, err - } - return nil, err - } - - if err := json.Unmarshal(b, &r); err != nil { - return nil, err - } - } - return &r, nil -} - -type ReleaseHostReservationResponse struct { - JobID string `json:"jobid,omitempty"` - Displaytext string `json:"displaytext,omitempty"` - Success bool `json:"success,omitempty"` -} - type AddBaremetalHostParams struct { p map[string]interface{} } @@ -1835,68 +183,614 @@ func (s *HostService) AddBaremetalHost(p *AddBaremetalHostParams) (*AddBaremetal if err := json.Unmarshal(resp, &r); err != nil { return nil, err } + return &r, nil } type AddBaremetalHostResponse struct { - Averageload int64 `json:"averageload,omitempty"` - Capabilities string `json:"capabilities,omitempty"` - Clusterid string `json:"clusterid,omitempty"` - Clustername string `json:"clustername,omitempty"` - Clustertype string `json:"clustertype,omitempty"` - Cpuallocated string `json:"cpuallocated,omitempty"` - Cpunumber int `json:"cpunumber,omitempty"` - Cpusockets int `json:"cpusockets,omitempty"` - Cpuspeed int64 `json:"cpuspeed,omitempty"` - Cpuused string `json:"cpuused,omitempty"` - Cpuwithoverprovisioning string `json:"cpuwithoverprovisioning,omitempty"` - Created string `json:"created,omitempty"` - Details map[string]string `json:"details,omitempty"` - Disconnected string `json:"disconnected,omitempty"` - Disksizeallocated int64 `json:"disksizeallocated,omitempty"` - Disksizetotal int64 `json:"disksizetotal,omitempty"` - Events string `json:"events,omitempty"` - Gpugroup []struct { - Gpugroupname string `json:"gpugroupname,omitempty"` - Vgpu []struct { - Maxcapacity int64 `json:"maxcapacity,omitempty"` - Maxheads int64 `json:"maxheads,omitempty"` - Maxresolutionx int64 `json:"maxresolutionx,omitempty"` - Maxresolutiony int64 `json:"maxresolutiony,omitempty"` - Maxvgpuperpgpu int64 `json:"maxvgpuperpgpu,omitempty"` - Remainingcapacity int64 `json:"remainingcapacity,omitempty"` - Vgputype string `json:"vgputype,omitempty"` - Videoram int64 `json:"videoram,omitempty"` - } `json:"vgpu,omitempty"` - } `json:"gpugroup,omitempty"` - Hahost bool `json:"hahost,omitempty"` - Hasenoughcapacity bool `json:"hasenoughcapacity,omitempty"` - Hosttags string `json:"hosttags,omitempty"` - Hypervisor string `json:"hypervisor,omitempty"` - Hypervisorversion string `json:"hypervisorversion,omitempty"` - Id string `json:"id,omitempty"` - Ipaddress string `json:"ipaddress,omitempty"` - Islocalstorageactive bool `json:"islocalstorageactive,omitempty"` - Lastpinged string `json:"lastpinged,omitempty"` - Managementserverid int64 `json:"managementserverid,omitempty"` - Memoryallocated int64 `json:"memoryallocated,omitempty"` - Memorytotal int64 `json:"memorytotal,omitempty"` - Memoryused int64 `json:"memoryused,omitempty"` - Name string `json:"name,omitempty"` - Networkkbsread int64 `json:"networkkbsread,omitempty"` - Networkkbswrite int64 `json:"networkkbswrite,omitempty"` - Oscategoryid string `json:"oscategoryid,omitempty"` - Oscategoryname string `json:"oscategoryname,omitempty"` - Podid string `json:"podid,omitempty"` - Podname string `json:"podname,omitempty"` - Removed string `json:"removed,omitempty"` - Resourcestate string `json:"resourcestate,omitempty"` - State string `json:"state,omitempty"` - Suitableformigration bool `json:"suitableformigration,omitempty"` - Type string `json:"type,omitempty"` - Version string `json:"version,omitempty"` - Zoneid string `json:"zoneid,omitempty"` - Zonename string `json:"zonename,omitempty"` + Annotation string `json:"annotation"` + Averageload int64 `json:"averageload"` + Capabilities string `json:"capabilities"` + Clusterid string `json:"clusterid"` + Clustername string `json:"clustername"` + Clustertype string `json:"clustertype"` + Cpuallocated string `json:"cpuallocated"` + Cpunumber int `json:"cpunumber"` + Cpusockets int `json:"cpusockets"` + Cpuspeed int64 `json:"cpuspeed"` + Cpuused string `json:"cpuused"` + Cpuwithoverprovisioning string `json:"cpuwithoverprovisioning"` + Created string `json:"created"` + Details map[string]string `json:"details"` + Disconnected string `json:"disconnected"` + Disksizeallocated int64 `json:"disksizeallocated"` + Disksizetotal int64 `json:"disksizetotal"` + Events string `json:"events"` + Gpugroup []AddBaremetalHostResponseGpugroup `json:"gpugroup"` + Hahost bool `json:"hahost"` + Hasenoughcapacity bool `json:"hasenoughcapacity"` + Hostha string `json:"hostha"` + Hosttags string `json:"hosttags"` + Hypervisor string `json:"hypervisor"` + Hypervisorversion string `json:"hypervisorversion"` + Id string `json:"id"` + Ipaddress string `json:"ipaddress"` + Islocalstorageactive bool `json:"islocalstorageactive"` + Lastannotated string `json:"lastannotated"` + Lastpinged string `json:"lastpinged"` + Managementserverid int64 `json:"managementserverid"` + Memoryallocated int64 `json:"memoryallocated"` + Memorytotal int64 `json:"memorytotal"` + Memoryused int64 `json:"memoryused"` + Memorywithoverprovisioning string `json:"memorywithoverprovisioning"` + Name string `json:"name"` + Networkkbsread int64 `json:"networkkbsread"` + Networkkbswrite int64 `json:"networkkbswrite"` + Oscategoryid string `json:"oscategoryid"` + Oscategoryname string `json:"oscategoryname"` + Outofbandmanagement OutOfBandManagementResponse `json:"outofbandmanagement"` + Podid string `json:"podid"` + Podname string `json:"podname"` + Removed string `json:"removed"` + Resourcestate string `json:"resourcestate"` + State string `json:"state"` + Suitableformigration bool `json:"suitableformigration"` + Type string `json:"type"` + Username string `json:"username"` + Version string `json:"version"` + Zoneid string `json:"zoneid"` + Zonename string `json:"zonename"` +} + +type AddBaremetalHostResponseGpugroup struct { + Gpugroupname string `json:"gpugroupname"` + Vgpu []AddBaremetalHostResponseGpugroupVgpu `json:"vgpu"` +} + +type AddBaremetalHostResponseGpugroupVgpu struct { + Maxcapacity int64 `json:"maxcapacity"` + Maxheads int64 `json:"maxheads"` + Maxresolutionx int64 `json:"maxresolutionx"` + Maxresolutiony int64 `json:"maxresolutiony"` + Maxvgpuperpgpu int64 `json:"maxvgpuperpgpu"` + Remainingcapacity int64 `json:"remainingcapacity"` + Vgputype string `json:"vgputype"` + Videoram int64 `json:"videoram"` +} + +type AddGloboDnsHostParams struct { + p map[string]interface{} +} + +func (p *AddGloboDnsHostParams) toURLValues() url.Values { + u := url.Values{} + if p.p == nil { + return u + } + if v, found := p.p["password"]; found { + u.Set("password", v.(string)) + } + if v, found := p.p["physicalnetworkid"]; found { + u.Set("physicalnetworkid", v.(string)) + } + if v, found := p.p["url"]; found { + u.Set("url", v.(string)) + } + if v, found := p.p["username"]; found { + u.Set("username", v.(string)) + } + return u +} + +func (p *AddGloboDnsHostParams) SetPassword(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["password"] = v + return +} + +func (p *AddGloboDnsHostParams) SetPhysicalnetworkid(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["physicalnetworkid"] = v + return +} + +func (p *AddGloboDnsHostParams) SetUrl(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["url"] = v + return +} + +func (p *AddGloboDnsHostParams) SetUsername(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["username"] = v + return +} + +// You should always use this function to get a new AddGloboDnsHostParams instance, +// as then you are sure you have configured all required params +func (s *HostService) NewAddGloboDnsHostParams(password string, physicalnetworkid string, url string, username string) *AddGloboDnsHostParams { + p := &AddGloboDnsHostParams{} + p.p = make(map[string]interface{}) + p.p["password"] = password + p.p["physicalnetworkid"] = physicalnetworkid + p.p["url"] = url + p.p["username"] = username + return p +} + +// Adds the GloboDNS external host +func (s *HostService) AddGloboDnsHost(p *AddGloboDnsHostParams) (*AddGloboDnsHostResponse, error) { + resp, err := s.cs.newRequest("addGloboDnsHost", p.toURLValues()) + if err != nil { + return nil, err + } + + var r AddGloboDnsHostResponse + if err := json.Unmarshal(resp, &r); err != nil { + return nil, err + } + + // If we have a async client, we need to wait for the async result + if s.cs.async { + b, err := s.cs.GetAsyncJobResult(r.JobID, s.cs.timeout) + if err != nil { + if err == AsyncTimeoutErr { + return &r, err + } + return nil, err + } + + if err := json.Unmarshal(b, &r); err != nil { + return nil, err + } + } + + return &r, nil +} + +type AddGloboDnsHostResponse struct { + JobID string `json:"jobid"` + Displaytext string `json:"displaytext"` + Success bool `json:"success"` +} + +type AddHostParams struct { + p map[string]interface{} +} + +func (p *AddHostParams) toURLValues() url.Values { + u := url.Values{} + if p.p == nil { + return u + } + if v, found := p.p["allocationstate"]; found { + u.Set("allocationstate", v.(string)) + } + if v, found := p.p["clusterid"]; found { + u.Set("clusterid", v.(string)) + } + if v, found := p.p["clustername"]; found { + u.Set("clustername", v.(string)) + } + if v, found := p.p["hosttags"]; found { + vv := strings.Join(v.([]string), ",") + u.Set("hosttags", vv) + } + if v, found := p.p["hypervisor"]; found { + u.Set("hypervisor", v.(string)) + } + if v, found := p.p["password"]; found { + u.Set("password", v.(string)) + } + if v, found := p.p["podid"]; found { + u.Set("podid", v.(string)) + } + if v, found := p.p["url"]; found { + u.Set("url", v.(string)) + } + if v, found := p.p["username"]; found { + u.Set("username", v.(string)) + } + if v, found := p.p["zoneid"]; found { + u.Set("zoneid", v.(string)) + } + return u +} + +func (p *AddHostParams) SetAllocationstate(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["allocationstate"] = v + return +} + +func (p *AddHostParams) SetClusterid(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["clusterid"] = v + return +} + +func (p *AddHostParams) SetClustername(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["clustername"] = v + return +} + +func (p *AddHostParams) SetHosttags(v []string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["hosttags"] = v + return +} + +func (p *AddHostParams) SetHypervisor(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["hypervisor"] = v + return +} + +func (p *AddHostParams) SetPassword(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["password"] = v + return +} + +func (p *AddHostParams) SetPodid(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["podid"] = v + return +} + +func (p *AddHostParams) SetUrl(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["url"] = v + return +} + +func (p *AddHostParams) SetUsername(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["username"] = v + return +} + +func (p *AddHostParams) SetZoneid(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["zoneid"] = v + return +} + +// You should always use this function to get a new AddHostParams instance, +// as then you are sure you have configured all required params +func (s *HostService) NewAddHostParams(hypervisor string, password string, podid string, url string, username string, zoneid string) *AddHostParams { + p := &AddHostParams{} + p.p = make(map[string]interface{}) + p.p["hypervisor"] = hypervisor + p.p["password"] = password + p.p["podid"] = podid + p.p["url"] = url + p.p["username"] = username + p.p["zoneid"] = zoneid + return p +} + +// Adds a new host. +func (s *HostService) AddHost(p *AddHostParams) (*AddHostResponse, error) { + resp, err := s.cs.newRequest("addHost", p.toURLValues()) + if err != nil { + return nil, err + } + + var r AddHostResponse + if err := json.Unmarshal(resp, &r); err != nil { + return nil, err + } + + return &r, nil +} + +type AddHostResponse struct { + Annotation string `json:"annotation"` + Averageload int64 `json:"averageload"` + Capabilities string `json:"capabilities"` + Clusterid string `json:"clusterid"` + Clustername string `json:"clustername"` + Clustertype string `json:"clustertype"` + Cpuallocated string `json:"cpuallocated"` + Cpunumber int `json:"cpunumber"` + Cpusockets int `json:"cpusockets"` + Cpuspeed int64 `json:"cpuspeed"` + Cpuused string `json:"cpuused"` + Cpuwithoverprovisioning string `json:"cpuwithoverprovisioning"` + Created string `json:"created"` + Details map[string]string `json:"details"` + Disconnected string `json:"disconnected"` + Disksizeallocated int64 `json:"disksizeallocated"` + Disksizetotal int64 `json:"disksizetotal"` + Events string `json:"events"` + Gpugroup []AddHostResponseGpugroup `json:"gpugroup"` + Hahost bool `json:"hahost"` + Hasenoughcapacity bool `json:"hasenoughcapacity"` + Hostha string `json:"hostha"` + Hosttags string `json:"hosttags"` + Hypervisor string `json:"hypervisor"` + Hypervisorversion string `json:"hypervisorversion"` + Id string `json:"id"` + Ipaddress string `json:"ipaddress"` + Islocalstorageactive bool `json:"islocalstorageactive"` + Lastannotated string `json:"lastannotated"` + Lastpinged string `json:"lastpinged"` + Managementserverid int64 `json:"managementserverid"` + Memoryallocated int64 `json:"memoryallocated"` + Memorytotal int64 `json:"memorytotal"` + Memoryused int64 `json:"memoryused"` + Memorywithoverprovisioning string `json:"memorywithoverprovisioning"` + Name string `json:"name"` + Networkkbsread int64 `json:"networkkbsread"` + Networkkbswrite int64 `json:"networkkbswrite"` + Oscategoryid string `json:"oscategoryid"` + Oscategoryname string `json:"oscategoryname"` + Outofbandmanagement OutOfBandManagementResponse `json:"outofbandmanagement"` + Podid string `json:"podid"` + Podname string `json:"podname"` + Removed string `json:"removed"` + Resourcestate string `json:"resourcestate"` + State string `json:"state"` + Suitableformigration bool `json:"suitableformigration"` + Type string `json:"type"` + Username string `json:"username"` + Version string `json:"version"` + Zoneid string `json:"zoneid"` + Zonename string `json:"zonename"` +} + +type AddHostResponseGpugroup struct { + Gpugroupname string `json:"gpugroupname"` + Vgpu []AddHostResponseGpugroupVgpu `json:"vgpu"` +} + +type AddHostResponseGpugroupVgpu struct { + Maxcapacity int64 `json:"maxcapacity"` + Maxheads int64 `json:"maxheads"` + Maxresolutionx int64 `json:"maxresolutionx"` + Maxresolutiony int64 `json:"maxresolutiony"` + Maxvgpuperpgpu int64 `json:"maxvgpuperpgpu"` + Remainingcapacity int64 `json:"remainingcapacity"` + Vgputype string `json:"vgputype"` + Videoram int64 `json:"videoram"` +} + +type AddSecondaryStorageParams struct { + p map[string]interface{} +} + +func (p *AddSecondaryStorageParams) toURLValues() url.Values { + u := url.Values{} + if p.p == nil { + return u + } + if v, found := p.p["url"]; found { + u.Set("url", v.(string)) + } + if v, found := p.p["zoneid"]; found { + u.Set("zoneid", v.(string)) + } + return u +} + +func (p *AddSecondaryStorageParams) SetUrl(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["url"] = v + return +} + +func (p *AddSecondaryStorageParams) SetZoneid(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["zoneid"] = v + return +} + +// You should always use this function to get a new AddSecondaryStorageParams instance, +// as then you are sure you have configured all required params +func (s *HostService) NewAddSecondaryStorageParams(url string) *AddSecondaryStorageParams { + p := &AddSecondaryStorageParams{} + p.p = make(map[string]interface{}) + p.p["url"] = url + return p +} + +// Adds secondary storage. +func (s *HostService) AddSecondaryStorage(p *AddSecondaryStorageParams) (*AddSecondaryStorageResponse, error) { + resp, err := s.cs.newRequest("addSecondaryStorage", p.toURLValues()) + if err != nil { + return nil, err + } + + var r AddSecondaryStorageResponse + if err := json.Unmarshal(resp, &r); err != nil { + return nil, err + } + + return &r, nil +} + +type AddSecondaryStorageResponse struct { + Id string `json:"id"` + Name string `json:"name"` + Protocol string `json:"protocol"` + Providername string `json:"providername"` + Scope string `json:"scope"` + Url string `json:"url"` + Zoneid string `json:"zoneid"` + Zonename string `json:"zonename"` +} + +type CancelHostMaintenanceParams struct { + p map[string]interface{} +} + +func (p *CancelHostMaintenanceParams) toURLValues() url.Values { + u := url.Values{} + if p.p == nil { + return u + } + if v, found := p.p["id"]; found { + u.Set("id", v.(string)) + } + return u +} + +func (p *CancelHostMaintenanceParams) SetId(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["id"] = v + return +} + +// You should always use this function to get a new CancelHostMaintenanceParams instance, +// as then you are sure you have configured all required params +func (s *HostService) NewCancelHostMaintenanceParams(id string) *CancelHostMaintenanceParams { + p := &CancelHostMaintenanceParams{} + p.p = make(map[string]interface{}) + p.p["id"] = id + return p +} + +// Cancels host maintenance. +func (s *HostService) CancelHostMaintenance(p *CancelHostMaintenanceParams) (*CancelHostMaintenanceResponse, error) { + resp, err := s.cs.newRequest("cancelHostMaintenance", p.toURLValues()) + if err != nil { + return nil, err + } + + var r CancelHostMaintenanceResponse + if err := json.Unmarshal(resp, &r); err != nil { + return nil, err + } + + // If we have a async client, we need to wait for the async result + if s.cs.async { + b, err := s.cs.GetAsyncJobResult(r.JobID, s.cs.timeout) + if err != nil { + if err == AsyncTimeoutErr { + return &r, err + } + return nil, err + } + + b, err = getRawValue(b) + if err != nil { + return nil, err + } + + if err := json.Unmarshal(b, &r); err != nil { + return nil, err + } + } + + return &r, nil +} + +type CancelHostMaintenanceResponse struct { + JobID string `json:"jobid"` + Annotation string `json:"annotation"` + Averageload int64 `json:"averageload"` + Capabilities string `json:"capabilities"` + Clusterid string `json:"clusterid"` + Clustername string `json:"clustername"` + Clustertype string `json:"clustertype"` + Cpuallocated string `json:"cpuallocated"` + Cpunumber int `json:"cpunumber"` + Cpusockets int `json:"cpusockets"` + Cpuspeed int64 `json:"cpuspeed"` + Cpuused string `json:"cpuused"` + Cpuwithoverprovisioning string `json:"cpuwithoverprovisioning"` + Created string `json:"created"` + Details map[string]string `json:"details"` + Disconnected string `json:"disconnected"` + Disksizeallocated int64 `json:"disksizeallocated"` + Disksizetotal int64 `json:"disksizetotal"` + Events string `json:"events"` + Gpugroup []CancelHostMaintenanceResponseGpugroup `json:"gpugroup"` + Hahost bool `json:"hahost"` + Hasenoughcapacity bool `json:"hasenoughcapacity"` + Hostha string `json:"hostha"` + Hosttags string `json:"hosttags"` + Hypervisor string `json:"hypervisor"` + Hypervisorversion string `json:"hypervisorversion"` + Id string `json:"id"` + Ipaddress string `json:"ipaddress"` + Islocalstorageactive bool `json:"islocalstorageactive"` + Lastannotated string `json:"lastannotated"` + Lastpinged string `json:"lastpinged"` + Managementserverid int64 `json:"managementserverid"` + Memoryallocated int64 `json:"memoryallocated"` + Memorytotal int64 `json:"memorytotal"` + Memoryused int64 `json:"memoryused"` + Memorywithoverprovisioning string `json:"memorywithoverprovisioning"` + Name string `json:"name"` + Networkkbsread int64 `json:"networkkbsread"` + Networkkbswrite int64 `json:"networkkbswrite"` + Oscategoryid string `json:"oscategoryid"` + Oscategoryname string `json:"oscategoryname"` + Outofbandmanagement OutOfBandManagementResponse `json:"outofbandmanagement"` + Podid string `json:"podid"` + Podname string `json:"podname"` + Removed string `json:"removed"` + Resourcestate string `json:"resourcestate"` + State string `json:"state"` + Suitableformigration bool `json:"suitableformigration"` + Type string `json:"type"` + Username string `json:"username"` + Version string `json:"version"` + Zoneid string `json:"zoneid"` + Zonename string `json:"zonename"` +} + +type CancelHostMaintenanceResponseGpugroup struct { + Gpugroupname string `json:"gpugroupname"` + Vgpu []CancelHostMaintenanceResponseGpugroupVgpu `json:"vgpu"` +} + +type CancelHostMaintenanceResponseGpugroupVgpu struct { + Maxcapacity int64 `json:"maxcapacity"` + Maxheads int64 `json:"maxheads"` + Maxresolutionx int64 `json:"maxresolutionx"` + Maxresolutiony int64 `json:"maxresolutiony"` + Maxvgpuperpgpu int64 `json:"maxvgpuperpgpu"` + Remainingcapacity int64 `json:"remainingcapacity"` + Vgputype string `json:"vgputype"` + Videoram int64 `json:"videoram"` } type DedicateHostParams struct { @@ -1985,24 +879,120 @@ func (s *HostService) DedicateHost(p *DedicateHostParams) (*DedicateHostResponse return nil, err } } + return &r, nil } type DedicateHostResponse struct { - JobID string `json:"jobid,omitempty"` - Accountid string `json:"accountid,omitempty"` - Affinitygroupid string `json:"affinitygroupid,omitempty"` - Domainid string `json:"domainid,omitempty"` - Hostid string `json:"hostid,omitempty"` - Hostname string `json:"hostname,omitempty"` - Id string `json:"id,omitempty"` + JobID string `json:"jobid"` + Accountid string `json:"accountid"` + Affinitygroupid string `json:"affinitygroupid"` + Domainid string `json:"domainid"` + Hostid string `json:"hostid"` + Hostname string `json:"hostname"` + Id string `json:"id"` } -type ReleaseDedicatedHostParams struct { +type DeleteHostParams struct { p map[string]interface{} } -func (p *ReleaseDedicatedHostParams) toURLValues() url.Values { +func (p *DeleteHostParams) toURLValues() url.Values { + u := url.Values{} + if p.p == nil { + return u + } + if v, found := p.p["forced"]; found { + vv := strconv.FormatBool(v.(bool)) + u.Set("forced", vv) + } + if v, found := p.p["forcedestroylocalstorage"]; found { + vv := strconv.FormatBool(v.(bool)) + u.Set("forcedestroylocalstorage", vv) + } + if v, found := p.p["id"]; found { + u.Set("id", v.(string)) + } + return u +} + +func (p *DeleteHostParams) SetForced(v bool) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["forced"] = v + return +} + +func (p *DeleteHostParams) SetForcedestroylocalstorage(v bool) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["forcedestroylocalstorage"] = v + return +} + +func (p *DeleteHostParams) SetId(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["id"] = v + return +} + +// You should always use this function to get a new DeleteHostParams instance, +// as then you are sure you have configured all required params +func (s *HostService) NewDeleteHostParams(id string) *DeleteHostParams { + p := &DeleteHostParams{} + p.p = make(map[string]interface{}) + p.p["id"] = id + return p +} + +// Deletes a host. +func (s *HostService) DeleteHost(p *DeleteHostParams) (*DeleteHostResponse, error) { + resp, err := s.cs.newRequest("deleteHost", p.toURLValues()) + if err != nil { + return nil, err + } + + var r DeleteHostResponse + if err := json.Unmarshal(resp, &r); err != nil { + return nil, err + } + + return &r, nil +} + +type DeleteHostResponse struct { + Displaytext string `json:"displaytext"` + Success bool `json:"success"` +} + +func (r *DeleteHostResponse) UnmarshalJSON(b []byte) error { + var m map[string]interface{} + err := json.Unmarshal(b, &m) + if err != nil { + return err + } + + if success, ok := m["success"].(string); ok { + m["success"] = success == "true" + b, err = json.Marshal(m) + if err != nil { + return err + } + } + + type alias DeleteHostResponse + return json.Unmarshal(b, (*alias)(r)) +} + +type DisableOutOfBandManagementForHostParams struct { + p map[string]interface{} +} + +func (p *DisableOutOfBandManagementForHostParams) toURLValues() url.Values { u := url.Values{} if p.p == nil { return u @@ -2013,7 +1003,7 @@ func (p *ReleaseDedicatedHostParams) toURLValues() url.Values { return u } -func (p *ReleaseDedicatedHostParams) SetHostid(v string) { +func (p *DisableOutOfBandManagementForHostParams) SetHostid(v string) { if p.p == nil { p.p = make(map[string]interface{}) } @@ -2021,23 +1011,23 @@ func (p *ReleaseDedicatedHostParams) SetHostid(v string) { return } -// You should always use this function to get a new ReleaseDedicatedHostParams instance, +// You should always use this function to get a new DisableOutOfBandManagementForHostParams instance, // as then you are sure you have configured all required params -func (s *HostService) NewReleaseDedicatedHostParams(hostid string) *ReleaseDedicatedHostParams { - p := &ReleaseDedicatedHostParams{} +func (s *HostService) NewDisableOutOfBandManagementForHostParams(hostid string) *DisableOutOfBandManagementForHostParams { + p := &DisableOutOfBandManagementForHostParams{} p.p = make(map[string]interface{}) p.p["hostid"] = hostid return p } -// Release the dedication for host -func (s *HostService) ReleaseDedicatedHost(p *ReleaseDedicatedHostParams) (*ReleaseDedicatedHostResponse, error) { - resp, err := s.cs.newRequest("releaseDedicatedHost", p.toURLValues()) +// Disables out-of-band management for a host +func (s *HostService) DisableOutOfBandManagementForHost(p *DisableOutOfBandManagementForHostParams) (*DisableOutOfBandManagementForHostResponse, error) { + resp, err := s.cs.newRequest("disableOutOfBandManagementForHost", p.toURLValues()) if err != nil { return nil, err } - var r ReleaseDedicatedHostResponse + var r DisableOutOfBandManagementForHostResponse if err := json.Unmarshal(resp, &r); err != nil { return nil, err } @@ -2052,17 +1042,244 @@ func (s *HostService) ReleaseDedicatedHost(p *ReleaseDedicatedHostParams) (*Rele return nil, err } + b, err = getRawValue(b) + if err != nil { + return nil, err + } + if err := json.Unmarshal(b, &r); err != nil { return nil, err } } + return &r, nil } -type ReleaseDedicatedHostResponse struct { - JobID string `json:"jobid,omitempty"` - Displaytext string `json:"displaytext,omitempty"` - Success bool `json:"success,omitempty"` +type DisableOutOfBandManagementForHostResponse struct { + JobID string `json:"jobid"` + Action string `json:"action"` + Address string `json:"address"` + Description string `json:"description"` + Driver string `json:"driver"` + Enabled bool `json:"enabled"` + Hostid string `json:"hostid"` + Password string `json:"password"` + Port string `json:"port"` + Powerstate string `json:"powerstate"` + Status bool `json:"status"` + Username string `json:"username"` +} + +type EnableOutOfBandManagementForHostParams struct { + p map[string]interface{} +} + +func (p *EnableOutOfBandManagementForHostParams) toURLValues() url.Values { + u := url.Values{} + if p.p == nil { + return u + } + if v, found := p.p["hostid"]; found { + u.Set("hostid", v.(string)) + } + return u +} + +func (p *EnableOutOfBandManagementForHostParams) SetHostid(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["hostid"] = v + return +} + +// You should always use this function to get a new EnableOutOfBandManagementForHostParams instance, +// as then you are sure you have configured all required params +func (s *HostService) NewEnableOutOfBandManagementForHostParams(hostid string) *EnableOutOfBandManagementForHostParams { + p := &EnableOutOfBandManagementForHostParams{} + p.p = make(map[string]interface{}) + p.p["hostid"] = hostid + return p +} + +// Enables out-of-band management for a host +func (s *HostService) EnableOutOfBandManagementForHost(p *EnableOutOfBandManagementForHostParams) (*EnableOutOfBandManagementForHostResponse, error) { + resp, err := s.cs.newRequest("enableOutOfBandManagementForHost", p.toURLValues()) + if err != nil { + return nil, err + } + + var r EnableOutOfBandManagementForHostResponse + if err := json.Unmarshal(resp, &r); err != nil { + return nil, err + } + + // If we have a async client, we need to wait for the async result + if s.cs.async { + b, err := s.cs.GetAsyncJobResult(r.JobID, s.cs.timeout) + if err != nil { + if err == AsyncTimeoutErr { + return &r, err + } + return nil, err + } + + b, err = getRawValue(b) + if err != nil { + return nil, err + } + + if err := json.Unmarshal(b, &r); err != nil { + return nil, err + } + } + + return &r, nil +} + +type EnableOutOfBandManagementForHostResponse struct { + JobID string `json:"jobid"` + Action string `json:"action"` + Address string `json:"address"` + Description string `json:"description"` + Driver string `json:"driver"` + Enabled bool `json:"enabled"` + Hostid string `json:"hostid"` + Password string `json:"password"` + Port string `json:"port"` + Powerstate string `json:"powerstate"` + Status bool `json:"status"` + Username string `json:"username"` +} + +type FindHostsForMigrationParams struct { + p map[string]interface{} +} + +func (p *FindHostsForMigrationParams) toURLValues() url.Values { + u := url.Values{} + if p.p == nil { + return u + } + if v, found := p.p["keyword"]; found { + u.Set("keyword", v.(string)) + } + if v, found := p.p["page"]; found { + vv := strconv.Itoa(v.(int)) + u.Set("page", vv) + } + if v, found := p.p["pagesize"]; found { + vv := strconv.Itoa(v.(int)) + u.Set("pagesize", vv) + } + if v, found := p.p["virtualmachineid"]; found { + u.Set("virtualmachineid", v.(string)) + } + return u +} + +func (p *FindHostsForMigrationParams) SetKeyword(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["keyword"] = v + return +} + +func (p *FindHostsForMigrationParams) SetPage(v int) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["page"] = v + return +} + +func (p *FindHostsForMigrationParams) SetPagesize(v int) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["pagesize"] = v + return +} + +func (p *FindHostsForMigrationParams) SetVirtualmachineid(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["virtualmachineid"] = v + return +} + +// You should always use this function to get a new FindHostsForMigrationParams instance, +// as then you are sure you have configured all required params +func (s *HostService) NewFindHostsForMigrationParams(virtualmachineid string) *FindHostsForMigrationParams { + p := &FindHostsForMigrationParams{} + p.p = make(map[string]interface{}) + p.p["virtualmachineid"] = virtualmachineid + return p +} + +// Find hosts suitable for migrating a virtual machine. +func (s *HostService) FindHostsForMigration(p *FindHostsForMigrationParams) (*FindHostsForMigrationResponse, error) { + resp, err := s.cs.newRequest("findHostsForMigration", p.toURLValues()) + if err != nil { + return nil, err + } + + var r FindHostsForMigrationResponse + if err := json.Unmarshal(resp, &r); err != nil { + return nil, err + } + + return &r, nil +} + +type FindHostsForMigrationResponse struct { + Averageload int64 `json:"averageload"` + Capabilities string `json:"capabilities"` + Clusterid string `json:"clusterid"` + Clustername string `json:"clustername"` + Clustertype string `json:"clustertype"` + Cpuallocated string `json:"cpuallocated"` + Cpunumber int `json:"cpunumber"` + Cpuspeed int64 `json:"cpuspeed"` + Cpuused string `json:"cpuused"` + Cpuwithoverprovisioning string `json:"cpuwithoverprovisioning"` + Created string `json:"created"` + Disconnected string `json:"disconnected"` + Disksizeallocated int64 `json:"disksizeallocated"` + Disksizetotal int64 `json:"disksizetotal"` + Events string `json:"events"` + Hahost bool `json:"hahost"` + Hasenoughcapacity bool `json:"hasenoughcapacity"` + Hosttags string `json:"hosttags"` + Hypervisor string `json:"hypervisor"` + Hypervisorversion string `json:"hypervisorversion"` + Id string `json:"id"` + Ipaddress string `json:"ipaddress"` + Islocalstorageactive bool `json:"islocalstorageactive"` + Lastpinged string `json:"lastpinged"` + Managementserverid int64 `json:"managementserverid"` + Memoryallocated string `json:"memoryallocated"` + Memorytotal int64 `json:"memorytotal"` + Memoryused int64 `json:"memoryused"` + Memorywithoverprovisioning string `json:"memorywithoverprovisioning"` + Name string `json:"name"` + Networkkbsread int64 `json:"networkkbsread"` + Networkkbswrite int64 `json:"networkkbswrite"` + Oscategoryid string `json:"oscategoryid"` + Oscategoryname string `json:"oscategoryname"` + Podid string `json:"podid"` + Podname string `json:"podname"` + Removed string `json:"removed"` + RequiresStorageMotion bool `json:"requiresStorageMotion"` + Resourcestate string `json:"resourcestate"` + State string `json:"state"` + Suitableformigration bool `json:"suitableformigration"` + Type string `json:"type"` + Version string `json:"version"` + Zoneid string `json:"zoneid"` + Zonename string `json:"zonename"` } type ListDedicatedHostsParams struct { @@ -2175,6 +1392,7 @@ func (s *HostService) ListDedicatedHosts(p *ListDedicatedHostsParams) (*ListDedi if err := json.Unmarshal(resp, &r); err != nil { return nil, err } + return &r, nil } @@ -2184,90 +1402,835 @@ type ListDedicatedHostsResponse struct { } type DedicatedHost struct { - Accountid string `json:"accountid,omitempty"` - Affinitygroupid string `json:"affinitygroupid,omitempty"` - Domainid string `json:"domainid,omitempty"` - Hostid string `json:"hostid,omitempty"` - Hostname string `json:"hostname,omitempty"` - Id string `json:"id,omitempty"` + Accountid string `json:"accountid"` + Affinitygroupid string `json:"affinitygroupid"` + Domainid string `json:"domainid"` + Hostid string `json:"hostid"` + Hostname string `json:"hostname"` + Id string `json:"id"` } -type AddGloboDnsHostParams struct { +type ListHostTagsParams struct { p map[string]interface{} } -func (p *AddGloboDnsHostParams) toURLValues() url.Values { +func (p *ListHostTagsParams) toURLValues() url.Values { u := url.Values{} if p.p == nil { return u } - if v, found := p.p["password"]; found { - u.Set("password", v.(string)) + if v, found := p.p["keyword"]; found { + u.Set("keyword", v.(string)) } - if v, found := p.p["physicalnetworkid"]; found { - u.Set("physicalnetworkid", v.(string)) + if v, found := p.p["page"]; found { + vv := strconv.Itoa(v.(int)) + u.Set("page", vv) } - if v, found := p.p["url"]; found { - u.Set("url", v.(string)) - } - if v, found := p.p["username"]; found { - u.Set("username", v.(string)) + if v, found := p.p["pagesize"]; found { + vv := strconv.Itoa(v.(int)) + u.Set("pagesize", vv) } return u } -func (p *AddGloboDnsHostParams) SetPassword(v string) { +func (p *ListHostTagsParams) SetKeyword(v string) { if p.p == nil { p.p = make(map[string]interface{}) } - p.p["password"] = v + p.p["keyword"] = v return } -func (p *AddGloboDnsHostParams) SetPhysicalnetworkid(v string) { +func (p *ListHostTagsParams) SetPage(v int) { if p.p == nil { p.p = make(map[string]interface{}) } - p.p["physicalnetworkid"] = v + p.p["page"] = v return } -func (p *AddGloboDnsHostParams) SetUrl(v string) { +func (p *ListHostTagsParams) SetPagesize(v int) { if p.p == nil { p.p = make(map[string]interface{}) } - p.p["url"] = v + p.p["pagesize"] = v return } -func (p *AddGloboDnsHostParams) SetUsername(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["username"] = v - return -} - -// You should always use this function to get a new AddGloboDnsHostParams instance, +// You should always use this function to get a new ListHostTagsParams instance, // as then you are sure you have configured all required params -func (s *HostService) NewAddGloboDnsHostParams(password string, physicalnetworkid string, url string, username string) *AddGloboDnsHostParams { - p := &AddGloboDnsHostParams{} +func (s *HostService) NewListHostTagsParams() *ListHostTagsParams { + p := &ListHostTagsParams{} p.p = make(map[string]interface{}) - p.p["password"] = password - p.p["physicalnetworkid"] = physicalnetworkid - p.p["url"] = url - p.p["username"] = username return p } -// Adds the GloboDNS external host -func (s *HostService) AddGloboDnsHost(p *AddGloboDnsHostParams) (*AddGloboDnsHostResponse, error) { - resp, err := s.cs.newRequest("addGloboDnsHost", p.toURLValues()) +// This is a courtesy helper function, which in some cases may not work as expected! +func (s *HostService) GetHostTagID(keyword string, opts ...OptionFunc) (string, int, error) { + p := &ListHostTagsParams{} + p.p = make(map[string]interface{}) + + p.p["keyword"] = keyword + + for _, fn := range append(s.cs.options, opts...) { + if err := fn(s.cs, p); err != nil { + return "", -1, err + } + } + + l, err := s.ListHostTags(p) + if err != nil { + return "", -1, err + } + + if l.Count == 0 { + return "", l.Count, fmt.Errorf("No match found for %s: %+v", keyword, l) + } + + if l.Count == 1 { + return l.HostTags[0].Id, l.Count, nil + } + + if l.Count > 1 { + for _, v := range l.HostTags { + if v.Name == keyword { + return v.Id, l.Count, nil + } + } + } + return "", l.Count, fmt.Errorf("Could not find an exact match for %s: %+v", keyword, l) +} + +// Lists host tags +func (s *HostService) ListHostTags(p *ListHostTagsParams) (*ListHostTagsResponse, error) { + resp, err := s.cs.newRequest("listHostTags", p.toURLValues()) if err != nil { return nil, err } - var r AddGloboDnsHostResponse + var r ListHostTagsResponse + if err := json.Unmarshal(resp, &r); err != nil { + return nil, err + } + + return &r, nil +} + +type ListHostTagsResponse struct { + Count int `json:"count"` + HostTags []*HostTag `json:"hosttag"` +} + +type HostTag struct { + Hostid int64 `json:"hostid"` + Id string `json:"id"` + Name string `json:"name"` +} + +type ListHostsParams struct { + p map[string]interface{} +} + +func (p *ListHostsParams) toURLValues() url.Values { + u := url.Values{} + if p.p == nil { + return u + } + if v, found := p.p["clusterid"]; found { + u.Set("clusterid", v.(string)) + } + if v, found := p.p["details"]; found { + vv := strings.Join(v.([]string), ",") + u.Set("details", vv) + } + if v, found := p.p["hahost"]; found { + vv := strconv.FormatBool(v.(bool)) + u.Set("hahost", vv) + } + if v, found := p.p["hypervisor"]; found { + u.Set("hypervisor", v.(string)) + } + if v, found := p.p["id"]; found { + u.Set("id", v.(string)) + } + if v, found := p.p["keyword"]; found { + u.Set("keyword", v.(string)) + } + if v, found := p.p["name"]; found { + u.Set("name", v.(string)) + } + if v, found := p.p["outofbandmanagementenabled"]; found { + vv := strconv.FormatBool(v.(bool)) + u.Set("outofbandmanagementenabled", vv) + } + if v, found := p.p["outofbandmanagementpowerstate"]; found { + u.Set("outofbandmanagementpowerstate", v.(string)) + } + if v, found := p.p["page"]; found { + vv := strconv.Itoa(v.(int)) + u.Set("page", vv) + } + if v, found := p.p["pagesize"]; found { + vv := strconv.Itoa(v.(int)) + u.Set("pagesize", vv) + } + if v, found := p.p["podid"]; found { + u.Set("podid", v.(string)) + } + if v, found := p.p["resourcestate"]; found { + u.Set("resourcestate", v.(string)) + } + if v, found := p.p["state"]; found { + u.Set("state", v.(string)) + } + if v, found := p.p["type"]; found { + u.Set("type", v.(string)) + } + if v, found := p.p["virtualmachineid"]; found { + u.Set("virtualmachineid", v.(string)) + } + if v, found := p.p["zoneid"]; found { + u.Set("zoneid", v.(string)) + } + return u +} + +func (p *ListHostsParams) SetClusterid(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["clusterid"] = v + return +} + +func (p *ListHostsParams) SetDetails(v []string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["details"] = v + return +} + +func (p *ListHostsParams) SetHahost(v bool) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["hahost"] = v + return +} + +func (p *ListHostsParams) SetHypervisor(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["hypervisor"] = v + return +} + +func (p *ListHostsParams) SetId(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["id"] = v + return +} + +func (p *ListHostsParams) SetKeyword(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["keyword"] = v + return +} + +func (p *ListHostsParams) SetName(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["name"] = v + return +} + +func (p *ListHostsParams) SetOutofbandmanagementenabled(v bool) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["outofbandmanagementenabled"] = v + return +} + +func (p *ListHostsParams) SetOutofbandmanagementpowerstate(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["outofbandmanagementpowerstate"] = v + return +} + +func (p *ListHostsParams) SetPage(v int) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["page"] = v + return +} + +func (p *ListHostsParams) SetPagesize(v int) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["pagesize"] = v + return +} + +func (p *ListHostsParams) SetPodid(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["podid"] = v + return +} + +func (p *ListHostsParams) SetResourcestate(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["resourcestate"] = v + return +} + +func (p *ListHostsParams) SetState(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["state"] = v + return +} + +func (p *ListHostsParams) SetType(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["type"] = v + return +} + +func (p *ListHostsParams) SetVirtualmachineid(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["virtualmachineid"] = v + return +} + +func (p *ListHostsParams) SetZoneid(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["zoneid"] = v + return +} + +// You should always use this function to get a new ListHostsParams instance, +// as then you are sure you have configured all required params +func (s *HostService) NewListHostsParams() *ListHostsParams { + p := &ListHostsParams{} + p.p = make(map[string]interface{}) + return p +} + +// This is a courtesy helper function, which in some cases may not work as expected! +func (s *HostService) GetHostID(name string, opts ...OptionFunc) (string, int, error) { + p := &ListHostsParams{} + p.p = make(map[string]interface{}) + + p.p["name"] = name + + for _, fn := range append(s.cs.options, opts...) { + if err := fn(s.cs, p); err != nil { + return "", -1, err + } + } + + l, err := s.ListHosts(p) + if err != nil { + return "", -1, err + } + + if l.Count == 0 { + return "", l.Count, fmt.Errorf("No match found for %s: %+v", name, l) + } + + if l.Count == 1 { + return l.Hosts[0].Id, l.Count, nil + } + + if l.Count > 1 { + for _, v := range l.Hosts { + if v.Name == name { + return v.Id, l.Count, nil + } + } + } + return "", l.Count, fmt.Errorf("Could not find an exact match for %s: %+v", name, l) +} + +// This is a courtesy helper function, which in some cases may not work as expected! +func (s *HostService) GetHostByName(name string, opts ...OptionFunc) (*Host, int, error) { + id, count, err := s.GetHostID(name, opts...) + if err != nil { + return nil, count, err + } + + r, count, err := s.GetHostByID(id, opts...) + if err != nil { + return nil, count, err + } + return r, count, nil +} + +// This is a courtesy helper function, which in some cases may not work as expected! +func (s *HostService) GetHostByID(id string, opts ...OptionFunc) (*Host, int, error) { + p := &ListHostsParams{} + p.p = make(map[string]interface{}) + + p.p["id"] = id + + for _, fn := range append(s.cs.options, opts...) { + if err := fn(s.cs, p); err != nil { + return nil, -1, err + } + } + + l, err := s.ListHosts(p) + if err != nil { + if strings.Contains(err.Error(), fmt.Sprintf( + "Invalid parameter id value=%s due to incorrect long value format, "+ + "or entity does not exist", id)) { + return nil, 0, fmt.Errorf("No match found for %s: %+v", id, l) + } + return nil, -1, err + } + + if l.Count == 0 { + return nil, l.Count, fmt.Errorf("No match found for %s: %+v", id, l) + } + + if l.Count == 1 { + return l.Hosts[0], l.Count, nil + } + return nil, l.Count, fmt.Errorf("There is more then one result for Host UUID: %s!", id) +} + +// Lists hosts. +func (s *HostService) ListHosts(p *ListHostsParams) (*ListHostsResponse, error) { + resp, err := s.cs.newRequest("listHosts", p.toURLValues()) + if err != nil { + return nil, err + } + + var r ListHostsResponse + if err := json.Unmarshal(resp, &r); err != nil { + return nil, err + } + + return &r, nil +} + +type ListHostsResponse struct { + Count int `json:"count"` + Hosts []*Host `json:"host"` +} + +type Host struct { + Annotation string `json:"annotation"` + Averageload int64 `json:"averageload"` + Capabilities string `json:"capabilities"` + Clusterid string `json:"clusterid"` + Clustername string `json:"clustername"` + Clustertype string `json:"clustertype"` + Cpuallocated string `json:"cpuallocated"` + Cpunumber int `json:"cpunumber"` + Cpusockets int `json:"cpusockets"` + Cpuspeed int64 `json:"cpuspeed"` + Cpuused string `json:"cpuused"` + Cpuwithoverprovisioning string `json:"cpuwithoverprovisioning"` + Created string `json:"created"` + Details map[string]string `json:"details"` + Disconnected string `json:"disconnected"` + Disksizeallocated int64 `json:"disksizeallocated"` + Disksizetotal int64 `json:"disksizetotal"` + Events string `json:"events"` + Gpugroup []HostGpugroup `json:"gpugroup"` + Hahost bool `json:"hahost"` + Hasenoughcapacity bool `json:"hasenoughcapacity"` + Hostha string `json:"hostha"` + Hosttags string `json:"hosttags"` + Hypervisor string `json:"hypervisor"` + Hypervisorversion string `json:"hypervisorversion"` + Id string `json:"id"` + Ipaddress string `json:"ipaddress"` + Islocalstorageactive bool `json:"islocalstorageactive"` + Lastannotated string `json:"lastannotated"` + Lastpinged string `json:"lastpinged"` + Managementserverid int64 `json:"managementserverid"` + Memoryallocated int64 `json:"memoryallocated"` + Memorytotal int64 `json:"memorytotal"` + Memoryused int64 `json:"memoryused"` + Memorywithoverprovisioning string `json:"memorywithoverprovisioning"` + Name string `json:"name"` + Networkkbsread int64 `json:"networkkbsread"` + Networkkbswrite int64 `json:"networkkbswrite"` + Oscategoryid string `json:"oscategoryid"` + Oscategoryname string `json:"oscategoryname"` + Outofbandmanagement OutOfBandManagementResponse `json:"outofbandmanagement"` + Podid string `json:"podid"` + Podname string `json:"podname"` + Removed string `json:"removed"` + Resourcestate string `json:"resourcestate"` + State string `json:"state"` + Suitableformigration bool `json:"suitableformigration"` + Type string `json:"type"` + Username string `json:"username"` + Version string `json:"version"` + Zoneid string `json:"zoneid"` + Zonename string `json:"zonename"` +} + +type HostGpugroup struct { + Gpugroupname string `json:"gpugroupname"` + Vgpu []HostGpugroupVgpu `json:"vgpu"` +} + +type HostGpugroupVgpu struct { + Maxcapacity int64 `json:"maxcapacity"` + Maxheads int64 `json:"maxheads"` + Maxresolutionx int64 `json:"maxresolutionx"` + Maxresolutiony int64 `json:"maxresolutiony"` + Maxvgpuperpgpu int64 `json:"maxvgpuperpgpu"` + Remainingcapacity int64 `json:"remainingcapacity"` + Vgputype string `json:"vgputype"` + Videoram int64 `json:"videoram"` +} + +type PrepareHostForMaintenanceParams struct { + p map[string]interface{} +} + +func (p *PrepareHostForMaintenanceParams) toURLValues() url.Values { + u := url.Values{} + if p.p == nil { + return u + } + if v, found := p.p["id"]; found { + u.Set("id", v.(string)) + } + return u +} + +func (p *PrepareHostForMaintenanceParams) SetId(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["id"] = v + return +} + +// You should always use this function to get a new PrepareHostForMaintenanceParams instance, +// as then you are sure you have configured all required params +func (s *HostService) NewPrepareHostForMaintenanceParams(id string) *PrepareHostForMaintenanceParams { + p := &PrepareHostForMaintenanceParams{} + p.p = make(map[string]interface{}) + p.p["id"] = id + return p +} + +// Prepares a host for maintenance. +func (s *HostService) PrepareHostForMaintenance(p *PrepareHostForMaintenanceParams) (*PrepareHostForMaintenanceResponse, error) { + resp, err := s.cs.newRequest("prepareHostForMaintenance", p.toURLValues()) + if err != nil { + return nil, err + } + + var r PrepareHostForMaintenanceResponse + if err := json.Unmarshal(resp, &r); err != nil { + return nil, err + } + + // If we have a async client, we need to wait for the async result + if s.cs.async { + b, err := s.cs.GetAsyncJobResult(r.JobID, s.cs.timeout) + if err != nil { + if err == AsyncTimeoutErr { + return &r, err + } + return nil, err + } + + b, err = getRawValue(b) + if err != nil { + return nil, err + } + + if err := json.Unmarshal(b, &r); err != nil { + return nil, err + } + } + + return &r, nil +} + +type PrepareHostForMaintenanceResponse struct { + JobID string `json:"jobid"` + Annotation string `json:"annotation"` + Averageload int64 `json:"averageload"` + Capabilities string `json:"capabilities"` + Clusterid string `json:"clusterid"` + Clustername string `json:"clustername"` + Clustertype string `json:"clustertype"` + Cpuallocated string `json:"cpuallocated"` + Cpunumber int `json:"cpunumber"` + Cpusockets int `json:"cpusockets"` + Cpuspeed int64 `json:"cpuspeed"` + Cpuused string `json:"cpuused"` + Cpuwithoverprovisioning string `json:"cpuwithoverprovisioning"` + Created string `json:"created"` + Details map[string]string `json:"details"` + Disconnected string `json:"disconnected"` + Disksizeallocated int64 `json:"disksizeallocated"` + Disksizetotal int64 `json:"disksizetotal"` + Events string `json:"events"` + Gpugroup []PrepareHostForMaintenanceResponseGpugroup `json:"gpugroup"` + Hahost bool `json:"hahost"` + Hasenoughcapacity bool `json:"hasenoughcapacity"` + Hostha string `json:"hostha"` + Hosttags string `json:"hosttags"` + Hypervisor string `json:"hypervisor"` + Hypervisorversion string `json:"hypervisorversion"` + Id string `json:"id"` + Ipaddress string `json:"ipaddress"` + Islocalstorageactive bool `json:"islocalstorageactive"` + Lastannotated string `json:"lastannotated"` + Lastpinged string `json:"lastpinged"` + Managementserverid int64 `json:"managementserverid"` + Memoryallocated int64 `json:"memoryallocated"` + Memorytotal int64 `json:"memorytotal"` + Memoryused int64 `json:"memoryused"` + Memorywithoverprovisioning string `json:"memorywithoverprovisioning"` + Name string `json:"name"` + Networkkbsread int64 `json:"networkkbsread"` + Networkkbswrite int64 `json:"networkkbswrite"` + Oscategoryid string `json:"oscategoryid"` + Oscategoryname string `json:"oscategoryname"` + Outofbandmanagement OutOfBandManagementResponse `json:"outofbandmanagement"` + Podid string `json:"podid"` + Podname string `json:"podname"` + Removed string `json:"removed"` + Resourcestate string `json:"resourcestate"` + State string `json:"state"` + Suitableformigration bool `json:"suitableformigration"` + Type string `json:"type"` + Username string `json:"username"` + Version string `json:"version"` + Zoneid string `json:"zoneid"` + Zonename string `json:"zonename"` +} + +type PrepareHostForMaintenanceResponseGpugroup struct { + Gpugroupname string `json:"gpugroupname"` + Vgpu []PrepareHostForMaintenanceResponseGpugroupVgpu `json:"vgpu"` +} + +type PrepareHostForMaintenanceResponseGpugroupVgpu struct { + Maxcapacity int64 `json:"maxcapacity"` + Maxheads int64 `json:"maxheads"` + Maxresolutionx int64 `json:"maxresolutionx"` + Maxresolutiony int64 `json:"maxresolutiony"` + Maxvgpuperpgpu int64 `json:"maxvgpuperpgpu"` + Remainingcapacity int64 `json:"remainingcapacity"` + Vgputype string `json:"vgputype"` + Videoram int64 `json:"videoram"` +} + +type ReconnectHostParams struct { + p map[string]interface{} +} + +func (p *ReconnectHostParams) toURLValues() url.Values { + u := url.Values{} + if p.p == nil { + return u + } + if v, found := p.p["id"]; found { + u.Set("id", v.(string)) + } + return u +} + +func (p *ReconnectHostParams) SetId(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["id"] = v + return +} + +// You should always use this function to get a new ReconnectHostParams instance, +// as then you are sure you have configured all required params +func (s *HostService) NewReconnectHostParams(id string) *ReconnectHostParams { + p := &ReconnectHostParams{} + p.p = make(map[string]interface{}) + p.p["id"] = id + return p +} + +// Reconnects a host. +func (s *HostService) ReconnectHost(p *ReconnectHostParams) (*ReconnectHostResponse, error) { + resp, err := s.cs.newRequest("reconnectHost", p.toURLValues()) + if err != nil { + return nil, err + } + + var r ReconnectHostResponse + if err := json.Unmarshal(resp, &r); err != nil { + return nil, err + } + + // If we have a async client, we need to wait for the async result + if s.cs.async { + b, err := s.cs.GetAsyncJobResult(r.JobID, s.cs.timeout) + if err != nil { + if err == AsyncTimeoutErr { + return &r, err + } + return nil, err + } + + b, err = getRawValue(b) + if err != nil { + return nil, err + } + + if err := json.Unmarshal(b, &r); err != nil { + return nil, err + } + } + + return &r, nil +} + +type ReconnectHostResponse struct { + JobID string `json:"jobid"` + Annotation string `json:"annotation"` + Averageload int64 `json:"averageload"` + Capabilities string `json:"capabilities"` + Clusterid string `json:"clusterid"` + Clustername string `json:"clustername"` + Clustertype string `json:"clustertype"` + Cpuallocated string `json:"cpuallocated"` + Cpunumber int `json:"cpunumber"` + Cpusockets int `json:"cpusockets"` + Cpuspeed int64 `json:"cpuspeed"` + Cpuused string `json:"cpuused"` + Cpuwithoverprovisioning string `json:"cpuwithoverprovisioning"` + Created string `json:"created"` + Details map[string]string `json:"details"` + Disconnected string `json:"disconnected"` + Disksizeallocated int64 `json:"disksizeallocated"` + Disksizetotal int64 `json:"disksizetotal"` + Events string `json:"events"` + Gpugroup []ReconnectHostResponseGpugroup `json:"gpugroup"` + Hahost bool `json:"hahost"` + Hasenoughcapacity bool `json:"hasenoughcapacity"` + Hostha string `json:"hostha"` + Hosttags string `json:"hosttags"` + Hypervisor string `json:"hypervisor"` + Hypervisorversion string `json:"hypervisorversion"` + Id string `json:"id"` + Ipaddress string `json:"ipaddress"` + Islocalstorageactive bool `json:"islocalstorageactive"` + Lastannotated string `json:"lastannotated"` + Lastpinged string `json:"lastpinged"` + Managementserverid int64 `json:"managementserverid"` + Memoryallocated int64 `json:"memoryallocated"` + Memorytotal int64 `json:"memorytotal"` + Memoryused int64 `json:"memoryused"` + Memorywithoverprovisioning string `json:"memorywithoverprovisioning"` + Name string `json:"name"` + Networkkbsread int64 `json:"networkkbsread"` + Networkkbswrite int64 `json:"networkkbswrite"` + Oscategoryid string `json:"oscategoryid"` + Oscategoryname string `json:"oscategoryname"` + Outofbandmanagement OutOfBandManagementResponse `json:"outofbandmanagement"` + Podid string `json:"podid"` + Podname string `json:"podname"` + Removed string `json:"removed"` + Resourcestate string `json:"resourcestate"` + State string `json:"state"` + Suitableformigration bool `json:"suitableformigration"` + Type string `json:"type"` + Username string `json:"username"` + Version string `json:"version"` + Zoneid string `json:"zoneid"` + Zonename string `json:"zonename"` +} + +type ReconnectHostResponseGpugroup struct { + Gpugroupname string `json:"gpugroupname"` + Vgpu []ReconnectHostResponseGpugroupVgpu `json:"vgpu"` +} + +type ReconnectHostResponseGpugroupVgpu struct { + Maxcapacity int64 `json:"maxcapacity"` + Maxheads int64 `json:"maxheads"` + Maxresolutionx int64 `json:"maxresolutionx"` + Maxresolutiony int64 `json:"maxresolutiony"` + Maxvgpuperpgpu int64 `json:"maxvgpuperpgpu"` + Remainingcapacity int64 `json:"remainingcapacity"` + Vgputype string `json:"vgputype"` + Videoram int64 `json:"videoram"` +} + +type ReleaseDedicatedHostParams struct { + p map[string]interface{} +} + +func (p *ReleaseDedicatedHostParams) toURLValues() url.Values { + u := url.Values{} + if p.p == nil { + return u + } + if v, found := p.p["hostid"]; found { + u.Set("hostid", v.(string)) + } + return u +} + +func (p *ReleaseDedicatedHostParams) SetHostid(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["hostid"] = v + return +} + +// You should always use this function to get a new ReleaseDedicatedHostParams instance, +// as then you are sure you have configured all required params +func (s *HostService) NewReleaseDedicatedHostParams(hostid string) *ReleaseDedicatedHostParams { + p := &ReleaseDedicatedHostParams{} + p.p = make(map[string]interface{}) + p.p["hostid"] = hostid + return p +} + +// Release the dedication for host +func (s *HostService) ReleaseDedicatedHost(p *ReleaseDedicatedHostParams) (*ReleaseDedicatedHostResponse, error) { + resp, err := s.cs.newRequest("releaseDedicatedHost", p.toURLValues()) + if err != nil { + return nil, err + } + + var r ReleaseDedicatedHostResponse if err := json.Unmarshal(resp, &r); err != nil { return nil, err } @@ -2286,11 +2249,371 @@ func (s *HostService) AddGloboDnsHost(p *AddGloboDnsHostParams) (*AddGloboDnsHos return nil, err } } + return &r, nil } -type AddGloboDnsHostResponse struct { - JobID string `json:"jobid,omitempty"` - Displaytext string `json:"displaytext,omitempty"` - Success bool `json:"success,omitempty"` +type ReleaseDedicatedHostResponse struct { + JobID string `json:"jobid"` + Displaytext string `json:"displaytext"` + Success bool `json:"success"` +} + +type ReleaseHostReservationParams struct { + p map[string]interface{} +} + +func (p *ReleaseHostReservationParams) toURLValues() url.Values { + u := url.Values{} + if p.p == nil { + return u + } + if v, found := p.p["id"]; found { + u.Set("id", v.(string)) + } + return u +} + +func (p *ReleaseHostReservationParams) SetId(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["id"] = v + return +} + +// You should always use this function to get a new ReleaseHostReservationParams instance, +// as then you are sure you have configured all required params +func (s *HostService) NewReleaseHostReservationParams(id string) *ReleaseHostReservationParams { + p := &ReleaseHostReservationParams{} + p.p = make(map[string]interface{}) + p.p["id"] = id + return p +} + +// Releases host reservation. +func (s *HostService) ReleaseHostReservation(p *ReleaseHostReservationParams) (*ReleaseHostReservationResponse, error) { + resp, err := s.cs.newRequest("releaseHostReservation", p.toURLValues()) + if err != nil { + return nil, err + } + + var r ReleaseHostReservationResponse + if err := json.Unmarshal(resp, &r); err != nil { + return nil, err + } + + // If we have a async client, we need to wait for the async result + if s.cs.async { + b, err := s.cs.GetAsyncJobResult(r.JobID, s.cs.timeout) + if err != nil { + if err == AsyncTimeoutErr { + return &r, err + } + return nil, err + } + + if err := json.Unmarshal(b, &r); err != nil { + return nil, err + } + } + + return &r, nil +} + +type ReleaseHostReservationResponse struct { + JobID string `json:"jobid"` + Displaytext string `json:"displaytext"` + Success bool `json:"success"` +} + +type UpdateHostParams struct { + p map[string]interface{} +} + +func (p *UpdateHostParams) toURLValues() url.Values { + u := url.Values{} + if p.p == nil { + return u + } + if v, found := p.p["allocationstate"]; found { + u.Set("allocationstate", v.(string)) + } + if v, found := p.p["annotation"]; found { + u.Set("annotation", v.(string)) + } + if v, found := p.p["hosttags"]; found { + vv := strings.Join(v.([]string), ",") + u.Set("hosttags", vv) + } + if v, found := p.p["id"]; found { + u.Set("id", v.(string)) + } + if v, found := p.p["oscategoryid"]; found { + u.Set("oscategoryid", v.(string)) + } + if v, found := p.p["url"]; found { + u.Set("url", v.(string)) + } + return u +} + +func (p *UpdateHostParams) SetAllocationstate(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["allocationstate"] = v + return +} + +func (p *UpdateHostParams) SetAnnotation(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["annotation"] = v + return +} + +func (p *UpdateHostParams) SetHosttags(v []string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["hosttags"] = v + return +} + +func (p *UpdateHostParams) SetId(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["id"] = v + return +} + +func (p *UpdateHostParams) SetOscategoryid(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["oscategoryid"] = v + return +} + +func (p *UpdateHostParams) SetUrl(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["url"] = v + return +} + +// You should always use this function to get a new UpdateHostParams instance, +// as then you are sure you have configured all required params +func (s *HostService) NewUpdateHostParams(id string) *UpdateHostParams { + p := &UpdateHostParams{} + p.p = make(map[string]interface{}) + p.p["id"] = id + return p +} + +// Updates a host. +func (s *HostService) UpdateHost(p *UpdateHostParams) (*UpdateHostResponse, error) { + resp, err := s.cs.newRequest("updateHost", p.toURLValues()) + if err != nil { + return nil, err + } + + var r UpdateHostResponse + if err := json.Unmarshal(resp, &r); err != nil { + return nil, err + } + + return &r, nil +} + +type UpdateHostResponse struct { + Annotation string `json:"annotation"` + Averageload int64 `json:"averageload"` + Capabilities string `json:"capabilities"` + Clusterid string `json:"clusterid"` + Clustername string `json:"clustername"` + Clustertype string `json:"clustertype"` + Cpuallocated string `json:"cpuallocated"` + Cpunumber int `json:"cpunumber"` + Cpusockets int `json:"cpusockets"` + Cpuspeed int64 `json:"cpuspeed"` + Cpuused string `json:"cpuused"` + Cpuwithoverprovisioning string `json:"cpuwithoverprovisioning"` + Created string `json:"created"` + Details map[string]string `json:"details"` + Disconnected string `json:"disconnected"` + Disksizeallocated int64 `json:"disksizeallocated"` + Disksizetotal int64 `json:"disksizetotal"` + Events string `json:"events"` + Gpugroup []UpdateHostResponseGpugroup `json:"gpugroup"` + Hahost bool `json:"hahost"` + Hasenoughcapacity bool `json:"hasenoughcapacity"` + Hostha string `json:"hostha"` + Hosttags string `json:"hosttags"` + Hypervisor string `json:"hypervisor"` + Hypervisorversion string `json:"hypervisorversion"` + Id string `json:"id"` + Ipaddress string `json:"ipaddress"` + Islocalstorageactive bool `json:"islocalstorageactive"` + Lastannotated string `json:"lastannotated"` + Lastpinged string `json:"lastpinged"` + Managementserverid int64 `json:"managementserverid"` + Memoryallocated int64 `json:"memoryallocated"` + Memorytotal int64 `json:"memorytotal"` + Memoryused int64 `json:"memoryused"` + Memorywithoverprovisioning string `json:"memorywithoverprovisioning"` + Name string `json:"name"` + Networkkbsread int64 `json:"networkkbsread"` + Networkkbswrite int64 `json:"networkkbswrite"` + Oscategoryid string `json:"oscategoryid"` + Oscategoryname string `json:"oscategoryname"` + Outofbandmanagement OutOfBandManagementResponse `json:"outofbandmanagement"` + Podid string `json:"podid"` + Podname string `json:"podname"` + Removed string `json:"removed"` + Resourcestate string `json:"resourcestate"` + State string `json:"state"` + Suitableformigration bool `json:"suitableformigration"` + Type string `json:"type"` + Username string `json:"username"` + Version string `json:"version"` + Zoneid string `json:"zoneid"` + Zonename string `json:"zonename"` +} + +type UpdateHostResponseGpugroup struct { + Gpugroupname string `json:"gpugroupname"` + Vgpu []UpdateHostResponseGpugroupVgpu `json:"vgpu"` +} + +type UpdateHostResponseGpugroupVgpu struct { + Maxcapacity int64 `json:"maxcapacity"` + Maxheads int64 `json:"maxheads"` + Maxresolutionx int64 `json:"maxresolutionx"` + Maxresolutiony int64 `json:"maxresolutiony"` + Maxvgpuperpgpu int64 `json:"maxvgpuperpgpu"` + Remainingcapacity int64 `json:"remainingcapacity"` + Vgputype string `json:"vgputype"` + Videoram int64 `json:"videoram"` +} + +type UpdateHostPasswordParams struct { + p map[string]interface{} +} + +func (p *UpdateHostPasswordParams) toURLValues() url.Values { + u := url.Values{} + if p.p == nil { + return u + } + if v, found := p.p["clusterid"]; found { + u.Set("clusterid", v.(string)) + } + if v, found := p.p["hostid"]; found { + u.Set("hostid", v.(string)) + } + if v, found := p.p["password"]; found { + u.Set("password", v.(string)) + } + if v, found := p.p["update_passwd_on_host"]; found { + vv := strconv.FormatBool(v.(bool)) + u.Set("update_passwd_on_host", vv) + } + if v, found := p.p["username"]; found { + u.Set("username", v.(string)) + } + return u +} + +func (p *UpdateHostPasswordParams) SetClusterid(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["clusterid"] = v + return +} + +func (p *UpdateHostPasswordParams) SetHostid(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["hostid"] = v + return +} + +func (p *UpdateHostPasswordParams) SetPassword(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["password"] = v + return +} + +func (p *UpdateHostPasswordParams) SetUpdate_passwd_on_host(v bool) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["update_passwd_on_host"] = v + return +} + +func (p *UpdateHostPasswordParams) SetUsername(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["username"] = v + return +} + +// You should always use this function to get a new UpdateHostPasswordParams instance, +// as then you are sure you have configured all required params +func (s *HostService) NewUpdateHostPasswordParams(password string, username string) *UpdateHostPasswordParams { + p := &UpdateHostPasswordParams{} + p.p = make(map[string]interface{}) + p.p["password"] = password + p.p["username"] = username + return p +} + +// Update password of a host/pool on management server. +func (s *HostService) UpdateHostPassword(p *UpdateHostPasswordParams) (*UpdateHostPasswordResponse, error) { + resp, err := s.cs.newRequest("updateHostPassword", p.toURLValues()) + if err != nil { + return nil, err + } + + var r UpdateHostPasswordResponse + if err := json.Unmarshal(resp, &r); err != nil { + return nil, err + } + + return &r, nil +} + +type UpdateHostPasswordResponse struct { + Displaytext string `json:"displaytext"` + Success bool `json:"success"` +} + +func (r *UpdateHostPasswordResponse) UnmarshalJSON(b []byte) error { + var m map[string]interface{} + err := json.Unmarshal(b, &m) + if err != nil { + return err + } + + if success, ok := m["success"].(string); ok { + m["success"] = success == "true" + b, err = json.Marshal(m) + if err != nil { + return err + } + } + + type alias UpdateHostPasswordResponse + return json.Unmarshal(b, (*alias)(r)) } diff --git a/vendor/github.com/xanzy/go-cloudstack/cloudstack/HypervisorService.go b/vendor/github.com/xanzy/go-cloudstack/cloudstack/HypervisorService.go index c172615c9..c457b3092 100644 --- a/vendor/github.com/xanzy/go-cloudstack/cloudstack/HypervisorService.go +++ b/vendor/github.com/xanzy/go-cloudstack/cloudstack/HypervisorService.go @@ -1,5 +1,5 @@ // -// Copyright 2016, Sander van Harmelen +// Copyright 2018, Sander van Harmelen // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -24,140 +24,6 @@ import ( "strings" ) -type ListHypervisorsParams struct { - p map[string]interface{} -} - -func (p *ListHypervisorsParams) toURLValues() url.Values { - u := url.Values{} - if p.p == nil { - return u - } - if v, found := p.p["zoneid"]; found { - u.Set("zoneid", v.(string)) - } - return u -} - -func (p *ListHypervisorsParams) SetZoneid(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["zoneid"] = v - return -} - -// You should always use this function to get a new ListHypervisorsParams instance, -// as then you are sure you have configured all required params -func (s *HypervisorService) NewListHypervisorsParams() *ListHypervisorsParams { - p := &ListHypervisorsParams{} - p.p = make(map[string]interface{}) - return p -} - -// List hypervisors -func (s *HypervisorService) ListHypervisors(p *ListHypervisorsParams) (*ListHypervisorsResponse, error) { - resp, err := s.cs.newRequest("listHypervisors", p.toURLValues()) - if err != nil { - return nil, err - } - - var r ListHypervisorsResponse - if err := json.Unmarshal(resp, &r); err != nil { - return nil, err - } - return &r, nil -} - -type ListHypervisorsResponse struct { - Count int `json:"count"` - Hypervisors []*Hypervisor `json:"hypervisor"` -} - -type Hypervisor struct { - Name string `json:"name,omitempty"` -} - -type UpdateHypervisorCapabilitiesParams struct { - p map[string]interface{} -} - -func (p *UpdateHypervisorCapabilitiesParams) toURLValues() url.Values { - u := url.Values{} - if p.p == nil { - return u - } - if v, found := p.p["id"]; found { - u.Set("id", v.(string)) - } - if v, found := p.p["maxguestslimit"]; found { - vv := strconv.FormatInt(v.(int64), 10) - u.Set("maxguestslimit", vv) - } - if v, found := p.p["securitygroupenabled"]; found { - vv := strconv.FormatBool(v.(bool)) - u.Set("securitygroupenabled", vv) - } - return u -} - -func (p *UpdateHypervisorCapabilitiesParams) SetId(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["id"] = v - return -} - -func (p *UpdateHypervisorCapabilitiesParams) SetMaxguestslimit(v int64) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["maxguestslimit"] = v - return -} - -func (p *UpdateHypervisorCapabilitiesParams) SetSecuritygroupenabled(v bool) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["securitygroupenabled"] = v - return -} - -// You should always use this function to get a new UpdateHypervisorCapabilitiesParams instance, -// as then you are sure you have configured all required params -func (s *HypervisorService) NewUpdateHypervisorCapabilitiesParams() *UpdateHypervisorCapabilitiesParams { - p := &UpdateHypervisorCapabilitiesParams{} - p.p = make(map[string]interface{}) - return p -} - -// Updates a hypervisor capabilities. -func (s *HypervisorService) UpdateHypervisorCapabilities(p *UpdateHypervisorCapabilitiesParams) (*UpdateHypervisorCapabilitiesResponse, error) { - resp, err := s.cs.newRequest("updateHypervisorCapabilities", p.toURLValues()) - if err != nil { - return nil, err - } - - var r UpdateHypervisorCapabilitiesResponse - if err := json.Unmarshal(resp, &r); err != nil { - return nil, err - } - return &r, nil -} - -type UpdateHypervisorCapabilitiesResponse struct { - Hypervisor string `json:"hypervisor,omitempty"` - Hypervisorversion string `json:"hypervisorversion,omitempty"` - Id string `json:"id,omitempty"` - Maxdatavolumeslimit int `json:"maxdatavolumeslimit,omitempty"` - Maxguestslimit int64 `json:"maxguestslimit,omitempty"` - Maxhostspercluster int `json:"maxhostspercluster,omitempty"` - Securitygroupenabled bool `json:"securitygroupenabled,omitempty"` - Storagemotionenabled bool `json:"storagemotionenabled,omitempty"` -} - type ListHypervisorCapabilitiesParams struct { p map[string]interface{} } @@ -242,7 +108,7 @@ func (s *HypervisorService) GetHypervisorCapabilityByID(id string, opts ...Optio p.p["id"] = id - for _, fn := range opts { + for _, fn := range append(s.cs.options, opts...) { if err := fn(s.cs, p); err != nil { return nil, -1, err } @@ -279,6 +145,7 @@ func (s *HypervisorService) ListHypervisorCapabilities(p *ListHypervisorCapabili if err := json.Unmarshal(resp, &r); err != nil { return nil, err } + return &r, nil } @@ -288,12 +155,148 @@ type ListHypervisorCapabilitiesResponse struct { } type HypervisorCapability struct { - Hypervisor string `json:"hypervisor,omitempty"` - Hypervisorversion string `json:"hypervisorversion,omitempty"` - Id string `json:"id,omitempty"` - Maxdatavolumeslimit int `json:"maxdatavolumeslimit,omitempty"` - Maxguestslimit int64 `json:"maxguestslimit,omitempty"` - Maxhostspercluster int `json:"maxhostspercluster,omitempty"` - Securitygroupenabled bool `json:"securitygroupenabled,omitempty"` - Storagemotionenabled bool `json:"storagemotionenabled,omitempty"` + Hypervisor string `json:"hypervisor"` + Hypervisorversion string `json:"hypervisorversion"` + Id string `json:"id"` + Maxdatavolumeslimit int `json:"maxdatavolumeslimit"` + Maxguestslimit int64 `json:"maxguestslimit"` + Maxhostspercluster int `json:"maxhostspercluster"` + Securitygroupenabled bool `json:"securitygroupenabled"` + Storagemotionenabled bool `json:"storagemotionenabled"` +} + +type ListHypervisorsParams struct { + p map[string]interface{} +} + +func (p *ListHypervisorsParams) toURLValues() url.Values { + u := url.Values{} + if p.p == nil { + return u + } + if v, found := p.p["zoneid"]; found { + u.Set("zoneid", v.(string)) + } + return u +} + +func (p *ListHypervisorsParams) SetZoneid(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["zoneid"] = v + return +} + +// You should always use this function to get a new ListHypervisorsParams instance, +// as then you are sure you have configured all required params +func (s *HypervisorService) NewListHypervisorsParams() *ListHypervisorsParams { + p := &ListHypervisorsParams{} + p.p = make(map[string]interface{}) + return p +} + +// List hypervisors +func (s *HypervisorService) ListHypervisors(p *ListHypervisorsParams) (*ListHypervisorsResponse, error) { + resp, err := s.cs.newRequest("listHypervisors", p.toURLValues()) + if err != nil { + return nil, err + } + + var r ListHypervisorsResponse + if err := json.Unmarshal(resp, &r); err != nil { + return nil, err + } + + return &r, nil +} + +type ListHypervisorsResponse struct { + Count int `json:"count"` + Hypervisors []*Hypervisor `json:"hypervisor"` +} + +type Hypervisor struct { + Name string `json:"name"` +} + +type UpdateHypervisorCapabilitiesParams struct { + p map[string]interface{} +} + +func (p *UpdateHypervisorCapabilitiesParams) toURLValues() url.Values { + u := url.Values{} + if p.p == nil { + return u + } + if v, found := p.p["id"]; found { + u.Set("id", v.(string)) + } + if v, found := p.p["maxguestslimit"]; found { + vv := strconv.FormatInt(v.(int64), 10) + u.Set("maxguestslimit", vv) + } + if v, found := p.p["securitygroupenabled"]; found { + vv := strconv.FormatBool(v.(bool)) + u.Set("securitygroupenabled", vv) + } + return u +} + +func (p *UpdateHypervisorCapabilitiesParams) SetId(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["id"] = v + return +} + +func (p *UpdateHypervisorCapabilitiesParams) SetMaxguestslimit(v int64) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["maxguestslimit"] = v + return +} + +func (p *UpdateHypervisorCapabilitiesParams) SetSecuritygroupenabled(v bool) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["securitygroupenabled"] = v + return +} + +// You should always use this function to get a new UpdateHypervisorCapabilitiesParams instance, +// as then you are sure you have configured all required params +func (s *HypervisorService) NewUpdateHypervisorCapabilitiesParams() *UpdateHypervisorCapabilitiesParams { + p := &UpdateHypervisorCapabilitiesParams{} + p.p = make(map[string]interface{}) + return p +} + +// Updates a hypervisor capabilities. +func (s *HypervisorService) UpdateHypervisorCapabilities(p *UpdateHypervisorCapabilitiesParams) (*UpdateHypervisorCapabilitiesResponse, error) { + resp, err := s.cs.newRequest("updateHypervisorCapabilities", p.toURLValues()) + if err != nil { + return nil, err + } + + var r UpdateHypervisorCapabilitiesResponse + if err := json.Unmarshal(resp, &r); err != nil { + return nil, err + } + + return &r, nil +} + +type UpdateHypervisorCapabilitiesResponse struct { + Hypervisor string `json:"hypervisor"` + Hypervisorversion string `json:"hypervisorversion"` + Id string `json:"id"` + Maxdatavolumeslimit int `json:"maxdatavolumeslimit"` + Maxguestslimit int64 `json:"maxguestslimit"` + Maxhostspercluster int `json:"maxhostspercluster"` + Securitygroupenabled bool `json:"securitygroupenabled"` + Storagemotionenabled bool `json:"storagemotionenabled"` } diff --git a/vendor/github.com/xanzy/go-cloudstack/cloudstack/ISOService.go b/vendor/github.com/xanzy/go-cloudstack/cloudstack/ISOService.go index a4ad582a6..96db4bf5f 100644 --- a/vendor/github.com/xanzy/go-cloudstack/cloudstack/ISOService.go +++ b/vendor/github.com/xanzy/go-cloudstack/cloudstack/ISOService.go @@ -1,5 +1,5 @@ // -// Copyright 2016, Sander van Harmelen +// Copyright 2018, Sander van Harmelen // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -99,184 +99,340 @@ func (s *ISOService) AttachIso(p *AttachIsoParams) (*AttachIsoResponse, error) { return nil, err } } + return &r, nil } type AttachIsoResponse struct { - JobID string `json:"jobid,omitempty"` - Account string `json:"account,omitempty"` - Affinitygroup []struct { - Account string `json:"account,omitempty"` - Description string `json:"description,omitempty"` - Domain string `json:"domain,omitempty"` - Domainid string `json:"domainid,omitempty"` - Id string `json:"id,omitempty"` - Name string `json:"name,omitempty"` - Project string `json:"project,omitempty"` - Projectid string `json:"projectid,omitempty"` - Type string `json:"type,omitempty"` - VirtualmachineIds []string `json:"virtualmachineIds,omitempty"` - } `json:"affinitygroup,omitempty"` - Cpunumber int `json:"cpunumber,omitempty"` - Cpuspeed int `json:"cpuspeed,omitempty"` - Cpuused string `json:"cpuused,omitempty"` - Created string `json:"created,omitempty"` - Details map[string]string `json:"details,omitempty"` - Diskioread int64 `json:"diskioread,omitempty"` - Diskiowrite int64 `json:"diskiowrite,omitempty"` - Diskkbsread int64 `json:"diskkbsread,omitempty"` - Diskkbswrite int64 `json:"diskkbswrite,omitempty"` - Diskofferingid string `json:"diskofferingid,omitempty"` - Diskofferingname string `json:"diskofferingname,omitempty"` - Displayname string `json:"displayname,omitempty"` - Displayvm bool `json:"displayvm,omitempty"` - Domain string `json:"domain,omitempty"` - Domainid string `json:"domainid,omitempty"` - Forvirtualnetwork bool `json:"forvirtualnetwork,omitempty"` - Group string `json:"group,omitempty"` - Groupid string `json:"groupid,omitempty"` - Guestosid string `json:"guestosid,omitempty"` - Haenable bool `json:"haenable,omitempty"` - Hostid string `json:"hostid,omitempty"` - Hostname string `json:"hostname,omitempty"` - Hypervisor string `json:"hypervisor,omitempty"` - Id string `json:"id,omitempty"` - Instancename string `json:"instancename,omitempty"` - Isdynamicallyscalable bool `json:"isdynamicallyscalable,omitempty"` - Isodisplaytext string `json:"isodisplaytext,omitempty"` - Isoid string `json:"isoid,omitempty"` - Isoname string `json:"isoname,omitempty"` - Keypair string `json:"keypair,omitempty"` - Memory int `json:"memory,omitempty"` - Name string `json:"name,omitempty"` - Networkkbsread int64 `json:"networkkbsread,omitempty"` - Networkkbswrite int64 `json:"networkkbswrite,omitempty"` - Nic []struct { - Broadcasturi string `json:"broadcasturi,omitempty"` - Deviceid string `json:"deviceid,omitempty"` - Gateway string `json:"gateway,omitempty"` - Id string `json:"id,omitempty"` - Ip6address string `json:"ip6address,omitempty"` - Ip6cidr string `json:"ip6cidr,omitempty"` - Ip6gateway string `json:"ip6gateway,omitempty"` - Ipaddress string `json:"ipaddress,omitempty"` - Isdefault bool `json:"isdefault,omitempty"` - Isolationuri string `json:"isolationuri,omitempty"` - Macaddress string `json:"macaddress,omitempty"` - Netmask string `json:"netmask,omitempty"` - Networkid string `json:"networkid,omitempty"` - Networkname string `json:"networkname,omitempty"` - Secondaryip []struct { - Id string `json:"id,omitempty"` - Ipaddress string `json:"ipaddress,omitempty"` - } `json:"secondaryip,omitempty"` - Traffictype string `json:"traffictype,omitempty"` - Type string `json:"type,omitempty"` - Virtualmachineid string `json:"virtualmachineid,omitempty"` - } `json:"nic,omitempty"` - Ostypeid int64 `json:"ostypeid,omitempty"` - Password string `json:"password,omitempty"` - Passwordenabled bool `json:"passwordenabled,omitempty"` - Project string `json:"project,omitempty"` - Projectid string `json:"projectid,omitempty"` - Publicip string `json:"publicip,omitempty"` - Publicipid string `json:"publicipid,omitempty"` - Rootdeviceid int64 `json:"rootdeviceid,omitempty"` - Rootdevicetype string `json:"rootdevicetype,omitempty"` - Securitygroup []struct { - Account string `json:"account,omitempty"` - Description string `json:"description,omitempty"` - Domain string `json:"domain,omitempty"` - Domainid string `json:"domainid,omitempty"` - Egressrule []struct { - Account string `json:"account,omitempty"` - Cidr string `json:"cidr,omitempty"` - Endport int `json:"endport,omitempty"` - Icmpcode int `json:"icmpcode,omitempty"` - Icmptype int `json:"icmptype,omitempty"` - Protocol string `json:"protocol,omitempty"` - Ruleid string `json:"ruleid,omitempty"` - Securitygroupname string `json:"securitygroupname,omitempty"` - Startport int `json:"startport,omitempty"` - Tags []struct { - Account string `json:"account,omitempty"` - Customer string `json:"customer,omitempty"` - Domain string `json:"domain,omitempty"` - Domainid string `json:"domainid,omitempty"` - Key string `json:"key,omitempty"` - Project string `json:"project,omitempty"` - Projectid string `json:"projectid,omitempty"` - Resourceid string `json:"resourceid,omitempty"` - Resourcetype string `json:"resourcetype,omitempty"` - Value string `json:"value,omitempty"` - } `json:"tags,omitempty"` - } `json:"egressrule,omitempty"` - Id string `json:"id,omitempty"` - Ingressrule []struct { - Account string `json:"account,omitempty"` - Cidr string `json:"cidr,omitempty"` - Endport int `json:"endport,omitempty"` - Icmpcode int `json:"icmpcode,omitempty"` - Icmptype int `json:"icmptype,omitempty"` - Protocol string `json:"protocol,omitempty"` - Ruleid string `json:"ruleid,omitempty"` - Securitygroupname string `json:"securitygroupname,omitempty"` - Startport int `json:"startport,omitempty"` - Tags []struct { - Account string `json:"account,omitempty"` - Customer string `json:"customer,omitempty"` - Domain string `json:"domain,omitempty"` - Domainid string `json:"domainid,omitempty"` - Key string `json:"key,omitempty"` - Project string `json:"project,omitempty"` - Projectid string `json:"projectid,omitempty"` - Resourceid string `json:"resourceid,omitempty"` - Resourcetype string `json:"resourcetype,omitempty"` - Value string `json:"value,omitempty"` - } `json:"tags,omitempty"` - } `json:"ingressrule,omitempty"` - Name string `json:"name,omitempty"` - Project string `json:"project,omitempty"` - Projectid string `json:"projectid,omitempty"` - Tags []struct { - Account string `json:"account,omitempty"` - Customer string `json:"customer,omitempty"` - Domain string `json:"domain,omitempty"` - Domainid string `json:"domainid,omitempty"` - Key string `json:"key,omitempty"` - Project string `json:"project,omitempty"` - Projectid string `json:"projectid,omitempty"` - Resourceid string `json:"resourceid,omitempty"` - Resourcetype string `json:"resourcetype,omitempty"` - Value string `json:"value,omitempty"` - } `json:"tags,omitempty"` - Virtualmachinecount int `json:"virtualmachinecount,omitempty"` - Virtualmachineids []string `json:"virtualmachineids,omitempty"` - } `json:"securitygroup,omitempty"` - Serviceofferingid string `json:"serviceofferingid,omitempty"` - Serviceofferingname string `json:"serviceofferingname,omitempty"` - Servicestate string `json:"servicestate,omitempty"` - State string `json:"state,omitempty"` - Tags []struct { - Account string `json:"account,omitempty"` - Customer string `json:"customer,omitempty"` - Domain string `json:"domain,omitempty"` - Domainid string `json:"domainid,omitempty"` - Key string `json:"key,omitempty"` - Project string `json:"project,omitempty"` - Projectid string `json:"projectid,omitempty"` - Resourceid string `json:"resourceid,omitempty"` - Resourcetype string `json:"resourcetype,omitempty"` - Value string `json:"value,omitempty"` - } `json:"tags,omitempty"` - Templatedisplaytext string `json:"templatedisplaytext,omitempty"` - Templateid string `json:"templateid,omitempty"` - Templatename string `json:"templatename,omitempty"` - Userid string `json:"userid,omitempty"` - Username string `json:"username,omitempty"` - Vgpu string `json:"vgpu,omitempty"` - Zoneid string `json:"zoneid,omitempty"` - Zonename string `json:"zonename,omitempty"` + JobID string `json:"jobid"` + Account string `json:"account"` + Affinitygroup []AttachIsoResponseAffinitygroup `json:"affinitygroup"` + Cpunumber int `json:"cpunumber"` + Cpuspeed int `json:"cpuspeed"` + Cpuused string `json:"cpuused"` + Created string `json:"created"` + Details map[string]string `json:"details"` + Diskioread int64 `json:"diskioread"` + Diskiowrite int64 `json:"diskiowrite"` + Diskkbsread int64 `json:"diskkbsread"` + Diskkbswrite int64 `json:"diskkbswrite"` + Diskofferingid string `json:"diskofferingid"` + Diskofferingname string `json:"diskofferingname"` + Displayname string `json:"displayname"` + Displayvm bool `json:"displayvm"` + Domain string `json:"domain"` + Domainid string `json:"domainid"` + Forvirtualnetwork bool `json:"forvirtualnetwork"` + Group string `json:"group"` + Groupid string `json:"groupid"` + Guestosid string `json:"guestosid"` + Haenable bool `json:"haenable"` + Hostid string `json:"hostid"` + Hostname string `json:"hostname"` + Hypervisor string `json:"hypervisor"` + Id string `json:"id"` + Instancename string `json:"instancename"` + Isdynamicallyscalable bool `json:"isdynamicallyscalable"` + Isodisplaytext string `json:"isodisplaytext"` + Isoid string `json:"isoid"` + Isoname string `json:"isoname"` + Keypair string `json:"keypair"` + Memory int `json:"memory"` + Memoryintfreekbs int64 `json:"memoryintfreekbs"` + Memorykbs int64 `json:"memorykbs"` + Memorytargetkbs int64 `json:"memorytargetkbs"` + Name string `json:"name"` + Networkkbsread int64 `json:"networkkbsread"` + Networkkbswrite int64 `json:"networkkbswrite"` + Nic []Nic `json:"nic"` + Ostypeid int64 `json:"ostypeid"` + Password string `json:"password"` + Passwordenabled bool `json:"passwordenabled"` + Project string `json:"project"` + Projectid string `json:"projectid"` + Publicip string `json:"publicip"` + Publicipid string `json:"publicipid"` + Rootdeviceid int64 `json:"rootdeviceid"` + Rootdevicetype string `json:"rootdevicetype"` + Securitygroup []AttachIsoResponseSecuritygroup `json:"securitygroup"` + Serviceofferingid string `json:"serviceofferingid"` + Serviceofferingname string `json:"serviceofferingname"` + Servicestate string `json:"servicestate"` + State string `json:"state"` + Templatedisplaytext string `json:"templatedisplaytext"` + Templateid string `json:"templateid"` + Templatename string `json:"templatename"` + Userid string `json:"userid"` + Username string `json:"username"` + Vgpu string `json:"vgpu"` + Zoneid string `json:"zoneid"` + Zonename string `json:"zonename"` +} + +type AttachIsoResponseSecuritygroup struct { + Account string `json:"account"` + Description string `json:"description"` + Domain string `json:"domain"` + Domainid string `json:"domainid"` + Egressrule []AttachIsoResponseSecuritygroupRule `json:"egressrule"` + Id string `json:"id"` + Ingressrule []AttachIsoResponseSecuritygroupRule `json:"ingressrule"` + Name string `json:"name"` + Project string `json:"project"` + Projectid string `json:"projectid"` + Tags []Tags `json:"tags"` + Virtualmachinecount int `json:"virtualmachinecount"` + Virtualmachineids []interface{} `json:"virtualmachineids"` +} + +type AttachIsoResponseSecuritygroupRule struct { + Account string `json:"account"` + Cidr string `json:"cidr"` + Endport int `json:"endport"` + Icmpcode int `json:"icmpcode"` + Icmptype int `json:"icmptype"` + Protocol string `json:"protocol"` + Ruleid string `json:"ruleid"` + Securitygroupname string `json:"securitygroupname"` + Startport int `json:"startport"` + Tags []Tags `json:"tags"` +} + +type AttachIsoResponseAffinitygroup struct { + Account string `json:"account"` + Description string `json:"description"` + Domain string `json:"domain"` + Domainid string `json:"domainid"` + Id string `json:"id"` + Name string `json:"name"` + Project string `json:"project"` + Projectid string `json:"projectid"` + Type string `json:"type"` + VirtualmachineIds []string `json:"virtualmachineIds"` +} + +type CopyIsoParams struct { + p map[string]interface{} +} + +func (p *CopyIsoParams) toURLValues() url.Values { + u := url.Values{} + if p.p == nil { + return u + } + if v, found := p.p["destzoneid"]; found { + u.Set("destzoneid", v.(string)) + } + if v, found := p.p["destzoneids"]; found { + vv := strings.Join(v.([]string), ",") + u.Set("destzoneids", vv) + } + if v, found := p.p["id"]; found { + u.Set("id", v.(string)) + } + if v, found := p.p["sourcezoneid"]; found { + u.Set("sourcezoneid", v.(string)) + } + return u +} + +func (p *CopyIsoParams) SetDestzoneid(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["destzoneid"] = v + return +} + +func (p *CopyIsoParams) SetDestzoneids(v []string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["destzoneids"] = v + return +} + +func (p *CopyIsoParams) SetId(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["id"] = v + return +} + +func (p *CopyIsoParams) SetSourcezoneid(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["sourcezoneid"] = v + return +} + +// You should always use this function to get a new CopyIsoParams instance, +// as then you are sure you have configured all required params +func (s *ISOService) NewCopyIsoParams(id string) *CopyIsoParams { + p := &CopyIsoParams{} + p.p = make(map[string]interface{}) + p.p["id"] = id + return p +} + +// Copies an iso from one zone to another. +func (s *ISOService) CopyIso(p *CopyIsoParams) (*CopyIsoResponse, error) { + resp, err := s.cs.newRequest("copyIso", p.toURLValues()) + if err != nil { + return nil, err + } + + var r CopyIsoResponse + if err := json.Unmarshal(resp, &r); err != nil { + return nil, err + } + + // If we have a async client, we need to wait for the async result + if s.cs.async { + b, err := s.cs.GetAsyncJobResult(r.JobID, s.cs.timeout) + if err != nil { + if err == AsyncTimeoutErr { + return &r, err + } + return nil, err + } + + b, err = getRawValue(b) + if err != nil { + return nil, err + } + + if err := json.Unmarshal(b, &r); err != nil { + return nil, err + } + } + + return &r, nil +} + +type CopyIsoResponse struct { + JobID string `json:"jobid"` + Account string `json:"account"` + Accountid string `json:"accountid"` + Bits int `json:"bits"` + Bootable bool `json:"bootable"` + Checksum string `json:"checksum"` + Childtemplates []interface{} `json:"childtemplates"` + Created string `json:"created"` + CrossZones bool `json:"crossZones"` + Details map[string]string `json:"details"` + Directdownload bool `json:"directdownload"` + Displaytext string `json:"displaytext"` + Domain string `json:"domain"` + Domainid string `json:"domainid"` + Format string `json:"format"` + Hostid string `json:"hostid"` + Hostname string `json:"hostname"` + Hypervisor string `json:"hypervisor"` + Id string `json:"id"` + Isdynamicallyscalable bool `json:"isdynamicallyscalable"` + Isextractable bool `json:"isextractable"` + Isfeatured bool `json:"isfeatured"` + Ispublic bool `json:"ispublic"` + Isready bool `json:"isready"` + Name string `json:"name"` + Ostypeid string `json:"ostypeid"` + Ostypename string `json:"ostypename"` + Parenttemplateid string `json:"parenttemplateid"` + Passwordenabled bool `json:"passwordenabled"` + Physicalsize int64 `json:"physicalsize"` + Project string `json:"project"` + Projectid string `json:"projectid"` + Removed string `json:"removed"` + Size int64 `json:"size"` + Sourcetemplateid string `json:"sourcetemplateid"` + Sshkeyenabled bool `json:"sshkeyenabled"` + Status string `json:"status"` + Templatetag string `json:"templatetag"` + Templatetype string `json:"templatetype"` + Zoneid string `json:"zoneid"` + Zonename string `json:"zonename"` +} + +type DeleteIsoParams struct { + p map[string]interface{} +} + +func (p *DeleteIsoParams) toURLValues() url.Values { + u := url.Values{} + if p.p == nil { + return u + } + if v, found := p.p["id"]; found { + u.Set("id", v.(string)) + } + if v, found := p.p["zoneid"]; found { + u.Set("zoneid", v.(string)) + } + return u +} + +func (p *DeleteIsoParams) SetId(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["id"] = v + return +} + +func (p *DeleteIsoParams) SetZoneid(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["zoneid"] = v + return +} + +// You should always use this function to get a new DeleteIsoParams instance, +// as then you are sure you have configured all required params +func (s *ISOService) NewDeleteIsoParams(id string) *DeleteIsoParams { + p := &DeleteIsoParams{} + p.p = make(map[string]interface{}) + p.p["id"] = id + return p +} + +// Deletes an ISO file. +func (s *ISOService) DeleteIso(p *DeleteIsoParams) (*DeleteIsoResponse, error) { + resp, err := s.cs.newRequest("deleteIso", p.toURLValues()) + if err != nil { + return nil, err + } + + var r DeleteIsoResponse + if err := json.Unmarshal(resp, &r); err != nil { + return nil, err + } + + // If we have a async client, we need to wait for the async result + if s.cs.async { + b, err := s.cs.GetAsyncJobResult(r.JobID, s.cs.timeout) + if err != nil { + if err == AsyncTimeoutErr { + return &r, err + } + return nil, err + } + + if err := json.Unmarshal(b, &r); err != nil { + return nil, err + } + } + + return &r, nil +} + +type DeleteIsoResponse struct { + JobID string `json:"jobid"` + Displaytext string `json:"displaytext"` + Success bool `json:"success"` } type DetachIsoParams struct { @@ -342,184 +498,328 @@ func (s *ISOService) DetachIso(p *DetachIsoParams) (*DetachIsoResponse, error) { return nil, err } } + return &r, nil } type DetachIsoResponse struct { - JobID string `json:"jobid,omitempty"` - Account string `json:"account,omitempty"` - Affinitygroup []struct { - Account string `json:"account,omitempty"` - Description string `json:"description,omitempty"` - Domain string `json:"domain,omitempty"` - Domainid string `json:"domainid,omitempty"` - Id string `json:"id,omitempty"` - Name string `json:"name,omitempty"` - Project string `json:"project,omitempty"` - Projectid string `json:"projectid,omitempty"` - Type string `json:"type,omitempty"` - VirtualmachineIds []string `json:"virtualmachineIds,omitempty"` - } `json:"affinitygroup,omitempty"` - Cpunumber int `json:"cpunumber,omitempty"` - Cpuspeed int `json:"cpuspeed,omitempty"` - Cpuused string `json:"cpuused,omitempty"` - Created string `json:"created,omitempty"` - Details map[string]string `json:"details,omitempty"` - Diskioread int64 `json:"diskioread,omitempty"` - Diskiowrite int64 `json:"diskiowrite,omitempty"` - Diskkbsread int64 `json:"diskkbsread,omitempty"` - Diskkbswrite int64 `json:"diskkbswrite,omitempty"` - Diskofferingid string `json:"diskofferingid,omitempty"` - Diskofferingname string `json:"diskofferingname,omitempty"` - Displayname string `json:"displayname,omitempty"` - Displayvm bool `json:"displayvm,omitempty"` - Domain string `json:"domain,omitempty"` - Domainid string `json:"domainid,omitempty"` - Forvirtualnetwork bool `json:"forvirtualnetwork,omitempty"` - Group string `json:"group,omitempty"` - Groupid string `json:"groupid,omitempty"` - Guestosid string `json:"guestosid,omitempty"` - Haenable bool `json:"haenable,omitempty"` - Hostid string `json:"hostid,omitempty"` - Hostname string `json:"hostname,omitempty"` - Hypervisor string `json:"hypervisor,omitempty"` - Id string `json:"id,omitempty"` - Instancename string `json:"instancename,omitempty"` - Isdynamicallyscalable bool `json:"isdynamicallyscalable,omitempty"` - Isodisplaytext string `json:"isodisplaytext,omitempty"` - Isoid string `json:"isoid,omitempty"` - Isoname string `json:"isoname,omitempty"` - Keypair string `json:"keypair,omitempty"` - Memory int `json:"memory,omitempty"` - Name string `json:"name,omitempty"` - Networkkbsread int64 `json:"networkkbsread,omitempty"` - Networkkbswrite int64 `json:"networkkbswrite,omitempty"` - Nic []struct { - Broadcasturi string `json:"broadcasturi,omitempty"` - Deviceid string `json:"deviceid,omitempty"` - Gateway string `json:"gateway,omitempty"` - Id string `json:"id,omitempty"` - Ip6address string `json:"ip6address,omitempty"` - Ip6cidr string `json:"ip6cidr,omitempty"` - Ip6gateway string `json:"ip6gateway,omitempty"` - Ipaddress string `json:"ipaddress,omitempty"` - Isdefault bool `json:"isdefault,omitempty"` - Isolationuri string `json:"isolationuri,omitempty"` - Macaddress string `json:"macaddress,omitempty"` - Netmask string `json:"netmask,omitempty"` - Networkid string `json:"networkid,omitempty"` - Networkname string `json:"networkname,omitempty"` - Secondaryip []struct { - Id string `json:"id,omitempty"` - Ipaddress string `json:"ipaddress,omitempty"` - } `json:"secondaryip,omitempty"` - Traffictype string `json:"traffictype,omitempty"` - Type string `json:"type,omitempty"` - Virtualmachineid string `json:"virtualmachineid,omitempty"` - } `json:"nic,omitempty"` - Ostypeid int64 `json:"ostypeid,omitempty"` - Password string `json:"password,omitempty"` - Passwordenabled bool `json:"passwordenabled,omitempty"` - Project string `json:"project,omitempty"` - Projectid string `json:"projectid,omitempty"` - Publicip string `json:"publicip,omitempty"` - Publicipid string `json:"publicipid,omitempty"` - Rootdeviceid int64 `json:"rootdeviceid,omitempty"` - Rootdevicetype string `json:"rootdevicetype,omitempty"` - Securitygroup []struct { - Account string `json:"account,omitempty"` - Description string `json:"description,omitempty"` - Domain string `json:"domain,omitempty"` - Domainid string `json:"domainid,omitempty"` - Egressrule []struct { - Account string `json:"account,omitempty"` - Cidr string `json:"cidr,omitempty"` - Endport int `json:"endport,omitempty"` - Icmpcode int `json:"icmpcode,omitempty"` - Icmptype int `json:"icmptype,omitempty"` - Protocol string `json:"protocol,omitempty"` - Ruleid string `json:"ruleid,omitempty"` - Securitygroupname string `json:"securitygroupname,omitempty"` - Startport int `json:"startport,omitempty"` - Tags []struct { - Account string `json:"account,omitempty"` - Customer string `json:"customer,omitempty"` - Domain string `json:"domain,omitempty"` - Domainid string `json:"domainid,omitempty"` - Key string `json:"key,omitempty"` - Project string `json:"project,omitempty"` - Projectid string `json:"projectid,omitempty"` - Resourceid string `json:"resourceid,omitempty"` - Resourcetype string `json:"resourcetype,omitempty"` - Value string `json:"value,omitempty"` - } `json:"tags,omitempty"` - } `json:"egressrule,omitempty"` - Id string `json:"id,omitempty"` - Ingressrule []struct { - Account string `json:"account,omitempty"` - Cidr string `json:"cidr,omitempty"` - Endport int `json:"endport,omitempty"` - Icmpcode int `json:"icmpcode,omitempty"` - Icmptype int `json:"icmptype,omitempty"` - Protocol string `json:"protocol,omitempty"` - Ruleid string `json:"ruleid,omitempty"` - Securitygroupname string `json:"securitygroupname,omitempty"` - Startport int `json:"startport,omitempty"` - Tags []struct { - Account string `json:"account,omitempty"` - Customer string `json:"customer,omitempty"` - Domain string `json:"domain,omitempty"` - Domainid string `json:"domainid,omitempty"` - Key string `json:"key,omitempty"` - Project string `json:"project,omitempty"` - Projectid string `json:"projectid,omitempty"` - Resourceid string `json:"resourceid,omitempty"` - Resourcetype string `json:"resourcetype,omitempty"` - Value string `json:"value,omitempty"` - } `json:"tags,omitempty"` - } `json:"ingressrule,omitempty"` - Name string `json:"name,omitempty"` - Project string `json:"project,omitempty"` - Projectid string `json:"projectid,omitempty"` - Tags []struct { - Account string `json:"account,omitempty"` - Customer string `json:"customer,omitempty"` - Domain string `json:"domain,omitempty"` - Domainid string `json:"domainid,omitempty"` - Key string `json:"key,omitempty"` - Project string `json:"project,omitempty"` - Projectid string `json:"projectid,omitempty"` - Resourceid string `json:"resourceid,omitempty"` - Resourcetype string `json:"resourcetype,omitempty"` - Value string `json:"value,omitempty"` - } `json:"tags,omitempty"` - Virtualmachinecount int `json:"virtualmachinecount,omitempty"` - Virtualmachineids []string `json:"virtualmachineids,omitempty"` - } `json:"securitygroup,omitempty"` - Serviceofferingid string `json:"serviceofferingid,omitempty"` - Serviceofferingname string `json:"serviceofferingname,omitempty"` - Servicestate string `json:"servicestate,omitempty"` - State string `json:"state,omitempty"` - Tags []struct { - Account string `json:"account,omitempty"` - Customer string `json:"customer,omitempty"` - Domain string `json:"domain,omitempty"` - Domainid string `json:"domainid,omitempty"` - Key string `json:"key,omitempty"` - Project string `json:"project,omitempty"` - Projectid string `json:"projectid,omitempty"` - Resourceid string `json:"resourceid,omitempty"` - Resourcetype string `json:"resourcetype,omitempty"` - Value string `json:"value,omitempty"` - } `json:"tags,omitempty"` - Templatedisplaytext string `json:"templatedisplaytext,omitempty"` - Templateid string `json:"templateid,omitempty"` - Templatename string `json:"templatename,omitempty"` - Userid string `json:"userid,omitempty"` - Username string `json:"username,omitempty"` - Vgpu string `json:"vgpu,omitempty"` - Zoneid string `json:"zoneid,omitempty"` - Zonename string `json:"zonename,omitempty"` + JobID string `json:"jobid"` + Account string `json:"account"` + Affinitygroup []DetachIsoResponseAffinitygroup `json:"affinitygroup"` + Cpunumber int `json:"cpunumber"` + Cpuspeed int `json:"cpuspeed"` + Cpuused string `json:"cpuused"` + Created string `json:"created"` + Details map[string]string `json:"details"` + Diskioread int64 `json:"diskioread"` + Diskiowrite int64 `json:"diskiowrite"` + Diskkbsread int64 `json:"diskkbsread"` + Diskkbswrite int64 `json:"diskkbswrite"` + Diskofferingid string `json:"diskofferingid"` + Diskofferingname string `json:"diskofferingname"` + Displayname string `json:"displayname"` + Displayvm bool `json:"displayvm"` + Domain string `json:"domain"` + Domainid string `json:"domainid"` + Forvirtualnetwork bool `json:"forvirtualnetwork"` + Group string `json:"group"` + Groupid string `json:"groupid"` + Guestosid string `json:"guestosid"` + Haenable bool `json:"haenable"` + Hostid string `json:"hostid"` + Hostname string `json:"hostname"` + Hypervisor string `json:"hypervisor"` + Id string `json:"id"` + Instancename string `json:"instancename"` + Isdynamicallyscalable bool `json:"isdynamicallyscalable"` + Isodisplaytext string `json:"isodisplaytext"` + Isoid string `json:"isoid"` + Isoname string `json:"isoname"` + Keypair string `json:"keypair"` + Memory int `json:"memory"` + Memoryintfreekbs int64 `json:"memoryintfreekbs"` + Memorykbs int64 `json:"memorykbs"` + Memorytargetkbs int64 `json:"memorytargetkbs"` + Name string `json:"name"` + Networkkbsread int64 `json:"networkkbsread"` + Networkkbswrite int64 `json:"networkkbswrite"` + Nic []Nic `json:"nic"` + Ostypeid int64 `json:"ostypeid"` + Password string `json:"password"` + Passwordenabled bool `json:"passwordenabled"` + Project string `json:"project"` + Projectid string `json:"projectid"` + Publicip string `json:"publicip"` + Publicipid string `json:"publicipid"` + Rootdeviceid int64 `json:"rootdeviceid"` + Rootdevicetype string `json:"rootdevicetype"` + Securitygroup []DetachIsoResponseSecuritygroup `json:"securitygroup"` + Serviceofferingid string `json:"serviceofferingid"` + Serviceofferingname string `json:"serviceofferingname"` + Servicestate string `json:"servicestate"` + State string `json:"state"` + Templatedisplaytext string `json:"templatedisplaytext"` + Templateid string `json:"templateid"` + Templatename string `json:"templatename"` + Userid string `json:"userid"` + Username string `json:"username"` + Vgpu string `json:"vgpu"` + Zoneid string `json:"zoneid"` + Zonename string `json:"zonename"` +} + +type DetachIsoResponseSecuritygroup struct { + Account string `json:"account"` + Description string `json:"description"` + Domain string `json:"domain"` + Domainid string `json:"domainid"` + Egressrule []DetachIsoResponseSecuritygroupRule `json:"egressrule"` + Id string `json:"id"` + Ingressrule []DetachIsoResponseSecuritygroupRule `json:"ingressrule"` + Name string `json:"name"` + Project string `json:"project"` + Projectid string `json:"projectid"` + Tags []Tags `json:"tags"` + Virtualmachinecount int `json:"virtualmachinecount"` + Virtualmachineids []interface{} `json:"virtualmachineids"` +} + +type DetachIsoResponseSecuritygroupRule struct { + Account string `json:"account"` + Cidr string `json:"cidr"` + Endport int `json:"endport"` + Icmpcode int `json:"icmpcode"` + Icmptype int `json:"icmptype"` + Protocol string `json:"protocol"` + Ruleid string `json:"ruleid"` + Securitygroupname string `json:"securitygroupname"` + Startport int `json:"startport"` + Tags []Tags `json:"tags"` +} + +type DetachIsoResponseAffinitygroup struct { + Account string `json:"account"` + Description string `json:"description"` + Domain string `json:"domain"` + Domainid string `json:"domainid"` + Id string `json:"id"` + Name string `json:"name"` + Project string `json:"project"` + Projectid string `json:"projectid"` + Type string `json:"type"` + VirtualmachineIds []string `json:"virtualmachineIds"` +} + +type ExtractIsoParams struct { + p map[string]interface{} +} + +func (p *ExtractIsoParams) toURLValues() url.Values { + u := url.Values{} + if p.p == nil { + return u + } + if v, found := p.p["id"]; found { + u.Set("id", v.(string)) + } + if v, found := p.p["mode"]; found { + u.Set("mode", v.(string)) + } + if v, found := p.p["url"]; found { + u.Set("url", v.(string)) + } + if v, found := p.p["zoneid"]; found { + u.Set("zoneid", v.(string)) + } + return u +} + +func (p *ExtractIsoParams) SetId(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["id"] = v + return +} + +func (p *ExtractIsoParams) SetMode(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["mode"] = v + return +} + +func (p *ExtractIsoParams) SetUrl(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["url"] = v + return +} + +func (p *ExtractIsoParams) SetZoneid(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["zoneid"] = v + return +} + +// You should always use this function to get a new ExtractIsoParams instance, +// as then you are sure you have configured all required params +func (s *ISOService) NewExtractIsoParams(id string, mode string) *ExtractIsoParams { + p := &ExtractIsoParams{} + p.p = make(map[string]interface{}) + p.p["id"] = id + p.p["mode"] = mode + return p +} + +// Extracts an ISO +func (s *ISOService) ExtractIso(p *ExtractIsoParams) (*ExtractIsoResponse, error) { + resp, err := s.cs.newRequest("extractIso", p.toURLValues()) + if err != nil { + return nil, err + } + + var r ExtractIsoResponse + if err := json.Unmarshal(resp, &r); err != nil { + return nil, err + } + + // If we have a async client, we need to wait for the async result + if s.cs.async { + b, err := s.cs.GetAsyncJobResult(r.JobID, s.cs.timeout) + if err != nil { + if err == AsyncTimeoutErr { + return &r, err + } + return nil, err + } + + b, err = getRawValue(b) + if err != nil { + return nil, err + } + + if err := json.Unmarshal(b, &r); err != nil { + return nil, err + } + } + + return &r, nil +} + +type ExtractIsoResponse struct { + JobID string `json:"jobid"` + Accountid string `json:"accountid"` + Created string `json:"created"` + ExtractId string `json:"extractId"` + ExtractMode string `json:"extractMode"` + Id string `json:"id"` + Name string `json:"name"` + Resultstring string `json:"resultstring"` + State string `json:"state"` + Status string `json:"status"` + Storagetype string `json:"storagetype"` + Uploadpercentage int `json:"uploadpercentage"` + Url string `json:"url"` + Zoneid string `json:"zoneid"` + Zonename string `json:"zonename"` +} + +type ListIsoPermissionsParams struct { + p map[string]interface{} +} + +func (p *ListIsoPermissionsParams) toURLValues() url.Values { + u := url.Values{} + if p.p == nil { + return u + } + if v, found := p.p["id"]; found { + u.Set("id", v.(string)) + } + return u +} + +func (p *ListIsoPermissionsParams) SetId(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["id"] = v + return +} + +// You should always use this function to get a new ListIsoPermissionsParams instance, +// as then you are sure you have configured all required params +func (s *ISOService) NewListIsoPermissionsParams(id string) *ListIsoPermissionsParams { + p := &ListIsoPermissionsParams{} + p.p = make(map[string]interface{}) + p.p["id"] = id + return p +} + +// This is a courtesy helper function, which in some cases may not work as expected! +func (s *ISOService) GetIsoPermissionByID(id string, opts ...OptionFunc) (*IsoPermission, int, error) { + p := &ListIsoPermissionsParams{} + p.p = make(map[string]interface{}) + + p.p["id"] = id + + for _, fn := range append(s.cs.options, opts...) { + if err := fn(s.cs, p); err != nil { + return nil, -1, err + } + } + + l, err := s.ListIsoPermissions(p) + if err != nil { + if strings.Contains(err.Error(), fmt.Sprintf( + "Invalid parameter id value=%s due to incorrect long value format, "+ + "or entity does not exist", id)) { + return nil, 0, fmt.Errorf("No match found for %s: %+v", id, l) + } + return nil, -1, err + } + + if l.Count == 0 { + return nil, l.Count, fmt.Errorf("No match found for %s: %+v", id, l) + } + + if l.Count == 1 { + return l.IsoPermissions[0], l.Count, nil + } + return nil, l.Count, fmt.Errorf("There is more then one result for IsoPermission UUID: %s!", id) +} + +// List iso visibility and all accounts that have permissions to view this iso. +func (s *ISOService) ListIsoPermissions(p *ListIsoPermissionsParams) (*ListIsoPermissionsResponse, error) { + resp, err := s.cs.newRequest("listIsoPermissions", p.toURLValues()) + if err != nil { + return nil, err + } + + var r ListIsoPermissionsResponse + if err := json.Unmarshal(resp, &r); err != nil { + return nil, err + } + + return &r, nil +} + +type ListIsoPermissionsResponse struct { + Count int `json:"count"` + IsoPermissions []*IsoPermission `json:"isopermission"` +} + +type IsoPermission struct { + Account []string `json:"account"` + Domainid string `json:"domainid"` + Id string `json:"id"` + Ispublic bool `json:"ispublic"` + Projectids []string `json:"projectids"` } type ListIsosParams struct { @@ -762,7 +1062,7 @@ func (s *ISOService) GetIsoID(name string, isofilter string, zoneid string, opts p.p["isofilter"] = isofilter p.p["zoneid"] = zoneid - for _, fn := range opts { + for _, fn := range append(s.cs.options, opts...) { if err := fn(s.cs, p); err != nil { return "", -1, err } @@ -812,7 +1112,7 @@ func (s *ISOService) GetIsoByID(id string, opts ...OptionFunc) (*Iso, int, error p.p["id"] = id - for _, fn := range opts { + for _, fn := range append(s.cs.options, opts...) { if err := fn(s.cs, p); err != nil { return nil, -1, err } @@ -849,6 +1149,7 @@ func (s *ISOService) ListIsos(p *ListIsosParams) (*ListIsosResponse, error) { if err := json.Unmarshal(resp, &r); err != nil { return nil, err } + return &r, nil } @@ -858,53 +1159,46 @@ type ListIsosResponse struct { } type Iso struct { - Account string `json:"account,omitempty"` - Accountid string `json:"accountid,omitempty"` - Bootable bool `json:"bootable,omitempty"` - Checksum string `json:"checksum,omitempty"` - Created string `json:"created,omitempty"` - CrossZones bool `json:"crossZones,omitempty"` - Details map[string]string `json:"details,omitempty"` - Displaytext string `json:"displaytext,omitempty"` - Domain string `json:"domain,omitempty"` - Domainid string `json:"domainid,omitempty"` - Format string `json:"format,omitempty"` - Hostid string `json:"hostid,omitempty"` - Hostname string `json:"hostname,omitempty"` - Hypervisor string `json:"hypervisor,omitempty"` - Id string `json:"id,omitempty"` - Isdynamicallyscalable bool `json:"isdynamicallyscalable,omitempty"` - Isextractable bool `json:"isextractable,omitempty"` - Isfeatured bool `json:"isfeatured,omitempty"` - Ispublic bool `json:"ispublic,omitempty"` - Isready bool `json:"isready,omitempty"` - Name string `json:"name,omitempty"` - Ostypeid string `json:"ostypeid,omitempty"` - Ostypename string `json:"ostypename,omitempty"` - Passwordenabled bool `json:"passwordenabled,omitempty"` - Project string `json:"project,omitempty"` - Projectid string `json:"projectid,omitempty"` - Removed string `json:"removed,omitempty"` - Size int64 `json:"size,omitempty"` - Sourcetemplateid string `json:"sourcetemplateid,omitempty"` - Sshkeyenabled bool `json:"sshkeyenabled,omitempty"` - Status string `json:"status,omitempty"` - Tags []struct { - Account string `json:"account,omitempty"` - Customer string `json:"customer,omitempty"` - Domain string `json:"domain,omitempty"` - Domainid string `json:"domainid,omitempty"` - Key string `json:"key,omitempty"` - Project string `json:"project,omitempty"` - Projectid string `json:"projectid,omitempty"` - Resourceid string `json:"resourceid,omitempty"` - Resourcetype string `json:"resourcetype,omitempty"` - Value string `json:"value,omitempty"` - } `json:"tags,omitempty"` - Templatetag string `json:"templatetag,omitempty"` - Templatetype string `json:"templatetype,omitempty"` - Zoneid string `json:"zoneid,omitempty"` - Zonename string `json:"zonename,omitempty"` + Account string `json:"account"` + Accountid string `json:"accountid"` + Bits int `json:"bits"` + Bootable bool `json:"bootable"` + Checksum string `json:"checksum"` + Childtemplates []interface{} `json:"childtemplates"` + Created string `json:"created"` + CrossZones bool `json:"crossZones"` + Details map[string]string `json:"details"` + Directdownload bool `json:"directdownload"` + Displaytext string `json:"displaytext"` + Domain string `json:"domain"` + Domainid string `json:"domainid"` + Format string `json:"format"` + Hostid string `json:"hostid"` + Hostname string `json:"hostname"` + Hypervisor string `json:"hypervisor"` + Id string `json:"id"` + Isdynamicallyscalable bool `json:"isdynamicallyscalable"` + Isextractable bool `json:"isextractable"` + Isfeatured bool `json:"isfeatured"` + Ispublic bool `json:"ispublic"` + Isready bool `json:"isready"` + Name string `json:"name"` + Ostypeid string `json:"ostypeid"` + Ostypename string `json:"ostypename"` + Parenttemplateid string `json:"parenttemplateid"` + Passwordenabled bool `json:"passwordenabled"` + Physicalsize int64 `json:"physicalsize"` + Project string `json:"project"` + Projectid string `json:"projectid"` + Removed string `json:"removed"` + Size int64 `json:"size"` + Sourcetemplateid string `json:"sourcetemplateid"` + Sshkeyenabled bool `json:"sshkeyenabled"` + Status string `json:"status"` + Templatetag string `json:"templatetag"` + Templatetype string `json:"templatetype"` + Zoneid string `json:"zoneid"` + Zonename string `json:"zonename"` } type RegisterIsoParams struct { @@ -926,6 +1220,10 @@ func (p *RegisterIsoParams) toURLValues() url.Values { if v, found := p.p["checksum"]; found { u.Set("checksum", v.(string)) } + if v, found := p.p["directdownload"]; found { + vv := strconv.FormatBool(v.(bool)) + u.Set("directdownload", vv) + } if v, found := p.p["displaytext"]; found { u.Set("displaytext", v.(string)) } @@ -993,6 +1291,14 @@ func (p *RegisterIsoParams) SetChecksum(v string) { return } +func (p *RegisterIsoParams) SetDirectdownload(v bool) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["directdownload"] = v + return +} + func (p *RegisterIsoParams) SetDisplaytext(v string) { if p.p == nil { p.p = make(map[string]interface{}) @@ -1112,57 +1418,51 @@ func (s *ISOService) RegisterIso(p *RegisterIsoParams) (*RegisterIsoResponse, er if err := json.Unmarshal(resp, &r); err != nil { return nil, err } + return &r, nil } type RegisterIsoResponse struct { - Account string `json:"account,omitempty"` - Accountid string `json:"accountid,omitempty"` - Bootable bool `json:"bootable,omitempty"` - Checksum string `json:"checksum,omitempty"` - Created string `json:"created,omitempty"` - CrossZones bool `json:"crossZones,omitempty"` - Details map[string]string `json:"details,omitempty"` - Displaytext string `json:"displaytext,omitempty"` - Domain string `json:"domain,omitempty"` - Domainid string `json:"domainid,omitempty"` - Format string `json:"format,omitempty"` - Hostid string `json:"hostid,omitempty"` - Hostname string `json:"hostname,omitempty"` - Hypervisor string `json:"hypervisor,omitempty"` - Id string `json:"id,omitempty"` - Isdynamicallyscalable bool `json:"isdynamicallyscalable,omitempty"` - Isextractable bool `json:"isextractable,omitempty"` - Isfeatured bool `json:"isfeatured,omitempty"` - Ispublic bool `json:"ispublic,omitempty"` - Isready bool `json:"isready,omitempty"` - Name string `json:"name,omitempty"` - Ostypeid string `json:"ostypeid,omitempty"` - Ostypename string `json:"ostypename,omitempty"` - Passwordenabled bool `json:"passwordenabled,omitempty"` - Project string `json:"project,omitempty"` - Projectid string `json:"projectid,omitempty"` - Removed string `json:"removed,omitempty"` - Size int64 `json:"size,omitempty"` - Sourcetemplateid string `json:"sourcetemplateid,omitempty"` - Sshkeyenabled bool `json:"sshkeyenabled,omitempty"` - Status string `json:"status,omitempty"` - Tags []struct { - Account string `json:"account,omitempty"` - Customer string `json:"customer,omitempty"` - Domain string `json:"domain,omitempty"` - Domainid string `json:"domainid,omitempty"` - Key string `json:"key,omitempty"` - Project string `json:"project,omitempty"` - Projectid string `json:"projectid,omitempty"` - Resourceid string `json:"resourceid,omitempty"` - Resourcetype string `json:"resourcetype,omitempty"` - Value string `json:"value,omitempty"` - } `json:"tags,omitempty"` - Templatetag string `json:"templatetag,omitempty"` - Templatetype string `json:"templatetype,omitempty"` - Zoneid string `json:"zoneid,omitempty"` - Zonename string `json:"zonename,omitempty"` + Account string `json:"account"` + Accountid string `json:"accountid"` + Bits int `json:"bits"` + Bootable bool `json:"bootable"` + Checksum string `json:"checksum"` + Childtemplates []interface{} `json:"childtemplates"` + Created string `json:"created"` + CrossZones bool `json:"crossZones"` + Details map[string]string `json:"details"` + Directdownload bool `json:"directdownload"` + Displaytext string `json:"displaytext"` + Domain string `json:"domain"` + Domainid string `json:"domainid"` + Format string `json:"format"` + Hostid string `json:"hostid"` + Hostname string `json:"hostname"` + Hypervisor string `json:"hypervisor"` + Id string `json:"id"` + Isdynamicallyscalable bool `json:"isdynamicallyscalable"` + Isextractable bool `json:"isextractable"` + Isfeatured bool `json:"isfeatured"` + Ispublic bool `json:"ispublic"` + Isready bool `json:"isready"` + Name string `json:"name"` + Ostypeid string `json:"ostypeid"` + Ostypename string `json:"ostypename"` + Parenttemplateid string `json:"parenttemplateid"` + Passwordenabled bool `json:"passwordenabled"` + Physicalsize int64 `json:"physicalsize"` + Project string `json:"project"` + Projectid string `json:"projectid"` + Removed string `json:"removed"` + Size int64 `json:"size"` + Sourcetemplateid string `json:"sourcetemplateid"` + Sshkeyenabled bool `json:"sshkeyenabled"` + Status string `json:"status"` + Templatetag string `json:"templatetag"` + Templatetype string `json:"templatetype"` + Zoneid string `json:"zoneid"` + Zonename string `json:"zonename"` } type UpdateIsoParams struct { @@ -1178,11 +1478,14 @@ func (p *UpdateIsoParams) toURLValues() url.Values { vv := strconv.FormatBool(v.(bool)) u.Set("bootable", vv) } + if v, found := p.p["cleanupdetails"]; found { + vv := strconv.FormatBool(v.(bool)) + u.Set("cleanupdetails", vv) + } if v, found := p.p["details"]; found { i := 0 for k, vv := range v.(map[string]string) { - u.Set(fmt.Sprintf("details[%d].key", i), k) - u.Set(fmt.Sprintf("details[%d].value", i), vv) + u.Set(fmt.Sprintf("details[%d].%s", i, k), vv) i++ } } @@ -1232,6 +1535,14 @@ func (p *UpdateIsoParams) SetBootable(v bool) { return } +func (p *UpdateIsoParams) SetCleanupdetails(v bool) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["cleanupdetails"] = v + return +} + func (p *UpdateIsoParams) SetDetails(v map[string]string) { if p.p == nil { p.p = make(map[string]interface{}) @@ -1340,275 +1651,51 @@ func (s *ISOService) UpdateIso(p *UpdateIsoParams) (*UpdateIsoResponse, error) { if err := json.Unmarshal(resp, &r); err != nil { return nil, err } + return &r, nil } type UpdateIsoResponse struct { - Account string `json:"account,omitempty"` - Accountid string `json:"accountid,omitempty"` - Bootable bool `json:"bootable,omitempty"` - Checksum string `json:"checksum,omitempty"` - Created string `json:"created,omitempty"` - CrossZones bool `json:"crossZones,omitempty"` - Details map[string]string `json:"details,omitempty"` - Displaytext string `json:"displaytext,omitempty"` - Domain string `json:"domain,omitempty"` - Domainid string `json:"domainid,omitempty"` - Format string `json:"format,omitempty"` - Hostid string `json:"hostid,omitempty"` - Hostname string `json:"hostname,omitempty"` - Hypervisor string `json:"hypervisor,omitempty"` - Id string `json:"id,omitempty"` - Isdynamicallyscalable bool `json:"isdynamicallyscalable,omitempty"` - Isextractable bool `json:"isextractable,omitempty"` - Isfeatured bool `json:"isfeatured,omitempty"` - Ispublic bool `json:"ispublic,omitempty"` - Isready bool `json:"isready,omitempty"` - Name string `json:"name,omitempty"` - Ostypeid string `json:"ostypeid,omitempty"` - Ostypename string `json:"ostypename,omitempty"` - Passwordenabled bool `json:"passwordenabled,omitempty"` - Project string `json:"project,omitempty"` - Projectid string `json:"projectid,omitempty"` - Removed string `json:"removed,omitempty"` - Size int64 `json:"size,omitempty"` - Sourcetemplateid string `json:"sourcetemplateid,omitempty"` - Sshkeyenabled bool `json:"sshkeyenabled,omitempty"` - Status string `json:"status,omitempty"` - Tags []struct { - Account string `json:"account,omitempty"` - Customer string `json:"customer,omitempty"` - Domain string `json:"domain,omitempty"` - Domainid string `json:"domainid,omitempty"` - Key string `json:"key,omitempty"` - Project string `json:"project,omitempty"` - Projectid string `json:"projectid,omitempty"` - Resourceid string `json:"resourceid,omitempty"` - Resourcetype string `json:"resourcetype,omitempty"` - Value string `json:"value,omitempty"` - } `json:"tags,omitempty"` - Templatetag string `json:"templatetag,omitempty"` - Templatetype string `json:"templatetype,omitempty"` - Zoneid string `json:"zoneid,omitempty"` - Zonename string `json:"zonename,omitempty"` -} - -type DeleteIsoParams struct { - p map[string]interface{} -} - -func (p *DeleteIsoParams) toURLValues() url.Values { - u := url.Values{} - if p.p == nil { - return u - } - if v, found := p.p["id"]; found { - u.Set("id", v.(string)) - } - if v, found := p.p["zoneid"]; found { - u.Set("zoneid", v.(string)) - } - return u -} - -func (p *DeleteIsoParams) SetId(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["id"] = v - return -} - -func (p *DeleteIsoParams) SetZoneid(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["zoneid"] = v - return -} - -// You should always use this function to get a new DeleteIsoParams instance, -// as then you are sure you have configured all required params -func (s *ISOService) NewDeleteIsoParams(id string) *DeleteIsoParams { - p := &DeleteIsoParams{} - p.p = make(map[string]interface{}) - p.p["id"] = id - return p -} - -// Deletes an ISO file. -func (s *ISOService) DeleteIso(p *DeleteIsoParams) (*DeleteIsoResponse, error) { - resp, err := s.cs.newRequest("deleteIso", p.toURLValues()) - if err != nil { - return nil, err - } - - var r DeleteIsoResponse - if err := json.Unmarshal(resp, &r); err != nil { - return nil, err - } - - // If we have a async client, we need to wait for the async result - if s.cs.async { - b, err := s.cs.GetAsyncJobResult(r.JobID, s.cs.timeout) - if err != nil { - if err == AsyncTimeoutErr { - return &r, err - } - return nil, err - } - - if err := json.Unmarshal(b, &r); err != nil { - return nil, err - } - } - return &r, nil -} - -type DeleteIsoResponse struct { - JobID string `json:"jobid,omitempty"` - Displaytext string `json:"displaytext,omitempty"` - Success bool `json:"success,omitempty"` -} - -type CopyIsoParams struct { - p map[string]interface{} -} - -func (p *CopyIsoParams) toURLValues() url.Values { - u := url.Values{} - if p.p == nil { - return u - } - if v, found := p.p["destzoneid"]; found { - u.Set("destzoneid", v.(string)) - } - if v, found := p.p["id"]; found { - u.Set("id", v.(string)) - } - if v, found := p.p["sourcezoneid"]; found { - u.Set("sourcezoneid", v.(string)) - } - return u -} - -func (p *CopyIsoParams) SetDestzoneid(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["destzoneid"] = v - return -} - -func (p *CopyIsoParams) SetId(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["id"] = v - return -} - -func (p *CopyIsoParams) SetSourcezoneid(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["sourcezoneid"] = v - return -} - -// You should always use this function to get a new CopyIsoParams instance, -// as then you are sure you have configured all required params -func (s *ISOService) NewCopyIsoParams(destzoneid string, id string) *CopyIsoParams { - p := &CopyIsoParams{} - p.p = make(map[string]interface{}) - p.p["destzoneid"] = destzoneid - p.p["id"] = id - return p -} - -// Copies an ISO from one zone to another. -func (s *ISOService) CopyIso(p *CopyIsoParams) (*CopyIsoResponse, error) { - resp, err := s.cs.newRequest("copyIso", p.toURLValues()) - if err != nil { - return nil, err - } - - var r CopyIsoResponse - if err := json.Unmarshal(resp, &r); err != nil { - return nil, err - } - - // If we have a async client, we need to wait for the async result - if s.cs.async { - b, err := s.cs.GetAsyncJobResult(r.JobID, s.cs.timeout) - if err != nil { - if err == AsyncTimeoutErr { - return &r, err - } - return nil, err - } - - b, err = getRawValue(b) - if err != nil { - return nil, err - } - - if err := json.Unmarshal(b, &r); err != nil { - return nil, err - } - } - return &r, nil -} - -type CopyIsoResponse struct { - JobID string `json:"jobid,omitempty"` - Account string `json:"account,omitempty"` - Accountid string `json:"accountid,omitempty"` - Bootable bool `json:"bootable,omitempty"` - Checksum string `json:"checksum,omitempty"` - Created string `json:"created,omitempty"` - CrossZones bool `json:"crossZones,omitempty"` - Details map[string]string `json:"details,omitempty"` - Displaytext string `json:"displaytext,omitempty"` - Domain string `json:"domain,omitempty"` - Domainid string `json:"domainid,omitempty"` - Format string `json:"format,omitempty"` - Hostid string `json:"hostid,omitempty"` - Hostname string `json:"hostname,omitempty"` - Hypervisor string `json:"hypervisor,omitempty"` - Id string `json:"id,omitempty"` - Isdynamicallyscalable bool `json:"isdynamicallyscalable,omitempty"` - Isextractable bool `json:"isextractable,omitempty"` - Isfeatured bool `json:"isfeatured,omitempty"` - Ispublic bool `json:"ispublic,omitempty"` - Isready bool `json:"isready,omitempty"` - Name string `json:"name,omitempty"` - Ostypeid string `json:"ostypeid,omitempty"` - Ostypename string `json:"ostypename,omitempty"` - Passwordenabled bool `json:"passwordenabled,omitempty"` - Project string `json:"project,omitempty"` - Projectid string `json:"projectid,omitempty"` - Removed string `json:"removed,omitempty"` - Size int64 `json:"size,omitempty"` - Sourcetemplateid string `json:"sourcetemplateid,omitempty"` - Sshkeyenabled bool `json:"sshkeyenabled,omitempty"` - Status string `json:"status,omitempty"` - Tags []struct { - Account string `json:"account,omitempty"` - Customer string `json:"customer,omitempty"` - Domain string `json:"domain,omitempty"` - Domainid string `json:"domainid,omitempty"` - Key string `json:"key,omitempty"` - Project string `json:"project,omitempty"` - Projectid string `json:"projectid,omitempty"` - Resourceid string `json:"resourceid,omitempty"` - Resourcetype string `json:"resourcetype,omitempty"` - Value string `json:"value,omitempty"` - } `json:"tags,omitempty"` - Templatetag string `json:"templatetag,omitempty"` - Templatetype string `json:"templatetype,omitempty"` - Zoneid string `json:"zoneid,omitempty"` - Zonename string `json:"zonename,omitempty"` + Account string `json:"account"` + Accountid string `json:"accountid"` + Bits int `json:"bits"` + Bootable bool `json:"bootable"` + Checksum string `json:"checksum"` + Childtemplates []interface{} `json:"childtemplates"` + Created string `json:"created"` + CrossZones bool `json:"crossZones"` + Details map[string]string `json:"details"` + Directdownload bool `json:"directdownload"` + Displaytext string `json:"displaytext"` + Domain string `json:"domain"` + Domainid string `json:"domainid"` + Format string `json:"format"` + Hostid string `json:"hostid"` + Hostname string `json:"hostname"` + Hypervisor string `json:"hypervisor"` + Id string `json:"id"` + Isdynamicallyscalable bool `json:"isdynamicallyscalable"` + Isextractable bool `json:"isextractable"` + Isfeatured bool `json:"isfeatured"` + Ispublic bool `json:"ispublic"` + Isready bool `json:"isready"` + Name string `json:"name"` + Ostypeid string `json:"ostypeid"` + Ostypename string `json:"ostypename"` + Parenttemplateid string `json:"parenttemplateid"` + Passwordenabled bool `json:"passwordenabled"` + Physicalsize int64 `json:"physicalsize"` + Project string `json:"project"` + Projectid string `json:"projectid"` + Removed string `json:"removed"` + Size int64 `json:"size"` + Sourcetemplateid string `json:"sourcetemplateid"` + Sshkeyenabled bool `json:"sshkeyenabled"` + Status string `json:"status"` + Templatetag string `json:"templatetag"` + Templatetype string `json:"templatetype"` + Zoneid string `json:"zoneid"` + Zonename string `json:"zonename"` } type UpdateIsoPermissionsParams struct { @@ -1725,220 +1812,30 @@ func (s *ISOService) UpdateIsoPermissions(p *UpdateIsoPermissionsParams) (*Updat if err := json.Unmarshal(resp, &r); err != nil { return nil, err } + return &r, nil } type UpdateIsoPermissionsResponse struct { - Displaytext string `json:"displaytext,omitempty"` - Success string `json:"success,omitempty"` + Displaytext string `json:"displaytext"` + Success bool `json:"success"` } -type ListIsoPermissionsParams struct { - p map[string]interface{} -} - -func (p *ListIsoPermissionsParams) toURLValues() url.Values { - u := url.Values{} - if p.p == nil { - return u - } - if v, found := p.p["id"]; found { - u.Set("id", v.(string)) - } - return u -} - -func (p *ListIsoPermissionsParams) SetId(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["id"] = v - return -} - -// You should always use this function to get a new ListIsoPermissionsParams instance, -// as then you are sure you have configured all required params -func (s *ISOService) NewListIsoPermissionsParams(id string) *ListIsoPermissionsParams { - p := &ListIsoPermissionsParams{} - p.p = make(map[string]interface{}) - p.p["id"] = id - return p -} - -// This is a courtesy helper function, which in some cases may not work as expected! -func (s *ISOService) GetIsoPermissionByID(id string, opts ...OptionFunc) (*IsoPermission, int, error) { - p := &ListIsoPermissionsParams{} - p.p = make(map[string]interface{}) - - p.p["id"] = id - - for _, fn := range opts { - if err := fn(s.cs, p); err != nil { - return nil, -1, err - } - } - - l, err := s.ListIsoPermissions(p) +func (r *UpdateIsoPermissionsResponse) UnmarshalJSON(b []byte) error { + var m map[string]interface{} + err := json.Unmarshal(b, &m) if err != nil { - if strings.Contains(err.Error(), fmt.Sprintf( - "Invalid parameter id value=%s due to incorrect long value format, "+ - "or entity does not exist", id)) { - return nil, 0, fmt.Errorf("No match found for %s: %+v", id, l) - } - return nil, -1, err + return err } - if l.Count == 0 { - return nil, l.Count, fmt.Errorf("No match found for %s: %+v", id, l) - } - - if l.Count == 1 { - return l.IsoPermissions[0], l.Count, nil - } - return nil, l.Count, fmt.Errorf("There is more then one result for IsoPermission UUID: %s!", id) -} - -// List iso visibility and all accounts that have permissions to view this iso. -func (s *ISOService) ListIsoPermissions(p *ListIsoPermissionsParams) (*ListIsoPermissionsResponse, error) { - resp, err := s.cs.newRequest("listIsoPermissions", p.toURLValues()) - if err != nil { - return nil, err - } - - var r ListIsoPermissionsResponse - if err := json.Unmarshal(resp, &r); err != nil { - return nil, err - } - return &r, nil -} - -type ListIsoPermissionsResponse struct { - Count int `json:"count"` - IsoPermissions []*IsoPermission `json:"isopermission"` -} - -type IsoPermission struct { - Account []string `json:"account,omitempty"` - Domainid string `json:"domainid,omitempty"` - Id string `json:"id,omitempty"` - Ispublic bool `json:"ispublic,omitempty"` - Projectids []string `json:"projectids,omitempty"` -} - -type ExtractIsoParams struct { - p map[string]interface{} -} - -func (p *ExtractIsoParams) toURLValues() url.Values { - u := url.Values{} - if p.p == nil { - return u - } - if v, found := p.p["id"]; found { - u.Set("id", v.(string)) - } - if v, found := p.p["mode"]; found { - u.Set("mode", v.(string)) - } - if v, found := p.p["url"]; found { - u.Set("url", v.(string)) - } - if v, found := p.p["zoneid"]; found { - u.Set("zoneid", v.(string)) - } - return u -} - -func (p *ExtractIsoParams) SetId(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["id"] = v - return -} - -func (p *ExtractIsoParams) SetMode(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["mode"] = v - return -} - -func (p *ExtractIsoParams) SetUrl(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["url"] = v - return -} - -func (p *ExtractIsoParams) SetZoneid(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["zoneid"] = v - return -} - -// You should always use this function to get a new ExtractIsoParams instance, -// as then you are sure you have configured all required params -func (s *ISOService) NewExtractIsoParams(id string, mode string) *ExtractIsoParams { - p := &ExtractIsoParams{} - p.p = make(map[string]interface{}) - p.p["id"] = id - p.p["mode"] = mode - return p -} - -// Extracts an ISO -func (s *ISOService) ExtractIso(p *ExtractIsoParams) (*ExtractIsoResponse, error) { - resp, err := s.cs.newRequest("extractIso", p.toURLValues()) - if err != nil { - return nil, err - } - - var r ExtractIsoResponse - if err := json.Unmarshal(resp, &r); err != nil { - return nil, err - } - - // If we have a async client, we need to wait for the async result - if s.cs.async { - b, err := s.cs.GetAsyncJobResult(r.JobID, s.cs.timeout) + if success, ok := m["success"].(string); ok { + m["success"] = success == "true" + b, err = json.Marshal(m) if err != nil { - if err == AsyncTimeoutErr { - return &r, err - } - return nil, err - } - - b, err = getRawValue(b) - if err != nil { - return nil, err - } - - if err := json.Unmarshal(b, &r); err != nil { - return nil, err + return err } } - return &r, nil -} -type ExtractIsoResponse struct { - JobID string `json:"jobid,omitempty"` - Accountid string `json:"accountid,omitempty"` - Created string `json:"created,omitempty"` - ExtractId string `json:"extractId,omitempty"` - ExtractMode string `json:"extractMode,omitempty"` - Id string `json:"id,omitempty"` - Name string `json:"name,omitempty"` - Resultstring string `json:"resultstring,omitempty"` - State string `json:"state,omitempty"` - Status string `json:"status,omitempty"` - Storagetype string `json:"storagetype,omitempty"` - Uploadpercentage int `json:"uploadpercentage,omitempty"` - Url string `json:"url,omitempty"` - Zoneid string `json:"zoneid,omitempty"` - Zonename string `json:"zonename,omitempty"` + type alias UpdateIsoPermissionsResponse + return json.Unmarshal(b, (*alias)(r)) } diff --git a/vendor/github.com/xanzy/go-cloudstack/cloudstack/ImageStoreService.go b/vendor/github.com/xanzy/go-cloudstack/cloudstack/ImageStoreService.go index 58fce6e82..1f7b7fb76 100644 --- a/vendor/github.com/xanzy/go-cloudstack/cloudstack/ImageStoreService.go +++ b/vendor/github.com/xanzy/go-cloudstack/cloudstack/ImageStoreService.go @@ -1,5 +1,5 @@ // -// Copyright 2016, Sander van Harmelen +// Copyright 2018, Sander van Harmelen // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -36,8 +36,7 @@ func (p *AddImageStoreParams) toURLValues() url.Values { if v, found := p.p["details"]; found { i := 0 for k, vv := range v.(map[string]string) { - u.Set(fmt.Sprintf("details[%d].key", i), k) - u.Set(fmt.Sprintf("details[%d].value", i), vv) + u.Set(fmt.Sprintf("details[%d].%s", i, k), vv) i++ } } @@ -116,19 +115,19 @@ func (s *ImageStoreService) AddImageStore(p *AddImageStoreParams) (*AddImageStor if err := json.Unmarshal(resp, &r); err != nil { return nil, err } + return &r, nil } type AddImageStoreResponse struct { - Details []string `json:"details,omitempty"` - Id string `json:"id,omitempty"` - Name string `json:"name,omitempty"` - Protocol string `json:"protocol,omitempty"` - Providername string `json:"providername,omitempty"` - Scope string `json:"scope,omitempty"` - Url string `json:"url,omitempty"` - Zoneid string `json:"zoneid,omitempty"` - Zonename string `json:"zonename,omitempty"` + Id string `json:"id"` + Name string `json:"name"` + Protocol string `json:"protocol"` + Providername string `json:"providername"` + Scope string `json:"scope"` + Url string `json:"url"` + Zoneid string `json:"zoneid"` + Zonename string `json:"zonename"` } type AddImageStoreS3Params struct { @@ -293,19 +292,267 @@ func (s *ImageStoreService) AddImageStoreS3(p *AddImageStoreS3Params) (*AddImage if err := json.Unmarshal(resp, &r); err != nil { return nil, err } + return &r, nil } type AddImageStoreS3Response struct { - Details []string `json:"details,omitempty"` - Id string `json:"id,omitempty"` - Name string `json:"name,omitempty"` - Protocol string `json:"protocol,omitempty"` - Providername string `json:"providername,omitempty"` - Scope string `json:"scope,omitempty"` - Url string `json:"url,omitempty"` - Zoneid string `json:"zoneid,omitempty"` - Zonename string `json:"zonename,omitempty"` + Id string `json:"id"` + Name string `json:"name"` + Protocol string `json:"protocol"` + Providername string `json:"providername"` + Scope string `json:"scope"` + Url string `json:"url"` + Zoneid string `json:"zoneid"` + Zonename string `json:"zonename"` +} + +type CreateSecondaryStagingStoreParams struct { + p map[string]interface{} +} + +func (p *CreateSecondaryStagingStoreParams) toURLValues() url.Values { + u := url.Values{} + if p.p == nil { + return u + } + if v, found := p.p["details"]; found { + i := 0 + for k, vv := range v.(map[string]string) { + u.Set(fmt.Sprintf("details[%d].%s", i, k), vv) + i++ + } + } + if v, found := p.p["provider"]; found { + u.Set("provider", v.(string)) + } + if v, found := p.p["scope"]; found { + u.Set("scope", v.(string)) + } + if v, found := p.p["url"]; found { + u.Set("url", v.(string)) + } + if v, found := p.p["zoneid"]; found { + u.Set("zoneid", v.(string)) + } + return u +} + +func (p *CreateSecondaryStagingStoreParams) SetDetails(v map[string]string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["details"] = v + return +} + +func (p *CreateSecondaryStagingStoreParams) SetProvider(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["provider"] = v + return +} + +func (p *CreateSecondaryStagingStoreParams) SetScope(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["scope"] = v + return +} + +func (p *CreateSecondaryStagingStoreParams) SetUrl(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["url"] = v + return +} + +func (p *CreateSecondaryStagingStoreParams) SetZoneid(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["zoneid"] = v + return +} + +// You should always use this function to get a new CreateSecondaryStagingStoreParams instance, +// as then you are sure you have configured all required params +func (s *ImageStoreService) NewCreateSecondaryStagingStoreParams(url string) *CreateSecondaryStagingStoreParams { + p := &CreateSecondaryStagingStoreParams{} + p.p = make(map[string]interface{}) + p.p["url"] = url + return p +} + +// create secondary staging store. +func (s *ImageStoreService) CreateSecondaryStagingStore(p *CreateSecondaryStagingStoreParams) (*CreateSecondaryStagingStoreResponse, error) { + resp, err := s.cs.newRequest("createSecondaryStagingStore", p.toURLValues()) + if err != nil { + return nil, err + } + + var r CreateSecondaryStagingStoreResponse + if err := json.Unmarshal(resp, &r); err != nil { + return nil, err + } + + return &r, nil +} + +type CreateSecondaryStagingStoreResponse struct { + Id string `json:"id"` + Name string `json:"name"` + Protocol string `json:"protocol"` + Providername string `json:"providername"` + Scope string `json:"scope"` + Url string `json:"url"` + Zoneid string `json:"zoneid"` + Zonename string `json:"zonename"` +} + +type DeleteImageStoreParams struct { + p map[string]interface{} +} + +func (p *DeleteImageStoreParams) toURLValues() url.Values { + u := url.Values{} + if p.p == nil { + return u + } + if v, found := p.p["id"]; found { + u.Set("id", v.(string)) + } + return u +} + +func (p *DeleteImageStoreParams) SetId(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["id"] = v + return +} + +// You should always use this function to get a new DeleteImageStoreParams instance, +// as then you are sure you have configured all required params +func (s *ImageStoreService) NewDeleteImageStoreParams(id string) *DeleteImageStoreParams { + p := &DeleteImageStoreParams{} + p.p = make(map[string]interface{}) + p.p["id"] = id + return p +} + +// Deletes an image store or Secondary Storage. +func (s *ImageStoreService) DeleteImageStore(p *DeleteImageStoreParams) (*DeleteImageStoreResponse, error) { + resp, err := s.cs.newRequest("deleteImageStore", p.toURLValues()) + if err != nil { + return nil, err + } + + var r DeleteImageStoreResponse + if err := json.Unmarshal(resp, &r); err != nil { + return nil, err + } + + return &r, nil +} + +type DeleteImageStoreResponse struct { + Displaytext string `json:"displaytext"` + Success bool `json:"success"` +} + +func (r *DeleteImageStoreResponse) UnmarshalJSON(b []byte) error { + var m map[string]interface{} + err := json.Unmarshal(b, &m) + if err != nil { + return err + } + + if success, ok := m["success"].(string); ok { + m["success"] = success == "true" + b, err = json.Marshal(m) + if err != nil { + return err + } + } + + type alias DeleteImageStoreResponse + return json.Unmarshal(b, (*alias)(r)) +} + +type DeleteSecondaryStagingStoreParams struct { + p map[string]interface{} +} + +func (p *DeleteSecondaryStagingStoreParams) toURLValues() url.Values { + u := url.Values{} + if p.p == nil { + return u + } + if v, found := p.p["id"]; found { + u.Set("id", v.(string)) + } + return u +} + +func (p *DeleteSecondaryStagingStoreParams) SetId(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["id"] = v + return +} + +// You should always use this function to get a new DeleteSecondaryStagingStoreParams instance, +// as then you are sure you have configured all required params +func (s *ImageStoreService) NewDeleteSecondaryStagingStoreParams(id string) *DeleteSecondaryStagingStoreParams { + p := &DeleteSecondaryStagingStoreParams{} + p.p = make(map[string]interface{}) + p.p["id"] = id + return p +} + +// Deletes a secondary staging store . +func (s *ImageStoreService) DeleteSecondaryStagingStore(p *DeleteSecondaryStagingStoreParams) (*DeleteSecondaryStagingStoreResponse, error) { + resp, err := s.cs.newRequest("deleteSecondaryStagingStore", p.toURLValues()) + if err != nil { + return nil, err + } + + var r DeleteSecondaryStagingStoreResponse + if err := json.Unmarshal(resp, &r); err != nil { + return nil, err + } + + return &r, nil +} + +type DeleteSecondaryStagingStoreResponse struct { + Displaytext string `json:"displaytext"` + Success bool `json:"success"` +} + +func (r *DeleteSecondaryStagingStoreResponse) UnmarshalJSON(b []byte) error { + var m map[string]interface{} + err := json.Unmarshal(b, &m) + if err != nil { + return err + } + + if success, ok := m["success"].(string); ok { + m["success"] = success == "true" + b, err = json.Marshal(m) + if err != nil { + return err + } + } + + type alias DeleteSecondaryStagingStoreResponse + return json.Unmarshal(b, (*alias)(r)) } type ListImageStoresParams struct { @@ -425,7 +672,7 @@ func (s *ImageStoreService) GetImageStoreID(name string, opts ...OptionFunc) (st p.p["name"] = name - for _, fn := range opts { + for _, fn := range append(s.cs.options, opts...) { if err := fn(s.cs, p); err != nil { return "", -1, err } @@ -475,7 +722,7 @@ func (s *ImageStoreService) GetImageStoreByID(id string, opts ...OptionFunc) (*I p.p["id"] = id - for _, fn := range opts { + for _, fn := range append(s.cs.options, opts...) { if err := fn(s.cs, p); err != nil { return nil, -1, err } @@ -512,6 +759,7 @@ func (s *ImageStoreService) ListImageStores(p *ListImageStoresParams) (*ListImag if err := json.Unmarshal(resp, &r); err != nil { return nil, err } + return &r, nil } @@ -521,173 +769,14 @@ type ListImageStoresResponse struct { } type ImageStore struct { - Details []string `json:"details,omitempty"` - Id string `json:"id,omitempty"` - Name string `json:"name,omitempty"` - Protocol string `json:"protocol,omitempty"` - Providername string `json:"providername,omitempty"` - Scope string `json:"scope,omitempty"` - Url string `json:"url,omitempty"` - Zoneid string `json:"zoneid,omitempty"` - Zonename string `json:"zonename,omitempty"` -} - -type DeleteImageStoreParams struct { - p map[string]interface{} -} - -func (p *DeleteImageStoreParams) toURLValues() url.Values { - u := url.Values{} - if p.p == nil { - return u - } - if v, found := p.p["id"]; found { - u.Set("id", v.(string)) - } - return u -} - -func (p *DeleteImageStoreParams) SetId(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["id"] = v - return -} - -// You should always use this function to get a new DeleteImageStoreParams instance, -// as then you are sure you have configured all required params -func (s *ImageStoreService) NewDeleteImageStoreParams(id string) *DeleteImageStoreParams { - p := &DeleteImageStoreParams{} - p.p = make(map[string]interface{}) - p.p["id"] = id - return p -} - -// Deletes an image store or Secondary Storage. -func (s *ImageStoreService) DeleteImageStore(p *DeleteImageStoreParams) (*DeleteImageStoreResponse, error) { - resp, err := s.cs.newRequest("deleteImageStore", p.toURLValues()) - if err != nil { - return nil, err - } - - var r DeleteImageStoreResponse - if err := json.Unmarshal(resp, &r); err != nil { - return nil, err - } - return &r, nil -} - -type DeleteImageStoreResponse struct { - Displaytext string `json:"displaytext,omitempty"` - Success string `json:"success,omitempty"` -} - -type CreateSecondaryStagingStoreParams struct { - p map[string]interface{} -} - -func (p *CreateSecondaryStagingStoreParams) toURLValues() url.Values { - u := url.Values{} - if p.p == nil { - return u - } - if v, found := p.p["details"]; found { - i := 0 - for k, vv := range v.(map[string]string) { - u.Set(fmt.Sprintf("details[%d].key", i), k) - u.Set(fmt.Sprintf("details[%d].value", i), vv) - i++ - } - } - if v, found := p.p["provider"]; found { - u.Set("provider", v.(string)) - } - if v, found := p.p["scope"]; found { - u.Set("scope", v.(string)) - } - if v, found := p.p["url"]; found { - u.Set("url", v.(string)) - } - if v, found := p.p["zoneid"]; found { - u.Set("zoneid", v.(string)) - } - return u -} - -func (p *CreateSecondaryStagingStoreParams) SetDetails(v map[string]string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["details"] = v - return -} - -func (p *CreateSecondaryStagingStoreParams) SetProvider(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["provider"] = v - return -} - -func (p *CreateSecondaryStagingStoreParams) SetScope(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["scope"] = v - return -} - -func (p *CreateSecondaryStagingStoreParams) SetUrl(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["url"] = v - return -} - -func (p *CreateSecondaryStagingStoreParams) SetZoneid(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["zoneid"] = v - return -} - -// You should always use this function to get a new CreateSecondaryStagingStoreParams instance, -// as then you are sure you have configured all required params -func (s *ImageStoreService) NewCreateSecondaryStagingStoreParams(url string) *CreateSecondaryStagingStoreParams { - p := &CreateSecondaryStagingStoreParams{} - p.p = make(map[string]interface{}) - p.p["url"] = url - return p -} - -// create secondary staging store. -func (s *ImageStoreService) CreateSecondaryStagingStore(p *CreateSecondaryStagingStoreParams) (*CreateSecondaryStagingStoreResponse, error) { - resp, err := s.cs.newRequest("createSecondaryStagingStore", p.toURLValues()) - if err != nil { - return nil, err - } - - var r CreateSecondaryStagingStoreResponse - if err := json.Unmarshal(resp, &r); err != nil { - return nil, err - } - return &r, nil -} - -type CreateSecondaryStagingStoreResponse struct { - Details []string `json:"details,omitempty"` - Id string `json:"id,omitempty"` - Name string `json:"name,omitempty"` - Protocol string `json:"protocol,omitempty"` - Providername string `json:"providername,omitempty"` - Scope string `json:"scope,omitempty"` - Url string `json:"url,omitempty"` - Zoneid string `json:"zoneid,omitempty"` - Zonename string `json:"zonename,omitempty"` + Id string `json:"id"` + Name string `json:"name"` + Protocol string `json:"protocol"` + Providername string `json:"providername"` + Scope string `json:"scope"` + Url string `json:"url"` + Zoneid string `json:"zoneid"` + Zonename string `json:"zonename"` } type ListSecondaryStagingStoresParams struct { @@ -807,7 +896,7 @@ func (s *ImageStoreService) GetSecondaryStagingStoreID(name string, opts ...Opti p.p["name"] = name - for _, fn := range opts { + for _, fn := range append(s.cs.options, opts...) { if err := fn(s.cs, p); err != nil { return "", -1, err } @@ -857,7 +946,7 @@ func (s *ImageStoreService) GetSecondaryStagingStoreByID(id string, opts ...Opti p.p["id"] = id - for _, fn := range opts { + for _, fn := range append(s.cs.options, opts...) { if err := fn(s.cs, p); err != nil { return nil, -1, err } @@ -894,6 +983,7 @@ func (s *ImageStoreService) ListSecondaryStagingStores(p *ListSecondaryStagingSt if err := json.Unmarshal(resp, &r); err != nil { return nil, err } + return &r, nil } @@ -903,66 +993,14 @@ type ListSecondaryStagingStoresResponse struct { } type SecondaryStagingStore struct { - Details []string `json:"details,omitempty"` - Id string `json:"id,omitempty"` - Name string `json:"name,omitempty"` - Protocol string `json:"protocol,omitempty"` - Providername string `json:"providername,omitempty"` - Scope string `json:"scope,omitempty"` - Url string `json:"url,omitempty"` - Zoneid string `json:"zoneid,omitempty"` - Zonename string `json:"zonename,omitempty"` -} - -type DeleteSecondaryStagingStoreParams struct { - p map[string]interface{} -} - -func (p *DeleteSecondaryStagingStoreParams) toURLValues() url.Values { - u := url.Values{} - if p.p == nil { - return u - } - if v, found := p.p["id"]; found { - u.Set("id", v.(string)) - } - return u -} - -func (p *DeleteSecondaryStagingStoreParams) SetId(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["id"] = v - return -} - -// You should always use this function to get a new DeleteSecondaryStagingStoreParams instance, -// as then you are sure you have configured all required params -func (s *ImageStoreService) NewDeleteSecondaryStagingStoreParams(id string) *DeleteSecondaryStagingStoreParams { - p := &DeleteSecondaryStagingStoreParams{} - p.p = make(map[string]interface{}) - p.p["id"] = id - return p -} - -// Deletes a secondary staging store . -func (s *ImageStoreService) DeleteSecondaryStagingStore(p *DeleteSecondaryStagingStoreParams) (*DeleteSecondaryStagingStoreResponse, error) { - resp, err := s.cs.newRequest("deleteSecondaryStagingStore", p.toURLValues()) - if err != nil { - return nil, err - } - - var r DeleteSecondaryStagingStoreResponse - if err := json.Unmarshal(resp, &r); err != nil { - return nil, err - } - return &r, nil -} - -type DeleteSecondaryStagingStoreResponse struct { - Displaytext string `json:"displaytext,omitempty"` - Success string `json:"success,omitempty"` + Id string `json:"id"` + Name string `json:"name"` + Protocol string `json:"protocol"` + Providername string `json:"providername"` + Scope string `json:"scope"` + Url string `json:"url"` + Zoneid string `json:"zoneid"` + Zonename string `json:"zonename"` } type UpdateCloudToUseObjectStoreParams struct { @@ -977,8 +1015,7 @@ func (p *UpdateCloudToUseObjectStoreParams) toURLValues() url.Values { if v, found := p.p["details"]; found { i := 0 for k, vv := range v.(map[string]string) { - u.Set(fmt.Sprintf("details[%d].key", i), k) - u.Set(fmt.Sprintf("details[%d].value", i), vv) + u.Set(fmt.Sprintf("details[%d].%s", i, k), vv) i++ } } @@ -1046,17 +1083,17 @@ func (s *ImageStoreService) UpdateCloudToUseObjectStore(p *UpdateCloudToUseObjec if err := json.Unmarshal(resp, &r); err != nil { return nil, err } + return &r, nil } type UpdateCloudToUseObjectStoreResponse struct { - Details []string `json:"details,omitempty"` - Id string `json:"id,omitempty"` - Name string `json:"name,omitempty"` - Protocol string `json:"protocol,omitempty"` - Providername string `json:"providername,omitempty"` - Scope string `json:"scope,omitempty"` - Url string `json:"url,omitempty"` - Zoneid string `json:"zoneid,omitempty"` - Zonename string `json:"zonename,omitempty"` + Id string `json:"id"` + Name string `json:"name"` + Protocol string `json:"protocol"` + Providername string `json:"providername"` + Scope string `json:"scope"` + Url string `json:"url"` + Zoneid string `json:"zoneid"` + Zonename string `json:"zonename"` } diff --git a/vendor/github.com/xanzy/go-cloudstack/cloudstack/InternalLBService.go b/vendor/github.com/xanzy/go-cloudstack/cloudstack/InternalLBService.go index ba86b3ee3..64df1cd22 100644 --- a/vendor/github.com/xanzy/go-cloudstack/cloudstack/InternalLBService.go +++ b/vendor/github.com/xanzy/go-cloudstack/cloudstack/InternalLBService.go @@ -1,5 +1,5 @@ // -// Copyright 2016, Sander van Harmelen +// Copyright 2018, Sander van Harmelen // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -70,13 +70,13 @@ func (s *InternalLBService) NewConfigureInternalLoadBalancerElementParams(enable } // Configures an Internal Load Balancer element. -func (s *InternalLBService) ConfigureInternalLoadBalancerElement(p *ConfigureInternalLoadBalancerElementParams) (*ConfigureInternalLoadBalancerElementResponse, error) { +func (s *InternalLBService) ConfigureInternalLoadBalancerElement(p *ConfigureInternalLoadBalancerElementParams) (*InternalLoadBalancerElementResponse, error) { resp, err := s.cs.newRequest("configureInternalLoadBalancerElement", p.toURLValues()) if err != nil { return nil, err } - var r ConfigureInternalLoadBalancerElementResponse + var r InternalLoadBalancerElementResponse if err := json.Unmarshal(resp, &r); err != nil { return nil, err } @@ -100,14 +100,15 @@ func (s *InternalLBService) ConfigureInternalLoadBalancerElement(p *ConfigureInt return nil, err } } + return &r, nil } -type ConfigureInternalLoadBalancerElementResponse struct { - JobID string `json:"jobid,omitempty"` - Enabled bool `json:"enabled,omitempty"` - Id string `json:"id,omitempty"` - Nspid string `json:"nspid,omitempty"` +type InternalLoadBalancerElementResponse struct { + JobID string `json:"jobid"` + Enabled bool `json:"enabled"` + Id string `json:"id"` + Nspid string `json:"nspid"` } type CreateInternalLoadBalancerElementParams struct { @@ -173,14 +174,15 @@ func (s *InternalLBService) CreateInternalLoadBalancerElement(p *CreateInternalL return nil, err } } + return &r, nil } type CreateInternalLoadBalancerElementResponse struct { - JobID string `json:"jobid,omitempty"` - Enabled bool `json:"enabled,omitempty"` - Id string `json:"id,omitempty"` - Nspid string `json:"nspid,omitempty"` + JobID string `json:"jobid"` + Enabled bool `json:"enabled"` + Id string `json:"id"` + Nspid string `json:"nspid"` } type ListInternalLoadBalancerElementsParams struct { @@ -279,7 +281,7 @@ func (s *InternalLBService) GetInternalLoadBalancerElementByID(id string, opts . p.p["id"] = id - for _, fn := range opts { + for _, fn := range append(s.cs.options, opts...) { if err := fn(s.cs, p); err != nil { return nil, -1, err } @@ -316,6 +318,7 @@ func (s *InternalLBService) ListInternalLoadBalancerElements(p *ListInternalLoad if err := json.Unmarshal(resp, &r); err != nil { return nil, err } + return &r, nil } @@ -325,297 +328,9 @@ type ListInternalLoadBalancerElementsResponse struct { } type InternalLoadBalancerElement struct { - Enabled bool `json:"enabled,omitempty"` - Id string `json:"id,omitempty"` - Nspid string `json:"nspid,omitempty"` -} - -type StopInternalLoadBalancerVMParams struct { - p map[string]interface{} -} - -func (p *StopInternalLoadBalancerVMParams) toURLValues() url.Values { - u := url.Values{} - if p.p == nil { - return u - } - if v, found := p.p["forced"]; found { - vv := strconv.FormatBool(v.(bool)) - u.Set("forced", vv) - } - if v, found := p.p["id"]; found { - u.Set("id", v.(string)) - } - return u -} - -func (p *StopInternalLoadBalancerVMParams) SetForced(v bool) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["forced"] = v - return -} - -func (p *StopInternalLoadBalancerVMParams) SetId(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["id"] = v - return -} - -// You should always use this function to get a new StopInternalLoadBalancerVMParams instance, -// as then you are sure you have configured all required params -func (s *InternalLBService) NewStopInternalLoadBalancerVMParams(id string) *StopInternalLoadBalancerVMParams { - p := &StopInternalLoadBalancerVMParams{} - p.p = make(map[string]interface{}) - p.p["id"] = id - return p -} - -// Stops an Internal LB vm. -func (s *InternalLBService) StopInternalLoadBalancerVM(p *StopInternalLoadBalancerVMParams) (*StopInternalLoadBalancerVMResponse, error) { - resp, err := s.cs.newRequest("stopInternalLoadBalancerVM", p.toURLValues()) - if err != nil { - return nil, err - } - - var r StopInternalLoadBalancerVMResponse - if err := json.Unmarshal(resp, &r); err != nil { - return nil, err - } - - // If we have a async client, we need to wait for the async result - if s.cs.async { - b, err := s.cs.GetAsyncJobResult(r.JobID, s.cs.timeout) - if err != nil { - if err == AsyncTimeoutErr { - return &r, err - } - return nil, err - } - - b, err = getRawValue(b) - if err != nil { - return nil, err - } - - if err := json.Unmarshal(b, &r); err != nil { - return nil, err - } - } - return &r, nil -} - -type StopInternalLoadBalancerVMResponse struct { - JobID string `json:"jobid,omitempty"` - Account string `json:"account,omitempty"` - Created string `json:"created,omitempty"` - Dns1 string `json:"dns1,omitempty"` - Dns2 string `json:"dns2,omitempty"` - Domain string `json:"domain,omitempty"` - Domainid string `json:"domainid,omitempty"` - Gateway string `json:"gateway,omitempty"` - Guestipaddress string `json:"guestipaddress,omitempty"` - Guestmacaddress string `json:"guestmacaddress,omitempty"` - Guestnetmask string `json:"guestnetmask,omitempty"` - Guestnetworkid string `json:"guestnetworkid,omitempty"` - Guestnetworkname string `json:"guestnetworkname,omitempty"` - Hostid string `json:"hostid,omitempty"` - Hostname string `json:"hostname,omitempty"` - Hypervisor string `json:"hypervisor,omitempty"` - Id string `json:"id,omitempty"` - Ip6dns1 string `json:"ip6dns1,omitempty"` - Ip6dns2 string `json:"ip6dns2,omitempty"` - Isredundantrouter bool `json:"isredundantrouter,omitempty"` - Linklocalip string `json:"linklocalip,omitempty"` - Linklocalmacaddress string `json:"linklocalmacaddress,omitempty"` - Linklocalnetmask string `json:"linklocalnetmask,omitempty"` - Linklocalnetworkid string `json:"linklocalnetworkid,omitempty"` - Name string `json:"name,omitempty"` - Networkdomain string `json:"networkdomain,omitempty"` - Nic []struct { - Broadcasturi string `json:"broadcasturi,omitempty"` - Deviceid string `json:"deviceid,omitempty"` - Gateway string `json:"gateway,omitempty"` - Id string `json:"id,omitempty"` - Ip6address string `json:"ip6address,omitempty"` - Ip6cidr string `json:"ip6cidr,omitempty"` - Ip6gateway string `json:"ip6gateway,omitempty"` - Ipaddress string `json:"ipaddress,omitempty"` - Isdefault bool `json:"isdefault,omitempty"` - Isolationuri string `json:"isolationuri,omitempty"` - Macaddress string `json:"macaddress,omitempty"` - Netmask string `json:"netmask,omitempty"` - Networkid string `json:"networkid,omitempty"` - Networkname string `json:"networkname,omitempty"` - Secondaryip []struct { - Id string `json:"id,omitempty"` - Ipaddress string `json:"ipaddress,omitempty"` - } `json:"secondaryip,omitempty"` - Traffictype string `json:"traffictype,omitempty"` - Type string `json:"type,omitempty"` - Virtualmachineid string `json:"virtualmachineid,omitempty"` - } `json:"nic,omitempty"` - Podid string `json:"podid,omitempty"` - Project string `json:"project,omitempty"` - Projectid string `json:"projectid,omitempty"` - Publicip string `json:"publicip,omitempty"` - Publicmacaddress string `json:"publicmacaddress,omitempty"` - Publicnetmask string `json:"publicnetmask,omitempty"` - Publicnetworkid string `json:"publicnetworkid,omitempty"` - Redundantstate string `json:"redundantstate,omitempty"` - Requiresupgrade bool `json:"requiresupgrade,omitempty"` - Role string `json:"role,omitempty"` - Scriptsversion string `json:"scriptsversion,omitempty"` - Serviceofferingid string `json:"serviceofferingid,omitempty"` - Serviceofferingname string `json:"serviceofferingname,omitempty"` - State string `json:"state,omitempty"` - Templateid string `json:"templateid,omitempty"` - Version string `json:"version,omitempty"` - Vpcid string `json:"vpcid,omitempty"` - Vpcname string `json:"vpcname,omitempty"` - Zoneid string `json:"zoneid,omitempty"` - Zonename string `json:"zonename,omitempty"` -} - -type StartInternalLoadBalancerVMParams struct { - p map[string]interface{} -} - -func (p *StartInternalLoadBalancerVMParams) toURLValues() url.Values { - u := url.Values{} - if p.p == nil { - return u - } - if v, found := p.p["id"]; found { - u.Set("id", v.(string)) - } - return u -} - -func (p *StartInternalLoadBalancerVMParams) SetId(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["id"] = v - return -} - -// You should always use this function to get a new StartInternalLoadBalancerVMParams instance, -// as then you are sure you have configured all required params -func (s *InternalLBService) NewStartInternalLoadBalancerVMParams(id string) *StartInternalLoadBalancerVMParams { - p := &StartInternalLoadBalancerVMParams{} - p.p = make(map[string]interface{}) - p.p["id"] = id - return p -} - -// Starts an existing internal lb vm. -func (s *InternalLBService) StartInternalLoadBalancerVM(p *StartInternalLoadBalancerVMParams) (*StartInternalLoadBalancerVMResponse, error) { - resp, err := s.cs.newRequest("startInternalLoadBalancerVM", p.toURLValues()) - if err != nil { - return nil, err - } - - var r StartInternalLoadBalancerVMResponse - if err := json.Unmarshal(resp, &r); err != nil { - return nil, err - } - - // If we have a async client, we need to wait for the async result - if s.cs.async { - b, err := s.cs.GetAsyncJobResult(r.JobID, s.cs.timeout) - if err != nil { - if err == AsyncTimeoutErr { - return &r, err - } - return nil, err - } - - b, err = getRawValue(b) - if err != nil { - return nil, err - } - - if err := json.Unmarshal(b, &r); err != nil { - return nil, err - } - } - return &r, nil -} - -type StartInternalLoadBalancerVMResponse struct { - JobID string `json:"jobid,omitempty"` - Account string `json:"account,omitempty"` - Created string `json:"created,omitempty"` - Dns1 string `json:"dns1,omitempty"` - Dns2 string `json:"dns2,omitempty"` - Domain string `json:"domain,omitempty"` - Domainid string `json:"domainid,omitempty"` - Gateway string `json:"gateway,omitempty"` - Guestipaddress string `json:"guestipaddress,omitempty"` - Guestmacaddress string `json:"guestmacaddress,omitempty"` - Guestnetmask string `json:"guestnetmask,omitempty"` - Guestnetworkid string `json:"guestnetworkid,omitempty"` - Guestnetworkname string `json:"guestnetworkname,omitempty"` - Hostid string `json:"hostid,omitempty"` - Hostname string `json:"hostname,omitempty"` - Hypervisor string `json:"hypervisor,omitempty"` - Id string `json:"id,omitempty"` - Ip6dns1 string `json:"ip6dns1,omitempty"` - Ip6dns2 string `json:"ip6dns2,omitempty"` - Isredundantrouter bool `json:"isredundantrouter,omitempty"` - Linklocalip string `json:"linklocalip,omitempty"` - Linklocalmacaddress string `json:"linklocalmacaddress,omitempty"` - Linklocalnetmask string `json:"linklocalnetmask,omitempty"` - Linklocalnetworkid string `json:"linklocalnetworkid,omitempty"` - Name string `json:"name,omitempty"` - Networkdomain string `json:"networkdomain,omitempty"` - Nic []struct { - Broadcasturi string `json:"broadcasturi,omitempty"` - Deviceid string `json:"deviceid,omitempty"` - Gateway string `json:"gateway,omitempty"` - Id string `json:"id,omitempty"` - Ip6address string `json:"ip6address,omitempty"` - Ip6cidr string `json:"ip6cidr,omitempty"` - Ip6gateway string `json:"ip6gateway,omitempty"` - Ipaddress string `json:"ipaddress,omitempty"` - Isdefault bool `json:"isdefault,omitempty"` - Isolationuri string `json:"isolationuri,omitempty"` - Macaddress string `json:"macaddress,omitempty"` - Netmask string `json:"netmask,omitempty"` - Networkid string `json:"networkid,omitempty"` - Networkname string `json:"networkname,omitempty"` - Secondaryip []struct { - Id string `json:"id,omitempty"` - Ipaddress string `json:"ipaddress,omitempty"` - } `json:"secondaryip,omitempty"` - Traffictype string `json:"traffictype,omitempty"` - Type string `json:"type,omitempty"` - Virtualmachineid string `json:"virtualmachineid,omitempty"` - } `json:"nic,omitempty"` - Podid string `json:"podid,omitempty"` - Project string `json:"project,omitempty"` - Projectid string `json:"projectid,omitempty"` - Publicip string `json:"publicip,omitempty"` - Publicmacaddress string `json:"publicmacaddress,omitempty"` - Publicnetmask string `json:"publicnetmask,omitempty"` - Publicnetworkid string `json:"publicnetworkid,omitempty"` - Redundantstate string `json:"redundantstate,omitempty"` - Requiresupgrade bool `json:"requiresupgrade,omitempty"` - Role string `json:"role,omitempty"` - Scriptsversion string `json:"scriptsversion,omitempty"` - Serviceofferingid string `json:"serviceofferingid,omitempty"` - Serviceofferingname string `json:"serviceofferingname,omitempty"` - State string `json:"state,omitempty"` - Templateid string `json:"templateid,omitempty"` - Version string `json:"version,omitempty"` - Vpcid string `json:"vpcid,omitempty"` - Vpcname string `json:"vpcname,omitempty"` - Zoneid string `json:"zoneid,omitempty"` - Zonename string `json:"zonename,omitempty"` + Enabled bool `json:"enabled"` + Id string `json:"id"` + Nspid string `json:"nspid"` } type ListInternalLoadBalancerVMsParams struct { @@ -837,7 +552,7 @@ func (s *InternalLBService) GetInternalLoadBalancerVMID(name string, opts ...Opt p.p["name"] = name - for _, fn := range opts { + for _, fn := range append(s.cs.options, opts...) { if err := fn(s.cs, p); err != nil { return "", -1, err } @@ -887,7 +602,7 @@ func (s *InternalLBService) GetInternalLoadBalancerVMByID(id string, opts ...Opt p.p["id"] = id - for _, fn := range opts { + for _, fn := range append(s.cs.options, opts...) { if err := fn(s.cs, p); err != nil { return nil, -1, err } @@ -924,6 +639,7 @@ func (s *InternalLBService) ListInternalLoadBalancerVMs(p *ListInternalLoadBalan if err := json.Unmarshal(resp, &r); err != nil { return nil, err } + return &r, nil } @@ -933,72 +649,296 @@ type ListInternalLoadBalancerVMsResponse struct { } type InternalLoadBalancerVM struct { - Account string `json:"account,omitempty"` - Created string `json:"created,omitempty"` - Dns1 string `json:"dns1,omitempty"` - Dns2 string `json:"dns2,omitempty"` - Domain string `json:"domain,omitempty"` - Domainid string `json:"domainid,omitempty"` - Gateway string `json:"gateway,omitempty"` - Guestipaddress string `json:"guestipaddress,omitempty"` - Guestmacaddress string `json:"guestmacaddress,omitempty"` - Guestnetmask string `json:"guestnetmask,omitempty"` - Guestnetworkid string `json:"guestnetworkid,omitempty"` - Guestnetworkname string `json:"guestnetworkname,omitempty"` - Hostid string `json:"hostid,omitempty"` - Hostname string `json:"hostname,omitempty"` - Hypervisor string `json:"hypervisor,omitempty"` - Id string `json:"id,omitempty"` - Ip6dns1 string `json:"ip6dns1,omitempty"` - Ip6dns2 string `json:"ip6dns2,omitempty"` - Isredundantrouter bool `json:"isredundantrouter,omitempty"` - Linklocalip string `json:"linklocalip,omitempty"` - Linklocalmacaddress string `json:"linklocalmacaddress,omitempty"` - Linklocalnetmask string `json:"linklocalnetmask,omitempty"` - Linklocalnetworkid string `json:"linklocalnetworkid,omitempty"` - Name string `json:"name,omitempty"` - Networkdomain string `json:"networkdomain,omitempty"` - Nic []struct { - Broadcasturi string `json:"broadcasturi,omitempty"` - Deviceid string `json:"deviceid,omitempty"` - Gateway string `json:"gateway,omitempty"` - Id string `json:"id,omitempty"` - Ip6address string `json:"ip6address,omitempty"` - Ip6cidr string `json:"ip6cidr,omitempty"` - Ip6gateway string `json:"ip6gateway,omitempty"` - Ipaddress string `json:"ipaddress,omitempty"` - Isdefault bool `json:"isdefault,omitempty"` - Isolationuri string `json:"isolationuri,omitempty"` - Macaddress string `json:"macaddress,omitempty"` - Netmask string `json:"netmask,omitempty"` - Networkid string `json:"networkid,omitempty"` - Networkname string `json:"networkname,omitempty"` - Secondaryip []struct { - Id string `json:"id,omitempty"` - Ipaddress string `json:"ipaddress,omitempty"` - } `json:"secondaryip,omitempty"` - Traffictype string `json:"traffictype,omitempty"` - Type string `json:"type,omitempty"` - Virtualmachineid string `json:"virtualmachineid,omitempty"` - } `json:"nic,omitempty"` - Podid string `json:"podid,omitempty"` - Project string `json:"project,omitempty"` - Projectid string `json:"projectid,omitempty"` - Publicip string `json:"publicip,omitempty"` - Publicmacaddress string `json:"publicmacaddress,omitempty"` - Publicnetmask string `json:"publicnetmask,omitempty"` - Publicnetworkid string `json:"publicnetworkid,omitempty"` - Redundantstate string `json:"redundantstate,omitempty"` - Requiresupgrade bool `json:"requiresupgrade,omitempty"` - Role string `json:"role,omitempty"` - Scriptsversion string `json:"scriptsversion,omitempty"` - Serviceofferingid string `json:"serviceofferingid,omitempty"` - Serviceofferingname string `json:"serviceofferingname,omitempty"` - State string `json:"state,omitempty"` - Templateid string `json:"templateid,omitempty"` - Version string `json:"version,omitempty"` - Vpcid string `json:"vpcid,omitempty"` - Vpcname string `json:"vpcname,omitempty"` - Zoneid string `json:"zoneid,omitempty"` - Zonename string `json:"zonename,omitempty"` + Account string `json:"account"` + Created string `json:"created"` + Dns1 string `json:"dns1"` + Dns2 string `json:"dns2"` + Domain string `json:"domain"` + Domainid string `json:"domainid"` + Gateway string `json:"gateway"` + Guestipaddress string `json:"guestipaddress"` + Guestmacaddress string `json:"guestmacaddress"` + Guestnetmask string `json:"guestnetmask"` + Guestnetworkid string `json:"guestnetworkid"` + Guestnetworkname string `json:"guestnetworkname"` + Hostid string `json:"hostid"` + Hostname string `json:"hostname"` + Hypervisor string `json:"hypervisor"` + Id string `json:"id"` + Ip6dns1 string `json:"ip6dns1"` + Ip6dns2 string `json:"ip6dns2"` + Isredundantrouter bool `json:"isredundantrouter"` + Linklocalip string `json:"linklocalip"` + Linklocalmacaddress string `json:"linklocalmacaddress"` + Linklocalnetmask string `json:"linklocalnetmask"` + Linklocalnetworkid string `json:"linklocalnetworkid"` + Name string `json:"name"` + Networkdomain string `json:"networkdomain"` + Nic []Nic `json:"nic"` + Podid string `json:"podid"` + Project string `json:"project"` + Projectid string `json:"projectid"` + Publicip string `json:"publicip"` + Publicmacaddress string `json:"publicmacaddress"` + Publicnetmask string `json:"publicnetmask"` + Publicnetworkid string `json:"publicnetworkid"` + Redundantstate string `json:"redundantstate"` + Requiresupgrade bool `json:"requiresupgrade"` + Role string `json:"role"` + Scriptsversion string `json:"scriptsversion"` + Serviceofferingid string `json:"serviceofferingid"` + Serviceofferingname string `json:"serviceofferingname"` + State string `json:"state"` + Templateid string `json:"templateid"` + Version string `json:"version"` + Vpcid string `json:"vpcid"` + Vpcname string `json:"vpcname"` + Zoneid string `json:"zoneid"` + Zonename string `json:"zonename"` +} + +type StartInternalLoadBalancerVMParams struct { + p map[string]interface{} +} + +func (p *StartInternalLoadBalancerVMParams) toURLValues() url.Values { + u := url.Values{} + if p.p == nil { + return u + } + if v, found := p.p["id"]; found { + u.Set("id", v.(string)) + } + return u +} + +func (p *StartInternalLoadBalancerVMParams) SetId(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["id"] = v + return +} + +// You should always use this function to get a new StartInternalLoadBalancerVMParams instance, +// as then you are sure you have configured all required params +func (s *InternalLBService) NewStartInternalLoadBalancerVMParams(id string) *StartInternalLoadBalancerVMParams { + p := &StartInternalLoadBalancerVMParams{} + p.p = make(map[string]interface{}) + p.p["id"] = id + return p +} + +// Starts an existing internal lb vm. +func (s *InternalLBService) StartInternalLoadBalancerVM(p *StartInternalLoadBalancerVMParams) (*StartInternalLoadBalancerVMResponse, error) { + resp, err := s.cs.newRequest("startInternalLoadBalancerVM", p.toURLValues()) + if err != nil { + return nil, err + } + + var r StartInternalLoadBalancerVMResponse + if err := json.Unmarshal(resp, &r); err != nil { + return nil, err + } + + // If we have a async client, we need to wait for the async result + if s.cs.async { + b, err := s.cs.GetAsyncJobResult(r.JobID, s.cs.timeout) + if err != nil { + if err == AsyncTimeoutErr { + return &r, err + } + return nil, err + } + + b, err = getRawValue(b) + if err != nil { + return nil, err + } + + if err := json.Unmarshal(b, &r); err != nil { + return nil, err + } + } + + return &r, nil +} + +type StartInternalLoadBalancerVMResponse struct { + JobID string `json:"jobid"` + Account string `json:"account"` + Created string `json:"created"` + Dns1 string `json:"dns1"` + Dns2 string `json:"dns2"` + Domain string `json:"domain"` + Domainid string `json:"domainid"` + Gateway string `json:"gateway"` + Guestipaddress string `json:"guestipaddress"` + Guestmacaddress string `json:"guestmacaddress"` + Guestnetmask string `json:"guestnetmask"` + Guestnetworkid string `json:"guestnetworkid"` + Guestnetworkname string `json:"guestnetworkname"` + Hostid string `json:"hostid"` + Hostname string `json:"hostname"` + Hypervisor string `json:"hypervisor"` + Id string `json:"id"` + Ip6dns1 string `json:"ip6dns1"` + Ip6dns2 string `json:"ip6dns2"` + Isredundantrouter bool `json:"isredundantrouter"` + Linklocalip string `json:"linklocalip"` + Linklocalmacaddress string `json:"linklocalmacaddress"` + Linklocalnetmask string `json:"linklocalnetmask"` + Linklocalnetworkid string `json:"linklocalnetworkid"` + Name string `json:"name"` + Networkdomain string `json:"networkdomain"` + Nic []Nic `json:"nic"` + Podid string `json:"podid"` + Project string `json:"project"` + Projectid string `json:"projectid"` + Publicip string `json:"publicip"` + Publicmacaddress string `json:"publicmacaddress"` + Publicnetmask string `json:"publicnetmask"` + Publicnetworkid string `json:"publicnetworkid"` + Redundantstate string `json:"redundantstate"` + Requiresupgrade bool `json:"requiresupgrade"` + Role string `json:"role"` + Scriptsversion string `json:"scriptsversion"` + Serviceofferingid string `json:"serviceofferingid"` + Serviceofferingname string `json:"serviceofferingname"` + State string `json:"state"` + Templateid string `json:"templateid"` + Version string `json:"version"` + Vpcid string `json:"vpcid"` + Vpcname string `json:"vpcname"` + Zoneid string `json:"zoneid"` + Zonename string `json:"zonename"` +} + +type StopInternalLoadBalancerVMParams struct { + p map[string]interface{} +} + +func (p *StopInternalLoadBalancerVMParams) toURLValues() url.Values { + u := url.Values{} + if p.p == nil { + return u + } + if v, found := p.p["forced"]; found { + vv := strconv.FormatBool(v.(bool)) + u.Set("forced", vv) + } + if v, found := p.p["id"]; found { + u.Set("id", v.(string)) + } + return u +} + +func (p *StopInternalLoadBalancerVMParams) SetForced(v bool) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["forced"] = v + return +} + +func (p *StopInternalLoadBalancerVMParams) SetId(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["id"] = v + return +} + +// You should always use this function to get a new StopInternalLoadBalancerVMParams instance, +// as then you are sure you have configured all required params +func (s *InternalLBService) NewStopInternalLoadBalancerVMParams(id string) *StopInternalLoadBalancerVMParams { + p := &StopInternalLoadBalancerVMParams{} + p.p = make(map[string]interface{}) + p.p["id"] = id + return p +} + +// Stops an Internal LB vm. +func (s *InternalLBService) StopInternalLoadBalancerVM(p *StopInternalLoadBalancerVMParams) (*StopInternalLoadBalancerVMResponse, error) { + resp, err := s.cs.newRequest("stopInternalLoadBalancerVM", p.toURLValues()) + if err != nil { + return nil, err + } + + var r StopInternalLoadBalancerVMResponse + if err := json.Unmarshal(resp, &r); err != nil { + return nil, err + } + + // If we have a async client, we need to wait for the async result + if s.cs.async { + b, err := s.cs.GetAsyncJobResult(r.JobID, s.cs.timeout) + if err != nil { + if err == AsyncTimeoutErr { + return &r, err + } + return nil, err + } + + b, err = getRawValue(b) + if err != nil { + return nil, err + } + + if err := json.Unmarshal(b, &r); err != nil { + return nil, err + } + } + + return &r, nil +} + +type StopInternalLoadBalancerVMResponse struct { + JobID string `json:"jobid"` + Account string `json:"account"` + Created string `json:"created"` + Dns1 string `json:"dns1"` + Dns2 string `json:"dns2"` + Domain string `json:"domain"` + Domainid string `json:"domainid"` + Gateway string `json:"gateway"` + Guestipaddress string `json:"guestipaddress"` + Guestmacaddress string `json:"guestmacaddress"` + Guestnetmask string `json:"guestnetmask"` + Guestnetworkid string `json:"guestnetworkid"` + Guestnetworkname string `json:"guestnetworkname"` + Hostid string `json:"hostid"` + Hostname string `json:"hostname"` + Hypervisor string `json:"hypervisor"` + Id string `json:"id"` + Ip6dns1 string `json:"ip6dns1"` + Ip6dns2 string `json:"ip6dns2"` + Isredundantrouter bool `json:"isredundantrouter"` + Linklocalip string `json:"linklocalip"` + Linklocalmacaddress string `json:"linklocalmacaddress"` + Linklocalnetmask string `json:"linklocalnetmask"` + Linklocalnetworkid string `json:"linklocalnetworkid"` + Name string `json:"name"` + Networkdomain string `json:"networkdomain"` + Nic []Nic `json:"nic"` + Podid string `json:"podid"` + Project string `json:"project"` + Projectid string `json:"projectid"` + Publicip string `json:"publicip"` + Publicmacaddress string `json:"publicmacaddress"` + Publicnetmask string `json:"publicnetmask"` + Publicnetworkid string `json:"publicnetworkid"` + Redundantstate string `json:"redundantstate"` + Requiresupgrade bool `json:"requiresupgrade"` + Role string `json:"role"` + Scriptsversion string `json:"scriptsversion"` + Serviceofferingid string `json:"serviceofferingid"` + Serviceofferingname string `json:"serviceofferingname"` + State string `json:"state"` + Templateid string `json:"templateid"` + Version string `json:"version"` + Vpcid string `json:"vpcid"` + Vpcname string `json:"vpcname"` + Zoneid string `json:"zoneid"` + Zonename string `json:"zonename"` } diff --git a/vendor/github.com/xanzy/go-cloudstack/cloudstack/LDAPService.go b/vendor/github.com/xanzy/go-cloudstack/cloudstack/LDAPService.go index 18935c294..baff7900d 100644 --- a/vendor/github.com/xanzy/go-cloudstack/cloudstack/LDAPService.go +++ b/vendor/github.com/xanzy/go-cloudstack/cloudstack/LDAPService.go @@ -1,5 +1,5 @@ // -// Copyright 2016, Sander van Harmelen +// Copyright 2018, Sander van Harmelen // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -23,6 +23,479 @@ import ( "strconv" ) +type AddLdapConfigurationParams struct { + p map[string]interface{} +} + +func (p *AddLdapConfigurationParams) toURLValues() url.Values { + u := url.Values{} + if p.p == nil { + return u + } + if v, found := p.p["domainid"]; found { + u.Set("domainid", v.(string)) + } + if v, found := p.p["hostname"]; found { + u.Set("hostname", v.(string)) + } + if v, found := p.p["port"]; found { + vv := strconv.Itoa(v.(int)) + u.Set("port", vv) + } + return u +} + +func (p *AddLdapConfigurationParams) SetDomainid(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["domainid"] = v + return +} + +func (p *AddLdapConfigurationParams) SetHostname(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["hostname"] = v + return +} + +func (p *AddLdapConfigurationParams) SetPort(v int) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["port"] = v + return +} + +// You should always use this function to get a new AddLdapConfigurationParams instance, +// as then you are sure you have configured all required params +func (s *LDAPService) NewAddLdapConfigurationParams(hostname string, port int) *AddLdapConfigurationParams { + p := &AddLdapConfigurationParams{} + p.p = make(map[string]interface{}) + p.p["hostname"] = hostname + p.p["port"] = port + return p +} + +// Add a new Ldap Configuration +func (s *LDAPService) AddLdapConfiguration(p *AddLdapConfigurationParams) (*AddLdapConfigurationResponse, error) { + resp, err := s.cs.newRequest("addLdapConfiguration", p.toURLValues()) + if err != nil { + return nil, err + } + + var r AddLdapConfigurationResponse + if err := json.Unmarshal(resp, &r); err != nil { + return nil, err + } + + return &r, nil +} + +type AddLdapConfigurationResponse struct { + Domainid string `json:"domainid"` + Hostname string `json:"hostname"` + Port int `json:"port"` +} + +type DeleteLdapConfigurationParams struct { + p map[string]interface{} +} + +func (p *DeleteLdapConfigurationParams) toURLValues() url.Values { + u := url.Values{} + if p.p == nil { + return u + } + if v, found := p.p["domainid"]; found { + u.Set("domainid", v.(string)) + } + if v, found := p.p["hostname"]; found { + u.Set("hostname", v.(string)) + } + if v, found := p.p["port"]; found { + vv := strconv.Itoa(v.(int)) + u.Set("port", vv) + } + return u +} + +func (p *DeleteLdapConfigurationParams) SetDomainid(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["domainid"] = v + return +} + +func (p *DeleteLdapConfigurationParams) SetHostname(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["hostname"] = v + return +} + +func (p *DeleteLdapConfigurationParams) SetPort(v int) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["port"] = v + return +} + +// You should always use this function to get a new DeleteLdapConfigurationParams instance, +// as then you are sure you have configured all required params +func (s *LDAPService) NewDeleteLdapConfigurationParams(hostname string) *DeleteLdapConfigurationParams { + p := &DeleteLdapConfigurationParams{} + p.p = make(map[string]interface{}) + p.p["hostname"] = hostname + return p +} + +// Remove an Ldap Configuration +func (s *LDAPService) DeleteLdapConfiguration(p *DeleteLdapConfigurationParams) (*DeleteLdapConfigurationResponse, error) { + resp, err := s.cs.newRequest("deleteLdapConfiguration", p.toURLValues()) + if err != nil { + return nil, err + } + + var r DeleteLdapConfigurationResponse + if err := json.Unmarshal(resp, &r); err != nil { + return nil, err + } + + return &r, nil +} + +type DeleteLdapConfigurationResponse struct { + Domainid string `json:"domainid"` + Hostname string `json:"hostname"` + Port int `json:"port"` +} + +type ImportLdapUsersParams struct { + p map[string]interface{} +} + +func (p *ImportLdapUsersParams) toURLValues() url.Values { + u := url.Values{} + if p.p == nil { + return u + } + if v, found := p.p["account"]; found { + u.Set("account", v.(string)) + } + if v, found := p.p["accountdetails"]; found { + i := 0 + for k, vv := range v.(map[string]string) { + u.Set(fmt.Sprintf("accountdetails[%d].key", i), k) + u.Set(fmt.Sprintf("accountdetails[%d].value", i), vv) + i++ + } + } + if v, found := p.p["accounttype"]; found { + vv := strconv.Itoa(v.(int)) + u.Set("accounttype", vv) + } + if v, found := p.p["domainid"]; found { + u.Set("domainid", v.(string)) + } + if v, found := p.p["group"]; found { + u.Set("group", v.(string)) + } + if v, found := p.p["keyword"]; found { + u.Set("keyword", v.(string)) + } + if v, found := p.p["page"]; found { + vv := strconv.Itoa(v.(int)) + u.Set("page", vv) + } + if v, found := p.p["pagesize"]; found { + vv := strconv.Itoa(v.(int)) + u.Set("pagesize", vv) + } + if v, found := p.p["roleid"]; found { + u.Set("roleid", v.(string)) + } + if v, found := p.p["timezone"]; found { + u.Set("timezone", v.(string)) + } + return u +} + +func (p *ImportLdapUsersParams) SetAccount(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["account"] = v + return +} + +func (p *ImportLdapUsersParams) SetAccountdetails(v map[string]string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["accountdetails"] = v + return +} + +func (p *ImportLdapUsersParams) SetAccounttype(v int) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["accounttype"] = v + return +} + +func (p *ImportLdapUsersParams) SetDomainid(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["domainid"] = v + return +} + +func (p *ImportLdapUsersParams) SetGroup(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["group"] = v + return +} + +func (p *ImportLdapUsersParams) SetKeyword(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["keyword"] = v + return +} + +func (p *ImportLdapUsersParams) SetPage(v int) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["page"] = v + return +} + +func (p *ImportLdapUsersParams) SetPagesize(v int) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["pagesize"] = v + return +} + +func (p *ImportLdapUsersParams) SetRoleid(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["roleid"] = v + return +} + +func (p *ImportLdapUsersParams) SetTimezone(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["timezone"] = v + return +} + +// You should always use this function to get a new ImportLdapUsersParams instance, +// as then you are sure you have configured all required params +func (s *LDAPService) NewImportLdapUsersParams() *ImportLdapUsersParams { + p := &ImportLdapUsersParams{} + p.p = make(map[string]interface{}) + return p +} + +// Import LDAP users +func (s *LDAPService) ImportLdapUsers(p *ImportLdapUsersParams) (*ImportLdapUsersResponse, error) { + resp, err := s.cs.newRequest("importLdapUsers", p.toURLValues()) + if err != nil { + return nil, err + } + + var r ImportLdapUsersResponse + if err := json.Unmarshal(resp, &r); err != nil { + return nil, err + } + + return &r, nil +} + +type ImportLdapUsersResponse struct { + Domain string `json:"domain"` + Email string `json:"email"` + Firstname string `json:"firstname"` + Lastname string `json:"lastname"` + Principal string `json:"principal"` + Username string `json:"username"` +} + +type LdapConfigParams struct { + p map[string]interface{} +} + +func (p *LdapConfigParams) toURLValues() url.Values { + u := url.Values{} + if p.p == nil { + return u + } + if v, found := p.p["binddn"]; found { + u.Set("binddn", v.(string)) + } + if v, found := p.p["bindpass"]; found { + u.Set("bindpass", v.(string)) + } + if v, found := p.p["hostname"]; found { + u.Set("hostname", v.(string)) + } + if v, found := p.p["listall"]; found { + vv := strconv.FormatBool(v.(bool)) + u.Set("listall", vv) + } + if v, found := p.p["port"]; found { + vv := strconv.Itoa(v.(int)) + u.Set("port", vv) + } + if v, found := p.p["queryfilter"]; found { + u.Set("queryfilter", v.(string)) + } + if v, found := p.p["searchbase"]; found { + u.Set("searchbase", v.(string)) + } + if v, found := p.p["ssl"]; found { + vv := strconv.FormatBool(v.(bool)) + u.Set("ssl", vv) + } + if v, found := p.p["truststore"]; found { + u.Set("truststore", v.(string)) + } + if v, found := p.p["truststorepass"]; found { + u.Set("truststorepass", v.(string)) + } + return u +} + +func (p *LdapConfigParams) SetBinddn(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["binddn"] = v + return +} + +func (p *LdapConfigParams) SetBindpass(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["bindpass"] = v + return +} + +func (p *LdapConfigParams) SetHostname(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["hostname"] = v + return +} + +func (p *LdapConfigParams) SetListall(v bool) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["listall"] = v + return +} + +func (p *LdapConfigParams) SetPort(v int) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["port"] = v + return +} + +func (p *LdapConfigParams) SetQueryfilter(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["queryfilter"] = v + return +} + +func (p *LdapConfigParams) SetSearchbase(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["searchbase"] = v + return +} + +func (p *LdapConfigParams) SetSsl(v bool) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["ssl"] = v + return +} + +func (p *LdapConfigParams) SetTruststore(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["truststore"] = v + return +} + +func (p *LdapConfigParams) SetTruststorepass(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["truststorepass"] = v + return +} + +// You should always use this function to get a new LdapConfigParams instance, +// as then you are sure you have configured all required params +func (s *LDAPService) NewLdapConfigParams() *LdapConfigParams { + p := &LdapConfigParams{} + p.p = make(map[string]interface{}) + return p +} + +// (Deprecated, use addLdapConfiguration) Configure the LDAP context for this site. +func (s *LDAPService) LdapConfig(p *LdapConfigParams) (*LdapConfigResponse, error) { + resp, err := s.cs.newRequest("ldapConfig", p.toURLValues()) + if err != nil { + return nil, err + } + + var r LdapConfigResponse + if err := json.Unmarshal(resp, &r); err != nil { + return nil, err + } + + return &r, nil +} + +type LdapConfigResponse struct { + Binddn string `json:"binddn"` + Bindpass string `json:"bindpass"` + Hostname string `json:"hostname"` + Port string `json:"port"` + Queryfilter string `json:"queryfilter"` + Searchbase string `json:"searchbase"` + Ssl string `json:"ssl"` +} + type LdapCreateAccountParams struct { p map[string]interface{} } @@ -56,6 +529,9 @@ func (p *LdapCreateAccountParams) toURLValues() url.Values { if v, found := p.p["networkdomain"]; found { u.Set("networkdomain", v.(string)) } + if v, found := p.p["roleid"]; found { + u.Set("roleid", v.(string)) + } if v, found := p.p["timezone"]; found { u.Set("timezone", v.(string)) } @@ -116,6 +592,14 @@ func (p *LdapCreateAccountParams) SetNetworkdomain(v string) { return } +func (p *LdapCreateAccountParams) SetRoleid(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["roleid"] = v + return +} + func (p *LdapCreateAccountParams) SetTimezone(v string) { if p.p == nil { p.p = make(map[string]interface{}) @@ -142,10 +626,9 @@ func (p *LdapCreateAccountParams) SetUsername(v string) { // You should always use this function to get a new LdapCreateAccountParams instance, // as then you are sure you have configured all required params -func (s *LDAPService) NewLdapCreateAccountParams(accounttype int, username string) *LdapCreateAccountParams { +func (s *LDAPService) NewLdapCreateAccountParams(username string) *LdapCreateAccountParams { p := &LdapCreateAccountParams{} p.p = make(map[string]interface{}) - p.p["accounttype"] = accounttype p.p["username"] = username return p } @@ -161,79 +644,549 @@ func (s *LDAPService) LdapCreateAccount(p *LdapCreateAccountParams) (*LdapCreate if err := json.Unmarshal(resp, &r); err != nil { return nil, err } + return &r, nil } type LdapCreateAccountResponse struct { - Accountdetails map[string]string `json:"accountdetails,omitempty"` - Accounttype int `json:"accounttype,omitempty"` - Cpuavailable string `json:"cpuavailable,omitempty"` - Cpulimit string `json:"cpulimit,omitempty"` - Cputotal int64 `json:"cputotal,omitempty"` - Defaultzoneid string `json:"defaultzoneid,omitempty"` - Domain string `json:"domain,omitempty"` - Domainid string `json:"domainid,omitempty"` - Groups []string `json:"groups,omitempty"` - Id string `json:"id,omitempty"` - Ipavailable string `json:"ipavailable,omitempty"` - Iplimit string `json:"iplimit,omitempty"` - Iptotal int64 `json:"iptotal,omitempty"` - Iscleanuprequired bool `json:"iscleanuprequired,omitempty"` - Isdefault bool `json:"isdefault,omitempty"` - Memoryavailable string `json:"memoryavailable,omitempty"` - Memorylimit string `json:"memorylimit,omitempty"` - Memorytotal int64 `json:"memorytotal,omitempty"` - Name string `json:"name,omitempty"` - Networkavailable string `json:"networkavailable,omitempty"` - Networkdomain string `json:"networkdomain,omitempty"` - Networklimit string `json:"networklimit,omitempty"` - Networktotal int64 `json:"networktotal,omitempty"` - Primarystorageavailable string `json:"primarystorageavailable,omitempty"` - Primarystoragelimit string `json:"primarystoragelimit,omitempty"` - Primarystoragetotal int64 `json:"primarystoragetotal,omitempty"` - Projectavailable string `json:"projectavailable,omitempty"` - Projectlimit string `json:"projectlimit,omitempty"` - Projecttotal int64 `json:"projecttotal,omitempty"` - Receivedbytes int64 `json:"receivedbytes,omitempty"` - Secondarystorageavailable string `json:"secondarystorageavailable,omitempty"` - Secondarystoragelimit string `json:"secondarystoragelimit,omitempty"` - Secondarystoragetotal int64 `json:"secondarystoragetotal,omitempty"` - Sentbytes int64 `json:"sentbytes,omitempty"` - Snapshotavailable string `json:"snapshotavailable,omitempty"` - Snapshotlimit string `json:"snapshotlimit,omitempty"` - Snapshottotal int64 `json:"snapshottotal,omitempty"` - State string `json:"state,omitempty"` - Templateavailable string `json:"templateavailable,omitempty"` - Templatelimit string `json:"templatelimit,omitempty"` - Templatetotal int64 `json:"templatetotal,omitempty"` - User []struct { - Account string `json:"account,omitempty"` - Accountid string `json:"accountid,omitempty"` - Accounttype int `json:"accounttype,omitempty"` - Apikey string `json:"apikey,omitempty"` - Created string `json:"created,omitempty"` - Domain string `json:"domain,omitempty"` - Domainid string `json:"domainid,omitempty"` - Email string `json:"email,omitempty"` - Firstname string `json:"firstname,omitempty"` - Id string `json:"id,omitempty"` - Iscallerchilddomain bool `json:"iscallerchilddomain,omitempty"` - Isdefault bool `json:"isdefault,omitempty"` - Lastname string `json:"lastname,omitempty"` - Secretkey string `json:"secretkey,omitempty"` - State string `json:"state,omitempty"` - Timezone string `json:"timezone,omitempty"` - Username string `json:"username,omitempty"` - } `json:"user,omitempty"` - Vmavailable string `json:"vmavailable,omitempty"` - Vmlimit string `json:"vmlimit,omitempty"` - Vmrunning int `json:"vmrunning,omitempty"` - Vmstopped int `json:"vmstopped,omitempty"` - Vmtotal int64 `json:"vmtotal,omitempty"` - Volumeavailable string `json:"volumeavailable,omitempty"` - Volumelimit string `json:"volumelimit,omitempty"` - Volumetotal int64 `json:"volumetotal,omitempty"` - Vpcavailable string `json:"vpcavailable,omitempty"` - Vpclimit string `json:"vpclimit,omitempty"` - Vpctotal int64 `json:"vpctotal,omitempty"` + Accountdetails map[string]string `json:"accountdetails"` + Accounttype int `json:"accounttype"` + Cpuavailable string `json:"cpuavailable"` + Cpulimit string `json:"cpulimit"` + Cputotal int64 `json:"cputotal"` + Defaultzoneid string `json:"defaultzoneid"` + Domain string `json:"domain"` + Domainid string `json:"domainid"` + Groups []string `json:"groups"` + Id string `json:"id"` + Ipavailable string `json:"ipavailable"` + Iplimit string `json:"iplimit"` + Iptotal int64 `json:"iptotal"` + Iscleanuprequired bool `json:"iscleanuprequired"` + Isdefault bool `json:"isdefault"` + Memoryavailable string `json:"memoryavailable"` + Memorylimit string `json:"memorylimit"` + Memorytotal int64 `json:"memorytotal"` + Name string `json:"name"` + Networkavailable string `json:"networkavailable"` + Networkdomain string `json:"networkdomain"` + Networklimit string `json:"networklimit"` + Networktotal int64 `json:"networktotal"` + Primarystorageavailable string `json:"primarystorageavailable"` + Primarystoragelimit string `json:"primarystoragelimit"` + Primarystoragetotal int64 `json:"primarystoragetotal"` + Projectavailable string `json:"projectavailable"` + Projectlimit string `json:"projectlimit"` + Projecttotal int64 `json:"projecttotal"` + Receivedbytes int64 `json:"receivedbytes"` + Roleid string `json:"roleid"` + Rolename string `json:"rolename"` + Roletype string `json:"roletype"` + Secondarystorageavailable string `json:"secondarystorageavailable"` + Secondarystoragelimit string `json:"secondarystoragelimit"` + Secondarystoragetotal float64 `json:"secondarystoragetotal"` + Sentbytes int64 `json:"sentbytes"` + Snapshotavailable string `json:"snapshotavailable"` + Snapshotlimit string `json:"snapshotlimit"` + Snapshottotal int64 `json:"snapshottotal"` + State string `json:"state"` + Templateavailable string `json:"templateavailable"` + Templatelimit string `json:"templatelimit"` + Templatetotal int64 `json:"templatetotal"` + User []LdapCreateAccountResponseUser `json:"user"` + Vmavailable string `json:"vmavailable"` + Vmlimit string `json:"vmlimit"` + Vmrunning int `json:"vmrunning"` + Vmstopped int `json:"vmstopped"` + Vmtotal int64 `json:"vmtotal"` + Volumeavailable string `json:"volumeavailable"` + Volumelimit string `json:"volumelimit"` + Volumetotal int64 `json:"volumetotal"` + Vpcavailable string `json:"vpcavailable"` + Vpclimit string `json:"vpclimit"` + Vpctotal int64 `json:"vpctotal"` +} + +type LdapCreateAccountResponseUser struct { + Account string `json:"account"` + Accountid string `json:"accountid"` + Accounttype int `json:"accounttype"` + Apikey string `json:"apikey"` + Created string `json:"created"` + Domain string `json:"domain"` + Domainid string `json:"domainid"` + Email string `json:"email"` + Firstname string `json:"firstname"` + Id string `json:"id"` + Iscallerchilddomain bool `json:"iscallerchilddomain"` + Isdefault bool `json:"isdefault"` + Lastname string `json:"lastname"` + Roleid string `json:"roleid"` + Rolename string `json:"rolename"` + Roletype string `json:"roletype"` + Secretkey string `json:"secretkey"` + State string `json:"state"` + Timezone string `json:"timezone"` + Username string `json:"username"` + Usersource string `json:"usersource"` +} + +type LdapRemoveParams struct { + p map[string]interface{} +} + +func (p *LdapRemoveParams) toURLValues() url.Values { + u := url.Values{} + if p.p == nil { + return u + } + return u +} + +// You should always use this function to get a new LdapRemoveParams instance, +// as then you are sure you have configured all required params +func (s *LDAPService) NewLdapRemoveParams() *LdapRemoveParams { + p := &LdapRemoveParams{} + p.p = make(map[string]interface{}) + return p +} + +// (Deprecated , use deleteLdapConfiguration) Remove the LDAP context for this site. +func (s *LDAPService) LdapRemove(p *LdapRemoveParams) (*LdapRemoveResponse, error) { + resp, err := s.cs.newRequest("ldapRemove", p.toURLValues()) + if err != nil { + return nil, err + } + + var r LdapRemoveResponse + if err := json.Unmarshal(resp, &r); err != nil { + return nil, err + } + + return &r, nil +} + +type LdapRemoveResponse struct { + Binddn string `json:"binddn"` + Bindpass string `json:"bindpass"` + Hostname string `json:"hostname"` + Port string `json:"port"` + Queryfilter string `json:"queryfilter"` + Searchbase string `json:"searchbase"` + Ssl string `json:"ssl"` +} + +type LinkDomainToLdapParams struct { + p map[string]interface{} +} + +func (p *LinkDomainToLdapParams) toURLValues() url.Values { + u := url.Values{} + if p.p == nil { + return u + } + if v, found := p.p["accounttype"]; found { + vv := strconv.Itoa(v.(int)) + u.Set("accounttype", vv) + } + if v, found := p.p["admin"]; found { + u.Set("admin", v.(string)) + } + if v, found := p.p["domainid"]; found { + u.Set("domainid", v.(string)) + } + if v, found := p.p["ldapdomain"]; found { + u.Set("ldapdomain", v.(string)) + } + if v, found := p.p["name"]; found { + u.Set("name", v.(string)) + } + if v, found := p.p["type"]; found { + u.Set("type", v.(string)) + } + return u +} + +func (p *LinkDomainToLdapParams) SetAccounttype(v int) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["accounttype"] = v + return +} + +func (p *LinkDomainToLdapParams) SetAdmin(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["admin"] = v + return +} + +func (p *LinkDomainToLdapParams) SetDomainid(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["domainid"] = v + return +} + +func (p *LinkDomainToLdapParams) SetLdapdomain(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["ldapdomain"] = v + return +} + +func (p *LinkDomainToLdapParams) SetName(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["name"] = v + return +} + +func (p *LinkDomainToLdapParams) SetType(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["type"] = v + return +} + +// You should always use this function to get a new LinkDomainToLdapParams instance, +// as then you are sure you have configured all required params +func (s *LDAPService) NewLinkDomainToLdapParams(accounttype int, domainid string, lDAPType string) *LinkDomainToLdapParams { + p := &LinkDomainToLdapParams{} + p.p = make(map[string]interface{}) + p.p["accounttype"] = accounttype + p.p["domainid"] = domainid + p.p["type"] = lDAPType + return p +} + +// link an existing cloudstack domain to group or OU in ldap +func (s *LDAPService) LinkDomainToLdap(p *LinkDomainToLdapParams) (*LinkDomainToLdapResponse, error) { + resp, err := s.cs.newRequest("linkDomainToLdap", p.toURLValues()) + if err != nil { + return nil, err + } + + var r LinkDomainToLdapResponse + if err := json.Unmarshal(resp, &r); err != nil { + return nil, err + } + + return &r, nil +} + +type LinkDomainToLdapResponse struct { + Accountid string `json:"accountid"` + Accounttype int `json:"accounttype"` + Domainid string `json:"domainid"` + Ldapdomain string `json:"ldapdomain"` + Name string `json:"name"` + Type string `json:"type"` +} + +type ListLdapConfigurationsParams struct { + p map[string]interface{} +} + +func (p *ListLdapConfigurationsParams) toURLValues() url.Values { + u := url.Values{} + if p.p == nil { + return u + } + if v, found := p.p["domainid"]; found { + u.Set("domainid", v.(string)) + } + if v, found := p.p["hostname"]; found { + u.Set("hostname", v.(string)) + } + if v, found := p.p["keyword"]; found { + u.Set("keyword", v.(string)) + } + if v, found := p.p["page"]; found { + vv := strconv.Itoa(v.(int)) + u.Set("page", vv) + } + if v, found := p.p["pagesize"]; found { + vv := strconv.Itoa(v.(int)) + u.Set("pagesize", vv) + } + if v, found := p.p["port"]; found { + vv := strconv.Itoa(v.(int)) + u.Set("port", vv) + } + return u +} + +func (p *ListLdapConfigurationsParams) SetDomainid(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["domainid"] = v + return +} + +func (p *ListLdapConfigurationsParams) SetHostname(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["hostname"] = v + return +} + +func (p *ListLdapConfigurationsParams) SetKeyword(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["keyword"] = v + return +} + +func (p *ListLdapConfigurationsParams) SetPage(v int) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["page"] = v + return +} + +func (p *ListLdapConfigurationsParams) SetPagesize(v int) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["pagesize"] = v + return +} + +func (p *ListLdapConfigurationsParams) SetPort(v int) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["port"] = v + return +} + +// You should always use this function to get a new ListLdapConfigurationsParams instance, +// as then you are sure you have configured all required params +func (s *LDAPService) NewListLdapConfigurationsParams() *ListLdapConfigurationsParams { + p := &ListLdapConfigurationsParams{} + p.p = make(map[string]interface{}) + return p +} + +// Lists all LDAP configurations +func (s *LDAPService) ListLdapConfigurations(p *ListLdapConfigurationsParams) (*ListLdapConfigurationsResponse, error) { + resp, err := s.cs.newRequest("listLdapConfigurations", p.toURLValues()) + if err != nil { + return nil, err + } + + var r ListLdapConfigurationsResponse + if err := json.Unmarshal(resp, &r); err != nil { + return nil, err + } + + return &r, nil +} + +type ListLdapConfigurationsResponse struct { + Count int `json:"count"` + LdapConfigurations []*LdapConfiguration `json:"ldapconfiguration"` +} + +type LdapConfiguration struct { + Domainid string `json:"domainid"` + Hostname string `json:"hostname"` + Port int `json:"port"` +} + +type ListLdapUsersParams struct { + p map[string]interface{} +} + +func (p *ListLdapUsersParams) toURLValues() url.Values { + u := url.Values{} + if p.p == nil { + return u + } + if v, found := p.p["keyword"]; found { + u.Set("keyword", v.(string)) + } + if v, found := p.p["listtype"]; found { + u.Set("listtype", v.(string)) + } + if v, found := p.p["page"]; found { + vv := strconv.Itoa(v.(int)) + u.Set("page", vv) + } + if v, found := p.p["pagesize"]; found { + vv := strconv.Itoa(v.(int)) + u.Set("pagesize", vv) + } + return u +} + +func (p *ListLdapUsersParams) SetKeyword(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["keyword"] = v + return +} + +func (p *ListLdapUsersParams) SetListtype(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["listtype"] = v + return +} + +func (p *ListLdapUsersParams) SetPage(v int) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["page"] = v + return +} + +func (p *ListLdapUsersParams) SetPagesize(v int) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["pagesize"] = v + return +} + +// You should always use this function to get a new ListLdapUsersParams instance, +// as then you are sure you have configured all required params +func (s *LDAPService) NewListLdapUsersParams() *ListLdapUsersParams { + p := &ListLdapUsersParams{} + p.p = make(map[string]interface{}) + return p +} + +// Lists all LDAP Users +func (s *LDAPService) ListLdapUsers(p *ListLdapUsersParams) (*ListLdapUsersResponse, error) { + resp, err := s.cs.newRequest("listLdapUsers", p.toURLValues()) + if err != nil { + return nil, err + } + + var r ListLdapUsersResponse + if err := json.Unmarshal(resp, &r); err != nil { + return nil, err + } + + return &r, nil +} + +type ListLdapUsersResponse struct { + Count int `json:"count"` + LdapUsers []*LdapUser `json:"ldapuser"` +} + +type LdapUser struct { + Domain string `json:"domain"` + Email string `json:"email"` + Firstname string `json:"firstname"` + Lastname string `json:"lastname"` + Principal string `json:"principal"` + Username string `json:"username"` +} + +type SearchLdapParams struct { + p map[string]interface{} +} + +func (p *SearchLdapParams) toURLValues() url.Values { + u := url.Values{} + if p.p == nil { + return u + } + if v, found := p.p["keyword"]; found { + u.Set("keyword", v.(string)) + } + if v, found := p.p["page"]; found { + vv := strconv.Itoa(v.(int)) + u.Set("page", vv) + } + if v, found := p.p["pagesize"]; found { + vv := strconv.Itoa(v.(int)) + u.Set("pagesize", vv) + } + if v, found := p.p["query"]; found { + u.Set("query", v.(string)) + } + return u +} + +func (p *SearchLdapParams) SetKeyword(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["keyword"] = v + return +} + +func (p *SearchLdapParams) SetPage(v int) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["page"] = v + return +} + +func (p *SearchLdapParams) SetPagesize(v int) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["pagesize"] = v + return +} + +func (p *SearchLdapParams) SetQuery(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["query"] = v + return +} + +// You should always use this function to get a new SearchLdapParams instance, +// as then you are sure you have configured all required params +func (s *LDAPService) NewSearchLdapParams(query string) *SearchLdapParams { + p := &SearchLdapParams{} + p.p = make(map[string]interface{}) + p.p["query"] = query + return p +} + +// Searches LDAP based on the username attribute +func (s *LDAPService) SearchLdap(p *SearchLdapParams) (*SearchLdapResponse, error) { + resp, err := s.cs.newRequest("searchLdap", p.toURLValues()) + if err != nil { + return nil, err + } + + var r SearchLdapResponse + if err := json.Unmarshal(resp, &r); err != nil { + return nil, err + } + + return &r, nil +} + +type SearchLdapResponse struct { + Domain string `json:"domain"` + Email string `json:"email"` + Firstname string `json:"firstname"` + Lastname string `json:"lastname"` + Principal string `json:"principal"` + Username string `json:"username"` } diff --git a/vendor/github.com/xanzy/go-cloudstack/cloudstack/LICENSE b/vendor/github.com/xanzy/go-cloudstack/cloudstack/LICENSE deleted file mode 100644 index 5c304d1a4..000000000 --- a/vendor/github.com/xanzy/go-cloudstack/cloudstack/LICENSE +++ /dev/null @@ -1,201 +0,0 @@ -Apache License - Version 2.0, January 2004 - http://www.apache.org/licenses/ - - TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION - - 1. Definitions. - - "License" shall mean the terms and conditions for use, reproduction, - and distribution as defined by Sections 1 through 9 of this document. - - "Licensor" shall mean the copyright owner or entity authorized by - the copyright owner that is granting the License. - - "Legal Entity" shall mean the union of the acting entity and all - other entities that control, are controlled by, or are under common - control with that entity. For the purposes of this definition, - "control" means (i) the power, direct or indirect, to cause the - direction or management of such entity, whether by contract or - otherwise, or (ii) ownership of fifty percent (50%) or more of the - outstanding shares, or (iii) beneficial ownership of such entity. - - "You" (or "Your") shall mean an individual or Legal Entity - exercising permissions granted by this License. - - "Source" form shall mean the preferred form for making modifications, - including but not limited to software source code, documentation - source, and configuration files. - - "Object" form shall mean any form resulting from mechanical - transformation or translation of a Source form, including but - not limited to compiled object code, generated documentation, - and conversions to other media types. - - "Work" shall mean the work of authorship, whether in Source or - Object form, made available under the License, as indicated by a - copyright notice that is included in or attached to the work - (an example is provided in the Appendix below). - - "Derivative Works" shall mean any work, whether in Source or Object - form, that is based on (or derived from) the Work and for which the - editorial revisions, annotations, elaborations, or other modifications - represent, as a whole, an original work of authorship. For the purposes - of this License, Derivative Works shall not include works that remain - separable from, or merely link (or bind by name) to the interfaces of, - the Work and Derivative Works thereof. - - "Contribution" shall mean any work of authorship, including - the original version of the Work and any modifications or additions - to that Work or Derivative Works thereof, that is intentionally - submitted to Licensor for inclusion in the Work by the copyright owner - or by an individual or Legal Entity authorized to submit on behalf of - the copyright owner. For the purposes of this definition, "submitted" - means any form of electronic, verbal, or written communication sent - to the Licensor or its representatives, including but not limited to - communication on electronic mailing lists, source code control systems, - and issue tracking systems that are managed by, or on behalf of, the - Licensor for the purpose of discussing and improving the Work, but - excluding communication that is conspicuously marked or otherwise - designated in writing by the copyright owner as "Not a Contribution." - - "Contributor" shall mean Licensor and any individual or Legal Entity - on behalf of whom a Contribution has been received by Licensor and - subsequently incorporated within the Work. - - 2. Grant of Copyright License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - copyright license to reproduce, prepare Derivative Works of, - publicly display, publicly perform, sublicense, and distribute the - Work and such Derivative Works in Source or Object form. - - 3. Grant of Patent License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - (except as stated in this section) patent license to make, have made, - use, offer to sell, sell, import, and otherwise transfer the Work, - where such license applies only to those patent claims licensable - by such Contributor that are necessarily infringed by their - Contribution(s) alone or by combination of their Contribution(s) - with the Work to which such Contribution(s) was submitted. If You - institute patent litigation against any entity (including a - cross-claim or counterclaim in a lawsuit) alleging that the Work - or a Contribution incorporated within the Work constitutes direct - or contributory patent infringement, then any patent licenses - granted to You under this License for that Work shall terminate - as of the date such litigation is filed. - - 4. Redistribution. You may reproduce and distribute copies of the - Work or Derivative Works thereof in any medium, with or without - modifications, and in Source or Object form, provided that You - meet the following conditions: - - (a) You must give any other recipients of the Work or - Derivative Works a copy of this License; and - - (b) You must cause any modified files to carry prominent notices - stating that You changed the files; and - - (c) You must retain, in the Source form of any Derivative Works - that You distribute, all copyright, patent, trademark, and - attribution notices from the Source form of the Work, - excluding those notices that do not pertain to any part of - the Derivative Works; and - - (d) If the Work includes a "NOTICE" text file as part of its - distribution, then any Derivative Works that You distribute must - include a readable copy of the attribution notices contained - within such NOTICE file, excluding those notices that do not - pertain to any part of the Derivative Works, in at least one - of the following places: within a NOTICE text file distributed - as part of the Derivative Works; within the Source form or - documentation, if provided along with the Derivative Works; or, - within a display generated by the Derivative Works, if and - wherever such third-party notices normally appear. The contents - of the NOTICE file are for informational purposes only and - do not modify the License. You may add Your own attribution - notices within Derivative Works that You distribute, alongside - or as an addendum to the NOTICE text from the Work, provided - that such additional attribution notices cannot be construed - as modifying the License. - - You may add Your own copyright statement to Your modifications and - may provide additional or different license terms and conditions - for use, reproduction, or distribution of Your modifications, or - for any such Derivative Works as a whole, provided Your use, - reproduction, and distribution of the Work otherwise complies with - the conditions stated in this License. - - 5. Submission of Contributions. Unless You explicitly state otherwise, - any Contribution intentionally submitted for inclusion in the Work - by You to the Licensor shall be under the terms and conditions of - this License, without any additional terms or conditions. - Notwithstanding the above, nothing herein shall supersede or modify - the terms of any separate license agreement you may have executed - with Licensor regarding such Contributions. - - 6. Trademarks. This License does not grant permission to use the trade - names, trademarks, service marks, or product names of the Licensor, - except as required for reasonable and customary use in describing the - origin of the Work and reproducing the content of the NOTICE file. - - 7. Disclaimer of Warranty. Unless required by applicable law or - agreed to in writing, Licensor provides the Work (and each - Contributor provides its Contributions) on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or - implied, including, without limitation, any warranties or conditions - of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A - PARTICULAR PURPOSE. You are solely responsible for determining the - appropriateness of using or redistributing the Work and assume any - risks associated with Your exercise of permissions under this License. - - 8. Limitation of Liability. In no event and under no legal theory, - whether in tort (including negligence), contract, or otherwise, - unless required by applicable law (such as deliberate and grossly - negligent acts) or agreed to in writing, shall any Contributor be - liable to You for damages, including any direct, indirect, special, - incidental, or consequential damages of any character arising as a - result of this License or out of the use or inability to use the - Work (including but not limited to damages for loss of goodwill, - work stoppage, computer failure or malfunction, or any and all - other commercial damages or losses), even if such Contributor - has been advised of the possibility of such damages. - - 9. Accepting Warranty or Additional Liability. While redistributing - the Work or Derivative Works thereof, You may choose to offer, - and charge a fee for, acceptance of support, warranty, indemnity, - or other liability obligations and/or rights consistent with this - License. However, in accepting such obligations, You may act only - on Your own behalf and on Your sole responsibility, not on behalf - of any other Contributor, and only if You agree to indemnify, - defend, and hold each Contributor harmless for any liability - incurred by, or claims asserted against, such Contributor by reason - of your accepting any such warranty or additional liability. - - END OF TERMS AND CONDITIONS - - APPENDIX: How to apply the Apache License to your work. - - To apply the Apache License to your work, attach the following - boilerplate notice, with the fields enclosed by brackets "{}" - replaced with your own identifying information. (Don't include - the brackets!) The text should be enclosed in the appropriate - comment syntax for the file format. We also recommend that a - file or class name and description of purpose be included on the - same "printed page" as the copyright notice for easier - identification within third-party archives. - - Copyright {yyyy} {name of copyright owner} - - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. diff --git a/vendor/github.com/xanzy/go-cloudstack/cloudstack/LimitService.go b/vendor/github.com/xanzy/go-cloudstack/cloudstack/LimitService.go index 276abecf8..23512715b 100644 --- a/vendor/github.com/xanzy/go-cloudstack/cloudstack/LimitService.go +++ b/vendor/github.com/xanzy/go-cloudstack/cloudstack/LimitService.go @@ -1,5 +1,5 @@ // -// Copyright 2016, Sander van Harmelen +// Copyright 2018, Sander van Harmelen // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -22,6 +22,373 @@ import ( "strconv" ) +type GetApiLimitParams struct { + p map[string]interface{} +} + +func (p *GetApiLimitParams) toURLValues() url.Values { + u := url.Values{} + if p.p == nil { + return u + } + return u +} + +// You should always use this function to get a new GetApiLimitParams instance, +// as then you are sure you have configured all required params +func (s *LimitService) NewGetApiLimitParams() *GetApiLimitParams { + p := &GetApiLimitParams{} + p.p = make(map[string]interface{}) + return p +} + +// Get API limit count for the caller +func (s *LimitService) GetApiLimit(p *GetApiLimitParams) (*GetApiLimitResponse, error) { + resp, err := s.cs.newRequest("getApiLimit", p.toURLValues()) + if err != nil { + return nil, err + } + + var r GetApiLimitResponse + if err := json.Unmarshal(resp, &r); err != nil { + return nil, err + } + + return &r, nil +} + +type GetApiLimitResponse struct { + Account string `json:"account"` + Accountid string `json:"accountid"` + ApiAllowed int `json:"apiAllowed"` + ApiIssued int `json:"apiIssued"` + ExpireAfter int64 `json:"expireAfter"` +} + +type ListResourceLimitsParams struct { + p map[string]interface{} +} + +func (p *ListResourceLimitsParams) toURLValues() url.Values { + u := url.Values{} + if p.p == nil { + return u + } + if v, found := p.p["account"]; found { + u.Set("account", v.(string)) + } + if v, found := p.p["domainid"]; found { + u.Set("domainid", v.(string)) + } + if v, found := p.p["id"]; found { + vv := strconv.FormatInt(v.(int64), 10) + u.Set("id", vv) + } + if v, found := p.p["isrecursive"]; found { + vv := strconv.FormatBool(v.(bool)) + u.Set("isrecursive", vv) + } + if v, found := p.p["keyword"]; found { + u.Set("keyword", v.(string)) + } + if v, found := p.p["listall"]; found { + vv := strconv.FormatBool(v.(bool)) + u.Set("listall", vv) + } + if v, found := p.p["page"]; found { + vv := strconv.Itoa(v.(int)) + u.Set("page", vv) + } + if v, found := p.p["pagesize"]; found { + vv := strconv.Itoa(v.(int)) + u.Set("pagesize", vv) + } + if v, found := p.p["projectid"]; found { + u.Set("projectid", v.(string)) + } + if v, found := p.p["resourcetype"]; found { + vv := strconv.Itoa(v.(int)) + u.Set("resourcetype", vv) + } + if v, found := p.p["resourcetypename"]; found { + u.Set("resourcetypename", v.(string)) + } + return u +} + +func (p *ListResourceLimitsParams) SetAccount(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["account"] = v + return +} + +func (p *ListResourceLimitsParams) SetDomainid(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["domainid"] = v + return +} + +func (p *ListResourceLimitsParams) SetId(v int64) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["id"] = v + return +} + +func (p *ListResourceLimitsParams) SetIsrecursive(v bool) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["isrecursive"] = v + return +} + +func (p *ListResourceLimitsParams) SetKeyword(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["keyword"] = v + return +} + +func (p *ListResourceLimitsParams) SetListall(v bool) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["listall"] = v + return +} + +func (p *ListResourceLimitsParams) SetPage(v int) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["page"] = v + return +} + +func (p *ListResourceLimitsParams) SetPagesize(v int) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["pagesize"] = v + return +} + +func (p *ListResourceLimitsParams) SetProjectid(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["projectid"] = v + return +} + +func (p *ListResourceLimitsParams) SetResourcetype(v int) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["resourcetype"] = v + return +} + +func (p *ListResourceLimitsParams) SetResourcetypename(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["resourcetypename"] = v + return +} + +// You should always use this function to get a new ListResourceLimitsParams instance, +// as then you are sure you have configured all required params +func (s *LimitService) NewListResourceLimitsParams() *ListResourceLimitsParams { + p := &ListResourceLimitsParams{} + p.p = make(map[string]interface{}) + return p +} + +// Lists resource limits. +func (s *LimitService) ListResourceLimits(p *ListResourceLimitsParams) (*ListResourceLimitsResponse, error) { + resp, err := s.cs.newRequest("listResourceLimits", p.toURLValues()) + if err != nil { + return nil, err + } + + var r ListResourceLimitsResponse + if err := json.Unmarshal(resp, &r); err != nil { + return nil, err + } + + return &r, nil +} + +type ListResourceLimitsResponse struct { + Count int `json:"count"` + ResourceLimits []*ResourceLimit `json:"resourcelimit"` +} + +type ResourceLimit struct { + Account string `json:"account"` + Domain string `json:"domain"` + Domainid string `json:"domainid"` + Max int64 `json:"max"` + Project string `json:"project"` + Projectid string `json:"projectid"` + Resourcetype string `json:"resourcetype"` + Resourcetypename string `json:"resourcetypename"` +} + +type ResetApiLimitParams struct { + p map[string]interface{} +} + +func (p *ResetApiLimitParams) toURLValues() url.Values { + u := url.Values{} + if p.p == nil { + return u + } + if v, found := p.p["account"]; found { + u.Set("account", v.(string)) + } + return u +} + +func (p *ResetApiLimitParams) SetAccount(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["account"] = v + return +} + +// You should always use this function to get a new ResetApiLimitParams instance, +// as then you are sure you have configured all required params +func (s *LimitService) NewResetApiLimitParams() *ResetApiLimitParams { + p := &ResetApiLimitParams{} + p.p = make(map[string]interface{}) + return p +} + +// Reset api count +func (s *LimitService) ResetApiLimit(p *ResetApiLimitParams) (*ResetApiLimitResponse, error) { + resp, err := s.cs.newRequest("resetApiLimit", p.toURLValues()) + if err != nil { + return nil, err + } + + var r ResetApiLimitResponse + if err := json.Unmarshal(resp, &r); err != nil { + return nil, err + } + + return &r, nil +} + +type ResetApiLimitResponse struct { + Account string `json:"account"` + Accountid string `json:"accountid"` + ApiAllowed int `json:"apiAllowed"` + ApiIssued int `json:"apiIssued"` + ExpireAfter int64 `json:"expireAfter"` +} + +type UpdateResourceCountParams struct { + p map[string]interface{} +} + +func (p *UpdateResourceCountParams) toURLValues() url.Values { + u := url.Values{} + if p.p == nil { + return u + } + if v, found := p.p["account"]; found { + u.Set("account", v.(string)) + } + if v, found := p.p["domainid"]; found { + u.Set("domainid", v.(string)) + } + if v, found := p.p["projectid"]; found { + u.Set("projectid", v.(string)) + } + if v, found := p.p["resourcetype"]; found { + vv := strconv.Itoa(v.(int)) + u.Set("resourcetype", vv) + } + return u +} + +func (p *UpdateResourceCountParams) SetAccount(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["account"] = v + return +} + +func (p *UpdateResourceCountParams) SetDomainid(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["domainid"] = v + return +} + +func (p *UpdateResourceCountParams) SetProjectid(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["projectid"] = v + return +} + +func (p *UpdateResourceCountParams) SetResourcetype(v int) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["resourcetype"] = v + return +} + +// You should always use this function to get a new UpdateResourceCountParams instance, +// as then you are sure you have configured all required params +func (s *LimitService) NewUpdateResourceCountParams(domainid string) *UpdateResourceCountParams { + p := &UpdateResourceCountParams{} + p.p = make(map[string]interface{}) + p.p["domainid"] = domainid + return p +} + +// Recalculate and update resource count for an account or domain. +func (s *LimitService) UpdateResourceCount(p *UpdateResourceCountParams) (*UpdateResourceCountResponse, error) { + resp, err := s.cs.newRequest("updateResourceCount", p.toURLValues()) + if err != nil { + return nil, err + } + + var r UpdateResourceCountResponse + if err := json.Unmarshal(resp, &r); err != nil { + return nil, err + } + + return &r, nil +} + +type UpdateResourceCountResponse struct { + Account string `json:"account"` + Domain string `json:"domain"` + Domainid string `json:"domainid"` + Project string `json:"project"` + Projectid string `json:"projectid"` + Resourcecount int64 `json:"resourcecount"` + Resourcetype string `json:"resourcetype"` + Resourcetypename string `json:"resourcetypename"` +} + type UpdateResourceLimitParams struct { p map[string]interface{} } @@ -111,365 +478,17 @@ func (s *LimitService) UpdateResourceLimit(p *UpdateResourceLimitParams) (*Updat if err := json.Unmarshal(resp, &r); err != nil { return nil, err } + return &r, nil } type UpdateResourceLimitResponse struct { - Account string `json:"account,omitempty"` - Domain string `json:"domain,omitempty"` - Domainid string `json:"domainid,omitempty"` - Max int64 `json:"max,omitempty"` - Project string `json:"project,omitempty"` - Projectid string `json:"projectid,omitempty"` - Resourcetype string `json:"resourcetype,omitempty"` -} - -type UpdateResourceCountParams struct { - p map[string]interface{} -} - -func (p *UpdateResourceCountParams) toURLValues() url.Values { - u := url.Values{} - if p.p == nil { - return u - } - if v, found := p.p["account"]; found { - u.Set("account", v.(string)) - } - if v, found := p.p["domainid"]; found { - u.Set("domainid", v.(string)) - } - if v, found := p.p["projectid"]; found { - u.Set("projectid", v.(string)) - } - if v, found := p.p["resourcetype"]; found { - vv := strconv.Itoa(v.(int)) - u.Set("resourcetype", vv) - } - return u -} - -func (p *UpdateResourceCountParams) SetAccount(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["account"] = v - return -} - -func (p *UpdateResourceCountParams) SetDomainid(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["domainid"] = v - return -} - -func (p *UpdateResourceCountParams) SetProjectid(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["projectid"] = v - return -} - -func (p *UpdateResourceCountParams) SetResourcetype(v int) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["resourcetype"] = v - return -} - -// You should always use this function to get a new UpdateResourceCountParams instance, -// as then you are sure you have configured all required params -func (s *LimitService) NewUpdateResourceCountParams(domainid string) *UpdateResourceCountParams { - p := &UpdateResourceCountParams{} - p.p = make(map[string]interface{}) - p.p["domainid"] = domainid - return p -} - -// Recalculate and update resource count for an account or domain. -func (s *LimitService) UpdateResourceCount(p *UpdateResourceCountParams) (*UpdateResourceCountResponse, error) { - resp, err := s.cs.newRequest("updateResourceCount", p.toURLValues()) - if err != nil { - return nil, err - } - - var r UpdateResourceCountResponse - if err := json.Unmarshal(resp, &r); err != nil { - return nil, err - } - return &r, nil -} - -type UpdateResourceCountResponse struct { - Account string `json:"account,omitempty"` - Domain string `json:"domain,omitempty"` - Domainid string `json:"domainid,omitempty"` - Project string `json:"project,omitempty"` - Projectid string `json:"projectid,omitempty"` - Resourcecount int64 `json:"resourcecount,omitempty"` - Resourcetype string `json:"resourcetype,omitempty"` -} - -type ListResourceLimitsParams struct { - p map[string]interface{} -} - -func (p *ListResourceLimitsParams) toURLValues() url.Values { - u := url.Values{} - if p.p == nil { - return u - } - if v, found := p.p["account"]; found { - u.Set("account", v.(string)) - } - if v, found := p.p["domainid"]; found { - u.Set("domainid", v.(string)) - } - if v, found := p.p["id"]; found { - vv := strconv.FormatInt(v.(int64), 10) - u.Set("id", vv) - } - if v, found := p.p["isrecursive"]; found { - vv := strconv.FormatBool(v.(bool)) - u.Set("isrecursive", vv) - } - if v, found := p.p["keyword"]; found { - u.Set("keyword", v.(string)) - } - if v, found := p.p["listall"]; found { - vv := strconv.FormatBool(v.(bool)) - u.Set("listall", vv) - } - if v, found := p.p["page"]; found { - vv := strconv.Itoa(v.(int)) - u.Set("page", vv) - } - if v, found := p.p["pagesize"]; found { - vv := strconv.Itoa(v.(int)) - u.Set("pagesize", vv) - } - if v, found := p.p["projectid"]; found { - u.Set("projectid", v.(string)) - } - if v, found := p.p["resourcetype"]; found { - vv := strconv.Itoa(v.(int)) - u.Set("resourcetype", vv) - } - return u -} - -func (p *ListResourceLimitsParams) SetAccount(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["account"] = v - return -} - -func (p *ListResourceLimitsParams) SetDomainid(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["domainid"] = v - return -} - -func (p *ListResourceLimitsParams) SetId(v int64) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["id"] = v - return -} - -func (p *ListResourceLimitsParams) SetIsrecursive(v bool) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["isrecursive"] = v - return -} - -func (p *ListResourceLimitsParams) SetKeyword(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["keyword"] = v - return -} - -func (p *ListResourceLimitsParams) SetListall(v bool) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["listall"] = v - return -} - -func (p *ListResourceLimitsParams) SetPage(v int) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["page"] = v - return -} - -func (p *ListResourceLimitsParams) SetPagesize(v int) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["pagesize"] = v - return -} - -func (p *ListResourceLimitsParams) SetProjectid(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["projectid"] = v - return -} - -func (p *ListResourceLimitsParams) SetResourcetype(v int) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["resourcetype"] = v - return -} - -// You should always use this function to get a new ListResourceLimitsParams instance, -// as then you are sure you have configured all required params -func (s *LimitService) NewListResourceLimitsParams() *ListResourceLimitsParams { - p := &ListResourceLimitsParams{} - p.p = make(map[string]interface{}) - return p -} - -// Lists resource limits. -func (s *LimitService) ListResourceLimits(p *ListResourceLimitsParams) (*ListResourceLimitsResponse, error) { - resp, err := s.cs.newRequest("listResourceLimits", p.toURLValues()) - if err != nil { - return nil, err - } - - var r ListResourceLimitsResponse - if err := json.Unmarshal(resp, &r); err != nil { - return nil, err - } - return &r, nil -} - -type ListResourceLimitsResponse struct { - Count int `json:"count"` - ResourceLimits []*ResourceLimit `json:"resourcelimit"` -} - -type ResourceLimit struct { - Account string `json:"account,omitempty"` - Domain string `json:"domain,omitempty"` - Domainid string `json:"domainid,omitempty"` - Max int64 `json:"max,omitempty"` - Project string `json:"project,omitempty"` - Projectid string `json:"projectid,omitempty"` - Resourcetype string `json:"resourcetype,omitempty"` -} - -type GetApiLimitParams struct { - p map[string]interface{} -} - -func (p *GetApiLimitParams) toURLValues() url.Values { - u := url.Values{} - if p.p == nil { - return u - } - return u -} - -// You should always use this function to get a new GetApiLimitParams instance, -// as then you are sure you have configured all required params -func (s *LimitService) NewGetApiLimitParams() *GetApiLimitParams { - p := &GetApiLimitParams{} - p.p = make(map[string]interface{}) - return p -} - -// Get API limit count for the caller -func (s *LimitService) GetApiLimit(p *GetApiLimitParams) (*GetApiLimitResponse, error) { - resp, err := s.cs.newRequest("getApiLimit", p.toURLValues()) - if err != nil { - return nil, err - } - - var r GetApiLimitResponse - if err := json.Unmarshal(resp, &r); err != nil { - return nil, err - } - return &r, nil -} - -type GetApiLimitResponse struct { - Account string `json:"account,omitempty"` - Accountid string `json:"accountid,omitempty"` - ApiAllowed int `json:"apiAllowed,omitempty"` - ApiIssued int `json:"apiIssued,omitempty"` - ExpireAfter int64 `json:"expireAfter,omitempty"` -} - -type ResetApiLimitParams struct { - p map[string]interface{} -} - -func (p *ResetApiLimitParams) toURLValues() url.Values { - u := url.Values{} - if p.p == nil { - return u - } - if v, found := p.p["account"]; found { - u.Set("account", v.(string)) - } - return u -} - -func (p *ResetApiLimitParams) SetAccount(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["account"] = v - return -} - -// You should always use this function to get a new ResetApiLimitParams instance, -// as then you are sure you have configured all required params -func (s *LimitService) NewResetApiLimitParams() *ResetApiLimitParams { - p := &ResetApiLimitParams{} - p.p = make(map[string]interface{}) - return p -} - -// Reset api count -func (s *LimitService) ResetApiLimit(p *ResetApiLimitParams) (*ResetApiLimitResponse, error) { - resp, err := s.cs.newRequest("resetApiLimit", p.toURLValues()) - if err != nil { - return nil, err - } - - var r ResetApiLimitResponse - if err := json.Unmarshal(resp, &r); err != nil { - return nil, err - } - return &r, nil -} - -type ResetApiLimitResponse struct { - Account string `json:"account,omitempty"` - Accountid string `json:"accountid,omitempty"` - ApiAllowed int `json:"apiAllowed,omitempty"` - ApiIssued int `json:"apiIssued,omitempty"` - ExpireAfter int64 `json:"expireAfter,omitempty"` + Account string `json:"account"` + Domain string `json:"domain"` + Domainid string `json:"domainid"` + Max int64 `json:"max"` + Project string `json:"project"` + Projectid string `json:"projectid"` + Resourcetype string `json:"resourcetype"` + Resourcetypename string `json:"resourcetypename"` } diff --git a/vendor/github.com/xanzy/go-cloudstack/cloudstack/LoadBalancerService.go b/vendor/github.com/xanzy/go-cloudstack/cloudstack/LoadBalancerService.go index 9900a0715..e74e3a3d4 100644 --- a/vendor/github.com/xanzy/go-cloudstack/cloudstack/LoadBalancerService.go +++ b/vendor/github.com/xanzy/go-cloudstack/cloudstack/LoadBalancerService.go @@ -1,5 +1,5 @@ // -// Copyright 2016, Sander van Harmelen +// Copyright 2018, Sander van Harmelen // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -24,6 +24,1326 @@ import ( "strings" ) +type AddNetscalerLoadBalancerParams struct { + p map[string]interface{} +} + +func (p *AddNetscalerLoadBalancerParams) toURLValues() url.Values { + u := url.Values{} + if p.p == nil { + return u + } + if v, found := p.p["gslbprovider"]; found { + vv := strconv.FormatBool(v.(bool)) + u.Set("gslbprovider", vv) + } + if v, found := p.p["gslbproviderprivateip"]; found { + u.Set("gslbproviderprivateip", v.(string)) + } + if v, found := p.p["gslbproviderpublicip"]; found { + u.Set("gslbproviderpublicip", v.(string)) + } + if v, found := p.p["isexclusivegslbprovider"]; found { + vv := strconv.FormatBool(v.(bool)) + u.Set("isexclusivegslbprovider", vv) + } + if v, found := p.p["networkdevicetype"]; found { + u.Set("networkdevicetype", v.(string)) + } + if v, found := p.p["password"]; found { + u.Set("password", v.(string)) + } + if v, found := p.p["physicalnetworkid"]; found { + u.Set("physicalnetworkid", v.(string)) + } + if v, found := p.p["url"]; found { + u.Set("url", v.(string)) + } + if v, found := p.p["username"]; found { + u.Set("username", v.(string)) + } + return u +} + +func (p *AddNetscalerLoadBalancerParams) SetGslbprovider(v bool) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["gslbprovider"] = v + return +} + +func (p *AddNetscalerLoadBalancerParams) SetGslbproviderprivateip(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["gslbproviderprivateip"] = v + return +} + +func (p *AddNetscalerLoadBalancerParams) SetGslbproviderpublicip(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["gslbproviderpublicip"] = v + return +} + +func (p *AddNetscalerLoadBalancerParams) SetIsexclusivegslbprovider(v bool) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["isexclusivegslbprovider"] = v + return +} + +func (p *AddNetscalerLoadBalancerParams) SetNetworkdevicetype(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["networkdevicetype"] = v + return +} + +func (p *AddNetscalerLoadBalancerParams) SetPassword(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["password"] = v + return +} + +func (p *AddNetscalerLoadBalancerParams) SetPhysicalnetworkid(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["physicalnetworkid"] = v + return +} + +func (p *AddNetscalerLoadBalancerParams) SetUrl(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["url"] = v + return +} + +func (p *AddNetscalerLoadBalancerParams) SetUsername(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["username"] = v + return +} + +// You should always use this function to get a new AddNetscalerLoadBalancerParams instance, +// as then you are sure you have configured all required params +func (s *LoadBalancerService) NewAddNetscalerLoadBalancerParams(networkdevicetype string, password string, physicalnetworkid string, url string, username string) *AddNetscalerLoadBalancerParams { + p := &AddNetscalerLoadBalancerParams{} + p.p = make(map[string]interface{}) + p.p["networkdevicetype"] = networkdevicetype + p.p["password"] = password + p.p["physicalnetworkid"] = physicalnetworkid + p.p["url"] = url + p.p["username"] = username + return p +} + +// Adds a netscaler load balancer device +func (s *LoadBalancerService) AddNetscalerLoadBalancer(p *AddNetscalerLoadBalancerParams) (*AddNetscalerLoadBalancerResponse, error) { + resp, err := s.cs.newRequest("addNetscalerLoadBalancer", p.toURLValues()) + if err != nil { + return nil, err + } + + var r AddNetscalerLoadBalancerResponse + if err := json.Unmarshal(resp, &r); err != nil { + return nil, err + } + + // If we have a async client, we need to wait for the async result + if s.cs.async { + b, err := s.cs.GetAsyncJobResult(r.JobID, s.cs.timeout) + if err != nil { + if err == AsyncTimeoutErr { + return &r, err + } + return nil, err + } + + b, err = getRawValue(b) + if err != nil { + return nil, err + } + + if err := json.Unmarshal(b, &r); err != nil { + return nil, err + } + } + + return &r, nil +} + +type AddNetscalerLoadBalancerResponse struct { + JobID string `json:"jobid"` + Gslbprovider bool `json:"gslbprovider"` + Gslbproviderprivateip string `json:"gslbproviderprivateip"` + Gslbproviderpublicip string `json:"gslbproviderpublicip"` + Ipaddress string `json:"ipaddress"` + Isexclusivegslbprovider bool `json:"isexclusivegslbprovider"` + Lbdevicecapacity int64 `json:"lbdevicecapacity"` + Lbdevicededicated bool `json:"lbdevicededicated"` + Lbdeviceid string `json:"lbdeviceid"` + Lbdevicename string `json:"lbdevicename"` + Lbdevicestate string `json:"lbdevicestate"` + Physicalnetworkid string `json:"physicalnetworkid"` + Podids []string `json:"podids"` + Privateinterface string `json:"privateinterface"` + Provider string `json:"provider"` + Publicinterface string `json:"publicinterface"` +} + +type AssignCertToLoadBalancerParams struct { + p map[string]interface{} +} + +func (p *AssignCertToLoadBalancerParams) toURLValues() url.Values { + u := url.Values{} + if p.p == nil { + return u + } + if v, found := p.p["certid"]; found { + u.Set("certid", v.(string)) + } + if v, found := p.p["lbruleid"]; found { + u.Set("lbruleid", v.(string)) + } + return u +} + +func (p *AssignCertToLoadBalancerParams) SetCertid(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["certid"] = v + return +} + +func (p *AssignCertToLoadBalancerParams) SetLbruleid(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["lbruleid"] = v + return +} + +// You should always use this function to get a new AssignCertToLoadBalancerParams instance, +// as then you are sure you have configured all required params +func (s *LoadBalancerService) NewAssignCertToLoadBalancerParams(certid string, lbruleid string) *AssignCertToLoadBalancerParams { + p := &AssignCertToLoadBalancerParams{} + p.p = make(map[string]interface{}) + p.p["certid"] = certid + p.p["lbruleid"] = lbruleid + return p +} + +// Assigns a certificate to a load balancer rule +func (s *LoadBalancerService) AssignCertToLoadBalancer(p *AssignCertToLoadBalancerParams) (*AssignCertToLoadBalancerResponse, error) { + resp, err := s.cs.newRequest("assignCertToLoadBalancer", p.toURLValues()) + if err != nil { + return nil, err + } + + var r AssignCertToLoadBalancerResponse + if err := json.Unmarshal(resp, &r); err != nil { + return nil, err + } + + // If we have a async client, we need to wait for the async result + if s.cs.async { + b, err := s.cs.GetAsyncJobResult(r.JobID, s.cs.timeout) + if err != nil { + if err == AsyncTimeoutErr { + return &r, err + } + return nil, err + } + + if err := json.Unmarshal(b, &r); err != nil { + return nil, err + } + } + + return &r, nil +} + +type AssignCertToLoadBalancerResponse struct { + JobID string `json:"jobid"` + Displaytext string `json:"displaytext"` + Success bool `json:"success"` +} + +type AssignToGlobalLoadBalancerRuleParams struct { + p map[string]interface{} +} + +func (p *AssignToGlobalLoadBalancerRuleParams) toURLValues() url.Values { + u := url.Values{} + if p.p == nil { + return u + } + if v, found := p.p["gslblbruleweightsmap"]; found { + i := 0 + for k, vv := range v.(map[string]string) { + u.Set(fmt.Sprintf("gslblbruleweightsmap[%d].key", i), k) + u.Set(fmt.Sprintf("gslblbruleweightsmap[%d].value", i), vv) + i++ + } + } + if v, found := p.p["id"]; found { + u.Set("id", v.(string)) + } + if v, found := p.p["loadbalancerrulelist"]; found { + vv := strings.Join(v.([]string), ",") + u.Set("loadbalancerrulelist", vv) + } + return u +} + +func (p *AssignToGlobalLoadBalancerRuleParams) SetGslblbruleweightsmap(v map[string]string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["gslblbruleweightsmap"] = v + return +} + +func (p *AssignToGlobalLoadBalancerRuleParams) SetId(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["id"] = v + return +} + +func (p *AssignToGlobalLoadBalancerRuleParams) SetLoadbalancerrulelist(v []string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["loadbalancerrulelist"] = v + return +} + +// You should always use this function to get a new AssignToGlobalLoadBalancerRuleParams instance, +// as then you are sure you have configured all required params +func (s *LoadBalancerService) NewAssignToGlobalLoadBalancerRuleParams(id string, loadbalancerrulelist []string) *AssignToGlobalLoadBalancerRuleParams { + p := &AssignToGlobalLoadBalancerRuleParams{} + p.p = make(map[string]interface{}) + p.p["id"] = id + p.p["loadbalancerrulelist"] = loadbalancerrulelist + return p +} + +// Assign load balancer rule or list of load balancer rules to a global load balancer rules. +func (s *LoadBalancerService) AssignToGlobalLoadBalancerRule(p *AssignToGlobalLoadBalancerRuleParams) (*AssignToGlobalLoadBalancerRuleResponse, error) { + resp, err := s.cs.newRequest("assignToGlobalLoadBalancerRule", p.toURLValues()) + if err != nil { + return nil, err + } + + var r AssignToGlobalLoadBalancerRuleResponse + if err := json.Unmarshal(resp, &r); err != nil { + return nil, err + } + + // If we have a async client, we need to wait for the async result + if s.cs.async { + b, err := s.cs.GetAsyncJobResult(r.JobID, s.cs.timeout) + if err != nil { + if err == AsyncTimeoutErr { + return &r, err + } + return nil, err + } + + if err := json.Unmarshal(b, &r); err != nil { + return nil, err + } + } + + return &r, nil +} + +type AssignToGlobalLoadBalancerRuleResponse struct { + JobID string `json:"jobid"` + Displaytext string `json:"displaytext"` + Success bool `json:"success"` +} + +type AssignToLoadBalancerRuleParams struct { + p map[string]interface{} +} + +func (p *AssignToLoadBalancerRuleParams) toURLValues() url.Values { + u := url.Values{} + if p.p == nil { + return u + } + if v, found := p.p["id"]; found { + u.Set("id", v.(string)) + } + if v, found := p.p["virtualmachineids"]; found { + vv := strings.Join(v.([]string), ",") + u.Set("virtualmachineids", vv) + } + if v, found := p.p["vmidipmap"]; found { + i := 0 + for k, vv := range v.(map[string]string) { + u.Set(fmt.Sprintf("vmidipmap[%d].key", i), k) + u.Set(fmt.Sprintf("vmidipmap[%d].value", i), vv) + i++ + } + } + return u +} + +func (p *AssignToLoadBalancerRuleParams) SetId(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["id"] = v + return +} + +func (p *AssignToLoadBalancerRuleParams) SetVirtualmachineids(v []string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["virtualmachineids"] = v + return +} + +func (p *AssignToLoadBalancerRuleParams) SetVmidipmap(v map[string]string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["vmidipmap"] = v + return +} + +// You should always use this function to get a new AssignToLoadBalancerRuleParams instance, +// as then you are sure you have configured all required params +func (s *LoadBalancerService) NewAssignToLoadBalancerRuleParams(id string) *AssignToLoadBalancerRuleParams { + p := &AssignToLoadBalancerRuleParams{} + p.p = make(map[string]interface{}) + p.p["id"] = id + return p +} + +// Assigns virtual machine or a list of virtual machines to a load balancer rule. +func (s *LoadBalancerService) AssignToLoadBalancerRule(p *AssignToLoadBalancerRuleParams) (*AssignToLoadBalancerRuleResponse, error) { + resp, err := s.cs.newRequest("assignToLoadBalancerRule", p.toURLValues()) + if err != nil { + return nil, err + } + + var r AssignToLoadBalancerRuleResponse + if err := json.Unmarshal(resp, &r); err != nil { + return nil, err + } + + // If we have a async client, we need to wait for the async result + if s.cs.async { + b, err := s.cs.GetAsyncJobResult(r.JobID, s.cs.timeout) + if err != nil { + if err == AsyncTimeoutErr { + return &r, err + } + return nil, err + } + + if err := json.Unmarshal(b, &r); err != nil { + return nil, err + } + } + + return &r, nil +} + +type AssignToLoadBalancerRuleResponse struct { + JobID string `json:"jobid"` + Displaytext string `json:"displaytext"` + Success bool `json:"success"` +} + +type ConfigureNetscalerLoadBalancerParams struct { + p map[string]interface{} +} + +func (p *ConfigureNetscalerLoadBalancerParams) toURLValues() url.Values { + u := url.Values{} + if p.p == nil { + return u + } + if v, found := p.p["inline"]; found { + vv := strconv.FormatBool(v.(bool)) + u.Set("inline", vv) + } + if v, found := p.p["lbdevicecapacity"]; found { + vv := strconv.FormatInt(v.(int64), 10) + u.Set("lbdevicecapacity", vv) + } + if v, found := p.p["lbdevicededicated"]; found { + vv := strconv.FormatBool(v.(bool)) + u.Set("lbdevicededicated", vv) + } + if v, found := p.p["lbdeviceid"]; found { + u.Set("lbdeviceid", v.(string)) + } + if v, found := p.p["podids"]; found { + vv := strings.Join(v.([]string), ",") + u.Set("podids", vv) + } + return u +} + +func (p *ConfigureNetscalerLoadBalancerParams) SetInline(v bool) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["inline"] = v + return +} + +func (p *ConfigureNetscalerLoadBalancerParams) SetLbdevicecapacity(v int64) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["lbdevicecapacity"] = v + return +} + +func (p *ConfigureNetscalerLoadBalancerParams) SetLbdevicededicated(v bool) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["lbdevicededicated"] = v + return +} + +func (p *ConfigureNetscalerLoadBalancerParams) SetLbdeviceid(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["lbdeviceid"] = v + return +} + +func (p *ConfigureNetscalerLoadBalancerParams) SetPodids(v []string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["podids"] = v + return +} + +// You should always use this function to get a new ConfigureNetscalerLoadBalancerParams instance, +// as then you are sure you have configured all required params +func (s *LoadBalancerService) NewConfigureNetscalerLoadBalancerParams(lbdeviceid string) *ConfigureNetscalerLoadBalancerParams { + p := &ConfigureNetscalerLoadBalancerParams{} + p.p = make(map[string]interface{}) + p.p["lbdeviceid"] = lbdeviceid + return p +} + +// configures a netscaler load balancer device +func (s *LoadBalancerService) ConfigureNetscalerLoadBalancer(p *ConfigureNetscalerLoadBalancerParams) (*NetscalerLoadBalancerResponse, error) { + resp, err := s.cs.newRequest("configureNetscalerLoadBalancer", p.toURLValues()) + if err != nil { + return nil, err + } + + var r NetscalerLoadBalancerResponse + if err := json.Unmarshal(resp, &r); err != nil { + return nil, err + } + + // If we have a async client, we need to wait for the async result + if s.cs.async { + b, err := s.cs.GetAsyncJobResult(r.JobID, s.cs.timeout) + if err != nil { + if err == AsyncTimeoutErr { + return &r, err + } + return nil, err + } + + b, err = getRawValue(b) + if err != nil { + return nil, err + } + + if err := json.Unmarshal(b, &r); err != nil { + return nil, err + } + } + + return &r, nil +} + +type NetscalerLoadBalancerResponse struct { + JobID string `json:"jobid"` + Gslbprovider bool `json:"gslbprovider"` + Gslbproviderprivateip string `json:"gslbproviderprivateip"` + Gslbproviderpublicip string `json:"gslbproviderpublicip"` + Ipaddress string `json:"ipaddress"` + Isexclusivegslbprovider bool `json:"isexclusivegslbprovider"` + Lbdevicecapacity int64 `json:"lbdevicecapacity"` + Lbdevicededicated bool `json:"lbdevicededicated"` + Lbdeviceid string `json:"lbdeviceid"` + Lbdevicename string `json:"lbdevicename"` + Lbdevicestate string `json:"lbdevicestate"` + Physicalnetworkid string `json:"physicalnetworkid"` + Podids []string `json:"podids"` + Privateinterface string `json:"privateinterface"` + Provider string `json:"provider"` + Publicinterface string `json:"publicinterface"` +} + +type CreateGlobalLoadBalancerRuleParams struct { + p map[string]interface{} +} + +func (p *CreateGlobalLoadBalancerRuleParams) toURLValues() url.Values { + u := url.Values{} + if p.p == nil { + return u + } + if v, found := p.p["account"]; found { + u.Set("account", v.(string)) + } + if v, found := p.p["description"]; found { + u.Set("description", v.(string)) + } + if v, found := p.p["domainid"]; found { + u.Set("domainid", v.(string)) + } + if v, found := p.p["gslbdomainname"]; found { + u.Set("gslbdomainname", v.(string)) + } + if v, found := p.p["gslblbmethod"]; found { + u.Set("gslblbmethod", v.(string)) + } + if v, found := p.p["gslbservicetype"]; found { + u.Set("gslbservicetype", v.(string)) + } + if v, found := p.p["gslbstickysessionmethodname"]; found { + u.Set("gslbstickysessionmethodname", v.(string)) + } + if v, found := p.p["name"]; found { + u.Set("name", v.(string)) + } + if v, found := p.p["regionid"]; found { + vv := strconv.Itoa(v.(int)) + u.Set("regionid", vv) + } + return u +} + +func (p *CreateGlobalLoadBalancerRuleParams) SetAccount(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["account"] = v + return +} + +func (p *CreateGlobalLoadBalancerRuleParams) SetDescription(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["description"] = v + return +} + +func (p *CreateGlobalLoadBalancerRuleParams) SetDomainid(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["domainid"] = v + return +} + +func (p *CreateGlobalLoadBalancerRuleParams) SetGslbdomainname(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["gslbdomainname"] = v + return +} + +func (p *CreateGlobalLoadBalancerRuleParams) SetGslblbmethod(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["gslblbmethod"] = v + return +} + +func (p *CreateGlobalLoadBalancerRuleParams) SetGslbservicetype(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["gslbservicetype"] = v + return +} + +func (p *CreateGlobalLoadBalancerRuleParams) SetGslbstickysessionmethodname(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["gslbstickysessionmethodname"] = v + return +} + +func (p *CreateGlobalLoadBalancerRuleParams) SetName(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["name"] = v + return +} + +func (p *CreateGlobalLoadBalancerRuleParams) SetRegionid(v int) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["regionid"] = v + return +} + +// You should always use this function to get a new CreateGlobalLoadBalancerRuleParams instance, +// as then you are sure you have configured all required params +func (s *LoadBalancerService) NewCreateGlobalLoadBalancerRuleParams(gslbdomainname string, gslbservicetype string, name string, regionid int) *CreateGlobalLoadBalancerRuleParams { + p := &CreateGlobalLoadBalancerRuleParams{} + p.p = make(map[string]interface{}) + p.p["gslbdomainname"] = gslbdomainname + p.p["gslbservicetype"] = gslbservicetype + p.p["name"] = name + p.p["regionid"] = regionid + return p +} + +// Creates a global load balancer rule +func (s *LoadBalancerService) CreateGlobalLoadBalancerRule(p *CreateGlobalLoadBalancerRuleParams) (*CreateGlobalLoadBalancerRuleResponse, error) { + resp, err := s.cs.newRequest("createGlobalLoadBalancerRule", p.toURLValues()) + if err != nil { + return nil, err + } + + var r CreateGlobalLoadBalancerRuleResponse + if err := json.Unmarshal(resp, &r); err != nil { + return nil, err + } + + // If we have a async client, we need to wait for the async result + if s.cs.async { + b, err := s.cs.GetAsyncJobResult(r.JobID, s.cs.timeout) + if err != nil { + if err == AsyncTimeoutErr { + return &r, err + } + return nil, err + } + + b, err = getRawValue(b) + if err != nil { + return nil, err + } + + if err := json.Unmarshal(b, &r); err != nil { + return nil, err + } + } + + return &r, nil +} + +type CreateGlobalLoadBalancerRuleResponse struct { + JobID string `json:"jobid"` + Account string `json:"account"` + Description string `json:"description"` + Domain string `json:"domain"` + Domainid string `json:"domainid"` + Gslbdomainname string `json:"gslbdomainname"` + Gslblbmethod string `json:"gslblbmethod"` + Gslbservicetype string `json:"gslbservicetype"` + Gslbstickysessionmethodname string `json:"gslbstickysessionmethodname"` + Id string `json:"id"` + Loadbalancerrule []CreateGlobalLoadBalancerRuleResponseLoadbalancerrule `json:"loadbalancerrule"` + Name string `json:"name"` + Project string `json:"project"` + Projectid string `json:"projectid"` + Regionid int `json:"regionid"` +} + +type CreateGlobalLoadBalancerRuleResponseLoadbalancerrule struct { + Account string `json:"account"` + Algorithm string `json:"algorithm"` + Cidrlist string `json:"cidrlist"` + Description string `json:"description"` + Domain string `json:"domain"` + Domainid string `json:"domainid"` + Fordisplay bool `json:"fordisplay"` + Id string `json:"id"` + Name string `json:"name"` + Networkid string `json:"networkid"` + Privateport string `json:"privateport"` + Project string `json:"project"` + Projectid string `json:"projectid"` + Protocol string `json:"protocol"` + Publicip string `json:"publicip"` + Publicipid string `json:"publicipid"` + Publicport string `json:"publicport"` + State string `json:"state"` + Tags []Tags `json:"tags"` + Zoneid string `json:"zoneid"` + Zonename string `json:"zonename"` +} + +type CreateLBHealthCheckPolicyParams struct { + p map[string]interface{} +} + +func (p *CreateLBHealthCheckPolicyParams) toURLValues() url.Values { + u := url.Values{} + if p.p == nil { + return u + } + if v, found := p.p["description"]; found { + u.Set("description", v.(string)) + } + if v, found := p.p["fordisplay"]; found { + vv := strconv.FormatBool(v.(bool)) + u.Set("fordisplay", vv) + } + if v, found := p.p["healthythreshold"]; found { + vv := strconv.Itoa(v.(int)) + u.Set("healthythreshold", vv) + } + if v, found := p.p["intervaltime"]; found { + vv := strconv.Itoa(v.(int)) + u.Set("intervaltime", vv) + } + if v, found := p.p["lbruleid"]; found { + u.Set("lbruleid", v.(string)) + } + if v, found := p.p["pingpath"]; found { + u.Set("pingpath", v.(string)) + } + if v, found := p.p["responsetimeout"]; found { + vv := strconv.Itoa(v.(int)) + u.Set("responsetimeout", vv) + } + if v, found := p.p["unhealthythreshold"]; found { + vv := strconv.Itoa(v.(int)) + u.Set("unhealthythreshold", vv) + } + return u +} + +func (p *CreateLBHealthCheckPolicyParams) SetDescription(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["description"] = v + return +} + +func (p *CreateLBHealthCheckPolicyParams) SetFordisplay(v bool) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["fordisplay"] = v + return +} + +func (p *CreateLBHealthCheckPolicyParams) SetHealthythreshold(v int) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["healthythreshold"] = v + return +} + +func (p *CreateLBHealthCheckPolicyParams) SetIntervaltime(v int) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["intervaltime"] = v + return +} + +func (p *CreateLBHealthCheckPolicyParams) SetLbruleid(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["lbruleid"] = v + return +} + +func (p *CreateLBHealthCheckPolicyParams) SetPingpath(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["pingpath"] = v + return +} + +func (p *CreateLBHealthCheckPolicyParams) SetResponsetimeout(v int) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["responsetimeout"] = v + return +} + +func (p *CreateLBHealthCheckPolicyParams) SetUnhealthythreshold(v int) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["unhealthythreshold"] = v + return +} + +// You should always use this function to get a new CreateLBHealthCheckPolicyParams instance, +// as then you are sure you have configured all required params +func (s *LoadBalancerService) NewCreateLBHealthCheckPolicyParams(lbruleid string) *CreateLBHealthCheckPolicyParams { + p := &CreateLBHealthCheckPolicyParams{} + p.p = make(map[string]interface{}) + p.p["lbruleid"] = lbruleid + return p +} + +// Creates a load balancer health check policy +func (s *LoadBalancerService) CreateLBHealthCheckPolicy(p *CreateLBHealthCheckPolicyParams) (*CreateLBHealthCheckPolicyResponse, error) { + resp, err := s.cs.newRequest("createLBHealthCheckPolicy", p.toURLValues()) + if err != nil { + return nil, err + } + + var r CreateLBHealthCheckPolicyResponse + if err := json.Unmarshal(resp, &r); err != nil { + return nil, err + } + + // If we have a async client, we need to wait for the async result + if s.cs.async { + b, err := s.cs.GetAsyncJobResult(r.JobID, s.cs.timeout) + if err != nil { + if err == AsyncTimeoutErr { + return &r, err + } + return nil, err + } + + b, err = getRawValue(b) + if err != nil { + return nil, err + } + + if err := json.Unmarshal(b, &r); err != nil { + return nil, err + } + } + + return &r, nil +} + +type CreateLBHealthCheckPolicyResponse struct { + JobID string `json:"jobid"` + Account string `json:"account"` + Domain string `json:"domain"` + Domainid string `json:"domainid"` + Healthcheckpolicy []CreateLBHealthCheckPolicyResponseHealthcheckpolicy `json:"healthcheckpolicy"` + Lbruleid string `json:"lbruleid"` + Zoneid string `json:"zoneid"` +} + +type CreateLBHealthCheckPolicyResponseHealthcheckpolicy struct { + Description string `json:"description"` + Fordisplay bool `json:"fordisplay"` + Healthcheckinterval int `json:"healthcheckinterval"` + Healthcheckthresshold int `json:"healthcheckthresshold"` + Id string `json:"id"` + Pingpath string `json:"pingpath"` + Responsetime int `json:"responsetime"` + State string `json:"state"` + Unhealthcheckthresshold int `json:"unhealthcheckthresshold"` +} + +type CreateLBStickinessPolicyParams struct { + p map[string]interface{} +} + +func (p *CreateLBStickinessPolicyParams) toURLValues() url.Values { + u := url.Values{} + if p.p == nil { + return u + } + if v, found := p.p["description"]; found { + u.Set("description", v.(string)) + } + if v, found := p.p["fordisplay"]; found { + vv := strconv.FormatBool(v.(bool)) + u.Set("fordisplay", vv) + } + if v, found := p.p["lbruleid"]; found { + u.Set("lbruleid", v.(string)) + } + if v, found := p.p["methodname"]; found { + u.Set("methodname", v.(string)) + } + if v, found := p.p["name"]; found { + u.Set("name", v.(string)) + } + if v, found := p.p["param"]; found { + i := 0 + for k, vv := range v.(map[string]string) { + u.Set(fmt.Sprintf("param[%d].key", i), k) + u.Set(fmt.Sprintf("param[%d].value", i), vv) + i++ + } + } + return u +} + +func (p *CreateLBStickinessPolicyParams) SetDescription(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["description"] = v + return +} + +func (p *CreateLBStickinessPolicyParams) SetFordisplay(v bool) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["fordisplay"] = v + return +} + +func (p *CreateLBStickinessPolicyParams) SetLbruleid(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["lbruleid"] = v + return +} + +func (p *CreateLBStickinessPolicyParams) SetMethodname(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["methodname"] = v + return +} + +func (p *CreateLBStickinessPolicyParams) SetName(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["name"] = v + return +} + +func (p *CreateLBStickinessPolicyParams) SetParam(v map[string]string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["param"] = v + return +} + +// You should always use this function to get a new CreateLBStickinessPolicyParams instance, +// as then you are sure you have configured all required params +func (s *LoadBalancerService) NewCreateLBStickinessPolicyParams(lbruleid string, methodname string, name string) *CreateLBStickinessPolicyParams { + p := &CreateLBStickinessPolicyParams{} + p.p = make(map[string]interface{}) + p.p["lbruleid"] = lbruleid + p.p["methodname"] = methodname + p.p["name"] = name + return p +} + +// Creates a load balancer stickiness policy +func (s *LoadBalancerService) CreateLBStickinessPolicy(p *CreateLBStickinessPolicyParams) (*CreateLBStickinessPolicyResponse, error) { + resp, err := s.cs.newRequest("createLBStickinessPolicy", p.toURLValues()) + if err != nil { + return nil, err + } + + var r CreateLBStickinessPolicyResponse + if err := json.Unmarshal(resp, &r); err != nil { + return nil, err + } + + // If we have a async client, we need to wait for the async result + if s.cs.async { + b, err := s.cs.GetAsyncJobResult(r.JobID, s.cs.timeout) + if err != nil { + if err == AsyncTimeoutErr { + return &r, err + } + return nil, err + } + + b, err = getRawValue(b) + if err != nil { + return nil, err + } + + if err := json.Unmarshal(b, &r); err != nil { + return nil, err + } + } + + return &r, nil +} + +type CreateLBStickinessPolicyResponse struct { + JobID string `json:"jobid"` + Account string `json:"account"` + Description string `json:"description"` + Domain string `json:"domain"` + Domainid string `json:"domainid"` + Lbruleid string `json:"lbruleid"` + Name string `json:"name"` + State string `json:"state"` + Stickinesspolicy []CreateLBStickinessPolicyResponseStickinesspolicy `json:"stickinesspolicy"` + Zoneid string `json:"zoneid"` +} + +type CreateLBStickinessPolicyResponseStickinesspolicy struct { + Description string `json:"description"` + Fordisplay bool `json:"fordisplay"` + Id string `json:"id"` + Methodname string `json:"methodname"` + Name string `json:"name"` + Params map[string]string `json:"params"` + State string `json:"state"` +} + +type CreateLoadBalancerParams struct { + p map[string]interface{} +} + +func (p *CreateLoadBalancerParams) toURLValues() url.Values { + u := url.Values{} + if p.p == nil { + return u + } + if v, found := p.p["algorithm"]; found { + u.Set("algorithm", v.(string)) + } + if v, found := p.p["description"]; found { + u.Set("description", v.(string)) + } + if v, found := p.p["fordisplay"]; found { + vv := strconv.FormatBool(v.(bool)) + u.Set("fordisplay", vv) + } + if v, found := p.p["instanceport"]; found { + vv := strconv.Itoa(v.(int)) + u.Set("instanceport", vv) + } + if v, found := p.p["name"]; found { + u.Set("name", v.(string)) + } + if v, found := p.p["networkid"]; found { + u.Set("networkid", v.(string)) + } + if v, found := p.p["scheme"]; found { + u.Set("scheme", v.(string)) + } + if v, found := p.p["sourceipaddress"]; found { + u.Set("sourceipaddress", v.(string)) + } + if v, found := p.p["sourceipaddressnetworkid"]; found { + u.Set("sourceipaddressnetworkid", v.(string)) + } + if v, found := p.p["sourceport"]; found { + vv := strconv.Itoa(v.(int)) + u.Set("sourceport", vv) + } + return u +} + +func (p *CreateLoadBalancerParams) SetAlgorithm(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["algorithm"] = v + return +} + +func (p *CreateLoadBalancerParams) SetDescription(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["description"] = v + return +} + +func (p *CreateLoadBalancerParams) SetFordisplay(v bool) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["fordisplay"] = v + return +} + +func (p *CreateLoadBalancerParams) SetInstanceport(v int) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["instanceport"] = v + return +} + +func (p *CreateLoadBalancerParams) SetName(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["name"] = v + return +} + +func (p *CreateLoadBalancerParams) SetNetworkid(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["networkid"] = v + return +} + +func (p *CreateLoadBalancerParams) SetScheme(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["scheme"] = v + return +} + +func (p *CreateLoadBalancerParams) SetSourceipaddress(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["sourceipaddress"] = v + return +} + +func (p *CreateLoadBalancerParams) SetSourceipaddressnetworkid(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["sourceipaddressnetworkid"] = v + return +} + +func (p *CreateLoadBalancerParams) SetSourceport(v int) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["sourceport"] = v + return +} + +// You should always use this function to get a new CreateLoadBalancerParams instance, +// as then you are sure you have configured all required params +func (s *LoadBalancerService) NewCreateLoadBalancerParams(algorithm string, instanceport int, name string, networkid string, scheme string, sourceipaddressnetworkid string, sourceport int) *CreateLoadBalancerParams { + p := &CreateLoadBalancerParams{} + p.p = make(map[string]interface{}) + p.p["algorithm"] = algorithm + p.p["instanceport"] = instanceport + p.p["name"] = name + p.p["networkid"] = networkid + p.p["scheme"] = scheme + p.p["sourceipaddressnetworkid"] = sourceipaddressnetworkid + p.p["sourceport"] = sourceport + return p +} + +// Creates a load balancer +func (s *LoadBalancerService) CreateLoadBalancer(p *CreateLoadBalancerParams) (*CreateLoadBalancerResponse, error) { + resp, err := s.cs.newRequest("createLoadBalancer", p.toURLValues()) + if err != nil { + return nil, err + } + + var r CreateLoadBalancerResponse + if err := json.Unmarshal(resp, &r); err != nil { + return nil, err + } + + // If we have a async client, we need to wait for the async result + if s.cs.async { + b, err := s.cs.GetAsyncJobResult(r.JobID, s.cs.timeout) + if err != nil { + if err == AsyncTimeoutErr { + return &r, err + } + return nil, err + } + + b, err = getRawValue(b) + if err != nil { + return nil, err + } + + if err := json.Unmarshal(b, &r); err != nil { + return nil, err + } + } + + return &r, nil +} + +type CreateLoadBalancerResponse struct { + JobID string `json:"jobid"` + Account string `json:"account"` + Algorithm string `json:"algorithm"` + Description string `json:"description"` + Domain string `json:"domain"` + Domainid string `json:"domainid"` + Fordisplay bool `json:"fordisplay"` + Id string `json:"id"` + Loadbalancerinstance []CreateLoadBalancerResponseLoadbalancerinstance `json:"loadbalancerinstance"` + Loadbalancerrule []CreateLoadBalancerResponseLoadbalancerrule `json:"loadbalancerrule"` + Name string `json:"name"` + Networkid string `json:"networkid"` + Project string `json:"project"` + Projectid string `json:"projectid"` + Sourceipaddress string `json:"sourceipaddress"` + Sourceipaddressnetworkid string `json:"sourceipaddressnetworkid"` + Tags []Tags `json:"tags"` +} + +type CreateLoadBalancerResponseLoadbalancerrule struct { + Instanceport int `json:"instanceport"` + Sourceport int `json:"sourceport"` + State string `json:"state"` +} + +type CreateLoadBalancerResponseLoadbalancerinstance struct { + Id string `json:"id"` + Ipaddress string `json:"ipaddress"` + Name string `json:"name"` + State string `json:"state"` +} + type CreateLoadBalancerRuleParams struct { p map[string]interface{} } @@ -238,49 +1558,40 @@ func (s *LoadBalancerService) CreateLoadBalancerRule(p *CreateLoadBalancerRulePa return nil, err } } + return &r, nil } type CreateLoadBalancerRuleResponse struct { - JobID string `json:"jobid,omitempty"` - Account string `json:"account,omitempty"` - Algorithm string `json:"algorithm,omitempty"` - Cidrlist string `json:"cidrlist,omitempty"` - Description string `json:"description,omitempty"` - Domain string `json:"domain,omitempty"` - Domainid string `json:"domainid,omitempty"` - Fordisplay bool `json:"fordisplay,omitempty"` - Id string `json:"id,omitempty"` - Name string `json:"name,omitempty"` - Networkid string `json:"networkid,omitempty"` - Privateport string `json:"privateport,omitempty"` - Project string `json:"project,omitempty"` - Projectid string `json:"projectid,omitempty"` - Protocol string `json:"protocol,omitempty"` - Publicip string `json:"publicip,omitempty"` - Publicipid string `json:"publicipid,omitempty"` - Publicport string `json:"publicport,omitempty"` - State string `json:"state,omitempty"` - Tags []struct { - Account string `json:"account,omitempty"` - Customer string `json:"customer,omitempty"` - Domain string `json:"domain,omitempty"` - Domainid string `json:"domainid,omitempty"` - Key string `json:"key,omitempty"` - Project string `json:"project,omitempty"` - Projectid string `json:"projectid,omitempty"` - Resourceid string `json:"resourceid,omitempty"` - Resourcetype string `json:"resourcetype,omitempty"` - Value string `json:"value,omitempty"` - } `json:"tags,omitempty"` - Zoneid string `json:"zoneid,omitempty"` + JobID string `json:"jobid"` + Account string `json:"account"` + Algorithm string `json:"algorithm"` + Cidrlist string `json:"cidrlist"` + Description string `json:"description"` + Domain string `json:"domain"` + Domainid string `json:"domainid"` + Fordisplay bool `json:"fordisplay"` + Id string `json:"id"` + Name string `json:"name"` + Networkid string `json:"networkid"` + Privateport string `json:"privateport"` + Project string `json:"project"` + Projectid string `json:"projectid"` + Protocol string `json:"protocol"` + Publicip string `json:"publicip"` + Publicipid string `json:"publicipid"` + Publicport string `json:"publicport"` + State string `json:"state"` + Tags []Tags `json:"tags"` + Zoneid string `json:"zoneid"` + Zonename string `json:"zonename"` } -type DeleteLoadBalancerRuleParams struct { +type DeleteGlobalLoadBalancerRuleParams struct { p map[string]interface{} } -func (p *DeleteLoadBalancerRuleParams) toURLValues() url.Values { +func (p *DeleteGlobalLoadBalancerRuleParams) toURLValues() url.Values { u := url.Values{} if p.p == nil { return u @@ -291,7 +1602,7 @@ func (p *DeleteLoadBalancerRuleParams) toURLValues() url.Values { return u } -func (p *DeleteLoadBalancerRuleParams) SetId(v string) { +func (p *DeleteGlobalLoadBalancerRuleParams) SetId(v string) { if p.p == nil { p.p = make(map[string]interface{}) } @@ -299,23 +1610,23 @@ func (p *DeleteLoadBalancerRuleParams) SetId(v string) { return } -// You should always use this function to get a new DeleteLoadBalancerRuleParams instance, +// You should always use this function to get a new DeleteGlobalLoadBalancerRuleParams instance, // as then you are sure you have configured all required params -func (s *LoadBalancerService) NewDeleteLoadBalancerRuleParams(id string) *DeleteLoadBalancerRuleParams { - p := &DeleteLoadBalancerRuleParams{} +func (s *LoadBalancerService) NewDeleteGlobalLoadBalancerRuleParams(id string) *DeleteGlobalLoadBalancerRuleParams { + p := &DeleteGlobalLoadBalancerRuleParams{} p.p = make(map[string]interface{}) p.p["id"] = id return p } -// Deletes a load balancer rule. -func (s *LoadBalancerService) DeleteLoadBalancerRule(p *DeleteLoadBalancerRuleParams) (*DeleteLoadBalancerRuleResponse, error) { - resp, err := s.cs.newRequest("deleteLoadBalancerRule", p.toURLValues()) +// Deletes a global load balancer rule. +func (s *LoadBalancerService) DeleteGlobalLoadBalancerRule(p *DeleteGlobalLoadBalancerRuleParams) (*DeleteGlobalLoadBalancerRuleResponse, error) { + resp, err := s.cs.newRequest("deleteGlobalLoadBalancerRule", p.toURLValues()) if err != nil { return nil, err } - var r DeleteLoadBalancerRuleResponse + var r DeleteGlobalLoadBalancerRuleResponse if err := json.Unmarshal(resp, &r); err != nil { return nil, err } @@ -334,20 +1645,21 @@ func (s *LoadBalancerService) DeleteLoadBalancerRule(p *DeleteLoadBalancerRulePa return nil, err } } + return &r, nil } -type DeleteLoadBalancerRuleResponse struct { - JobID string `json:"jobid,omitempty"` - Displaytext string `json:"displaytext,omitempty"` - Success bool `json:"success,omitempty"` +type DeleteGlobalLoadBalancerRuleResponse struct { + JobID string `json:"jobid"` + Displaytext string `json:"displaytext"` + Success bool `json:"success"` } -type RemoveFromLoadBalancerRuleParams struct { +type DeleteLBHealthCheckPolicyParams struct { p map[string]interface{} } -func (p *RemoveFromLoadBalancerRuleParams) toURLValues() url.Values { +func (p *DeleteLBHealthCheckPolicyParams) toURLValues() url.Values { u := url.Values{} if p.p == nil { return u @@ -355,22 +1667,10 @@ func (p *RemoveFromLoadBalancerRuleParams) toURLValues() url.Values { if v, found := p.p["id"]; found { u.Set("id", v.(string)) } - if v, found := p.p["virtualmachineids"]; found { - vv := strings.Join(v.([]string), ",") - u.Set("virtualmachineids", vv) - } - if v, found := p.p["vmidipmap"]; found { - i := 0 - for k, vv := range v.(map[string]string) { - u.Set(fmt.Sprintf("vmidipmap[%d].key", i), k) - u.Set(fmt.Sprintf("vmidipmap[%d].value", i), vv) - i++ - } - } return u } -func (p *RemoveFromLoadBalancerRuleParams) SetId(v string) { +func (p *DeleteLBHealthCheckPolicyParams) SetId(v string) { if p.p == nil { p.p = make(map[string]interface{}) } @@ -378,39 +1678,23 @@ func (p *RemoveFromLoadBalancerRuleParams) SetId(v string) { return } -func (p *RemoveFromLoadBalancerRuleParams) SetVirtualmachineids(v []string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["virtualmachineids"] = v - return -} - -func (p *RemoveFromLoadBalancerRuleParams) SetVmidipmap(v map[string]string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["vmidipmap"] = v - return -} - -// You should always use this function to get a new RemoveFromLoadBalancerRuleParams instance, +// You should always use this function to get a new DeleteLBHealthCheckPolicyParams instance, // as then you are sure you have configured all required params -func (s *LoadBalancerService) NewRemoveFromLoadBalancerRuleParams(id string) *RemoveFromLoadBalancerRuleParams { - p := &RemoveFromLoadBalancerRuleParams{} +func (s *LoadBalancerService) NewDeleteLBHealthCheckPolicyParams(id string) *DeleteLBHealthCheckPolicyParams { + p := &DeleteLBHealthCheckPolicyParams{} p.p = make(map[string]interface{}) p.p["id"] = id return p } -// Removes a virtual machine or a list of virtual machines from a load balancer rule. -func (s *LoadBalancerService) RemoveFromLoadBalancerRule(p *RemoveFromLoadBalancerRuleParams) (*RemoveFromLoadBalancerRuleResponse, error) { - resp, err := s.cs.newRequest("removeFromLoadBalancerRule", p.toURLValues()) +// Deletes a load balancer health check policy. +func (s *LoadBalancerService) DeleteLBHealthCheckPolicy(p *DeleteLBHealthCheckPolicyParams) (*DeleteLBHealthCheckPolicyResponse, error) { + resp, err := s.cs.newRequest("deleteLBHealthCheckPolicy", p.toURLValues()) if err != nil { return nil, err } - var r RemoveFromLoadBalancerRuleResponse + var r DeleteLBHealthCheckPolicyResponse if err := json.Unmarshal(resp, &r); err != nil { return nil, err } @@ -429,368 +1713,14 @@ func (s *LoadBalancerService) RemoveFromLoadBalancerRule(p *RemoveFromLoadBalanc return nil, err } } + return &r, nil } -type RemoveFromLoadBalancerRuleResponse struct { - JobID string `json:"jobid,omitempty"` - Displaytext string `json:"displaytext,omitempty"` - Success bool `json:"success,omitempty"` -} - -type AssignToLoadBalancerRuleParams struct { - p map[string]interface{} -} - -func (p *AssignToLoadBalancerRuleParams) toURLValues() url.Values { - u := url.Values{} - if p.p == nil { - return u - } - if v, found := p.p["id"]; found { - u.Set("id", v.(string)) - } - if v, found := p.p["virtualmachineids"]; found { - vv := strings.Join(v.([]string), ",") - u.Set("virtualmachineids", vv) - } - if v, found := p.p["vmidipmap"]; found { - i := 0 - for k, vv := range v.(map[string]string) { - u.Set(fmt.Sprintf("vmidipmap[%d].key", i), k) - u.Set(fmt.Sprintf("vmidipmap[%d].value", i), vv) - i++ - } - } - return u -} - -func (p *AssignToLoadBalancerRuleParams) SetId(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["id"] = v - return -} - -func (p *AssignToLoadBalancerRuleParams) SetVirtualmachineids(v []string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["virtualmachineids"] = v - return -} - -func (p *AssignToLoadBalancerRuleParams) SetVmidipmap(v map[string]string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["vmidipmap"] = v - return -} - -// You should always use this function to get a new AssignToLoadBalancerRuleParams instance, -// as then you are sure you have configured all required params -func (s *LoadBalancerService) NewAssignToLoadBalancerRuleParams(id string) *AssignToLoadBalancerRuleParams { - p := &AssignToLoadBalancerRuleParams{} - p.p = make(map[string]interface{}) - p.p["id"] = id - return p -} - -// Assigns virtual machine or a list of virtual machines to a load balancer rule. -func (s *LoadBalancerService) AssignToLoadBalancerRule(p *AssignToLoadBalancerRuleParams) (*AssignToLoadBalancerRuleResponse, error) { - resp, err := s.cs.newRequest("assignToLoadBalancerRule", p.toURLValues()) - if err != nil { - return nil, err - } - - var r AssignToLoadBalancerRuleResponse - if err := json.Unmarshal(resp, &r); err != nil { - return nil, err - } - - // If we have a async client, we need to wait for the async result - if s.cs.async { - b, err := s.cs.GetAsyncJobResult(r.JobID, s.cs.timeout) - if err != nil { - if err == AsyncTimeoutErr { - return &r, err - } - return nil, err - } - - if err := json.Unmarshal(b, &r); err != nil { - return nil, err - } - } - return &r, nil -} - -type AssignToLoadBalancerRuleResponse struct { - JobID string `json:"jobid,omitempty"` - Displaytext string `json:"displaytext,omitempty"` - Success bool `json:"success,omitempty"` -} - -type CreateLBStickinessPolicyParams struct { - p map[string]interface{} -} - -func (p *CreateLBStickinessPolicyParams) toURLValues() url.Values { - u := url.Values{} - if p.p == nil { - return u - } - if v, found := p.p["description"]; found { - u.Set("description", v.(string)) - } - if v, found := p.p["fordisplay"]; found { - vv := strconv.FormatBool(v.(bool)) - u.Set("fordisplay", vv) - } - if v, found := p.p["lbruleid"]; found { - u.Set("lbruleid", v.(string)) - } - if v, found := p.p["methodname"]; found { - u.Set("methodname", v.(string)) - } - if v, found := p.p["name"]; found { - u.Set("name", v.(string)) - } - if v, found := p.p["param"]; found { - i := 0 - for k, vv := range v.(map[string]string) { - u.Set(fmt.Sprintf("param[%d].key", i), k) - u.Set(fmt.Sprintf("param[%d].value", i), vv) - i++ - } - } - return u -} - -func (p *CreateLBStickinessPolicyParams) SetDescription(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["description"] = v - return -} - -func (p *CreateLBStickinessPolicyParams) SetFordisplay(v bool) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["fordisplay"] = v - return -} - -func (p *CreateLBStickinessPolicyParams) SetLbruleid(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["lbruleid"] = v - return -} - -func (p *CreateLBStickinessPolicyParams) SetMethodname(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["methodname"] = v - return -} - -func (p *CreateLBStickinessPolicyParams) SetName(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["name"] = v - return -} - -func (p *CreateLBStickinessPolicyParams) SetParam(v map[string]string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["param"] = v - return -} - -// You should always use this function to get a new CreateLBStickinessPolicyParams instance, -// as then you are sure you have configured all required params -func (s *LoadBalancerService) NewCreateLBStickinessPolicyParams(lbruleid string, methodname string, name string) *CreateLBStickinessPolicyParams { - p := &CreateLBStickinessPolicyParams{} - p.p = make(map[string]interface{}) - p.p["lbruleid"] = lbruleid - p.p["methodname"] = methodname - p.p["name"] = name - return p -} - -// Creates a load balancer stickiness policy -func (s *LoadBalancerService) CreateLBStickinessPolicy(p *CreateLBStickinessPolicyParams) (*CreateLBStickinessPolicyResponse, error) { - resp, err := s.cs.newRequest("createLBStickinessPolicy", p.toURLValues()) - if err != nil { - return nil, err - } - - var r CreateLBStickinessPolicyResponse - if err := json.Unmarshal(resp, &r); err != nil { - return nil, err - } - - // If we have a async client, we need to wait for the async result - if s.cs.async { - b, err := s.cs.GetAsyncJobResult(r.JobID, s.cs.timeout) - if err != nil { - if err == AsyncTimeoutErr { - return &r, err - } - return nil, err - } - - b, err = getRawValue(b) - if err != nil { - return nil, err - } - - if err := json.Unmarshal(b, &r); err != nil { - return nil, err - } - } - return &r, nil -} - -type CreateLBStickinessPolicyResponse struct { - JobID string `json:"jobid,omitempty"` - Account string `json:"account,omitempty"` - Description string `json:"description,omitempty"` - Domain string `json:"domain,omitempty"` - Domainid string `json:"domainid,omitempty"` - Lbruleid string `json:"lbruleid,omitempty"` - Name string `json:"name,omitempty"` - State string `json:"state,omitempty"` - Stickinesspolicy []struct { - Description string `json:"description,omitempty"` - Fordisplay bool `json:"fordisplay,omitempty"` - Id string `json:"id,omitempty"` - Methodname string `json:"methodname,omitempty"` - Name string `json:"name,omitempty"` - Params map[string]string `json:"params,omitempty"` - State string `json:"state,omitempty"` - } `json:"stickinesspolicy,omitempty"` - Zoneid string `json:"zoneid,omitempty"` -} - -type UpdateLBStickinessPolicyParams struct { - p map[string]interface{} -} - -func (p *UpdateLBStickinessPolicyParams) toURLValues() url.Values { - u := url.Values{} - if p.p == nil { - return u - } - if v, found := p.p["customid"]; found { - u.Set("customid", v.(string)) - } - if v, found := p.p["fordisplay"]; found { - vv := strconv.FormatBool(v.(bool)) - u.Set("fordisplay", vv) - } - if v, found := p.p["id"]; found { - u.Set("id", v.(string)) - } - return u -} - -func (p *UpdateLBStickinessPolicyParams) SetCustomid(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["customid"] = v - return -} - -func (p *UpdateLBStickinessPolicyParams) SetFordisplay(v bool) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["fordisplay"] = v - return -} - -func (p *UpdateLBStickinessPolicyParams) SetId(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["id"] = v - return -} - -// You should always use this function to get a new UpdateLBStickinessPolicyParams instance, -// as then you are sure you have configured all required params -func (s *LoadBalancerService) NewUpdateLBStickinessPolicyParams(id string) *UpdateLBStickinessPolicyParams { - p := &UpdateLBStickinessPolicyParams{} - p.p = make(map[string]interface{}) - p.p["id"] = id - return p -} - -// Updates load balancer stickiness policy -func (s *LoadBalancerService) UpdateLBStickinessPolicy(p *UpdateLBStickinessPolicyParams) (*UpdateLBStickinessPolicyResponse, error) { - resp, err := s.cs.newRequest("updateLBStickinessPolicy", p.toURLValues()) - if err != nil { - return nil, err - } - - var r UpdateLBStickinessPolicyResponse - if err := json.Unmarshal(resp, &r); err != nil { - return nil, err - } - - // If we have a async client, we need to wait for the async result - if s.cs.async { - b, err := s.cs.GetAsyncJobResult(r.JobID, s.cs.timeout) - if err != nil { - if err == AsyncTimeoutErr { - return &r, err - } - return nil, err - } - - b, err = getRawValue(b) - if err != nil { - return nil, err - } - - if err := json.Unmarshal(b, &r); err != nil { - return nil, err - } - } - return &r, nil -} - -type UpdateLBStickinessPolicyResponse struct { - JobID string `json:"jobid,omitempty"` - Account string `json:"account,omitempty"` - Description string `json:"description,omitempty"` - Domain string `json:"domain,omitempty"` - Domainid string `json:"domainid,omitempty"` - Lbruleid string `json:"lbruleid,omitempty"` - Name string `json:"name,omitempty"` - State string `json:"state,omitempty"` - Stickinesspolicy []struct { - Description string `json:"description,omitempty"` - Fordisplay bool `json:"fordisplay,omitempty"` - Id string `json:"id,omitempty"` - Methodname string `json:"methodname,omitempty"` - Name string `json:"name,omitempty"` - Params map[string]string `json:"params,omitempty"` - State string `json:"state,omitempty"` - } `json:"stickinesspolicy,omitempty"` - Zoneid string `json:"zoneid,omitempty"` +type DeleteLBHealthCheckPolicyResponse struct { + JobID string `json:"jobid"` + Displaytext string `json:"displaytext"` + Success bool `json:"success"` } type DeleteLBStickinessPolicyParams struct { @@ -851,13 +1781,1061 @@ func (s *LoadBalancerService) DeleteLBStickinessPolicy(p *DeleteLBStickinessPoli return nil, err } } + return &r, nil } type DeleteLBStickinessPolicyResponse struct { - JobID string `json:"jobid,omitempty"` - Displaytext string `json:"displaytext,omitempty"` - Success bool `json:"success,omitempty"` + JobID string `json:"jobid"` + Displaytext string `json:"displaytext"` + Success bool `json:"success"` +} + +type DeleteLoadBalancerParams struct { + p map[string]interface{} +} + +func (p *DeleteLoadBalancerParams) toURLValues() url.Values { + u := url.Values{} + if p.p == nil { + return u + } + if v, found := p.p["id"]; found { + u.Set("id", v.(string)) + } + return u +} + +func (p *DeleteLoadBalancerParams) SetId(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["id"] = v + return +} + +// You should always use this function to get a new DeleteLoadBalancerParams instance, +// as then you are sure you have configured all required params +func (s *LoadBalancerService) NewDeleteLoadBalancerParams(id string) *DeleteLoadBalancerParams { + p := &DeleteLoadBalancerParams{} + p.p = make(map[string]interface{}) + p.p["id"] = id + return p +} + +// Deletes a load balancer +func (s *LoadBalancerService) DeleteLoadBalancer(p *DeleteLoadBalancerParams) (*DeleteLoadBalancerResponse, error) { + resp, err := s.cs.newRequest("deleteLoadBalancer", p.toURLValues()) + if err != nil { + return nil, err + } + + var r DeleteLoadBalancerResponse + if err := json.Unmarshal(resp, &r); err != nil { + return nil, err + } + + // If we have a async client, we need to wait for the async result + if s.cs.async { + b, err := s.cs.GetAsyncJobResult(r.JobID, s.cs.timeout) + if err != nil { + if err == AsyncTimeoutErr { + return &r, err + } + return nil, err + } + + if err := json.Unmarshal(b, &r); err != nil { + return nil, err + } + } + + return &r, nil +} + +type DeleteLoadBalancerResponse struct { + JobID string `json:"jobid"` + Displaytext string `json:"displaytext"` + Success bool `json:"success"` +} + +type DeleteLoadBalancerRuleParams struct { + p map[string]interface{} +} + +func (p *DeleteLoadBalancerRuleParams) toURLValues() url.Values { + u := url.Values{} + if p.p == nil { + return u + } + if v, found := p.p["id"]; found { + u.Set("id", v.(string)) + } + return u +} + +func (p *DeleteLoadBalancerRuleParams) SetId(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["id"] = v + return +} + +// You should always use this function to get a new DeleteLoadBalancerRuleParams instance, +// as then you are sure you have configured all required params +func (s *LoadBalancerService) NewDeleteLoadBalancerRuleParams(id string) *DeleteLoadBalancerRuleParams { + p := &DeleteLoadBalancerRuleParams{} + p.p = make(map[string]interface{}) + p.p["id"] = id + return p +} + +// Deletes a load balancer rule. +func (s *LoadBalancerService) DeleteLoadBalancerRule(p *DeleteLoadBalancerRuleParams) (*DeleteLoadBalancerRuleResponse, error) { + resp, err := s.cs.newRequest("deleteLoadBalancerRule", p.toURLValues()) + if err != nil { + return nil, err + } + + var r DeleteLoadBalancerRuleResponse + if err := json.Unmarshal(resp, &r); err != nil { + return nil, err + } + + // If we have a async client, we need to wait for the async result + if s.cs.async { + b, err := s.cs.GetAsyncJobResult(r.JobID, s.cs.timeout) + if err != nil { + if err == AsyncTimeoutErr { + return &r, err + } + return nil, err + } + + if err := json.Unmarshal(b, &r); err != nil { + return nil, err + } + } + + return &r, nil +} + +type DeleteLoadBalancerRuleResponse struct { + JobID string `json:"jobid"` + Displaytext string `json:"displaytext"` + Success bool `json:"success"` +} + +type DeleteNetscalerLoadBalancerParams struct { + p map[string]interface{} +} + +func (p *DeleteNetscalerLoadBalancerParams) toURLValues() url.Values { + u := url.Values{} + if p.p == nil { + return u + } + if v, found := p.p["lbdeviceid"]; found { + u.Set("lbdeviceid", v.(string)) + } + return u +} + +func (p *DeleteNetscalerLoadBalancerParams) SetLbdeviceid(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["lbdeviceid"] = v + return +} + +// You should always use this function to get a new DeleteNetscalerLoadBalancerParams instance, +// as then you are sure you have configured all required params +func (s *LoadBalancerService) NewDeleteNetscalerLoadBalancerParams(lbdeviceid string) *DeleteNetscalerLoadBalancerParams { + p := &DeleteNetscalerLoadBalancerParams{} + p.p = make(map[string]interface{}) + p.p["lbdeviceid"] = lbdeviceid + return p +} + +// delete a netscaler load balancer device +func (s *LoadBalancerService) DeleteNetscalerLoadBalancer(p *DeleteNetscalerLoadBalancerParams) (*DeleteNetscalerLoadBalancerResponse, error) { + resp, err := s.cs.newRequest("deleteNetscalerLoadBalancer", p.toURLValues()) + if err != nil { + return nil, err + } + + var r DeleteNetscalerLoadBalancerResponse + if err := json.Unmarshal(resp, &r); err != nil { + return nil, err + } + + // If we have a async client, we need to wait for the async result + if s.cs.async { + b, err := s.cs.GetAsyncJobResult(r.JobID, s.cs.timeout) + if err != nil { + if err == AsyncTimeoutErr { + return &r, err + } + return nil, err + } + + if err := json.Unmarshal(b, &r); err != nil { + return nil, err + } + } + + return &r, nil +} + +type DeleteNetscalerLoadBalancerResponse struct { + JobID string `json:"jobid"` + Displaytext string `json:"displaytext"` + Success bool `json:"success"` +} + +type DeleteSslCertParams struct { + p map[string]interface{} +} + +func (p *DeleteSslCertParams) toURLValues() url.Values { + u := url.Values{} + if p.p == nil { + return u + } + if v, found := p.p["id"]; found { + u.Set("id", v.(string)) + } + return u +} + +func (p *DeleteSslCertParams) SetId(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["id"] = v + return +} + +// You should always use this function to get a new DeleteSslCertParams instance, +// as then you are sure you have configured all required params +func (s *LoadBalancerService) NewDeleteSslCertParams(id string) *DeleteSslCertParams { + p := &DeleteSslCertParams{} + p.p = make(map[string]interface{}) + p.p["id"] = id + return p +} + +// Delete a certificate to CloudStack +func (s *LoadBalancerService) DeleteSslCert(p *DeleteSslCertParams) (*DeleteSslCertResponse, error) { + resp, err := s.cs.newRequest("deleteSslCert", p.toURLValues()) + if err != nil { + return nil, err + } + + var r DeleteSslCertResponse + if err := json.Unmarshal(resp, &r); err != nil { + return nil, err + } + + return &r, nil +} + +type DeleteSslCertResponse struct { + Displaytext string `json:"displaytext"` + Success bool `json:"success"` +} + +func (r *DeleteSslCertResponse) UnmarshalJSON(b []byte) error { + var m map[string]interface{} + err := json.Unmarshal(b, &m) + if err != nil { + return err + } + + if success, ok := m["success"].(string); ok { + m["success"] = success == "true" + b, err = json.Marshal(m) + if err != nil { + return err + } + } + + type alias DeleteSslCertResponse + return json.Unmarshal(b, (*alias)(r)) +} + +type ListGlobalLoadBalancerRulesParams struct { + p map[string]interface{} +} + +func (p *ListGlobalLoadBalancerRulesParams) toURLValues() url.Values { + u := url.Values{} + if p.p == nil { + return u + } + if v, found := p.p["account"]; found { + u.Set("account", v.(string)) + } + if v, found := p.p["domainid"]; found { + u.Set("domainid", v.(string)) + } + if v, found := p.p["id"]; found { + u.Set("id", v.(string)) + } + if v, found := p.p["isrecursive"]; found { + vv := strconv.FormatBool(v.(bool)) + u.Set("isrecursive", vv) + } + if v, found := p.p["keyword"]; found { + u.Set("keyword", v.(string)) + } + if v, found := p.p["listall"]; found { + vv := strconv.FormatBool(v.(bool)) + u.Set("listall", vv) + } + if v, found := p.p["page"]; found { + vv := strconv.Itoa(v.(int)) + u.Set("page", vv) + } + if v, found := p.p["pagesize"]; found { + vv := strconv.Itoa(v.(int)) + u.Set("pagesize", vv) + } + if v, found := p.p["projectid"]; found { + u.Set("projectid", v.(string)) + } + if v, found := p.p["regionid"]; found { + vv := strconv.Itoa(v.(int)) + u.Set("regionid", vv) + } + if v, found := p.p["tags"]; found { + i := 0 + for k, vv := range v.(map[string]string) { + u.Set(fmt.Sprintf("tags[%d].key", i), k) + u.Set(fmt.Sprintf("tags[%d].value", i), vv) + i++ + } + } + return u +} + +func (p *ListGlobalLoadBalancerRulesParams) SetAccount(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["account"] = v + return +} + +func (p *ListGlobalLoadBalancerRulesParams) SetDomainid(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["domainid"] = v + return +} + +func (p *ListGlobalLoadBalancerRulesParams) SetId(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["id"] = v + return +} + +func (p *ListGlobalLoadBalancerRulesParams) SetIsrecursive(v bool) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["isrecursive"] = v + return +} + +func (p *ListGlobalLoadBalancerRulesParams) SetKeyword(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["keyword"] = v + return +} + +func (p *ListGlobalLoadBalancerRulesParams) SetListall(v bool) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["listall"] = v + return +} + +func (p *ListGlobalLoadBalancerRulesParams) SetPage(v int) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["page"] = v + return +} + +func (p *ListGlobalLoadBalancerRulesParams) SetPagesize(v int) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["pagesize"] = v + return +} + +func (p *ListGlobalLoadBalancerRulesParams) SetProjectid(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["projectid"] = v + return +} + +func (p *ListGlobalLoadBalancerRulesParams) SetRegionid(v int) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["regionid"] = v + return +} + +func (p *ListGlobalLoadBalancerRulesParams) SetTags(v map[string]string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["tags"] = v + return +} + +// You should always use this function to get a new ListGlobalLoadBalancerRulesParams instance, +// as then you are sure you have configured all required params +func (s *LoadBalancerService) NewListGlobalLoadBalancerRulesParams() *ListGlobalLoadBalancerRulesParams { + p := &ListGlobalLoadBalancerRulesParams{} + p.p = make(map[string]interface{}) + return p +} + +// This is a courtesy helper function, which in some cases may not work as expected! +func (s *LoadBalancerService) GetGlobalLoadBalancerRuleID(keyword string, opts ...OptionFunc) (string, int, error) { + p := &ListGlobalLoadBalancerRulesParams{} + p.p = make(map[string]interface{}) + + p.p["keyword"] = keyword + + for _, fn := range append(s.cs.options, opts...) { + if err := fn(s.cs, p); err != nil { + return "", -1, err + } + } + + l, err := s.ListGlobalLoadBalancerRules(p) + if err != nil { + return "", -1, err + } + + if l.Count == 0 { + return "", l.Count, fmt.Errorf("No match found for %s: %+v", keyword, l) + } + + if l.Count == 1 { + return l.GlobalLoadBalancerRules[0].Id, l.Count, nil + } + + if l.Count > 1 { + for _, v := range l.GlobalLoadBalancerRules { + if v.Name == keyword { + return v.Id, l.Count, nil + } + } + } + return "", l.Count, fmt.Errorf("Could not find an exact match for %s: %+v", keyword, l) +} + +// This is a courtesy helper function, which in some cases may not work as expected! +func (s *LoadBalancerService) GetGlobalLoadBalancerRuleByName(name string, opts ...OptionFunc) (*GlobalLoadBalancerRule, int, error) { + id, count, err := s.GetGlobalLoadBalancerRuleID(name, opts...) + if err != nil { + return nil, count, err + } + + r, count, err := s.GetGlobalLoadBalancerRuleByID(id, opts...) + if err != nil { + return nil, count, err + } + return r, count, nil +} + +// This is a courtesy helper function, which in some cases may not work as expected! +func (s *LoadBalancerService) GetGlobalLoadBalancerRuleByID(id string, opts ...OptionFunc) (*GlobalLoadBalancerRule, int, error) { + p := &ListGlobalLoadBalancerRulesParams{} + p.p = make(map[string]interface{}) + + p.p["id"] = id + + for _, fn := range append(s.cs.options, opts...) { + if err := fn(s.cs, p); err != nil { + return nil, -1, err + } + } + + l, err := s.ListGlobalLoadBalancerRules(p) + if err != nil { + if strings.Contains(err.Error(), fmt.Sprintf( + "Invalid parameter id value=%s due to incorrect long value format, "+ + "or entity does not exist", id)) { + return nil, 0, fmt.Errorf("No match found for %s: %+v", id, l) + } + return nil, -1, err + } + + if l.Count == 0 { + return nil, l.Count, fmt.Errorf("No match found for %s: %+v", id, l) + } + + if l.Count == 1 { + return l.GlobalLoadBalancerRules[0], l.Count, nil + } + return nil, l.Count, fmt.Errorf("There is more then one result for GlobalLoadBalancerRule UUID: %s!", id) +} + +// Lists load balancer rules. +func (s *LoadBalancerService) ListGlobalLoadBalancerRules(p *ListGlobalLoadBalancerRulesParams) (*ListGlobalLoadBalancerRulesResponse, error) { + resp, err := s.cs.newRequest("listGlobalLoadBalancerRules", p.toURLValues()) + if err != nil { + return nil, err + } + + var r ListGlobalLoadBalancerRulesResponse + if err := json.Unmarshal(resp, &r); err != nil { + return nil, err + } + + return &r, nil +} + +type ListGlobalLoadBalancerRulesResponse struct { + Count int `json:"count"` + GlobalLoadBalancerRules []*GlobalLoadBalancerRule `json:"globalloadbalancerrule"` +} + +type GlobalLoadBalancerRule struct { + Account string `json:"account"` + Description string `json:"description"` + Domain string `json:"domain"` + Domainid string `json:"domainid"` + Gslbdomainname string `json:"gslbdomainname"` + Gslblbmethod string `json:"gslblbmethod"` + Gslbservicetype string `json:"gslbservicetype"` + Gslbstickysessionmethodname string `json:"gslbstickysessionmethodname"` + Id string `json:"id"` + Loadbalancerrule []GlobalLoadBalancerRuleLoadbalancerrule `json:"loadbalancerrule"` + Name string `json:"name"` + Project string `json:"project"` + Projectid string `json:"projectid"` + Regionid int `json:"regionid"` +} + +type GlobalLoadBalancerRuleLoadbalancerrule struct { + Account string `json:"account"` + Algorithm string `json:"algorithm"` + Cidrlist string `json:"cidrlist"` + Description string `json:"description"` + Domain string `json:"domain"` + Domainid string `json:"domainid"` + Fordisplay bool `json:"fordisplay"` + Id string `json:"id"` + Name string `json:"name"` + Networkid string `json:"networkid"` + Privateport string `json:"privateport"` + Project string `json:"project"` + Projectid string `json:"projectid"` + Protocol string `json:"protocol"` + Publicip string `json:"publicip"` + Publicipid string `json:"publicipid"` + Publicport string `json:"publicport"` + State string `json:"state"` + Tags []Tags `json:"tags"` + Zoneid string `json:"zoneid"` + Zonename string `json:"zonename"` +} + +type ListLBHealthCheckPoliciesParams struct { + p map[string]interface{} +} + +func (p *ListLBHealthCheckPoliciesParams) toURLValues() url.Values { + u := url.Values{} + if p.p == nil { + return u + } + if v, found := p.p["fordisplay"]; found { + vv := strconv.FormatBool(v.(bool)) + u.Set("fordisplay", vv) + } + if v, found := p.p["id"]; found { + u.Set("id", v.(string)) + } + if v, found := p.p["keyword"]; found { + u.Set("keyword", v.(string)) + } + if v, found := p.p["lbruleid"]; found { + u.Set("lbruleid", v.(string)) + } + if v, found := p.p["page"]; found { + vv := strconv.Itoa(v.(int)) + u.Set("page", vv) + } + if v, found := p.p["pagesize"]; found { + vv := strconv.Itoa(v.(int)) + u.Set("pagesize", vv) + } + return u +} + +func (p *ListLBHealthCheckPoliciesParams) SetFordisplay(v bool) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["fordisplay"] = v + return +} + +func (p *ListLBHealthCheckPoliciesParams) SetId(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["id"] = v + return +} + +func (p *ListLBHealthCheckPoliciesParams) SetKeyword(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["keyword"] = v + return +} + +func (p *ListLBHealthCheckPoliciesParams) SetLbruleid(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["lbruleid"] = v + return +} + +func (p *ListLBHealthCheckPoliciesParams) SetPage(v int) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["page"] = v + return +} + +func (p *ListLBHealthCheckPoliciesParams) SetPagesize(v int) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["pagesize"] = v + return +} + +// You should always use this function to get a new ListLBHealthCheckPoliciesParams instance, +// as then you are sure you have configured all required params +func (s *LoadBalancerService) NewListLBHealthCheckPoliciesParams() *ListLBHealthCheckPoliciesParams { + p := &ListLBHealthCheckPoliciesParams{} + p.p = make(map[string]interface{}) + return p +} + +// This is a courtesy helper function, which in some cases may not work as expected! +func (s *LoadBalancerService) GetLBHealthCheckPolicyByID(id string, opts ...OptionFunc) (*LBHealthCheckPolicy, int, error) { + p := &ListLBHealthCheckPoliciesParams{} + p.p = make(map[string]interface{}) + + p.p["id"] = id + + for _, fn := range append(s.cs.options, opts...) { + if err := fn(s.cs, p); err != nil { + return nil, -1, err + } + } + + l, err := s.ListLBHealthCheckPolicies(p) + if err != nil { + if strings.Contains(err.Error(), fmt.Sprintf( + "Invalid parameter id value=%s due to incorrect long value format, "+ + "or entity does not exist", id)) { + return nil, 0, fmt.Errorf("No match found for %s: %+v", id, l) + } + return nil, -1, err + } + + if l.Count == 0 { + return nil, l.Count, fmt.Errorf("No match found for %s: %+v", id, l) + } + + if l.Count == 1 { + return l.LBHealthCheckPolicies[0], l.Count, nil + } + return nil, l.Count, fmt.Errorf("There is more then one result for LBHealthCheckPolicy UUID: %s!", id) +} + +// Lists load balancer health check policies. +func (s *LoadBalancerService) ListLBHealthCheckPolicies(p *ListLBHealthCheckPoliciesParams) (*ListLBHealthCheckPoliciesResponse, error) { + resp, err := s.cs.newRequest("listLBHealthCheckPolicies", p.toURLValues()) + if err != nil { + return nil, err + } + + var r ListLBHealthCheckPoliciesResponse + if err := json.Unmarshal(resp, &r); err != nil { + return nil, err + } + + return &r, nil +} + +type ListLBHealthCheckPoliciesResponse struct { + Count int `json:"count"` + LBHealthCheckPolicies []*LBHealthCheckPolicy `json:"lbhealthcheckpolicy"` +} + +type LBHealthCheckPolicy struct { + Account string `json:"account"` + Domain string `json:"domain"` + Domainid string `json:"domainid"` + Healthcheckpolicy []LBHealthCheckPolicyHealthcheckpolicy `json:"healthcheckpolicy"` + Lbruleid string `json:"lbruleid"` + Zoneid string `json:"zoneid"` +} + +type LBHealthCheckPolicyHealthcheckpolicy struct { + Description string `json:"description"` + Fordisplay bool `json:"fordisplay"` + Healthcheckinterval int `json:"healthcheckinterval"` + Healthcheckthresshold int `json:"healthcheckthresshold"` + Id string `json:"id"` + Pingpath string `json:"pingpath"` + Responsetime int `json:"responsetime"` + State string `json:"state"` + Unhealthcheckthresshold int `json:"unhealthcheckthresshold"` +} + +type ListLBStickinessPoliciesParams struct { + p map[string]interface{} +} + +func (p *ListLBStickinessPoliciesParams) toURLValues() url.Values { + u := url.Values{} + if p.p == nil { + return u + } + if v, found := p.p["fordisplay"]; found { + vv := strconv.FormatBool(v.(bool)) + u.Set("fordisplay", vv) + } + if v, found := p.p["id"]; found { + u.Set("id", v.(string)) + } + if v, found := p.p["keyword"]; found { + u.Set("keyword", v.(string)) + } + if v, found := p.p["lbruleid"]; found { + u.Set("lbruleid", v.(string)) + } + if v, found := p.p["page"]; found { + vv := strconv.Itoa(v.(int)) + u.Set("page", vv) + } + if v, found := p.p["pagesize"]; found { + vv := strconv.Itoa(v.(int)) + u.Set("pagesize", vv) + } + return u +} + +func (p *ListLBStickinessPoliciesParams) SetFordisplay(v bool) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["fordisplay"] = v + return +} + +func (p *ListLBStickinessPoliciesParams) SetId(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["id"] = v + return +} + +func (p *ListLBStickinessPoliciesParams) SetKeyword(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["keyword"] = v + return +} + +func (p *ListLBStickinessPoliciesParams) SetLbruleid(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["lbruleid"] = v + return +} + +func (p *ListLBStickinessPoliciesParams) SetPage(v int) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["page"] = v + return +} + +func (p *ListLBStickinessPoliciesParams) SetPagesize(v int) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["pagesize"] = v + return +} + +// You should always use this function to get a new ListLBStickinessPoliciesParams instance, +// as then you are sure you have configured all required params +func (s *LoadBalancerService) NewListLBStickinessPoliciesParams() *ListLBStickinessPoliciesParams { + p := &ListLBStickinessPoliciesParams{} + p.p = make(map[string]interface{}) + return p +} + +// This is a courtesy helper function, which in some cases may not work as expected! +func (s *LoadBalancerService) GetLBStickinessPolicyByID(id string, opts ...OptionFunc) (*LBStickinessPolicy, int, error) { + p := &ListLBStickinessPoliciesParams{} + p.p = make(map[string]interface{}) + + p.p["id"] = id + + for _, fn := range append(s.cs.options, opts...) { + if err := fn(s.cs, p); err != nil { + return nil, -1, err + } + } + + l, err := s.ListLBStickinessPolicies(p) + if err != nil { + if strings.Contains(err.Error(), fmt.Sprintf( + "Invalid parameter id value=%s due to incorrect long value format, "+ + "or entity does not exist", id)) { + return nil, 0, fmt.Errorf("No match found for %s: %+v", id, l) + } + return nil, -1, err + } + + if l.Count == 0 { + return nil, l.Count, fmt.Errorf("No match found for %s: %+v", id, l) + } + + if l.Count == 1 { + return l.LBStickinessPolicies[0], l.Count, nil + } + return nil, l.Count, fmt.Errorf("There is more then one result for LBStickinessPolicy UUID: %s!", id) +} + +// Lists load balancer stickiness policies. +func (s *LoadBalancerService) ListLBStickinessPolicies(p *ListLBStickinessPoliciesParams) (*ListLBStickinessPoliciesResponse, error) { + resp, err := s.cs.newRequest("listLBStickinessPolicies", p.toURLValues()) + if err != nil { + return nil, err + } + + var r ListLBStickinessPoliciesResponse + if err := json.Unmarshal(resp, &r); err != nil { + return nil, err + } + + return &r, nil +} + +type ListLBStickinessPoliciesResponse struct { + Count int `json:"count"` + LBStickinessPolicies []*LBStickinessPolicy `json:"lbstickinesspolicy"` +} + +type LBStickinessPolicy struct { + Account string `json:"account"` + Description string `json:"description"` + Domain string `json:"domain"` + Domainid string `json:"domainid"` + Lbruleid string `json:"lbruleid"` + Name string `json:"name"` + State string `json:"state"` + Stickinesspolicy []LBStickinessPolicyStickinesspolicy `json:"stickinesspolicy"` + Zoneid string `json:"zoneid"` +} + +type LBStickinessPolicyStickinesspolicy struct { + Description string `json:"description"` + Fordisplay bool `json:"fordisplay"` + Id string `json:"id"` + Methodname string `json:"methodname"` + Name string `json:"name"` + Params map[string]string `json:"params"` + State string `json:"state"` +} + +type ListLoadBalancerRuleInstancesParams struct { + p map[string]interface{} +} + +func (p *ListLoadBalancerRuleInstancesParams) toURLValues() url.Values { + u := url.Values{} + if p.p == nil { + return u + } + if v, found := p.p["applied"]; found { + vv := strconv.FormatBool(v.(bool)) + u.Set("applied", vv) + } + if v, found := p.p["id"]; found { + u.Set("id", v.(string)) + } + if v, found := p.p["keyword"]; found { + u.Set("keyword", v.(string)) + } + if v, found := p.p["lbvmips"]; found { + vv := strconv.FormatBool(v.(bool)) + u.Set("lbvmips", vv) + } + if v, found := p.p["page"]; found { + vv := strconv.Itoa(v.(int)) + u.Set("page", vv) + } + if v, found := p.p["pagesize"]; found { + vv := strconv.Itoa(v.(int)) + u.Set("pagesize", vv) + } + return u +} + +func (p *ListLoadBalancerRuleInstancesParams) SetApplied(v bool) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["applied"] = v + return +} + +func (p *ListLoadBalancerRuleInstancesParams) SetId(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["id"] = v + return +} + +func (p *ListLoadBalancerRuleInstancesParams) SetKeyword(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["keyword"] = v + return +} + +func (p *ListLoadBalancerRuleInstancesParams) SetLbvmips(v bool) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["lbvmips"] = v + return +} + +func (p *ListLoadBalancerRuleInstancesParams) SetPage(v int) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["page"] = v + return +} + +func (p *ListLoadBalancerRuleInstancesParams) SetPagesize(v int) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["pagesize"] = v + return +} + +// You should always use this function to get a new ListLoadBalancerRuleInstancesParams instance, +// as then you are sure you have configured all required params +func (s *LoadBalancerService) NewListLoadBalancerRuleInstancesParams(id string) *ListLoadBalancerRuleInstancesParams { + p := &ListLoadBalancerRuleInstancesParams{} + p.p = make(map[string]interface{}) + p.p["id"] = id + return p +} + +// This is a courtesy helper function, which in some cases may not work as expected! +func (s *LoadBalancerService) GetLoadBalancerRuleInstanceByID(id string, opts ...OptionFunc) (*VirtualMachine, int, error) { + p := &ListLoadBalancerRuleInstancesParams{} + p.p = make(map[string]interface{}) + + p.p["id"] = id + + for _, fn := range append(s.cs.options, opts...) { + if err := fn(s.cs, p); err != nil { + return nil, -1, err + } + } + + l, err := s.ListLoadBalancerRuleInstances(p) + if err != nil { + if strings.Contains(err.Error(), fmt.Sprintf( + "Invalid parameter id value=%s due to incorrect long value format, "+ + "or entity does not exist", id)) { + return nil, 0, fmt.Errorf("No match found for %s: %+v", id, l) + } + return nil, -1, err + } + + if l.Count == 0 { + return nil, l.Count, fmt.Errorf("No match found for %s: %+v", id, l) + } + + if l.Count == 1 { + return l.LoadBalancerRuleInstances[0], l.Count, nil + } + return nil, l.Count, fmt.Errorf("There is more then one result for LoadBalancerRuleInstance UUID: %s!", id) +} + +// List all virtual machine instances that are assigned to a load balancer rule. +func (s *LoadBalancerService) ListLoadBalancerRuleInstances(p *ListLoadBalancerRuleInstancesParams) (*ListLoadBalancerRuleInstancesResponse, error) { + resp, err := s.cs.newRequest("listLoadBalancerRuleInstances", p.toURLValues()) + if err != nil { + return nil, err + } + + var r ListLoadBalancerRuleInstancesResponse + if err := json.Unmarshal(resp, &r); err != nil { + return nil, err + } + + return &r, nil +} + +type ListLoadBalancerRuleInstancesResponse struct { + Count int `json:"count"` + LBRuleVMIDIPs []*LoadBalancerRuleInstance `json:"lbrulevmidip"` + LoadBalancerRuleInstances []*VirtualMachine `json:"loadbalancerruleinstance"` +} + +type LoadBalancerRuleInstance struct { + Lbvmipaddresses []string `json:"lbvmipaddresses"` + Loadbalancerruleinstance *VirtualMachine `json:"loadbalancerruleinstance"` } type ListLoadBalancerRulesParams struct { @@ -1073,7 +3051,7 @@ func (s *LoadBalancerService) GetLoadBalancerRuleID(name string, opts ...OptionF p.p["name"] = name - for _, fn := range opts { + for _, fn := range append(s.cs.options, opts...) { if err := fn(s.cs, p); err != nil { return "", -1, err } @@ -1123,7 +3101,7 @@ func (s *LoadBalancerService) GetLoadBalancerRuleByID(id string, opts ...OptionF p.p["id"] = id - for _, fn := range opts { + for _, fn := range append(s.cs.options, opts...) { if err := fn(s.cs, p); err != nil { return nil, -1, err } @@ -1160,6 +3138,7 @@ func (s *LoadBalancerService) ListLoadBalancerRules(p *ListLoadBalancerRulesPara if err := json.Unmarshal(resp, &r); err != nil { return nil, err } + return &r, nil } @@ -1169,3036 +3148,27 @@ type ListLoadBalancerRulesResponse struct { } type LoadBalancerRule struct { - Account string `json:"account,omitempty"` - Algorithm string `json:"algorithm,omitempty"` - Cidrlist string `json:"cidrlist,omitempty"` - Description string `json:"description,omitempty"` - Domain string `json:"domain,omitempty"` - Domainid string `json:"domainid,omitempty"` - Fordisplay bool `json:"fordisplay,omitempty"` - Id string `json:"id,omitempty"` - Name string `json:"name,omitempty"` - Networkid string `json:"networkid,omitempty"` - Privateport string `json:"privateport,omitempty"` - Project string `json:"project,omitempty"` - Projectid string `json:"projectid,omitempty"` - Protocol string `json:"protocol,omitempty"` - Publicip string `json:"publicip,omitempty"` - Publicipid string `json:"publicipid,omitempty"` - Publicport string `json:"publicport,omitempty"` - State string `json:"state,omitempty"` - Tags []struct { - Account string `json:"account,omitempty"` - Customer string `json:"customer,omitempty"` - Domain string `json:"domain,omitempty"` - Domainid string `json:"domainid,omitempty"` - Key string `json:"key,omitempty"` - Project string `json:"project,omitempty"` - Projectid string `json:"projectid,omitempty"` - Resourceid string `json:"resourceid,omitempty"` - Resourcetype string `json:"resourcetype,omitempty"` - Value string `json:"value,omitempty"` - } `json:"tags,omitempty"` - Zoneid string `json:"zoneid,omitempty"` -} - -type ListLBStickinessPoliciesParams struct { - p map[string]interface{} -} - -func (p *ListLBStickinessPoliciesParams) toURLValues() url.Values { - u := url.Values{} - if p.p == nil { - return u - } - if v, found := p.p["fordisplay"]; found { - vv := strconv.FormatBool(v.(bool)) - u.Set("fordisplay", vv) - } - if v, found := p.p["id"]; found { - u.Set("id", v.(string)) - } - if v, found := p.p["keyword"]; found { - u.Set("keyword", v.(string)) - } - if v, found := p.p["lbruleid"]; found { - u.Set("lbruleid", v.(string)) - } - if v, found := p.p["page"]; found { - vv := strconv.Itoa(v.(int)) - u.Set("page", vv) - } - if v, found := p.p["pagesize"]; found { - vv := strconv.Itoa(v.(int)) - u.Set("pagesize", vv) - } - return u -} - -func (p *ListLBStickinessPoliciesParams) SetFordisplay(v bool) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["fordisplay"] = v - return -} - -func (p *ListLBStickinessPoliciesParams) SetId(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["id"] = v - return -} - -func (p *ListLBStickinessPoliciesParams) SetKeyword(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["keyword"] = v - return -} - -func (p *ListLBStickinessPoliciesParams) SetLbruleid(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["lbruleid"] = v - return -} - -func (p *ListLBStickinessPoliciesParams) SetPage(v int) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["page"] = v - return -} - -func (p *ListLBStickinessPoliciesParams) SetPagesize(v int) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["pagesize"] = v - return -} - -// You should always use this function to get a new ListLBStickinessPoliciesParams instance, -// as then you are sure you have configured all required params -func (s *LoadBalancerService) NewListLBStickinessPoliciesParams() *ListLBStickinessPoliciesParams { - p := &ListLBStickinessPoliciesParams{} - p.p = make(map[string]interface{}) - return p -} - -// This is a courtesy helper function, which in some cases may not work as expected! -func (s *LoadBalancerService) GetLBStickinessPolicyByID(id string, opts ...OptionFunc) (*LBStickinessPolicy, int, error) { - p := &ListLBStickinessPoliciesParams{} - p.p = make(map[string]interface{}) - - p.p["id"] = id - - for _, fn := range opts { - if err := fn(s.cs, p); err != nil { - return nil, -1, err - } - } - - l, err := s.ListLBStickinessPolicies(p) - if err != nil { - if strings.Contains(err.Error(), fmt.Sprintf( - "Invalid parameter id value=%s due to incorrect long value format, "+ - "or entity does not exist", id)) { - return nil, 0, fmt.Errorf("No match found for %s: %+v", id, l) - } - return nil, -1, err - } - - if l.Count == 0 { - return nil, l.Count, fmt.Errorf("No match found for %s: %+v", id, l) - } - - if l.Count == 1 { - return l.LBStickinessPolicies[0], l.Count, nil - } - return nil, l.Count, fmt.Errorf("There is more then one result for LBStickinessPolicy UUID: %s!", id) -} - -// Lists load balancer stickiness policies. -func (s *LoadBalancerService) ListLBStickinessPolicies(p *ListLBStickinessPoliciesParams) (*ListLBStickinessPoliciesResponse, error) { - resp, err := s.cs.newRequest("listLBStickinessPolicies", p.toURLValues()) - if err != nil { - return nil, err - } - - var r ListLBStickinessPoliciesResponse - if err := json.Unmarshal(resp, &r); err != nil { - return nil, err - } - return &r, nil -} - -type ListLBStickinessPoliciesResponse struct { - Count int `json:"count"` - LBStickinessPolicies []*LBStickinessPolicy `json:"lbstickinesspolicy"` -} - -type LBStickinessPolicy struct { - Account string `json:"account,omitempty"` - Description string `json:"description,omitempty"` - Domain string `json:"domain,omitempty"` - Domainid string `json:"domainid,omitempty"` - Lbruleid string `json:"lbruleid,omitempty"` - Name string `json:"name,omitempty"` - State string `json:"state,omitempty"` - Stickinesspolicy []struct { - Description string `json:"description,omitempty"` - Fordisplay bool `json:"fordisplay,omitempty"` - Id string `json:"id,omitempty"` - Methodname string `json:"methodname,omitempty"` - Name string `json:"name,omitempty"` - Params map[string]string `json:"params,omitempty"` - State string `json:"state,omitempty"` - } `json:"stickinesspolicy,omitempty"` - Zoneid string `json:"zoneid,omitempty"` -} - -type ListLBHealthCheckPoliciesParams struct { - p map[string]interface{} -} - -func (p *ListLBHealthCheckPoliciesParams) toURLValues() url.Values { - u := url.Values{} - if p.p == nil { - return u - } - if v, found := p.p["fordisplay"]; found { - vv := strconv.FormatBool(v.(bool)) - u.Set("fordisplay", vv) - } - if v, found := p.p["id"]; found { - u.Set("id", v.(string)) - } - if v, found := p.p["keyword"]; found { - u.Set("keyword", v.(string)) - } - if v, found := p.p["lbruleid"]; found { - u.Set("lbruleid", v.(string)) - } - if v, found := p.p["page"]; found { - vv := strconv.Itoa(v.(int)) - u.Set("page", vv) - } - if v, found := p.p["pagesize"]; found { - vv := strconv.Itoa(v.(int)) - u.Set("pagesize", vv) - } - return u -} - -func (p *ListLBHealthCheckPoliciesParams) SetFordisplay(v bool) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["fordisplay"] = v - return -} - -func (p *ListLBHealthCheckPoliciesParams) SetId(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["id"] = v - return -} - -func (p *ListLBHealthCheckPoliciesParams) SetKeyword(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["keyword"] = v - return -} - -func (p *ListLBHealthCheckPoliciesParams) SetLbruleid(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["lbruleid"] = v - return -} - -func (p *ListLBHealthCheckPoliciesParams) SetPage(v int) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["page"] = v - return -} - -func (p *ListLBHealthCheckPoliciesParams) SetPagesize(v int) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["pagesize"] = v - return -} - -// You should always use this function to get a new ListLBHealthCheckPoliciesParams instance, -// as then you are sure you have configured all required params -func (s *LoadBalancerService) NewListLBHealthCheckPoliciesParams() *ListLBHealthCheckPoliciesParams { - p := &ListLBHealthCheckPoliciesParams{} - p.p = make(map[string]interface{}) - return p -} - -// This is a courtesy helper function, which in some cases may not work as expected! -func (s *LoadBalancerService) GetLBHealthCheckPolicyByID(id string, opts ...OptionFunc) (*LBHealthCheckPolicy, int, error) { - p := &ListLBHealthCheckPoliciesParams{} - p.p = make(map[string]interface{}) - - p.p["id"] = id - - for _, fn := range opts { - if err := fn(s.cs, p); err != nil { - return nil, -1, err - } - } - - l, err := s.ListLBHealthCheckPolicies(p) - if err != nil { - if strings.Contains(err.Error(), fmt.Sprintf( - "Invalid parameter id value=%s due to incorrect long value format, "+ - "or entity does not exist", id)) { - return nil, 0, fmt.Errorf("No match found for %s: %+v", id, l) - } - return nil, -1, err - } - - if l.Count == 0 { - return nil, l.Count, fmt.Errorf("No match found for %s: %+v", id, l) - } - - if l.Count == 1 { - return l.LBHealthCheckPolicies[0], l.Count, nil - } - return nil, l.Count, fmt.Errorf("There is more then one result for LBHealthCheckPolicy UUID: %s!", id) -} - -// Lists load balancer health check policies. -func (s *LoadBalancerService) ListLBHealthCheckPolicies(p *ListLBHealthCheckPoliciesParams) (*ListLBHealthCheckPoliciesResponse, error) { - resp, err := s.cs.newRequest("listLBHealthCheckPolicies", p.toURLValues()) - if err != nil { - return nil, err - } - - var r ListLBHealthCheckPoliciesResponse - if err := json.Unmarshal(resp, &r); err != nil { - return nil, err - } - return &r, nil -} - -type ListLBHealthCheckPoliciesResponse struct { - Count int `json:"count"` - LBHealthCheckPolicies []*LBHealthCheckPolicy `json:"lbhealthcheckpolicy"` -} - -type LBHealthCheckPolicy struct { - Account string `json:"account,omitempty"` - Domain string `json:"domain,omitempty"` - Domainid string `json:"domainid,omitempty"` - Healthcheckpolicy []struct { - Description string `json:"description,omitempty"` - Fordisplay bool `json:"fordisplay,omitempty"` - Healthcheckinterval int `json:"healthcheckinterval,omitempty"` - Healthcheckthresshold int `json:"healthcheckthresshold,omitempty"` - Id string `json:"id,omitempty"` - Pingpath string `json:"pingpath,omitempty"` - Responsetime int `json:"responsetime,omitempty"` - State string `json:"state,omitempty"` - Unhealthcheckthresshold int `json:"unhealthcheckthresshold,omitempty"` - } `json:"healthcheckpolicy,omitempty"` - Lbruleid string `json:"lbruleid,omitempty"` - Zoneid string `json:"zoneid,omitempty"` -} - -type CreateLBHealthCheckPolicyParams struct { - p map[string]interface{} -} - -func (p *CreateLBHealthCheckPolicyParams) toURLValues() url.Values { - u := url.Values{} - if p.p == nil { - return u - } - if v, found := p.p["description"]; found { - u.Set("description", v.(string)) - } - if v, found := p.p["fordisplay"]; found { - vv := strconv.FormatBool(v.(bool)) - u.Set("fordisplay", vv) - } - if v, found := p.p["healthythreshold"]; found { - vv := strconv.Itoa(v.(int)) - u.Set("healthythreshold", vv) - } - if v, found := p.p["intervaltime"]; found { - vv := strconv.Itoa(v.(int)) - u.Set("intervaltime", vv) - } - if v, found := p.p["lbruleid"]; found { - u.Set("lbruleid", v.(string)) - } - if v, found := p.p["pingpath"]; found { - u.Set("pingpath", v.(string)) - } - if v, found := p.p["responsetimeout"]; found { - vv := strconv.Itoa(v.(int)) - u.Set("responsetimeout", vv) - } - if v, found := p.p["unhealthythreshold"]; found { - vv := strconv.Itoa(v.(int)) - u.Set("unhealthythreshold", vv) - } - return u -} - -func (p *CreateLBHealthCheckPolicyParams) SetDescription(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["description"] = v - return -} - -func (p *CreateLBHealthCheckPolicyParams) SetFordisplay(v bool) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["fordisplay"] = v - return -} - -func (p *CreateLBHealthCheckPolicyParams) SetHealthythreshold(v int) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["healthythreshold"] = v - return -} - -func (p *CreateLBHealthCheckPolicyParams) SetIntervaltime(v int) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["intervaltime"] = v - return -} - -func (p *CreateLBHealthCheckPolicyParams) SetLbruleid(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["lbruleid"] = v - return -} - -func (p *CreateLBHealthCheckPolicyParams) SetPingpath(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["pingpath"] = v - return -} - -func (p *CreateLBHealthCheckPolicyParams) SetResponsetimeout(v int) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["responsetimeout"] = v - return -} - -func (p *CreateLBHealthCheckPolicyParams) SetUnhealthythreshold(v int) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["unhealthythreshold"] = v - return -} - -// You should always use this function to get a new CreateLBHealthCheckPolicyParams instance, -// as then you are sure you have configured all required params -func (s *LoadBalancerService) NewCreateLBHealthCheckPolicyParams(lbruleid string) *CreateLBHealthCheckPolicyParams { - p := &CreateLBHealthCheckPolicyParams{} - p.p = make(map[string]interface{}) - p.p["lbruleid"] = lbruleid - return p -} - -// Creates a load balancer health check policy -func (s *LoadBalancerService) CreateLBHealthCheckPolicy(p *CreateLBHealthCheckPolicyParams) (*CreateLBHealthCheckPolicyResponse, error) { - resp, err := s.cs.newRequest("createLBHealthCheckPolicy", p.toURLValues()) - if err != nil { - return nil, err - } - - var r CreateLBHealthCheckPolicyResponse - if err := json.Unmarshal(resp, &r); err != nil { - return nil, err - } - - // If we have a async client, we need to wait for the async result - if s.cs.async { - b, err := s.cs.GetAsyncJobResult(r.JobID, s.cs.timeout) - if err != nil { - if err == AsyncTimeoutErr { - return &r, err - } - return nil, err - } - - b, err = getRawValue(b) - if err != nil { - return nil, err - } - - if err := json.Unmarshal(b, &r); err != nil { - return nil, err - } - } - return &r, nil -} - -type CreateLBHealthCheckPolicyResponse struct { - JobID string `json:"jobid,omitempty"` - Account string `json:"account,omitempty"` - Domain string `json:"domain,omitempty"` - Domainid string `json:"domainid,omitempty"` - Healthcheckpolicy []struct { - Description string `json:"description,omitempty"` - Fordisplay bool `json:"fordisplay,omitempty"` - Healthcheckinterval int `json:"healthcheckinterval,omitempty"` - Healthcheckthresshold int `json:"healthcheckthresshold,omitempty"` - Id string `json:"id,omitempty"` - Pingpath string `json:"pingpath,omitempty"` - Responsetime int `json:"responsetime,omitempty"` - State string `json:"state,omitempty"` - Unhealthcheckthresshold int `json:"unhealthcheckthresshold,omitempty"` - } `json:"healthcheckpolicy,omitempty"` - Lbruleid string `json:"lbruleid,omitempty"` - Zoneid string `json:"zoneid,omitempty"` -} - -type UpdateLBHealthCheckPolicyParams struct { - p map[string]interface{} -} - -func (p *UpdateLBHealthCheckPolicyParams) toURLValues() url.Values { - u := url.Values{} - if p.p == nil { - return u - } - if v, found := p.p["customid"]; found { - u.Set("customid", v.(string)) - } - if v, found := p.p["fordisplay"]; found { - vv := strconv.FormatBool(v.(bool)) - u.Set("fordisplay", vv) - } - if v, found := p.p["id"]; found { - u.Set("id", v.(string)) - } - return u -} - -func (p *UpdateLBHealthCheckPolicyParams) SetCustomid(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["customid"] = v - return -} - -func (p *UpdateLBHealthCheckPolicyParams) SetFordisplay(v bool) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["fordisplay"] = v - return -} - -func (p *UpdateLBHealthCheckPolicyParams) SetId(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["id"] = v - return -} - -// You should always use this function to get a new UpdateLBHealthCheckPolicyParams instance, -// as then you are sure you have configured all required params -func (s *LoadBalancerService) NewUpdateLBHealthCheckPolicyParams(id string) *UpdateLBHealthCheckPolicyParams { - p := &UpdateLBHealthCheckPolicyParams{} - p.p = make(map[string]interface{}) - p.p["id"] = id - return p -} - -// Updates load balancer health check policy -func (s *LoadBalancerService) UpdateLBHealthCheckPolicy(p *UpdateLBHealthCheckPolicyParams) (*UpdateLBHealthCheckPolicyResponse, error) { - resp, err := s.cs.newRequest("updateLBHealthCheckPolicy", p.toURLValues()) - if err != nil { - return nil, err - } - - var r UpdateLBHealthCheckPolicyResponse - if err := json.Unmarshal(resp, &r); err != nil { - return nil, err - } - - // If we have a async client, we need to wait for the async result - if s.cs.async { - b, err := s.cs.GetAsyncJobResult(r.JobID, s.cs.timeout) - if err != nil { - if err == AsyncTimeoutErr { - return &r, err - } - return nil, err - } - - b, err = getRawValue(b) - if err != nil { - return nil, err - } - - if err := json.Unmarshal(b, &r); err != nil { - return nil, err - } - } - return &r, nil -} - -type UpdateLBHealthCheckPolicyResponse struct { - JobID string `json:"jobid,omitempty"` - Account string `json:"account,omitempty"` - Domain string `json:"domain,omitempty"` - Domainid string `json:"domainid,omitempty"` - Healthcheckpolicy []struct { - Description string `json:"description,omitempty"` - Fordisplay bool `json:"fordisplay,omitempty"` - Healthcheckinterval int `json:"healthcheckinterval,omitempty"` - Healthcheckthresshold int `json:"healthcheckthresshold,omitempty"` - Id string `json:"id,omitempty"` - Pingpath string `json:"pingpath,omitempty"` - Responsetime int `json:"responsetime,omitempty"` - State string `json:"state,omitempty"` - Unhealthcheckthresshold int `json:"unhealthcheckthresshold,omitempty"` - } `json:"healthcheckpolicy,omitempty"` - Lbruleid string `json:"lbruleid,omitempty"` - Zoneid string `json:"zoneid,omitempty"` -} - -type DeleteLBHealthCheckPolicyParams struct { - p map[string]interface{} -} - -func (p *DeleteLBHealthCheckPolicyParams) toURLValues() url.Values { - u := url.Values{} - if p.p == nil { - return u - } - if v, found := p.p["id"]; found { - u.Set("id", v.(string)) - } - return u -} - -func (p *DeleteLBHealthCheckPolicyParams) SetId(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["id"] = v - return -} - -// You should always use this function to get a new DeleteLBHealthCheckPolicyParams instance, -// as then you are sure you have configured all required params -func (s *LoadBalancerService) NewDeleteLBHealthCheckPolicyParams(id string) *DeleteLBHealthCheckPolicyParams { - p := &DeleteLBHealthCheckPolicyParams{} - p.p = make(map[string]interface{}) - p.p["id"] = id - return p -} - -// Deletes a load balancer health check policy. -func (s *LoadBalancerService) DeleteLBHealthCheckPolicy(p *DeleteLBHealthCheckPolicyParams) (*DeleteLBHealthCheckPolicyResponse, error) { - resp, err := s.cs.newRequest("deleteLBHealthCheckPolicy", p.toURLValues()) - if err != nil { - return nil, err - } - - var r DeleteLBHealthCheckPolicyResponse - if err := json.Unmarshal(resp, &r); err != nil { - return nil, err - } - - // If we have a async client, we need to wait for the async result - if s.cs.async { - b, err := s.cs.GetAsyncJobResult(r.JobID, s.cs.timeout) - if err != nil { - if err == AsyncTimeoutErr { - return &r, err - } - return nil, err - } - - if err := json.Unmarshal(b, &r); err != nil { - return nil, err - } - } - return &r, nil -} - -type DeleteLBHealthCheckPolicyResponse struct { - JobID string `json:"jobid,omitempty"` - Displaytext string `json:"displaytext,omitempty"` - Success bool `json:"success,omitempty"` -} - -type ListLoadBalancerRuleInstancesParams struct { - p map[string]interface{} -} - -func (p *ListLoadBalancerRuleInstancesParams) toURLValues() url.Values { - u := url.Values{} - if p.p == nil { - return u - } - if v, found := p.p["applied"]; found { - vv := strconv.FormatBool(v.(bool)) - u.Set("applied", vv) - } - if v, found := p.p["id"]; found { - u.Set("id", v.(string)) - } - if v, found := p.p["keyword"]; found { - u.Set("keyword", v.(string)) - } - if v, found := p.p["lbvmips"]; found { - vv := strconv.FormatBool(v.(bool)) - u.Set("lbvmips", vv) - } - if v, found := p.p["page"]; found { - vv := strconv.Itoa(v.(int)) - u.Set("page", vv) - } - if v, found := p.p["pagesize"]; found { - vv := strconv.Itoa(v.(int)) - u.Set("pagesize", vv) - } - return u -} - -func (p *ListLoadBalancerRuleInstancesParams) SetApplied(v bool) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["applied"] = v - return -} - -func (p *ListLoadBalancerRuleInstancesParams) SetId(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["id"] = v - return -} - -func (p *ListLoadBalancerRuleInstancesParams) SetKeyword(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["keyword"] = v - return -} - -func (p *ListLoadBalancerRuleInstancesParams) SetLbvmips(v bool) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["lbvmips"] = v - return -} - -func (p *ListLoadBalancerRuleInstancesParams) SetPage(v int) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["page"] = v - return -} - -func (p *ListLoadBalancerRuleInstancesParams) SetPagesize(v int) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["pagesize"] = v - return -} - -// You should always use this function to get a new ListLoadBalancerRuleInstancesParams instance, -// as then you are sure you have configured all required params -func (s *LoadBalancerService) NewListLoadBalancerRuleInstancesParams(id string) *ListLoadBalancerRuleInstancesParams { - p := &ListLoadBalancerRuleInstancesParams{} - p.p = make(map[string]interface{}) - p.p["id"] = id - return p -} - -// This is a courtesy helper function, which in some cases may not work as expected! -func (s *LoadBalancerService) GetLoadBalancerRuleInstanceByID(id string, opts ...OptionFunc) (*VirtualMachine, int, error) { - p := &ListLoadBalancerRuleInstancesParams{} - p.p = make(map[string]interface{}) - - p.p["id"] = id - - for _, fn := range opts { - if err := fn(s.cs, p); err != nil { - return nil, -1, err - } - } - - l, err := s.ListLoadBalancerRuleInstances(p) - if err != nil { - if strings.Contains(err.Error(), fmt.Sprintf( - "Invalid parameter id value=%s due to incorrect long value format, "+ - "or entity does not exist", id)) { - return nil, 0, fmt.Errorf("No match found for %s: %+v", id, l) - } - return nil, -1, err - } - - if l.Count == 0 { - return nil, l.Count, fmt.Errorf("No match found for %s: %+v", id, l) - } - - if l.Count == 1 { - return l.LoadBalancerRuleInstances[0], l.Count, nil - } - return nil, l.Count, fmt.Errorf("There is more then one result for LoadBalancerRuleInstance UUID: %s!", id) -} - -// List all virtual machine instances that are assigned to a load balancer rule. -func (s *LoadBalancerService) ListLoadBalancerRuleInstances(p *ListLoadBalancerRuleInstancesParams) (*ListLoadBalancerRuleInstancesResponse, error) { - resp, err := s.cs.newRequest("listLoadBalancerRuleInstances", p.toURLValues()) - if err != nil { - return nil, err - } - - var r ListLoadBalancerRuleInstancesResponse - if err := json.Unmarshal(resp, &r); err != nil { - return nil, err - } - return &r, nil -} - -type ListLoadBalancerRuleInstancesResponse struct { - Count int `json:"count"` - LBRuleVMIDIPs []*LoadBalancerRuleInstance `json:"lbrulevmidip,omitempty"` - LoadBalancerRuleInstances []*VirtualMachine `json:"loadbalancerruleinstance,omitempty"` -} - -type LoadBalancerRuleInstance struct { - Lbvmipaddresses []string `json:"lbvmipaddresses,omitempty"` - Loadbalancerruleinstance *VirtualMachine `json:"loadbalancerruleinstance,omitempty"` -} - -type UpdateLoadBalancerRuleParams struct { - p map[string]interface{} -} - -func (p *UpdateLoadBalancerRuleParams) toURLValues() url.Values { - u := url.Values{} - if p.p == nil { - return u - } - if v, found := p.p["algorithm"]; found { - u.Set("algorithm", v.(string)) - } - if v, found := p.p["customid"]; found { - u.Set("customid", v.(string)) - } - if v, found := p.p["description"]; found { - u.Set("description", v.(string)) - } - if v, found := p.p["fordisplay"]; found { - vv := strconv.FormatBool(v.(bool)) - u.Set("fordisplay", vv) - } - if v, found := p.p["id"]; found { - u.Set("id", v.(string)) - } - if v, found := p.p["name"]; found { - u.Set("name", v.(string)) - } - return u -} - -func (p *UpdateLoadBalancerRuleParams) SetAlgorithm(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["algorithm"] = v - return -} - -func (p *UpdateLoadBalancerRuleParams) SetCustomid(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["customid"] = v - return -} - -func (p *UpdateLoadBalancerRuleParams) SetDescription(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["description"] = v - return -} - -func (p *UpdateLoadBalancerRuleParams) SetFordisplay(v bool) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["fordisplay"] = v - return -} - -func (p *UpdateLoadBalancerRuleParams) SetId(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["id"] = v - return -} - -func (p *UpdateLoadBalancerRuleParams) SetName(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["name"] = v - return -} - -// You should always use this function to get a new UpdateLoadBalancerRuleParams instance, -// as then you are sure you have configured all required params -func (s *LoadBalancerService) NewUpdateLoadBalancerRuleParams(id string) *UpdateLoadBalancerRuleParams { - p := &UpdateLoadBalancerRuleParams{} - p.p = make(map[string]interface{}) - p.p["id"] = id - return p -} - -// Updates load balancer -func (s *LoadBalancerService) UpdateLoadBalancerRule(p *UpdateLoadBalancerRuleParams) (*UpdateLoadBalancerRuleResponse, error) { - resp, err := s.cs.newRequest("updateLoadBalancerRule", p.toURLValues()) - if err != nil { - return nil, err - } - - var r UpdateLoadBalancerRuleResponse - if err := json.Unmarshal(resp, &r); err != nil { - return nil, err - } - - // If we have a async client, we need to wait for the async result - if s.cs.async { - b, err := s.cs.GetAsyncJobResult(r.JobID, s.cs.timeout) - if err != nil { - if err == AsyncTimeoutErr { - return &r, err - } - return nil, err - } - - b, err = getRawValue(b) - if err != nil { - return nil, err - } - - if err := json.Unmarshal(b, &r); err != nil { - return nil, err - } - } - return &r, nil -} - -type UpdateLoadBalancerRuleResponse struct { - JobID string `json:"jobid,omitempty"` - Account string `json:"account,omitempty"` - Algorithm string `json:"algorithm,omitempty"` - Cidrlist string `json:"cidrlist,omitempty"` - Description string `json:"description,omitempty"` - Domain string `json:"domain,omitempty"` - Domainid string `json:"domainid,omitempty"` - Fordisplay bool `json:"fordisplay,omitempty"` - Id string `json:"id,omitempty"` - Name string `json:"name,omitempty"` - Networkid string `json:"networkid,omitempty"` - Privateport string `json:"privateport,omitempty"` - Project string `json:"project,omitempty"` - Projectid string `json:"projectid,omitempty"` - Protocol string `json:"protocol,omitempty"` - Publicip string `json:"publicip,omitempty"` - Publicipid string `json:"publicipid,omitempty"` - Publicport string `json:"publicport,omitempty"` - State string `json:"state,omitempty"` - Tags []struct { - Account string `json:"account,omitempty"` - Customer string `json:"customer,omitempty"` - Domain string `json:"domain,omitempty"` - Domainid string `json:"domainid,omitempty"` - Key string `json:"key,omitempty"` - Project string `json:"project,omitempty"` - Projectid string `json:"projectid,omitempty"` - Resourceid string `json:"resourceid,omitempty"` - Resourcetype string `json:"resourcetype,omitempty"` - Value string `json:"value,omitempty"` - } `json:"tags,omitempty"` - Zoneid string `json:"zoneid,omitempty"` -} - -type UploadSslCertParams struct { - p map[string]interface{} -} - -func (p *UploadSslCertParams) toURLValues() url.Values { - u := url.Values{} - if p.p == nil { - return u - } - if v, found := p.p["account"]; found { - u.Set("account", v.(string)) - } - if v, found := p.p["certchain"]; found { - u.Set("certchain", v.(string)) - } - if v, found := p.p["certificate"]; found { - u.Set("certificate", v.(string)) - } - if v, found := p.p["domainid"]; found { - u.Set("domainid", v.(string)) - } - if v, found := p.p["password"]; found { - u.Set("password", v.(string)) - } - if v, found := p.p["privatekey"]; found { - u.Set("privatekey", v.(string)) - } - if v, found := p.p["projectid"]; found { - u.Set("projectid", v.(string)) - } - return u -} - -func (p *UploadSslCertParams) SetAccount(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["account"] = v - return -} - -func (p *UploadSslCertParams) SetCertchain(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["certchain"] = v - return -} - -func (p *UploadSslCertParams) SetCertificate(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["certificate"] = v - return -} - -func (p *UploadSslCertParams) SetDomainid(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["domainid"] = v - return -} - -func (p *UploadSslCertParams) SetPassword(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["password"] = v - return -} - -func (p *UploadSslCertParams) SetPrivatekey(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["privatekey"] = v - return -} - -func (p *UploadSslCertParams) SetProjectid(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["projectid"] = v - return -} - -// You should always use this function to get a new UploadSslCertParams instance, -// as then you are sure you have configured all required params -func (s *LoadBalancerService) NewUploadSslCertParams(certificate string, privatekey string) *UploadSslCertParams { - p := &UploadSslCertParams{} - p.p = make(map[string]interface{}) - p.p["certificate"] = certificate - p.p["privatekey"] = privatekey - return p -} - -// Upload a certificate to CloudStack -func (s *LoadBalancerService) UploadSslCert(p *UploadSslCertParams) (*UploadSslCertResponse, error) { - resp, err := s.cs.newRequest("uploadSslCert", p.toURLValues()) - if err != nil { - return nil, err - } - - var r UploadSslCertResponse - if err := json.Unmarshal(resp, &r); err != nil { - return nil, err - } - return &r, nil -} - -type UploadSslCertResponse struct { - Account string `json:"account,omitempty"` - Certchain string `json:"certchain,omitempty"` - Certificate string `json:"certificate,omitempty"` - Domain string `json:"domain,omitempty"` - Domainid string `json:"domainid,omitempty"` - Fingerprint string `json:"fingerprint,omitempty"` - Id string `json:"id,omitempty"` - Loadbalancerrulelist []string `json:"loadbalancerrulelist,omitempty"` - Project string `json:"project,omitempty"` - Projectid string `json:"projectid,omitempty"` -} - -type DeleteSslCertParams struct { - p map[string]interface{} -} - -func (p *DeleteSslCertParams) toURLValues() url.Values { - u := url.Values{} - if p.p == nil { - return u - } - if v, found := p.p["id"]; found { - u.Set("id", v.(string)) - } - return u -} - -func (p *DeleteSslCertParams) SetId(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["id"] = v - return -} - -// You should always use this function to get a new DeleteSslCertParams instance, -// as then you are sure you have configured all required params -func (s *LoadBalancerService) NewDeleteSslCertParams(id string) *DeleteSslCertParams { - p := &DeleteSslCertParams{} - p.p = make(map[string]interface{}) - p.p["id"] = id - return p -} - -// Delete a certificate to CloudStack -func (s *LoadBalancerService) DeleteSslCert(p *DeleteSslCertParams) (*DeleteSslCertResponse, error) { - resp, err := s.cs.newRequest("deleteSslCert", p.toURLValues()) - if err != nil { - return nil, err - } - - var r DeleteSslCertResponse - if err := json.Unmarshal(resp, &r); err != nil { - return nil, err - } - return &r, nil -} - -type DeleteSslCertResponse struct { - Displaytext string `json:"displaytext,omitempty"` - Success string `json:"success,omitempty"` -} - -type ListSslCertsParams struct { - p map[string]interface{} -} - -func (p *ListSslCertsParams) toURLValues() url.Values { - u := url.Values{} - if p.p == nil { - return u - } - if v, found := p.p["accountid"]; found { - u.Set("accountid", v.(string)) - } - if v, found := p.p["certid"]; found { - u.Set("certid", v.(string)) - } - if v, found := p.p["lbruleid"]; found { - u.Set("lbruleid", v.(string)) - } - if v, found := p.p["projectid"]; found { - u.Set("projectid", v.(string)) - } - return u -} - -func (p *ListSslCertsParams) SetAccountid(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["accountid"] = v - return -} - -func (p *ListSslCertsParams) SetCertid(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["certid"] = v - return -} - -func (p *ListSslCertsParams) SetLbruleid(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["lbruleid"] = v - return -} - -func (p *ListSslCertsParams) SetProjectid(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["projectid"] = v - return -} - -// You should always use this function to get a new ListSslCertsParams instance, -// as then you are sure you have configured all required params -func (s *LoadBalancerService) NewListSslCertsParams() *ListSslCertsParams { - p := &ListSslCertsParams{} - p.p = make(map[string]interface{}) - return p -} - -// Lists SSL certificates -func (s *LoadBalancerService) ListSslCerts(p *ListSslCertsParams) (*ListSslCertsResponse, error) { - resp, err := s.cs.newRequest("listSslCerts", p.toURLValues()) - if err != nil { - return nil, err - } - - var r ListSslCertsResponse - if err := json.Unmarshal(resp, &r); err != nil { - return nil, err - } - return &r, nil -} - -type ListSslCertsResponse struct { - Count int `json:"count"` - SslCerts []*SslCert `json:"sslcert"` -} - -type SslCert struct { - Account string `json:"account,omitempty"` - Certchain string `json:"certchain,omitempty"` - Certificate string `json:"certificate,omitempty"` - Domain string `json:"domain,omitempty"` - Domainid string `json:"domainid,omitempty"` - Fingerprint string `json:"fingerprint,omitempty"` - Id string `json:"id,omitempty"` - Loadbalancerrulelist []string `json:"loadbalancerrulelist,omitempty"` - Project string `json:"project,omitempty"` - Projectid string `json:"projectid,omitempty"` -} - -type AssignCertToLoadBalancerParams struct { - p map[string]interface{} -} - -func (p *AssignCertToLoadBalancerParams) toURLValues() url.Values { - u := url.Values{} - if p.p == nil { - return u - } - if v, found := p.p["certid"]; found { - u.Set("certid", v.(string)) - } - if v, found := p.p["lbruleid"]; found { - u.Set("lbruleid", v.(string)) - } - return u -} - -func (p *AssignCertToLoadBalancerParams) SetCertid(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["certid"] = v - return -} - -func (p *AssignCertToLoadBalancerParams) SetLbruleid(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["lbruleid"] = v - return -} - -// You should always use this function to get a new AssignCertToLoadBalancerParams instance, -// as then you are sure you have configured all required params -func (s *LoadBalancerService) NewAssignCertToLoadBalancerParams(certid string, lbruleid string) *AssignCertToLoadBalancerParams { - p := &AssignCertToLoadBalancerParams{} - p.p = make(map[string]interface{}) - p.p["certid"] = certid - p.p["lbruleid"] = lbruleid - return p -} - -// Assigns a certificate to a load balancer rule -func (s *LoadBalancerService) AssignCertToLoadBalancer(p *AssignCertToLoadBalancerParams) (*AssignCertToLoadBalancerResponse, error) { - resp, err := s.cs.newRequest("assignCertToLoadBalancer", p.toURLValues()) - if err != nil { - return nil, err - } - - var r AssignCertToLoadBalancerResponse - if err := json.Unmarshal(resp, &r); err != nil { - return nil, err - } - - // If we have a async client, we need to wait for the async result - if s.cs.async { - b, err := s.cs.GetAsyncJobResult(r.JobID, s.cs.timeout) - if err != nil { - if err == AsyncTimeoutErr { - return &r, err - } - return nil, err - } - - if err := json.Unmarshal(b, &r); err != nil { - return nil, err - } - } - return &r, nil -} - -type AssignCertToLoadBalancerResponse struct { - JobID string `json:"jobid,omitempty"` - Displaytext string `json:"displaytext,omitempty"` - Success bool `json:"success,omitempty"` -} - -type RemoveCertFromLoadBalancerParams struct { - p map[string]interface{} -} - -func (p *RemoveCertFromLoadBalancerParams) toURLValues() url.Values { - u := url.Values{} - if p.p == nil { - return u - } - if v, found := p.p["lbruleid"]; found { - u.Set("lbruleid", v.(string)) - } - return u -} - -func (p *RemoveCertFromLoadBalancerParams) SetLbruleid(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["lbruleid"] = v - return -} - -// You should always use this function to get a new RemoveCertFromLoadBalancerParams instance, -// as then you are sure you have configured all required params -func (s *LoadBalancerService) NewRemoveCertFromLoadBalancerParams(lbruleid string) *RemoveCertFromLoadBalancerParams { - p := &RemoveCertFromLoadBalancerParams{} - p.p = make(map[string]interface{}) - p.p["lbruleid"] = lbruleid - return p -} - -// Removes a certificate from a load balancer rule -func (s *LoadBalancerService) RemoveCertFromLoadBalancer(p *RemoveCertFromLoadBalancerParams) (*RemoveCertFromLoadBalancerResponse, error) { - resp, err := s.cs.newRequest("removeCertFromLoadBalancer", p.toURLValues()) - if err != nil { - return nil, err - } - - var r RemoveCertFromLoadBalancerResponse - if err := json.Unmarshal(resp, &r); err != nil { - return nil, err - } - - // If we have a async client, we need to wait for the async result - if s.cs.async { - b, err := s.cs.GetAsyncJobResult(r.JobID, s.cs.timeout) - if err != nil { - if err == AsyncTimeoutErr { - return &r, err - } - return nil, err - } - - if err := json.Unmarshal(b, &r); err != nil { - return nil, err - } - } - return &r, nil -} - -type RemoveCertFromLoadBalancerResponse struct { - JobID string `json:"jobid,omitempty"` - Displaytext string `json:"displaytext,omitempty"` - Success bool `json:"success,omitempty"` -} - -type AddNetscalerLoadBalancerParams struct { - p map[string]interface{} -} - -func (p *AddNetscalerLoadBalancerParams) toURLValues() url.Values { - u := url.Values{} - if p.p == nil { - return u - } - if v, found := p.p["gslbprovider"]; found { - vv := strconv.FormatBool(v.(bool)) - u.Set("gslbprovider", vv) - } - if v, found := p.p["gslbproviderprivateip"]; found { - u.Set("gslbproviderprivateip", v.(string)) - } - if v, found := p.p["gslbproviderpublicip"]; found { - u.Set("gslbproviderpublicip", v.(string)) - } - if v, found := p.p["isexclusivegslbprovider"]; found { - vv := strconv.FormatBool(v.(bool)) - u.Set("isexclusivegslbprovider", vv) - } - if v, found := p.p["networkdevicetype"]; found { - u.Set("networkdevicetype", v.(string)) - } - if v, found := p.p["password"]; found { - u.Set("password", v.(string)) - } - if v, found := p.p["physicalnetworkid"]; found { - u.Set("physicalnetworkid", v.(string)) - } - if v, found := p.p["url"]; found { - u.Set("url", v.(string)) - } - if v, found := p.p["username"]; found { - u.Set("username", v.(string)) - } - return u -} - -func (p *AddNetscalerLoadBalancerParams) SetGslbprovider(v bool) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["gslbprovider"] = v - return -} - -func (p *AddNetscalerLoadBalancerParams) SetGslbproviderprivateip(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["gslbproviderprivateip"] = v - return -} - -func (p *AddNetscalerLoadBalancerParams) SetGslbproviderpublicip(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["gslbproviderpublicip"] = v - return -} - -func (p *AddNetscalerLoadBalancerParams) SetIsexclusivegslbprovider(v bool) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["isexclusivegslbprovider"] = v - return -} - -func (p *AddNetscalerLoadBalancerParams) SetNetworkdevicetype(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["networkdevicetype"] = v - return -} - -func (p *AddNetscalerLoadBalancerParams) SetPassword(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["password"] = v - return -} - -func (p *AddNetscalerLoadBalancerParams) SetPhysicalnetworkid(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["physicalnetworkid"] = v - return -} - -func (p *AddNetscalerLoadBalancerParams) SetUrl(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["url"] = v - return -} - -func (p *AddNetscalerLoadBalancerParams) SetUsername(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["username"] = v - return -} - -// You should always use this function to get a new AddNetscalerLoadBalancerParams instance, -// as then you are sure you have configured all required params -func (s *LoadBalancerService) NewAddNetscalerLoadBalancerParams(networkdevicetype string, password string, physicalnetworkid string, url string, username string) *AddNetscalerLoadBalancerParams { - p := &AddNetscalerLoadBalancerParams{} - p.p = make(map[string]interface{}) - p.p["networkdevicetype"] = networkdevicetype - p.p["password"] = password - p.p["physicalnetworkid"] = physicalnetworkid - p.p["url"] = url - p.p["username"] = username - return p -} - -// Adds a netscaler load balancer device -func (s *LoadBalancerService) AddNetscalerLoadBalancer(p *AddNetscalerLoadBalancerParams) (*AddNetscalerLoadBalancerResponse, error) { - resp, err := s.cs.newRequest("addNetscalerLoadBalancer", p.toURLValues()) - if err != nil { - return nil, err - } - - var r AddNetscalerLoadBalancerResponse - if err := json.Unmarshal(resp, &r); err != nil { - return nil, err - } - - // If we have a async client, we need to wait for the async result - if s.cs.async { - b, err := s.cs.GetAsyncJobResult(r.JobID, s.cs.timeout) - if err != nil { - if err == AsyncTimeoutErr { - return &r, err - } - return nil, err - } - - b, err = getRawValue(b) - if err != nil { - return nil, err - } - - if err := json.Unmarshal(b, &r); err != nil { - return nil, err - } - } - return &r, nil -} - -type AddNetscalerLoadBalancerResponse struct { - JobID string `json:"jobid,omitempty"` - Gslbprovider bool `json:"gslbprovider,omitempty"` - Gslbproviderprivateip string `json:"gslbproviderprivateip,omitempty"` - Gslbproviderpublicip string `json:"gslbproviderpublicip,omitempty"` - Ipaddress string `json:"ipaddress,omitempty"` - Isexclusivegslbprovider bool `json:"isexclusivegslbprovider,omitempty"` - Lbdevicecapacity int64 `json:"lbdevicecapacity,omitempty"` - Lbdevicededicated bool `json:"lbdevicededicated,omitempty"` - Lbdeviceid string `json:"lbdeviceid,omitempty"` - Lbdevicename string `json:"lbdevicename,omitempty"` - Lbdevicestate string `json:"lbdevicestate,omitempty"` - Physicalnetworkid string `json:"physicalnetworkid,omitempty"` - Podids []string `json:"podids,omitempty"` - Privateinterface string `json:"privateinterface,omitempty"` - Provider string `json:"provider,omitempty"` - Publicinterface string `json:"publicinterface,omitempty"` -} - -type DeleteNetscalerLoadBalancerParams struct { - p map[string]interface{} -} - -func (p *DeleteNetscalerLoadBalancerParams) toURLValues() url.Values { - u := url.Values{} - if p.p == nil { - return u - } - if v, found := p.p["lbdeviceid"]; found { - u.Set("lbdeviceid", v.(string)) - } - return u -} - -func (p *DeleteNetscalerLoadBalancerParams) SetLbdeviceid(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["lbdeviceid"] = v - return -} - -// You should always use this function to get a new DeleteNetscalerLoadBalancerParams instance, -// as then you are sure you have configured all required params -func (s *LoadBalancerService) NewDeleteNetscalerLoadBalancerParams(lbdeviceid string) *DeleteNetscalerLoadBalancerParams { - p := &DeleteNetscalerLoadBalancerParams{} - p.p = make(map[string]interface{}) - p.p["lbdeviceid"] = lbdeviceid - return p -} - -// delete a netscaler load balancer device -func (s *LoadBalancerService) DeleteNetscalerLoadBalancer(p *DeleteNetscalerLoadBalancerParams) (*DeleteNetscalerLoadBalancerResponse, error) { - resp, err := s.cs.newRequest("deleteNetscalerLoadBalancer", p.toURLValues()) - if err != nil { - return nil, err - } - - var r DeleteNetscalerLoadBalancerResponse - if err := json.Unmarshal(resp, &r); err != nil { - return nil, err - } - - // If we have a async client, we need to wait for the async result - if s.cs.async { - b, err := s.cs.GetAsyncJobResult(r.JobID, s.cs.timeout) - if err != nil { - if err == AsyncTimeoutErr { - return &r, err - } - return nil, err - } - - if err := json.Unmarshal(b, &r); err != nil { - return nil, err - } - } - return &r, nil -} - -type DeleteNetscalerLoadBalancerResponse struct { - JobID string `json:"jobid,omitempty"` - Displaytext string `json:"displaytext,omitempty"` - Success bool `json:"success,omitempty"` -} - -type ConfigureNetscalerLoadBalancerParams struct { - p map[string]interface{} -} - -func (p *ConfigureNetscalerLoadBalancerParams) toURLValues() url.Values { - u := url.Values{} - if p.p == nil { - return u - } - if v, found := p.p["inline"]; found { - vv := strconv.FormatBool(v.(bool)) - u.Set("inline", vv) - } - if v, found := p.p["lbdevicecapacity"]; found { - vv := strconv.FormatInt(v.(int64), 10) - u.Set("lbdevicecapacity", vv) - } - if v, found := p.p["lbdevicededicated"]; found { - vv := strconv.FormatBool(v.(bool)) - u.Set("lbdevicededicated", vv) - } - if v, found := p.p["lbdeviceid"]; found { - u.Set("lbdeviceid", v.(string)) - } - if v, found := p.p["podids"]; found { - vv := strings.Join(v.([]string), ",") - u.Set("podids", vv) - } - return u -} - -func (p *ConfigureNetscalerLoadBalancerParams) SetInline(v bool) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["inline"] = v - return -} - -func (p *ConfigureNetscalerLoadBalancerParams) SetLbdevicecapacity(v int64) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["lbdevicecapacity"] = v - return -} - -func (p *ConfigureNetscalerLoadBalancerParams) SetLbdevicededicated(v bool) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["lbdevicededicated"] = v - return -} - -func (p *ConfigureNetscalerLoadBalancerParams) SetLbdeviceid(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["lbdeviceid"] = v - return -} - -func (p *ConfigureNetscalerLoadBalancerParams) SetPodids(v []string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["podids"] = v - return -} - -// You should always use this function to get a new ConfigureNetscalerLoadBalancerParams instance, -// as then you are sure you have configured all required params -func (s *LoadBalancerService) NewConfigureNetscalerLoadBalancerParams(lbdeviceid string) *ConfigureNetscalerLoadBalancerParams { - p := &ConfigureNetscalerLoadBalancerParams{} - p.p = make(map[string]interface{}) - p.p["lbdeviceid"] = lbdeviceid - return p -} - -// configures a netscaler load balancer device -func (s *LoadBalancerService) ConfigureNetscalerLoadBalancer(p *ConfigureNetscalerLoadBalancerParams) (*ConfigureNetscalerLoadBalancerResponse, error) { - resp, err := s.cs.newRequest("configureNetscalerLoadBalancer", p.toURLValues()) - if err != nil { - return nil, err - } - - var r ConfigureNetscalerLoadBalancerResponse - if err := json.Unmarshal(resp, &r); err != nil { - return nil, err - } - - // If we have a async client, we need to wait for the async result - if s.cs.async { - b, err := s.cs.GetAsyncJobResult(r.JobID, s.cs.timeout) - if err != nil { - if err == AsyncTimeoutErr { - return &r, err - } - return nil, err - } - - b, err = getRawValue(b) - if err != nil { - return nil, err - } - - if err := json.Unmarshal(b, &r); err != nil { - return nil, err - } - } - return &r, nil -} - -type ConfigureNetscalerLoadBalancerResponse struct { - JobID string `json:"jobid,omitempty"` - Gslbprovider bool `json:"gslbprovider,omitempty"` - Gslbproviderprivateip string `json:"gslbproviderprivateip,omitempty"` - Gslbproviderpublicip string `json:"gslbproviderpublicip,omitempty"` - Ipaddress string `json:"ipaddress,omitempty"` - Isexclusivegslbprovider bool `json:"isexclusivegslbprovider,omitempty"` - Lbdevicecapacity int64 `json:"lbdevicecapacity,omitempty"` - Lbdevicededicated bool `json:"lbdevicededicated,omitempty"` - Lbdeviceid string `json:"lbdeviceid,omitempty"` - Lbdevicename string `json:"lbdevicename,omitempty"` - Lbdevicestate string `json:"lbdevicestate,omitempty"` - Physicalnetworkid string `json:"physicalnetworkid,omitempty"` - Podids []string `json:"podids,omitempty"` - Privateinterface string `json:"privateinterface,omitempty"` - Provider string `json:"provider,omitempty"` - Publicinterface string `json:"publicinterface,omitempty"` -} - -type ListNetscalerLoadBalancersParams struct { - p map[string]interface{} -} - -func (p *ListNetscalerLoadBalancersParams) toURLValues() url.Values { - u := url.Values{} - if p.p == nil { - return u - } - if v, found := p.p["keyword"]; found { - u.Set("keyword", v.(string)) - } - if v, found := p.p["lbdeviceid"]; found { - u.Set("lbdeviceid", v.(string)) - } - if v, found := p.p["page"]; found { - vv := strconv.Itoa(v.(int)) - u.Set("page", vv) - } - if v, found := p.p["pagesize"]; found { - vv := strconv.Itoa(v.(int)) - u.Set("pagesize", vv) - } - if v, found := p.p["physicalnetworkid"]; found { - u.Set("physicalnetworkid", v.(string)) - } - return u -} - -func (p *ListNetscalerLoadBalancersParams) SetKeyword(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["keyword"] = v - return -} - -func (p *ListNetscalerLoadBalancersParams) SetLbdeviceid(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["lbdeviceid"] = v - return -} - -func (p *ListNetscalerLoadBalancersParams) SetPage(v int) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["page"] = v - return -} - -func (p *ListNetscalerLoadBalancersParams) SetPagesize(v int) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["pagesize"] = v - return -} - -func (p *ListNetscalerLoadBalancersParams) SetPhysicalnetworkid(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["physicalnetworkid"] = v - return -} - -// You should always use this function to get a new ListNetscalerLoadBalancersParams instance, -// as then you are sure you have configured all required params -func (s *LoadBalancerService) NewListNetscalerLoadBalancersParams() *ListNetscalerLoadBalancersParams { - p := &ListNetscalerLoadBalancersParams{} - p.p = make(map[string]interface{}) - return p -} - -// lists netscaler load balancer devices -func (s *LoadBalancerService) ListNetscalerLoadBalancers(p *ListNetscalerLoadBalancersParams) (*ListNetscalerLoadBalancersResponse, error) { - resp, err := s.cs.newRequest("listNetscalerLoadBalancers", p.toURLValues()) - if err != nil { - return nil, err - } - - var r ListNetscalerLoadBalancersResponse - if err := json.Unmarshal(resp, &r); err != nil { - return nil, err - } - return &r, nil -} - -type ListNetscalerLoadBalancersResponse struct { - Count int `json:"count"` - NetscalerLoadBalancers []*NetscalerLoadBalancer `json:"netscalerloadbalancer"` -} - -type NetscalerLoadBalancer struct { - Gslbprovider bool `json:"gslbprovider,omitempty"` - Gslbproviderprivateip string `json:"gslbproviderprivateip,omitempty"` - Gslbproviderpublicip string `json:"gslbproviderpublicip,omitempty"` - Ipaddress string `json:"ipaddress,omitempty"` - Isexclusivegslbprovider bool `json:"isexclusivegslbprovider,omitempty"` - Lbdevicecapacity int64 `json:"lbdevicecapacity,omitempty"` - Lbdevicededicated bool `json:"lbdevicededicated,omitempty"` - Lbdeviceid string `json:"lbdeviceid,omitempty"` - Lbdevicename string `json:"lbdevicename,omitempty"` - Lbdevicestate string `json:"lbdevicestate,omitempty"` - Physicalnetworkid string `json:"physicalnetworkid,omitempty"` - Podids []string `json:"podids,omitempty"` - Privateinterface string `json:"privateinterface,omitempty"` - Provider string `json:"provider,omitempty"` - Publicinterface string `json:"publicinterface,omitempty"` -} - -type CreateGlobalLoadBalancerRuleParams struct { - p map[string]interface{} -} - -func (p *CreateGlobalLoadBalancerRuleParams) toURLValues() url.Values { - u := url.Values{} - if p.p == nil { - return u - } - if v, found := p.p["account"]; found { - u.Set("account", v.(string)) - } - if v, found := p.p["description"]; found { - u.Set("description", v.(string)) - } - if v, found := p.p["domainid"]; found { - u.Set("domainid", v.(string)) - } - if v, found := p.p["gslbdomainname"]; found { - u.Set("gslbdomainname", v.(string)) - } - if v, found := p.p["gslblbmethod"]; found { - u.Set("gslblbmethod", v.(string)) - } - if v, found := p.p["gslbservicetype"]; found { - u.Set("gslbservicetype", v.(string)) - } - if v, found := p.p["gslbstickysessionmethodname"]; found { - u.Set("gslbstickysessionmethodname", v.(string)) - } - if v, found := p.p["name"]; found { - u.Set("name", v.(string)) - } - if v, found := p.p["regionid"]; found { - vv := strconv.Itoa(v.(int)) - u.Set("regionid", vv) - } - return u -} - -func (p *CreateGlobalLoadBalancerRuleParams) SetAccount(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["account"] = v - return -} - -func (p *CreateGlobalLoadBalancerRuleParams) SetDescription(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["description"] = v - return -} - -func (p *CreateGlobalLoadBalancerRuleParams) SetDomainid(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["domainid"] = v - return -} - -func (p *CreateGlobalLoadBalancerRuleParams) SetGslbdomainname(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["gslbdomainname"] = v - return -} - -func (p *CreateGlobalLoadBalancerRuleParams) SetGslblbmethod(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["gslblbmethod"] = v - return -} - -func (p *CreateGlobalLoadBalancerRuleParams) SetGslbservicetype(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["gslbservicetype"] = v - return -} - -func (p *CreateGlobalLoadBalancerRuleParams) SetGslbstickysessionmethodname(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["gslbstickysessionmethodname"] = v - return -} - -func (p *CreateGlobalLoadBalancerRuleParams) SetName(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["name"] = v - return -} - -func (p *CreateGlobalLoadBalancerRuleParams) SetRegionid(v int) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["regionid"] = v - return -} - -// You should always use this function to get a new CreateGlobalLoadBalancerRuleParams instance, -// as then you are sure you have configured all required params -func (s *LoadBalancerService) NewCreateGlobalLoadBalancerRuleParams(gslbdomainname string, gslbservicetype string, name string, regionid int) *CreateGlobalLoadBalancerRuleParams { - p := &CreateGlobalLoadBalancerRuleParams{} - p.p = make(map[string]interface{}) - p.p["gslbdomainname"] = gslbdomainname - p.p["gslbservicetype"] = gslbservicetype - p.p["name"] = name - p.p["regionid"] = regionid - return p -} - -// Creates a global load balancer rule -func (s *LoadBalancerService) CreateGlobalLoadBalancerRule(p *CreateGlobalLoadBalancerRuleParams) (*CreateGlobalLoadBalancerRuleResponse, error) { - resp, err := s.cs.newRequest("createGlobalLoadBalancerRule", p.toURLValues()) - if err != nil { - return nil, err - } - - var r CreateGlobalLoadBalancerRuleResponse - if err := json.Unmarshal(resp, &r); err != nil { - return nil, err - } - - // If we have a async client, we need to wait for the async result - if s.cs.async { - b, err := s.cs.GetAsyncJobResult(r.JobID, s.cs.timeout) - if err != nil { - if err == AsyncTimeoutErr { - return &r, err - } - return nil, err - } - - b, err = getRawValue(b) - if err != nil { - return nil, err - } - - if err := json.Unmarshal(b, &r); err != nil { - return nil, err - } - } - return &r, nil -} - -type CreateGlobalLoadBalancerRuleResponse struct { - JobID string `json:"jobid,omitempty"` - Account string `json:"account,omitempty"` - Description string `json:"description,omitempty"` - Domain string `json:"domain,omitempty"` - Domainid string `json:"domainid,omitempty"` - Gslbdomainname string `json:"gslbdomainname,omitempty"` - Gslblbmethod string `json:"gslblbmethod,omitempty"` - Gslbservicetype string `json:"gslbservicetype,omitempty"` - Gslbstickysessionmethodname string `json:"gslbstickysessionmethodname,omitempty"` - Id string `json:"id,omitempty"` - Loadbalancerrule []struct { - Account string `json:"account,omitempty"` - Algorithm string `json:"algorithm,omitempty"` - Cidrlist string `json:"cidrlist,omitempty"` - Description string `json:"description,omitempty"` - Domain string `json:"domain,omitempty"` - Domainid string `json:"domainid,omitempty"` - Fordisplay bool `json:"fordisplay,omitempty"` - Id string `json:"id,omitempty"` - Name string `json:"name,omitempty"` - Networkid string `json:"networkid,omitempty"` - Privateport string `json:"privateport,omitempty"` - Project string `json:"project,omitempty"` - Projectid string `json:"projectid,omitempty"` - Protocol string `json:"protocol,omitempty"` - Publicip string `json:"publicip,omitempty"` - Publicipid string `json:"publicipid,omitempty"` - Publicport string `json:"publicport,omitempty"` - State string `json:"state,omitempty"` - Tags []struct { - Account string `json:"account,omitempty"` - Customer string `json:"customer,omitempty"` - Domain string `json:"domain,omitempty"` - Domainid string `json:"domainid,omitempty"` - Key string `json:"key,omitempty"` - Project string `json:"project,omitempty"` - Projectid string `json:"projectid,omitempty"` - Resourceid string `json:"resourceid,omitempty"` - Resourcetype string `json:"resourcetype,omitempty"` - Value string `json:"value,omitempty"` - } `json:"tags,omitempty"` - Zoneid string `json:"zoneid,omitempty"` - } `json:"loadbalancerrule,omitempty"` - Name string `json:"name,omitempty"` - Project string `json:"project,omitempty"` - Projectid string `json:"projectid,omitempty"` - Regionid int `json:"regionid,omitempty"` -} - -type DeleteGlobalLoadBalancerRuleParams struct { - p map[string]interface{} -} - -func (p *DeleteGlobalLoadBalancerRuleParams) toURLValues() url.Values { - u := url.Values{} - if p.p == nil { - return u - } - if v, found := p.p["id"]; found { - u.Set("id", v.(string)) - } - return u -} - -func (p *DeleteGlobalLoadBalancerRuleParams) SetId(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["id"] = v - return -} - -// You should always use this function to get a new DeleteGlobalLoadBalancerRuleParams instance, -// as then you are sure you have configured all required params -func (s *LoadBalancerService) NewDeleteGlobalLoadBalancerRuleParams(id string) *DeleteGlobalLoadBalancerRuleParams { - p := &DeleteGlobalLoadBalancerRuleParams{} - p.p = make(map[string]interface{}) - p.p["id"] = id - return p -} - -// Deletes a global load balancer rule. -func (s *LoadBalancerService) DeleteGlobalLoadBalancerRule(p *DeleteGlobalLoadBalancerRuleParams) (*DeleteGlobalLoadBalancerRuleResponse, error) { - resp, err := s.cs.newRequest("deleteGlobalLoadBalancerRule", p.toURLValues()) - if err != nil { - return nil, err - } - - var r DeleteGlobalLoadBalancerRuleResponse - if err := json.Unmarshal(resp, &r); err != nil { - return nil, err - } - - // If we have a async client, we need to wait for the async result - if s.cs.async { - b, err := s.cs.GetAsyncJobResult(r.JobID, s.cs.timeout) - if err != nil { - if err == AsyncTimeoutErr { - return &r, err - } - return nil, err - } - - if err := json.Unmarshal(b, &r); err != nil { - return nil, err - } - } - return &r, nil -} - -type DeleteGlobalLoadBalancerRuleResponse struct { - JobID string `json:"jobid,omitempty"` - Displaytext string `json:"displaytext,omitempty"` - Success bool `json:"success,omitempty"` -} - -type UpdateGlobalLoadBalancerRuleParams struct { - p map[string]interface{} -} - -func (p *UpdateGlobalLoadBalancerRuleParams) toURLValues() url.Values { - u := url.Values{} - if p.p == nil { - return u - } - if v, found := p.p["description"]; found { - u.Set("description", v.(string)) - } - if v, found := p.p["gslblbmethod"]; found { - u.Set("gslblbmethod", v.(string)) - } - if v, found := p.p["gslbstickysessionmethodname"]; found { - u.Set("gslbstickysessionmethodname", v.(string)) - } - if v, found := p.p["id"]; found { - u.Set("id", v.(string)) - } - return u -} - -func (p *UpdateGlobalLoadBalancerRuleParams) SetDescription(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["description"] = v - return -} - -func (p *UpdateGlobalLoadBalancerRuleParams) SetGslblbmethod(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["gslblbmethod"] = v - return -} - -func (p *UpdateGlobalLoadBalancerRuleParams) SetGslbstickysessionmethodname(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["gslbstickysessionmethodname"] = v - return -} - -func (p *UpdateGlobalLoadBalancerRuleParams) SetId(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["id"] = v - return -} - -// You should always use this function to get a new UpdateGlobalLoadBalancerRuleParams instance, -// as then you are sure you have configured all required params -func (s *LoadBalancerService) NewUpdateGlobalLoadBalancerRuleParams(id string) *UpdateGlobalLoadBalancerRuleParams { - p := &UpdateGlobalLoadBalancerRuleParams{} - p.p = make(map[string]interface{}) - p.p["id"] = id - return p -} - -// update global load balancer rules. -func (s *LoadBalancerService) UpdateGlobalLoadBalancerRule(p *UpdateGlobalLoadBalancerRuleParams) (*UpdateGlobalLoadBalancerRuleResponse, error) { - resp, err := s.cs.newRequest("updateGlobalLoadBalancerRule", p.toURLValues()) - if err != nil { - return nil, err - } - - var r UpdateGlobalLoadBalancerRuleResponse - if err := json.Unmarshal(resp, &r); err != nil { - return nil, err - } - - // If we have a async client, we need to wait for the async result - if s.cs.async { - b, err := s.cs.GetAsyncJobResult(r.JobID, s.cs.timeout) - if err != nil { - if err == AsyncTimeoutErr { - return &r, err - } - return nil, err - } - - b, err = getRawValue(b) - if err != nil { - return nil, err - } - - if err := json.Unmarshal(b, &r); err != nil { - return nil, err - } - } - return &r, nil -} - -type UpdateGlobalLoadBalancerRuleResponse struct { - JobID string `json:"jobid,omitempty"` - Account string `json:"account,omitempty"` - Description string `json:"description,omitempty"` - Domain string `json:"domain,omitempty"` - Domainid string `json:"domainid,omitempty"` - Gslbdomainname string `json:"gslbdomainname,omitempty"` - Gslblbmethod string `json:"gslblbmethod,omitempty"` - Gslbservicetype string `json:"gslbservicetype,omitempty"` - Gslbstickysessionmethodname string `json:"gslbstickysessionmethodname,omitempty"` - Id string `json:"id,omitempty"` - Loadbalancerrule []struct { - Account string `json:"account,omitempty"` - Algorithm string `json:"algorithm,omitempty"` - Cidrlist string `json:"cidrlist,omitempty"` - Description string `json:"description,omitempty"` - Domain string `json:"domain,omitempty"` - Domainid string `json:"domainid,omitempty"` - Fordisplay bool `json:"fordisplay,omitempty"` - Id string `json:"id,omitempty"` - Name string `json:"name,omitempty"` - Networkid string `json:"networkid,omitempty"` - Privateport string `json:"privateport,omitempty"` - Project string `json:"project,omitempty"` - Projectid string `json:"projectid,omitempty"` - Protocol string `json:"protocol,omitempty"` - Publicip string `json:"publicip,omitempty"` - Publicipid string `json:"publicipid,omitempty"` - Publicport string `json:"publicport,omitempty"` - State string `json:"state,omitempty"` - Tags []struct { - Account string `json:"account,omitempty"` - Customer string `json:"customer,omitempty"` - Domain string `json:"domain,omitempty"` - Domainid string `json:"domainid,omitempty"` - Key string `json:"key,omitempty"` - Project string `json:"project,omitempty"` - Projectid string `json:"projectid,omitempty"` - Resourceid string `json:"resourceid,omitempty"` - Resourcetype string `json:"resourcetype,omitempty"` - Value string `json:"value,omitempty"` - } `json:"tags,omitempty"` - Zoneid string `json:"zoneid,omitempty"` - } `json:"loadbalancerrule,omitempty"` - Name string `json:"name,omitempty"` - Project string `json:"project,omitempty"` - Projectid string `json:"projectid,omitempty"` - Regionid int `json:"regionid,omitempty"` -} - -type ListGlobalLoadBalancerRulesParams struct { - p map[string]interface{} -} - -func (p *ListGlobalLoadBalancerRulesParams) toURLValues() url.Values { - u := url.Values{} - if p.p == nil { - return u - } - if v, found := p.p["account"]; found { - u.Set("account", v.(string)) - } - if v, found := p.p["domainid"]; found { - u.Set("domainid", v.(string)) - } - if v, found := p.p["id"]; found { - u.Set("id", v.(string)) - } - if v, found := p.p["isrecursive"]; found { - vv := strconv.FormatBool(v.(bool)) - u.Set("isrecursive", vv) - } - if v, found := p.p["keyword"]; found { - u.Set("keyword", v.(string)) - } - if v, found := p.p["listall"]; found { - vv := strconv.FormatBool(v.(bool)) - u.Set("listall", vv) - } - if v, found := p.p["page"]; found { - vv := strconv.Itoa(v.(int)) - u.Set("page", vv) - } - if v, found := p.p["pagesize"]; found { - vv := strconv.Itoa(v.(int)) - u.Set("pagesize", vv) - } - if v, found := p.p["projectid"]; found { - u.Set("projectid", v.(string)) - } - if v, found := p.p["regionid"]; found { - vv := strconv.Itoa(v.(int)) - u.Set("regionid", vv) - } - if v, found := p.p["tags"]; found { - i := 0 - for k, vv := range v.(map[string]string) { - u.Set(fmt.Sprintf("tags[%d].key", i), k) - u.Set(fmt.Sprintf("tags[%d].value", i), vv) - i++ - } - } - return u -} - -func (p *ListGlobalLoadBalancerRulesParams) SetAccount(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["account"] = v - return -} - -func (p *ListGlobalLoadBalancerRulesParams) SetDomainid(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["domainid"] = v - return -} - -func (p *ListGlobalLoadBalancerRulesParams) SetId(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["id"] = v - return -} - -func (p *ListGlobalLoadBalancerRulesParams) SetIsrecursive(v bool) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["isrecursive"] = v - return -} - -func (p *ListGlobalLoadBalancerRulesParams) SetKeyword(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["keyword"] = v - return -} - -func (p *ListGlobalLoadBalancerRulesParams) SetListall(v bool) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["listall"] = v - return -} - -func (p *ListGlobalLoadBalancerRulesParams) SetPage(v int) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["page"] = v - return -} - -func (p *ListGlobalLoadBalancerRulesParams) SetPagesize(v int) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["pagesize"] = v - return -} - -func (p *ListGlobalLoadBalancerRulesParams) SetProjectid(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["projectid"] = v - return -} - -func (p *ListGlobalLoadBalancerRulesParams) SetRegionid(v int) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["regionid"] = v - return -} - -func (p *ListGlobalLoadBalancerRulesParams) SetTags(v map[string]string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["tags"] = v - return -} - -// You should always use this function to get a new ListGlobalLoadBalancerRulesParams instance, -// as then you are sure you have configured all required params -func (s *LoadBalancerService) NewListGlobalLoadBalancerRulesParams() *ListGlobalLoadBalancerRulesParams { - p := &ListGlobalLoadBalancerRulesParams{} - p.p = make(map[string]interface{}) - return p -} - -// This is a courtesy helper function, which in some cases may not work as expected! -func (s *LoadBalancerService) GetGlobalLoadBalancerRuleID(keyword string, opts ...OptionFunc) (string, int, error) { - p := &ListGlobalLoadBalancerRulesParams{} - p.p = make(map[string]interface{}) - - p.p["keyword"] = keyword - - for _, fn := range opts { - if err := fn(s.cs, p); err != nil { - return "", -1, err - } - } - - l, err := s.ListGlobalLoadBalancerRules(p) - if err != nil { - return "", -1, err - } - - if l.Count == 0 { - return "", l.Count, fmt.Errorf("No match found for %s: %+v", keyword, l) - } - - if l.Count == 1 { - return l.GlobalLoadBalancerRules[0].Id, l.Count, nil - } - - if l.Count > 1 { - for _, v := range l.GlobalLoadBalancerRules { - if v.Name == keyword { - return v.Id, l.Count, nil - } - } - } - return "", l.Count, fmt.Errorf("Could not find an exact match for %s: %+v", keyword, l) -} - -// This is a courtesy helper function, which in some cases may not work as expected! -func (s *LoadBalancerService) GetGlobalLoadBalancerRuleByName(name string, opts ...OptionFunc) (*GlobalLoadBalancerRule, int, error) { - id, count, err := s.GetGlobalLoadBalancerRuleID(name, opts...) - if err != nil { - return nil, count, err - } - - r, count, err := s.GetGlobalLoadBalancerRuleByID(id, opts...) - if err != nil { - return nil, count, err - } - return r, count, nil -} - -// This is a courtesy helper function, which in some cases may not work as expected! -func (s *LoadBalancerService) GetGlobalLoadBalancerRuleByID(id string, opts ...OptionFunc) (*GlobalLoadBalancerRule, int, error) { - p := &ListGlobalLoadBalancerRulesParams{} - p.p = make(map[string]interface{}) - - p.p["id"] = id - - for _, fn := range opts { - if err := fn(s.cs, p); err != nil { - return nil, -1, err - } - } - - l, err := s.ListGlobalLoadBalancerRules(p) - if err != nil { - if strings.Contains(err.Error(), fmt.Sprintf( - "Invalid parameter id value=%s due to incorrect long value format, "+ - "or entity does not exist", id)) { - return nil, 0, fmt.Errorf("No match found for %s: %+v", id, l) - } - return nil, -1, err - } - - if l.Count == 0 { - return nil, l.Count, fmt.Errorf("No match found for %s: %+v", id, l) - } - - if l.Count == 1 { - return l.GlobalLoadBalancerRules[0], l.Count, nil - } - return nil, l.Count, fmt.Errorf("There is more then one result for GlobalLoadBalancerRule UUID: %s!", id) -} - -// Lists load balancer rules. -func (s *LoadBalancerService) ListGlobalLoadBalancerRules(p *ListGlobalLoadBalancerRulesParams) (*ListGlobalLoadBalancerRulesResponse, error) { - resp, err := s.cs.newRequest("listGlobalLoadBalancerRules", p.toURLValues()) - if err != nil { - return nil, err - } - - var r ListGlobalLoadBalancerRulesResponse - if err := json.Unmarshal(resp, &r); err != nil { - return nil, err - } - return &r, nil -} - -type ListGlobalLoadBalancerRulesResponse struct { - Count int `json:"count"` - GlobalLoadBalancerRules []*GlobalLoadBalancerRule `json:"globalloadbalancerrule"` -} - -type GlobalLoadBalancerRule struct { - Account string `json:"account,omitempty"` - Description string `json:"description,omitempty"` - Domain string `json:"domain,omitempty"` - Domainid string `json:"domainid,omitempty"` - Gslbdomainname string `json:"gslbdomainname,omitempty"` - Gslblbmethod string `json:"gslblbmethod,omitempty"` - Gslbservicetype string `json:"gslbservicetype,omitempty"` - Gslbstickysessionmethodname string `json:"gslbstickysessionmethodname,omitempty"` - Id string `json:"id,omitempty"` - Loadbalancerrule []struct { - Account string `json:"account,omitempty"` - Algorithm string `json:"algorithm,omitempty"` - Cidrlist string `json:"cidrlist,omitempty"` - Description string `json:"description,omitempty"` - Domain string `json:"domain,omitempty"` - Domainid string `json:"domainid,omitempty"` - Fordisplay bool `json:"fordisplay,omitempty"` - Id string `json:"id,omitempty"` - Name string `json:"name,omitempty"` - Networkid string `json:"networkid,omitempty"` - Privateport string `json:"privateport,omitempty"` - Project string `json:"project,omitempty"` - Projectid string `json:"projectid,omitempty"` - Protocol string `json:"protocol,omitempty"` - Publicip string `json:"publicip,omitempty"` - Publicipid string `json:"publicipid,omitempty"` - Publicport string `json:"publicport,omitempty"` - State string `json:"state,omitempty"` - Tags []struct { - Account string `json:"account,omitempty"` - Customer string `json:"customer,omitempty"` - Domain string `json:"domain,omitempty"` - Domainid string `json:"domainid,omitempty"` - Key string `json:"key,omitempty"` - Project string `json:"project,omitempty"` - Projectid string `json:"projectid,omitempty"` - Resourceid string `json:"resourceid,omitempty"` - Resourcetype string `json:"resourcetype,omitempty"` - Value string `json:"value,omitempty"` - } `json:"tags,omitempty"` - Zoneid string `json:"zoneid,omitempty"` - } `json:"loadbalancerrule,omitempty"` - Name string `json:"name,omitempty"` - Project string `json:"project,omitempty"` - Projectid string `json:"projectid,omitempty"` - Regionid int `json:"regionid,omitempty"` -} - -type AssignToGlobalLoadBalancerRuleParams struct { - p map[string]interface{} -} - -func (p *AssignToGlobalLoadBalancerRuleParams) toURLValues() url.Values { - u := url.Values{} - if p.p == nil { - return u - } - if v, found := p.p["gslblbruleweightsmap"]; found { - i := 0 - for k, vv := range v.(map[string]string) { - u.Set(fmt.Sprintf("gslblbruleweightsmap[%d].key", i), k) - u.Set(fmt.Sprintf("gslblbruleweightsmap[%d].value", i), vv) - i++ - } - } - if v, found := p.p["id"]; found { - u.Set("id", v.(string)) - } - if v, found := p.p["loadbalancerrulelist"]; found { - vv := strings.Join(v.([]string), ",") - u.Set("loadbalancerrulelist", vv) - } - return u -} - -func (p *AssignToGlobalLoadBalancerRuleParams) SetGslblbruleweightsmap(v map[string]string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["gslblbruleweightsmap"] = v - return -} - -func (p *AssignToGlobalLoadBalancerRuleParams) SetId(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["id"] = v - return -} - -func (p *AssignToGlobalLoadBalancerRuleParams) SetLoadbalancerrulelist(v []string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["loadbalancerrulelist"] = v - return -} - -// You should always use this function to get a new AssignToGlobalLoadBalancerRuleParams instance, -// as then you are sure you have configured all required params -func (s *LoadBalancerService) NewAssignToGlobalLoadBalancerRuleParams(id string, loadbalancerrulelist []string) *AssignToGlobalLoadBalancerRuleParams { - p := &AssignToGlobalLoadBalancerRuleParams{} - p.p = make(map[string]interface{}) - p.p["id"] = id - p.p["loadbalancerrulelist"] = loadbalancerrulelist - return p -} - -// Assign load balancer rule or list of load balancer rules to a global load balancer rules. -func (s *LoadBalancerService) AssignToGlobalLoadBalancerRule(p *AssignToGlobalLoadBalancerRuleParams) (*AssignToGlobalLoadBalancerRuleResponse, error) { - resp, err := s.cs.newRequest("assignToGlobalLoadBalancerRule", p.toURLValues()) - if err != nil { - return nil, err - } - - var r AssignToGlobalLoadBalancerRuleResponse - if err := json.Unmarshal(resp, &r); err != nil { - return nil, err - } - - // If we have a async client, we need to wait for the async result - if s.cs.async { - b, err := s.cs.GetAsyncJobResult(r.JobID, s.cs.timeout) - if err != nil { - if err == AsyncTimeoutErr { - return &r, err - } - return nil, err - } - - if err := json.Unmarshal(b, &r); err != nil { - return nil, err - } - } - return &r, nil -} - -type AssignToGlobalLoadBalancerRuleResponse struct { - JobID string `json:"jobid,omitempty"` - Displaytext string `json:"displaytext,omitempty"` - Success bool `json:"success,omitempty"` -} - -type RemoveFromGlobalLoadBalancerRuleParams struct { - p map[string]interface{} -} - -func (p *RemoveFromGlobalLoadBalancerRuleParams) toURLValues() url.Values { - u := url.Values{} - if p.p == nil { - return u - } - if v, found := p.p["id"]; found { - u.Set("id", v.(string)) - } - if v, found := p.p["loadbalancerrulelist"]; found { - vv := strings.Join(v.([]string), ",") - u.Set("loadbalancerrulelist", vv) - } - return u -} - -func (p *RemoveFromGlobalLoadBalancerRuleParams) SetId(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["id"] = v - return -} - -func (p *RemoveFromGlobalLoadBalancerRuleParams) SetLoadbalancerrulelist(v []string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["loadbalancerrulelist"] = v - return -} - -// You should always use this function to get a new RemoveFromGlobalLoadBalancerRuleParams instance, -// as then you are sure you have configured all required params -func (s *LoadBalancerService) NewRemoveFromGlobalLoadBalancerRuleParams(id string, loadbalancerrulelist []string) *RemoveFromGlobalLoadBalancerRuleParams { - p := &RemoveFromGlobalLoadBalancerRuleParams{} - p.p = make(map[string]interface{}) - p.p["id"] = id - p.p["loadbalancerrulelist"] = loadbalancerrulelist - return p -} - -// Removes a load balancer rule association with global load balancer rule -func (s *LoadBalancerService) RemoveFromGlobalLoadBalancerRule(p *RemoveFromGlobalLoadBalancerRuleParams) (*RemoveFromGlobalLoadBalancerRuleResponse, error) { - resp, err := s.cs.newRequest("removeFromGlobalLoadBalancerRule", p.toURLValues()) - if err != nil { - return nil, err - } - - var r RemoveFromGlobalLoadBalancerRuleResponse - if err := json.Unmarshal(resp, &r); err != nil { - return nil, err - } - - // If we have a async client, we need to wait for the async result - if s.cs.async { - b, err := s.cs.GetAsyncJobResult(r.JobID, s.cs.timeout) - if err != nil { - if err == AsyncTimeoutErr { - return &r, err - } - return nil, err - } - - if err := json.Unmarshal(b, &r); err != nil { - return nil, err - } - } - return &r, nil -} - -type RemoveFromGlobalLoadBalancerRuleResponse struct { - JobID string `json:"jobid,omitempty"` - Displaytext string `json:"displaytext,omitempty"` - Success bool `json:"success,omitempty"` -} - -type CreateLoadBalancerParams struct { - p map[string]interface{} -} - -func (p *CreateLoadBalancerParams) toURLValues() url.Values { - u := url.Values{} - if p.p == nil { - return u - } - if v, found := p.p["algorithm"]; found { - u.Set("algorithm", v.(string)) - } - if v, found := p.p["description"]; found { - u.Set("description", v.(string)) - } - if v, found := p.p["fordisplay"]; found { - vv := strconv.FormatBool(v.(bool)) - u.Set("fordisplay", vv) - } - if v, found := p.p["instanceport"]; found { - vv := strconv.Itoa(v.(int)) - u.Set("instanceport", vv) - } - if v, found := p.p["name"]; found { - u.Set("name", v.(string)) - } - if v, found := p.p["networkid"]; found { - u.Set("networkid", v.(string)) - } - if v, found := p.p["scheme"]; found { - u.Set("scheme", v.(string)) - } - if v, found := p.p["sourceipaddress"]; found { - u.Set("sourceipaddress", v.(string)) - } - if v, found := p.p["sourceipaddressnetworkid"]; found { - u.Set("sourceipaddressnetworkid", v.(string)) - } - if v, found := p.p["sourceport"]; found { - vv := strconv.Itoa(v.(int)) - u.Set("sourceport", vv) - } - return u -} - -func (p *CreateLoadBalancerParams) SetAlgorithm(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["algorithm"] = v - return -} - -func (p *CreateLoadBalancerParams) SetDescription(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["description"] = v - return -} - -func (p *CreateLoadBalancerParams) SetFordisplay(v bool) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["fordisplay"] = v - return -} - -func (p *CreateLoadBalancerParams) SetInstanceport(v int) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["instanceport"] = v - return -} - -func (p *CreateLoadBalancerParams) SetName(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["name"] = v - return -} - -func (p *CreateLoadBalancerParams) SetNetworkid(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["networkid"] = v - return -} - -func (p *CreateLoadBalancerParams) SetScheme(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["scheme"] = v - return -} - -func (p *CreateLoadBalancerParams) SetSourceipaddress(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["sourceipaddress"] = v - return -} - -func (p *CreateLoadBalancerParams) SetSourceipaddressnetworkid(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["sourceipaddressnetworkid"] = v - return -} - -func (p *CreateLoadBalancerParams) SetSourceport(v int) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["sourceport"] = v - return -} - -// You should always use this function to get a new CreateLoadBalancerParams instance, -// as then you are sure you have configured all required params -func (s *LoadBalancerService) NewCreateLoadBalancerParams(algorithm string, instanceport int, name string, networkid string, scheme string, sourceipaddressnetworkid string, sourceport int) *CreateLoadBalancerParams { - p := &CreateLoadBalancerParams{} - p.p = make(map[string]interface{}) - p.p["algorithm"] = algorithm - p.p["instanceport"] = instanceport - p.p["name"] = name - p.p["networkid"] = networkid - p.p["scheme"] = scheme - p.p["sourceipaddressnetworkid"] = sourceipaddressnetworkid - p.p["sourceport"] = sourceport - return p -} - -// Creates a load balancer -func (s *LoadBalancerService) CreateLoadBalancer(p *CreateLoadBalancerParams) (*CreateLoadBalancerResponse, error) { - resp, err := s.cs.newRequest("createLoadBalancer", p.toURLValues()) - if err != nil { - return nil, err - } - - var r CreateLoadBalancerResponse - if err := json.Unmarshal(resp, &r); err != nil { - return nil, err - } - - // If we have a async client, we need to wait for the async result - if s.cs.async { - b, err := s.cs.GetAsyncJobResult(r.JobID, s.cs.timeout) - if err != nil { - if err == AsyncTimeoutErr { - return &r, err - } - return nil, err - } - - b, err = getRawValue(b) - if err != nil { - return nil, err - } - - if err := json.Unmarshal(b, &r); err != nil { - return nil, err - } - } - return &r, nil -} - -type CreateLoadBalancerResponse struct { - JobID string `json:"jobid,omitempty"` - Account string `json:"account,omitempty"` - Algorithm string `json:"algorithm,omitempty"` - Description string `json:"description,omitempty"` - Domain string `json:"domain,omitempty"` - Domainid string `json:"domainid,omitempty"` - Fordisplay bool `json:"fordisplay,omitempty"` - Id string `json:"id,omitempty"` - Loadbalancerinstance []struct { - Id string `json:"id,omitempty"` - Ipaddress string `json:"ipaddress,omitempty"` - Name string `json:"name,omitempty"` - State string `json:"state,omitempty"` - } `json:"loadbalancerinstance,omitempty"` - Loadbalancerrule []struct { - Instanceport int `json:"instanceport,omitempty"` - Sourceport int `json:"sourceport,omitempty"` - State string `json:"state,omitempty"` - } `json:"loadbalancerrule,omitempty"` - Name string `json:"name,omitempty"` - Networkid string `json:"networkid,omitempty"` - Project string `json:"project,omitempty"` - Projectid string `json:"projectid,omitempty"` - Sourceipaddress string `json:"sourceipaddress,omitempty"` - Sourceipaddressnetworkid string `json:"sourceipaddressnetworkid,omitempty"` - Tags []struct { - Account string `json:"account,omitempty"` - Customer string `json:"customer,omitempty"` - Domain string `json:"domain,omitempty"` - Domainid string `json:"domainid,omitempty"` - Key string `json:"key,omitempty"` - Project string `json:"project,omitempty"` - Projectid string `json:"projectid,omitempty"` - Resourceid string `json:"resourceid,omitempty"` - Resourcetype string `json:"resourcetype,omitempty"` - Value string `json:"value,omitempty"` - } `json:"tags,omitempty"` + Account string `json:"account"` + Algorithm string `json:"algorithm"` + Cidrlist string `json:"cidrlist"` + Description string `json:"description"` + Domain string `json:"domain"` + Domainid string `json:"domainid"` + Fordisplay bool `json:"fordisplay"` + Id string `json:"id"` + Name string `json:"name"` + Networkid string `json:"networkid"` + Privateport string `json:"privateport"` + Project string `json:"project"` + Projectid string `json:"projectid"` + Protocol string `json:"protocol"` + Publicip string `json:"publicip"` + Publicipid string `json:"publicipid"` + Publicport string `json:"publicport"` + State string `json:"state"` + Tags []Tags `json:"tags"` + Zoneid string `json:"zoneid"` + Zonename string `json:"zonename"` } type ListLoadBalancersParams struct { @@ -4414,7 +3384,7 @@ func (s *LoadBalancerService) GetLoadBalancerID(name string, opts ...OptionFunc) p.p["name"] = name - for _, fn := range opts { + for _, fn := range append(s.cs.options, opts...) { if err := fn(s.cs, p); err != nil { return "", -1, err } @@ -4464,7 +3434,7 @@ func (s *LoadBalancerService) GetLoadBalancerByID(id string, opts ...OptionFunc) p.p["id"] = id - for _, fn := range opts { + for _, fn := range append(s.cs.options, opts...) { if err := fn(s.cs, p); err != nil { return nil, -1, err } @@ -4501,6 +3471,7 @@ func (s *LoadBalancerService) ListLoadBalancers(p *ListLoadBalancersParams) (*Li if err := json.Unmarshal(resp, &r); err != nil { return nil, err } + return &r, nil } @@ -4510,84 +3481,290 @@ type ListLoadBalancersResponse struct { } type LoadBalancer struct { - Account string `json:"account,omitempty"` - Algorithm string `json:"algorithm,omitempty"` - Description string `json:"description,omitempty"` - Domain string `json:"domain,omitempty"` - Domainid string `json:"domainid,omitempty"` - Fordisplay bool `json:"fordisplay,omitempty"` - Id string `json:"id,omitempty"` - Loadbalancerinstance []struct { - Id string `json:"id,omitempty"` - Ipaddress string `json:"ipaddress,omitempty"` - Name string `json:"name,omitempty"` - State string `json:"state,omitempty"` - } `json:"loadbalancerinstance,omitempty"` - Loadbalancerrule []struct { - Instanceport int `json:"instanceport,omitempty"` - Sourceport int `json:"sourceport,omitempty"` - State string `json:"state,omitempty"` - } `json:"loadbalancerrule,omitempty"` - Name string `json:"name,omitempty"` - Networkid string `json:"networkid,omitempty"` - Project string `json:"project,omitempty"` - Projectid string `json:"projectid,omitempty"` - Sourceipaddress string `json:"sourceipaddress,omitempty"` - Sourceipaddressnetworkid string `json:"sourceipaddressnetworkid,omitempty"` - Tags []struct { - Account string `json:"account,omitempty"` - Customer string `json:"customer,omitempty"` - Domain string `json:"domain,omitempty"` - Domainid string `json:"domainid,omitempty"` - Key string `json:"key,omitempty"` - Project string `json:"project,omitempty"` - Projectid string `json:"projectid,omitempty"` - Resourceid string `json:"resourceid,omitempty"` - Resourcetype string `json:"resourcetype,omitempty"` - Value string `json:"value,omitempty"` - } `json:"tags,omitempty"` + Account string `json:"account"` + Algorithm string `json:"algorithm"` + Description string `json:"description"` + Domain string `json:"domain"` + Domainid string `json:"domainid"` + Fordisplay bool `json:"fordisplay"` + Id string `json:"id"` + Loadbalancerinstance []LoadBalancerLoadbalancerinstance `json:"loadbalancerinstance"` + Loadbalancerrule []LoadBalancerLoadbalancerrule `json:"loadbalancerrule"` + Name string `json:"name"` + Networkid string `json:"networkid"` + Project string `json:"project"` + Projectid string `json:"projectid"` + Sourceipaddress string `json:"sourceipaddress"` + Sourceipaddressnetworkid string `json:"sourceipaddressnetworkid"` + Tags []Tags `json:"tags"` } -type DeleteLoadBalancerParams struct { +type LoadBalancerLoadbalancerrule struct { + Instanceport int `json:"instanceport"` + Sourceport int `json:"sourceport"` + State string `json:"state"` +} + +type LoadBalancerLoadbalancerinstance struct { + Id string `json:"id"` + Ipaddress string `json:"ipaddress"` + Name string `json:"name"` + State string `json:"state"` +} + +type ListNetscalerLoadBalancersParams struct { p map[string]interface{} } -func (p *DeleteLoadBalancerParams) toURLValues() url.Values { +func (p *ListNetscalerLoadBalancersParams) toURLValues() url.Values { u := url.Values{} if p.p == nil { return u } - if v, found := p.p["id"]; found { - u.Set("id", v.(string)) + if v, found := p.p["keyword"]; found { + u.Set("keyword", v.(string)) + } + if v, found := p.p["lbdeviceid"]; found { + u.Set("lbdeviceid", v.(string)) + } + if v, found := p.p["page"]; found { + vv := strconv.Itoa(v.(int)) + u.Set("page", vv) + } + if v, found := p.p["pagesize"]; found { + vv := strconv.Itoa(v.(int)) + u.Set("pagesize", vv) + } + if v, found := p.p["physicalnetworkid"]; found { + u.Set("physicalnetworkid", v.(string)) } return u } -func (p *DeleteLoadBalancerParams) SetId(v string) { +func (p *ListNetscalerLoadBalancersParams) SetKeyword(v string) { if p.p == nil { p.p = make(map[string]interface{}) } - p.p["id"] = v + p.p["keyword"] = v return } -// You should always use this function to get a new DeleteLoadBalancerParams instance, +func (p *ListNetscalerLoadBalancersParams) SetLbdeviceid(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["lbdeviceid"] = v + return +} + +func (p *ListNetscalerLoadBalancersParams) SetPage(v int) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["page"] = v + return +} + +func (p *ListNetscalerLoadBalancersParams) SetPagesize(v int) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["pagesize"] = v + return +} + +func (p *ListNetscalerLoadBalancersParams) SetPhysicalnetworkid(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["physicalnetworkid"] = v + return +} + +// You should always use this function to get a new ListNetscalerLoadBalancersParams instance, // as then you are sure you have configured all required params -func (s *LoadBalancerService) NewDeleteLoadBalancerParams(id string) *DeleteLoadBalancerParams { - p := &DeleteLoadBalancerParams{} +func (s *LoadBalancerService) NewListNetscalerLoadBalancersParams() *ListNetscalerLoadBalancersParams { + p := &ListNetscalerLoadBalancersParams{} p.p = make(map[string]interface{}) - p.p["id"] = id return p } -// Deletes a load balancer -func (s *LoadBalancerService) DeleteLoadBalancer(p *DeleteLoadBalancerParams) (*DeleteLoadBalancerResponse, error) { - resp, err := s.cs.newRequest("deleteLoadBalancer", p.toURLValues()) +// lists netscaler load balancer devices +func (s *LoadBalancerService) ListNetscalerLoadBalancers(p *ListNetscalerLoadBalancersParams) (*ListNetscalerLoadBalancersResponse, error) { + resp, err := s.cs.newRequest("listNetscalerLoadBalancers", p.toURLValues()) if err != nil { return nil, err } - var r DeleteLoadBalancerResponse + var r ListNetscalerLoadBalancersResponse + if err := json.Unmarshal(resp, &r); err != nil { + return nil, err + } + + return &r, nil +} + +type ListNetscalerLoadBalancersResponse struct { + Count int `json:"count"` + NetscalerLoadBalancers []*NetscalerLoadBalancer `json:"netscalerloadbalancer"` +} + +type NetscalerLoadBalancer struct { + Gslbprovider bool `json:"gslbprovider"` + Gslbproviderprivateip string `json:"gslbproviderprivateip"` + Gslbproviderpublicip string `json:"gslbproviderpublicip"` + Ipaddress string `json:"ipaddress"` + Isexclusivegslbprovider bool `json:"isexclusivegslbprovider"` + Lbdevicecapacity int64 `json:"lbdevicecapacity"` + Lbdevicededicated bool `json:"lbdevicededicated"` + Lbdeviceid string `json:"lbdeviceid"` + Lbdevicename string `json:"lbdevicename"` + Lbdevicestate string `json:"lbdevicestate"` + Physicalnetworkid string `json:"physicalnetworkid"` + Podids []string `json:"podids"` + Privateinterface string `json:"privateinterface"` + Provider string `json:"provider"` + Publicinterface string `json:"publicinterface"` +} + +type ListSslCertsParams struct { + p map[string]interface{} +} + +func (p *ListSslCertsParams) toURLValues() url.Values { + u := url.Values{} + if p.p == nil { + return u + } + if v, found := p.p["accountid"]; found { + u.Set("accountid", v.(string)) + } + if v, found := p.p["certid"]; found { + u.Set("certid", v.(string)) + } + if v, found := p.p["lbruleid"]; found { + u.Set("lbruleid", v.(string)) + } + if v, found := p.p["projectid"]; found { + u.Set("projectid", v.(string)) + } + return u +} + +func (p *ListSslCertsParams) SetAccountid(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["accountid"] = v + return +} + +func (p *ListSslCertsParams) SetCertid(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["certid"] = v + return +} + +func (p *ListSslCertsParams) SetLbruleid(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["lbruleid"] = v + return +} + +func (p *ListSslCertsParams) SetProjectid(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["projectid"] = v + return +} + +// You should always use this function to get a new ListSslCertsParams instance, +// as then you are sure you have configured all required params +func (s *LoadBalancerService) NewListSslCertsParams() *ListSslCertsParams { + p := &ListSslCertsParams{} + p.p = make(map[string]interface{}) + return p +} + +// Lists SSL certificates +func (s *LoadBalancerService) ListSslCerts(p *ListSslCertsParams) (*ListSslCertsResponse, error) { + resp, err := s.cs.newRequest("listSslCerts", p.toURLValues()) + if err != nil { + return nil, err + } + + var r ListSslCertsResponse + if err := json.Unmarshal(resp, &r); err != nil { + return nil, err + } + + return &r, nil +} + +type ListSslCertsResponse struct { + Count int `json:"count"` + SslCerts []*SslCert `json:"sslcert"` +} + +type SslCert struct { + Account string `json:"account"` + Certchain string `json:"certchain"` + Certificate string `json:"certificate"` + Domain string `json:"domain"` + Domainid string `json:"domainid"` + Fingerprint string `json:"fingerprint"` + Id string `json:"id"` + Loadbalancerrulelist []string `json:"loadbalancerrulelist"` + Name string `json:"name"` + Project string `json:"project"` + Projectid string `json:"projectid"` +} + +type RemoveCertFromLoadBalancerParams struct { + p map[string]interface{} +} + +func (p *RemoveCertFromLoadBalancerParams) toURLValues() url.Values { + u := url.Values{} + if p.p == nil { + return u + } + if v, found := p.p["lbruleid"]; found { + u.Set("lbruleid", v.(string)) + } + return u +} + +func (p *RemoveCertFromLoadBalancerParams) SetLbruleid(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["lbruleid"] = v + return +} + +// You should always use this function to get a new RemoveCertFromLoadBalancerParams instance, +// as then you are sure you have configured all required params +func (s *LoadBalancerService) NewRemoveCertFromLoadBalancerParams(lbruleid string) *RemoveCertFromLoadBalancerParams { + p := &RemoveCertFromLoadBalancerParams{} + p.p = make(map[string]interface{}) + p.p["lbruleid"] = lbruleid + return p +} + +// Removes a certificate from a load balancer rule +func (s *LoadBalancerService) RemoveCertFromLoadBalancer(p *RemoveCertFromLoadBalancerParams) (*RemoveCertFromLoadBalancerResponse, error) { + resp, err := s.cs.newRequest("removeCertFromLoadBalancer", p.toURLValues()) + if err != nil { + return nil, err + } + + var r RemoveCertFromLoadBalancerResponse if err := json.Unmarshal(resp, &r); err != nil { return nil, err } @@ -4606,13 +3783,558 @@ func (s *LoadBalancerService) DeleteLoadBalancer(p *DeleteLoadBalancerParams) (* return nil, err } } + return &r, nil } -type DeleteLoadBalancerResponse struct { - JobID string `json:"jobid,omitempty"` - Displaytext string `json:"displaytext,omitempty"` - Success bool `json:"success,omitempty"` +type RemoveCertFromLoadBalancerResponse struct { + JobID string `json:"jobid"` + Displaytext string `json:"displaytext"` + Success bool `json:"success"` +} + +type RemoveFromGlobalLoadBalancerRuleParams struct { + p map[string]interface{} +} + +func (p *RemoveFromGlobalLoadBalancerRuleParams) toURLValues() url.Values { + u := url.Values{} + if p.p == nil { + return u + } + if v, found := p.p["id"]; found { + u.Set("id", v.(string)) + } + if v, found := p.p["loadbalancerrulelist"]; found { + vv := strings.Join(v.([]string), ",") + u.Set("loadbalancerrulelist", vv) + } + return u +} + +func (p *RemoveFromGlobalLoadBalancerRuleParams) SetId(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["id"] = v + return +} + +func (p *RemoveFromGlobalLoadBalancerRuleParams) SetLoadbalancerrulelist(v []string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["loadbalancerrulelist"] = v + return +} + +// You should always use this function to get a new RemoveFromGlobalLoadBalancerRuleParams instance, +// as then you are sure you have configured all required params +func (s *LoadBalancerService) NewRemoveFromGlobalLoadBalancerRuleParams(id string, loadbalancerrulelist []string) *RemoveFromGlobalLoadBalancerRuleParams { + p := &RemoveFromGlobalLoadBalancerRuleParams{} + p.p = make(map[string]interface{}) + p.p["id"] = id + p.p["loadbalancerrulelist"] = loadbalancerrulelist + return p +} + +// Removes a load balancer rule association with global load balancer rule +func (s *LoadBalancerService) RemoveFromGlobalLoadBalancerRule(p *RemoveFromGlobalLoadBalancerRuleParams) (*RemoveFromGlobalLoadBalancerRuleResponse, error) { + resp, err := s.cs.newRequest("removeFromGlobalLoadBalancerRule", p.toURLValues()) + if err != nil { + return nil, err + } + + var r RemoveFromGlobalLoadBalancerRuleResponse + if err := json.Unmarshal(resp, &r); err != nil { + return nil, err + } + + // If we have a async client, we need to wait for the async result + if s.cs.async { + b, err := s.cs.GetAsyncJobResult(r.JobID, s.cs.timeout) + if err != nil { + if err == AsyncTimeoutErr { + return &r, err + } + return nil, err + } + + if err := json.Unmarshal(b, &r); err != nil { + return nil, err + } + } + + return &r, nil +} + +type RemoveFromGlobalLoadBalancerRuleResponse struct { + JobID string `json:"jobid"` + Displaytext string `json:"displaytext"` + Success bool `json:"success"` +} + +type RemoveFromLoadBalancerRuleParams struct { + p map[string]interface{} +} + +func (p *RemoveFromLoadBalancerRuleParams) toURLValues() url.Values { + u := url.Values{} + if p.p == nil { + return u + } + if v, found := p.p["id"]; found { + u.Set("id", v.(string)) + } + if v, found := p.p["virtualmachineids"]; found { + vv := strings.Join(v.([]string), ",") + u.Set("virtualmachineids", vv) + } + if v, found := p.p["vmidipmap"]; found { + i := 0 + for k, vv := range v.(map[string]string) { + u.Set(fmt.Sprintf("vmidipmap[%d].key", i), k) + u.Set(fmt.Sprintf("vmidipmap[%d].value", i), vv) + i++ + } + } + return u +} + +func (p *RemoveFromLoadBalancerRuleParams) SetId(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["id"] = v + return +} + +func (p *RemoveFromLoadBalancerRuleParams) SetVirtualmachineids(v []string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["virtualmachineids"] = v + return +} + +func (p *RemoveFromLoadBalancerRuleParams) SetVmidipmap(v map[string]string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["vmidipmap"] = v + return +} + +// You should always use this function to get a new RemoveFromLoadBalancerRuleParams instance, +// as then you are sure you have configured all required params +func (s *LoadBalancerService) NewRemoveFromLoadBalancerRuleParams(id string) *RemoveFromLoadBalancerRuleParams { + p := &RemoveFromLoadBalancerRuleParams{} + p.p = make(map[string]interface{}) + p.p["id"] = id + return p +} + +// Removes a virtual machine or a list of virtual machines from a load balancer rule. +func (s *LoadBalancerService) RemoveFromLoadBalancerRule(p *RemoveFromLoadBalancerRuleParams) (*RemoveFromLoadBalancerRuleResponse, error) { + resp, err := s.cs.newRequest("removeFromLoadBalancerRule", p.toURLValues()) + if err != nil { + return nil, err + } + + var r RemoveFromLoadBalancerRuleResponse + if err := json.Unmarshal(resp, &r); err != nil { + return nil, err + } + + // If we have a async client, we need to wait for the async result + if s.cs.async { + b, err := s.cs.GetAsyncJobResult(r.JobID, s.cs.timeout) + if err != nil { + if err == AsyncTimeoutErr { + return &r, err + } + return nil, err + } + + if err := json.Unmarshal(b, &r); err != nil { + return nil, err + } + } + + return &r, nil +} + +type RemoveFromLoadBalancerRuleResponse struct { + JobID string `json:"jobid"` + Displaytext string `json:"displaytext"` + Success bool `json:"success"` +} + +type UpdateGlobalLoadBalancerRuleParams struct { + p map[string]interface{} +} + +func (p *UpdateGlobalLoadBalancerRuleParams) toURLValues() url.Values { + u := url.Values{} + if p.p == nil { + return u + } + if v, found := p.p["description"]; found { + u.Set("description", v.(string)) + } + if v, found := p.p["gslblbmethod"]; found { + u.Set("gslblbmethod", v.(string)) + } + if v, found := p.p["gslbstickysessionmethodname"]; found { + u.Set("gslbstickysessionmethodname", v.(string)) + } + if v, found := p.p["id"]; found { + u.Set("id", v.(string)) + } + return u +} + +func (p *UpdateGlobalLoadBalancerRuleParams) SetDescription(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["description"] = v + return +} + +func (p *UpdateGlobalLoadBalancerRuleParams) SetGslblbmethod(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["gslblbmethod"] = v + return +} + +func (p *UpdateGlobalLoadBalancerRuleParams) SetGslbstickysessionmethodname(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["gslbstickysessionmethodname"] = v + return +} + +func (p *UpdateGlobalLoadBalancerRuleParams) SetId(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["id"] = v + return +} + +// You should always use this function to get a new UpdateGlobalLoadBalancerRuleParams instance, +// as then you are sure you have configured all required params +func (s *LoadBalancerService) NewUpdateGlobalLoadBalancerRuleParams(id string) *UpdateGlobalLoadBalancerRuleParams { + p := &UpdateGlobalLoadBalancerRuleParams{} + p.p = make(map[string]interface{}) + p.p["id"] = id + return p +} + +// update global load balancer rules. +func (s *LoadBalancerService) UpdateGlobalLoadBalancerRule(p *UpdateGlobalLoadBalancerRuleParams) (*UpdateGlobalLoadBalancerRuleResponse, error) { + resp, err := s.cs.newRequest("updateGlobalLoadBalancerRule", p.toURLValues()) + if err != nil { + return nil, err + } + + var r UpdateGlobalLoadBalancerRuleResponse + if err := json.Unmarshal(resp, &r); err != nil { + return nil, err + } + + // If we have a async client, we need to wait for the async result + if s.cs.async { + b, err := s.cs.GetAsyncJobResult(r.JobID, s.cs.timeout) + if err != nil { + if err == AsyncTimeoutErr { + return &r, err + } + return nil, err + } + + b, err = getRawValue(b) + if err != nil { + return nil, err + } + + if err := json.Unmarshal(b, &r); err != nil { + return nil, err + } + } + + return &r, nil +} + +type UpdateGlobalLoadBalancerRuleResponse struct { + JobID string `json:"jobid"` + Account string `json:"account"` + Description string `json:"description"` + Domain string `json:"domain"` + Domainid string `json:"domainid"` + Gslbdomainname string `json:"gslbdomainname"` + Gslblbmethod string `json:"gslblbmethod"` + Gslbservicetype string `json:"gslbservicetype"` + Gslbstickysessionmethodname string `json:"gslbstickysessionmethodname"` + Id string `json:"id"` + Loadbalancerrule []UpdateGlobalLoadBalancerRuleResponseLoadbalancerrule `json:"loadbalancerrule"` + Name string `json:"name"` + Project string `json:"project"` + Projectid string `json:"projectid"` + Regionid int `json:"regionid"` +} + +type UpdateGlobalLoadBalancerRuleResponseLoadbalancerrule struct { + Account string `json:"account"` + Algorithm string `json:"algorithm"` + Cidrlist string `json:"cidrlist"` + Description string `json:"description"` + Domain string `json:"domain"` + Domainid string `json:"domainid"` + Fordisplay bool `json:"fordisplay"` + Id string `json:"id"` + Name string `json:"name"` + Networkid string `json:"networkid"` + Privateport string `json:"privateport"` + Project string `json:"project"` + Projectid string `json:"projectid"` + Protocol string `json:"protocol"` + Publicip string `json:"publicip"` + Publicipid string `json:"publicipid"` + Publicport string `json:"publicport"` + State string `json:"state"` + Tags []Tags `json:"tags"` + Zoneid string `json:"zoneid"` + Zonename string `json:"zonename"` +} + +type UpdateLBHealthCheckPolicyParams struct { + p map[string]interface{} +} + +func (p *UpdateLBHealthCheckPolicyParams) toURLValues() url.Values { + u := url.Values{} + if p.p == nil { + return u + } + if v, found := p.p["customid"]; found { + u.Set("customid", v.(string)) + } + if v, found := p.p["fordisplay"]; found { + vv := strconv.FormatBool(v.(bool)) + u.Set("fordisplay", vv) + } + if v, found := p.p["id"]; found { + u.Set("id", v.(string)) + } + return u +} + +func (p *UpdateLBHealthCheckPolicyParams) SetCustomid(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["customid"] = v + return +} + +func (p *UpdateLBHealthCheckPolicyParams) SetFordisplay(v bool) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["fordisplay"] = v + return +} + +func (p *UpdateLBHealthCheckPolicyParams) SetId(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["id"] = v + return +} + +// You should always use this function to get a new UpdateLBHealthCheckPolicyParams instance, +// as then you are sure you have configured all required params +func (s *LoadBalancerService) NewUpdateLBHealthCheckPolicyParams(id string) *UpdateLBHealthCheckPolicyParams { + p := &UpdateLBHealthCheckPolicyParams{} + p.p = make(map[string]interface{}) + p.p["id"] = id + return p +} + +// Updates load balancer health check policy +func (s *LoadBalancerService) UpdateLBHealthCheckPolicy(p *UpdateLBHealthCheckPolicyParams) (*UpdateLBHealthCheckPolicyResponse, error) { + resp, err := s.cs.newRequest("updateLBHealthCheckPolicy", p.toURLValues()) + if err != nil { + return nil, err + } + + var r UpdateLBHealthCheckPolicyResponse + if err := json.Unmarshal(resp, &r); err != nil { + return nil, err + } + + // If we have a async client, we need to wait for the async result + if s.cs.async { + b, err := s.cs.GetAsyncJobResult(r.JobID, s.cs.timeout) + if err != nil { + if err == AsyncTimeoutErr { + return &r, err + } + return nil, err + } + + b, err = getRawValue(b) + if err != nil { + return nil, err + } + + if err := json.Unmarshal(b, &r); err != nil { + return nil, err + } + } + + return &r, nil +} + +type UpdateLBHealthCheckPolicyResponse struct { + JobID string `json:"jobid"` + Account string `json:"account"` + Domain string `json:"domain"` + Domainid string `json:"domainid"` + Healthcheckpolicy []UpdateLBHealthCheckPolicyResponseHealthcheckpolicy `json:"healthcheckpolicy"` + Lbruleid string `json:"lbruleid"` + Zoneid string `json:"zoneid"` +} + +type UpdateLBHealthCheckPolicyResponseHealthcheckpolicy struct { + Description string `json:"description"` + Fordisplay bool `json:"fordisplay"` + Healthcheckinterval int `json:"healthcheckinterval"` + Healthcheckthresshold int `json:"healthcheckthresshold"` + Id string `json:"id"` + Pingpath string `json:"pingpath"` + Responsetime int `json:"responsetime"` + State string `json:"state"` + Unhealthcheckthresshold int `json:"unhealthcheckthresshold"` +} + +type UpdateLBStickinessPolicyParams struct { + p map[string]interface{} +} + +func (p *UpdateLBStickinessPolicyParams) toURLValues() url.Values { + u := url.Values{} + if p.p == nil { + return u + } + if v, found := p.p["customid"]; found { + u.Set("customid", v.(string)) + } + if v, found := p.p["fordisplay"]; found { + vv := strconv.FormatBool(v.(bool)) + u.Set("fordisplay", vv) + } + if v, found := p.p["id"]; found { + u.Set("id", v.(string)) + } + return u +} + +func (p *UpdateLBStickinessPolicyParams) SetCustomid(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["customid"] = v + return +} + +func (p *UpdateLBStickinessPolicyParams) SetFordisplay(v bool) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["fordisplay"] = v + return +} + +func (p *UpdateLBStickinessPolicyParams) SetId(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["id"] = v + return +} + +// You should always use this function to get a new UpdateLBStickinessPolicyParams instance, +// as then you are sure you have configured all required params +func (s *LoadBalancerService) NewUpdateLBStickinessPolicyParams(id string) *UpdateLBStickinessPolicyParams { + p := &UpdateLBStickinessPolicyParams{} + p.p = make(map[string]interface{}) + p.p["id"] = id + return p +} + +// Updates load balancer stickiness policy +func (s *LoadBalancerService) UpdateLBStickinessPolicy(p *UpdateLBStickinessPolicyParams) (*UpdateLBStickinessPolicyResponse, error) { + resp, err := s.cs.newRequest("updateLBStickinessPolicy", p.toURLValues()) + if err != nil { + return nil, err + } + + var r UpdateLBStickinessPolicyResponse + if err := json.Unmarshal(resp, &r); err != nil { + return nil, err + } + + // If we have a async client, we need to wait for the async result + if s.cs.async { + b, err := s.cs.GetAsyncJobResult(r.JobID, s.cs.timeout) + if err != nil { + if err == AsyncTimeoutErr { + return &r, err + } + return nil, err + } + + b, err = getRawValue(b) + if err != nil { + return nil, err + } + + if err := json.Unmarshal(b, &r); err != nil { + return nil, err + } + } + + return &r, nil +} + +type UpdateLBStickinessPolicyResponse struct { + JobID string `json:"jobid"` + Account string `json:"account"` + Description string `json:"description"` + Domain string `json:"domain"` + Domainid string `json:"domainid"` + Lbruleid string `json:"lbruleid"` + Name string `json:"name"` + State string `json:"state"` + Stickinesspolicy []UpdateLBStickinessPolicyResponseStickinesspolicy `json:"stickinesspolicy"` + Zoneid string `json:"zoneid"` +} + +type UpdateLBStickinessPolicyResponseStickinesspolicy struct { + Description string `json:"description"` + Fordisplay bool `json:"fordisplay"` + Id string `json:"id"` + Methodname string `json:"methodname"` + Name string `json:"name"` + Params map[string]string `json:"params"` + State string `json:"state"` } type UpdateLoadBalancerParams struct { @@ -4701,45 +4423,338 @@ func (s *LoadBalancerService) UpdateLoadBalancer(p *UpdateLoadBalancerParams) (* return nil, err } } + return &r, nil } type UpdateLoadBalancerResponse struct { - JobID string `json:"jobid,omitempty"` - Account string `json:"account,omitempty"` - Algorithm string `json:"algorithm,omitempty"` - Description string `json:"description,omitempty"` - Domain string `json:"domain,omitempty"` - Domainid string `json:"domainid,omitempty"` - Fordisplay bool `json:"fordisplay,omitempty"` - Id string `json:"id,omitempty"` - Loadbalancerinstance []struct { - Id string `json:"id,omitempty"` - Ipaddress string `json:"ipaddress,omitempty"` - Name string `json:"name,omitempty"` - State string `json:"state,omitempty"` - } `json:"loadbalancerinstance,omitempty"` - Loadbalancerrule []struct { - Instanceport int `json:"instanceport,omitempty"` - Sourceport int `json:"sourceport,omitempty"` - State string `json:"state,omitempty"` - } `json:"loadbalancerrule,omitempty"` - Name string `json:"name,omitempty"` - Networkid string `json:"networkid,omitempty"` - Project string `json:"project,omitempty"` - Projectid string `json:"projectid,omitempty"` - Sourceipaddress string `json:"sourceipaddress,omitempty"` - Sourceipaddressnetworkid string `json:"sourceipaddressnetworkid,omitempty"` - Tags []struct { - Account string `json:"account,omitempty"` - Customer string `json:"customer,omitempty"` - Domain string `json:"domain,omitempty"` - Domainid string `json:"domainid,omitempty"` - Key string `json:"key,omitempty"` - Project string `json:"project,omitempty"` - Projectid string `json:"projectid,omitempty"` - Resourceid string `json:"resourceid,omitempty"` - Resourcetype string `json:"resourcetype,omitempty"` - Value string `json:"value,omitempty"` - } `json:"tags,omitempty"` + JobID string `json:"jobid"` + Account string `json:"account"` + Algorithm string `json:"algorithm"` + Description string `json:"description"` + Domain string `json:"domain"` + Domainid string `json:"domainid"` + Fordisplay bool `json:"fordisplay"` + Id string `json:"id"` + Loadbalancerinstance []UpdateLoadBalancerResponseLoadbalancerinstance `json:"loadbalancerinstance"` + Loadbalancerrule []UpdateLoadBalancerResponseLoadbalancerrule `json:"loadbalancerrule"` + Name string `json:"name"` + Networkid string `json:"networkid"` + Project string `json:"project"` + Projectid string `json:"projectid"` + Sourceipaddress string `json:"sourceipaddress"` + Sourceipaddressnetworkid string `json:"sourceipaddressnetworkid"` + Tags []Tags `json:"tags"` +} + +type UpdateLoadBalancerResponseLoadbalancerrule struct { + Instanceport int `json:"instanceport"` + Sourceport int `json:"sourceport"` + State string `json:"state"` +} + +type UpdateLoadBalancerResponseLoadbalancerinstance struct { + Id string `json:"id"` + Ipaddress string `json:"ipaddress"` + Name string `json:"name"` + State string `json:"state"` +} + +type UpdateLoadBalancerRuleParams struct { + p map[string]interface{} +} + +func (p *UpdateLoadBalancerRuleParams) toURLValues() url.Values { + u := url.Values{} + if p.p == nil { + return u + } + if v, found := p.p["algorithm"]; found { + u.Set("algorithm", v.(string)) + } + if v, found := p.p["customid"]; found { + u.Set("customid", v.(string)) + } + if v, found := p.p["description"]; found { + u.Set("description", v.(string)) + } + if v, found := p.p["fordisplay"]; found { + vv := strconv.FormatBool(v.(bool)) + u.Set("fordisplay", vv) + } + if v, found := p.p["id"]; found { + u.Set("id", v.(string)) + } + if v, found := p.p["name"]; found { + u.Set("name", v.(string)) + } + if v, found := p.p["protocol"]; found { + u.Set("protocol", v.(string)) + } + return u +} + +func (p *UpdateLoadBalancerRuleParams) SetAlgorithm(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["algorithm"] = v + return +} + +func (p *UpdateLoadBalancerRuleParams) SetCustomid(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["customid"] = v + return +} + +func (p *UpdateLoadBalancerRuleParams) SetDescription(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["description"] = v + return +} + +func (p *UpdateLoadBalancerRuleParams) SetFordisplay(v bool) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["fordisplay"] = v + return +} + +func (p *UpdateLoadBalancerRuleParams) SetId(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["id"] = v + return +} + +func (p *UpdateLoadBalancerRuleParams) SetName(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["name"] = v + return +} + +func (p *UpdateLoadBalancerRuleParams) SetProtocol(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["protocol"] = v + return +} + +// You should always use this function to get a new UpdateLoadBalancerRuleParams instance, +// as then you are sure you have configured all required params +func (s *LoadBalancerService) NewUpdateLoadBalancerRuleParams(id string) *UpdateLoadBalancerRuleParams { + p := &UpdateLoadBalancerRuleParams{} + p.p = make(map[string]interface{}) + p.p["id"] = id + return p +} + +// Updates load balancer +func (s *LoadBalancerService) UpdateLoadBalancerRule(p *UpdateLoadBalancerRuleParams) (*UpdateLoadBalancerRuleResponse, error) { + resp, err := s.cs.newRequest("updateLoadBalancerRule", p.toURLValues()) + if err != nil { + return nil, err + } + + var r UpdateLoadBalancerRuleResponse + if err := json.Unmarshal(resp, &r); err != nil { + return nil, err + } + + // If we have a async client, we need to wait for the async result + if s.cs.async { + b, err := s.cs.GetAsyncJobResult(r.JobID, s.cs.timeout) + if err != nil { + if err == AsyncTimeoutErr { + return &r, err + } + return nil, err + } + + b, err = getRawValue(b) + if err != nil { + return nil, err + } + + if err := json.Unmarshal(b, &r); err != nil { + return nil, err + } + } + + return &r, nil +} + +type UpdateLoadBalancerRuleResponse struct { + JobID string `json:"jobid"` + Account string `json:"account"` + Algorithm string `json:"algorithm"` + Cidrlist string `json:"cidrlist"` + Description string `json:"description"` + Domain string `json:"domain"` + Domainid string `json:"domainid"` + Fordisplay bool `json:"fordisplay"` + Id string `json:"id"` + Name string `json:"name"` + Networkid string `json:"networkid"` + Privateport string `json:"privateport"` + Project string `json:"project"` + Projectid string `json:"projectid"` + Protocol string `json:"protocol"` + Publicip string `json:"publicip"` + Publicipid string `json:"publicipid"` + Publicport string `json:"publicport"` + State string `json:"state"` + Tags []Tags `json:"tags"` + Zoneid string `json:"zoneid"` + Zonename string `json:"zonename"` +} + +type UploadSslCertParams struct { + p map[string]interface{} +} + +func (p *UploadSslCertParams) toURLValues() url.Values { + u := url.Values{} + if p.p == nil { + return u + } + if v, found := p.p["account"]; found { + u.Set("account", v.(string)) + } + if v, found := p.p["certchain"]; found { + u.Set("certchain", v.(string)) + } + if v, found := p.p["certificate"]; found { + u.Set("certificate", v.(string)) + } + if v, found := p.p["domainid"]; found { + u.Set("domainid", v.(string)) + } + if v, found := p.p["name"]; found { + u.Set("name", v.(string)) + } + if v, found := p.p["password"]; found { + u.Set("password", v.(string)) + } + if v, found := p.p["privatekey"]; found { + u.Set("privatekey", v.(string)) + } + if v, found := p.p["projectid"]; found { + u.Set("projectid", v.(string)) + } + return u +} + +func (p *UploadSslCertParams) SetAccount(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["account"] = v + return +} + +func (p *UploadSslCertParams) SetCertchain(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["certchain"] = v + return +} + +func (p *UploadSslCertParams) SetCertificate(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["certificate"] = v + return +} + +func (p *UploadSslCertParams) SetDomainid(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["domainid"] = v + return +} + +func (p *UploadSslCertParams) SetName(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["name"] = v + return +} + +func (p *UploadSslCertParams) SetPassword(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["password"] = v + return +} + +func (p *UploadSslCertParams) SetPrivatekey(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["privatekey"] = v + return +} + +func (p *UploadSslCertParams) SetProjectid(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["projectid"] = v + return +} + +// You should always use this function to get a new UploadSslCertParams instance, +// as then you are sure you have configured all required params +func (s *LoadBalancerService) NewUploadSslCertParams(certificate string, name string, privatekey string) *UploadSslCertParams { + p := &UploadSslCertParams{} + p.p = make(map[string]interface{}) + p.p["certificate"] = certificate + p.p["name"] = name + p.p["privatekey"] = privatekey + return p +} + +// Upload a certificate to CloudStack +func (s *LoadBalancerService) UploadSslCert(p *UploadSslCertParams) (*UploadSslCertResponse, error) { + resp, err := s.cs.newRequest("uploadSslCert", p.toURLValues()) + if err != nil { + return nil, err + } + + var r UploadSslCertResponse + if err := json.Unmarshal(resp, &r); err != nil { + return nil, err + } + + return &r, nil +} + +type UploadSslCertResponse struct { + Account string `json:"account"` + Certchain string `json:"certchain"` + Certificate string `json:"certificate"` + Domain string `json:"domain"` + Domainid string `json:"domainid"` + Fingerprint string `json:"fingerprint"` + Id string `json:"id"` + Loadbalancerrulelist []string `json:"loadbalancerrulelist"` + Name string `json:"name"` + Project string `json:"project"` + Projectid string `json:"projectid"` } diff --git a/vendor/github.com/xanzy/go-cloudstack/cloudstack/NATService.go b/vendor/github.com/xanzy/go-cloudstack/cloudstack/NATService.go index daaf10ede..714dfa590 100644 --- a/vendor/github.com/xanzy/go-cloudstack/cloudstack/NATService.go +++ b/vendor/github.com/xanzy/go-cloudstack/cloudstack/NATService.go @@ -1,5 +1,5 @@ // -// Copyright 2016, Sander van Harmelen +// Copyright 2018, Sander van Harmelen // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -24,91 +24,6 @@ import ( "strings" ) -type EnableStaticNatParams struct { - p map[string]interface{} -} - -func (p *EnableStaticNatParams) toURLValues() url.Values { - u := url.Values{} - if p.p == nil { - return u - } - if v, found := p.p["ipaddressid"]; found { - u.Set("ipaddressid", v.(string)) - } - if v, found := p.p["networkid"]; found { - u.Set("networkid", v.(string)) - } - if v, found := p.p["virtualmachineid"]; found { - u.Set("virtualmachineid", v.(string)) - } - if v, found := p.p["vmguestip"]; found { - u.Set("vmguestip", v.(string)) - } - return u -} - -func (p *EnableStaticNatParams) SetIpaddressid(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["ipaddressid"] = v - return -} - -func (p *EnableStaticNatParams) SetNetworkid(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["networkid"] = v - return -} - -func (p *EnableStaticNatParams) SetVirtualmachineid(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["virtualmachineid"] = v - return -} - -func (p *EnableStaticNatParams) SetVmguestip(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["vmguestip"] = v - return -} - -// You should always use this function to get a new EnableStaticNatParams instance, -// as then you are sure you have configured all required params -func (s *NATService) NewEnableStaticNatParams(ipaddressid string, virtualmachineid string) *EnableStaticNatParams { - p := &EnableStaticNatParams{} - p.p = make(map[string]interface{}) - p.p["ipaddressid"] = ipaddressid - p.p["virtualmachineid"] = virtualmachineid - return p -} - -// Enables static NAT for given IP address -func (s *NATService) EnableStaticNat(p *EnableStaticNatParams) (*EnableStaticNatResponse, error) { - resp, err := s.cs.newRequest("enableStaticNat", p.toURLValues()) - if err != nil { - return nil, err - } - - var r EnableStaticNatResponse - if err := json.Unmarshal(resp, &r); err != nil { - return nil, err - } - return &r, nil -} - -type EnableStaticNatResponse struct { - Displaytext string `json:"displaytext,omitempty"` - Success string `json:"success,omitempty"` -} - type CreateIpForwardingRuleParams struct { p map[string]interface{} } @@ -233,39 +148,29 @@ func (s *NATService) CreateIpForwardingRule(p *CreateIpForwardingRuleParams) (*C return nil, err } } + return &r, nil } type CreateIpForwardingRuleResponse struct { - JobID string `json:"jobid,omitempty"` - Cidrlist string `json:"cidrlist,omitempty"` - Fordisplay bool `json:"fordisplay,omitempty"` - Id string `json:"id,omitempty"` - Ipaddress string `json:"ipaddress,omitempty"` - Ipaddressid string `json:"ipaddressid,omitempty"` - Networkid string `json:"networkid,omitempty"` - Privateendport string `json:"privateendport,omitempty"` - Privateport string `json:"privateport,omitempty"` - Protocol string `json:"protocol,omitempty"` - Publicendport string `json:"publicendport,omitempty"` - Publicport string `json:"publicport,omitempty"` - State string `json:"state,omitempty"` - Tags []struct { - Account string `json:"account,omitempty"` - Customer string `json:"customer,omitempty"` - Domain string `json:"domain,omitempty"` - Domainid string `json:"domainid,omitempty"` - Key string `json:"key,omitempty"` - Project string `json:"project,omitempty"` - Projectid string `json:"projectid,omitempty"` - Resourceid string `json:"resourceid,omitempty"` - Resourcetype string `json:"resourcetype,omitempty"` - Value string `json:"value,omitempty"` - } `json:"tags,omitempty"` - Virtualmachinedisplayname string `json:"virtualmachinedisplayname,omitempty"` - Virtualmachineid string `json:"virtualmachineid,omitempty"` - Virtualmachinename string `json:"virtualmachinename,omitempty"` - Vmguestip string `json:"vmguestip,omitempty"` + JobID string `json:"jobid"` + Cidrlist string `json:"cidrlist"` + Fordisplay bool `json:"fordisplay"` + Id string `json:"id"` + Ipaddress string `json:"ipaddress"` + Ipaddressid string `json:"ipaddressid"` + Networkid string `json:"networkid"` + Privateendport string `json:"privateendport"` + Privateport string `json:"privateport"` + Protocol string `json:"protocol"` + Publicendport string `json:"publicendport"` + Publicport string `json:"publicport"` + State string `json:"state"` + Tags []Tags `json:"tags"` + Virtualmachinedisplayname string `json:"virtualmachinedisplayname"` + Virtualmachineid string `json:"virtualmachineid"` + Virtualmachinename string `json:"virtualmachinename"` + Vmguestip string `json:"vmguestip"` } type DeleteIpForwardingRuleParams struct { @@ -326,13 +231,187 @@ func (s *NATService) DeleteIpForwardingRule(p *DeleteIpForwardingRuleParams) (*D return nil, err } } + return &r, nil } type DeleteIpForwardingRuleResponse struct { - JobID string `json:"jobid,omitempty"` - Displaytext string `json:"displaytext,omitempty"` - Success bool `json:"success,omitempty"` + JobID string `json:"jobid"` + Displaytext string `json:"displaytext"` + Success bool `json:"success"` +} + +type DisableStaticNatParams struct { + p map[string]interface{} +} + +func (p *DisableStaticNatParams) toURLValues() url.Values { + u := url.Values{} + if p.p == nil { + return u + } + if v, found := p.p["ipaddressid"]; found { + u.Set("ipaddressid", v.(string)) + } + return u +} + +func (p *DisableStaticNatParams) SetIpaddressid(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["ipaddressid"] = v + return +} + +// You should always use this function to get a new DisableStaticNatParams instance, +// as then you are sure you have configured all required params +func (s *NATService) NewDisableStaticNatParams(ipaddressid string) *DisableStaticNatParams { + p := &DisableStaticNatParams{} + p.p = make(map[string]interface{}) + p.p["ipaddressid"] = ipaddressid + return p +} + +// Disables static rule for given IP address +func (s *NATService) DisableStaticNat(p *DisableStaticNatParams) (*DisableStaticNatResponse, error) { + resp, err := s.cs.newRequest("disableStaticNat", p.toURLValues()) + if err != nil { + return nil, err + } + + var r DisableStaticNatResponse + if err := json.Unmarshal(resp, &r); err != nil { + return nil, err + } + + // If we have a async client, we need to wait for the async result + if s.cs.async { + b, err := s.cs.GetAsyncJobResult(r.JobID, s.cs.timeout) + if err != nil { + if err == AsyncTimeoutErr { + return &r, err + } + return nil, err + } + + if err := json.Unmarshal(b, &r); err != nil { + return nil, err + } + } + + return &r, nil +} + +type DisableStaticNatResponse struct { + JobID string `json:"jobid"` + Displaytext string `json:"displaytext"` + Success bool `json:"success"` +} + +type EnableStaticNatParams struct { + p map[string]interface{} +} + +func (p *EnableStaticNatParams) toURLValues() url.Values { + u := url.Values{} + if p.p == nil { + return u + } + if v, found := p.p["ipaddressid"]; found { + u.Set("ipaddressid", v.(string)) + } + if v, found := p.p["networkid"]; found { + u.Set("networkid", v.(string)) + } + if v, found := p.p["virtualmachineid"]; found { + u.Set("virtualmachineid", v.(string)) + } + if v, found := p.p["vmguestip"]; found { + u.Set("vmguestip", v.(string)) + } + return u +} + +func (p *EnableStaticNatParams) SetIpaddressid(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["ipaddressid"] = v + return +} + +func (p *EnableStaticNatParams) SetNetworkid(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["networkid"] = v + return +} + +func (p *EnableStaticNatParams) SetVirtualmachineid(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["virtualmachineid"] = v + return +} + +func (p *EnableStaticNatParams) SetVmguestip(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["vmguestip"] = v + return +} + +// You should always use this function to get a new EnableStaticNatParams instance, +// as then you are sure you have configured all required params +func (s *NATService) NewEnableStaticNatParams(ipaddressid string, virtualmachineid string) *EnableStaticNatParams { + p := &EnableStaticNatParams{} + p.p = make(map[string]interface{}) + p.p["ipaddressid"] = ipaddressid + p.p["virtualmachineid"] = virtualmachineid + return p +} + +// Enables static NAT for given IP address +func (s *NATService) EnableStaticNat(p *EnableStaticNatParams) (*EnableStaticNatResponse, error) { + resp, err := s.cs.newRequest("enableStaticNat", p.toURLValues()) + if err != nil { + return nil, err + } + + var r EnableStaticNatResponse + if err := json.Unmarshal(resp, &r); err != nil { + return nil, err + } + + return &r, nil +} + +type EnableStaticNatResponse struct { + Displaytext string `json:"displaytext"` + Success bool `json:"success"` +} + +func (r *EnableStaticNatResponse) UnmarshalJSON(b []byte) error { + var m map[string]interface{} + err := json.Unmarshal(b, &m) + if err != nil { + return err + } + + if success, ok := m["success"].(string); ok { + m["success"] = success == "true" + b, err = json.Marshal(m) + if err != nil { + return err + } + } + + type alias EnableStaticNatResponse + return json.Unmarshal(b, (*alias)(r)) } type ListIpForwardingRulesParams struct { @@ -487,7 +566,7 @@ func (s *NATService) GetIpForwardingRuleByID(id string, opts ...OptionFunc) (*Ip p.p["id"] = id - for _, fn := range opts { + for _, fn := range append(s.cs.options, opts...) { if err := fn(s.cs, p); err != nil { return nil, -1, err } @@ -524,6 +603,7 @@ func (s *NATService) ListIpForwardingRules(p *ListIpForwardingRulesParams) (*Lis if err := json.Unmarshal(resp, &r); err != nil { return nil, err } + return &r, nil } @@ -533,99 +613,21 @@ type ListIpForwardingRulesResponse struct { } type IpForwardingRule struct { - Cidrlist string `json:"cidrlist,omitempty"` - Fordisplay bool `json:"fordisplay,omitempty"` - Id string `json:"id,omitempty"` - Ipaddress string `json:"ipaddress,omitempty"` - Ipaddressid string `json:"ipaddressid,omitempty"` - Networkid string `json:"networkid,omitempty"` - Privateendport string `json:"privateendport,omitempty"` - Privateport string `json:"privateport,omitempty"` - Protocol string `json:"protocol,omitempty"` - Publicendport string `json:"publicendport,omitempty"` - Publicport string `json:"publicport,omitempty"` - State string `json:"state,omitempty"` - Tags []struct { - Account string `json:"account,omitempty"` - Customer string `json:"customer,omitempty"` - Domain string `json:"domain,omitempty"` - Domainid string `json:"domainid,omitempty"` - Key string `json:"key,omitempty"` - Project string `json:"project,omitempty"` - Projectid string `json:"projectid,omitempty"` - Resourceid string `json:"resourceid,omitempty"` - Resourcetype string `json:"resourcetype,omitempty"` - Value string `json:"value,omitempty"` - } `json:"tags,omitempty"` - Virtualmachinedisplayname string `json:"virtualmachinedisplayname,omitempty"` - Virtualmachineid string `json:"virtualmachineid,omitempty"` - Virtualmachinename string `json:"virtualmachinename,omitempty"` - Vmguestip string `json:"vmguestip,omitempty"` -} - -type DisableStaticNatParams struct { - p map[string]interface{} -} - -func (p *DisableStaticNatParams) toURLValues() url.Values { - u := url.Values{} - if p.p == nil { - return u - } - if v, found := p.p["ipaddressid"]; found { - u.Set("ipaddressid", v.(string)) - } - return u -} - -func (p *DisableStaticNatParams) SetIpaddressid(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["ipaddressid"] = v - return -} - -// You should always use this function to get a new DisableStaticNatParams instance, -// as then you are sure you have configured all required params -func (s *NATService) NewDisableStaticNatParams(ipaddressid string) *DisableStaticNatParams { - p := &DisableStaticNatParams{} - p.p = make(map[string]interface{}) - p.p["ipaddressid"] = ipaddressid - return p -} - -// Disables static rule for given IP address -func (s *NATService) DisableStaticNat(p *DisableStaticNatParams) (*DisableStaticNatResponse, error) { - resp, err := s.cs.newRequest("disableStaticNat", p.toURLValues()) - if err != nil { - return nil, err - } - - var r DisableStaticNatResponse - if err := json.Unmarshal(resp, &r); err != nil { - return nil, err - } - - // If we have a async client, we need to wait for the async result - if s.cs.async { - b, err := s.cs.GetAsyncJobResult(r.JobID, s.cs.timeout) - if err != nil { - if err == AsyncTimeoutErr { - return &r, err - } - return nil, err - } - - if err := json.Unmarshal(b, &r); err != nil { - return nil, err - } - } - return &r, nil -} - -type DisableStaticNatResponse struct { - JobID string `json:"jobid,omitempty"` - Displaytext string `json:"displaytext,omitempty"` - Success bool `json:"success,omitempty"` + Cidrlist string `json:"cidrlist"` + Fordisplay bool `json:"fordisplay"` + Id string `json:"id"` + Ipaddress string `json:"ipaddress"` + Ipaddressid string `json:"ipaddressid"` + Networkid string `json:"networkid"` + Privateendport string `json:"privateendport"` + Privateport string `json:"privateport"` + Protocol string `json:"protocol"` + Publicendport string `json:"publicendport"` + Publicport string `json:"publicport"` + State string `json:"state"` + Tags []Tags `json:"tags"` + Virtualmachinedisplayname string `json:"virtualmachinedisplayname"` + Virtualmachineid string `json:"virtualmachineid"` + Virtualmachinename string `json:"virtualmachinename"` + Vmguestip string `json:"vmguestip"` } diff --git a/vendor/github.com/xanzy/go-cloudstack/cloudstack/NetworkACLService.go b/vendor/github.com/xanzy/go-cloudstack/cloudstack/NetworkACLService.go index 8a53ddf6e..6d0e1547b 100644 --- a/vendor/github.com/xanzy/go-cloudstack/cloudstack/NetworkACLService.go +++ b/vendor/github.com/xanzy/go-cloudstack/cloudstack/NetworkACLService.go @@ -1,5 +1,5 @@ // -// Copyright 2016, Sander van Harmelen +// Copyright 2018, Sander van Harmelen // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -215,126 +215,62 @@ func (s *NetworkACLService) CreateNetworkACL(p *CreateNetworkACLParams) (*Create return nil, err } } + return &r, nil } type CreateNetworkACLResponse struct { - JobID string `json:"jobid,omitempty"` - Aclid string `json:"aclid,omitempty"` - Action string `json:"action,omitempty"` - Cidrlist string `json:"cidrlist,omitempty"` - Endport string `json:"endport,omitempty"` - Fordisplay bool `json:"fordisplay,omitempty"` - Icmpcode int `json:"icmpcode,omitempty"` - Icmptype int `json:"icmptype,omitempty"` - Id string `json:"id,omitempty"` - Number int `json:"number,omitempty"` - Protocol string `json:"protocol,omitempty"` - Startport string `json:"startport,omitempty"` - State string `json:"state,omitempty"` - Tags []struct { - Account string `json:"account,omitempty"` - Customer string `json:"customer,omitempty"` - Domain string `json:"domain,omitempty"` - Domainid string `json:"domainid,omitempty"` - Key string `json:"key,omitempty"` - Project string `json:"project,omitempty"` - Projectid string `json:"projectid,omitempty"` - Resourceid string `json:"resourceid,omitempty"` - Resourcetype string `json:"resourcetype,omitempty"` - Value string `json:"value,omitempty"` - } `json:"tags,omitempty"` - Traffictype string `json:"traffictype,omitempty"` + JobID string `json:"jobid"` + Aclid string `json:"aclid"` + Action string `json:"action"` + Cidrlist string `json:"cidrlist"` + Endport string `json:"endport"` + Fordisplay bool `json:"fordisplay"` + Icmpcode int `json:"icmpcode"` + Icmptype int `json:"icmptype"` + Id string `json:"id"` + Number int `json:"number"` + Protocol string `json:"protocol"` + Startport string `json:"startport"` + State string `json:"state"` + Tags []Tags `json:"tags"` + Traffictype string `json:"traffictype"` } -type UpdateNetworkACLItemParams struct { +type CreateNetworkACLListParams struct { p map[string]interface{} } -func (p *UpdateNetworkACLItemParams) toURLValues() url.Values { +func (p *CreateNetworkACLListParams) toURLValues() url.Values { u := url.Values{} if p.p == nil { return u } - if v, found := p.p["action"]; found { - u.Set("action", v.(string)) - } - if v, found := p.p["cidrlist"]; found { - vv := strings.Join(v.([]string), ",") - u.Set("cidrlist", vv) - } - if v, found := p.p["customid"]; found { - u.Set("customid", v.(string)) - } - if v, found := p.p["endport"]; found { - vv := strconv.Itoa(v.(int)) - u.Set("endport", vv) + if v, found := p.p["description"]; found { + u.Set("description", v.(string)) } if v, found := p.p["fordisplay"]; found { vv := strconv.FormatBool(v.(bool)) u.Set("fordisplay", vv) } - if v, found := p.p["icmpcode"]; found { - vv := strconv.Itoa(v.(int)) - u.Set("icmpcode", vv) + if v, found := p.p["name"]; found { + u.Set("name", v.(string)) } - if v, found := p.p["icmptype"]; found { - vv := strconv.Itoa(v.(int)) - u.Set("icmptype", vv) - } - if v, found := p.p["id"]; found { - u.Set("id", v.(string)) - } - if v, found := p.p["number"]; found { - vv := strconv.Itoa(v.(int)) - u.Set("number", vv) - } - if v, found := p.p["protocol"]; found { - u.Set("protocol", v.(string)) - } - if v, found := p.p["startport"]; found { - vv := strconv.Itoa(v.(int)) - u.Set("startport", vv) - } - if v, found := p.p["traffictype"]; found { - u.Set("traffictype", v.(string)) + if v, found := p.p["vpcid"]; found { + u.Set("vpcid", v.(string)) } return u } -func (p *UpdateNetworkACLItemParams) SetAction(v string) { +func (p *CreateNetworkACLListParams) SetDescription(v string) { if p.p == nil { p.p = make(map[string]interface{}) } - p.p["action"] = v + p.p["description"] = v return } -func (p *UpdateNetworkACLItemParams) SetCidrlist(v []string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["cidrlist"] = v - return -} - -func (p *UpdateNetworkACLItemParams) SetCustomid(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["customid"] = v - return -} - -func (p *UpdateNetworkACLItemParams) SetEndport(v int) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["endport"] = v - return -} - -func (p *UpdateNetworkACLItemParams) SetFordisplay(v bool) { +func (p *CreateNetworkACLListParams) SetFordisplay(v bool) { if p.p == nil { p.p = make(map[string]interface{}) } @@ -342,79 +278,40 @@ func (p *UpdateNetworkACLItemParams) SetFordisplay(v bool) { return } -func (p *UpdateNetworkACLItemParams) SetIcmpcode(v int) { +func (p *CreateNetworkACLListParams) SetName(v string) { if p.p == nil { p.p = make(map[string]interface{}) } - p.p["icmpcode"] = v + p.p["name"] = v return } -func (p *UpdateNetworkACLItemParams) SetIcmptype(v int) { +func (p *CreateNetworkACLListParams) SetVpcid(v string) { if p.p == nil { p.p = make(map[string]interface{}) } - p.p["icmptype"] = v + p.p["vpcid"] = v return } -func (p *UpdateNetworkACLItemParams) SetId(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["id"] = v - return -} - -func (p *UpdateNetworkACLItemParams) SetNumber(v int) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["number"] = v - return -} - -func (p *UpdateNetworkACLItemParams) SetProtocol(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["protocol"] = v - return -} - -func (p *UpdateNetworkACLItemParams) SetStartport(v int) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["startport"] = v - return -} - -func (p *UpdateNetworkACLItemParams) SetTraffictype(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["traffictype"] = v - return -} - -// You should always use this function to get a new UpdateNetworkACLItemParams instance, +// You should always use this function to get a new CreateNetworkACLListParams instance, // as then you are sure you have configured all required params -func (s *NetworkACLService) NewUpdateNetworkACLItemParams(id string) *UpdateNetworkACLItemParams { - p := &UpdateNetworkACLItemParams{} +func (s *NetworkACLService) NewCreateNetworkACLListParams(name string, vpcid string) *CreateNetworkACLListParams { + p := &CreateNetworkACLListParams{} p.p = make(map[string]interface{}) - p.p["id"] = id + p.p["name"] = name + p.p["vpcid"] = vpcid return p } -// Updates ACL item with specified ID -func (s *NetworkACLService) UpdateNetworkACLItem(p *UpdateNetworkACLItemParams) (*UpdateNetworkACLItemResponse, error) { - resp, err := s.cs.newRequest("updateNetworkACLItem", p.toURLValues()) +// Creates a network ACL for the given VPC +func (s *NetworkACLService) CreateNetworkACLList(p *CreateNetworkACLListParams) (*CreateNetworkACLListResponse, error) { + resp, err := s.cs.newRequest("createNetworkACLList", p.toURLValues()) if err != nil { return nil, err } - var r UpdateNetworkACLItemResponse + var r CreateNetworkACLListResponse if err := json.Unmarshal(resp, &r); err != nil { return nil, err } @@ -438,36 +335,17 @@ func (s *NetworkACLService) UpdateNetworkACLItem(p *UpdateNetworkACLItemParams) return nil, err } } + return &r, nil } -type UpdateNetworkACLItemResponse struct { - JobID string `json:"jobid,omitempty"` - Aclid string `json:"aclid,omitempty"` - Action string `json:"action,omitempty"` - Cidrlist string `json:"cidrlist,omitempty"` - Endport string `json:"endport,omitempty"` - Fordisplay bool `json:"fordisplay,omitempty"` - Icmpcode int `json:"icmpcode,omitempty"` - Icmptype int `json:"icmptype,omitempty"` - Id string `json:"id,omitempty"` - Number int `json:"number,omitempty"` - Protocol string `json:"protocol,omitempty"` - Startport string `json:"startport,omitempty"` - State string `json:"state,omitempty"` - Tags []struct { - Account string `json:"account,omitempty"` - Customer string `json:"customer,omitempty"` - Domain string `json:"domain,omitempty"` - Domainid string `json:"domainid,omitempty"` - Key string `json:"key,omitempty"` - Project string `json:"project,omitempty"` - Projectid string `json:"projectid,omitempty"` - Resourceid string `json:"resourceid,omitempty"` - Resourcetype string `json:"resourcetype,omitempty"` - Value string `json:"value,omitempty"` - } `json:"tags,omitempty"` - Traffictype string `json:"traffictype,omitempty"` +type CreateNetworkACLListResponse struct { + JobID string `json:"jobid"` + Description string `json:"description"` + Fordisplay bool `json:"fordisplay"` + Id string `json:"id"` + Name string `json:"name"` + Vpcid string `json:"vpcid"` } type DeleteNetworkACLParams struct { @@ -528,13 +406,361 @@ func (s *NetworkACLService) DeleteNetworkACL(p *DeleteNetworkACLParams) (*Delete return nil, err } } + return &r, nil } type DeleteNetworkACLResponse struct { - JobID string `json:"jobid,omitempty"` - Displaytext string `json:"displaytext,omitempty"` - Success bool `json:"success,omitempty"` + JobID string `json:"jobid"` + Displaytext string `json:"displaytext"` + Success bool `json:"success"` +} + +type DeleteNetworkACLListParams struct { + p map[string]interface{} +} + +func (p *DeleteNetworkACLListParams) toURLValues() url.Values { + u := url.Values{} + if p.p == nil { + return u + } + if v, found := p.p["id"]; found { + u.Set("id", v.(string)) + } + return u +} + +func (p *DeleteNetworkACLListParams) SetId(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["id"] = v + return +} + +// You should always use this function to get a new DeleteNetworkACLListParams instance, +// as then you are sure you have configured all required params +func (s *NetworkACLService) NewDeleteNetworkACLListParams(id string) *DeleteNetworkACLListParams { + p := &DeleteNetworkACLListParams{} + p.p = make(map[string]interface{}) + p.p["id"] = id + return p +} + +// Deletes a network ACL +func (s *NetworkACLService) DeleteNetworkACLList(p *DeleteNetworkACLListParams) (*DeleteNetworkACLListResponse, error) { + resp, err := s.cs.newRequest("deleteNetworkACLList", p.toURLValues()) + if err != nil { + return nil, err + } + + var r DeleteNetworkACLListResponse + if err := json.Unmarshal(resp, &r); err != nil { + return nil, err + } + + // If we have a async client, we need to wait for the async result + if s.cs.async { + b, err := s.cs.GetAsyncJobResult(r.JobID, s.cs.timeout) + if err != nil { + if err == AsyncTimeoutErr { + return &r, err + } + return nil, err + } + + if err := json.Unmarshal(b, &r); err != nil { + return nil, err + } + } + + return &r, nil +} + +type DeleteNetworkACLListResponse struct { + JobID string `json:"jobid"` + Displaytext string `json:"displaytext"` + Success bool `json:"success"` +} + +type ListNetworkACLListsParams struct { + p map[string]interface{} +} + +func (p *ListNetworkACLListsParams) toURLValues() url.Values { + u := url.Values{} + if p.p == nil { + return u + } + if v, found := p.p["account"]; found { + u.Set("account", v.(string)) + } + if v, found := p.p["domainid"]; found { + u.Set("domainid", v.(string)) + } + if v, found := p.p["fordisplay"]; found { + vv := strconv.FormatBool(v.(bool)) + u.Set("fordisplay", vv) + } + if v, found := p.p["id"]; found { + u.Set("id", v.(string)) + } + if v, found := p.p["isrecursive"]; found { + vv := strconv.FormatBool(v.(bool)) + u.Set("isrecursive", vv) + } + if v, found := p.p["keyword"]; found { + u.Set("keyword", v.(string)) + } + if v, found := p.p["listall"]; found { + vv := strconv.FormatBool(v.(bool)) + u.Set("listall", vv) + } + if v, found := p.p["name"]; found { + u.Set("name", v.(string)) + } + if v, found := p.p["networkid"]; found { + u.Set("networkid", v.(string)) + } + if v, found := p.p["page"]; found { + vv := strconv.Itoa(v.(int)) + u.Set("page", vv) + } + if v, found := p.p["pagesize"]; found { + vv := strconv.Itoa(v.(int)) + u.Set("pagesize", vv) + } + if v, found := p.p["projectid"]; found { + u.Set("projectid", v.(string)) + } + if v, found := p.p["vpcid"]; found { + u.Set("vpcid", v.(string)) + } + return u +} + +func (p *ListNetworkACLListsParams) SetAccount(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["account"] = v + return +} + +func (p *ListNetworkACLListsParams) SetDomainid(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["domainid"] = v + return +} + +func (p *ListNetworkACLListsParams) SetFordisplay(v bool) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["fordisplay"] = v + return +} + +func (p *ListNetworkACLListsParams) SetId(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["id"] = v + return +} + +func (p *ListNetworkACLListsParams) SetIsrecursive(v bool) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["isrecursive"] = v + return +} + +func (p *ListNetworkACLListsParams) SetKeyword(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["keyword"] = v + return +} + +func (p *ListNetworkACLListsParams) SetListall(v bool) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["listall"] = v + return +} + +func (p *ListNetworkACLListsParams) SetName(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["name"] = v + return +} + +func (p *ListNetworkACLListsParams) SetNetworkid(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["networkid"] = v + return +} + +func (p *ListNetworkACLListsParams) SetPage(v int) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["page"] = v + return +} + +func (p *ListNetworkACLListsParams) SetPagesize(v int) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["pagesize"] = v + return +} + +func (p *ListNetworkACLListsParams) SetProjectid(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["projectid"] = v + return +} + +func (p *ListNetworkACLListsParams) SetVpcid(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["vpcid"] = v + return +} + +// You should always use this function to get a new ListNetworkACLListsParams instance, +// as then you are sure you have configured all required params +func (s *NetworkACLService) NewListNetworkACLListsParams() *ListNetworkACLListsParams { + p := &ListNetworkACLListsParams{} + p.p = make(map[string]interface{}) + return p +} + +// This is a courtesy helper function, which in some cases may not work as expected! +func (s *NetworkACLService) GetNetworkACLListID(name string, opts ...OptionFunc) (string, int, error) { + p := &ListNetworkACLListsParams{} + p.p = make(map[string]interface{}) + + p.p["name"] = name + + for _, fn := range append(s.cs.options, opts...) { + if err := fn(s.cs, p); err != nil { + return "", -1, err + } + } + + l, err := s.ListNetworkACLLists(p) + if err != nil { + return "", -1, err + } + + if l.Count == 0 { + return "", l.Count, fmt.Errorf("No match found for %s: %+v", name, l) + } + + if l.Count == 1 { + return l.NetworkACLLists[0].Id, l.Count, nil + } + + if l.Count > 1 { + for _, v := range l.NetworkACLLists { + if v.Name == name { + return v.Id, l.Count, nil + } + } + } + return "", l.Count, fmt.Errorf("Could not find an exact match for %s: %+v", name, l) +} + +// This is a courtesy helper function, which in some cases may not work as expected! +func (s *NetworkACLService) GetNetworkACLListByName(name string, opts ...OptionFunc) (*NetworkACLList, int, error) { + id, count, err := s.GetNetworkACLListID(name, opts...) + if err != nil { + return nil, count, err + } + + r, count, err := s.GetNetworkACLListByID(id, opts...) + if err != nil { + return nil, count, err + } + return r, count, nil +} + +// This is a courtesy helper function, which in some cases may not work as expected! +func (s *NetworkACLService) GetNetworkACLListByID(id string, opts ...OptionFunc) (*NetworkACLList, int, error) { + p := &ListNetworkACLListsParams{} + p.p = make(map[string]interface{}) + + p.p["id"] = id + + for _, fn := range append(s.cs.options, opts...) { + if err := fn(s.cs, p); err != nil { + return nil, -1, err + } + } + + l, err := s.ListNetworkACLLists(p) + if err != nil { + if strings.Contains(err.Error(), fmt.Sprintf( + "Invalid parameter id value=%s due to incorrect long value format, "+ + "or entity does not exist", id)) { + return nil, 0, fmt.Errorf("No match found for %s: %+v", id, l) + } + return nil, -1, err + } + + if l.Count == 0 { + return nil, l.Count, fmt.Errorf("No match found for %s: %+v", id, l) + } + + if l.Count == 1 { + return l.NetworkACLLists[0], l.Count, nil + } + return nil, l.Count, fmt.Errorf("There is more then one result for NetworkACLList UUID: %s!", id) +} + +// Lists all network ACLs +func (s *NetworkACLService) ListNetworkACLLists(p *ListNetworkACLListsParams) (*ListNetworkACLListsResponse, error) { + resp, err := s.cs.newRequest("listNetworkACLLists", p.toURLValues()) + if err != nil { + return nil, err + } + + var r ListNetworkACLListsResponse + if err := json.Unmarshal(resp, &r); err != nil { + return nil, err + } + + return &r, nil +} + +type ListNetworkACLListsResponse struct { + Count int `json:"count"` + NetworkACLLists []*NetworkACLList `json:"networkacllist"` +} + +type NetworkACLList struct { + Description string `json:"description"` + Fordisplay bool `json:"fordisplay"` + Id string `json:"id"` + Name string `json:"name"` + Vpcid string `json:"vpcid"` } type ListNetworkACLsParams struct { @@ -750,7 +976,7 @@ func (s *NetworkACLService) GetNetworkACLByID(id string, opts ...OptionFunc) (*N p.p["id"] = id - for _, fn := range opts { + for _, fn := range append(s.cs.options, opts...) { if err := fn(s.cs, p); err != nil { return nil, -1, err } @@ -787,6 +1013,7 @@ func (s *NetworkACLService) ListNetworkACLs(p *ListNetworkACLsParams) (*ListNetw if err := json.Unmarshal(resp, &r); err != nil { return nil, err } + return &r, nil } @@ -796,208 +1023,20 @@ type ListNetworkACLsResponse struct { } type NetworkACL struct { - Aclid string `json:"aclid,omitempty"` - Action string `json:"action,omitempty"` - Cidrlist string `json:"cidrlist,omitempty"` - Endport string `json:"endport,omitempty"` - Fordisplay bool `json:"fordisplay,omitempty"` - Icmpcode int `json:"icmpcode,omitempty"` - Icmptype int `json:"icmptype,omitempty"` - Id string `json:"id,omitempty"` - Number int `json:"number,omitempty"` - Protocol string `json:"protocol,omitempty"` - Startport string `json:"startport,omitempty"` - State string `json:"state,omitempty"` - Tags []struct { - Account string `json:"account,omitempty"` - Customer string `json:"customer,omitempty"` - Domain string `json:"domain,omitempty"` - Domainid string `json:"domainid,omitempty"` - Key string `json:"key,omitempty"` - Project string `json:"project,omitempty"` - Projectid string `json:"projectid,omitempty"` - Resourceid string `json:"resourceid,omitempty"` - Resourcetype string `json:"resourcetype,omitempty"` - Value string `json:"value,omitempty"` - } `json:"tags,omitempty"` - Traffictype string `json:"traffictype,omitempty"` -} - -type CreateNetworkACLListParams struct { - p map[string]interface{} -} - -func (p *CreateNetworkACLListParams) toURLValues() url.Values { - u := url.Values{} - if p.p == nil { - return u - } - if v, found := p.p["description"]; found { - u.Set("description", v.(string)) - } - if v, found := p.p["fordisplay"]; found { - vv := strconv.FormatBool(v.(bool)) - u.Set("fordisplay", vv) - } - if v, found := p.p["name"]; found { - u.Set("name", v.(string)) - } - if v, found := p.p["vpcid"]; found { - u.Set("vpcid", v.(string)) - } - return u -} - -func (p *CreateNetworkACLListParams) SetDescription(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["description"] = v - return -} - -func (p *CreateNetworkACLListParams) SetFordisplay(v bool) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["fordisplay"] = v - return -} - -func (p *CreateNetworkACLListParams) SetName(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["name"] = v - return -} - -func (p *CreateNetworkACLListParams) SetVpcid(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["vpcid"] = v - return -} - -// You should always use this function to get a new CreateNetworkACLListParams instance, -// as then you are sure you have configured all required params -func (s *NetworkACLService) NewCreateNetworkACLListParams(name string, vpcid string) *CreateNetworkACLListParams { - p := &CreateNetworkACLListParams{} - p.p = make(map[string]interface{}) - p.p["name"] = name - p.p["vpcid"] = vpcid - return p -} - -// Creates a network ACL for the given VPC -func (s *NetworkACLService) CreateNetworkACLList(p *CreateNetworkACLListParams) (*CreateNetworkACLListResponse, error) { - resp, err := s.cs.newRequest("createNetworkACLList", p.toURLValues()) - if err != nil { - return nil, err - } - - var r CreateNetworkACLListResponse - if err := json.Unmarshal(resp, &r); err != nil { - return nil, err - } - - // If we have a async client, we need to wait for the async result - if s.cs.async { - b, err := s.cs.GetAsyncJobResult(r.JobID, s.cs.timeout) - if err != nil { - if err == AsyncTimeoutErr { - return &r, err - } - return nil, err - } - - b, err = getRawValue(b) - if err != nil { - return nil, err - } - - if err := json.Unmarshal(b, &r); err != nil { - return nil, err - } - } - return &r, nil -} - -type CreateNetworkACLListResponse struct { - JobID string `json:"jobid,omitempty"` - Description string `json:"description,omitempty"` - Fordisplay bool `json:"fordisplay,omitempty"` - Id string `json:"id,omitempty"` - Name string `json:"name,omitempty"` - Vpcid string `json:"vpcid,omitempty"` -} - -type DeleteNetworkACLListParams struct { - p map[string]interface{} -} - -func (p *DeleteNetworkACLListParams) toURLValues() url.Values { - u := url.Values{} - if p.p == nil { - return u - } - if v, found := p.p["id"]; found { - u.Set("id", v.(string)) - } - return u -} - -func (p *DeleteNetworkACLListParams) SetId(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["id"] = v - return -} - -// You should always use this function to get a new DeleteNetworkACLListParams instance, -// as then you are sure you have configured all required params -func (s *NetworkACLService) NewDeleteNetworkACLListParams(id string) *DeleteNetworkACLListParams { - p := &DeleteNetworkACLListParams{} - p.p = make(map[string]interface{}) - p.p["id"] = id - return p -} - -// Deletes a network ACL -func (s *NetworkACLService) DeleteNetworkACLList(p *DeleteNetworkACLListParams) (*DeleteNetworkACLListResponse, error) { - resp, err := s.cs.newRequest("deleteNetworkACLList", p.toURLValues()) - if err != nil { - return nil, err - } - - var r DeleteNetworkACLListResponse - if err := json.Unmarshal(resp, &r); err != nil { - return nil, err - } - - // If we have a async client, we need to wait for the async result - if s.cs.async { - b, err := s.cs.GetAsyncJobResult(r.JobID, s.cs.timeout) - if err != nil { - if err == AsyncTimeoutErr { - return &r, err - } - return nil, err - } - - if err := json.Unmarshal(b, &r); err != nil { - return nil, err - } - } - return &r, nil -} - -type DeleteNetworkACLListResponse struct { - JobID string `json:"jobid,omitempty"` - Displaytext string `json:"displaytext,omitempty"` - Success bool `json:"success,omitempty"` + Aclid string `json:"aclid"` + Action string `json:"action"` + Cidrlist string `json:"cidrlist"` + Endport string `json:"endport"` + Fordisplay bool `json:"fordisplay"` + Icmpcode int `json:"icmpcode"` + Icmptype int `json:"icmptype"` + Id string `json:"id"` + Number int `json:"number"` + Protocol string `json:"protocol"` + Startport string `json:"startport"` + State string `json:"state"` + Tags []Tags `json:"tags"` + Traffictype string `json:"traffictype"` } type ReplaceNetworkACLListParams struct { @@ -1080,88 +1119,104 @@ func (s *NetworkACLService) ReplaceNetworkACLList(p *ReplaceNetworkACLListParams return nil, err } } + return &r, nil } type ReplaceNetworkACLListResponse struct { - JobID string `json:"jobid,omitempty"` - Displaytext string `json:"displaytext,omitempty"` - Success bool `json:"success,omitempty"` + JobID string `json:"jobid"` + Displaytext string `json:"displaytext"` + Success bool `json:"success"` } -type ListNetworkACLListsParams struct { +type UpdateNetworkACLItemParams struct { p map[string]interface{} } -func (p *ListNetworkACLListsParams) toURLValues() url.Values { +func (p *UpdateNetworkACLItemParams) toURLValues() url.Values { u := url.Values{} if p.p == nil { return u } - if v, found := p.p["account"]; found { - u.Set("account", v.(string)) + if v, found := p.p["action"]; found { + u.Set("action", v.(string)) } - if v, found := p.p["domainid"]; found { - u.Set("domainid", v.(string)) + if v, found := p.p["cidrlist"]; found { + vv := strings.Join(v.([]string), ",") + u.Set("cidrlist", vv) + } + if v, found := p.p["customid"]; found { + u.Set("customid", v.(string)) + } + if v, found := p.p["endport"]; found { + vv := strconv.Itoa(v.(int)) + u.Set("endport", vv) } if v, found := p.p["fordisplay"]; found { vv := strconv.FormatBool(v.(bool)) u.Set("fordisplay", vv) } + if v, found := p.p["icmpcode"]; found { + vv := strconv.Itoa(v.(int)) + u.Set("icmpcode", vv) + } + if v, found := p.p["icmptype"]; found { + vv := strconv.Itoa(v.(int)) + u.Set("icmptype", vv) + } if v, found := p.p["id"]; found { u.Set("id", v.(string)) } - if v, found := p.p["isrecursive"]; found { - vv := strconv.FormatBool(v.(bool)) - u.Set("isrecursive", vv) - } - if v, found := p.p["keyword"]; found { - u.Set("keyword", v.(string)) - } - if v, found := p.p["listall"]; found { - vv := strconv.FormatBool(v.(bool)) - u.Set("listall", vv) - } - if v, found := p.p["name"]; found { - u.Set("name", v.(string)) - } - if v, found := p.p["networkid"]; found { - u.Set("networkid", v.(string)) - } - if v, found := p.p["page"]; found { + if v, found := p.p["number"]; found { vv := strconv.Itoa(v.(int)) - u.Set("page", vv) + u.Set("number", vv) } - if v, found := p.p["pagesize"]; found { + if v, found := p.p["protocol"]; found { + u.Set("protocol", v.(string)) + } + if v, found := p.p["startport"]; found { vv := strconv.Itoa(v.(int)) - u.Set("pagesize", vv) + u.Set("startport", vv) } - if v, found := p.p["projectid"]; found { - u.Set("projectid", v.(string)) - } - if v, found := p.p["vpcid"]; found { - u.Set("vpcid", v.(string)) + if v, found := p.p["traffictype"]; found { + u.Set("traffictype", v.(string)) } return u } -func (p *ListNetworkACLListsParams) SetAccount(v string) { +func (p *UpdateNetworkACLItemParams) SetAction(v string) { if p.p == nil { p.p = make(map[string]interface{}) } - p.p["account"] = v + p.p["action"] = v return } -func (p *ListNetworkACLListsParams) SetDomainid(v string) { +func (p *UpdateNetworkACLItemParams) SetCidrlist(v []string) { if p.p == nil { p.p = make(map[string]interface{}) } - p.p["domainid"] = v + p.p["cidrlist"] = v return } -func (p *ListNetworkACLListsParams) SetFordisplay(v bool) { +func (p *UpdateNetworkACLItemParams) SetCustomid(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["customid"] = v + return +} + +func (p *UpdateNetworkACLItemParams) SetEndport(v int) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["endport"] = v + return +} + +func (p *UpdateNetworkACLItemParams) SetFordisplay(v bool) { if p.p == nil { p.p = make(map[string]interface{}) } @@ -1169,7 +1224,23 @@ func (p *ListNetworkACLListsParams) SetFordisplay(v bool) { return } -func (p *ListNetworkACLListsParams) SetId(v string) { +func (p *UpdateNetworkACLItemParams) SetIcmpcode(v int) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["icmpcode"] = v + return +} + +func (p *UpdateNetworkACLItemParams) SetIcmptype(v int) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["icmptype"] = v + return +} + +func (p *UpdateNetworkACLItemParams) SetId(v string) { if p.p == nil { p.p = make(map[string]interface{}) } @@ -1177,194 +1248,98 @@ func (p *ListNetworkACLListsParams) SetId(v string) { return } -func (p *ListNetworkACLListsParams) SetIsrecursive(v bool) { +func (p *UpdateNetworkACLItemParams) SetNumber(v int) { if p.p == nil { p.p = make(map[string]interface{}) } - p.p["isrecursive"] = v + p.p["number"] = v return } -func (p *ListNetworkACLListsParams) SetKeyword(v string) { +func (p *UpdateNetworkACLItemParams) SetProtocol(v string) { if p.p == nil { p.p = make(map[string]interface{}) } - p.p["keyword"] = v + p.p["protocol"] = v return } -func (p *ListNetworkACLListsParams) SetListall(v bool) { +func (p *UpdateNetworkACLItemParams) SetStartport(v int) { if p.p == nil { p.p = make(map[string]interface{}) } - p.p["listall"] = v + p.p["startport"] = v return } -func (p *ListNetworkACLListsParams) SetName(v string) { +func (p *UpdateNetworkACLItemParams) SetTraffictype(v string) { if p.p == nil { p.p = make(map[string]interface{}) } - p.p["name"] = v + p.p["traffictype"] = v return } -func (p *ListNetworkACLListsParams) SetNetworkid(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["networkid"] = v - return -} - -func (p *ListNetworkACLListsParams) SetPage(v int) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["page"] = v - return -} - -func (p *ListNetworkACLListsParams) SetPagesize(v int) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["pagesize"] = v - return -} - -func (p *ListNetworkACLListsParams) SetProjectid(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["projectid"] = v - return -} - -func (p *ListNetworkACLListsParams) SetVpcid(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["vpcid"] = v - return -} - -// You should always use this function to get a new ListNetworkACLListsParams instance, +// You should always use this function to get a new UpdateNetworkACLItemParams instance, // as then you are sure you have configured all required params -func (s *NetworkACLService) NewListNetworkACLListsParams() *ListNetworkACLListsParams { - p := &ListNetworkACLListsParams{} +func (s *NetworkACLService) NewUpdateNetworkACLItemParams(id string) *UpdateNetworkACLItemParams { + p := &UpdateNetworkACLItemParams{} p.p = make(map[string]interface{}) + p.p["id"] = id return p } -// This is a courtesy helper function, which in some cases may not work as expected! -func (s *NetworkACLService) GetNetworkACLListID(name string, opts ...OptionFunc) (string, int, error) { - p := &ListNetworkACLListsParams{} - p.p = make(map[string]interface{}) - - p.p["name"] = name - - for _, fn := range opts { - if err := fn(s.cs, p); err != nil { - return "", -1, err - } - } - - l, err := s.ListNetworkACLLists(p) - if err != nil { - return "", -1, err - } - - if l.Count == 0 { - return "", l.Count, fmt.Errorf("No match found for %s: %+v", name, l) - } - - if l.Count == 1 { - return l.NetworkACLLists[0].Id, l.Count, nil - } - - if l.Count > 1 { - for _, v := range l.NetworkACLLists { - if v.Name == name { - return v.Id, l.Count, nil - } - } - } - return "", l.Count, fmt.Errorf("Could not find an exact match for %s: %+v", name, l) -} - -// This is a courtesy helper function, which in some cases may not work as expected! -func (s *NetworkACLService) GetNetworkACLListByName(name string, opts ...OptionFunc) (*NetworkACLList, int, error) { - id, count, err := s.GetNetworkACLListID(name, opts...) - if err != nil { - return nil, count, err - } - - r, count, err := s.GetNetworkACLListByID(id, opts...) - if err != nil { - return nil, count, err - } - return r, count, nil -} - -// This is a courtesy helper function, which in some cases may not work as expected! -func (s *NetworkACLService) GetNetworkACLListByID(id string, opts ...OptionFunc) (*NetworkACLList, int, error) { - p := &ListNetworkACLListsParams{} - p.p = make(map[string]interface{}) - - p.p["id"] = id - - for _, fn := range opts { - if err := fn(s.cs, p); err != nil { - return nil, -1, err - } - } - - l, err := s.ListNetworkACLLists(p) - if err != nil { - if strings.Contains(err.Error(), fmt.Sprintf( - "Invalid parameter id value=%s due to incorrect long value format, "+ - "or entity does not exist", id)) { - return nil, 0, fmt.Errorf("No match found for %s: %+v", id, l) - } - return nil, -1, err - } - - if l.Count == 0 { - return nil, l.Count, fmt.Errorf("No match found for %s: %+v", id, l) - } - - if l.Count == 1 { - return l.NetworkACLLists[0], l.Count, nil - } - return nil, l.Count, fmt.Errorf("There is more then one result for NetworkACLList UUID: %s!", id) -} - -// Lists all network ACLs -func (s *NetworkACLService) ListNetworkACLLists(p *ListNetworkACLListsParams) (*ListNetworkACLListsResponse, error) { - resp, err := s.cs.newRequest("listNetworkACLLists", p.toURLValues()) +// Updates ACL item with specified ID +func (s *NetworkACLService) UpdateNetworkACLItem(p *UpdateNetworkACLItemParams) (*UpdateNetworkACLItemResponse, error) { + resp, err := s.cs.newRequest("updateNetworkACLItem", p.toURLValues()) if err != nil { return nil, err } - var r ListNetworkACLListsResponse + var r UpdateNetworkACLItemResponse if err := json.Unmarshal(resp, &r); err != nil { return nil, err } + + // If we have a async client, we need to wait for the async result + if s.cs.async { + b, err := s.cs.GetAsyncJobResult(r.JobID, s.cs.timeout) + if err != nil { + if err == AsyncTimeoutErr { + return &r, err + } + return nil, err + } + + b, err = getRawValue(b) + if err != nil { + return nil, err + } + + if err := json.Unmarshal(b, &r); err != nil { + return nil, err + } + } + return &r, nil } -type ListNetworkACLListsResponse struct { - Count int `json:"count"` - NetworkACLLists []*NetworkACLList `json:"networkacllist"` -} - -type NetworkACLList struct { - Description string `json:"description,omitempty"` - Fordisplay bool `json:"fordisplay,omitempty"` - Id string `json:"id,omitempty"` - Name string `json:"name,omitempty"` - Vpcid string `json:"vpcid,omitempty"` +type UpdateNetworkACLItemResponse struct { + JobID string `json:"jobid"` + Aclid string `json:"aclid"` + Action string `json:"action"` + Cidrlist string `json:"cidrlist"` + Endport string `json:"endport"` + Fordisplay bool `json:"fordisplay"` + Icmpcode int `json:"icmpcode"` + Icmptype int `json:"icmptype"` + Id string `json:"id"` + Number int `json:"number"` + Protocol string `json:"protocol"` + Startport string `json:"startport"` + State string `json:"state"` + Tags []Tags `json:"tags"` + Traffictype string `json:"traffictype"` } type UpdateNetworkACLListParams struct { @@ -1448,11 +1423,12 @@ func (s *NetworkACLService) UpdateNetworkACLList(p *UpdateNetworkACLListParams) return nil, err } } + return &r, nil } type UpdateNetworkACLListResponse struct { - JobID string `json:"jobid,omitempty"` - Displaytext string `json:"displaytext,omitempty"` - Success bool `json:"success,omitempty"` + JobID string `json:"jobid"` + Displaytext string `json:"displaytext"` + Success bool `json:"success"` } diff --git a/vendor/github.com/xanzy/go-cloudstack/cloudstack/NetworkDeviceService.go b/vendor/github.com/xanzy/go-cloudstack/cloudstack/NetworkDeviceService.go index 878d5286e..cea5a8acf 100644 --- a/vendor/github.com/xanzy/go-cloudstack/cloudstack/NetworkDeviceService.go +++ b/vendor/github.com/xanzy/go-cloudstack/cloudstack/NetworkDeviceService.go @@ -1,5 +1,5 @@ // -// Copyright 2016, Sander van Harmelen +// Copyright 2018, Sander van Harmelen // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -81,11 +81,83 @@ func (s *NetworkDeviceService) AddNetworkDevice(p *AddNetworkDeviceParams) (*Add if err := json.Unmarshal(resp, &r); err != nil { return nil, err } + return &r, nil } type AddNetworkDeviceResponse struct { - Id string `json:"id,omitempty"` + Id string `json:"id"` +} + +type DeleteNetworkDeviceParams struct { + p map[string]interface{} +} + +func (p *DeleteNetworkDeviceParams) toURLValues() url.Values { + u := url.Values{} + if p.p == nil { + return u + } + if v, found := p.p["id"]; found { + u.Set("id", v.(string)) + } + return u +} + +func (p *DeleteNetworkDeviceParams) SetId(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["id"] = v + return +} + +// You should always use this function to get a new DeleteNetworkDeviceParams instance, +// as then you are sure you have configured all required params +func (s *NetworkDeviceService) NewDeleteNetworkDeviceParams(id string) *DeleteNetworkDeviceParams { + p := &DeleteNetworkDeviceParams{} + p.p = make(map[string]interface{}) + p.p["id"] = id + return p +} + +// Deletes network device. +func (s *NetworkDeviceService) DeleteNetworkDevice(p *DeleteNetworkDeviceParams) (*DeleteNetworkDeviceResponse, error) { + resp, err := s.cs.newRequest("deleteNetworkDevice", p.toURLValues()) + if err != nil { + return nil, err + } + + var r DeleteNetworkDeviceResponse + if err := json.Unmarshal(resp, &r); err != nil { + return nil, err + } + + return &r, nil +} + +type DeleteNetworkDeviceResponse struct { + Displaytext string `json:"displaytext"` + Success bool `json:"success"` +} + +func (r *DeleteNetworkDeviceResponse) UnmarshalJSON(b []byte) error { + var m map[string]interface{} + err := json.Unmarshal(b, &m) + if err != nil { + return err + } + + if success, ok := m["success"].(string); ok { + m["success"] = success == "true" + b, err = json.Marshal(m) + if err != nil { + return err + } + } + + type alias DeleteNetworkDeviceResponse + return json.Unmarshal(b, (*alias)(r)) } type ListNetworkDeviceParams struct { @@ -181,6 +253,7 @@ func (s *NetworkDeviceService) ListNetworkDevice(p *ListNetworkDeviceParams) (*L if err := json.Unmarshal(resp, &r); err != nil { return nil, err } + return &r, nil } @@ -190,56 +263,5 @@ type ListNetworkDeviceResponse struct { } type NetworkDevice struct { - Id string `json:"id,omitempty"` -} - -type DeleteNetworkDeviceParams struct { - p map[string]interface{} -} - -func (p *DeleteNetworkDeviceParams) toURLValues() url.Values { - u := url.Values{} - if p.p == nil { - return u - } - if v, found := p.p["id"]; found { - u.Set("id", v.(string)) - } - return u -} - -func (p *DeleteNetworkDeviceParams) SetId(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["id"] = v - return -} - -// You should always use this function to get a new DeleteNetworkDeviceParams instance, -// as then you are sure you have configured all required params -func (s *NetworkDeviceService) NewDeleteNetworkDeviceParams(id string) *DeleteNetworkDeviceParams { - p := &DeleteNetworkDeviceParams{} - p.p = make(map[string]interface{}) - p.p["id"] = id - return p -} - -// Deletes network device. -func (s *NetworkDeviceService) DeleteNetworkDevice(p *DeleteNetworkDeviceParams) (*DeleteNetworkDeviceResponse, error) { - resp, err := s.cs.newRequest("deleteNetworkDevice", p.toURLValues()) - if err != nil { - return nil, err - } - - var r DeleteNetworkDeviceResponse - if err := json.Unmarshal(resp, &r); err != nil { - return nil, err - } - return &r, nil -} - -type DeleteNetworkDeviceResponse struct { - Displaytext string `json:"displaytext,omitempty"` - Success string `json:"success,omitempty"` + Id string `json:"id"` } diff --git a/vendor/github.com/xanzy/go-cloudstack/cloudstack/NetworkOfferingService.go b/vendor/github.com/xanzy/go-cloudstack/cloudstack/NetworkOfferingService.go index e0adf29af..51ed208dd 100644 --- a/vendor/github.com/xanzy/go-cloudstack/cloudstack/NetworkOfferingService.go +++ b/vendor/github.com/xanzy/go-cloudstack/cloudstack/NetworkOfferingService.go @@ -1,5 +1,5 @@ // -// Copyright 2016, Sander van Harmelen +// Copyright 2018, Sander van Harmelen // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -43,8 +43,7 @@ func (p *CreateNetworkOfferingParams) toURLValues() url.Values { if v, found := p.p["details"]; found { i := 0 for k, vv := range v.(map[string]string) { - u.Set(fmt.Sprintf("details[%d].key", i), k) - u.Set(fmt.Sprintf("details[%d].value", i), vv) + u.Set(fmt.Sprintf("details[%d].%s", i, k), vv) i++ } } @@ -55,6 +54,10 @@ func (p *CreateNetworkOfferingParams) toURLValues() url.Values { vv := strconv.FormatBool(v.(bool)) u.Set("egressdefaultpolicy", vv) } + if v, found := p.p["forvpc"]; found { + vv := strconv.FormatBool(v.(bool)) + u.Set("forvpc", vv) + } if v, found := p.p["guestiptype"]; found { u.Set("guestiptype", v.(string)) } @@ -157,6 +160,14 @@ func (p *CreateNetworkOfferingParams) SetEgressdefaultpolicy(v bool) { return } +func (p *CreateNetworkOfferingParams) SetForvpc(v bool) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["forvpc"] = v + return +} + func (p *CreateNetworkOfferingParams) SetGuestiptype(v string) { if p.p == nil { p.p = make(map[string]interface{}) @@ -297,214 +308,56 @@ func (s *NetworkOfferingService) CreateNetworkOffering(p *CreateNetworkOfferingP if err := json.Unmarshal(resp, &r); err != nil { return nil, err } + return &r, nil } type CreateNetworkOfferingResponse struct { - Availability string `json:"availability,omitempty"` - Conservemode bool `json:"conservemode,omitempty"` - Created string `json:"created,omitempty"` - Details map[string]string `json:"details,omitempty"` - Displaytext string `json:"displaytext,omitempty"` - Egressdefaultpolicy bool `json:"egressdefaultpolicy,omitempty"` - Forvpc bool `json:"forvpc,omitempty"` - Guestiptype string `json:"guestiptype,omitempty"` - Id string `json:"id,omitempty"` - Isdefault bool `json:"isdefault,omitempty"` - Ispersistent bool `json:"ispersistent,omitempty"` - Maxconnections int `json:"maxconnections,omitempty"` - Name string `json:"name,omitempty"` - Networkrate int `json:"networkrate,omitempty"` - Service []struct { - Capability []struct { - Canchooseservicecapability bool `json:"canchooseservicecapability,omitempty"` - Name string `json:"name,omitempty"` - Value string `json:"value,omitempty"` - } `json:"capability,omitempty"` - Name string `json:"name,omitempty"` - Provider []struct { - Canenableindividualservice bool `json:"canenableindividualservice,omitempty"` - Destinationphysicalnetworkid string `json:"destinationphysicalnetworkid,omitempty"` - Id string `json:"id,omitempty"` - Name string `json:"name,omitempty"` - Physicalnetworkid string `json:"physicalnetworkid,omitempty"` - Servicelist []string `json:"servicelist,omitempty"` - State string `json:"state,omitempty"` - } `json:"provider,omitempty"` - } `json:"service,omitempty"` - Serviceofferingid string `json:"serviceofferingid,omitempty"` - Specifyipranges bool `json:"specifyipranges,omitempty"` - Specifyvlan bool `json:"specifyvlan,omitempty"` - State string `json:"state,omitempty"` - Supportsstrechedl2subnet bool `json:"supportsstrechedl2subnet,omitempty"` - Tags string `json:"tags,omitempty"` - Traffictype string `json:"traffictype,omitempty"` + Availability string `json:"availability"` + Conservemode bool `json:"conservemode"` + Created string `json:"created"` + Details map[string]string `json:"details"` + Displaytext string `json:"displaytext"` + Egressdefaultpolicy bool `json:"egressdefaultpolicy"` + Forvpc bool `json:"forvpc"` + Guestiptype string `json:"guestiptype"` + Id string `json:"id"` + Isdefault bool `json:"isdefault"` + Ispersistent bool `json:"ispersistent"` + Maxconnections int `json:"maxconnections"` + Name string `json:"name"` + Networkrate int `json:"networkrate"` + Service []CreateNetworkOfferingResponseService `json:"service"` + Serviceofferingid string `json:"serviceofferingid"` + Specifyipranges bool `json:"specifyipranges"` + Specifyvlan bool `json:"specifyvlan"` + State string `json:"state"` + Supportspublicaccess bool `json:"supportspublicaccess"` + Supportsstrechedl2subnet bool `json:"supportsstrechedl2subnet"` + Tags string `json:"tags"` + Traffictype string `json:"traffictype"` } -type UpdateNetworkOfferingParams struct { - p map[string]interface{} +type CreateNetworkOfferingResponseService struct { + Capability []CreateNetworkOfferingResponseServiceCapability `json:"capability"` + Name string `json:"name"` + Provider []CreateNetworkOfferingResponseServiceProvider `json:"provider"` } -func (p *UpdateNetworkOfferingParams) toURLValues() url.Values { - u := url.Values{} - if p.p == nil { - return u - } - if v, found := p.p["availability"]; found { - u.Set("availability", v.(string)) - } - if v, found := p.p["displaytext"]; found { - u.Set("displaytext", v.(string)) - } - if v, found := p.p["id"]; found { - u.Set("id", v.(string)) - } - if v, found := p.p["keepaliveenabled"]; found { - vv := strconv.FormatBool(v.(bool)) - u.Set("keepaliveenabled", vv) - } - if v, found := p.p["maxconnections"]; found { - vv := strconv.Itoa(v.(int)) - u.Set("maxconnections", vv) - } - if v, found := p.p["name"]; found { - u.Set("name", v.(string)) - } - if v, found := p.p["sortkey"]; found { - vv := strconv.Itoa(v.(int)) - u.Set("sortkey", vv) - } - if v, found := p.p["state"]; found { - u.Set("state", v.(string)) - } - return u +type CreateNetworkOfferingResponseServiceProvider struct { + Canenableindividualservice bool `json:"canenableindividualservice"` + Destinationphysicalnetworkid string `json:"destinationphysicalnetworkid"` + Id string `json:"id"` + Name string `json:"name"` + Physicalnetworkid string `json:"physicalnetworkid"` + Servicelist []string `json:"servicelist"` + State string `json:"state"` } -func (p *UpdateNetworkOfferingParams) SetAvailability(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["availability"] = v - return -} - -func (p *UpdateNetworkOfferingParams) SetDisplaytext(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["displaytext"] = v - return -} - -func (p *UpdateNetworkOfferingParams) SetId(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["id"] = v - return -} - -func (p *UpdateNetworkOfferingParams) SetKeepaliveenabled(v bool) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["keepaliveenabled"] = v - return -} - -func (p *UpdateNetworkOfferingParams) SetMaxconnections(v int) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["maxconnections"] = v - return -} - -func (p *UpdateNetworkOfferingParams) SetName(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["name"] = v - return -} - -func (p *UpdateNetworkOfferingParams) SetSortkey(v int) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["sortkey"] = v - return -} - -func (p *UpdateNetworkOfferingParams) SetState(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["state"] = v - return -} - -// You should always use this function to get a new UpdateNetworkOfferingParams instance, -// as then you are sure you have configured all required params -func (s *NetworkOfferingService) NewUpdateNetworkOfferingParams() *UpdateNetworkOfferingParams { - p := &UpdateNetworkOfferingParams{} - p.p = make(map[string]interface{}) - return p -} - -// Updates a network offering. -func (s *NetworkOfferingService) UpdateNetworkOffering(p *UpdateNetworkOfferingParams) (*UpdateNetworkOfferingResponse, error) { - resp, err := s.cs.newRequest("updateNetworkOffering", p.toURLValues()) - if err != nil { - return nil, err - } - - var r UpdateNetworkOfferingResponse - if err := json.Unmarshal(resp, &r); err != nil { - return nil, err - } - return &r, nil -} - -type UpdateNetworkOfferingResponse struct { - Availability string `json:"availability,omitempty"` - Conservemode bool `json:"conservemode,omitempty"` - Created string `json:"created,omitempty"` - Details map[string]string `json:"details,omitempty"` - Displaytext string `json:"displaytext,omitempty"` - Egressdefaultpolicy bool `json:"egressdefaultpolicy,omitempty"` - Forvpc bool `json:"forvpc,omitempty"` - Guestiptype string `json:"guestiptype,omitempty"` - Id string `json:"id,omitempty"` - Isdefault bool `json:"isdefault,omitempty"` - Ispersistent bool `json:"ispersistent,omitempty"` - Maxconnections int `json:"maxconnections,omitempty"` - Name string `json:"name,omitempty"` - Networkrate int `json:"networkrate,omitempty"` - Service []struct { - Capability []struct { - Canchooseservicecapability bool `json:"canchooseservicecapability,omitempty"` - Name string `json:"name,omitempty"` - Value string `json:"value,omitempty"` - } `json:"capability,omitempty"` - Name string `json:"name,omitempty"` - Provider []struct { - Canenableindividualservice bool `json:"canenableindividualservice,omitempty"` - Destinationphysicalnetworkid string `json:"destinationphysicalnetworkid,omitempty"` - Id string `json:"id,omitempty"` - Name string `json:"name,omitempty"` - Physicalnetworkid string `json:"physicalnetworkid,omitempty"` - Servicelist []string `json:"servicelist,omitempty"` - State string `json:"state,omitempty"` - } `json:"provider,omitempty"` - } `json:"service,omitempty"` - Serviceofferingid string `json:"serviceofferingid,omitempty"` - Specifyipranges bool `json:"specifyipranges,omitempty"` - Specifyvlan bool `json:"specifyvlan,omitempty"` - State string `json:"state,omitempty"` - Supportsstrechedl2subnet bool `json:"supportsstrechedl2subnet,omitempty"` - Tags string `json:"tags,omitempty"` - Traffictype string `json:"traffictype,omitempty"` +type CreateNetworkOfferingResponseServiceCapability struct { + Canchooseservicecapability bool `json:"canchooseservicecapability"` + Name string `json:"name"` + Value string `json:"value"` } type DeleteNetworkOfferingParams struct { @@ -550,12 +403,32 @@ func (s *NetworkOfferingService) DeleteNetworkOffering(p *DeleteNetworkOfferingP if err := json.Unmarshal(resp, &r); err != nil { return nil, err } + return &r, nil } type DeleteNetworkOfferingResponse struct { - Displaytext string `json:"displaytext,omitempty"` - Success string `json:"success,omitempty"` + Displaytext string `json:"displaytext"` + Success bool `json:"success"` +} + +func (r *DeleteNetworkOfferingResponse) UnmarshalJSON(b []byte) error { + var m map[string]interface{} + err := json.Unmarshal(b, &m) + if err != nil { + return err + } + + if success, ok := m["success"].(string); ok { + m["success"] = success == "true" + b, err = json.Marshal(m) + if err != nil { + return err + } + } + + type alias DeleteNetworkOfferingResponse + return json.Unmarshal(b, (*alias)(r)) } type ListNetworkOfferingsParams struct { @@ -814,7 +687,7 @@ func (s *NetworkOfferingService) GetNetworkOfferingID(name string, opts ...Optio p.p["name"] = name - for _, fn := range opts { + for _, fn := range append(s.cs.options, opts...) { if err := fn(s.cs, p); err != nil { return "", -1, err } @@ -864,7 +737,7 @@ func (s *NetworkOfferingService) GetNetworkOfferingByID(id string, opts ...Optio p.p["id"] = id - for _, fn := range opts { + for _, fn := range append(s.cs.options, opts...) { if err := fn(s.cs, p); err != nil { return nil, -1, err } @@ -901,6 +774,7 @@ func (s *NetworkOfferingService) ListNetworkOfferings(p *ListNetworkOfferingsPar if err := json.Unmarshal(resp, &r); err != nil { return nil, err } + return &r, nil } @@ -910,42 +784,234 @@ type ListNetworkOfferingsResponse struct { } type NetworkOffering struct { - Availability string `json:"availability,omitempty"` - Conservemode bool `json:"conservemode,omitempty"` - Created string `json:"created,omitempty"` - Details map[string]string `json:"details,omitempty"` - Displaytext string `json:"displaytext,omitempty"` - Egressdefaultpolicy bool `json:"egressdefaultpolicy,omitempty"` - Forvpc bool `json:"forvpc,omitempty"` - Guestiptype string `json:"guestiptype,omitempty"` - Id string `json:"id,omitempty"` - Isdefault bool `json:"isdefault,omitempty"` - Ispersistent bool `json:"ispersistent,omitempty"` - Maxconnections int `json:"maxconnections,omitempty"` - Name string `json:"name,omitempty"` - Networkrate int `json:"networkrate,omitempty"` - Service []struct { - Capability []struct { - Canchooseservicecapability bool `json:"canchooseservicecapability,omitempty"` - Name string `json:"name,omitempty"` - Value string `json:"value,omitempty"` - } `json:"capability,omitempty"` - Name string `json:"name,omitempty"` - Provider []struct { - Canenableindividualservice bool `json:"canenableindividualservice,omitempty"` - Destinationphysicalnetworkid string `json:"destinationphysicalnetworkid,omitempty"` - Id string `json:"id,omitempty"` - Name string `json:"name,omitempty"` - Physicalnetworkid string `json:"physicalnetworkid,omitempty"` - Servicelist []string `json:"servicelist,omitempty"` - State string `json:"state,omitempty"` - } `json:"provider,omitempty"` - } `json:"service,omitempty"` - Serviceofferingid string `json:"serviceofferingid,omitempty"` - Specifyipranges bool `json:"specifyipranges,omitempty"` - Specifyvlan bool `json:"specifyvlan,omitempty"` - State string `json:"state,omitempty"` - Supportsstrechedl2subnet bool `json:"supportsstrechedl2subnet,omitempty"` - Tags string `json:"tags,omitempty"` - Traffictype string `json:"traffictype,omitempty"` + Availability string `json:"availability"` + Conservemode bool `json:"conservemode"` + Created string `json:"created"` + Details map[string]string `json:"details"` + Displaytext string `json:"displaytext"` + Egressdefaultpolicy bool `json:"egressdefaultpolicy"` + Forvpc bool `json:"forvpc"` + Guestiptype string `json:"guestiptype"` + Id string `json:"id"` + Isdefault bool `json:"isdefault"` + Ispersistent bool `json:"ispersistent"` + Maxconnections int `json:"maxconnections"` + Name string `json:"name"` + Networkrate int `json:"networkrate"` + Service []NetworkOfferingServiceInternal `json:"service"` + Serviceofferingid string `json:"serviceofferingid"` + Specifyipranges bool `json:"specifyipranges"` + Specifyvlan bool `json:"specifyvlan"` + State string `json:"state"` + Supportspublicaccess bool `json:"supportspublicaccess"` + Supportsstrechedl2subnet bool `json:"supportsstrechedl2subnet"` + Tags string `json:"tags"` + Traffictype string `json:"traffictype"` +} + +type NetworkOfferingServiceInternal struct { + Capability []NetworkOfferingServiceInternalCapability `json:"capability"` + Name string `json:"name"` + Provider []NetworkOfferingServiceInternalProvider `json:"provider"` +} + +type NetworkOfferingServiceInternalProvider struct { + Canenableindividualservice bool `json:"canenableindividualservice"` + Destinationphysicalnetworkid string `json:"destinationphysicalnetworkid"` + Id string `json:"id"` + Name string `json:"name"` + Physicalnetworkid string `json:"physicalnetworkid"` + Servicelist []string `json:"servicelist"` + State string `json:"state"` +} + +type NetworkOfferingServiceInternalCapability struct { + Canchooseservicecapability bool `json:"canchooseservicecapability"` + Name string `json:"name"` + Value string `json:"value"` +} + +type UpdateNetworkOfferingParams struct { + p map[string]interface{} +} + +func (p *UpdateNetworkOfferingParams) toURLValues() url.Values { + u := url.Values{} + if p.p == nil { + return u + } + if v, found := p.p["availability"]; found { + u.Set("availability", v.(string)) + } + if v, found := p.p["displaytext"]; found { + u.Set("displaytext", v.(string)) + } + if v, found := p.p["id"]; found { + u.Set("id", v.(string)) + } + if v, found := p.p["keepaliveenabled"]; found { + vv := strconv.FormatBool(v.(bool)) + u.Set("keepaliveenabled", vv) + } + if v, found := p.p["maxconnections"]; found { + vv := strconv.Itoa(v.(int)) + u.Set("maxconnections", vv) + } + if v, found := p.p["name"]; found { + u.Set("name", v.(string)) + } + if v, found := p.p["sortkey"]; found { + vv := strconv.Itoa(v.(int)) + u.Set("sortkey", vv) + } + if v, found := p.p["state"]; found { + u.Set("state", v.(string)) + } + if v, found := p.p["tags"]; found { + u.Set("tags", v.(string)) + } + return u +} + +func (p *UpdateNetworkOfferingParams) SetAvailability(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["availability"] = v + return +} + +func (p *UpdateNetworkOfferingParams) SetDisplaytext(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["displaytext"] = v + return +} + +func (p *UpdateNetworkOfferingParams) SetId(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["id"] = v + return +} + +func (p *UpdateNetworkOfferingParams) SetKeepaliveenabled(v bool) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["keepaliveenabled"] = v + return +} + +func (p *UpdateNetworkOfferingParams) SetMaxconnections(v int) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["maxconnections"] = v + return +} + +func (p *UpdateNetworkOfferingParams) SetName(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["name"] = v + return +} + +func (p *UpdateNetworkOfferingParams) SetSortkey(v int) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["sortkey"] = v + return +} + +func (p *UpdateNetworkOfferingParams) SetState(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["state"] = v + return +} + +func (p *UpdateNetworkOfferingParams) SetTags(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["tags"] = v + return +} + +// You should always use this function to get a new UpdateNetworkOfferingParams instance, +// as then you are sure you have configured all required params +func (s *NetworkOfferingService) NewUpdateNetworkOfferingParams() *UpdateNetworkOfferingParams { + p := &UpdateNetworkOfferingParams{} + p.p = make(map[string]interface{}) + return p +} + +// Updates a network offering. +func (s *NetworkOfferingService) UpdateNetworkOffering(p *UpdateNetworkOfferingParams) (*UpdateNetworkOfferingResponse, error) { + resp, err := s.cs.newRequest("updateNetworkOffering", p.toURLValues()) + if err != nil { + return nil, err + } + + var r UpdateNetworkOfferingResponse + if err := json.Unmarshal(resp, &r); err != nil { + return nil, err + } + + return &r, nil +} + +type UpdateNetworkOfferingResponse struct { + Availability string `json:"availability"` + Conservemode bool `json:"conservemode"` + Created string `json:"created"` + Details map[string]string `json:"details"` + Displaytext string `json:"displaytext"` + Egressdefaultpolicy bool `json:"egressdefaultpolicy"` + Forvpc bool `json:"forvpc"` + Guestiptype string `json:"guestiptype"` + Id string `json:"id"` + Isdefault bool `json:"isdefault"` + Ispersistent bool `json:"ispersistent"` + Maxconnections int `json:"maxconnections"` + Name string `json:"name"` + Networkrate int `json:"networkrate"` + Service []UpdateNetworkOfferingResponseService `json:"service"` + Serviceofferingid string `json:"serviceofferingid"` + Specifyipranges bool `json:"specifyipranges"` + Specifyvlan bool `json:"specifyvlan"` + State string `json:"state"` + Supportspublicaccess bool `json:"supportspublicaccess"` + Supportsstrechedl2subnet bool `json:"supportsstrechedl2subnet"` + Tags string `json:"tags"` + Traffictype string `json:"traffictype"` +} + +type UpdateNetworkOfferingResponseService struct { + Capability []UpdateNetworkOfferingResponseServiceCapability `json:"capability"` + Name string `json:"name"` + Provider []UpdateNetworkOfferingResponseServiceProvider `json:"provider"` +} + +type UpdateNetworkOfferingResponseServiceProvider struct { + Canenableindividualservice bool `json:"canenableindividualservice"` + Destinationphysicalnetworkid string `json:"destinationphysicalnetworkid"` + Id string `json:"id"` + Name string `json:"name"` + Physicalnetworkid string `json:"physicalnetworkid"` + Servicelist []string `json:"servicelist"` + State string `json:"state"` +} + +type UpdateNetworkOfferingResponseServiceCapability struct { + Canchooseservicecapability bool `json:"canchooseservicecapability"` + Name string `json:"name"` + Value string `json:"value"` } diff --git a/vendor/github.com/xanzy/go-cloudstack/cloudstack/NetworkService.go b/vendor/github.com/xanzy/go-cloudstack/cloudstack/NetworkService.go index ce07a3b9e..aef044e78 100644 --- a/vendor/github.com/xanzy/go-cloudstack/cloudstack/NetworkService.go +++ b/vendor/github.com/xanzy/go-cloudstack/cloudstack/NetworkService.go @@ -1,5 +1,5 @@ // -// Copyright 2016, Sander van Harmelen +// Copyright 2018, Sander van Harmelen // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -24,160 +24,229 @@ import ( "strings" ) -type DedicatePublicIpRangeParams struct { +type AddNetworkServiceProviderParams struct { p map[string]interface{} } -func (p *DedicatePublicIpRangeParams) toURLValues() url.Values { +func (p *AddNetworkServiceProviderParams) toURLValues() url.Values { u := url.Values{} if p.p == nil { return u } - if v, found := p.p["account"]; found { - u.Set("account", v.(string)) + if v, found := p.p["destinationphysicalnetworkid"]; found { + u.Set("destinationphysicalnetworkid", v.(string)) } - if v, found := p.p["domainid"]; found { - u.Set("domainid", v.(string)) + if v, found := p.p["name"]; found { + u.Set("name", v.(string)) } - if v, found := p.p["id"]; found { - u.Set("id", v.(string)) + if v, found := p.p["physicalnetworkid"]; found { + u.Set("physicalnetworkid", v.(string)) } - if v, found := p.p["projectid"]; found { - u.Set("projectid", v.(string)) + if v, found := p.p["servicelist"]; found { + vv := strings.Join(v.([]string), ",") + u.Set("servicelist", vv) } return u } -func (p *DedicatePublicIpRangeParams) SetAccount(v string) { +func (p *AddNetworkServiceProviderParams) SetDestinationphysicalnetworkid(v string) { if p.p == nil { p.p = make(map[string]interface{}) } - p.p["account"] = v + p.p["destinationphysicalnetworkid"] = v return } -func (p *DedicatePublicIpRangeParams) SetDomainid(v string) { +func (p *AddNetworkServiceProviderParams) SetName(v string) { if p.p == nil { p.p = make(map[string]interface{}) } - p.p["domainid"] = v + p.p["name"] = v return } -func (p *DedicatePublicIpRangeParams) SetId(v string) { +func (p *AddNetworkServiceProviderParams) SetPhysicalnetworkid(v string) { if p.p == nil { p.p = make(map[string]interface{}) } - p.p["id"] = v + p.p["physicalnetworkid"] = v return } -func (p *DedicatePublicIpRangeParams) SetProjectid(v string) { +func (p *AddNetworkServiceProviderParams) SetServicelist(v []string) { if p.p == nil { p.p = make(map[string]interface{}) } - p.p["projectid"] = v + p.p["servicelist"] = v return } -// You should always use this function to get a new DedicatePublicIpRangeParams instance, +// You should always use this function to get a new AddNetworkServiceProviderParams instance, // as then you are sure you have configured all required params -func (s *NetworkService) NewDedicatePublicIpRangeParams(domainid string, id string) *DedicatePublicIpRangeParams { - p := &DedicatePublicIpRangeParams{} +func (s *NetworkService) NewAddNetworkServiceProviderParams(name string, physicalnetworkid string) *AddNetworkServiceProviderParams { + p := &AddNetworkServiceProviderParams{} p.p = make(map[string]interface{}) - p.p["domainid"] = domainid - p.p["id"] = id + p.p["name"] = name + p.p["physicalnetworkid"] = physicalnetworkid return p } -// Dedicates a Public IP range to an account -func (s *NetworkService) DedicatePublicIpRange(p *DedicatePublicIpRangeParams) (*DedicatePublicIpRangeResponse, error) { - resp, err := s.cs.newRequest("dedicatePublicIpRange", p.toURLValues()) +// Adds a network serviceProvider to a physical network +func (s *NetworkService) AddNetworkServiceProvider(p *AddNetworkServiceProviderParams) (*AddNetworkServiceProviderResponse, error) { + resp, err := s.cs.newRequest("addNetworkServiceProvider", p.toURLValues()) if err != nil { return nil, err } - var r DedicatePublicIpRangeResponse + var r AddNetworkServiceProviderResponse if err := json.Unmarshal(resp, &r); err != nil { return nil, err } + + // If we have a async client, we need to wait for the async result + if s.cs.async { + b, err := s.cs.GetAsyncJobResult(r.JobID, s.cs.timeout) + if err != nil { + if err == AsyncTimeoutErr { + return &r, err + } + return nil, err + } + + b, err = getRawValue(b) + if err != nil { + return nil, err + } + + if err := json.Unmarshal(b, &r); err != nil { + return nil, err + } + } + return &r, nil } -type DedicatePublicIpRangeResponse struct { - Account string `json:"account,omitempty"` - Description string `json:"description,omitempty"` - Domain string `json:"domain,omitempty"` - Domainid string `json:"domainid,omitempty"` - Endip string `json:"endip,omitempty"` - Endipv6 string `json:"endipv6,omitempty"` - Forvirtualnetwork bool `json:"forvirtualnetwork,omitempty"` - Gateway string `json:"gateway,omitempty"` - Id string `json:"id,omitempty"` - Ip6cidr string `json:"ip6cidr,omitempty"` - Ip6gateway string `json:"ip6gateway,omitempty"` - Netmask string `json:"netmask,omitempty"` - Networkid string `json:"networkid,omitempty"` - Physicalnetworkid string `json:"physicalnetworkid,omitempty"` - Podid string `json:"podid,omitempty"` - Podname string `json:"podname,omitempty"` - Project string `json:"project,omitempty"` - Projectid string `json:"projectid,omitempty"` - Startip string `json:"startip,omitempty"` - Startipv6 string `json:"startipv6,omitempty"` - Vlan string `json:"vlan,omitempty"` - Zoneid string `json:"zoneid,omitempty"` +type AddNetworkServiceProviderResponse struct { + JobID string `json:"jobid"` + Canenableindividualservice bool `json:"canenableindividualservice"` + Destinationphysicalnetworkid string `json:"destinationphysicalnetworkid"` + Id string `json:"id"` + Name string `json:"name"` + Physicalnetworkid string `json:"physicalnetworkid"` + Servicelist []string `json:"servicelist"` + State string `json:"state"` } -type ReleasePublicIpRangeParams struct { +type AddOpenDaylightControllerParams struct { p map[string]interface{} } -func (p *ReleasePublicIpRangeParams) toURLValues() url.Values { +func (p *AddOpenDaylightControllerParams) toURLValues() url.Values { u := url.Values{} if p.p == nil { return u } - if v, found := p.p["id"]; found { - u.Set("id", v.(string)) + if v, found := p.p["password"]; found { + u.Set("password", v.(string)) + } + if v, found := p.p["physicalnetworkid"]; found { + u.Set("physicalnetworkid", v.(string)) + } + if v, found := p.p["url"]; found { + u.Set("url", v.(string)) + } + if v, found := p.p["username"]; found { + u.Set("username", v.(string)) } return u } -func (p *ReleasePublicIpRangeParams) SetId(v string) { +func (p *AddOpenDaylightControllerParams) SetPassword(v string) { if p.p == nil { p.p = make(map[string]interface{}) } - p.p["id"] = v + p.p["password"] = v return } -// You should always use this function to get a new ReleasePublicIpRangeParams instance, +func (p *AddOpenDaylightControllerParams) SetPhysicalnetworkid(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["physicalnetworkid"] = v + return +} + +func (p *AddOpenDaylightControllerParams) SetUrl(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["url"] = v + return +} + +func (p *AddOpenDaylightControllerParams) SetUsername(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["username"] = v + return +} + +// You should always use this function to get a new AddOpenDaylightControllerParams instance, // as then you are sure you have configured all required params -func (s *NetworkService) NewReleasePublicIpRangeParams(id string) *ReleasePublicIpRangeParams { - p := &ReleasePublicIpRangeParams{} +func (s *NetworkService) NewAddOpenDaylightControllerParams(password string, physicalnetworkid string, url string, username string) *AddOpenDaylightControllerParams { + p := &AddOpenDaylightControllerParams{} p.p = make(map[string]interface{}) - p.p["id"] = id + p.p["password"] = password + p.p["physicalnetworkid"] = physicalnetworkid + p.p["url"] = url + p.p["username"] = username return p } -// Releases a Public IP range back to the system pool -func (s *NetworkService) ReleasePublicIpRange(p *ReleasePublicIpRangeParams) (*ReleasePublicIpRangeResponse, error) { - resp, err := s.cs.newRequest("releasePublicIpRange", p.toURLValues()) +// Adds an OpenDyalight controler +func (s *NetworkService) AddOpenDaylightController(p *AddOpenDaylightControllerParams) (*AddOpenDaylightControllerResponse, error) { + resp, err := s.cs.newRequest("addOpenDaylightController", p.toURLValues()) if err != nil { return nil, err } - var r ReleasePublicIpRangeResponse + var r AddOpenDaylightControllerResponse if err := json.Unmarshal(resp, &r); err != nil { return nil, err } + + // If we have a async client, we need to wait for the async result + if s.cs.async { + b, err := s.cs.GetAsyncJobResult(r.JobID, s.cs.timeout) + if err != nil { + if err == AsyncTimeoutErr { + return &r, err + } + return nil, err + } + + b, err = getRawValue(b) + if err != nil { + return nil, err + } + + if err := json.Unmarshal(b, &r); err != nil { + return nil, err + } + } + return &r, nil } -type ReleasePublicIpRangeResponse struct { - Displaytext string `json:"displaytext,omitempty"` - Success string `json:"success,omitempty"` +type AddOpenDaylightControllerResponse struct { + JobID string `json:"jobid"` + Id string `json:"id"` + Name string `json:"name"` + Physicalnetworkid string `json:"physicalnetworkid"` + Url string `json:"url"` + Username string `json:"username"` } type CreateNetworkParams struct { @@ -198,6 +267,10 @@ func (p *CreateNetworkParams) toURLValues() url.Values { if v, found := p.p["acltype"]; found { u.Set("acltype", v.(string)) } + if v, found := p.p["bypassvlanoverlapcheck"]; found { + vv := strconv.FormatBool(v.(bool)) + u.Set("bypassvlanoverlapcheck", vv) + } if v, found := p.p["displaynetwork"]; found { vv := strconv.FormatBool(v.(bool)) u.Set("displaynetwork", vv) @@ -214,6 +287,9 @@ func (p *CreateNetworkParams) toURLValues() url.Values { if v, found := p.p["endipv6"]; found { u.Set("endipv6", v.(string)) } + if v, found := p.p["externalid"]; found { + u.Set("externalid", v.(string)) + } if v, found := p.p["gateway"]; found { u.Set("gateway", v.(string)) } @@ -290,6 +366,14 @@ func (p *CreateNetworkParams) SetAcltype(v string) { return } +func (p *CreateNetworkParams) SetBypassvlanoverlapcheck(v bool) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["bypassvlanoverlapcheck"] = v + return +} + func (p *CreateNetworkParams) SetDisplaynetwork(v bool) { if p.p == nil { p.p = make(map[string]interface{}) @@ -330,6 +414,14 @@ func (p *CreateNetworkParams) SetEndipv6(v string) { return } +func (p *CreateNetworkParams) SetExternalid(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["externalid"] = v + return +} + func (p *CreateNetworkParams) SetGateway(v string) { if p.p == nil { p.p = make(map[string]interface{}) @@ -485,85 +577,662 @@ func (s *NetworkService) CreateNetwork(p *CreateNetworkParams) (*CreateNetworkRe if err := json.Unmarshal(resp, &r); err != nil { return nil, err } + return &r, nil } type CreateNetworkResponse struct { - Account string `json:"account,omitempty"` - Aclid string `json:"aclid,omitempty"` - Acltype string `json:"acltype,omitempty"` - Broadcastdomaintype string `json:"broadcastdomaintype,omitempty"` - Broadcasturi string `json:"broadcasturi,omitempty"` - Canusefordeploy bool `json:"canusefordeploy,omitempty"` - Cidr string `json:"cidr,omitempty"` - Displaynetwork bool `json:"displaynetwork,omitempty"` - Displaytext string `json:"displaytext,omitempty"` - Dns1 string `json:"dns1,omitempty"` - Dns2 string `json:"dns2,omitempty"` - Domain string `json:"domain,omitempty"` - Domainid string `json:"domainid,omitempty"` - Gateway string `json:"gateway,omitempty"` - Id string `json:"id,omitempty"` - Ip6cidr string `json:"ip6cidr,omitempty"` - Ip6gateway string `json:"ip6gateway,omitempty"` - Isdefault bool `json:"isdefault,omitempty"` - Ispersistent bool `json:"ispersistent,omitempty"` - Issystem bool `json:"issystem,omitempty"` - Name string `json:"name,omitempty"` - Netmask string `json:"netmask,omitempty"` - Networkcidr string `json:"networkcidr,omitempty"` - Networkdomain string `json:"networkdomain,omitempty"` - Networkofferingavailability string `json:"networkofferingavailability,omitempty"` - Networkofferingconservemode bool `json:"networkofferingconservemode,omitempty"` - Networkofferingdisplaytext string `json:"networkofferingdisplaytext,omitempty"` - Networkofferingid string `json:"networkofferingid,omitempty"` - Networkofferingname string `json:"networkofferingname,omitempty"` - Physicalnetworkid string `json:"physicalnetworkid,omitempty"` - Project string `json:"project,omitempty"` - Projectid string `json:"projectid,omitempty"` - Related string `json:"related,omitempty"` - Reservediprange string `json:"reservediprange,omitempty"` - Restartrequired bool `json:"restartrequired,omitempty"` - Service []struct { - Capability []struct { - Canchooseservicecapability bool `json:"canchooseservicecapability,omitempty"` - Name string `json:"name,omitempty"` - Value string `json:"value,omitempty"` - } `json:"capability,omitempty"` - Name string `json:"name,omitempty"` - Provider []struct { - Canenableindividualservice bool `json:"canenableindividualservice,omitempty"` - Destinationphysicalnetworkid string `json:"destinationphysicalnetworkid,omitempty"` - Id string `json:"id,omitempty"` - Name string `json:"name,omitempty"` - Physicalnetworkid string `json:"physicalnetworkid,omitempty"` - Servicelist []string `json:"servicelist,omitempty"` - State string `json:"state,omitempty"` - } `json:"provider,omitempty"` - } `json:"service,omitempty"` - Specifyipranges bool `json:"specifyipranges,omitempty"` - State string `json:"state,omitempty"` - Strechedl2subnet bool `json:"strechedl2subnet,omitempty"` - Subdomainaccess bool `json:"subdomainaccess,omitempty"` - Tags []struct { - Account string `json:"account,omitempty"` - Customer string `json:"customer,omitempty"` - Domain string `json:"domain,omitempty"` - Domainid string `json:"domainid,omitempty"` - Key string `json:"key,omitempty"` - Project string `json:"project,omitempty"` - Projectid string `json:"projectid,omitempty"` - Resourceid string `json:"resourceid,omitempty"` - Resourcetype string `json:"resourcetype,omitempty"` - Value string `json:"value,omitempty"` - } `json:"tags,omitempty"` - Traffictype string `json:"traffictype,omitempty"` - Type string `json:"type,omitempty"` - Vlan string `json:"vlan,omitempty"` - Vpcid string `json:"vpcid,omitempty"` - Zoneid string `json:"zoneid,omitempty"` - Zonename string `json:"zonename,omitempty"` - Zonesnetworkspans []string `json:"zonesnetworkspans,omitempty"` + Account string `json:"account"` + Aclid string `json:"aclid"` + Acltype string `json:"acltype"` + Broadcastdomaintype string `json:"broadcastdomaintype"` + Broadcasturi string `json:"broadcasturi"` + Canusefordeploy bool `json:"canusefordeploy"` + Cidr string `json:"cidr"` + Displaynetwork bool `json:"displaynetwork"` + Displaytext string `json:"displaytext"` + Dns1 string `json:"dns1"` + Dns2 string `json:"dns2"` + Domain string `json:"domain"` + Domainid string `json:"domainid"` + Externalid string `json:"externalid"` + Gateway string `json:"gateway"` + Id string `json:"id"` + Ip6cidr string `json:"ip6cidr"` + Ip6gateway string `json:"ip6gateway"` + Isdefault bool `json:"isdefault"` + Ispersistent bool `json:"ispersistent"` + Issystem bool `json:"issystem"` + Name string `json:"name"` + Netmask string `json:"netmask"` + Networkcidr string `json:"networkcidr"` + Networkdomain string `json:"networkdomain"` + Networkofferingavailability string `json:"networkofferingavailability"` + Networkofferingconservemode bool `json:"networkofferingconservemode"` + Networkofferingdisplaytext string `json:"networkofferingdisplaytext"` + Networkofferingid string `json:"networkofferingid"` + Networkofferingname string `json:"networkofferingname"` + Physicalnetworkid string `json:"physicalnetworkid"` + Project string `json:"project"` + Projectid string `json:"projectid"` + Redundantrouter bool `json:"redundantrouter"` + Related string `json:"related"` + Reservediprange string `json:"reservediprange"` + Restartrequired bool `json:"restartrequired"` + Service []CreateNetworkResponseService `json:"service"` + Specifyipranges bool `json:"specifyipranges"` + State string `json:"state"` + Strechedl2subnet bool `json:"strechedl2subnet"` + Subdomainaccess bool `json:"subdomainaccess"` + Tags []Tags `json:"tags"` + Traffictype string `json:"traffictype"` + Type string `json:"type"` + Vlan string `json:"vlan"` + Vpcid string `json:"vpcid"` + Zoneid string `json:"zoneid"` + Zonename string `json:"zonename"` + Zonesnetworkspans []interface{} `json:"zonesnetworkspans"` +} + +type CreateNetworkResponseService struct { + Capability []CreateNetworkResponseServiceCapability `json:"capability"` + Name string `json:"name"` + Provider []CreateNetworkResponseServiceProvider `json:"provider"` +} + +type CreateNetworkResponseServiceProvider struct { + Canenableindividualservice bool `json:"canenableindividualservice"` + Destinationphysicalnetworkid string `json:"destinationphysicalnetworkid"` + Id string `json:"id"` + Name string `json:"name"` + Physicalnetworkid string `json:"physicalnetworkid"` + Servicelist []string `json:"servicelist"` + State string `json:"state"` +} + +type CreateNetworkResponseServiceCapability struct { + Canchooseservicecapability bool `json:"canchooseservicecapability"` + Name string `json:"name"` + Value string `json:"value"` +} + +type CreatePhysicalNetworkParams struct { + p map[string]interface{} +} + +func (p *CreatePhysicalNetworkParams) toURLValues() url.Values { + u := url.Values{} + if p.p == nil { + return u + } + if v, found := p.p["broadcastdomainrange"]; found { + u.Set("broadcastdomainrange", v.(string)) + } + if v, found := p.p["domainid"]; found { + u.Set("domainid", v.(string)) + } + if v, found := p.p["isolationmethods"]; found { + vv := strings.Join(v.([]string), ",") + u.Set("isolationmethods", vv) + } + if v, found := p.p["name"]; found { + u.Set("name", v.(string)) + } + if v, found := p.p["networkspeed"]; found { + u.Set("networkspeed", v.(string)) + } + if v, found := p.p["tags"]; found { + vv := strings.Join(v.([]string), ",") + u.Set("tags", vv) + } + if v, found := p.p["vlan"]; found { + u.Set("vlan", v.(string)) + } + if v, found := p.p["zoneid"]; found { + u.Set("zoneid", v.(string)) + } + return u +} + +func (p *CreatePhysicalNetworkParams) SetBroadcastdomainrange(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["broadcastdomainrange"] = v + return +} + +func (p *CreatePhysicalNetworkParams) SetDomainid(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["domainid"] = v + return +} + +func (p *CreatePhysicalNetworkParams) SetIsolationmethods(v []string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["isolationmethods"] = v + return +} + +func (p *CreatePhysicalNetworkParams) SetName(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["name"] = v + return +} + +func (p *CreatePhysicalNetworkParams) SetNetworkspeed(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["networkspeed"] = v + return +} + +func (p *CreatePhysicalNetworkParams) SetTags(v []string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["tags"] = v + return +} + +func (p *CreatePhysicalNetworkParams) SetVlan(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["vlan"] = v + return +} + +func (p *CreatePhysicalNetworkParams) SetZoneid(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["zoneid"] = v + return +} + +// You should always use this function to get a new CreatePhysicalNetworkParams instance, +// as then you are sure you have configured all required params +func (s *NetworkService) NewCreatePhysicalNetworkParams(name string, zoneid string) *CreatePhysicalNetworkParams { + p := &CreatePhysicalNetworkParams{} + p.p = make(map[string]interface{}) + p.p["name"] = name + p.p["zoneid"] = zoneid + return p +} + +// Creates a physical network +func (s *NetworkService) CreatePhysicalNetwork(p *CreatePhysicalNetworkParams) (*CreatePhysicalNetworkResponse, error) { + resp, err := s.cs.newRequest("createPhysicalNetwork", p.toURLValues()) + if err != nil { + return nil, err + } + + var r CreatePhysicalNetworkResponse + if err := json.Unmarshal(resp, &r); err != nil { + return nil, err + } + + // If we have a async client, we need to wait for the async result + if s.cs.async { + b, err := s.cs.GetAsyncJobResult(r.JobID, s.cs.timeout) + if err != nil { + if err == AsyncTimeoutErr { + return &r, err + } + return nil, err + } + + b, err = getRawValue(b) + if err != nil { + return nil, err + } + + if err := json.Unmarshal(b, &r); err != nil { + return nil, err + } + } + + return &r, nil +} + +type CreatePhysicalNetworkResponse struct { + JobID string `json:"jobid"` + Broadcastdomainrange string `json:"broadcastdomainrange"` + Domainid string `json:"domainid"` + Id string `json:"id"` + Isolationmethods string `json:"isolationmethods"` + Name string `json:"name"` + Networkspeed string `json:"networkspeed"` + State string `json:"state"` + Tags string `json:"tags"` + Vlan string `json:"vlan"` + Zoneid string `json:"zoneid"` +} + +type CreateServiceInstanceParams struct { + p map[string]interface{} +} + +func (p *CreateServiceInstanceParams) toURLValues() url.Values { + u := url.Values{} + if p.p == nil { + return u + } + if v, found := p.p["account"]; found { + u.Set("account", v.(string)) + } + if v, found := p.p["domainid"]; found { + u.Set("domainid", v.(string)) + } + if v, found := p.p["leftnetworkid"]; found { + u.Set("leftnetworkid", v.(string)) + } + if v, found := p.p["name"]; found { + u.Set("name", v.(string)) + } + if v, found := p.p["projectid"]; found { + u.Set("projectid", v.(string)) + } + if v, found := p.p["rightnetworkid"]; found { + u.Set("rightnetworkid", v.(string)) + } + if v, found := p.p["serviceofferingid"]; found { + u.Set("serviceofferingid", v.(string)) + } + if v, found := p.p["templateid"]; found { + u.Set("templateid", v.(string)) + } + if v, found := p.p["zoneid"]; found { + u.Set("zoneid", v.(string)) + } + return u +} + +func (p *CreateServiceInstanceParams) SetAccount(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["account"] = v + return +} + +func (p *CreateServiceInstanceParams) SetDomainid(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["domainid"] = v + return +} + +func (p *CreateServiceInstanceParams) SetLeftnetworkid(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["leftnetworkid"] = v + return +} + +func (p *CreateServiceInstanceParams) SetName(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["name"] = v + return +} + +func (p *CreateServiceInstanceParams) SetProjectid(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["projectid"] = v + return +} + +func (p *CreateServiceInstanceParams) SetRightnetworkid(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["rightnetworkid"] = v + return +} + +func (p *CreateServiceInstanceParams) SetServiceofferingid(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["serviceofferingid"] = v + return +} + +func (p *CreateServiceInstanceParams) SetTemplateid(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["templateid"] = v + return +} + +func (p *CreateServiceInstanceParams) SetZoneid(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["zoneid"] = v + return +} + +// You should always use this function to get a new CreateServiceInstanceParams instance, +// as then you are sure you have configured all required params +func (s *NetworkService) NewCreateServiceInstanceParams(leftnetworkid string, name string, rightnetworkid string, serviceofferingid string, templateid string, zoneid string) *CreateServiceInstanceParams { + p := &CreateServiceInstanceParams{} + p.p = make(map[string]interface{}) + p.p["leftnetworkid"] = leftnetworkid + p.p["name"] = name + p.p["rightnetworkid"] = rightnetworkid + p.p["serviceofferingid"] = serviceofferingid + p.p["templateid"] = templateid + p.p["zoneid"] = zoneid + return p +} + +// Creates a system virtual-machine that implements network services +func (s *NetworkService) CreateServiceInstance(p *CreateServiceInstanceParams) (*CreateServiceInstanceResponse, error) { + resp, err := s.cs.newRequest("createServiceInstance", p.toURLValues()) + if err != nil { + return nil, err + } + + var r CreateServiceInstanceResponse + if err := json.Unmarshal(resp, &r); err != nil { + return nil, err + } + + // If we have a async client, we need to wait for the async result + if s.cs.async { + b, err := s.cs.GetAsyncJobResult(r.JobID, s.cs.timeout) + if err != nil { + if err == AsyncTimeoutErr { + return &r, err + } + return nil, err + } + + b, err = getRawValue(b) + if err != nil { + return nil, err + } + + if err := json.Unmarshal(b, &r); err != nil { + return nil, err + } + } + + return &r, nil +} + +type CreateServiceInstanceResponse struct { + JobID string `json:"jobid"` + Account string `json:"account"` + Displayname string `json:"displayname"` + Domain string `json:"domain"` + Domainid string `json:"domainid"` + Id string `json:"id"` + Name string `json:"name"` + Project string `json:"project"` + Projectid string `json:"projectid"` +} + +type CreateStorageNetworkIpRangeParams struct { + p map[string]interface{} +} + +func (p *CreateStorageNetworkIpRangeParams) toURLValues() url.Values { + u := url.Values{} + if p.p == nil { + return u + } + if v, found := p.p["endip"]; found { + u.Set("endip", v.(string)) + } + if v, found := p.p["gateway"]; found { + u.Set("gateway", v.(string)) + } + if v, found := p.p["netmask"]; found { + u.Set("netmask", v.(string)) + } + if v, found := p.p["podid"]; found { + u.Set("podid", v.(string)) + } + if v, found := p.p["startip"]; found { + u.Set("startip", v.(string)) + } + if v, found := p.p["vlan"]; found { + vv := strconv.Itoa(v.(int)) + u.Set("vlan", vv) + } + return u +} + +func (p *CreateStorageNetworkIpRangeParams) SetEndip(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["endip"] = v + return +} + +func (p *CreateStorageNetworkIpRangeParams) SetGateway(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["gateway"] = v + return +} + +func (p *CreateStorageNetworkIpRangeParams) SetNetmask(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["netmask"] = v + return +} + +func (p *CreateStorageNetworkIpRangeParams) SetPodid(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["podid"] = v + return +} + +func (p *CreateStorageNetworkIpRangeParams) SetStartip(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["startip"] = v + return +} + +func (p *CreateStorageNetworkIpRangeParams) SetVlan(v int) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["vlan"] = v + return +} + +// You should always use this function to get a new CreateStorageNetworkIpRangeParams instance, +// as then you are sure you have configured all required params +func (s *NetworkService) NewCreateStorageNetworkIpRangeParams(gateway string, netmask string, podid string, startip string) *CreateStorageNetworkIpRangeParams { + p := &CreateStorageNetworkIpRangeParams{} + p.p = make(map[string]interface{}) + p.p["gateway"] = gateway + p.p["netmask"] = netmask + p.p["podid"] = podid + p.p["startip"] = startip + return p +} + +// Creates a Storage network IP range. +func (s *NetworkService) CreateStorageNetworkIpRange(p *CreateStorageNetworkIpRangeParams) (*CreateStorageNetworkIpRangeResponse, error) { + resp, err := s.cs.newRequest("createStorageNetworkIpRange", p.toURLValues()) + if err != nil { + return nil, err + } + + var r CreateStorageNetworkIpRangeResponse + if err := json.Unmarshal(resp, &r); err != nil { + return nil, err + } + + // If we have a async client, we need to wait for the async result + if s.cs.async { + b, err := s.cs.GetAsyncJobResult(r.JobID, s.cs.timeout) + if err != nil { + if err == AsyncTimeoutErr { + return &r, err + } + return nil, err + } + + b, err = getRawValue(b) + if err != nil { + return nil, err + } + + if err := json.Unmarshal(b, &r); err != nil { + return nil, err + } + } + + return &r, nil +} + +type CreateStorageNetworkIpRangeResponse struct { + JobID string `json:"jobid"` + Endip string `json:"endip"` + Gateway string `json:"gateway"` + Id string `json:"id"` + Netmask string `json:"netmask"` + Networkid string `json:"networkid"` + Podid string `json:"podid"` + Startip string `json:"startip"` + Vlan int `json:"vlan"` + Zoneid string `json:"zoneid"` +} + +type DedicatePublicIpRangeParams struct { + p map[string]interface{} +} + +func (p *DedicatePublicIpRangeParams) toURLValues() url.Values { + u := url.Values{} + if p.p == nil { + return u + } + if v, found := p.p["account"]; found { + u.Set("account", v.(string)) + } + if v, found := p.p["domainid"]; found { + u.Set("domainid", v.(string)) + } + if v, found := p.p["id"]; found { + u.Set("id", v.(string)) + } + if v, found := p.p["projectid"]; found { + u.Set("projectid", v.(string)) + } + return u +} + +func (p *DedicatePublicIpRangeParams) SetAccount(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["account"] = v + return +} + +func (p *DedicatePublicIpRangeParams) SetDomainid(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["domainid"] = v + return +} + +func (p *DedicatePublicIpRangeParams) SetId(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["id"] = v + return +} + +func (p *DedicatePublicIpRangeParams) SetProjectid(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["projectid"] = v + return +} + +// You should always use this function to get a new DedicatePublicIpRangeParams instance, +// as then you are sure you have configured all required params +func (s *NetworkService) NewDedicatePublicIpRangeParams(domainid string, id string) *DedicatePublicIpRangeParams { + p := &DedicatePublicIpRangeParams{} + p.p = make(map[string]interface{}) + p.p["domainid"] = domainid + p.p["id"] = id + return p +} + +// Dedicates a Public IP range to an account +func (s *NetworkService) DedicatePublicIpRange(p *DedicatePublicIpRangeParams) (*DedicatePublicIpRangeResponse, error) { + resp, err := s.cs.newRequest("dedicatePublicIpRange", p.toURLValues()) + if err != nil { + return nil, err + } + + var r DedicatePublicIpRangeResponse + if err := json.Unmarshal(resp, &r); err != nil { + return nil, err + } + + return &r, nil +} + +type DedicatePublicIpRangeResponse struct { + Account string `json:"account"` + Description string `json:"description"` + Domain string `json:"domain"` + Domainid string `json:"domainid"` + Endip string `json:"endip"` + Endipv6 string `json:"endipv6"` + Forsystemvms bool `json:"forsystemvms"` + Forvirtualnetwork bool `json:"forvirtualnetwork"` + Gateway string `json:"gateway"` + Id string `json:"id"` + Ip6cidr string `json:"ip6cidr"` + Ip6gateway string `json:"ip6gateway"` + Netmask string `json:"netmask"` + Networkid string `json:"networkid"` + Physicalnetworkid string `json:"physicalnetworkid"` + Podid string `json:"podid"` + Podname string `json:"podname"` + Project string `json:"project"` + Projectid string `json:"projectid"` + Startip string `json:"startip"` + Startipv6 string `json:"startipv6"` + Vlan string `json:"vlan"` + Zoneid string `json:"zoneid"` } type DeleteNetworkParams struct { @@ -636,13 +1305,726 @@ func (s *NetworkService) DeleteNetwork(p *DeleteNetworkParams) (*DeleteNetworkRe return nil, err } } + return &r, nil } type DeleteNetworkResponse struct { - JobID string `json:"jobid,omitempty"` - Displaytext string `json:"displaytext,omitempty"` - Success bool `json:"success,omitempty"` + JobID string `json:"jobid"` + Displaytext string `json:"displaytext"` + Success bool `json:"success"` +} + +type DeleteNetworkServiceProviderParams struct { + p map[string]interface{} +} + +func (p *DeleteNetworkServiceProviderParams) toURLValues() url.Values { + u := url.Values{} + if p.p == nil { + return u + } + if v, found := p.p["id"]; found { + u.Set("id", v.(string)) + } + return u +} + +func (p *DeleteNetworkServiceProviderParams) SetId(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["id"] = v + return +} + +// You should always use this function to get a new DeleteNetworkServiceProviderParams instance, +// as then you are sure you have configured all required params +func (s *NetworkService) NewDeleteNetworkServiceProviderParams(id string) *DeleteNetworkServiceProviderParams { + p := &DeleteNetworkServiceProviderParams{} + p.p = make(map[string]interface{}) + p.p["id"] = id + return p +} + +// Deletes a Network Service Provider. +func (s *NetworkService) DeleteNetworkServiceProvider(p *DeleteNetworkServiceProviderParams) (*DeleteNetworkServiceProviderResponse, error) { + resp, err := s.cs.newRequest("deleteNetworkServiceProvider", p.toURLValues()) + if err != nil { + return nil, err + } + + var r DeleteNetworkServiceProviderResponse + if err := json.Unmarshal(resp, &r); err != nil { + return nil, err + } + + // If we have a async client, we need to wait for the async result + if s.cs.async { + b, err := s.cs.GetAsyncJobResult(r.JobID, s.cs.timeout) + if err != nil { + if err == AsyncTimeoutErr { + return &r, err + } + return nil, err + } + + if err := json.Unmarshal(b, &r); err != nil { + return nil, err + } + } + + return &r, nil +} + +type DeleteNetworkServiceProviderResponse struct { + JobID string `json:"jobid"` + Displaytext string `json:"displaytext"` + Success bool `json:"success"` +} + +type DeleteOpenDaylightControllerParams struct { + p map[string]interface{} +} + +func (p *DeleteOpenDaylightControllerParams) toURLValues() url.Values { + u := url.Values{} + if p.p == nil { + return u + } + if v, found := p.p["id"]; found { + u.Set("id", v.(string)) + } + return u +} + +func (p *DeleteOpenDaylightControllerParams) SetId(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["id"] = v + return +} + +// You should always use this function to get a new DeleteOpenDaylightControllerParams instance, +// as then you are sure you have configured all required params +func (s *NetworkService) NewDeleteOpenDaylightControllerParams(id string) *DeleteOpenDaylightControllerParams { + p := &DeleteOpenDaylightControllerParams{} + p.p = make(map[string]interface{}) + p.p["id"] = id + return p +} + +// Removes an OpenDyalight controler +func (s *NetworkService) DeleteOpenDaylightController(p *DeleteOpenDaylightControllerParams) (*DeleteOpenDaylightControllerResponse, error) { + resp, err := s.cs.newRequest("deleteOpenDaylightController", p.toURLValues()) + if err != nil { + return nil, err + } + + var r DeleteOpenDaylightControllerResponse + if err := json.Unmarshal(resp, &r); err != nil { + return nil, err + } + + // If we have a async client, we need to wait for the async result + if s.cs.async { + b, err := s.cs.GetAsyncJobResult(r.JobID, s.cs.timeout) + if err != nil { + if err == AsyncTimeoutErr { + return &r, err + } + return nil, err + } + + b, err = getRawValue(b) + if err != nil { + return nil, err + } + + if err := json.Unmarshal(b, &r); err != nil { + return nil, err + } + } + + return &r, nil +} + +type DeleteOpenDaylightControllerResponse struct { + JobID string `json:"jobid"` + Id string `json:"id"` + Name string `json:"name"` + Physicalnetworkid string `json:"physicalnetworkid"` + Url string `json:"url"` + Username string `json:"username"` +} + +type DeletePhysicalNetworkParams struct { + p map[string]interface{} +} + +func (p *DeletePhysicalNetworkParams) toURLValues() url.Values { + u := url.Values{} + if p.p == nil { + return u + } + if v, found := p.p["id"]; found { + u.Set("id", v.(string)) + } + return u +} + +func (p *DeletePhysicalNetworkParams) SetId(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["id"] = v + return +} + +// You should always use this function to get a new DeletePhysicalNetworkParams instance, +// as then you are sure you have configured all required params +func (s *NetworkService) NewDeletePhysicalNetworkParams(id string) *DeletePhysicalNetworkParams { + p := &DeletePhysicalNetworkParams{} + p.p = make(map[string]interface{}) + p.p["id"] = id + return p +} + +// Deletes a Physical Network. +func (s *NetworkService) DeletePhysicalNetwork(p *DeletePhysicalNetworkParams) (*DeletePhysicalNetworkResponse, error) { + resp, err := s.cs.newRequest("deletePhysicalNetwork", p.toURLValues()) + if err != nil { + return nil, err + } + + var r DeletePhysicalNetworkResponse + if err := json.Unmarshal(resp, &r); err != nil { + return nil, err + } + + // If we have a async client, we need to wait for the async result + if s.cs.async { + b, err := s.cs.GetAsyncJobResult(r.JobID, s.cs.timeout) + if err != nil { + if err == AsyncTimeoutErr { + return &r, err + } + return nil, err + } + + if err := json.Unmarshal(b, &r); err != nil { + return nil, err + } + } + + return &r, nil +} + +type DeletePhysicalNetworkResponse struct { + JobID string `json:"jobid"` + Displaytext string `json:"displaytext"` + Success bool `json:"success"` +} + +type DeleteStorageNetworkIpRangeParams struct { + p map[string]interface{} +} + +func (p *DeleteStorageNetworkIpRangeParams) toURLValues() url.Values { + u := url.Values{} + if p.p == nil { + return u + } + if v, found := p.p["id"]; found { + u.Set("id", v.(string)) + } + return u +} + +func (p *DeleteStorageNetworkIpRangeParams) SetId(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["id"] = v + return +} + +// You should always use this function to get a new DeleteStorageNetworkIpRangeParams instance, +// as then you are sure you have configured all required params +func (s *NetworkService) NewDeleteStorageNetworkIpRangeParams(id string) *DeleteStorageNetworkIpRangeParams { + p := &DeleteStorageNetworkIpRangeParams{} + p.p = make(map[string]interface{}) + p.p["id"] = id + return p +} + +// Deletes a storage network IP Range. +func (s *NetworkService) DeleteStorageNetworkIpRange(p *DeleteStorageNetworkIpRangeParams) (*DeleteStorageNetworkIpRangeResponse, error) { + resp, err := s.cs.newRequest("deleteStorageNetworkIpRange", p.toURLValues()) + if err != nil { + return nil, err + } + + var r DeleteStorageNetworkIpRangeResponse + if err := json.Unmarshal(resp, &r); err != nil { + return nil, err + } + + // If we have a async client, we need to wait for the async result + if s.cs.async { + b, err := s.cs.GetAsyncJobResult(r.JobID, s.cs.timeout) + if err != nil { + if err == AsyncTimeoutErr { + return &r, err + } + return nil, err + } + + if err := json.Unmarshal(b, &r); err != nil { + return nil, err + } + } + + return &r, nil +} + +type DeleteStorageNetworkIpRangeResponse struct { + JobID string `json:"jobid"` + Displaytext string `json:"displaytext"` + Success bool `json:"success"` +} + +type ListNetscalerLoadBalancerNetworksParams struct { + p map[string]interface{} +} + +func (p *ListNetscalerLoadBalancerNetworksParams) toURLValues() url.Values { + u := url.Values{} + if p.p == nil { + return u + } + if v, found := p.p["keyword"]; found { + u.Set("keyword", v.(string)) + } + if v, found := p.p["lbdeviceid"]; found { + u.Set("lbdeviceid", v.(string)) + } + if v, found := p.p["page"]; found { + vv := strconv.Itoa(v.(int)) + u.Set("page", vv) + } + if v, found := p.p["pagesize"]; found { + vv := strconv.Itoa(v.(int)) + u.Set("pagesize", vv) + } + return u +} + +func (p *ListNetscalerLoadBalancerNetworksParams) SetKeyword(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["keyword"] = v + return +} + +func (p *ListNetscalerLoadBalancerNetworksParams) SetLbdeviceid(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["lbdeviceid"] = v + return +} + +func (p *ListNetscalerLoadBalancerNetworksParams) SetPage(v int) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["page"] = v + return +} + +func (p *ListNetscalerLoadBalancerNetworksParams) SetPagesize(v int) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["pagesize"] = v + return +} + +// You should always use this function to get a new ListNetscalerLoadBalancerNetworksParams instance, +// as then you are sure you have configured all required params +func (s *NetworkService) NewListNetscalerLoadBalancerNetworksParams(lbdeviceid string) *ListNetscalerLoadBalancerNetworksParams { + p := &ListNetscalerLoadBalancerNetworksParams{} + p.p = make(map[string]interface{}) + p.p["lbdeviceid"] = lbdeviceid + return p +} + +// This is a courtesy helper function, which in some cases may not work as expected! +func (s *NetworkService) GetNetscalerLoadBalancerNetworkID(keyword string, lbdeviceid string, opts ...OptionFunc) (string, int, error) { + p := &ListNetscalerLoadBalancerNetworksParams{} + p.p = make(map[string]interface{}) + + p.p["keyword"] = keyword + p.p["lbdeviceid"] = lbdeviceid + + for _, fn := range append(s.cs.options, opts...) { + if err := fn(s.cs, p); err != nil { + return "", -1, err + } + } + + l, err := s.ListNetscalerLoadBalancerNetworks(p) + if err != nil { + return "", -1, err + } + + if l.Count == 0 { + return "", l.Count, fmt.Errorf("No match found for %s: %+v", keyword, l) + } + + if l.Count == 1 { + return l.NetscalerLoadBalancerNetworks[0].Id, l.Count, nil + } + + if l.Count > 1 { + for _, v := range l.NetscalerLoadBalancerNetworks { + if v.Name == keyword { + return v.Id, l.Count, nil + } + } + } + return "", l.Count, fmt.Errorf("Could not find an exact match for %s: %+v", keyword, l) +} + +// lists network that are using a netscaler load balancer device +func (s *NetworkService) ListNetscalerLoadBalancerNetworks(p *ListNetscalerLoadBalancerNetworksParams) (*ListNetscalerLoadBalancerNetworksResponse, error) { + resp, err := s.cs.newRequest("listNetscalerLoadBalancerNetworks", p.toURLValues()) + if err != nil { + return nil, err + } + + var r ListNetscalerLoadBalancerNetworksResponse + if err := json.Unmarshal(resp, &r); err != nil { + return nil, err + } + + return &r, nil +} + +type ListNetscalerLoadBalancerNetworksResponse struct { + Count int `json:"count"` + NetscalerLoadBalancerNetworks []*NetscalerLoadBalancerNetwork `json:"netscalerloadbalancernetwork"` +} + +type NetscalerLoadBalancerNetwork struct { + Account string `json:"account"` + Aclid string `json:"aclid"` + Acltype string `json:"acltype"` + Broadcastdomaintype string `json:"broadcastdomaintype"` + Broadcasturi string `json:"broadcasturi"` + Canusefordeploy bool `json:"canusefordeploy"` + Cidr string `json:"cidr"` + Displaynetwork bool `json:"displaynetwork"` + Displaytext string `json:"displaytext"` + Dns1 string `json:"dns1"` + Dns2 string `json:"dns2"` + Domain string `json:"domain"` + Domainid string `json:"domainid"` + Externalid string `json:"externalid"` + Gateway string `json:"gateway"` + Id string `json:"id"` + Ip6cidr string `json:"ip6cidr"` + Ip6gateway string `json:"ip6gateway"` + Isdefault bool `json:"isdefault"` + Ispersistent bool `json:"ispersistent"` + Issystem bool `json:"issystem"` + Name string `json:"name"` + Netmask string `json:"netmask"` + Networkcidr string `json:"networkcidr"` + Networkdomain string `json:"networkdomain"` + Networkofferingavailability string `json:"networkofferingavailability"` + Networkofferingconservemode bool `json:"networkofferingconservemode"` + Networkofferingdisplaytext string `json:"networkofferingdisplaytext"` + Networkofferingid string `json:"networkofferingid"` + Networkofferingname string `json:"networkofferingname"` + Physicalnetworkid string `json:"physicalnetworkid"` + Project string `json:"project"` + Projectid string `json:"projectid"` + Redundantrouter bool `json:"redundantrouter"` + Related string `json:"related"` + Reservediprange string `json:"reservediprange"` + Restartrequired bool `json:"restartrequired"` + Service []NetscalerLoadBalancerNetworkService `json:"service"` + Specifyipranges bool `json:"specifyipranges"` + State string `json:"state"` + Strechedl2subnet bool `json:"strechedl2subnet"` + Subdomainaccess bool `json:"subdomainaccess"` + Tags []Tags `json:"tags"` + Traffictype string `json:"traffictype"` + Type string `json:"type"` + Vlan string `json:"vlan"` + Vpcid string `json:"vpcid"` + Zoneid string `json:"zoneid"` + Zonename string `json:"zonename"` + Zonesnetworkspans []interface{} `json:"zonesnetworkspans"` +} + +type NetscalerLoadBalancerNetworkService struct { + Capability []NetscalerLoadBalancerNetworkServiceCapability `json:"capability"` + Name string `json:"name"` + Provider []NetscalerLoadBalancerNetworkServiceProvider `json:"provider"` +} + +type NetscalerLoadBalancerNetworkServiceProvider struct { + Canenableindividualservice bool `json:"canenableindividualservice"` + Destinationphysicalnetworkid string `json:"destinationphysicalnetworkid"` + Id string `json:"id"` + Name string `json:"name"` + Physicalnetworkid string `json:"physicalnetworkid"` + Servicelist []string `json:"servicelist"` + State string `json:"state"` +} + +type NetscalerLoadBalancerNetworkServiceCapability struct { + Canchooseservicecapability bool `json:"canchooseservicecapability"` + Name string `json:"name"` + Value string `json:"value"` +} + +type ListNetworkIsolationMethodsParams struct { + p map[string]interface{} +} + +func (p *ListNetworkIsolationMethodsParams) toURLValues() url.Values { + u := url.Values{} + if p.p == nil { + return u + } + if v, found := p.p["keyword"]; found { + u.Set("keyword", v.(string)) + } + if v, found := p.p["page"]; found { + vv := strconv.Itoa(v.(int)) + u.Set("page", vv) + } + if v, found := p.p["pagesize"]; found { + vv := strconv.Itoa(v.(int)) + u.Set("pagesize", vv) + } + return u +} + +func (p *ListNetworkIsolationMethodsParams) SetKeyword(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["keyword"] = v + return +} + +func (p *ListNetworkIsolationMethodsParams) SetPage(v int) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["page"] = v + return +} + +func (p *ListNetworkIsolationMethodsParams) SetPagesize(v int) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["pagesize"] = v + return +} + +// You should always use this function to get a new ListNetworkIsolationMethodsParams instance, +// as then you are sure you have configured all required params +func (s *NetworkService) NewListNetworkIsolationMethodsParams() *ListNetworkIsolationMethodsParams { + p := &ListNetworkIsolationMethodsParams{} + p.p = make(map[string]interface{}) + return p +} + +// Lists supported methods of network isolation +func (s *NetworkService) ListNetworkIsolationMethods(p *ListNetworkIsolationMethodsParams) (*ListNetworkIsolationMethodsResponse, error) { + resp, err := s.cs.newRequest("listNetworkIsolationMethods", p.toURLValues()) + if err != nil { + return nil, err + } + + var r ListNetworkIsolationMethodsResponse + if err := json.Unmarshal(resp, &r); err != nil { + return nil, err + } + + return &r, nil +} + +type ListNetworkIsolationMethodsResponse struct { + Count int `json:"count"` + NetworkIsolationMethods []*NetworkIsolationMethod `json:"networkisolationmethod"` +} + +type NetworkIsolationMethod struct { + Name string `json:"name"` +} + +type ListNetworkServiceProvidersParams struct { + p map[string]interface{} +} + +func (p *ListNetworkServiceProvidersParams) toURLValues() url.Values { + u := url.Values{} + if p.p == nil { + return u + } + if v, found := p.p["keyword"]; found { + u.Set("keyword", v.(string)) + } + if v, found := p.p["name"]; found { + u.Set("name", v.(string)) + } + if v, found := p.p["page"]; found { + vv := strconv.Itoa(v.(int)) + u.Set("page", vv) + } + if v, found := p.p["pagesize"]; found { + vv := strconv.Itoa(v.(int)) + u.Set("pagesize", vv) + } + if v, found := p.p["physicalnetworkid"]; found { + u.Set("physicalnetworkid", v.(string)) + } + if v, found := p.p["state"]; found { + u.Set("state", v.(string)) + } + return u +} + +func (p *ListNetworkServiceProvidersParams) SetKeyword(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["keyword"] = v + return +} + +func (p *ListNetworkServiceProvidersParams) SetName(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["name"] = v + return +} + +func (p *ListNetworkServiceProvidersParams) SetPage(v int) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["page"] = v + return +} + +func (p *ListNetworkServiceProvidersParams) SetPagesize(v int) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["pagesize"] = v + return +} + +func (p *ListNetworkServiceProvidersParams) SetPhysicalnetworkid(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["physicalnetworkid"] = v + return +} + +func (p *ListNetworkServiceProvidersParams) SetState(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["state"] = v + return +} + +// You should always use this function to get a new ListNetworkServiceProvidersParams instance, +// as then you are sure you have configured all required params +func (s *NetworkService) NewListNetworkServiceProvidersParams() *ListNetworkServiceProvidersParams { + p := &ListNetworkServiceProvidersParams{} + p.p = make(map[string]interface{}) + return p +} + +// This is a courtesy helper function, which in some cases may not work as expected! +func (s *NetworkService) GetNetworkServiceProviderID(name string, opts ...OptionFunc) (string, int, error) { + p := &ListNetworkServiceProvidersParams{} + p.p = make(map[string]interface{}) + + p.p["name"] = name + + for _, fn := range append(s.cs.options, opts...) { + if err := fn(s.cs, p); err != nil { + return "", -1, err + } + } + + l, err := s.ListNetworkServiceProviders(p) + if err != nil { + return "", -1, err + } + + if l.Count == 0 { + return "", l.Count, fmt.Errorf("No match found for %s: %+v", name, l) + } + + if l.Count == 1 { + return l.NetworkServiceProviders[0].Id, l.Count, nil + } + + if l.Count > 1 { + for _, v := range l.NetworkServiceProviders { + if v.Name == name { + return v.Id, l.Count, nil + } + } + } + return "", l.Count, fmt.Errorf("Could not find an exact match for %s: %+v", name, l) +} + +// Lists network serviceproviders for a given physical network. +func (s *NetworkService) ListNetworkServiceProviders(p *ListNetworkServiceProvidersParams) (*ListNetworkServiceProvidersResponse, error) { + resp, err := s.cs.newRequest("listNetworkServiceProviders", p.toURLValues()) + if err != nil { + return nil, err + } + + var r ListNetworkServiceProvidersResponse + if err := json.Unmarshal(resp, &r); err != nil { + return nil, err + } + + return &r, nil +} + +type ListNetworkServiceProvidersResponse struct { + Count int `json:"count"` + NetworkServiceProviders []*NetworkServiceProvider `json:"networkserviceprovider"` +} + +type NetworkServiceProvider struct { + Canenableindividualservice bool `json:"canenableindividualservice"` + Destinationphysicalnetworkid string `json:"destinationphysicalnetworkid"` + Id string `json:"id"` + Name string `json:"name"` + Physicalnetworkid string `json:"physicalnetworkid"` + Servicelist []string `json:"servicelist"` + State string `json:"state"` } type ListNetworksParams struct { @@ -941,7 +2323,7 @@ func (s *NetworkService) GetNetworkID(keyword string, opts ...OptionFunc) (strin p.p["keyword"] = keyword - for _, fn := range opts { + for _, fn := range append(s.cs.options, opts...) { if err := fn(s.cs, p); err != nil { return "", -1, err } @@ -991,7 +2373,7 @@ func (s *NetworkService) GetNetworkByID(id string, opts ...OptionFunc) (*Network p.p["id"] = id - for _, fn := range opts { + for _, fn := range append(s.cs.options, opts...) { if err := fn(s.cs, p); err != nil { return nil, -1, err } @@ -1028,6 +2410,7 @@ func (s *NetworkService) ListNetworks(p *ListNetworksParams) (*ListNetworksRespo if err := json.Unmarshal(resp, &r); err != nil { return nil, err } + return &r, nil } @@ -1037,606 +2420,284 @@ type ListNetworksResponse struct { } type Network struct { - Account string `json:"account,omitempty"` - Aclid string `json:"aclid,omitempty"` - Acltype string `json:"acltype,omitempty"` - Broadcastdomaintype string `json:"broadcastdomaintype,omitempty"` - Broadcasturi string `json:"broadcasturi,omitempty"` - Canusefordeploy bool `json:"canusefordeploy,omitempty"` - Cidr string `json:"cidr,omitempty"` - Displaynetwork bool `json:"displaynetwork,omitempty"` - Displaytext string `json:"displaytext,omitempty"` - Dns1 string `json:"dns1,omitempty"` - Dns2 string `json:"dns2,omitempty"` - Domain string `json:"domain,omitempty"` - Domainid string `json:"domainid,omitempty"` - Gateway string `json:"gateway,omitempty"` - Id string `json:"id,omitempty"` - Ip6cidr string `json:"ip6cidr,omitempty"` - Ip6gateway string `json:"ip6gateway,omitempty"` - Isdefault bool `json:"isdefault,omitempty"` - Ispersistent bool `json:"ispersistent,omitempty"` - Issystem bool `json:"issystem,omitempty"` - Name string `json:"name,omitempty"` - Netmask string `json:"netmask,omitempty"` - Networkcidr string `json:"networkcidr,omitempty"` - Networkdomain string `json:"networkdomain,omitempty"` - Networkofferingavailability string `json:"networkofferingavailability,omitempty"` - Networkofferingconservemode bool `json:"networkofferingconservemode,omitempty"` - Networkofferingdisplaytext string `json:"networkofferingdisplaytext,omitempty"` - Networkofferingid string `json:"networkofferingid,omitempty"` - Networkofferingname string `json:"networkofferingname,omitempty"` - Physicalnetworkid string `json:"physicalnetworkid,omitempty"` - Project string `json:"project,omitempty"` - Projectid string `json:"projectid,omitempty"` - Related string `json:"related,omitempty"` - Reservediprange string `json:"reservediprange,omitempty"` - Restartrequired bool `json:"restartrequired,omitempty"` - Service []struct { - Capability []struct { - Canchooseservicecapability bool `json:"canchooseservicecapability,omitempty"` - Name string `json:"name,omitempty"` - Value string `json:"value,omitempty"` - } `json:"capability,omitempty"` - Name string `json:"name,omitempty"` - Provider []struct { - Canenableindividualservice bool `json:"canenableindividualservice,omitempty"` - Destinationphysicalnetworkid string `json:"destinationphysicalnetworkid,omitempty"` - Id string `json:"id,omitempty"` - Name string `json:"name,omitempty"` - Physicalnetworkid string `json:"physicalnetworkid,omitempty"` - Servicelist []string `json:"servicelist,omitempty"` - State string `json:"state,omitempty"` - } `json:"provider,omitempty"` - } `json:"service,omitempty"` - Specifyipranges bool `json:"specifyipranges,omitempty"` - State string `json:"state,omitempty"` - Strechedl2subnet bool `json:"strechedl2subnet,omitempty"` - Subdomainaccess bool `json:"subdomainaccess,omitempty"` - Tags []struct { - Account string `json:"account,omitempty"` - Customer string `json:"customer,omitempty"` - Domain string `json:"domain,omitempty"` - Domainid string `json:"domainid,omitempty"` - Key string `json:"key,omitempty"` - Project string `json:"project,omitempty"` - Projectid string `json:"projectid,omitempty"` - Resourceid string `json:"resourceid,omitempty"` - Resourcetype string `json:"resourcetype,omitempty"` - Value string `json:"value,omitempty"` - } `json:"tags,omitempty"` - Traffictype string `json:"traffictype,omitempty"` - Type string `json:"type,omitempty"` - Vlan string `json:"vlan,omitempty"` - Vpcid string `json:"vpcid,omitempty"` - Zoneid string `json:"zoneid,omitempty"` - Zonename string `json:"zonename,omitempty"` - Zonesnetworkspans []string `json:"zonesnetworkspans,omitempty"` + Account string `json:"account"` + Aclid string `json:"aclid"` + Acltype string `json:"acltype"` + Broadcastdomaintype string `json:"broadcastdomaintype"` + Broadcasturi string `json:"broadcasturi"` + Canusefordeploy bool `json:"canusefordeploy"` + Cidr string `json:"cidr"` + Displaynetwork bool `json:"displaynetwork"` + Displaytext string `json:"displaytext"` + Dns1 string `json:"dns1"` + Dns2 string `json:"dns2"` + Domain string `json:"domain"` + Domainid string `json:"domainid"` + Externalid string `json:"externalid"` + Gateway string `json:"gateway"` + Id string `json:"id"` + Ip6cidr string `json:"ip6cidr"` + Ip6gateway string `json:"ip6gateway"` + Isdefault bool `json:"isdefault"` + Ispersistent bool `json:"ispersistent"` + Issystem bool `json:"issystem"` + Name string `json:"name"` + Netmask string `json:"netmask"` + Networkcidr string `json:"networkcidr"` + Networkdomain string `json:"networkdomain"` + Networkofferingavailability string `json:"networkofferingavailability"` + Networkofferingconservemode bool `json:"networkofferingconservemode"` + Networkofferingdisplaytext string `json:"networkofferingdisplaytext"` + Networkofferingid string `json:"networkofferingid"` + Networkofferingname string `json:"networkofferingname"` + Physicalnetworkid string `json:"physicalnetworkid"` + Project string `json:"project"` + Projectid string `json:"projectid"` + Redundantrouter bool `json:"redundantrouter"` + Related string `json:"related"` + Reservediprange string `json:"reservediprange"` + Restartrequired bool `json:"restartrequired"` + Service []NetworkServiceInternal `json:"service"` + Specifyipranges bool `json:"specifyipranges"` + State string `json:"state"` + Strechedl2subnet bool `json:"strechedl2subnet"` + Subdomainaccess bool `json:"subdomainaccess"` + Tags []Tags `json:"tags"` + Traffictype string `json:"traffictype"` + Type string `json:"type"` + Vlan string `json:"vlan"` + Vpcid string `json:"vpcid"` + Zoneid string `json:"zoneid"` + Zonename string `json:"zonename"` + Zonesnetworkspans []interface{} `json:"zonesnetworkspans"` } -type RestartNetworkParams struct { +type NetworkServiceInternal struct { + Capability []NetworkServiceInternalCapability `json:"capability"` + Name string `json:"name"` + Provider []NetworkServiceInternalProvider `json:"provider"` +} + +type NetworkServiceInternalProvider struct { + Canenableindividualservice bool `json:"canenableindividualservice"` + Destinationphysicalnetworkid string `json:"destinationphysicalnetworkid"` + Id string `json:"id"` + Name string `json:"name"` + Physicalnetworkid string `json:"physicalnetworkid"` + Servicelist []string `json:"servicelist"` + State string `json:"state"` +} + +type NetworkServiceInternalCapability struct { + Canchooseservicecapability bool `json:"canchooseservicecapability"` + Name string `json:"name"` + Value string `json:"value"` +} + +type ListNiciraNvpDeviceNetworksParams struct { p map[string]interface{} } -func (p *RestartNetworkParams) toURLValues() url.Values { +func (p *ListNiciraNvpDeviceNetworksParams) toURLValues() url.Values { u := url.Values{} if p.p == nil { return u } - if v, found := p.p["cleanup"]; found { - vv := strconv.FormatBool(v.(bool)) - u.Set("cleanup", vv) + if v, found := p.p["keyword"]; found { + u.Set("keyword", v.(string)) } - if v, found := p.p["id"]; found { - u.Set("id", v.(string)) + if v, found := p.p["nvpdeviceid"]; found { + u.Set("nvpdeviceid", v.(string)) + } + if v, found := p.p["page"]; found { + vv := strconv.Itoa(v.(int)) + u.Set("page", vv) + } + if v, found := p.p["pagesize"]; found { + vv := strconv.Itoa(v.(int)) + u.Set("pagesize", vv) } return u } -func (p *RestartNetworkParams) SetCleanup(v bool) { +func (p *ListNiciraNvpDeviceNetworksParams) SetKeyword(v string) { if p.p == nil { p.p = make(map[string]interface{}) } - p.p["cleanup"] = v + p.p["keyword"] = v return } -func (p *RestartNetworkParams) SetId(v string) { +func (p *ListNiciraNvpDeviceNetworksParams) SetNvpdeviceid(v string) { if p.p == nil { p.p = make(map[string]interface{}) } - p.p["id"] = v + p.p["nvpdeviceid"] = v return } -// You should always use this function to get a new RestartNetworkParams instance, +func (p *ListNiciraNvpDeviceNetworksParams) SetPage(v int) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["page"] = v + return +} + +func (p *ListNiciraNvpDeviceNetworksParams) SetPagesize(v int) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["pagesize"] = v + return +} + +// You should always use this function to get a new ListNiciraNvpDeviceNetworksParams instance, // as then you are sure you have configured all required params -func (s *NetworkService) NewRestartNetworkParams(id string) *RestartNetworkParams { - p := &RestartNetworkParams{} +func (s *NetworkService) NewListNiciraNvpDeviceNetworksParams(nvpdeviceid string) *ListNiciraNvpDeviceNetworksParams { + p := &ListNiciraNvpDeviceNetworksParams{} p.p = make(map[string]interface{}) - p.p["id"] = id + p.p["nvpdeviceid"] = nvpdeviceid return p } -// Restarts the network; includes 1) restarting network elements - virtual routers, DHCP servers 2) reapplying all public IPs 3) reapplying loadBalancing/portForwarding rules -func (s *NetworkService) RestartNetwork(p *RestartNetworkParams) (*RestartNetworkResponse, error) { - resp, err := s.cs.newRequest("restartNetwork", p.toURLValues()) +// This is a courtesy helper function, which in some cases may not work as expected! +func (s *NetworkService) GetNiciraNvpDeviceNetworkID(keyword string, nvpdeviceid string, opts ...OptionFunc) (string, int, error) { + p := &ListNiciraNvpDeviceNetworksParams{} + p.p = make(map[string]interface{}) + + p.p["keyword"] = keyword + p.p["nvpdeviceid"] = nvpdeviceid + + for _, fn := range append(s.cs.options, opts...) { + if err := fn(s.cs, p); err != nil { + return "", -1, err + } + } + + l, err := s.ListNiciraNvpDeviceNetworks(p) + if err != nil { + return "", -1, err + } + + if l.Count == 0 { + return "", l.Count, fmt.Errorf("No match found for %s: %+v", keyword, l) + } + + if l.Count == 1 { + return l.NiciraNvpDeviceNetworks[0].Id, l.Count, nil + } + + if l.Count > 1 { + for _, v := range l.NiciraNvpDeviceNetworks { + if v.Name == keyword { + return v.Id, l.Count, nil + } + } + } + return "", l.Count, fmt.Errorf("Could not find an exact match for %s: %+v", keyword, l) +} + +// lists network that are using a nicira nvp device +func (s *NetworkService) ListNiciraNvpDeviceNetworks(p *ListNiciraNvpDeviceNetworksParams) (*ListNiciraNvpDeviceNetworksResponse, error) { + resp, err := s.cs.newRequest("listNiciraNvpDeviceNetworks", p.toURLValues()) if err != nil { return nil, err } - var r RestartNetworkResponse + var r ListNiciraNvpDeviceNetworksResponse if err := json.Unmarshal(resp, &r); err != nil { return nil, err } - // If we have a async client, we need to wait for the async result - if s.cs.async { - b, err := s.cs.GetAsyncJobResult(r.JobID, s.cs.timeout) - if err != nil { - if err == AsyncTimeoutErr { - return &r, err - } - return nil, err - } - - b, err = getRawValue(b) - if err != nil { - return nil, err - } - - if err := json.Unmarshal(b, &r); err != nil { - return nil, err - } - } return &r, nil } -type RestartNetworkResponse struct { - JobID string `json:"jobid,omitempty"` - Account string `json:"account,omitempty"` - Allocated string `json:"allocated,omitempty"` - Associatednetworkid string `json:"associatednetworkid,omitempty"` - Associatednetworkname string `json:"associatednetworkname,omitempty"` - Domain string `json:"domain,omitempty"` - Domainid string `json:"domainid,omitempty"` - Fordisplay bool `json:"fordisplay,omitempty"` - Forvirtualnetwork bool `json:"forvirtualnetwork,omitempty"` - Id string `json:"id,omitempty"` - Ipaddress string `json:"ipaddress,omitempty"` - Isportable bool `json:"isportable,omitempty"` - Issourcenat bool `json:"issourcenat,omitempty"` - Isstaticnat bool `json:"isstaticnat,omitempty"` - Issystem bool `json:"issystem,omitempty"` - Networkid string `json:"networkid,omitempty"` - Physicalnetworkid string `json:"physicalnetworkid,omitempty"` - Project string `json:"project,omitempty"` - Projectid string `json:"projectid,omitempty"` - Purpose string `json:"purpose,omitempty"` - State string `json:"state,omitempty"` - Tags []struct { - Account string `json:"account,omitempty"` - Customer string `json:"customer,omitempty"` - Domain string `json:"domain,omitempty"` - Domainid string `json:"domainid,omitempty"` - Key string `json:"key,omitempty"` - Project string `json:"project,omitempty"` - Projectid string `json:"projectid,omitempty"` - Resourceid string `json:"resourceid,omitempty"` - Resourcetype string `json:"resourcetype,omitempty"` - Value string `json:"value,omitempty"` - } `json:"tags,omitempty"` - Virtualmachinedisplayname string `json:"virtualmachinedisplayname,omitempty"` - Virtualmachineid string `json:"virtualmachineid,omitempty"` - Virtualmachinename string `json:"virtualmachinename,omitempty"` - Vlanid string `json:"vlanid,omitempty"` - Vlanname string `json:"vlanname,omitempty"` - Vmipaddress string `json:"vmipaddress,omitempty"` - Vpcid string `json:"vpcid,omitempty"` - Zoneid string `json:"zoneid,omitempty"` - Zonename string `json:"zonename,omitempty"` +type ListNiciraNvpDeviceNetworksResponse struct { + Count int `json:"count"` + NiciraNvpDeviceNetworks []*NiciraNvpDeviceNetwork `json:"niciranvpdevicenetwork"` } -type UpdateNetworkParams struct { +type NiciraNvpDeviceNetwork struct { + Account string `json:"account"` + Aclid string `json:"aclid"` + Acltype string `json:"acltype"` + Broadcastdomaintype string `json:"broadcastdomaintype"` + Broadcasturi string `json:"broadcasturi"` + Canusefordeploy bool `json:"canusefordeploy"` + Cidr string `json:"cidr"` + Displaynetwork bool `json:"displaynetwork"` + Displaytext string `json:"displaytext"` + Dns1 string `json:"dns1"` + Dns2 string `json:"dns2"` + Domain string `json:"domain"` + Domainid string `json:"domainid"` + Externalid string `json:"externalid"` + Gateway string `json:"gateway"` + Id string `json:"id"` + Ip6cidr string `json:"ip6cidr"` + Ip6gateway string `json:"ip6gateway"` + Isdefault bool `json:"isdefault"` + Ispersistent bool `json:"ispersistent"` + Issystem bool `json:"issystem"` + Name string `json:"name"` + Netmask string `json:"netmask"` + Networkcidr string `json:"networkcidr"` + Networkdomain string `json:"networkdomain"` + Networkofferingavailability string `json:"networkofferingavailability"` + Networkofferingconservemode bool `json:"networkofferingconservemode"` + Networkofferingdisplaytext string `json:"networkofferingdisplaytext"` + Networkofferingid string `json:"networkofferingid"` + Networkofferingname string `json:"networkofferingname"` + Physicalnetworkid string `json:"physicalnetworkid"` + Project string `json:"project"` + Projectid string `json:"projectid"` + Redundantrouter bool `json:"redundantrouter"` + Related string `json:"related"` + Reservediprange string `json:"reservediprange"` + Restartrequired bool `json:"restartrequired"` + Service []NiciraNvpDeviceNetworkService `json:"service"` + Specifyipranges bool `json:"specifyipranges"` + State string `json:"state"` + Strechedl2subnet bool `json:"strechedl2subnet"` + Subdomainaccess bool `json:"subdomainaccess"` + Tags []Tags `json:"tags"` + Traffictype string `json:"traffictype"` + Type string `json:"type"` + Vlan string `json:"vlan"` + Vpcid string `json:"vpcid"` + Zoneid string `json:"zoneid"` + Zonename string `json:"zonename"` + Zonesnetworkspans []interface{} `json:"zonesnetworkspans"` +} + +type NiciraNvpDeviceNetworkService struct { + Capability []NiciraNvpDeviceNetworkServiceCapability `json:"capability"` + Name string `json:"name"` + Provider []NiciraNvpDeviceNetworkServiceProvider `json:"provider"` +} + +type NiciraNvpDeviceNetworkServiceProvider struct { + Canenableindividualservice bool `json:"canenableindividualservice"` + Destinationphysicalnetworkid string `json:"destinationphysicalnetworkid"` + Id string `json:"id"` + Name string `json:"name"` + Physicalnetworkid string `json:"physicalnetworkid"` + Servicelist []string `json:"servicelist"` + State string `json:"state"` +} + +type NiciraNvpDeviceNetworkServiceCapability struct { + Canchooseservicecapability bool `json:"canchooseservicecapability"` + Name string `json:"name"` + Value string `json:"value"` +} + +type ListOpenDaylightControllersParams struct { p map[string]interface{} } -func (p *UpdateNetworkParams) toURLValues() url.Values { - u := url.Values{} - if p.p == nil { - return u - } - if v, found := p.p["changecidr"]; found { - vv := strconv.FormatBool(v.(bool)) - u.Set("changecidr", vv) - } - if v, found := p.p["customid"]; found { - u.Set("customid", v.(string)) - } - if v, found := p.p["displaynetwork"]; found { - vv := strconv.FormatBool(v.(bool)) - u.Set("displaynetwork", vv) - } - if v, found := p.p["displaytext"]; found { - u.Set("displaytext", v.(string)) - } - if v, found := p.p["guestvmcidr"]; found { - u.Set("guestvmcidr", v.(string)) - } - if v, found := p.p["id"]; found { - u.Set("id", v.(string)) - } - if v, found := p.p["name"]; found { - u.Set("name", v.(string)) - } - if v, found := p.p["networkdomain"]; found { - u.Set("networkdomain", v.(string)) - } - if v, found := p.p["networkofferingid"]; found { - u.Set("networkofferingid", v.(string)) - } - return u -} - -func (p *UpdateNetworkParams) SetChangecidr(v bool) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["changecidr"] = v - return -} - -func (p *UpdateNetworkParams) SetCustomid(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["customid"] = v - return -} - -func (p *UpdateNetworkParams) SetDisplaynetwork(v bool) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["displaynetwork"] = v - return -} - -func (p *UpdateNetworkParams) SetDisplaytext(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["displaytext"] = v - return -} - -func (p *UpdateNetworkParams) SetGuestvmcidr(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["guestvmcidr"] = v - return -} - -func (p *UpdateNetworkParams) SetId(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["id"] = v - return -} - -func (p *UpdateNetworkParams) SetName(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["name"] = v - return -} - -func (p *UpdateNetworkParams) SetNetworkdomain(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["networkdomain"] = v - return -} - -func (p *UpdateNetworkParams) SetNetworkofferingid(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["networkofferingid"] = v - return -} - -// You should always use this function to get a new UpdateNetworkParams instance, -// as then you are sure you have configured all required params -func (s *NetworkService) NewUpdateNetworkParams(id string) *UpdateNetworkParams { - p := &UpdateNetworkParams{} - p.p = make(map[string]interface{}) - p.p["id"] = id - return p -} - -// Updates a network -func (s *NetworkService) UpdateNetwork(p *UpdateNetworkParams) (*UpdateNetworkResponse, error) { - resp, err := s.cs.newRequest("updateNetwork", p.toURLValues()) - if err != nil { - return nil, err - } - - var r UpdateNetworkResponse - if err := json.Unmarshal(resp, &r); err != nil { - return nil, err - } - - // If we have a async client, we need to wait for the async result - if s.cs.async { - b, err := s.cs.GetAsyncJobResult(r.JobID, s.cs.timeout) - if err != nil { - if err == AsyncTimeoutErr { - return &r, err - } - return nil, err - } - - b, err = getRawValue(b) - if err != nil { - return nil, err - } - - if err := json.Unmarshal(b, &r); err != nil { - return nil, err - } - } - return &r, nil -} - -type UpdateNetworkResponse struct { - JobID string `json:"jobid,omitempty"` - Account string `json:"account,omitempty"` - Aclid string `json:"aclid,omitempty"` - Acltype string `json:"acltype,omitempty"` - Broadcastdomaintype string `json:"broadcastdomaintype,omitempty"` - Broadcasturi string `json:"broadcasturi,omitempty"` - Canusefordeploy bool `json:"canusefordeploy,omitempty"` - Cidr string `json:"cidr,omitempty"` - Displaynetwork bool `json:"displaynetwork,omitempty"` - Displaytext string `json:"displaytext,omitempty"` - Dns1 string `json:"dns1,omitempty"` - Dns2 string `json:"dns2,omitempty"` - Domain string `json:"domain,omitempty"` - Domainid string `json:"domainid,omitempty"` - Gateway string `json:"gateway,omitempty"` - Id string `json:"id,omitempty"` - Ip6cidr string `json:"ip6cidr,omitempty"` - Ip6gateway string `json:"ip6gateway,omitempty"` - Isdefault bool `json:"isdefault,omitempty"` - Ispersistent bool `json:"ispersistent,omitempty"` - Issystem bool `json:"issystem,omitempty"` - Name string `json:"name,omitempty"` - Netmask string `json:"netmask,omitempty"` - Networkcidr string `json:"networkcidr,omitempty"` - Networkdomain string `json:"networkdomain,omitempty"` - Networkofferingavailability string `json:"networkofferingavailability,omitempty"` - Networkofferingconservemode bool `json:"networkofferingconservemode,omitempty"` - Networkofferingdisplaytext string `json:"networkofferingdisplaytext,omitempty"` - Networkofferingid string `json:"networkofferingid,omitempty"` - Networkofferingname string `json:"networkofferingname,omitempty"` - Physicalnetworkid string `json:"physicalnetworkid,omitempty"` - Project string `json:"project,omitempty"` - Projectid string `json:"projectid,omitempty"` - Related string `json:"related,omitempty"` - Reservediprange string `json:"reservediprange,omitempty"` - Restartrequired bool `json:"restartrequired,omitempty"` - Service []struct { - Capability []struct { - Canchooseservicecapability bool `json:"canchooseservicecapability,omitempty"` - Name string `json:"name,omitempty"` - Value string `json:"value,omitempty"` - } `json:"capability,omitempty"` - Name string `json:"name,omitempty"` - Provider []struct { - Canenableindividualservice bool `json:"canenableindividualservice,omitempty"` - Destinationphysicalnetworkid string `json:"destinationphysicalnetworkid,omitempty"` - Id string `json:"id,omitempty"` - Name string `json:"name,omitempty"` - Physicalnetworkid string `json:"physicalnetworkid,omitempty"` - Servicelist []string `json:"servicelist,omitempty"` - State string `json:"state,omitempty"` - } `json:"provider,omitempty"` - } `json:"service,omitempty"` - Specifyipranges bool `json:"specifyipranges,omitempty"` - State string `json:"state,omitempty"` - Strechedl2subnet bool `json:"strechedl2subnet,omitempty"` - Subdomainaccess bool `json:"subdomainaccess,omitempty"` - Tags []struct { - Account string `json:"account,omitempty"` - Customer string `json:"customer,omitempty"` - Domain string `json:"domain,omitempty"` - Domainid string `json:"domainid,omitempty"` - Key string `json:"key,omitempty"` - Project string `json:"project,omitempty"` - Projectid string `json:"projectid,omitempty"` - Resourceid string `json:"resourceid,omitempty"` - Resourcetype string `json:"resourcetype,omitempty"` - Value string `json:"value,omitempty"` - } `json:"tags,omitempty"` - Traffictype string `json:"traffictype,omitempty"` - Type string `json:"type,omitempty"` - Vlan string `json:"vlan,omitempty"` - Vpcid string `json:"vpcid,omitempty"` - Zoneid string `json:"zoneid,omitempty"` - Zonename string `json:"zonename,omitempty"` - Zonesnetworkspans []string `json:"zonesnetworkspans,omitempty"` -} - -type CreatePhysicalNetworkParams struct { - p map[string]interface{} -} - -func (p *CreatePhysicalNetworkParams) toURLValues() url.Values { - u := url.Values{} - if p.p == nil { - return u - } - if v, found := p.p["broadcastdomainrange"]; found { - u.Set("broadcastdomainrange", v.(string)) - } - if v, found := p.p["domainid"]; found { - u.Set("domainid", v.(string)) - } - if v, found := p.p["isolationmethods"]; found { - vv := strings.Join(v.([]string), ",") - u.Set("isolationmethods", vv) - } - if v, found := p.p["name"]; found { - u.Set("name", v.(string)) - } - if v, found := p.p["networkspeed"]; found { - u.Set("networkspeed", v.(string)) - } - if v, found := p.p["tags"]; found { - vv := strings.Join(v.([]string), ",") - u.Set("tags", vv) - } - if v, found := p.p["vlan"]; found { - u.Set("vlan", v.(string)) - } - if v, found := p.p["zoneid"]; found { - u.Set("zoneid", v.(string)) - } - return u -} - -func (p *CreatePhysicalNetworkParams) SetBroadcastdomainrange(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["broadcastdomainrange"] = v - return -} - -func (p *CreatePhysicalNetworkParams) SetDomainid(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["domainid"] = v - return -} - -func (p *CreatePhysicalNetworkParams) SetIsolationmethods(v []string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["isolationmethods"] = v - return -} - -func (p *CreatePhysicalNetworkParams) SetName(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["name"] = v - return -} - -func (p *CreatePhysicalNetworkParams) SetNetworkspeed(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["networkspeed"] = v - return -} - -func (p *CreatePhysicalNetworkParams) SetTags(v []string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["tags"] = v - return -} - -func (p *CreatePhysicalNetworkParams) SetVlan(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["vlan"] = v - return -} - -func (p *CreatePhysicalNetworkParams) SetZoneid(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["zoneid"] = v - return -} - -// You should always use this function to get a new CreatePhysicalNetworkParams instance, -// as then you are sure you have configured all required params -func (s *NetworkService) NewCreatePhysicalNetworkParams(name string, zoneid string) *CreatePhysicalNetworkParams { - p := &CreatePhysicalNetworkParams{} - p.p = make(map[string]interface{}) - p.p["name"] = name - p.p["zoneid"] = zoneid - return p -} - -// Creates a physical network -func (s *NetworkService) CreatePhysicalNetwork(p *CreatePhysicalNetworkParams) (*CreatePhysicalNetworkResponse, error) { - resp, err := s.cs.newRequest("createPhysicalNetwork", p.toURLValues()) - if err != nil { - return nil, err - } - - var r CreatePhysicalNetworkResponse - if err := json.Unmarshal(resp, &r); err != nil { - return nil, err - } - - // If we have a async client, we need to wait for the async result - if s.cs.async { - b, err := s.cs.GetAsyncJobResult(r.JobID, s.cs.timeout) - if err != nil { - if err == AsyncTimeoutErr { - return &r, err - } - return nil, err - } - - b, err = getRawValue(b) - if err != nil { - return nil, err - } - - if err := json.Unmarshal(b, &r); err != nil { - return nil, err - } - } - return &r, nil -} - -type CreatePhysicalNetworkResponse struct { - JobID string `json:"jobid,omitempty"` - Broadcastdomainrange string `json:"broadcastdomainrange,omitempty"` - Domainid string `json:"domainid,omitempty"` - Id string `json:"id,omitempty"` - Isolationmethods string `json:"isolationmethods,omitempty"` - Name string `json:"name,omitempty"` - Networkspeed string `json:"networkspeed,omitempty"` - State string `json:"state,omitempty"` - Tags string `json:"tags,omitempty"` - Vlan string `json:"vlan,omitempty"` - Zoneid string `json:"zoneid,omitempty"` -} - -type DeletePhysicalNetworkParams struct { - p map[string]interface{} -} - -func (p *DeletePhysicalNetworkParams) toURLValues() url.Values { +func (p *ListOpenDaylightControllersParams) toURLValues() url.Values { u := url.Values{} if p.p == nil { return u @@ -1644,10 +2705,13 @@ func (p *DeletePhysicalNetworkParams) toURLValues() url.Values { if v, found := p.p["id"]; found { u.Set("id", v.(string)) } + if v, found := p.p["physicalnetworkid"]; found { + u.Set("physicalnetworkid", v.(string)) + } return u } -func (p *DeletePhysicalNetworkParams) SetId(v string) { +func (p *ListOpenDaylightControllersParams) SetId(v string) { if p.p == nil { p.p = make(map[string]interface{}) } @@ -1655,48 +2719,280 @@ func (p *DeletePhysicalNetworkParams) SetId(v string) { return } -// You should always use this function to get a new DeletePhysicalNetworkParams instance, +func (p *ListOpenDaylightControllersParams) SetPhysicalnetworkid(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["physicalnetworkid"] = v + return +} + +// You should always use this function to get a new ListOpenDaylightControllersParams instance, // as then you are sure you have configured all required params -func (s *NetworkService) NewDeletePhysicalNetworkParams(id string) *DeletePhysicalNetworkParams { - p := &DeletePhysicalNetworkParams{} +func (s *NetworkService) NewListOpenDaylightControllersParams() *ListOpenDaylightControllersParams { + p := &ListOpenDaylightControllersParams{} p.p = make(map[string]interface{}) - p.p["id"] = id return p } -// Deletes a Physical Network. -func (s *NetworkService) DeletePhysicalNetwork(p *DeletePhysicalNetworkParams) (*DeletePhysicalNetworkResponse, error) { - resp, err := s.cs.newRequest("deletePhysicalNetwork", p.toURLValues()) +// This is a courtesy helper function, which in some cases may not work as expected! +func (s *NetworkService) GetOpenDaylightControllerByID(id string, opts ...OptionFunc) (*OpenDaylightController, int, error) { + p := &ListOpenDaylightControllersParams{} + p.p = make(map[string]interface{}) + + p.p["id"] = id + + for _, fn := range append(s.cs.options, opts...) { + if err := fn(s.cs, p); err != nil { + return nil, -1, err + } + } + + l, err := s.ListOpenDaylightControllers(p) + if err != nil { + if strings.Contains(err.Error(), fmt.Sprintf( + "Invalid parameter id value=%s due to incorrect long value format, "+ + "or entity does not exist", id)) { + return nil, 0, fmt.Errorf("No match found for %s: %+v", id, l) + } + return nil, -1, err + } + + if l.Count == 0 { + return nil, l.Count, fmt.Errorf("No match found for %s: %+v", id, l) + } + + if l.Count == 1 { + return l.OpenDaylightControllers[0], l.Count, nil + } + return nil, l.Count, fmt.Errorf("There is more then one result for OpenDaylightController UUID: %s!", id) +} + +// Lists OpenDyalight controllers +func (s *NetworkService) ListOpenDaylightControllers(p *ListOpenDaylightControllersParams) (*ListOpenDaylightControllersResponse, error) { + resp, err := s.cs.newRequest("listOpenDaylightControllers", p.toURLValues()) if err != nil { return nil, err } - var r DeletePhysicalNetworkResponse + var r ListOpenDaylightControllersResponse if err := json.Unmarshal(resp, &r); err != nil { return nil, err } - // If we have a async client, we need to wait for the async result - if s.cs.async { - b, err := s.cs.GetAsyncJobResult(r.JobID, s.cs.timeout) - if err != nil { - if err == AsyncTimeoutErr { - return &r, err - } - return nil, err - } - - if err := json.Unmarshal(b, &r); err != nil { - return nil, err - } - } return &r, nil } -type DeletePhysicalNetworkResponse struct { - JobID string `json:"jobid,omitempty"` - Displaytext string `json:"displaytext,omitempty"` - Success bool `json:"success,omitempty"` +type ListOpenDaylightControllersResponse struct { + Count int `json:"count"` + OpenDaylightControllers []*OpenDaylightController `json:"opendaylightcontroller"` +} + +type OpenDaylightController struct { + Id string `json:"id"` + Name string `json:"name"` + Physicalnetworkid string `json:"physicalnetworkid"` + Url string `json:"url"` + Username string `json:"username"` +} + +type ListPaloAltoFirewallNetworksParams struct { + p map[string]interface{} +} + +func (p *ListPaloAltoFirewallNetworksParams) toURLValues() url.Values { + u := url.Values{} + if p.p == nil { + return u + } + if v, found := p.p["keyword"]; found { + u.Set("keyword", v.(string)) + } + if v, found := p.p["lbdeviceid"]; found { + u.Set("lbdeviceid", v.(string)) + } + if v, found := p.p["page"]; found { + vv := strconv.Itoa(v.(int)) + u.Set("page", vv) + } + if v, found := p.p["pagesize"]; found { + vv := strconv.Itoa(v.(int)) + u.Set("pagesize", vv) + } + return u +} + +func (p *ListPaloAltoFirewallNetworksParams) SetKeyword(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["keyword"] = v + return +} + +func (p *ListPaloAltoFirewallNetworksParams) SetLbdeviceid(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["lbdeviceid"] = v + return +} + +func (p *ListPaloAltoFirewallNetworksParams) SetPage(v int) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["page"] = v + return +} + +func (p *ListPaloAltoFirewallNetworksParams) SetPagesize(v int) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["pagesize"] = v + return +} + +// You should always use this function to get a new ListPaloAltoFirewallNetworksParams instance, +// as then you are sure you have configured all required params +func (s *NetworkService) NewListPaloAltoFirewallNetworksParams(lbdeviceid string) *ListPaloAltoFirewallNetworksParams { + p := &ListPaloAltoFirewallNetworksParams{} + p.p = make(map[string]interface{}) + p.p["lbdeviceid"] = lbdeviceid + return p +} + +// This is a courtesy helper function, which in some cases may not work as expected! +func (s *NetworkService) GetPaloAltoFirewallNetworkID(keyword string, lbdeviceid string, opts ...OptionFunc) (string, int, error) { + p := &ListPaloAltoFirewallNetworksParams{} + p.p = make(map[string]interface{}) + + p.p["keyword"] = keyword + p.p["lbdeviceid"] = lbdeviceid + + for _, fn := range append(s.cs.options, opts...) { + if err := fn(s.cs, p); err != nil { + return "", -1, err + } + } + + l, err := s.ListPaloAltoFirewallNetworks(p) + if err != nil { + return "", -1, err + } + + if l.Count == 0 { + return "", l.Count, fmt.Errorf("No match found for %s: %+v", keyword, l) + } + + if l.Count == 1 { + return l.PaloAltoFirewallNetworks[0].Id, l.Count, nil + } + + if l.Count > 1 { + for _, v := range l.PaloAltoFirewallNetworks { + if v.Name == keyword { + return v.Id, l.Count, nil + } + } + } + return "", l.Count, fmt.Errorf("Could not find an exact match for %s: %+v", keyword, l) +} + +// lists network that are using Palo Alto firewall device +func (s *NetworkService) ListPaloAltoFirewallNetworks(p *ListPaloAltoFirewallNetworksParams) (*ListPaloAltoFirewallNetworksResponse, error) { + resp, err := s.cs.newRequest("listPaloAltoFirewallNetworks", p.toURLValues()) + if err != nil { + return nil, err + } + + var r ListPaloAltoFirewallNetworksResponse + if err := json.Unmarshal(resp, &r); err != nil { + return nil, err + } + + return &r, nil +} + +type ListPaloAltoFirewallNetworksResponse struct { + Count int `json:"count"` + PaloAltoFirewallNetworks []*PaloAltoFirewallNetwork `json:"paloaltofirewallnetwork"` +} + +type PaloAltoFirewallNetwork struct { + Account string `json:"account"` + Aclid string `json:"aclid"` + Acltype string `json:"acltype"` + Broadcastdomaintype string `json:"broadcastdomaintype"` + Broadcasturi string `json:"broadcasturi"` + Canusefordeploy bool `json:"canusefordeploy"` + Cidr string `json:"cidr"` + Displaynetwork bool `json:"displaynetwork"` + Displaytext string `json:"displaytext"` + Dns1 string `json:"dns1"` + Dns2 string `json:"dns2"` + Domain string `json:"domain"` + Domainid string `json:"domainid"` + Externalid string `json:"externalid"` + Gateway string `json:"gateway"` + Id string `json:"id"` + Ip6cidr string `json:"ip6cidr"` + Ip6gateway string `json:"ip6gateway"` + Isdefault bool `json:"isdefault"` + Ispersistent bool `json:"ispersistent"` + Issystem bool `json:"issystem"` + Name string `json:"name"` + Netmask string `json:"netmask"` + Networkcidr string `json:"networkcidr"` + Networkdomain string `json:"networkdomain"` + Networkofferingavailability string `json:"networkofferingavailability"` + Networkofferingconservemode bool `json:"networkofferingconservemode"` + Networkofferingdisplaytext string `json:"networkofferingdisplaytext"` + Networkofferingid string `json:"networkofferingid"` + Networkofferingname string `json:"networkofferingname"` + Physicalnetworkid string `json:"physicalnetworkid"` + Project string `json:"project"` + Projectid string `json:"projectid"` + Redundantrouter bool `json:"redundantrouter"` + Related string `json:"related"` + Reservediprange string `json:"reservediprange"` + Restartrequired bool `json:"restartrequired"` + Service []PaloAltoFirewallNetworkService `json:"service"` + Specifyipranges bool `json:"specifyipranges"` + State string `json:"state"` + Strechedl2subnet bool `json:"strechedl2subnet"` + Subdomainaccess bool `json:"subdomainaccess"` + Tags []Tags `json:"tags"` + Traffictype string `json:"traffictype"` + Type string `json:"type"` + Vlan string `json:"vlan"` + Vpcid string `json:"vpcid"` + Zoneid string `json:"zoneid"` + Zonename string `json:"zonename"` + Zonesnetworkspans []interface{} `json:"zonesnetworkspans"` +} + +type PaloAltoFirewallNetworkService struct { + Capability []PaloAltoFirewallNetworkServiceCapability `json:"capability"` + Name string `json:"name"` + Provider []PaloAltoFirewallNetworkServiceProvider `json:"provider"` +} + +type PaloAltoFirewallNetworkServiceProvider struct { + Canenableindividualservice bool `json:"canenableindividualservice"` + Destinationphysicalnetworkid string `json:"destinationphysicalnetworkid"` + Id string `json:"id"` + Name string `json:"name"` + Physicalnetworkid string `json:"physicalnetworkid"` + Servicelist []string `json:"servicelist"` + State string `json:"state"` +} + +type PaloAltoFirewallNetworkServiceCapability struct { + Canchooseservicecapability bool `json:"canchooseservicecapability"` + Name string `json:"name"` + Value string `json:"value"` } type ListPhysicalNetworksParams struct { @@ -1794,7 +3090,7 @@ func (s *NetworkService) GetPhysicalNetworkID(name string, opts ...OptionFunc) ( p.p["name"] = name - for _, fn := range opts { + for _, fn := range append(s.cs.options, opts...) { if err := fn(s.cs, p); err != nil { return "", -1, err } @@ -1844,7 +3140,7 @@ func (s *NetworkService) GetPhysicalNetworkByID(id string, opts ...OptionFunc) ( p.p["id"] = id - for _, fn := range opts { + for _, fn := range append(s.cs.options, opts...) { if err := fn(s.cs, p); err != nil { return nil, -1, err } @@ -1881,6 +3177,7 @@ func (s *NetworkService) ListPhysicalNetworks(p *ListPhysicalNetworksParams) (*L if err := json.Unmarshal(resp, &r); err != nil { return nil, err } + return &r, nil } @@ -1890,16 +3187,842 @@ type ListPhysicalNetworksResponse struct { } type PhysicalNetwork struct { - Broadcastdomainrange string `json:"broadcastdomainrange,omitempty"` - Domainid string `json:"domainid,omitempty"` - Id string `json:"id,omitempty"` - Isolationmethods string `json:"isolationmethods,omitempty"` - Name string `json:"name,omitempty"` - Networkspeed string `json:"networkspeed,omitempty"` - State string `json:"state,omitempty"` - Tags string `json:"tags,omitempty"` - Vlan string `json:"vlan,omitempty"` - Zoneid string `json:"zoneid,omitempty"` + Broadcastdomainrange string `json:"broadcastdomainrange"` + Domainid string `json:"domainid"` + Id string `json:"id"` + Isolationmethods string `json:"isolationmethods"` + Name string `json:"name"` + Networkspeed string `json:"networkspeed"` + State string `json:"state"` + Tags string `json:"tags"` + Vlan string `json:"vlan"` + Zoneid string `json:"zoneid"` +} + +type ListStorageNetworkIpRangeParams struct { + p map[string]interface{} +} + +func (p *ListStorageNetworkIpRangeParams) toURLValues() url.Values { + u := url.Values{} + if p.p == nil { + return u + } + if v, found := p.p["id"]; found { + u.Set("id", v.(string)) + } + if v, found := p.p["keyword"]; found { + u.Set("keyword", v.(string)) + } + if v, found := p.p["page"]; found { + vv := strconv.Itoa(v.(int)) + u.Set("page", vv) + } + if v, found := p.p["pagesize"]; found { + vv := strconv.Itoa(v.(int)) + u.Set("pagesize", vv) + } + if v, found := p.p["podid"]; found { + u.Set("podid", v.(string)) + } + if v, found := p.p["zoneid"]; found { + u.Set("zoneid", v.(string)) + } + return u +} + +func (p *ListStorageNetworkIpRangeParams) SetId(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["id"] = v + return +} + +func (p *ListStorageNetworkIpRangeParams) SetKeyword(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["keyword"] = v + return +} + +func (p *ListStorageNetworkIpRangeParams) SetPage(v int) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["page"] = v + return +} + +func (p *ListStorageNetworkIpRangeParams) SetPagesize(v int) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["pagesize"] = v + return +} + +func (p *ListStorageNetworkIpRangeParams) SetPodid(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["podid"] = v + return +} + +func (p *ListStorageNetworkIpRangeParams) SetZoneid(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["zoneid"] = v + return +} + +// You should always use this function to get a new ListStorageNetworkIpRangeParams instance, +// as then you are sure you have configured all required params +func (s *NetworkService) NewListStorageNetworkIpRangeParams() *ListStorageNetworkIpRangeParams { + p := &ListStorageNetworkIpRangeParams{} + p.p = make(map[string]interface{}) + return p +} + +// This is a courtesy helper function, which in some cases may not work as expected! +func (s *NetworkService) GetStorageNetworkIpRangeByID(id string, opts ...OptionFunc) (*StorageNetworkIpRange, int, error) { + p := &ListStorageNetworkIpRangeParams{} + p.p = make(map[string]interface{}) + + p.p["id"] = id + + for _, fn := range append(s.cs.options, opts...) { + if err := fn(s.cs, p); err != nil { + return nil, -1, err + } + } + + l, err := s.ListStorageNetworkIpRange(p) + if err != nil { + if strings.Contains(err.Error(), fmt.Sprintf( + "Invalid parameter id value=%s due to incorrect long value format, "+ + "or entity does not exist", id)) { + return nil, 0, fmt.Errorf("No match found for %s: %+v", id, l) + } + return nil, -1, err + } + + if l.Count == 0 { + return nil, l.Count, fmt.Errorf("No match found for %s: %+v", id, l) + } + + if l.Count == 1 { + return l.StorageNetworkIpRange[0], l.Count, nil + } + return nil, l.Count, fmt.Errorf("There is more then one result for StorageNetworkIpRange UUID: %s!", id) +} + +// List a storage network IP range. +func (s *NetworkService) ListStorageNetworkIpRange(p *ListStorageNetworkIpRangeParams) (*ListStorageNetworkIpRangeResponse, error) { + resp, err := s.cs.newRequest("listStorageNetworkIpRange", p.toURLValues()) + if err != nil { + return nil, err + } + + var r ListStorageNetworkIpRangeResponse + if err := json.Unmarshal(resp, &r); err != nil { + return nil, err + } + + return &r, nil +} + +type ListStorageNetworkIpRangeResponse struct { + Count int `json:"count"` + StorageNetworkIpRange []*StorageNetworkIpRange `json:"storagenetworkiprange"` +} + +type StorageNetworkIpRange struct { + Endip string `json:"endip"` + Gateway string `json:"gateway"` + Id string `json:"id"` + Netmask string `json:"netmask"` + Networkid string `json:"networkid"` + Podid string `json:"podid"` + Startip string `json:"startip"` + Vlan int `json:"vlan"` + Zoneid string `json:"zoneid"` +} + +type ListSupportedNetworkServicesParams struct { + p map[string]interface{} +} + +func (p *ListSupportedNetworkServicesParams) toURLValues() url.Values { + u := url.Values{} + if p.p == nil { + return u + } + if v, found := p.p["keyword"]; found { + u.Set("keyword", v.(string)) + } + if v, found := p.p["page"]; found { + vv := strconv.Itoa(v.(int)) + u.Set("page", vv) + } + if v, found := p.p["pagesize"]; found { + vv := strconv.Itoa(v.(int)) + u.Set("pagesize", vv) + } + if v, found := p.p["provider"]; found { + u.Set("provider", v.(string)) + } + if v, found := p.p["service"]; found { + u.Set("service", v.(string)) + } + return u +} + +func (p *ListSupportedNetworkServicesParams) SetKeyword(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["keyword"] = v + return +} + +func (p *ListSupportedNetworkServicesParams) SetPage(v int) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["page"] = v + return +} + +func (p *ListSupportedNetworkServicesParams) SetPagesize(v int) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["pagesize"] = v + return +} + +func (p *ListSupportedNetworkServicesParams) SetProvider(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["provider"] = v + return +} + +func (p *ListSupportedNetworkServicesParams) SetService(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["service"] = v + return +} + +// You should always use this function to get a new ListSupportedNetworkServicesParams instance, +// as then you are sure you have configured all required params +func (s *NetworkService) NewListSupportedNetworkServicesParams() *ListSupportedNetworkServicesParams { + p := &ListSupportedNetworkServicesParams{} + p.p = make(map[string]interface{}) + return p +} + +// Lists all network services provided by CloudStack or for the given Provider. +func (s *NetworkService) ListSupportedNetworkServices(p *ListSupportedNetworkServicesParams) (*ListSupportedNetworkServicesResponse, error) { + resp, err := s.cs.newRequest("listSupportedNetworkServices", p.toURLValues()) + if err != nil { + return nil, err + } + + var r ListSupportedNetworkServicesResponse + if err := json.Unmarshal(resp, &r); err != nil { + return nil, err + } + + return &r, nil +} + +type ListSupportedNetworkServicesResponse struct { + Count int `json:"count"` + SupportedNetworkServices []*SupportedNetworkService `json:"supportednetworkservice"` +} + +type SupportedNetworkService struct { + Capability []SupportedNetworkServiceCapability `json:"capability"` + Name string `json:"name"` + Provider []SupportedNetworkServiceProvider `json:"provider"` +} + +type SupportedNetworkServiceProvider struct { + Canenableindividualservice bool `json:"canenableindividualservice"` + Destinationphysicalnetworkid string `json:"destinationphysicalnetworkid"` + Id string `json:"id"` + Name string `json:"name"` + Physicalnetworkid string `json:"physicalnetworkid"` + Servicelist []string `json:"servicelist"` + State string `json:"state"` +} + +type SupportedNetworkServiceCapability struct { + Canchooseservicecapability bool `json:"canchooseservicecapability"` + Name string `json:"name"` + Value string `json:"value"` +} + +type ReleasePublicIpRangeParams struct { + p map[string]interface{} +} + +func (p *ReleasePublicIpRangeParams) toURLValues() url.Values { + u := url.Values{} + if p.p == nil { + return u + } + if v, found := p.p["id"]; found { + u.Set("id", v.(string)) + } + return u +} + +func (p *ReleasePublicIpRangeParams) SetId(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["id"] = v + return +} + +// You should always use this function to get a new ReleasePublicIpRangeParams instance, +// as then you are sure you have configured all required params +func (s *NetworkService) NewReleasePublicIpRangeParams(id string) *ReleasePublicIpRangeParams { + p := &ReleasePublicIpRangeParams{} + p.p = make(map[string]interface{}) + p.p["id"] = id + return p +} + +// Releases a Public IP range back to the system pool +func (s *NetworkService) ReleasePublicIpRange(p *ReleasePublicIpRangeParams) (*ReleasePublicIpRangeResponse, error) { + resp, err := s.cs.newRequest("releasePublicIpRange", p.toURLValues()) + if err != nil { + return nil, err + } + + var r ReleasePublicIpRangeResponse + if err := json.Unmarshal(resp, &r); err != nil { + return nil, err + } + + return &r, nil +} + +type ReleasePublicIpRangeResponse struct { + Displaytext string `json:"displaytext"` + Success bool `json:"success"` +} + +func (r *ReleasePublicIpRangeResponse) UnmarshalJSON(b []byte) error { + var m map[string]interface{} + err := json.Unmarshal(b, &m) + if err != nil { + return err + } + + if success, ok := m["success"].(string); ok { + m["success"] = success == "true" + b, err = json.Marshal(m) + if err != nil { + return err + } + } + + type alias ReleasePublicIpRangeResponse + return json.Unmarshal(b, (*alias)(r)) +} + +type RestartNetworkParams struct { + p map[string]interface{} +} + +func (p *RestartNetworkParams) toURLValues() url.Values { + u := url.Values{} + if p.p == nil { + return u + } + if v, found := p.p["cleanup"]; found { + vv := strconv.FormatBool(v.(bool)) + u.Set("cleanup", vv) + } + if v, found := p.p["id"]; found { + u.Set("id", v.(string)) + } + if v, found := p.p["makeredundant"]; found { + vv := strconv.FormatBool(v.(bool)) + u.Set("makeredundant", vv) + } + return u +} + +func (p *RestartNetworkParams) SetCleanup(v bool) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["cleanup"] = v + return +} + +func (p *RestartNetworkParams) SetId(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["id"] = v + return +} + +func (p *RestartNetworkParams) SetMakeredundant(v bool) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["makeredundant"] = v + return +} + +// You should always use this function to get a new RestartNetworkParams instance, +// as then you are sure you have configured all required params +func (s *NetworkService) NewRestartNetworkParams(id string) *RestartNetworkParams { + p := &RestartNetworkParams{} + p.p = make(map[string]interface{}) + p.p["id"] = id + return p +} + +// Restarts the network; includes 1) restarting network elements - virtual routers, DHCP servers 2) reapplying all public IPs 3) reapplying loadBalancing/portForwarding rules +func (s *NetworkService) RestartNetwork(p *RestartNetworkParams) (*RestartNetworkResponse, error) { + resp, err := s.cs.newRequest("restartNetwork", p.toURLValues()) + if err != nil { + return nil, err + } + + var r RestartNetworkResponse + if err := json.Unmarshal(resp, &r); err != nil { + return nil, err + } + + // If we have a async client, we need to wait for the async result + if s.cs.async { + b, err := s.cs.GetAsyncJobResult(r.JobID, s.cs.timeout) + if err != nil { + if err == AsyncTimeoutErr { + return &r, err + } + return nil, err + } + + b, err = getRawValue(b) + if err != nil { + return nil, err + } + + if err := json.Unmarshal(b, &r); err != nil { + return nil, err + } + } + + return &r, nil +} + +type RestartNetworkResponse struct { + JobID string `json:"jobid"` + Account string `json:"account"` + Allocated string `json:"allocated"` + Associatednetworkid string `json:"associatednetworkid"` + Associatednetworkname string `json:"associatednetworkname"` + Domain string `json:"domain"` + Domainid string `json:"domainid"` + Fordisplay bool `json:"fordisplay"` + Forvirtualnetwork bool `json:"forvirtualnetwork"` + Id string `json:"id"` + Ipaddress string `json:"ipaddress"` + Isportable bool `json:"isportable"` + Issourcenat bool `json:"issourcenat"` + Isstaticnat bool `json:"isstaticnat"` + Issystem bool `json:"issystem"` + Networkid string `json:"networkid"` + Physicalnetworkid string `json:"physicalnetworkid"` + Project string `json:"project"` + Projectid string `json:"projectid"` + Purpose string `json:"purpose"` + State string `json:"state"` + Tags []Tags `json:"tags"` + Virtualmachinedisplayname string `json:"virtualmachinedisplayname"` + Virtualmachineid string `json:"virtualmachineid"` + Virtualmachinename string `json:"virtualmachinename"` + Vlanid string `json:"vlanid"` + Vlanname string `json:"vlanname"` + Vmipaddress string `json:"vmipaddress"` + Vpcid string `json:"vpcid"` + Zoneid string `json:"zoneid"` + Zonename string `json:"zonename"` +} + +type UpdateNetworkParams struct { + p map[string]interface{} +} + +func (p *UpdateNetworkParams) toURLValues() url.Values { + u := url.Values{} + if p.p == nil { + return u + } + if v, found := p.p["changecidr"]; found { + vv := strconv.FormatBool(v.(bool)) + u.Set("changecidr", vv) + } + if v, found := p.p["customid"]; found { + u.Set("customid", v.(string)) + } + if v, found := p.p["displaynetwork"]; found { + vv := strconv.FormatBool(v.(bool)) + u.Set("displaynetwork", vv) + } + if v, found := p.p["displaytext"]; found { + u.Set("displaytext", v.(string)) + } + if v, found := p.p["forced"]; found { + vv := strconv.FormatBool(v.(bool)) + u.Set("forced", vv) + } + if v, found := p.p["guestvmcidr"]; found { + u.Set("guestvmcidr", v.(string)) + } + if v, found := p.p["id"]; found { + u.Set("id", v.(string)) + } + if v, found := p.p["name"]; found { + u.Set("name", v.(string)) + } + if v, found := p.p["networkdomain"]; found { + u.Set("networkdomain", v.(string)) + } + if v, found := p.p["networkofferingid"]; found { + u.Set("networkofferingid", v.(string)) + } + if v, found := p.p["updateinsequence"]; found { + vv := strconv.FormatBool(v.(bool)) + u.Set("updateinsequence", vv) + } + return u +} + +func (p *UpdateNetworkParams) SetChangecidr(v bool) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["changecidr"] = v + return +} + +func (p *UpdateNetworkParams) SetCustomid(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["customid"] = v + return +} + +func (p *UpdateNetworkParams) SetDisplaynetwork(v bool) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["displaynetwork"] = v + return +} + +func (p *UpdateNetworkParams) SetDisplaytext(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["displaytext"] = v + return +} + +func (p *UpdateNetworkParams) SetForced(v bool) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["forced"] = v + return +} + +func (p *UpdateNetworkParams) SetGuestvmcidr(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["guestvmcidr"] = v + return +} + +func (p *UpdateNetworkParams) SetId(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["id"] = v + return +} + +func (p *UpdateNetworkParams) SetName(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["name"] = v + return +} + +func (p *UpdateNetworkParams) SetNetworkdomain(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["networkdomain"] = v + return +} + +func (p *UpdateNetworkParams) SetNetworkofferingid(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["networkofferingid"] = v + return +} + +func (p *UpdateNetworkParams) SetUpdateinsequence(v bool) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["updateinsequence"] = v + return +} + +// You should always use this function to get a new UpdateNetworkParams instance, +// as then you are sure you have configured all required params +func (s *NetworkService) NewUpdateNetworkParams(id string) *UpdateNetworkParams { + p := &UpdateNetworkParams{} + p.p = make(map[string]interface{}) + p.p["id"] = id + return p +} + +// Updates a network +func (s *NetworkService) UpdateNetwork(p *UpdateNetworkParams) (*UpdateNetworkResponse, error) { + resp, err := s.cs.newRequest("updateNetwork", p.toURLValues()) + if err != nil { + return nil, err + } + + var r UpdateNetworkResponse + if err := json.Unmarshal(resp, &r); err != nil { + return nil, err + } + + // If we have a async client, we need to wait for the async result + if s.cs.async { + b, err := s.cs.GetAsyncJobResult(r.JobID, s.cs.timeout) + if err != nil { + if err == AsyncTimeoutErr { + return &r, err + } + return nil, err + } + + b, err = getRawValue(b) + if err != nil { + return nil, err + } + + if err := json.Unmarshal(b, &r); err != nil { + return nil, err + } + } + + return &r, nil +} + +type UpdateNetworkResponse struct { + JobID string `json:"jobid"` + Account string `json:"account"` + Aclid string `json:"aclid"` + Acltype string `json:"acltype"` + Broadcastdomaintype string `json:"broadcastdomaintype"` + Broadcasturi string `json:"broadcasturi"` + Canusefordeploy bool `json:"canusefordeploy"` + Cidr string `json:"cidr"` + Displaynetwork bool `json:"displaynetwork"` + Displaytext string `json:"displaytext"` + Dns1 string `json:"dns1"` + Dns2 string `json:"dns2"` + Domain string `json:"domain"` + Domainid string `json:"domainid"` + Externalid string `json:"externalid"` + Gateway string `json:"gateway"` + Id string `json:"id"` + Ip6cidr string `json:"ip6cidr"` + Ip6gateway string `json:"ip6gateway"` + Isdefault bool `json:"isdefault"` + Ispersistent bool `json:"ispersistent"` + Issystem bool `json:"issystem"` + Name string `json:"name"` + Netmask string `json:"netmask"` + Networkcidr string `json:"networkcidr"` + Networkdomain string `json:"networkdomain"` + Networkofferingavailability string `json:"networkofferingavailability"` + Networkofferingconservemode bool `json:"networkofferingconservemode"` + Networkofferingdisplaytext string `json:"networkofferingdisplaytext"` + Networkofferingid string `json:"networkofferingid"` + Networkofferingname string `json:"networkofferingname"` + Physicalnetworkid string `json:"physicalnetworkid"` + Project string `json:"project"` + Projectid string `json:"projectid"` + Redundantrouter bool `json:"redundantrouter"` + Related string `json:"related"` + Reservediprange string `json:"reservediprange"` + Restartrequired bool `json:"restartrequired"` + Service []UpdateNetworkResponseService `json:"service"` + Specifyipranges bool `json:"specifyipranges"` + State string `json:"state"` + Strechedl2subnet bool `json:"strechedl2subnet"` + Subdomainaccess bool `json:"subdomainaccess"` + Tags []Tags `json:"tags"` + Traffictype string `json:"traffictype"` + Type string `json:"type"` + Vlan string `json:"vlan"` + Vpcid string `json:"vpcid"` + Zoneid string `json:"zoneid"` + Zonename string `json:"zonename"` + Zonesnetworkspans []interface{} `json:"zonesnetworkspans"` +} + +type UpdateNetworkResponseService struct { + Capability []UpdateNetworkResponseServiceCapability `json:"capability"` + Name string `json:"name"` + Provider []UpdateNetworkResponseServiceProvider `json:"provider"` +} + +type UpdateNetworkResponseServiceProvider struct { + Canenableindividualservice bool `json:"canenableindividualservice"` + Destinationphysicalnetworkid string `json:"destinationphysicalnetworkid"` + Id string `json:"id"` + Name string `json:"name"` + Physicalnetworkid string `json:"physicalnetworkid"` + Servicelist []string `json:"servicelist"` + State string `json:"state"` +} + +type UpdateNetworkResponseServiceCapability struct { + Canchooseservicecapability bool `json:"canchooseservicecapability"` + Name string `json:"name"` + Value string `json:"value"` +} + +type UpdateNetworkServiceProviderParams struct { + p map[string]interface{} +} + +func (p *UpdateNetworkServiceProviderParams) toURLValues() url.Values { + u := url.Values{} + if p.p == nil { + return u + } + if v, found := p.p["id"]; found { + u.Set("id", v.(string)) + } + if v, found := p.p["servicelist"]; found { + vv := strings.Join(v.([]string), ",") + u.Set("servicelist", vv) + } + if v, found := p.p["state"]; found { + u.Set("state", v.(string)) + } + return u +} + +func (p *UpdateNetworkServiceProviderParams) SetId(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["id"] = v + return +} + +func (p *UpdateNetworkServiceProviderParams) SetServicelist(v []string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["servicelist"] = v + return +} + +func (p *UpdateNetworkServiceProviderParams) SetState(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["state"] = v + return +} + +// You should always use this function to get a new UpdateNetworkServiceProviderParams instance, +// as then you are sure you have configured all required params +func (s *NetworkService) NewUpdateNetworkServiceProviderParams(id string) *UpdateNetworkServiceProviderParams { + p := &UpdateNetworkServiceProviderParams{} + p.p = make(map[string]interface{}) + p.p["id"] = id + return p +} + +// Updates a network serviceProvider of a physical network +func (s *NetworkService) UpdateNetworkServiceProvider(p *UpdateNetworkServiceProviderParams) (*UpdateNetworkServiceProviderResponse, error) { + resp, err := s.cs.newRequest("updateNetworkServiceProvider", p.toURLValues()) + if err != nil { + return nil, err + } + + var r UpdateNetworkServiceProviderResponse + if err := json.Unmarshal(resp, &r); err != nil { + return nil, err + } + + // If we have a async client, we need to wait for the async result + if s.cs.async { + b, err := s.cs.GetAsyncJobResult(r.JobID, s.cs.timeout) + if err != nil { + if err == AsyncTimeoutErr { + return &r, err + } + return nil, err + } + + b, err = getRawValue(b) + if err != nil { + return nil, err + } + + if err := json.Unmarshal(b, &r); err != nil { + return nil, err + } + } + + return &r, nil +} + +type UpdateNetworkServiceProviderResponse struct { + JobID string `json:"jobid"` + Canenableindividualservice bool `json:"canenableindividualservice"` + Destinationphysicalnetworkid string `json:"destinationphysicalnetworkid"` + Id string `json:"id"` + Name string `json:"name"` + Physicalnetworkid string `json:"physicalnetworkid"` + Servicelist []string `json:"servicelist"` + State string `json:"state"` } type UpdatePhysicalNetworkParams struct { @@ -2010,924 +4133,22 @@ func (s *NetworkService) UpdatePhysicalNetwork(p *UpdatePhysicalNetworkParams) ( return nil, err } } + return &r, nil } type UpdatePhysicalNetworkResponse struct { - JobID string `json:"jobid,omitempty"` - Broadcastdomainrange string `json:"broadcastdomainrange,omitempty"` - Domainid string `json:"domainid,omitempty"` - Id string `json:"id,omitempty"` - Isolationmethods string `json:"isolationmethods,omitempty"` - Name string `json:"name,omitempty"` - Networkspeed string `json:"networkspeed,omitempty"` - State string `json:"state,omitempty"` - Tags string `json:"tags,omitempty"` - Vlan string `json:"vlan,omitempty"` - Zoneid string `json:"zoneid,omitempty"` -} - -type ListSupportedNetworkServicesParams struct { - p map[string]interface{} -} - -func (p *ListSupportedNetworkServicesParams) toURLValues() url.Values { - u := url.Values{} - if p.p == nil { - return u - } - if v, found := p.p["keyword"]; found { - u.Set("keyword", v.(string)) - } - if v, found := p.p["page"]; found { - vv := strconv.Itoa(v.(int)) - u.Set("page", vv) - } - if v, found := p.p["pagesize"]; found { - vv := strconv.Itoa(v.(int)) - u.Set("pagesize", vv) - } - if v, found := p.p["provider"]; found { - u.Set("provider", v.(string)) - } - if v, found := p.p["service"]; found { - u.Set("service", v.(string)) - } - return u -} - -func (p *ListSupportedNetworkServicesParams) SetKeyword(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["keyword"] = v - return -} - -func (p *ListSupportedNetworkServicesParams) SetPage(v int) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["page"] = v - return -} - -func (p *ListSupportedNetworkServicesParams) SetPagesize(v int) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["pagesize"] = v - return -} - -func (p *ListSupportedNetworkServicesParams) SetProvider(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["provider"] = v - return -} - -func (p *ListSupportedNetworkServicesParams) SetService(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["service"] = v - return -} - -// You should always use this function to get a new ListSupportedNetworkServicesParams instance, -// as then you are sure you have configured all required params -func (s *NetworkService) NewListSupportedNetworkServicesParams() *ListSupportedNetworkServicesParams { - p := &ListSupportedNetworkServicesParams{} - p.p = make(map[string]interface{}) - return p -} - -// Lists all network services provided by CloudStack or for the given Provider. -func (s *NetworkService) ListSupportedNetworkServices(p *ListSupportedNetworkServicesParams) (*ListSupportedNetworkServicesResponse, error) { - resp, err := s.cs.newRequest("listSupportedNetworkServices", p.toURLValues()) - if err != nil { - return nil, err - } - - var r ListSupportedNetworkServicesResponse - if err := json.Unmarshal(resp, &r); err != nil { - return nil, err - } - return &r, nil -} - -type ListSupportedNetworkServicesResponse struct { - Count int `json:"count"` - SupportedNetworkServices []*SupportedNetworkService `json:"supportednetworkservice"` -} - -type SupportedNetworkService struct { - Capability []struct { - Canchooseservicecapability bool `json:"canchooseservicecapability,omitempty"` - Name string `json:"name,omitempty"` - Value string `json:"value,omitempty"` - } `json:"capability,omitempty"` - Name string `json:"name,omitempty"` - Provider []struct { - Canenableindividualservice bool `json:"canenableindividualservice,omitempty"` - Destinationphysicalnetworkid string `json:"destinationphysicalnetworkid,omitempty"` - Id string `json:"id,omitempty"` - Name string `json:"name,omitempty"` - Physicalnetworkid string `json:"physicalnetworkid,omitempty"` - Servicelist []string `json:"servicelist,omitempty"` - State string `json:"state,omitempty"` - } `json:"provider,omitempty"` -} - -type AddNetworkServiceProviderParams struct { - p map[string]interface{} -} - -func (p *AddNetworkServiceProviderParams) toURLValues() url.Values { - u := url.Values{} - if p.p == nil { - return u - } - if v, found := p.p["destinationphysicalnetworkid"]; found { - u.Set("destinationphysicalnetworkid", v.(string)) - } - if v, found := p.p["name"]; found { - u.Set("name", v.(string)) - } - if v, found := p.p["physicalnetworkid"]; found { - u.Set("physicalnetworkid", v.(string)) - } - if v, found := p.p["servicelist"]; found { - vv := strings.Join(v.([]string), ",") - u.Set("servicelist", vv) - } - return u -} - -func (p *AddNetworkServiceProviderParams) SetDestinationphysicalnetworkid(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["destinationphysicalnetworkid"] = v - return -} - -func (p *AddNetworkServiceProviderParams) SetName(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["name"] = v - return -} - -func (p *AddNetworkServiceProviderParams) SetPhysicalnetworkid(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["physicalnetworkid"] = v - return -} - -func (p *AddNetworkServiceProviderParams) SetServicelist(v []string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["servicelist"] = v - return -} - -// You should always use this function to get a new AddNetworkServiceProviderParams instance, -// as then you are sure you have configured all required params -func (s *NetworkService) NewAddNetworkServiceProviderParams(name string, physicalnetworkid string) *AddNetworkServiceProviderParams { - p := &AddNetworkServiceProviderParams{} - p.p = make(map[string]interface{}) - p.p["name"] = name - p.p["physicalnetworkid"] = physicalnetworkid - return p -} - -// Adds a network serviceProvider to a physical network -func (s *NetworkService) AddNetworkServiceProvider(p *AddNetworkServiceProviderParams) (*AddNetworkServiceProviderResponse, error) { - resp, err := s.cs.newRequest("addNetworkServiceProvider", p.toURLValues()) - if err != nil { - return nil, err - } - - var r AddNetworkServiceProviderResponse - if err := json.Unmarshal(resp, &r); err != nil { - return nil, err - } - - // If we have a async client, we need to wait for the async result - if s.cs.async { - b, err := s.cs.GetAsyncJobResult(r.JobID, s.cs.timeout) - if err != nil { - if err == AsyncTimeoutErr { - return &r, err - } - return nil, err - } - - b, err = getRawValue(b) - if err != nil { - return nil, err - } - - if err := json.Unmarshal(b, &r); err != nil { - return nil, err - } - } - return &r, nil -} - -type AddNetworkServiceProviderResponse struct { - JobID string `json:"jobid,omitempty"` - Canenableindividualservice bool `json:"canenableindividualservice,omitempty"` - Destinationphysicalnetworkid string `json:"destinationphysicalnetworkid,omitempty"` - Id string `json:"id,omitempty"` - Name string `json:"name,omitempty"` - Physicalnetworkid string `json:"physicalnetworkid,omitempty"` - Servicelist []string `json:"servicelist,omitempty"` - State string `json:"state,omitempty"` -} - -type DeleteNetworkServiceProviderParams struct { - p map[string]interface{} -} - -func (p *DeleteNetworkServiceProviderParams) toURLValues() url.Values { - u := url.Values{} - if p.p == nil { - return u - } - if v, found := p.p["id"]; found { - u.Set("id", v.(string)) - } - return u -} - -func (p *DeleteNetworkServiceProviderParams) SetId(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["id"] = v - return -} - -// You should always use this function to get a new DeleteNetworkServiceProviderParams instance, -// as then you are sure you have configured all required params -func (s *NetworkService) NewDeleteNetworkServiceProviderParams(id string) *DeleteNetworkServiceProviderParams { - p := &DeleteNetworkServiceProviderParams{} - p.p = make(map[string]interface{}) - p.p["id"] = id - return p -} - -// Deletes a Network Service Provider. -func (s *NetworkService) DeleteNetworkServiceProvider(p *DeleteNetworkServiceProviderParams) (*DeleteNetworkServiceProviderResponse, error) { - resp, err := s.cs.newRequest("deleteNetworkServiceProvider", p.toURLValues()) - if err != nil { - return nil, err - } - - var r DeleteNetworkServiceProviderResponse - if err := json.Unmarshal(resp, &r); err != nil { - return nil, err - } - - // If we have a async client, we need to wait for the async result - if s.cs.async { - b, err := s.cs.GetAsyncJobResult(r.JobID, s.cs.timeout) - if err != nil { - if err == AsyncTimeoutErr { - return &r, err - } - return nil, err - } - - if err := json.Unmarshal(b, &r); err != nil { - return nil, err - } - } - return &r, nil -} - -type DeleteNetworkServiceProviderResponse struct { - JobID string `json:"jobid,omitempty"` - Displaytext string `json:"displaytext,omitempty"` - Success bool `json:"success,omitempty"` -} - -type ListNetworkServiceProvidersParams struct { - p map[string]interface{} -} - -func (p *ListNetworkServiceProvidersParams) toURLValues() url.Values { - u := url.Values{} - if p.p == nil { - return u - } - if v, found := p.p["keyword"]; found { - u.Set("keyword", v.(string)) - } - if v, found := p.p["name"]; found { - u.Set("name", v.(string)) - } - if v, found := p.p["page"]; found { - vv := strconv.Itoa(v.(int)) - u.Set("page", vv) - } - if v, found := p.p["pagesize"]; found { - vv := strconv.Itoa(v.(int)) - u.Set("pagesize", vv) - } - if v, found := p.p["physicalnetworkid"]; found { - u.Set("physicalnetworkid", v.(string)) - } - if v, found := p.p["state"]; found { - u.Set("state", v.(string)) - } - return u -} - -func (p *ListNetworkServiceProvidersParams) SetKeyword(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["keyword"] = v - return -} - -func (p *ListNetworkServiceProvidersParams) SetName(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["name"] = v - return -} - -func (p *ListNetworkServiceProvidersParams) SetPage(v int) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["page"] = v - return -} - -func (p *ListNetworkServiceProvidersParams) SetPagesize(v int) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["pagesize"] = v - return -} - -func (p *ListNetworkServiceProvidersParams) SetPhysicalnetworkid(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["physicalnetworkid"] = v - return -} - -func (p *ListNetworkServiceProvidersParams) SetState(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["state"] = v - return -} - -// You should always use this function to get a new ListNetworkServiceProvidersParams instance, -// as then you are sure you have configured all required params -func (s *NetworkService) NewListNetworkServiceProvidersParams() *ListNetworkServiceProvidersParams { - p := &ListNetworkServiceProvidersParams{} - p.p = make(map[string]interface{}) - return p -} - -// This is a courtesy helper function, which in some cases may not work as expected! -func (s *NetworkService) GetNetworkServiceProviderID(name string, opts ...OptionFunc) (string, int, error) { - p := &ListNetworkServiceProvidersParams{} - p.p = make(map[string]interface{}) - - p.p["name"] = name - - for _, fn := range opts { - if err := fn(s.cs, p); err != nil { - return "", -1, err - } - } - - l, err := s.ListNetworkServiceProviders(p) - if err != nil { - return "", -1, err - } - - if l.Count == 0 { - return "", l.Count, fmt.Errorf("No match found for %s: %+v", name, l) - } - - if l.Count == 1 { - return l.NetworkServiceProviders[0].Id, l.Count, nil - } - - if l.Count > 1 { - for _, v := range l.NetworkServiceProviders { - if v.Name == name { - return v.Id, l.Count, nil - } - } - } - return "", l.Count, fmt.Errorf("Could not find an exact match for %s: %+v", name, l) -} - -// Lists network serviceproviders for a given physical network. -func (s *NetworkService) ListNetworkServiceProviders(p *ListNetworkServiceProvidersParams) (*ListNetworkServiceProvidersResponse, error) { - resp, err := s.cs.newRequest("listNetworkServiceProviders", p.toURLValues()) - if err != nil { - return nil, err - } - - var r ListNetworkServiceProvidersResponse - if err := json.Unmarshal(resp, &r); err != nil { - return nil, err - } - return &r, nil -} - -type ListNetworkServiceProvidersResponse struct { - Count int `json:"count"` - NetworkServiceProviders []*NetworkServiceProvider `json:"networkserviceprovider"` -} - -type NetworkServiceProvider struct { - Canenableindividualservice bool `json:"canenableindividualservice,omitempty"` - Destinationphysicalnetworkid string `json:"destinationphysicalnetworkid,omitempty"` - Id string `json:"id,omitempty"` - Name string `json:"name,omitempty"` - Physicalnetworkid string `json:"physicalnetworkid,omitempty"` - Servicelist []string `json:"servicelist,omitempty"` - State string `json:"state,omitempty"` -} - -type UpdateNetworkServiceProviderParams struct { - p map[string]interface{} -} - -func (p *UpdateNetworkServiceProviderParams) toURLValues() url.Values { - u := url.Values{} - if p.p == nil { - return u - } - if v, found := p.p["id"]; found { - u.Set("id", v.(string)) - } - if v, found := p.p["servicelist"]; found { - vv := strings.Join(v.([]string), ",") - u.Set("servicelist", vv) - } - if v, found := p.p["state"]; found { - u.Set("state", v.(string)) - } - return u -} - -func (p *UpdateNetworkServiceProviderParams) SetId(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["id"] = v - return -} - -func (p *UpdateNetworkServiceProviderParams) SetServicelist(v []string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["servicelist"] = v - return -} - -func (p *UpdateNetworkServiceProviderParams) SetState(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["state"] = v - return -} - -// You should always use this function to get a new UpdateNetworkServiceProviderParams instance, -// as then you are sure you have configured all required params -func (s *NetworkService) NewUpdateNetworkServiceProviderParams(id string) *UpdateNetworkServiceProviderParams { - p := &UpdateNetworkServiceProviderParams{} - p.p = make(map[string]interface{}) - p.p["id"] = id - return p -} - -// Updates a network serviceProvider of a physical network -func (s *NetworkService) UpdateNetworkServiceProvider(p *UpdateNetworkServiceProviderParams) (*UpdateNetworkServiceProviderResponse, error) { - resp, err := s.cs.newRequest("updateNetworkServiceProvider", p.toURLValues()) - if err != nil { - return nil, err - } - - var r UpdateNetworkServiceProviderResponse - if err := json.Unmarshal(resp, &r); err != nil { - return nil, err - } - - // If we have a async client, we need to wait for the async result - if s.cs.async { - b, err := s.cs.GetAsyncJobResult(r.JobID, s.cs.timeout) - if err != nil { - if err == AsyncTimeoutErr { - return &r, err - } - return nil, err - } - - b, err = getRawValue(b) - if err != nil { - return nil, err - } - - if err := json.Unmarshal(b, &r); err != nil { - return nil, err - } - } - return &r, nil -} - -type UpdateNetworkServiceProviderResponse struct { - JobID string `json:"jobid,omitempty"` - Canenableindividualservice bool `json:"canenableindividualservice,omitempty"` - Destinationphysicalnetworkid string `json:"destinationphysicalnetworkid,omitempty"` - Id string `json:"id,omitempty"` - Name string `json:"name,omitempty"` - Physicalnetworkid string `json:"physicalnetworkid,omitempty"` - Servicelist []string `json:"servicelist,omitempty"` - State string `json:"state,omitempty"` -} - -type CreateStorageNetworkIpRangeParams struct { - p map[string]interface{} -} - -func (p *CreateStorageNetworkIpRangeParams) toURLValues() url.Values { - u := url.Values{} - if p.p == nil { - return u - } - if v, found := p.p["endip"]; found { - u.Set("endip", v.(string)) - } - if v, found := p.p["gateway"]; found { - u.Set("gateway", v.(string)) - } - if v, found := p.p["netmask"]; found { - u.Set("netmask", v.(string)) - } - if v, found := p.p["podid"]; found { - u.Set("podid", v.(string)) - } - if v, found := p.p["startip"]; found { - u.Set("startip", v.(string)) - } - if v, found := p.p["vlan"]; found { - vv := strconv.Itoa(v.(int)) - u.Set("vlan", vv) - } - return u -} - -func (p *CreateStorageNetworkIpRangeParams) SetEndip(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["endip"] = v - return -} - -func (p *CreateStorageNetworkIpRangeParams) SetGateway(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["gateway"] = v - return -} - -func (p *CreateStorageNetworkIpRangeParams) SetNetmask(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["netmask"] = v - return -} - -func (p *CreateStorageNetworkIpRangeParams) SetPodid(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["podid"] = v - return -} - -func (p *CreateStorageNetworkIpRangeParams) SetStartip(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["startip"] = v - return -} - -func (p *CreateStorageNetworkIpRangeParams) SetVlan(v int) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["vlan"] = v - return -} - -// You should always use this function to get a new CreateStorageNetworkIpRangeParams instance, -// as then you are sure you have configured all required params -func (s *NetworkService) NewCreateStorageNetworkIpRangeParams(gateway string, netmask string, podid string, startip string) *CreateStorageNetworkIpRangeParams { - p := &CreateStorageNetworkIpRangeParams{} - p.p = make(map[string]interface{}) - p.p["gateway"] = gateway - p.p["netmask"] = netmask - p.p["podid"] = podid - p.p["startip"] = startip - return p -} - -// Creates a Storage network IP range. -func (s *NetworkService) CreateStorageNetworkIpRange(p *CreateStorageNetworkIpRangeParams) (*CreateStorageNetworkIpRangeResponse, error) { - resp, err := s.cs.newRequest("createStorageNetworkIpRange", p.toURLValues()) - if err != nil { - return nil, err - } - - var r CreateStorageNetworkIpRangeResponse - if err := json.Unmarshal(resp, &r); err != nil { - return nil, err - } - - // If we have a async client, we need to wait for the async result - if s.cs.async { - b, err := s.cs.GetAsyncJobResult(r.JobID, s.cs.timeout) - if err != nil { - if err == AsyncTimeoutErr { - return &r, err - } - return nil, err - } - - b, err = getRawValue(b) - if err != nil { - return nil, err - } - - if err := json.Unmarshal(b, &r); err != nil { - return nil, err - } - } - return &r, nil -} - -type CreateStorageNetworkIpRangeResponse struct { - JobID string `json:"jobid,omitempty"` - Endip string `json:"endip,omitempty"` - Gateway string `json:"gateway,omitempty"` - Id string `json:"id,omitempty"` - Netmask string `json:"netmask,omitempty"` - Networkid string `json:"networkid,omitempty"` - Podid string `json:"podid,omitempty"` - Startip string `json:"startip,omitempty"` - Vlan int `json:"vlan,omitempty"` - Zoneid string `json:"zoneid,omitempty"` -} - -type DeleteStorageNetworkIpRangeParams struct { - p map[string]interface{} -} - -func (p *DeleteStorageNetworkIpRangeParams) toURLValues() url.Values { - u := url.Values{} - if p.p == nil { - return u - } - if v, found := p.p["id"]; found { - u.Set("id", v.(string)) - } - return u -} - -func (p *DeleteStorageNetworkIpRangeParams) SetId(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["id"] = v - return -} - -// You should always use this function to get a new DeleteStorageNetworkIpRangeParams instance, -// as then you are sure you have configured all required params -func (s *NetworkService) NewDeleteStorageNetworkIpRangeParams(id string) *DeleteStorageNetworkIpRangeParams { - p := &DeleteStorageNetworkIpRangeParams{} - p.p = make(map[string]interface{}) - p.p["id"] = id - return p -} - -// Deletes a storage network IP Range. -func (s *NetworkService) DeleteStorageNetworkIpRange(p *DeleteStorageNetworkIpRangeParams) (*DeleteStorageNetworkIpRangeResponse, error) { - resp, err := s.cs.newRequest("deleteStorageNetworkIpRange", p.toURLValues()) - if err != nil { - return nil, err - } - - var r DeleteStorageNetworkIpRangeResponse - if err := json.Unmarshal(resp, &r); err != nil { - return nil, err - } - - // If we have a async client, we need to wait for the async result - if s.cs.async { - b, err := s.cs.GetAsyncJobResult(r.JobID, s.cs.timeout) - if err != nil { - if err == AsyncTimeoutErr { - return &r, err - } - return nil, err - } - - if err := json.Unmarshal(b, &r); err != nil { - return nil, err - } - } - return &r, nil -} - -type DeleteStorageNetworkIpRangeResponse struct { - JobID string `json:"jobid,omitempty"` - Displaytext string `json:"displaytext,omitempty"` - Success bool `json:"success,omitempty"` -} - -type ListStorageNetworkIpRangeParams struct { - p map[string]interface{} -} - -func (p *ListStorageNetworkIpRangeParams) toURLValues() url.Values { - u := url.Values{} - if p.p == nil { - return u - } - if v, found := p.p["id"]; found { - u.Set("id", v.(string)) - } - if v, found := p.p["keyword"]; found { - u.Set("keyword", v.(string)) - } - if v, found := p.p["page"]; found { - vv := strconv.Itoa(v.(int)) - u.Set("page", vv) - } - if v, found := p.p["pagesize"]; found { - vv := strconv.Itoa(v.(int)) - u.Set("pagesize", vv) - } - if v, found := p.p["podid"]; found { - u.Set("podid", v.(string)) - } - if v, found := p.p["zoneid"]; found { - u.Set("zoneid", v.(string)) - } - return u -} - -func (p *ListStorageNetworkIpRangeParams) SetId(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["id"] = v - return -} - -func (p *ListStorageNetworkIpRangeParams) SetKeyword(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["keyword"] = v - return -} - -func (p *ListStorageNetworkIpRangeParams) SetPage(v int) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["page"] = v - return -} - -func (p *ListStorageNetworkIpRangeParams) SetPagesize(v int) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["pagesize"] = v - return -} - -func (p *ListStorageNetworkIpRangeParams) SetPodid(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["podid"] = v - return -} - -func (p *ListStorageNetworkIpRangeParams) SetZoneid(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["zoneid"] = v - return -} - -// You should always use this function to get a new ListStorageNetworkIpRangeParams instance, -// as then you are sure you have configured all required params -func (s *NetworkService) NewListStorageNetworkIpRangeParams() *ListStorageNetworkIpRangeParams { - p := &ListStorageNetworkIpRangeParams{} - p.p = make(map[string]interface{}) - return p -} - -// This is a courtesy helper function, which in some cases may not work as expected! -func (s *NetworkService) GetStorageNetworkIpRangeByID(id string, opts ...OptionFunc) (*StorageNetworkIpRange, int, error) { - p := &ListStorageNetworkIpRangeParams{} - p.p = make(map[string]interface{}) - - p.p["id"] = id - - for _, fn := range opts { - if err := fn(s.cs, p); err != nil { - return nil, -1, err - } - } - - l, err := s.ListStorageNetworkIpRange(p) - if err != nil { - if strings.Contains(err.Error(), fmt.Sprintf( - "Invalid parameter id value=%s due to incorrect long value format, "+ - "or entity does not exist", id)) { - return nil, 0, fmt.Errorf("No match found for %s: %+v", id, l) - } - return nil, -1, err - } - - if l.Count == 0 { - return nil, l.Count, fmt.Errorf("No match found for %s: %+v", id, l) - } - - if l.Count == 1 { - return l.StorageNetworkIpRange[0], l.Count, nil - } - return nil, l.Count, fmt.Errorf("There is more then one result for StorageNetworkIpRange UUID: %s!", id) -} - -// List a storage network IP range. -func (s *NetworkService) ListStorageNetworkIpRange(p *ListStorageNetworkIpRangeParams) (*ListStorageNetworkIpRangeResponse, error) { - resp, err := s.cs.newRequest("listStorageNetworkIpRange", p.toURLValues()) - if err != nil { - return nil, err - } - - var r ListStorageNetworkIpRangeResponse - if err := json.Unmarshal(resp, &r); err != nil { - return nil, err - } - return &r, nil -} - -type ListStorageNetworkIpRangeResponse struct { - Count int `json:"count"` - StorageNetworkIpRange []*StorageNetworkIpRange `json:"storagenetworkiprange"` -} - -type StorageNetworkIpRange struct { - Endip string `json:"endip,omitempty"` - Gateway string `json:"gateway,omitempty"` - Id string `json:"id,omitempty"` - Netmask string `json:"netmask,omitempty"` - Networkid string `json:"networkid,omitempty"` - Podid string `json:"podid,omitempty"` - Startip string `json:"startip,omitempty"` - Vlan int `json:"vlan,omitempty"` - Zoneid string `json:"zoneid,omitempty"` + JobID string `json:"jobid"` + Broadcastdomainrange string `json:"broadcastdomainrange"` + Domainid string `json:"domainid"` + Id string `json:"id"` + Isolationmethods string `json:"isolationmethods"` + Name string `json:"name"` + Networkspeed string `json:"networkspeed"` + State string `json:"state"` + Tags string `json:"tags"` + Vlan string `json:"vlan"` + Zoneid string `json:"zoneid"` } type UpdateStorageNetworkIpRangeParams struct { @@ -3038,987 +4259,19 @@ func (s *NetworkService) UpdateStorageNetworkIpRange(p *UpdateStorageNetworkIpRa return nil, err } } + return &r, nil } type UpdateStorageNetworkIpRangeResponse struct { - JobID string `json:"jobid,omitempty"` - Endip string `json:"endip,omitempty"` - Gateway string `json:"gateway,omitempty"` - Id string `json:"id,omitempty"` - Netmask string `json:"netmask,omitempty"` - Networkid string `json:"networkid,omitempty"` - Podid string `json:"podid,omitempty"` - Startip string `json:"startip,omitempty"` - Vlan int `json:"vlan,omitempty"` - Zoneid string `json:"zoneid,omitempty"` -} - -type ListPaloAltoFirewallNetworksParams struct { - p map[string]interface{} -} - -func (p *ListPaloAltoFirewallNetworksParams) toURLValues() url.Values { - u := url.Values{} - if p.p == nil { - return u - } - if v, found := p.p["keyword"]; found { - u.Set("keyword", v.(string)) - } - if v, found := p.p["lbdeviceid"]; found { - u.Set("lbdeviceid", v.(string)) - } - if v, found := p.p["page"]; found { - vv := strconv.Itoa(v.(int)) - u.Set("page", vv) - } - if v, found := p.p["pagesize"]; found { - vv := strconv.Itoa(v.(int)) - u.Set("pagesize", vv) - } - return u -} - -func (p *ListPaloAltoFirewallNetworksParams) SetKeyword(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["keyword"] = v - return -} - -func (p *ListPaloAltoFirewallNetworksParams) SetLbdeviceid(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["lbdeviceid"] = v - return -} - -func (p *ListPaloAltoFirewallNetworksParams) SetPage(v int) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["page"] = v - return -} - -func (p *ListPaloAltoFirewallNetworksParams) SetPagesize(v int) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["pagesize"] = v - return -} - -// You should always use this function to get a new ListPaloAltoFirewallNetworksParams instance, -// as then you are sure you have configured all required params -func (s *NetworkService) NewListPaloAltoFirewallNetworksParams(lbdeviceid string) *ListPaloAltoFirewallNetworksParams { - p := &ListPaloAltoFirewallNetworksParams{} - p.p = make(map[string]interface{}) - p.p["lbdeviceid"] = lbdeviceid - return p -} - -// This is a courtesy helper function, which in some cases may not work as expected! -func (s *NetworkService) GetPaloAltoFirewallNetworkID(keyword string, lbdeviceid string, opts ...OptionFunc) (string, int, error) { - p := &ListPaloAltoFirewallNetworksParams{} - p.p = make(map[string]interface{}) - - p.p["keyword"] = keyword - p.p["lbdeviceid"] = lbdeviceid - - for _, fn := range opts { - if err := fn(s.cs, p); err != nil { - return "", -1, err - } - } - - l, err := s.ListPaloAltoFirewallNetworks(p) - if err != nil { - return "", -1, err - } - - if l.Count == 0 { - return "", l.Count, fmt.Errorf("No match found for %s: %+v", keyword, l) - } - - if l.Count == 1 { - return l.PaloAltoFirewallNetworks[0].Id, l.Count, nil - } - - if l.Count > 1 { - for _, v := range l.PaloAltoFirewallNetworks { - if v.Name == keyword { - return v.Id, l.Count, nil - } - } - } - return "", l.Count, fmt.Errorf("Could not find an exact match for %s: %+v", keyword, l) -} - -// lists network that are using Palo Alto firewall device -func (s *NetworkService) ListPaloAltoFirewallNetworks(p *ListPaloAltoFirewallNetworksParams) (*ListPaloAltoFirewallNetworksResponse, error) { - resp, err := s.cs.newRequest("listPaloAltoFirewallNetworks", p.toURLValues()) - if err != nil { - return nil, err - } - - var r ListPaloAltoFirewallNetworksResponse - if err := json.Unmarshal(resp, &r); err != nil { - return nil, err - } - return &r, nil -} - -type ListPaloAltoFirewallNetworksResponse struct { - Count int `json:"count"` - PaloAltoFirewallNetworks []*PaloAltoFirewallNetwork `json:"paloaltofirewallnetwork"` -} - -type PaloAltoFirewallNetwork struct { - Account string `json:"account,omitempty"` - Aclid string `json:"aclid,omitempty"` - Acltype string `json:"acltype,omitempty"` - Broadcastdomaintype string `json:"broadcastdomaintype,omitempty"` - Broadcasturi string `json:"broadcasturi,omitempty"` - Canusefordeploy bool `json:"canusefordeploy,omitempty"` - Cidr string `json:"cidr,omitempty"` - Displaynetwork bool `json:"displaynetwork,omitempty"` - Displaytext string `json:"displaytext,omitempty"` - Dns1 string `json:"dns1,omitempty"` - Dns2 string `json:"dns2,omitempty"` - Domain string `json:"domain,omitempty"` - Domainid string `json:"domainid,omitempty"` - Gateway string `json:"gateway,omitempty"` - Id string `json:"id,omitempty"` - Ip6cidr string `json:"ip6cidr,omitempty"` - Ip6gateway string `json:"ip6gateway,omitempty"` - Isdefault bool `json:"isdefault,omitempty"` - Ispersistent bool `json:"ispersistent,omitempty"` - Issystem bool `json:"issystem,omitempty"` - Name string `json:"name,omitempty"` - Netmask string `json:"netmask,omitempty"` - Networkcidr string `json:"networkcidr,omitempty"` - Networkdomain string `json:"networkdomain,omitempty"` - Networkofferingavailability string `json:"networkofferingavailability,omitempty"` - Networkofferingconservemode bool `json:"networkofferingconservemode,omitempty"` - Networkofferingdisplaytext string `json:"networkofferingdisplaytext,omitempty"` - Networkofferingid string `json:"networkofferingid,omitempty"` - Networkofferingname string `json:"networkofferingname,omitempty"` - Physicalnetworkid string `json:"physicalnetworkid,omitempty"` - Project string `json:"project,omitempty"` - Projectid string `json:"projectid,omitempty"` - Related string `json:"related,omitempty"` - Reservediprange string `json:"reservediprange,omitempty"` - Restartrequired bool `json:"restartrequired,omitempty"` - Service []struct { - Capability []struct { - Canchooseservicecapability bool `json:"canchooseservicecapability,omitempty"` - Name string `json:"name,omitempty"` - Value string `json:"value,omitempty"` - } `json:"capability,omitempty"` - Name string `json:"name,omitempty"` - Provider []struct { - Canenableindividualservice bool `json:"canenableindividualservice,omitempty"` - Destinationphysicalnetworkid string `json:"destinationphysicalnetworkid,omitempty"` - Id string `json:"id,omitempty"` - Name string `json:"name,omitempty"` - Physicalnetworkid string `json:"physicalnetworkid,omitempty"` - Servicelist []string `json:"servicelist,omitempty"` - State string `json:"state,omitempty"` - } `json:"provider,omitempty"` - } `json:"service,omitempty"` - Specifyipranges bool `json:"specifyipranges,omitempty"` - State string `json:"state,omitempty"` - Strechedl2subnet bool `json:"strechedl2subnet,omitempty"` - Subdomainaccess bool `json:"subdomainaccess,omitempty"` - Tags []struct { - Account string `json:"account,omitempty"` - Customer string `json:"customer,omitempty"` - Domain string `json:"domain,omitempty"` - Domainid string `json:"domainid,omitempty"` - Key string `json:"key,omitempty"` - Project string `json:"project,omitempty"` - Projectid string `json:"projectid,omitempty"` - Resourceid string `json:"resourceid,omitempty"` - Resourcetype string `json:"resourcetype,omitempty"` - Value string `json:"value,omitempty"` - } `json:"tags,omitempty"` - Traffictype string `json:"traffictype,omitempty"` - Type string `json:"type,omitempty"` - Vlan string `json:"vlan,omitempty"` - Vpcid string `json:"vpcid,omitempty"` - Zoneid string `json:"zoneid,omitempty"` - Zonename string `json:"zonename,omitempty"` - Zonesnetworkspans []string `json:"zonesnetworkspans,omitempty"` -} - -type ListNetscalerLoadBalancerNetworksParams struct { - p map[string]interface{} -} - -func (p *ListNetscalerLoadBalancerNetworksParams) toURLValues() url.Values { - u := url.Values{} - if p.p == nil { - return u - } - if v, found := p.p["keyword"]; found { - u.Set("keyword", v.(string)) - } - if v, found := p.p["lbdeviceid"]; found { - u.Set("lbdeviceid", v.(string)) - } - if v, found := p.p["page"]; found { - vv := strconv.Itoa(v.(int)) - u.Set("page", vv) - } - if v, found := p.p["pagesize"]; found { - vv := strconv.Itoa(v.(int)) - u.Set("pagesize", vv) - } - return u -} - -func (p *ListNetscalerLoadBalancerNetworksParams) SetKeyword(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["keyword"] = v - return -} - -func (p *ListNetscalerLoadBalancerNetworksParams) SetLbdeviceid(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["lbdeviceid"] = v - return -} - -func (p *ListNetscalerLoadBalancerNetworksParams) SetPage(v int) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["page"] = v - return -} - -func (p *ListNetscalerLoadBalancerNetworksParams) SetPagesize(v int) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["pagesize"] = v - return -} - -// You should always use this function to get a new ListNetscalerLoadBalancerNetworksParams instance, -// as then you are sure you have configured all required params -func (s *NetworkService) NewListNetscalerLoadBalancerNetworksParams(lbdeviceid string) *ListNetscalerLoadBalancerNetworksParams { - p := &ListNetscalerLoadBalancerNetworksParams{} - p.p = make(map[string]interface{}) - p.p["lbdeviceid"] = lbdeviceid - return p -} - -// This is a courtesy helper function, which in some cases may not work as expected! -func (s *NetworkService) GetNetscalerLoadBalancerNetworkID(keyword string, lbdeviceid string, opts ...OptionFunc) (string, int, error) { - p := &ListNetscalerLoadBalancerNetworksParams{} - p.p = make(map[string]interface{}) - - p.p["keyword"] = keyword - p.p["lbdeviceid"] = lbdeviceid - - for _, fn := range opts { - if err := fn(s.cs, p); err != nil { - return "", -1, err - } - } - - l, err := s.ListNetscalerLoadBalancerNetworks(p) - if err != nil { - return "", -1, err - } - - if l.Count == 0 { - return "", l.Count, fmt.Errorf("No match found for %s: %+v", keyword, l) - } - - if l.Count == 1 { - return l.NetscalerLoadBalancerNetworks[0].Id, l.Count, nil - } - - if l.Count > 1 { - for _, v := range l.NetscalerLoadBalancerNetworks { - if v.Name == keyword { - return v.Id, l.Count, nil - } - } - } - return "", l.Count, fmt.Errorf("Could not find an exact match for %s: %+v", keyword, l) -} - -// lists network that are using a netscaler load balancer device -func (s *NetworkService) ListNetscalerLoadBalancerNetworks(p *ListNetscalerLoadBalancerNetworksParams) (*ListNetscalerLoadBalancerNetworksResponse, error) { - resp, err := s.cs.newRequest("listNetscalerLoadBalancerNetworks", p.toURLValues()) - if err != nil { - return nil, err - } - - var r ListNetscalerLoadBalancerNetworksResponse - if err := json.Unmarshal(resp, &r); err != nil { - return nil, err - } - return &r, nil -} - -type ListNetscalerLoadBalancerNetworksResponse struct { - Count int `json:"count"` - NetscalerLoadBalancerNetworks []*NetscalerLoadBalancerNetwork `json:"netscalerloadbalancernetwork"` -} - -type NetscalerLoadBalancerNetwork struct { - Account string `json:"account,omitempty"` - Aclid string `json:"aclid,omitempty"` - Acltype string `json:"acltype,omitempty"` - Broadcastdomaintype string `json:"broadcastdomaintype,omitempty"` - Broadcasturi string `json:"broadcasturi,omitempty"` - Canusefordeploy bool `json:"canusefordeploy,omitempty"` - Cidr string `json:"cidr,omitempty"` - Displaynetwork bool `json:"displaynetwork,omitempty"` - Displaytext string `json:"displaytext,omitempty"` - Dns1 string `json:"dns1,omitempty"` - Dns2 string `json:"dns2,omitempty"` - Domain string `json:"domain,omitempty"` - Domainid string `json:"domainid,omitempty"` - Gateway string `json:"gateway,omitempty"` - Id string `json:"id,omitempty"` - Ip6cidr string `json:"ip6cidr,omitempty"` - Ip6gateway string `json:"ip6gateway,omitempty"` - Isdefault bool `json:"isdefault,omitempty"` - Ispersistent bool `json:"ispersistent,omitempty"` - Issystem bool `json:"issystem,omitempty"` - Name string `json:"name,omitempty"` - Netmask string `json:"netmask,omitempty"` - Networkcidr string `json:"networkcidr,omitempty"` - Networkdomain string `json:"networkdomain,omitempty"` - Networkofferingavailability string `json:"networkofferingavailability,omitempty"` - Networkofferingconservemode bool `json:"networkofferingconservemode,omitempty"` - Networkofferingdisplaytext string `json:"networkofferingdisplaytext,omitempty"` - Networkofferingid string `json:"networkofferingid,omitempty"` - Networkofferingname string `json:"networkofferingname,omitempty"` - Physicalnetworkid string `json:"physicalnetworkid,omitempty"` - Project string `json:"project,omitempty"` - Projectid string `json:"projectid,omitempty"` - Related string `json:"related,omitempty"` - Reservediprange string `json:"reservediprange,omitempty"` - Restartrequired bool `json:"restartrequired,omitempty"` - Service []struct { - Capability []struct { - Canchooseservicecapability bool `json:"canchooseservicecapability,omitempty"` - Name string `json:"name,omitempty"` - Value string `json:"value,omitempty"` - } `json:"capability,omitempty"` - Name string `json:"name,omitempty"` - Provider []struct { - Canenableindividualservice bool `json:"canenableindividualservice,omitempty"` - Destinationphysicalnetworkid string `json:"destinationphysicalnetworkid,omitempty"` - Id string `json:"id,omitempty"` - Name string `json:"name,omitempty"` - Physicalnetworkid string `json:"physicalnetworkid,omitempty"` - Servicelist []string `json:"servicelist,omitempty"` - State string `json:"state,omitempty"` - } `json:"provider,omitempty"` - } `json:"service,omitempty"` - Specifyipranges bool `json:"specifyipranges,omitempty"` - State string `json:"state,omitempty"` - Strechedl2subnet bool `json:"strechedl2subnet,omitempty"` - Subdomainaccess bool `json:"subdomainaccess,omitempty"` - Tags []struct { - Account string `json:"account,omitempty"` - Customer string `json:"customer,omitempty"` - Domain string `json:"domain,omitempty"` - Domainid string `json:"domainid,omitempty"` - Key string `json:"key,omitempty"` - Project string `json:"project,omitempty"` - Projectid string `json:"projectid,omitempty"` - Resourceid string `json:"resourceid,omitempty"` - Resourcetype string `json:"resourcetype,omitempty"` - Value string `json:"value,omitempty"` - } `json:"tags,omitempty"` - Traffictype string `json:"traffictype,omitempty"` - Type string `json:"type,omitempty"` - Vlan string `json:"vlan,omitempty"` - Vpcid string `json:"vpcid,omitempty"` - Zoneid string `json:"zoneid,omitempty"` - Zonename string `json:"zonename,omitempty"` - Zonesnetworkspans []string `json:"zonesnetworkspans,omitempty"` -} - -type ListNiciraNvpDeviceNetworksParams struct { - p map[string]interface{} -} - -func (p *ListNiciraNvpDeviceNetworksParams) toURLValues() url.Values { - u := url.Values{} - if p.p == nil { - return u - } - if v, found := p.p["keyword"]; found { - u.Set("keyword", v.(string)) - } - if v, found := p.p["nvpdeviceid"]; found { - u.Set("nvpdeviceid", v.(string)) - } - if v, found := p.p["page"]; found { - vv := strconv.Itoa(v.(int)) - u.Set("page", vv) - } - if v, found := p.p["pagesize"]; found { - vv := strconv.Itoa(v.(int)) - u.Set("pagesize", vv) - } - return u -} - -func (p *ListNiciraNvpDeviceNetworksParams) SetKeyword(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["keyword"] = v - return -} - -func (p *ListNiciraNvpDeviceNetworksParams) SetNvpdeviceid(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["nvpdeviceid"] = v - return -} - -func (p *ListNiciraNvpDeviceNetworksParams) SetPage(v int) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["page"] = v - return -} - -func (p *ListNiciraNvpDeviceNetworksParams) SetPagesize(v int) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["pagesize"] = v - return -} - -// You should always use this function to get a new ListNiciraNvpDeviceNetworksParams instance, -// as then you are sure you have configured all required params -func (s *NetworkService) NewListNiciraNvpDeviceNetworksParams(nvpdeviceid string) *ListNiciraNvpDeviceNetworksParams { - p := &ListNiciraNvpDeviceNetworksParams{} - p.p = make(map[string]interface{}) - p.p["nvpdeviceid"] = nvpdeviceid - return p -} - -// This is a courtesy helper function, which in some cases may not work as expected! -func (s *NetworkService) GetNiciraNvpDeviceNetworkID(keyword string, nvpdeviceid string, opts ...OptionFunc) (string, int, error) { - p := &ListNiciraNvpDeviceNetworksParams{} - p.p = make(map[string]interface{}) - - p.p["keyword"] = keyword - p.p["nvpdeviceid"] = nvpdeviceid - - for _, fn := range opts { - if err := fn(s.cs, p); err != nil { - return "", -1, err - } - } - - l, err := s.ListNiciraNvpDeviceNetworks(p) - if err != nil { - return "", -1, err - } - - if l.Count == 0 { - return "", l.Count, fmt.Errorf("No match found for %s: %+v", keyword, l) - } - - if l.Count == 1 { - return l.NiciraNvpDeviceNetworks[0].Id, l.Count, nil - } - - if l.Count > 1 { - for _, v := range l.NiciraNvpDeviceNetworks { - if v.Name == keyword { - return v.Id, l.Count, nil - } - } - } - return "", l.Count, fmt.Errorf("Could not find an exact match for %s: %+v", keyword, l) -} - -// lists network that are using a nicira nvp device -func (s *NetworkService) ListNiciraNvpDeviceNetworks(p *ListNiciraNvpDeviceNetworksParams) (*ListNiciraNvpDeviceNetworksResponse, error) { - resp, err := s.cs.newRequest("listNiciraNvpDeviceNetworks", p.toURLValues()) - if err != nil { - return nil, err - } - - var r ListNiciraNvpDeviceNetworksResponse - if err := json.Unmarshal(resp, &r); err != nil { - return nil, err - } - return &r, nil -} - -type ListNiciraNvpDeviceNetworksResponse struct { - Count int `json:"count"` - NiciraNvpDeviceNetworks []*NiciraNvpDeviceNetwork `json:"niciranvpdevicenetwork"` -} - -type NiciraNvpDeviceNetwork struct { - Account string `json:"account,omitempty"` - Aclid string `json:"aclid,omitempty"` - Acltype string `json:"acltype,omitempty"` - Broadcastdomaintype string `json:"broadcastdomaintype,omitempty"` - Broadcasturi string `json:"broadcasturi,omitempty"` - Canusefordeploy bool `json:"canusefordeploy,omitempty"` - Cidr string `json:"cidr,omitempty"` - Displaynetwork bool `json:"displaynetwork,omitempty"` - Displaytext string `json:"displaytext,omitempty"` - Dns1 string `json:"dns1,omitempty"` - Dns2 string `json:"dns2,omitempty"` - Domain string `json:"domain,omitempty"` - Domainid string `json:"domainid,omitempty"` - Gateway string `json:"gateway,omitempty"` - Id string `json:"id,omitempty"` - Ip6cidr string `json:"ip6cidr,omitempty"` - Ip6gateway string `json:"ip6gateway,omitempty"` - Isdefault bool `json:"isdefault,omitempty"` - Ispersistent bool `json:"ispersistent,omitempty"` - Issystem bool `json:"issystem,omitempty"` - Name string `json:"name,omitempty"` - Netmask string `json:"netmask,omitempty"` - Networkcidr string `json:"networkcidr,omitempty"` - Networkdomain string `json:"networkdomain,omitempty"` - Networkofferingavailability string `json:"networkofferingavailability,omitempty"` - Networkofferingconservemode bool `json:"networkofferingconservemode,omitempty"` - Networkofferingdisplaytext string `json:"networkofferingdisplaytext,omitempty"` - Networkofferingid string `json:"networkofferingid,omitempty"` - Networkofferingname string `json:"networkofferingname,omitempty"` - Physicalnetworkid string `json:"physicalnetworkid,omitempty"` - Project string `json:"project,omitempty"` - Projectid string `json:"projectid,omitempty"` - Related string `json:"related,omitempty"` - Reservediprange string `json:"reservediprange,omitempty"` - Restartrequired bool `json:"restartrequired,omitempty"` - Service []struct { - Capability []struct { - Canchooseservicecapability bool `json:"canchooseservicecapability,omitempty"` - Name string `json:"name,omitempty"` - Value string `json:"value,omitempty"` - } `json:"capability,omitempty"` - Name string `json:"name,omitempty"` - Provider []struct { - Canenableindividualservice bool `json:"canenableindividualservice,omitempty"` - Destinationphysicalnetworkid string `json:"destinationphysicalnetworkid,omitempty"` - Id string `json:"id,omitempty"` - Name string `json:"name,omitempty"` - Physicalnetworkid string `json:"physicalnetworkid,omitempty"` - Servicelist []string `json:"servicelist,omitempty"` - State string `json:"state,omitempty"` - } `json:"provider,omitempty"` - } `json:"service,omitempty"` - Specifyipranges bool `json:"specifyipranges,omitempty"` - State string `json:"state,omitempty"` - Strechedl2subnet bool `json:"strechedl2subnet,omitempty"` - Subdomainaccess bool `json:"subdomainaccess,omitempty"` - Tags []struct { - Account string `json:"account,omitempty"` - Customer string `json:"customer,omitempty"` - Domain string `json:"domain,omitempty"` - Domainid string `json:"domainid,omitempty"` - Key string `json:"key,omitempty"` - Project string `json:"project,omitempty"` - Projectid string `json:"projectid,omitempty"` - Resourceid string `json:"resourceid,omitempty"` - Resourcetype string `json:"resourcetype,omitempty"` - Value string `json:"value,omitempty"` - } `json:"tags,omitempty"` - Traffictype string `json:"traffictype,omitempty"` - Type string `json:"type,omitempty"` - Vlan string `json:"vlan,omitempty"` - Vpcid string `json:"vpcid,omitempty"` - Zoneid string `json:"zoneid,omitempty"` - Zonename string `json:"zonename,omitempty"` - Zonesnetworkspans []string `json:"zonesnetworkspans,omitempty"` -} - -type ListNetworkIsolationMethodsParams struct { - p map[string]interface{} -} - -func (p *ListNetworkIsolationMethodsParams) toURLValues() url.Values { - u := url.Values{} - if p.p == nil { - return u - } - if v, found := p.p["keyword"]; found { - u.Set("keyword", v.(string)) - } - if v, found := p.p["page"]; found { - vv := strconv.Itoa(v.(int)) - u.Set("page", vv) - } - if v, found := p.p["pagesize"]; found { - vv := strconv.Itoa(v.(int)) - u.Set("pagesize", vv) - } - return u -} - -func (p *ListNetworkIsolationMethodsParams) SetKeyword(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["keyword"] = v - return -} - -func (p *ListNetworkIsolationMethodsParams) SetPage(v int) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["page"] = v - return -} - -func (p *ListNetworkIsolationMethodsParams) SetPagesize(v int) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["pagesize"] = v - return -} - -// You should always use this function to get a new ListNetworkIsolationMethodsParams instance, -// as then you are sure you have configured all required params -func (s *NetworkService) NewListNetworkIsolationMethodsParams() *ListNetworkIsolationMethodsParams { - p := &ListNetworkIsolationMethodsParams{} - p.p = make(map[string]interface{}) - return p -} - -// Lists supported methods of network isolation -func (s *NetworkService) ListNetworkIsolationMethods(p *ListNetworkIsolationMethodsParams) (*ListNetworkIsolationMethodsResponse, error) { - resp, err := s.cs.newRequest("listNetworkIsolationMethods", p.toURLValues()) - if err != nil { - return nil, err - } - - var r ListNetworkIsolationMethodsResponse - if err := json.Unmarshal(resp, &r); err != nil { - return nil, err - } - return &r, nil -} - -type ListNetworkIsolationMethodsResponse struct { - Count int `json:"count"` - NetworkIsolationMethods []*NetworkIsolationMethod `json:"networkisolationmethod"` -} - -type NetworkIsolationMethod struct { - Name string `json:"name,omitempty"` -} - -type AddOpenDaylightControllerParams struct { - p map[string]interface{} -} - -func (p *AddOpenDaylightControllerParams) toURLValues() url.Values { - u := url.Values{} - if p.p == nil { - return u - } - if v, found := p.p["password"]; found { - u.Set("password", v.(string)) - } - if v, found := p.p["physicalnetworkid"]; found { - u.Set("physicalnetworkid", v.(string)) - } - if v, found := p.p["url"]; found { - u.Set("url", v.(string)) - } - if v, found := p.p["username"]; found { - u.Set("username", v.(string)) - } - return u -} - -func (p *AddOpenDaylightControllerParams) SetPassword(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["password"] = v - return -} - -func (p *AddOpenDaylightControllerParams) SetPhysicalnetworkid(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["physicalnetworkid"] = v - return -} - -func (p *AddOpenDaylightControllerParams) SetUrl(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["url"] = v - return -} - -func (p *AddOpenDaylightControllerParams) SetUsername(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["username"] = v - return -} - -// You should always use this function to get a new AddOpenDaylightControllerParams instance, -// as then you are sure you have configured all required params -func (s *NetworkService) NewAddOpenDaylightControllerParams(password string, physicalnetworkid string, url string, username string) *AddOpenDaylightControllerParams { - p := &AddOpenDaylightControllerParams{} - p.p = make(map[string]interface{}) - p.p["password"] = password - p.p["physicalnetworkid"] = physicalnetworkid - p.p["url"] = url - p.p["username"] = username - return p -} - -// Adds an OpenDyalight controler -func (s *NetworkService) AddOpenDaylightController(p *AddOpenDaylightControllerParams) (*AddOpenDaylightControllerResponse, error) { - resp, err := s.cs.newRequest("addOpenDaylightController", p.toURLValues()) - if err != nil { - return nil, err - } - - var r AddOpenDaylightControllerResponse - if err := json.Unmarshal(resp, &r); err != nil { - return nil, err - } - - // If we have a async client, we need to wait for the async result - if s.cs.async { - b, err := s.cs.GetAsyncJobResult(r.JobID, s.cs.timeout) - if err != nil { - if err == AsyncTimeoutErr { - return &r, err - } - return nil, err - } - - b, err = getRawValue(b) - if err != nil { - return nil, err - } - - if err := json.Unmarshal(b, &r); err != nil { - return nil, err - } - } - return &r, nil -} - -type AddOpenDaylightControllerResponse struct { - JobID string `json:"jobid,omitempty"` - Id string `json:"id,omitempty"` - Name string `json:"name,omitempty"` - Physicalnetworkid string `json:"physicalnetworkid,omitempty"` - Url string `json:"url,omitempty"` - Username string `json:"username,omitempty"` -} - -type DeleteOpenDaylightControllerParams struct { - p map[string]interface{} -} - -func (p *DeleteOpenDaylightControllerParams) toURLValues() url.Values { - u := url.Values{} - if p.p == nil { - return u - } - if v, found := p.p["id"]; found { - u.Set("id", v.(string)) - } - return u -} - -func (p *DeleteOpenDaylightControllerParams) SetId(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["id"] = v - return -} - -// You should always use this function to get a new DeleteOpenDaylightControllerParams instance, -// as then you are sure you have configured all required params -func (s *NetworkService) NewDeleteOpenDaylightControllerParams(id string) *DeleteOpenDaylightControllerParams { - p := &DeleteOpenDaylightControllerParams{} - p.p = make(map[string]interface{}) - p.p["id"] = id - return p -} - -// Removes an OpenDyalight controler -func (s *NetworkService) DeleteOpenDaylightController(p *DeleteOpenDaylightControllerParams) (*DeleteOpenDaylightControllerResponse, error) { - resp, err := s.cs.newRequest("deleteOpenDaylightController", p.toURLValues()) - if err != nil { - return nil, err - } - - var r DeleteOpenDaylightControllerResponse - if err := json.Unmarshal(resp, &r); err != nil { - return nil, err - } - - // If we have a async client, we need to wait for the async result - if s.cs.async { - b, err := s.cs.GetAsyncJobResult(r.JobID, s.cs.timeout) - if err != nil { - if err == AsyncTimeoutErr { - return &r, err - } - return nil, err - } - - b, err = getRawValue(b) - if err != nil { - return nil, err - } - - if err := json.Unmarshal(b, &r); err != nil { - return nil, err - } - } - return &r, nil -} - -type DeleteOpenDaylightControllerResponse struct { - JobID string `json:"jobid,omitempty"` - Id string `json:"id,omitempty"` - Name string `json:"name,omitempty"` - Physicalnetworkid string `json:"physicalnetworkid,omitempty"` - Url string `json:"url,omitempty"` - Username string `json:"username,omitempty"` -} - -type ListOpenDaylightControllersParams struct { - p map[string]interface{} -} - -func (p *ListOpenDaylightControllersParams) toURLValues() url.Values { - u := url.Values{} - if p.p == nil { - return u - } - if v, found := p.p["id"]; found { - u.Set("id", v.(string)) - } - if v, found := p.p["physicalnetworkid"]; found { - u.Set("physicalnetworkid", v.(string)) - } - return u -} - -func (p *ListOpenDaylightControllersParams) SetId(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["id"] = v - return -} - -func (p *ListOpenDaylightControllersParams) SetPhysicalnetworkid(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["physicalnetworkid"] = v - return -} - -// You should always use this function to get a new ListOpenDaylightControllersParams instance, -// as then you are sure you have configured all required params -func (s *NetworkService) NewListOpenDaylightControllersParams() *ListOpenDaylightControllersParams { - p := &ListOpenDaylightControllersParams{} - p.p = make(map[string]interface{}) - return p -} - -// This is a courtesy helper function, which in some cases may not work as expected! -func (s *NetworkService) GetOpenDaylightControllerByID(id string, opts ...OptionFunc) (*OpenDaylightController, int, error) { - p := &ListOpenDaylightControllersParams{} - p.p = make(map[string]interface{}) - - p.p["id"] = id - - for _, fn := range opts { - if err := fn(s.cs, p); err != nil { - return nil, -1, err - } - } - - l, err := s.ListOpenDaylightControllers(p) - if err != nil { - if strings.Contains(err.Error(), fmt.Sprintf( - "Invalid parameter id value=%s due to incorrect long value format, "+ - "or entity does not exist", id)) { - return nil, 0, fmt.Errorf("No match found for %s: %+v", id, l) - } - return nil, -1, err - } - - if l.Count == 0 { - return nil, l.Count, fmt.Errorf("No match found for %s: %+v", id, l) - } - - if l.Count == 1 { - return l.OpenDaylightControllers[0], l.Count, nil - } - return nil, l.Count, fmt.Errorf("There is more then one result for OpenDaylightController UUID: %s!", id) -} - -// Lists OpenDyalight controllers -func (s *NetworkService) ListOpenDaylightControllers(p *ListOpenDaylightControllersParams) (*ListOpenDaylightControllersResponse, error) { - resp, err := s.cs.newRequest("listOpenDaylightControllers", p.toURLValues()) - if err != nil { - return nil, err - } - - var r ListOpenDaylightControllersResponse - if err := json.Unmarshal(resp, &r); err != nil { - return nil, err - } - return &r, nil -} - -type ListOpenDaylightControllersResponse struct { - Count int `json:"count"` - OpenDaylightControllers []*OpenDaylightController `json:"opendaylightcontroller"` -} - -type OpenDaylightController struct { - Id string `json:"id,omitempty"` - Name string `json:"name,omitempty"` - Physicalnetworkid string `json:"physicalnetworkid,omitempty"` - Url string `json:"url,omitempty"` - Username string `json:"username,omitempty"` + JobID string `json:"jobid"` + Endip string `json:"endip"` + Gateway string `json:"gateway"` + Id string `json:"id"` + Netmask string `json:"netmask"` + Networkid string `json:"networkid"` + Podid string `json:"podid"` + Startip string `json:"startip"` + Vlan int `json:"vlan"` + Zoneid string `json:"zoneid"` } diff --git a/vendor/github.com/xanzy/go-cloudstack/cloudstack/NicService.go b/vendor/github.com/xanzy/go-cloudstack/cloudstack/NicService.go index d83e07567..525f1b99b 100644 --- a/vendor/github.com/xanzy/go-cloudstack/cloudstack/NicService.go +++ b/vendor/github.com/xanzy/go-cloudstack/cloudstack/NicService.go @@ -1,5 +1,5 @@ // -// Copyright 2016, Sander van Harmelen +// Copyright 2018, Sander van Harmelen // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -96,337 +96,21 @@ func (s *NicService) AddIpToNic(p *AddIpToNicParams) (*AddIpToNicResponse, error return nil, err } } + return &r, nil } type AddIpToNicResponse struct { - JobID string `json:"jobid,omitempty"` - Id string `json:"id,omitempty"` - Ipaddress string `json:"ipaddress,omitempty"` - Networkid string `json:"networkid,omitempty"` - Nicid string `json:"nicid,omitempty"` - Virtualmachineid string `json:"virtualmachineid,omitempty"` -} - -type RemoveIpFromNicParams struct { - p map[string]interface{} -} - -func (p *RemoveIpFromNicParams) toURLValues() url.Values { - u := url.Values{} - if p.p == nil { - return u - } - if v, found := p.p["id"]; found { - u.Set("id", v.(string)) - } - return u -} - -func (p *RemoveIpFromNicParams) SetId(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["id"] = v - return -} - -// You should always use this function to get a new RemoveIpFromNicParams instance, -// as then you are sure you have configured all required params -func (s *NicService) NewRemoveIpFromNicParams(id string) *RemoveIpFromNicParams { - p := &RemoveIpFromNicParams{} - p.p = make(map[string]interface{}) - p.p["id"] = id - return p -} - -// Removes secondary IP from the NIC. -func (s *NicService) RemoveIpFromNic(p *RemoveIpFromNicParams) (*RemoveIpFromNicResponse, error) { - resp, err := s.cs.newRequest("removeIpFromNic", p.toURLValues()) - if err != nil { - return nil, err - } - - var r RemoveIpFromNicResponse - if err := json.Unmarshal(resp, &r); err != nil { - return nil, err - } - - // If we have a async client, we need to wait for the async result - if s.cs.async { - b, err := s.cs.GetAsyncJobResult(r.JobID, s.cs.timeout) - if err != nil { - if err == AsyncTimeoutErr { - return &r, err - } - return nil, err - } - - if err := json.Unmarshal(b, &r); err != nil { - return nil, err - } - } - return &r, nil -} - -type RemoveIpFromNicResponse struct { - JobID string `json:"jobid,omitempty"` - Displaytext string `json:"displaytext,omitempty"` - Success bool `json:"success,omitempty"` -} - -type UpdateVmNicIpParams struct { - p map[string]interface{} -} - -func (p *UpdateVmNicIpParams) toURLValues() url.Values { - u := url.Values{} - if p.p == nil { - return u - } - if v, found := p.p["ipaddress"]; found { - u.Set("ipaddress", v.(string)) - } - if v, found := p.p["nicid"]; found { - u.Set("nicid", v.(string)) - } - return u -} - -func (p *UpdateVmNicIpParams) SetIpaddress(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["ipaddress"] = v - return -} - -func (p *UpdateVmNicIpParams) SetNicid(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["nicid"] = v - return -} - -// You should always use this function to get a new UpdateVmNicIpParams instance, -// as then you are sure you have configured all required params -func (s *NicService) NewUpdateVmNicIpParams(nicid string) *UpdateVmNicIpParams { - p := &UpdateVmNicIpParams{} - p.p = make(map[string]interface{}) - p.p["nicid"] = nicid - return p -} - -// Update the default Ip of a VM Nic -func (s *NicService) UpdateVmNicIp(p *UpdateVmNicIpParams) (*UpdateVmNicIpResponse, error) { - resp, err := s.cs.newRequest("updateVmNicIp", p.toURLValues()) - if err != nil { - return nil, err - } - - var r UpdateVmNicIpResponse - if err := json.Unmarshal(resp, &r); err != nil { - return nil, err - } - - // If we have a async client, we need to wait for the async result - if s.cs.async { - b, err := s.cs.GetAsyncJobResult(r.JobID, s.cs.timeout) - if err != nil { - if err == AsyncTimeoutErr { - return &r, err - } - return nil, err - } - - b, err = getRawValue(b) - if err != nil { - return nil, err - } - - if err := json.Unmarshal(b, &r); err != nil { - return nil, err - } - } - return &r, nil -} - -type UpdateVmNicIpResponse struct { - JobID string `json:"jobid,omitempty"` - Account string `json:"account,omitempty"` - Affinitygroup []struct { - Account string `json:"account,omitempty"` - Description string `json:"description,omitempty"` - Domain string `json:"domain,omitempty"` - Domainid string `json:"domainid,omitempty"` - Id string `json:"id,omitempty"` - Name string `json:"name,omitempty"` - Project string `json:"project,omitempty"` - Projectid string `json:"projectid,omitempty"` - Type string `json:"type,omitempty"` - VirtualmachineIds []string `json:"virtualmachineIds,omitempty"` - } `json:"affinitygroup,omitempty"` - Cpunumber int `json:"cpunumber,omitempty"` - Cpuspeed int `json:"cpuspeed,omitempty"` - Cpuused string `json:"cpuused,omitempty"` - Created string `json:"created,omitempty"` - Details map[string]string `json:"details,omitempty"` - Diskioread int64 `json:"diskioread,omitempty"` - Diskiowrite int64 `json:"diskiowrite,omitempty"` - Diskkbsread int64 `json:"diskkbsread,omitempty"` - Diskkbswrite int64 `json:"diskkbswrite,omitempty"` - Diskofferingid string `json:"diskofferingid,omitempty"` - Diskofferingname string `json:"diskofferingname,omitempty"` - Displayname string `json:"displayname,omitempty"` - Displayvm bool `json:"displayvm,omitempty"` - Domain string `json:"domain,omitempty"` - Domainid string `json:"domainid,omitempty"` - Forvirtualnetwork bool `json:"forvirtualnetwork,omitempty"` - Group string `json:"group,omitempty"` - Groupid string `json:"groupid,omitempty"` - Guestosid string `json:"guestosid,omitempty"` - Haenable bool `json:"haenable,omitempty"` - Hostid string `json:"hostid,omitempty"` - Hostname string `json:"hostname,omitempty"` - Hypervisor string `json:"hypervisor,omitempty"` - Id string `json:"id,omitempty"` - Instancename string `json:"instancename,omitempty"` - Isdynamicallyscalable bool `json:"isdynamicallyscalable,omitempty"` - Isodisplaytext string `json:"isodisplaytext,omitempty"` - Isoid string `json:"isoid,omitempty"` - Isoname string `json:"isoname,omitempty"` - Keypair string `json:"keypair,omitempty"` - Memory int `json:"memory,omitempty"` - Name string `json:"name,omitempty"` - Networkkbsread int64 `json:"networkkbsread,omitempty"` - Networkkbswrite int64 `json:"networkkbswrite,omitempty"` - Nic []struct { - Broadcasturi string `json:"broadcasturi,omitempty"` - Deviceid string `json:"deviceid,omitempty"` - Gateway string `json:"gateway,omitempty"` - Id string `json:"id,omitempty"` - Ip6address string `json:"ip6address,omitempty"` - Ip6cidr string `json:"ip6cidr,omitempty"` - Ip6gateway string `json:"ip6gateway,omitempty"` - Ipaddress string `json:"ipaddress,omitempty"` - Isdefault bool `json:"isdefault,omitempty"` - Isolationuri string `json:"isolationuri,omitempty"` - Macaddress string `json:"macaddress,omitempty"` - Netmask string `json:"netmask,omitempty"` - Networkid string `json:"networkid,omitempty"` - Networkname string `json:"networkname,omitempty"` - Secondaryip []struct { - Id string `json:"id,omitempty"` - Ipaddress string `json:"ipaddress,omitempty"` - } `json:"secondaryip,omitempty"` - Traffictype string `json:"traffictype,omitempty"` - Type string `json:"type,omitempty"` - Virtualmachineid string `json:"virtualmachineid,omitempty"` - } `json:"nic,omitempty"` - Ostypeid int64 `json:"ostypeid,omitempty"` - Password string `json:"password,omitempty"` - Passwordenabled bool `json:"passwordenabled,omitempty"` - Project string `json:"project,omitempty"` - Projectid string `json:"projectid,omitempty"` - Publicip string `json:"publicip,omitempty"` - Publicipid string `json:"publicipid,omitempty"` - Rootdeviceid int64 `json:"rootdeviceid,omitempty"` - Rootdevicetype string `json:"rootdevicetype,omitempty"` - Securitygroup []struct { - Account string `json:"account,omitempty"` - Description string `json:"description,omitempty"` - Domain string `json:"domain,omitempty"` - Domainid string `json:"domainid,omitempty"` - Egressrule []struct { - Account string `json:"account,omitempty"` - Cidr string `json:"cidr,omitempty"` - Endport int `json:"endport,omitempty"` - Icmpcode int `json:"icmpcode,omitempty"` - Icmptype int `json:"icmptype,omitempty"` - Protocol string `json:"protocol,omitempty"` - Ruleid string `json:"ruleid,omitempty"` - Securitygroupname string `json:"securitygroupname,omitempty"` - Startport int `json:"startport,omitempty"` - Tags []struct { - Account string `json:"account,omitempty"` - Customer string `json:"customer,omitempty"` - Domain string `json:"domain,omitempty"` - Domainid string `json:"domainid,omitempty"` - Key string `json:"key,omitempty"` - Project string `json:"project,omitempty"` - Projectid string `json:"projectid,omitempty"` - Resourceid string `json:"resourceid,omitempty"` - Resourcetype string `json:"resourcetype,omitempty"` - Value string `json:"value,omitempty"` - } `json:"tags,omitempty"` - } `json:"egressrule,omitempty"` - Id string `json:"id,omitempty"` - Ingressrule []struct { - Account string `json:"account,omitempty"` - Cidr string `json:"cidr,omitempty"` - Endport int `json:"endport,omitempty"` - Icmpcode int `json:"icmpcode,omitempty"` - Icmptype int `json:"icmptype,omitempty"` - Protocol string `json:"protocol,omitempty"` - Ruleid string `json:"ruleid,omitempty"` - Securitygroupname string `json:"securitygroupname,omitempty"` - Startport int `json:"startport,omitempty"` - Tags []struct { - Account string `json:"account,omitempty"` - Customer string `json:"customer,omitempty"` - Domain string `json:"domain,omitempty"` - Domainid string `json:"domainid,omitempty"` - Key string `json:"key,omitempty"` - Project string `json:"project,omitempty"` - Projectid string `json:"projectid,omitempty"` - Resourceid string `json:"resourceid,omitempty"` - Resourcetype string `json:"resourcetype,omitempty"` - Value string `json:"value,omitempty"` - } `json:"tags,omitempty"` - } `json:"ingressrule,omitempty"` - Name string `json:"name,omitempty"` - Project string `json:"project,omitempty"` - Projectid string `json:"projectid,omitempty"` - Tags []struct { - Account string `json:"account,omitempty"` - Customer string `json:"customer,omitempty"` - Domain string `json:"domain,omitempty"` - Domainid string `json:"domainid,omitempty"` - Key string `json:"key,omitempty"` - Project string `json:"project,omitempty"` - Projectid string `json:"projectid,omitempty"` - Resourceid string `json:"resourceid,omitempty"` - Resourcetype string `json:"resourcetype,omitempty"` - Value string `json:"value,omitempty"` - } `json:"tags,omitempty"` - Virtualmachinecount int `json:"virtualmachinecount,omitempty"` - Virtualmachineids []string `json:"virtualmachineids,omitempty"` - } `json:"securitygroup,omitempty"` - Serviceofferingid string `json:"serviceofferingid,omitempty"` - Serviceofferingname string `json:"serviceofferingname,omitempty"` - Servicestate string `json:"servicestate,omitempty"` - State string `json:"state,omitempty"` - Tags []struct { - Account string `json:"account,omitempty"` - Customer string `json:"customer,omitempty"` - Domain string `json:"domain,omitempty"` - Domainid string `json:"domainid,omitempty"` - Key string `json:"key,omitempty"` - Project string `json:"project,omitempty"` - Projectid string `json:"projectid,omitempty"` - Resourceid string `json:"resourceid,omitempty"` - Resourcetype string `json:"resourcetype,omitempty"` - Value string `json:"value,omitempty"` - } `json:"tags,omitempty"` - Templatedisplaytext string `json:"templatedisplaytext,omitempty"` - Templateid string `json:"templateid,omitempty"` - Templatename string `json:"templatename,omitempty"` - Userid string `json:"userid,omitempty"` - Username string `json:"username,omitempty"` - Vgpu string `json:"vgpu,omitempty"` - Zoneid string `json:"zoneid,omitempty"` - Zonename string `json:"zonename,omitempty"` + JobID string `json:"jobid"` + Id string `json:"id"` + Ipaddress string `json:"ipaddress"` + Networkid string `json:"networkid"` + Nicid string `json:"nicid"` + Secondaryip []struct { + Id string `json:"id"` + Ipaddress string `json:"ipaddress"` + } `json:"secondaryip"` + Virtualmachineid string `json:"virtualmachineid"` } type ListNicsParams struct { @@ -541,6 +225,7 @@ func (s *NicService) ListNics(p *ListNicsParams) (*ListNicsResponse, error) { if err := json.Unmarshal(resp, &r); err != nil { return nil, err } + return &r, nil } @@ -550,25 +235,282 @@ type ListNicsResponse struct { } type Nic struct { - Broadcasturi string `json:"broadcasturi,omitempty"` - Deviceid string `json:"deviceid,omitempty"` - Gateway string `json:"gateway,omitempty"` - Id string `json:"id,omitempty"` - Ip6address string `json:"ip6address,omitempty"` - Ip6cidr string `json:"ip6cidr,omitempty"` - Ip6gateway string `json:"ip6gateway,omitempty"` - Ipaddress string `json:"ipaddress,omitempty"` - Isdefault bool `json:"isdefault,omitempty"` - Isolationuri string `json:"isolationuri,omitempty"` - Macaddress string `json:"macaddress,omitempty"` - Netmask string `json:"netmask,omitempty"` - Networkid string `json:"networkid,omitempty"` - Networkname string `json:"networkname,omitempty"` - Secondaryip []struct { - Id string `json:"id,omitempty"` - Ipaddress string `json:"ipaddress,omitempty"` - } `json:"secondaryip,omitempty"` - Traffictype string `json:"traffictype,omitempty"` - Type string `json:"type,omitempty"` - Virtualmachineid string `json:"virtualmachineid,omitempty"` + Broadcasturi string `json:"broadcasturi"` + Deviceid string `json:"deviceid"` + Extradhcpoption []string `json:"extradhcpoption"` + Gateway string `json:"gateway"` + Id string `json:"id"` + Ip6address string `json:"ip6address"` + Ip6cidr string `json:"ip6cidr"` + Ip6gateway string `json:"ip6gateway"` + Ipaddress string `json:"ipaddress"` + Isdefault bool `json:"isdefault"` + Isolationuri string `json:"isolationuri"` + Macaddress string `json:"macaddress"` + Netmask string `json:"netmask"` + Networkid string `json:"networkid"` + Networkname string `json:"networkname"` + Nsxlogicalswitch string `json:"nsxlogicalswitch"` + Nsxlogicalswitchport string `json:"nsxlogicalswitchport"` + Secondaryip []struct { + Id string `json:"id"` + Ipaddress string `json:"ipaddress"` + } `json:"secondaryip"` + Traffictype string `json:"traffictype"` + Type string `json:"type"` + Virtualmachineid string `json:"virtualmachineid"` +} + +type RemoveIpFromNicParams struct { + p map[string]interface{} +} + +func (p *RemoveIpFromNicParams) toURLValues() url.Values { + u := url.Values{} + if p.p == nil { + return u + } + if v, found := p.p["id"]; found { + u.Set("id", v.(string)) + } + return u +} + +func (p *RemoveIpFromNicParams) SetId(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["id"] = v + return +} + +// You should always use this function to get a new RemoveIpFromNicParams instance, +// as then you are sure you have configured all required params +func (s *NicService) NewRemoveIpFromNicParams(id string) *RemoveIpFromNicParams { + p := &RemoveIpFromNicParams{} + p.p = make(map[string]interface{}) + p.p["id"] = id + return p +} + +// Removes secondary IP from the NIC. +func (s *NicService) RemoveIpFromNic(p *RemoveIpFromNicParams) (*RemoveIpFromNicResponse, error) { + resp, err := s.cs.newRequest("removeIpFromNic", p.toURLValues()) + if err != nil { + return nil, err + } + + var r RemoveIpFromNicResponse + if err := json.Unmarshal(resp, &r); err != nil { + return nil, err + } + + // If we have a async client, we need to wait for the async result + if s.cs.async { + b, err := s.cs.GetAsyncJobResult(r.JobID, s.cs.timeout) + if err != nil { + if err == AsyncTimeoutErr { + return &r, err + } + return nil, err + } + + if err := json.Unmarshal(b, &r); err != nil { + return nil, err + } + } + + return &r, nil +} + +type RemoveIpFromNicResponse struct { + JobID string `json:"jobid"` + Displaytext string `json:"displaytext"` + Success bool `json:"success"` +} + +type UpdateVmNicIpParams struct { + p map[string]interface{} +} + +func (p *UpdateVmNicIpParams) toURLValues() url.Values { + u := url.Values{} + if p.p == nil { + return u + } + if v, found := p.p["ipaddress"]; found { + u.Set("ipaddress", v.(string)) + } + if v, found := p.p["nicid"]; found { + u.Set("nicid", v.(string)) + } + return u +} + +func (p *UpdateVmNicIpParams) SetIpaddress(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["ipaddress"] = v + return +} + +func (p *UpdateVmNicIpParams) SetNicid(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["nicid"] = v + return +} + +// You should always use this function to get a new UpdateVmNicIpParams instance, +// as then you are sure you have configured all required params +func (s *NicService) NewUpdateVmNicIpParams(nicid string) *UpdateVmNicIpParams { + p := &UpdateVmNicIpParams{} + p.p = make(map[string]interface{}) + p.p["nicid"] = nicid + return p +} + +// Update the default Ip of a VM Nic +func (s *NicService) UpdateVmNicIp(p *UpdateVmNicIpParams) (*UpdateVmNicIpResponse, error) { + resp, err := s.cs.newRequest("updateVmNicIp", p.toURLValues()) + if err != nil { + return nil, err + } + + var r UpdateVmNicIpResponse + if err := json.Unmarshal(resp, &r); err != nil { + return nil, err + } + + // If we have a async client, we need to wait for the async result + if s.cs.async { + b, err := s.cs.GetAsyncJobResult(r.JobID, s.cs.timeout) + if err != nil { + if err == AsyncTimeoutErr { + return &r, err + } + return nil, err + } + + b, err = getRawValue(b) + if err != nil { + return nil, err + } + + if err := json.Unmarshal(b, &r); err != nil { + return nil, err + } + } + + return &r, nil +} + +type UpdateVmNicIpResponse struct { + JobID string `json:"jobid"` + Account string `json:"account"` + Affinitygroup []UpdateVmNicIpResponseAffinitygroup `json:"affinitygroup"` + Cpunumber int `json:"cpunumber"` + Cpuspeed int `json:"cpuspeed"` + Cpuused string `json:"cpuused"` + Created string `json:"created"` + Details map[string]string `json:"details"` + Diskioread int64 `json:"diskioread"` + Diskiowrite int64 `json:"diskiowrite"` + Diskkbsread int64 `json:"diskkbsread"` + Diskkbswrite int64 `json:"diskkbswrite"` + Diskofferingid string `json:"diskofferingid"` + Diskofferingname string `json:"diskofferingname"` + Displayname string `json:"displayname"` + Displayvm bool `json:"displayvm"` + Domain string `json:"domain"` + Domainid string `json:"domainid"` + Forvirtualnetwork bool `json:"forvirtualnetwork"` + Group string `json:"group"` + Groupid string `json:"groupid"` + Guestosid string `json:"guestosid"` + Haenable bool `json:"haenable"` + Hostid string `json:"hostid"` + Hostname string `json:"hostname"` + Hypervisor string `json:"hypervisor"` + Id string `json:"id"` + Instancename string `json:"instancename"` + Isdynamicallyscalable bool `json:"isdynamicallyscalable"` + Isodisplaytext string `json:"isodisplaytext"` + Isoid string `json:"isoid"` + Isoname string `json:"isoname"` + Keypair string `json:"keypair"` + Memory int `json:"memory"` + Memoryintfreekbs int64 `json:"memoryintfreekbs"` + Memorykbs int64 `json:"memorykbs"` + Memorytargetkbs int64 `json:"memorytargetkbs"` + Name string `json:"name"` + Networkkbsread int64 `json:"networkkbsread"` + Networkkbswrite int64 `json:"networkkbswrite"` + Nic []Nic `json:"nic"` + Ostypeid int64 `json:"ostypeid"` + Password string `json:"password"` + Passwordenabled bool `json:"passwordenabled"` + Project string `json:"project"` + Projectid string `json:"projectid"` + Publicip string `json:"publicip"` + Publicipid string `json:"publicipid"` + Rootdeviceid int64 `json:"rootdeviceid"` + Rootdevicetype string `json:"rootdevicetype"` + Securitygroup []UpdateVmNicIpResponseSecuritygroup `json:"securitygroup"` + Serviceofferingid string `json:"serviceofferingid"` + Serviceofferingname string `json:"serviceofferingname"` + Servicestate string `json:"servicestate"` + State string `json:"state"` + Templatedisplaytext string `json:"templatedisplaytext"` + Templateid string `json:"templateid"` + Templatename string `json:"templatename"` + Userid string `json:"userid"` + Username string `json:"username"` + Vgpu string `json:"vgpu"` + Zoneid string `json:"zoneid"` + Zonename string `json:"zonename"` +} + +type UpdateVmNicIpResponseSecuritygroup struct { + Account string `json:"account"` + Description string `json:"description"` + Domain string `json:"domain"` + Domainid string `json:"domainid"` + Egressrule []UpdateVmNicIpResponseSecuritygroupRule `json:"egressrule"` + Id string `json:"id"` + Ingressrule []UpdateVmNicIpResponseSecuritygroupRule `json:"ingressrule"` + Name string `json:"name"` + Project string `json:"project"` + Projectid string `json:"projectid"` + Tags []Tags `json:"tags"` + Virtualmachinecount int `json:"virtualmachinecount"` + Virtualmachineids []interface{} `json:"virtualmachineids"` +} + +type UpdateVmNicIpResponseSecuritygroupRule struct { + Account string `json:"account"` + Cidr string `json:"cidr"` + Endport int `json:"endport"` + Icmpcode int `json:"icmpcode"` + Icmptype int `json:"icmptype"` + Protocol string `json:"protocol"` + Ruleid string `json:"ruleid"` + Securitygroupname string `json:"securitygroupname"` + Startport int `json:"startport"` + Tags []Tags `json:"tags"` +} + +type UpdateVmNicIpResponseAffinitygroup struct { + Account string `json:"account"` + Description string `json:"description"` + Domain string `json:"domain"` + Domainid string `json:"domainid"` + Id string `json:"id"` + Name string `json:"name"` + Project string `json:"project"` + Projectid string `json:"projectid"` + Type string `json:"type"` + VirtualmachineIds []string `json:"virtualmachineIds"` } diff --git a/vendor/github.com/xanzy/go-cloudstack/cloudstack/NiciraNVPService.go b/vendor/github.com/xanzy/go-cloudstack/cloudstack/NiciraNVPService.go index 2efcd1587..ec90845bc 100644 --- a/vendor/github.com/xanzy/go-cloudstack/cloudstack/NiciraNVPService.go +++ b/vendor/github.com/xanzy/go-cloudstack/cloudstack/NiciraNVPService.go @@ -1,5 +1,5 @@ // -// Copyright 2016, Sander van Harmelen +// Copyright 2018, Sander van Harmelen // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -34,6 +34,9 @@ func (p *AddNiciraNvpDeviceParams) toURLValues() url.Values { if v, found := p.p["hostname"]; found { u.Set("hostname", v.(string)) } + if v, found := p.p["l2gatewayserviceuuid"]; found { + u.Set("l2gatewayserviceuuid", v.(string)) + } if v, found := p.p["l3gatewayserviceuuid"]; found { u.Set("l3gatewayserviceuuid", v.(string)) } @@ -60,6 +63,14 @@ func (p *AddNiciraNvpDeviceParams) SetHostname(v string) { return } +func (p *AddNiciraNvpDeviceParams) SetL2gatewayserviceuuid(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["l2gatewayserviceuuid"] = v + return +} + func (p *AddNiciraNvpDeviceParams) SetL3gatewayserviceuuid(v string) { if p.p == nil { p.p = make(map[string]interface{}) @@ -144,18 +155,20 @@ func (s *NiciraNVPService) AddNiciraNvpDevice(p *AddNiciraNvpDeviceParams) (*Add return nil, err } } + return &r, nil } type AddNiciraNvpDeviceResponse struct { - JobID string `json:"jobid,omitempty"` - Hostname string `json:"hostname,omitempty"` - L3gatewayserviceuuid string `json:"l3gatewayserviceuuid,omitempty"` - Niciradevicename string `json:"niciradevicename,omitempty"` - Nvpdeviceid string `json:"nvpdeviceid,omitempty"` - Physicalnetworkid string `json:"physicalnetworkid,omitempty"` - Provider string `json:"provider,omitempty"` - Transportzoneuuid string `json:"transportzoneuuid,omitempty"` + JobID string `json:"jobid"` + Hostname string `json:"hostname"` + L2gatewayserviceuuid string `json:"l2gatewayserviceuuid"` + L3gatewayserviceuuid string `json:"l3gatewayserviceuuid"` + Niciradevicename string `json:"niciradevicename"` + Nvpdeviceid string `json:"nvpdeviceid"` + Physicalnetworkid string `json:"physicalnetworkid"` + Provider string `json:"provider"` + Transportzoneuuid string `json:"transportzoneuuid"` } type DeleteNiciraNvpDeviceParams struct { @@ -216,13 +229,14 @@ func (s *NiciraNVPService) DeleteNiciraNvpDevice(p *DeleteNiciraNvpDeviceParams) return nil, err } } + return &r, nil } type DeleteNiciraNvpDeviceResponse struct { - JobID string `json:"jobid,omitempty"` - Displaytext string `json:"displaytext,omitempty"` - Success bool `json:"success,omitempty"` + JobID string `json:"jobid"` + Displaytext string `json:"displaytext"` + Success bool `json:"success"` } type ListNiciraNvpDevicesParams struct { @@ -313,6 +327,7 @@ func (s *NiciraNVPService) ListNiciraNvpDevices(p *ListNiciraNvpDevicesParams) ( if err := json.Unmarshal(resp, &r); err != nil { return nil, err } + return &r, nil } @@ -322,11 +337,12 @@ type ListNiciraNvpDevicesResponse struct { } type NiciraNvpDevice struct { - Hostname string `json:"hostname,omitempty"` - L3gatewayserviceuuid string `json:"l3gatewayserviceuuid,omitempty"` - Niciradevicename string `json:"niciradevicename,omitempty"` - Nvpdeviceid string `json:"nvpdeviceid,omitempty"` - Physicalnetworkid string `json:"physicalnetworkid,omitempty"` - Provider string `json:"provider,omitempty"` - Transportzoneuuid string `json:"transportzoneuuid,omitempty"` + Hostname string `json:"hostname"` + L2gatewayserviceuuid string `json:"l2gatewayserviceuuid"` + L3gatewayserviceuuid string `json:"l3gatewayserviceuuid"` + Niciradevicename string `json:"niciradevicename"` + Nvpdeviceid string `json:"nvpdeviceid"` + Physicalnetworkid string `json:"physicalnetworkid"` + Provider string `json:"provider"` + Transportzoneuuid string `json:"transportzoneuuid"` } diff --git a/vendor/github.com/xanzy/go-cloudstack/cloudstack/NuageVSPService.go b/vendor/github.com/xanzy/go-cloudstack/cloudstack/NuageVSPService.go new file mode 100644 index 000000000..31f4df2ad --- /dev/null +++ b/vendor/github.com/xanzy/go-cloudstack/cloudstack/NuageVSPService.go @@ -0,0 +1,527 @@ +// +// Copyright 2018, Sander van Harmelen +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// + +package cloudstack + +import ( + "encoding/json" + "net/url" + "strconv" +) + +type AddNuageVspDeviceParams struct { + p map[string]interface{} +} + +func (p *AddNuageVspDeviceParams) toURLValues() url.Values { + u := url.Values{} + if p.p == nil { + return u + } + if v, found := p.p["apiversion"]; found { + u.Set("apiversion", v.(string)) + } + if v, found := p.p["hostname"]; found { + u.Set("hostname", v.(string)) + } + if v, found := p.p["password"]; found { + u.Set("password", v.(string)) + } + if v, found := p.p["physicalnetworkid"]; found { + u.Set("physicalnetworkid", v.(string)) + } + if v, found := p.p["port"]; found { + vv := strconv.Itoa(v.(int)) + u.Set("port", vv) + } + if v, found := p.p["retrycount"]; found { + vv := strconv.Itoa(v.(int)) + u.Set("retrycount", vv) + } + if v, found := p.p["retryinterval"]; found { + vv := strconv.FormatInt(v.(int64), 10) + u.Set("retryinterval", vv) + } + if v, found := p.p["username"]; found { + u.Set("username", v.(string)) + } + return u +} + +func (p *AddNuageVspDeviceParams) SetApiversion(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["apiversion"] = v + return +} + +func (p *AddNuageVspDeviceParams) SetHostname(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["hostname"] = v + return +} + +func (p *AddNuageVspDeviceParams) SetPassword(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["password"] = v + return +} + +func (p *AddNuageVspDeviceParams) SetPhysicalnetworkid(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["physicalnetworkid"] = v + return +} + +func (p *AddNuageVspDeviceParams) SetPort(v int) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["port"] = v + return +} + +func (p *AddNuageVspDeviceParams) SetRetrycount(v int) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["retrycount"] = v + return +} + +func (p *AddNuageVspDeviceParams) SetRetryinterval(v int64) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["retryinterval"] = v + return +} + +func (p *AddNuageVspDeviceParams) SetUsername(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["username"] = v + return +} + +// You should always use this function to get a new AddNuageVspDeviceParams instance, +// as then you are sure you have configured all required params +func (s *NuageVSPService) NewAddNuageVspDeviceParams(hostname string, password string, physicalnetworkid string, port int, username string) *AddNuageVspDeviceParams { + p := &AddNuageVspDeviceParams{} + p.p = make(map[string]interface{}) + p.p["hostname"] = hostname + p.p["password"] = password + p.p["physicalnetworkid"] = physicalnetworkid + p.p["port"] = port + p.p["username"] = username + return p +} + +// Adds a Nuage VSP device +func (s *NuageVSPService) AddNuageVspDevice(p *AddNuageVspDeviceParams) (*AddNuageVspDeviceResponse, error) { + resp, err := s.cs.newRequest("addNuageVspDevice", p.toURLValues()) + if err != nil { + return nil, err + } + + var r AddNuageVspDeviceResponse + if err := json.Unmarshal(resp, &r); err != nil { + return nil, err + } + + // If we have a async client, we need to wait for the async result + if s.cs.async { + b, err := s.cs.GetAsyncJobResult(r.JobID, s.cs.timeout) + if err != nil { + if err == AsyncTimeoutErr { + return &r, err + } + return nil, err + } + + b, err = getRawValue(b) + if err != nil { + return nil, err + } + + if err := json.Unmarshal(b, &r); err != nil { + return nil, err + } + } + + return &r, nil +} + +type AddNuageVspDeviceResponse struct { + JobID string `json:"jobid"` + Apiversion string `json:"apiversion"` + Cmsid string `json:"cmsid"` + Hostname string `json:"hostname"` + Nuagedevicename string `json:"nuagedevicename"` + Physicalnetworkid string `json:"physicalnetworkid"` + Port int `json:"port"` + Provider string `json:"provider"` + Retrycount int `json:"retrycount"` + Retryinterval int64 `json:"retryinterval"` + Vspdeviceid string `json:"vspdeviceid"` +} + +type DeleteNuageVspDeviceParams struct { + p map[string]interface{} +} + +func (p *DeleteNuageVspDeviceParams) toURLValues() url.Values { + u := url.Values{} + if p.p == nil { + return u + } + if v, found := p.p["vspdeviceid"]; found { + u.Set("vspdeviceid", v.(string)) + } + return u +} + +func (p *DeleteNuageVspDeviceParams) SetVspdeviceid(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["vspdeviceid"] = v + return +} + +// You should always use this function to get a new DeleteNuageVspDeviceParams instance, +// as then you are sure you have configured all required params +func (s *NuageVSPService) NewDeleteNuageVspDeviceParams(vspdeviceid string) *DeleteNuageVspDeviceParams { + p := &DeleteNuageVspDeviceParams{} + p.p = make(map[string]interface{}) + p.p["vspdeviceid"] = vspdeviceid + return p +} + +// delete a nuage vsp device +func (s *NuageVSPService) DeleteNuageVspDevice(p *DeleteNuageVspDeviceParams) (*DeleteNuageVspDeviceResponse, error) { + resp, err := s.cs.newRequest("deleteNuageVspDevice", p.toURLValues()) + if err != nil { + return nil, err + } + + var r DeleteNuageVspDeviceResponse + if err := json.Unmarshal(resp, &r); err != nil { + return nil, err + } + + // If we have a async client, we need to wait for the async result + if s.cs.async { + b, err := s.cs.GetAsyncJobResult(r.JobID, s.cs.timeout) + if err != nil { + if err == AsyncTimeoutErr { + return &r, err + } + return nil, err + } + + if err := json.Unmarshal(b, &r); err != nil { + return nil, err + } + } + + return &r, nil +} + +type DeleteNuageVspDeviceResponse struct { + JobID string `json:"jobid"` + Displaytext string `json:"displaytext"` + Success bool `json:"success"` +} + +type ListNuageVspDevicesParams struct { + p map[string]interface{} +} + +func (p *ListNuageVspDevicesParams) toURLValues() url.Values { + u := url.Values{} + if p.p == nil { + return u + } + if v, found := p.p["keyword"]; found { + u.Set("keyword", v.(string)) + } + if v, found := p.p["page"]; found { + vv := strconv.Itoa(v.(int)) + u.Set("page", vv) + } + if v, found := p.p["pagesize"]; found { + vv := strconv.Itoa(v.(int)) + u.Set("pagesize", vv) + } + if v, found := p.p["physicalnetworkid"]; found { + u.Set("physicalnetworkid", v.(string)) + } + if v, found := p.p["vspdeviceid"]; found { + u.Set("vspdeviceid", v.(string)) + } + return u +} + +func (p *ListNuageVspDevicesParams) SetKeyword(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["keyword"] = v + return +} + +func (p *ListNuageVspDevicesParams) SetPage(v int) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["page"] = v + return +} + +func (p *ListNuageVspDevicesParams) SetPagesize(v int) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["pagesize"] = v + return +} + +func (p *ListNuageVspDevicesParams) SetPhysicalnetworkid(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["physicalnetworkid"] = v + return +} + +func (p *ListNuageVspDevicesParams) SetVspdeviceid(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["vspdeviceid"] = v + return +} + +// You should always use this function to get a new ListNuageVspDevicesParams instance, +// as then you are sure you have configured all required params +func (s *NuageVSPService) NewListNuageVspDevicesParams() *ListNuageVspDevicesParams { + p := &ListNuageVspDevicesParams{} + p.p = make(map[string]interface{}) + return p +} + +// Lists Nuage VSP devices +func (s *NuageVSPService) ListNuageVspDevices(p *ListNuageVspDevicesParams) (*ListNuageVspDevicesResponse, error) { + resp, err := s.cs.newRequest("listNuageVspDevices", p.toURLValues()) + if err != nil { + return nil, err + } + + var r ListNuageVspDevicesResponse + if err := json.Unmarshal(resp, &r); err != nil { + return nil, err + } + + return &r, nil +} + +type ListNuageVspDevicesResponse struct { + Count int `json:"count"` + NuageVspDevices []*NuageVspDevice `json:"nuagevspdevice"` +} + +type NuageVspDevice struct { + Apiversion string `json:"apiversion"` + Cmsid string `json:"cmsid"` + Hostname string `json:"hostname"` + Nuagedevicename string `json:"nuagedevicename"` + Physicalnetworkid string `json:"physicalnetworkid"` + Port int `json:"port"` + Provider string `json:"provider"` + Retrycount int `json:"retrycount"` + Retryinterval int64 `json:"retryinterval"` + Vspdeviceid string `json:"vspdeviceid"` +} + +type UpdateNuageVspDeviceParams struct { + p map[string]interface{} +} + +func (p *UpdateNuageVspDeviceParams) toURLValues() url.Values { + u := url.Values{} + if p.p == nil { + return u + } + if v, found := p.p["apiversion"]; found { + u.Set("apiversion", v.(string)) + } + if v, found := p.p["hostname"]; found { + u.Set("hostname", v.(string)) + } + if v, found := p.p["password"]; found { + u.Set("password", v.(string)) + } + if v, found := p.p["physicalnetworkid"]; found { + u.Set("physicalnetworkid", v.(string)) + } + if v, found := p.p["port"]; found { + vv := strconv.Itoa(v.(int)) + u.Set("port", vv) + } + if v, found := p.p["retrycount"]; found { + vv := strconv.Itoa(v.(int)) + u.Set("retrycount", vv) + } + if v, found := p.p["retryinterval"]; found { + vv := strconv.FormatInt(v.(int64), 10) + u.Set("retryinterval", vv) + } + if v, found := p.p["username"]; found { + u.Set("username", v.(string)) + } + return u +} + +func (p *UpdateNuageVspDeviceParams) SetApiversion(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["apiversion"] = v + return +} + +func (p *UpdateNuageVspDeviceParams) SetHostname(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["hostname"] = v + return +} + +func (p *UpdateNuageVspDeviceParams) SetPassword(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["password"] = v + return +} + +func (p *UpdateNuageVspDeviceParams) SetPhysicalnetworkid(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["physicalnetworkid"] = v + return +} + +func (p *UpdateNuageVspDeviceParams) SetPort(v int) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["port"] = v + return +} + +func (p *UpdateNuageVspDeviceParams) SetRetrycount(v int) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["retrycount"] = v + return +} + +func (p *UpdateNuageVspDeviceParams) SetRetryinterval(v int64) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["retryinterval"] = v + return +} + +func (p *UpdateNuageVspDeviceParams) SetUsername(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["username"] = v + return +} + +// You should always use this function to get a new UpdateNuageVspDeviceParams instance, +// as then you are sure you have configured all required params +func (s *NuageVSPService) NewUpdateNuageVspDeviceParams(physicalnetworkid string) *UpdateNuageVspDeviceParams { + p := &UpdateNuageVspDeviceParams{} + p.p = make(map[string]interface{}) + p.p["physicalnetworkid"] = physicalnetworkid + return p +} + +// Update a Nuage VSP device +func (s *NuageVSPService) UpdateNuageVspDevice(p *UpdateNuageVspDeviceParams) (*UpdateNuageVspDeviceResponse, error) { + resp, err := s.cs.newRequest("updateNuageVspDevice", p.toURLValues()) + if err != nil { + return nil, err + } + + var r UpdateNuageVspDeviceResponse + if err := json.Unmarshal(resp, &r); err != nil { + return nil, err + } + + // If we have a async client, we need to wait for the async result + if s.cs.async { + b, err := s.cs.GetAsyncJobResult(r.JobID, s.cs.timeout) + if err != nil { + if err == AsyncTimeoutErr { + return &r, err + } + return nil, err + } + + b, err = getRawValue(b) + if err != nil { + return nil, err + } + + if err := json.Unmarshal(b, &r); err != nil { + return nil, err + } + } + + return &r, nil +} + +type UpdateNuageVspDeviceResponse struct { + JobID string `json:"jobid"` + Apiversion string `json:"apiversion"` + Cmsid string `json:"cmsid"` + Hostname string `json:"hostname"` + Nuagedevicename string `json:"nuagedevicename"` + Physicalnetworkid string `json:"physicalnetworkid"` + Port int `json:"port"` + Provider string `json:"provider"` + Retrycount int `json:"retrycount"` + Retryinterval int64 `json:"retryinterval"` + Vspdeviceid string `json:"vspdeviceid"` +} diff --git a/vendor/github.com/xanzy/go-cloudstack/cloudstack/OutofbandManagementService.go b/vendor/github.com/xanzy/go-cloudstack/cloudstack/OutofbandManagementService.go new file mode 100644 index 000000000..eb12c45e1 --- /dev/null +++ b/vendor/github.com/xanzy/go-cloudstack/cloudstack/OutofbandManagementService.go @@ -0,0 +1,343 @@ +// +// Copyright 2018, Sander van Harmelen +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// + +package cloudstack + +import ( + "encoding/json" + "net/url" + "strconv" +) + +type ChangeOutOfBandManagementPasswordParams struct { + p map[string]interface{} +} + +func (p *ChangeOutOfBandManagementPasswordParams) toURLValues() url.Values { + u := url.Values{} + if p.p == nil { + return u + } + if v, found := p.p["hostid"]; found { + u.Set("hostid", v.(string)) + } + if v, found := p.p["password"]; found { + u.Set("password", v.(string)) + } + return u +} + +func (p *ChangeOutOfBandManagementPasswordParams) SetHostid(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["hostid"] = v + return +} + +func (p *ChangeOutOfBandManagementPasswordParams) SetPassword(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["password"] = v + return +} + +// You should always use this function to get a new ChangeOutOfBandManagementPasswordParams instance, +// as then you are sure you have configured all required params +func (s *OutofbandManagementService) NewChangeOutOfBandManagementPasswordParams(hostid string) *ChangeOutOfBandManagementPasswordParams { + p := &ChangeOutOfBandManagementPasswordParams{} + p.p = make(map[string]interface{}) + p.p["hostid"] = hostid + return p +} + +// Changes out-of-band management interface password on the host and updates the interface configuration in CloudStack if the operation succeeds, else reverts the old password +func (s *OutofbandManagementService) ChangeOutOfBandManagementPassword(p *ChangeOutOfBandManagementPasswordParams) (*ChangeOutOfBandManagementPasswordResponse, error) { + resp, err := s.cs.newRequest("changeOutOfBandManagementPassword", p.toURLValues()) + if err != nil { + return nil, err + } + + var r ChangeOutOfBandManagementPasswordResponse + if err := json.Unmarshal(resp, &r); err != nil { + return nil, err + } + + // If we have a async client, we need to wait for the async result + if s.cs.async { + b, err := s.cs.GetAsyncJobResult(r.JobID, s.cs.timeout) + if err != nil { + if err == AsyncTimeoutErr { + return &r, err + } + return nil, err + } + + b, err = getRawValue(b) + if err != nil { + return nil, err + } + + if err := json.Unmarshal(b, &r); err != nil { + return nil, err + } + } + + return &r, nil +} + +type ChangeOutOfBandManagementPasswordResponse struct { + JobID string `json:"jobid"` + Action string `json:"action"` + Address string `json:"address"` + Description string `json:"description"` + Driver string `json:"driver"` + Enabled bool `json:"enabled"` + Hostid string `json:"hostid"` + Password string `json:"password"` + Port string `json:"port"` + Powerstate string `json:"powerstate"` + Status bool `json:"status"` + Username string `json:"username"` +} + +type ConfigureOutOfBandManagementParams struct { + p map[string]interface{} +} + +func (p *ConfigureOutOfBandManagementParams) toURLValues() url.Values { + u := url.Values{} + if p.p == nil { + return u + } + if v, found := p.p["address"]; found { + u.Set("address", v.(string)) + } + if v, found := p.p["driver"]; found { + u.Set("driver", v.(string)) + } + if v, found := p.p["hostid"]; found { + u.Set("hostid", v.(string)) + } + if v, found := p.p["password"]; found { + u.Set("password", v.(string)) + } + if v, found := p.p["port"]; found { + u.Set("port", v.(string)) + } + if v, found := p.p["username"]; found { + u.Set("username", v.(string)) + } + return u +} + +func (p *ConfigureOutOfBandManagementParams) SetAddress(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["address"] = v + return +} + +func (p *ConfigureOutOfBandManagementParams) SetDriver(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["driver"] = v + return +} + +func (p *ConfigureOutOfBandManagementParams) SetHostid(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["hostid"] = v + return +} + +func (p *ConfigureOutOfBandManagementParams) SetPassword(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["password"] = v + return +} + +func (p *ConfigureOutOfBandManagementParams) SetPort(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["port"] = v + return +} + +func (p *ConfigureOutOfBandManagementParams) SetUsername(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["username"] = v + return +} + +// You should always use this function to get a new ConfigureOutOfBandManagementParams instance, +// as then you are sure you have configured all required params +func (s *OutofbandManagementService) NewConfigureOutOfBandManagementParams(address string, driver string, hostid string, password string, port string, username string) *ConfigureOutOfBandManagementParams { + p := &ConfigureOutOfBandManagementParams{} + p.p = make(map[string]interface{}) + p.p["address"] = address + p.p["driver"] = driver + p.p["hostid"] = hostid + p.p["password"] = password + p.p["port"] = port + p.p["username"] = username + return p +} + +// Configures a host's out-of-band management interface +func (s *OutofbandManagementService) ConfigureOutOfBandManagement(p *ConfigureOutOfBandManagementParams) (*OutOfBandManagementResponse, error) { + resp, err := s.cs.newRequest("configureOutOfBandManagement", p.toURLValues()) + if err != nil { + return nil, err + } + + var r OutOfBandManagementResponse + if err := json.Unmarshal(resp, &r); err != nil { + return nil, err + } + + return &r, nil +} + +type OutOfBandManagementResponse struct { + Action string `json:"action"` + Address string `json:"address"` + Description string `json:"description"` + Driver string `json:"driver"` + Enabled bool `json:"enabled"` + Hostid string `json:"hostid"` + Password string `json:"password"` + Port string `json:"port"` + Powerstate string `json:"powerstate"` + Status bool `json:"status"` + Username string `json:"username"` +} + +type IssueOutOfBandManagementPowerActionParams struct { + p map[string]interface{} +} + +func (p *IssueOutOfBandManagementPowerActionParams) toURLValues() url.Values { + u := url.Values{} + if p.p == nil { + return u + } + if v, found := p.p["action"]; found { + u.Set("action", v.(string)) + } + if v, found := p.p["hostid"]; found { + u.Set("hostid", v.(string)) + } + if v, found := p.p["timeout"]; found { + vv := strconv.FormatInt(v.(int64), 10) + u.Set("timeout", vv) + } + return u +} + +func (p *IssueOutOfBandManagementPowerActionParams) SetAction(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["action"] = v + return +} + +func (p *IssueOutOfBandManagementPowerActionParams) SetHostid(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["hostid"] = v + return +} + +func (p *IssueOutOfBandManagementPowerActionParams) SetTimeout(v int64) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["timeout"] = v + return +} + +// You should always use this function to get a new IssueOutOfBandManagementPowerActionParams instance, +// as then you are sure you have configured all required params +func (s *OutofbandManagementService) NewIssueOutOfBandManagementPowerActionParams(action string, hostid string) *IssueOutOfBandManagementPowerActionParams { + p := &IssueOutOfBandManagementPowerActionParams{} + p.p = make(map[string]interface{}) + p.p["action"] = action + p.p["hostid"] = hostid + return p +} + +// Initiates the specified power action to the host's out-of-band management interface +func (s *OutofbandManagementService) IssueOutOfBandManagementPowerAction(p *IssueOutOfBandManagementPowerActionParams) (*IssueOutOfBandManagementPowerActionResponse, error) { + resp, err := s.cs.newRequest("issueOutOfBandManagementPowerAction", p.toURLValues()) + if err != nil { + return nil, err + } + + var r IssueOutOfBandManagementPowerActionResponse + if err := json.Unmarshal(resp, &r); err != nil { + return nil, err + } + + // If we have a async client, we need to wait for the async result + if s.cs.async { + b, err := s.cs.GetAsyncJobResult(r.JobID, s.cs.timeout) + if err != nil { + if err == AsyncTimeoutErr { + return &r, err + } + return nil, err + } + + b, err = getRawValue(b) + if err != nil { + return nil, err + } + + if err := json.Unmarshal(b, &r); err != nil { + return nil, err + } + } + + return &r, nil +} + +type IssueOutOfBandManagementPowerActionResponse struct { + JobID string `json:"jobid"` + Action string `json:"action"` + Address string `json:"address"` + Description string `json:"description"` + Driver string `json:"driver"` + Enabled bool `json:"enabled"` + Hostid string `json:"hostid"` + Password string `json:"password"` + Port string `json:"port"` + Powerstate string `json:"powerstate"` + Status bool `json:"status"` + Username string `json:"username"` +} diff --git a/vendor/github.com/xanzy/go-cloudstack/cloudstack/OvsElementService.go b/vendor/github.com/xanzy/go-cloudstack/cloudstack/OvsElementService.go index a86d61f28..cd5b22e1c 100644 --- a/vendor/github.com/xanzy/go-cloudstack/cloudstack/OvsElementService.go +++ b/vendor/github.com/xanzy/go-cloudstack/cloudstack/OvsElementService.go @@ -1,5 +1,5 @@ // -// Copyright 2016, Sander van Harmelen +// Copyright 2018, Sander van Harmelen // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -70,13 +70,13 @@ func (s *OvsElementService) NewConfigureOvsElementParams(enabled bool, id string } // Configures an ovs element. -func (s *OvsElementService) ConfigureOvsElement(p *ConfigureOvsElementParams) (*ConfigureOvsElementResponse, error) { +func (s *OvsElementService) ConfigureOvsElement(p *ConfigureOvsElementParams) (*OvsElementResponse, error) { resp, err := s.cs.newRequest("configureOvsElement", p.toURLValues()) if err != nil { return nil, err } - var r ConfigureOvsElementResponse + var r OvsElementResponse if err := json.Unmarshal(resp, &r); err != nil { return nil, err } @@ -100,19 +100,20 @@ func (s *OvsElementService) ConfigureOvsElement(p *ConfigureOvsElementParams) (* return nil, err } } + return &r, nil } -type ConfigureOvsElementResponse struct { - JobID string `json:"jobid,omitempty"` - Account string `json:"account,omitempty"` - Domain string `json:"domain,omitempty"` - Domainid string `json:"domainid,omitempty"` - Enabled bool `json:"enabled,omitempty"` - Id string `json:"id,omitempty"` - Nspid string `json:"nspid,omitempty"` - Project string `json:"project,omitempty"` - Projectid string `json:"projectid,omitempty"` +type OvsElementResponse struct { + JobID string `json:"jobid"` + Account string `json:"account"` + Domain string `json:"domain"` + Domainid string `json:"domainid"` + Enabled bool `json:"enabled"` + Id string `json:"id"` + Nspid string `json:"nspid"` + Project string `json:"project"` + Projectid string `json:"projectid"` } type ListOvsElementsParams struct { @@ -211,7 +212,7 @@ func (s *OvsElementService) GetOvsElementByID(id string, opts ...OptionFunc) (*O p.p["id"] = id - for _, fn := range opts { + for _, fn := range append(s.cs.options, opts...) { if err := fn(s.cs, p); err != nil { return nil, -1, err } @@ -248,6 +249,7 @@ func (s *OvsElementService) ListOvsElements(p *ListOvsElementsParams) (*ListOvsE if err := json.Unmarshal(resp, &r); err != nil { return nil, err } + return &r, nil } @@ -257,12 +259,12 @@ type ListOvsElementsResponse struct { } type OvsElement struct { - Account string `json:"account,omitempty"` - Domain string `json:"domain,omitempty"` - Domainid string `json:"domainid,omitempty"` - Enabled bool `json:"enabled,omitempty"` - Id string `json:"id,omitempty"` - Nspid string `json:"nspid,omitempty"` - Project string `json:"project,omitempty"` - Projectid string `json:"projectid,omitempty"` + Account string `json:"account"` + Domain string `json:"domain"` + Domainid string `json:"domainid"` + Enabled bool `json:"enabled"` + Id string `json:"id"` + Nspid string `json:"nspid"` + Project string `json:"project"` + Projectid string `json:"projectid"` } diff --git a/vendor/github.com/xanzy/go-cloudstack/cloudstack/PodService.go b/vendor/github.com/xanzy/go-cloudstack/cloudstack/PodService.go index 2f0af1eec..377e2618e 100644 --- a/vendor/github.com/xanzy/go-cloudstack/cloudstack/PodService.go +++ b/vendor/github.com/xanzy/go-cloudstack/cloudstack/PodService.go @@ -1,5 +1,5 @@ // -// Copyright 2016, Sander van Harmelen +// Copyright 2018, Sander van Harmelen // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -137,167 +137,138 @@ func (s *PodService) CreatePod(p *CreatePodParams) (*CreatePodResponse, error) { if err := json.Unmarshal(resp, &r); err != nil { return nil, err } + return &r, nil } type CreatePodResponse struct { - Allocationstate string `json:"allocationstate,omitempty"` - Capacity []struct { - Capacitytotal int64 `json:"capacitytotal,omitempty"` - Capacityused int64 `json:"capacityused,omitempty"` - Clusterid string `json:"clusterid,omitempty"` - Clustername string `json:"clustername,omitempty"` - Percentused string `json:"percentused,omitempty"` - Podid string `json:"podid,omitempty"` - Podname string `json:"podname,omitempty"` - Type int `json:"type,omitempty"` - Zoneid string `json:"zoneid,omitempty"` - Zonename string `json:"zonename,omitempty"` - } `json:"capacity,omitempty"` - Endip string `json:"endip,omitempty"` - Gateway string `json:"gateway,omitempty"` - Id string `json:"id,omitempty"` - Name string `json:"name,omitempty"` - Netmask string `json:"netmask,omitempty"` - Startip string `json:"startip,omitempty"` - Zoneid string `json:"zoneid,omitempty"` - Zonename string `json:"zonename,omitempty"` + Allocationstate string `json:"allocationstate"` + Capacity []CreatePodResponseCapacity `json:"capacity"` + Endip []string `json:"endip"` + Forsystemvms []string `json:"forsystemvms"` + Gateway string `json:"gateway"` + Id string `json:"id"` + Name string `json:"name"` + Netmask string `json:"netmask"` + Startip []string `json:"startip"` + Vlanid []string `json:"vlanid"` + Zoneid string `json:"zoneid"` + Zonename string `json:"zonename"` } -type UpdatePodParams struct { +type CreatePodResponseCapacity struct { + Capacityallocated int64 `json:"capacityallocated"` + Capacitytotal int64 `json:"capacitytotal"` + Capacityused int64 `json:"capacityused"` + Clusterid string `json:"clusterid"` + Clustername string `json:"clustername"` + Name string `json:"name"` + Percentused string `json:"percentused"` + Podid string `json:"podid"` + Podname string `json:"podname"` + Type int `json:"type"` + Zoneid string `json:"zoneid"` + Zonename string `json:"zonename"` +} + +type DedicatePodParams struct { p map[string]interface{} } -func (p *UpdatePodParams) toURLValues() url.Values { +func (p *DedicatePodParams) toURLValues() url.Values { u := url.Values{} if p.p == nil { return u } - if v, found := p.p["allocationstate"]; found { - u.Set("allocationstate", v.(string)) + if v, found := p.p["account"]; found { + u.Set("account", v.(string)) } - if v, found := p.p["endip"]; found { - u.Set("endip", v.(string)) + if v, found := p.p["domainid"]; found { + u.Set("domainid", v.(string)) } - if v, found := p.p["gateway"]; found { - u.Set("gateway", v.(string)) - } - if v, found := p.p["id"]; found { - u.Set("id", v.(string)) - } - if v, found := p.p["name"]; found { - u.Set("name", v.(string)) - } - if v, found := p.p["netmask"]; found { - u.Set("netmask", v.(string)) - } - if v, found := p.p["startip"]; found { - u.Set("startip", v.(string)) + if v, found := p.p["podid"]; found { + u.Set("podid", v.(string)) } return u } -func (p *UpdatePodParams) SetAllocationstate(v string) { +func (p *DedicatePodParams) SetAccount(v string) { if p.p == nil { p.p = make(map[string]interface{}) } - p.p["allocationstate"] = v + p.p["account"] = v return } -func (p *UpdatePodParams) SetEndip(v string) { +func (p *DedicatePodParams) SetDomainid(v string) { if p.p == nil { p.p = make(map[string]interface{}) } - p.p["endip"] = v + p.p["domainid"] = v return } -func (p *UpdatePodParams) SetGateway(v string) { +func (p *DedicatePodParams) SetPodid(v string) { if p.p == nil { p.p = make(map[string]interface{}) } - p.p["gateway"] = v + p.p["podid"] = v return } -func (p *UpdatePodParams) SetId(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["id"] = v - return -} - -func (p *UpdatePodParams) SetName(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["name"] = v - return -} - -func (p *UpdatePodParams) SetNetmask(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["netmask"] = v - return -} - -func (p *UpdatePodParams) SetStartip(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["startip"] = v - return -} - -// You should always use this function to get a new UpdatePodParams instance, +// You should always use this function to get a new DedicatePodParams instance, // as then you are sure you have configured all required params -func (s *PodService) NewUpdatePodParams(id string) *UpdatePodParams { - p := &UpdatePodParams{} +func (s *PodService) NewDedicatePodParams(domainid string, podid string) *DedicatePodParams { + p := &DedicatePodParams{} p.p = make(map[string]interface{}) - p.p["id"] = id + p.p["domainid"] = domainid + p.p["podid"] = podid return p } -// Updates a Pod. -func (s *PodService) UpdatePod(p *UpdatePodParams) (*UpdatePodResponse, error) { - resp, err := s.cs.newRequest("updatePod", p.toURLValues()) +// Dedicates a Pod. +func (s *PodService) DedicatePod(p *DedicatePodParams) (*DedicatePodResponse, error) { + resp, err := s.cs.newRequest("dedicatePod", p.toURLValues()) if err != nil { return nil, err } - var r UpdatePodResponse + var r DedicatePodResponse if err := json.Unmarshal(resp, &r); err != nil { return nil, err } + + // If we have a async client, we need to wait for the async result + if s.cs.async { + b, err := s.cs.GetAsyncJobResult(r.JobID, s.cs.timeout) + if err != nil { + if err == AsyncTimeoutErr { + return &r, err + } + return nil, err + } + + b, err = getRawValue(b) + if err != nil { + return nil, err + } + + if err := json.Unmarshal(b, &r); err != nil { + return nil, err + } + } + return &r, nil } -type UpdatePodResponse struct { - Allocationstate string `json:"allocationstate,omitempty"` - Capacity []struct { - Capacitytotal int64 `json:"capacitytotal,omitempty"` - Capacityused int64 `json:"capacityused,omitempty"` - Clusterid string `json:"clusterid,omitempty"` - Clustername string `json:"clustername,omitempty"` - Percentused string `json:"percentused,omitempty"` - Podid string `json:"podid,omitempty"` - Podname string `json:"podname,omitempty"` - Type int `json:"type,omitempty"` - Zoneid string `json:"zoneid,omitempty"` - Zonename string `json:"zonename,omitempty"` - } `json:"capacity,omitempty"` - Endip string `json:"endip,omitempty"` - Gateway string `json:"gateway,omitempty"` - Id string `json:"id,omitempty"` - Name string `json:"name,omitempty"` - Netmask string `json:"netmask,omitempty"` - Startip string `json:"startip,omitempty"` - Zoneid string `json:"zoneid,omitempty"` - Zonename string `json:"zonename,omitempty"` +type DedicatePodResponse struct { + JobID string `json:"jobid"` + Accountid string `json:"accountid"` + Affinitygroupid string `json:"affinitygroupid"` + Domainid string `json:"domainid"` + Id string `json:"id"` + Podid string `json:"podid"` + Podname string `json:"podname"` } type DeletePodParams struct { @@ -343,12 +314,160 @@ func (s *PodService) DeletePod(p *DeletePodParams) (*DeletePodResponse, error) { if err := json.Unmarshal(resp, &r); err != nil { return nil, err } + return &r, nil } type DeletePodResponse struct { - Displaytext string `json:"displaytext,omitempty"` - Success string `json:"success,omitempty"` + Displaytext string `json:"displaytext"` + Success bool `json:"success"` +} + +func (r *DeletePodResponse) UnmarshalJSON(b []byte) error { + var m map[string]interface{} + err := json.Unmarshal(b, &m) + if err != nil { + return err + } + + if success, ok := m["success"].(string); ok { + m["success"] = success == "true" + b, err = json.Marshal(m) + if err != nil { + return err + } + } + + type alias DeletePodResponse + return json.Unmarshal(b, (*alias)(r)) +} + +type ListDedicatedPodsParams struct { + p map[string]interface{} +} + +func (p *ListDedicatedPodsParams) toURLValues() url.Values { + u := url.Values{} + if p.p == nil { + return u + } + if v, found := p.p["account"]; found { + u.Set("account", v.(string)) + } + if v, found := p.p["affinitygroupid"]; found { + u.Set("affinitygroupid", v.(string)) + } + if v, found := p.p["domainid"]; found { + u.Set("domainid", v.(string)) + } + if v, found := p.p["keyword"]; found { + u.Set("keyword", v.(string)) + } + if v, found := p.p["page"]; found { + vv := strconv.Itoa(v.(int)) + u.Set("page", vv) + } + if v, found := p.p["pagesize"]; found { + vv := strconv.Itoa(v.(int)) + u.Set("pagesize", vv) + } + if v, found := p.p["podid"]; found { + u.Set("podid", v.(string)) + } + return u +} + +func (p *ListDedicatedPodsParams) SetAccount(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["account"] = v + return +} + +func (p *ListDedicatedPodsParams) SetAffinitygroupid(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["affinitygroupid"] = v + return +} + +func (p *ListDedicatedPodsParams) SetDomainid(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["domainid"] = v + return +} + +func (p *ListDedicatedPodsParams) SetKeyword(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["keyword"] = v + return +} + +func (p *ListDedicatedPodsParams) SetPage(v int) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["page"] = v + return +} + +func (p *ListDedicatedPodsParams) SetPagesize(v int) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["pagesize"] = v + return +} + +func (p *ListDedicatedPodsParams) SetPodid(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["podid"] = v + return +} + +// You should always use this function to get a new ListDedicatedPodsParams instance, +// as then you are sure you have configured all required params +func (s *PodService) NewListDedicatedPodsParams() *ListDedicatedPodsParams { + p := &ListDedicatedPodsParams{} + p.p = make(map[string]interface{}) + return p +} + +// Lists dedicated pods. +func (s *PodService) ListDedicatedPods(p *ListDedicatedPodsParams) (*ListDedicatedPodsResponse, error) { + resp, err := s.cs.newRequest("listDedicatedPods", p.toURLValues()) + if err != nil { + return nil, err + } + + var r ListDedicatedPodsResponse + if err := json.Unmarshal(resp, &r); err != nil { + return nil, err + } + + return &r, nil +} + +type ListDedicatedPodsResponse struct { + Count int `json:"count"` + DedicatedPods []*DedicatedPod `json:"dedicatedpod"` +} + +type DedicatedPod struct { + Accountid string `json:"accountid"` + Affinitygroupid string `json:"affinitygroupid"` + Domainid string `json:"domainid"` + Id string `json:"id"` + Podid string `json:"podid"` + Podname string `json:"podname"` } type ListPodsParams struct { @@ -469,7 +588,7 @@ func (s *PodService) GetPodID(name string, opts ...OptionFunc) (string, int, err p.p["name"] = name - for _, fn := range opts { + for _, fn := range append(s.cs.options, opts...) { if err := fn(s.cs, p); err != nil { return "", -1, err } @@ -519,7 +638,7 @@ func (s *PodService) GetPodByID(id string, opts ...OptionFunc) (*Pod, int, error p.p["id"] = id - for _, fn := range opts { + for _, fn := range append(s.cs.options, opts...) { if err := fn(s.cs, p); err != nil { return nil, -1, err } @@ -556,6 +675,7 @@ func (s *PodService) ListPods(p *ListPodsParams) (*ListPodsResponse, error) { if err := json.Unmarshal(resp, &r); err != nil { return nil, err } + return &r, nil } @@ -565,126 +685,33 @@ type ListPodsResponse struct { } type Pod struct { - Allocationstate string `json:"allocationstate,omitempty"` - Capacity []struct { - Capacitytotal int64 `json:"capacitytotal,omitempty"` - Capacityused int64 `json:"capacityused,omitempty"` - Clusterid string `json:"clusterid,omitempty"` - Clustername string `json:"clustername,omitempty"` - Percentused string `json:"percentused,omitempty"` - Podid string `json:"podid,omitempty"` - Podname string `json:"podname,omitempty"` - Type int `json:"type,omitempty"` - Zoneid string `json:"zoneid,omitempty"` - Zonename string `json:"zonename,omitempty"` - } `json:"capacity,omitempty"` - Endip string `json:"endip,omitempty"` - Gateway string `json:"gateway,omitempty"` - Id string `json:"id,omitempty"` - Name string `json:"name,omitempty"` - Netmask string `json:"netmask,omitempty"` - Startip string `json:"startip,omitempty"` - Zoneid string `json:"zoneid,omitempty"` - Zonename string `json:"zonename,omitempty"` + Allocationstate string `json:"allocationstate"` + Capacity []PodCapacity `json:"capacity"` + Endip []string `json:"endip"` + Forsystemvms []string `json:"forsystemvms"` + Gateway string `json:"gateway"` + Id string `json:"id"` + Name string `json:"name"` + Netmask string `json:"netmask"` + Startip []string `json:"startip"` + Vlanid []string `json:"vlanid"` + Zoneid string `json:"zoneid"` + Zonename string `json:"zonename"` } -type DedicatePodParams struct { - p map[string]interface{} -} - -func (p *DedicatePodParams) toURLValues() url.Values { - u := url.Values{} - if p.p == nil { - return u - } - if v, found := p.p["account"]; found { - u.Set("account", v.(string)) - } - if v, found := p.p["domainid"]; found { - u.Set("domainid", v.(string)) - } - if v, found := p.p["podid"]; found { - u.Set("podid", v.(string)) - } - return u -} - -func (p *DedicatePodParams) SetAccount(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["account"] = v - return -} - -func (p *DedicatePodParams) SetDomainid(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["domainid"] = v - return -} - -func (p *DedicatePodParams) SetPodid(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["podid"] = v - return -} - -// You should always use this function to get a new DedicatePodParams instance, -// as then you are sure you have configured all required params -func (s *PodService) NewDedicatePodParams(domainid string, podid string) *DedicatePodParams { - p := &DedicatePodParams{} - p.p = make(map[string]interface{}) - p.p["domainid"] = domainid - p.p["podid"] = podid - return p -} - -// Dedicates a Pod. -func (s *PodService) DedicatePod(p *DedicatePodParams) (*DedicatePodResponse, error) { - resp, err := s.cs.newRequest("dedicatePod", p.toURLValues()) - if err != nil { - return nil, err - } - - var r DedicatePodResponse - if err := json.Unmarshal(resp, &r); err != nil { - return nil, err - } - - // If we have a async client, we need to wait for the async result - if s.cs.async { - b, err := s.cs.GetAsyncJobResult(r.JobID, s.cs.timeout) - if err != nil { - if err == AsyncTimeoutErr { - return &r, err - } - return nil, err - } - - b, err = getRawValue(b) - if err != nil { - return nil, err - } - - if err := json.Unmarshal(b, &r); err != nil { - return nil, err - } - } - return &r, nil -} - -type DedicatePodResponse struct { - JobID string `json:"jobid,omitempty"` - Accountid string `json:"accountid,omitempty"` - Affinitygroupid string `json:"affinitygroupid,omitempty"` - Domainid string `json:"domainid,omitempty"` - Id string `json:"id,omitempty"` - Podid string `json:"podid,omitempty"` - Podname string `json:"podname,omitempty"` +type PodCapacity struct { + Capacityallocated int64 `json:"capacityallocated"` + Capacitytotal int64 `json:"capacitytotal"` + Capacityused int64 `json:"capacityused"` + Clusterid string `json:"clusterid"` + Clustername string `json:"clustername"` + Name string `json:"name"` + Percentused string `json:"percentused"` + Podid string `json:"podid"` + Podname string `json:"podname"` + Type int `json:"type"` + Zoneid string `json:"zoneid"` + Zonename string `json:"zonename"` } type ReleaseDedicatedPodParams struct { @@ -745,138 +772,155 @@ func (s *PodService) ReleaseDedicatedPod(p *ReleaseDedicatedPodParams) (*Release return nil, err } } + return &r, nil } type ReleaseDedicatedPodResponse struct { - JobID string `json:"jobid,omitempty"` - Displaytext string `json:"displaytext,omitempty"` - Success bool `json:"success,omitempty"` + JobID string `json:"jobid"` + Displaytext string `json:"displaytext"` + Success bool `json:"success"` } -type ListDedicatedPodsParams struct { +type UpdatePodParams struct { p map[string]interface{} } -func (p *ListDedicatedPodsParams) toURLValues() url.Values { +func (p *UpdatePodParams) toURLValues() url.Values { u := url.Values{} if p.p == nil { return u } - if v, found := p.p["account"]; found { - u.Set("account", v.(string)) + if v, found := p.p["allocationstate"]; found { + u.Set("allocationstate", v.(string)) } - if v, found := p.p["affinitygroupid"]; found { - u.Set("affinitygroupid", v.(string)) + if v, found := p.p["endip"]; found { + u.Set("endip", v.(string)) } - if v, found := p.p["domainid"]; found { - u.Set("domainid", v.(string)) + if v, found := p.p["gateway"]; found { + u.Set("gateway", v.(string)) } - if v, found := p.p["keyword"]; found { - u.Set("keyword", v.(string)) + if v, found := p.p["id"]; found { + u.Set("id", v.(string)) } - if v, found := p.p["page"]; found { - vv := strconv.Itoa(v.(int)) - u.Set("page", vv) + if v, found := p.p["name"]; found { + u.Set("name", v.(string)) } - if v, found := p.p["pagesize"]; found { - vv := strconv.Itoa(v.(int)) - u.Set("pagesize", vv) + if v, found := p.p["netmask"]; found { + u.Set("netmask", v.(string)) } - if v, found := p.p["podid"]; found { - u.Set("podid", v.(string)) + if v, found := p.p["startip"]; found { + u.Set("startip", v.(string)) } return u } -func (p *ListDedicatedPodsParams) SetAccount(v string) { +func (p *UpdatePodParams) SetAllocationstate(v string) { if p.p == nil { p.p = make(map[string]interface{}) } - p.p["account"] = v + p.p["allocationstate"] = v return } -func (p *ListDedicatedPodsParams) SetAffinitygroupid(v string) { +func (p *UpdatePodParams) SetEndip(v string) { if p.p == nil { p.p = make(map[string]interface{}) } - p.p["affinitygroupid"] = v + p.p["endip"] = v return } -func (p *ListDedicatedPodsParams) SetDomainid(v string) { +func (p *UpdatePodParams) SetGateway(v string) { if p.p == nil { p.p = make(map[string]interface{}) } - p.p["domainid"] = v + p.p["gateway"] = v return } -func (p *ListDedicatedPodsParams) SetKeyword(v string) { +func (p *UpdatePodParams) SetId(v string) { if p.p == nil { p.p = make(map[string]interface{}) } - p.p["keyword"] = v + p.p["id"] = v return } -func (p *ListDedicatedPodsParams) SetPage(v int) { +func (p *UpdatePodParams) SetName(v string) { if p.p == nil { p.p = make(map[string]interface{}) } - p.p["page"] = v + p.p["name"] = v return } -func (p *ListDedicatedPodsParams) SetPagesize(v int) { +func (p *UpdatePodParams) SetNetmask(v string) { if p.p == nil { p.p = make(map[string]interface{}) } - p.p["pagesize"] = v + p.p["netmask"] = v return } -func (p *ListDedicatedPodsParams) SetPodid(v string) { +func (p *UpdatePodParams) SetStartip(v string) { if p.p == nil { p.p = make(map[string]interface{}) } - p.p["podid"] = v + p.p["startip"] = v return } -// You should always use this function to get a new ListDedicatedPodsParams instance, +// You should always use this function to get a new UpdatePodParams instance, // as then you are sure you have configured all required params -func (s *PodService) NewListDedicatedPodsParams() *ListDedicatedPodsParams { - p := &ListDedicatedPodsParams{} +func (s *PodService) NewUpdatePodParams(id string) *UpdatePodParams { + p := &UpdatePodParams{} p.p = make(map[string]interface{}) + p.p["id"] = id return p } -// Lists dedicated pods. -func (s *PodService) ListDedicatedPods(p *ListDedicatedPodsParams) (*ListDedicatedPodsResponse, error) { - resp, err := s.cs.newRequest("listDedicatedPods", p.toURLValues()) +// Updates a Pod. +func (s *PodService) UpdatePod(p *UpdatePodParams) (*UpdatePodResponse, error) { + resp, err := s.cs.newRequest("updatePod", p.toURLValues()) if err != nil { return nil, err } - var r ListDedicatedPodsResponse + var r UpdatePodResponse if err := json.Unmarshal(resp, &r); err != nil { return nil, err } + return &r, nil } -type ListDedicatedPodsResponse struct { - Count int `json:"count"` - DedicatedPods []*DedicatedPod `json:"dedicatedpod"` +type UpdatePodResponse struct { + Allocationstate string `json:"allocationstate"` + Capacity []UpdatePodResponseCapacity `json:"capacity"` + Endip []string `json:"endip"` + Forsystemvms []string `json:"forsystemvms"` + Gateway string `json:"gateway"` + Id string `json:"id"` + Name string `json:"name"` + Netmask string `json:"netmask"` + Startip []string `json:"startip"` + Vlanid []string `json:"vlanid"` + Zoneid string `json:"zoneid"` + Zonename string `json:"zonename"` } -type DedicatedPod struct { - Accountid string `json:"accountid,omitempty"` - Affinitygroupid string `json:"affinitygroupid,omitempty"` - Domainid string `json:"domainid,omitempty"` - Id string `json:"id,omitempty"` - Podid string `json:"podid,omitempty"` - Podname string `json:"podname,omitempty"` +type UpdatePodResponseCapacity struct { + Capacityallocated int64 `json:"capacityallocated"` + Capacitytotal int64 `json:"capacitytotal"` + Capacityused int64 `json:"capacityused"` + Clusterid string `json:"clusterid"` + Clustername string `json:"clustername"` + Name string `json:"name"` + Percentused string `json:"percentused"` + Podid string `json:"podid"` + Podname string `json:"podname"` + Type int `json:"type"` + Zoneid string `json:"zoneid"` + Zonename string `json:"zonename"` } diff --git a/vendor/github.com/xanzy/go-cloudstack/cloudstack/PoolService.go b/vendor/github.com/xanzy/go-cloudstack/cloudstack/PoolService.go index f2f8fce99..b235a2821 100644 --- a/vendor/github.com/xanzy/go-cloudstack/cloudstack/PoolService.go +++ b/vendor/github.com/xanzy/go-cloudstack/cloudstack/PoolService.go @@ -1,5 +1,5 @@ // -// Copyright 2016, Sander van Harmelen +// Copyright 2018, Sander van Harmelen // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -24,277 +24,6 @@ import ( "strings" ) -type ListStoragePoolsParams struct { - p map[string]interface{} -} - -func (p *ListStoragePoolsParams) toURLValues() url.Values { - u := url.Values{} - if p.p == nil { - return u - } - if v, found := p.p["clusterid"]; found { - u.Set("clusterid", v.(string)) - } - if v, found := p.p["id"]; found { - u.Set("id", v.(string)) - } - if v, found := p.p["ipaddress"]; found { - u.Set("ipaddress", v.(string)) - } - if v, found := p.p["keyword"]; found { - u.Set("keyword", v.(string)) - } - if v, found := p.p["name"]; found { - u.Set("name", v.(string)) - } - if v, found := p.p["page"]; found { - vv := strconv.Itoa(v.(int)) - u.Set("page", vv) - } - if v, found := p.p["pagesize"]; found { - vv := strconv.Itoa(v.(int)) - u.Set("pagesize", vv) - } - if v, found := p.p["path"]; found { - u.Set("path", v.(string)) - } - if v, found := p.p["podid"]; found { - u.Set("podid", v.(string)) - } - if v, found := p.p["scope"]; found { - u.Set("scope", v.(string)) - } - if v, found := p.p["zoneid"]; found { - u.Set("zoneid", v.(string)) - } - return u -} - -func (p *ListStoragePoolsParams) SetClusterid(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["clusterid"] = v - return -} - -func (p *ListStoragePoolsParams) SetId(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["id"] = v - return -} - -func (p *ListStoragePoolsParams) SetIpaddress(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["ipaddress"] = v - return -} - -func (p *ListStoragePoolsParams) SetKeyword(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["keyword"] = v - return -} - -func (p *ListStoragePoolsParams) SetName(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["name"] = v - return -} - -func (p *ListStoragePoolsParams) SetPage(v int) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["page"] = v - return -} - -func (p *ListStoragePoolsParams) SetPagesize(v int) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["pagesize"] = v - return -} - -func (p *ListStoragePoolsParams) SetPath(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["path"] = v - return -} - -func (p *ListStoragePoolsParams) SetPodid(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["podid"] = v - return -} - -func (p *ListStoragePoolsParams) SetScope(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["scope"] = v - return -} - -func (p *ListStoragePoolsParams) SetZoneid(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["zoneid"] = v - return -} - -// You should always use this function to get a new ListStoragePoolsParams instance, -// as then you are sure you have configured all required params -func (s *PoolService) NewListStoragePoolsParams() *ListStoragePoolsParams { - p := &ListStoragePoolsParams{} - p.p = make(map[string]interface{}) - return p -} - -// This is a courtesy helper function, which in some cases may not work as expected! -func (s *PoolService) GetStoragePoolID(name string, opts ...OptionFunc) (string, int, error) { - p := &ListStoragePoolsParams{} - p.p = make(map[string]interface{}) - - p.p["name"] = name - - for _, fn := range opts { - if err := fn(s.cs, p); err != nil { - return "", -1, err - } - } - - l, err := s.ListStoragePools(p) - if err != nil { - return "", -1, err - } - - if l.Count == 0 { - return "", l.Count, fmt.Errorf("No match found for %s: %+v", name, l) - } - - if l.Count == 1 { - return l.StoragePools[0].Id, l.Count, nil - } - - if l.Count > 1 { - for _, v := range l.StoragePools { - if v.Name == name { - return v.Id, l.Count, nil - } - } - } - return "", l.Count, fmt.Errorf("Could not find an exact match for %s: %+v", name, l) -} - -// This is a courtesy helper function, which in some cases may not work as expected! -func (s *PoolService) GetStoragePoolByName(name string, opts ...OptionFunc) (*StoragePool, int, error) { - id, count, err := s.GetStoragePoolID(name, opts...) - if err != nil { - return nil, count, err - } - - r, count, err := s.GetStoragePoolByID(id, opts...) - if err != nil { - return nil, count, err - } - return r, count, nil -} - -// This is a courtesy helper function, which in some cases may not work as expected! -func (s *PoolService) GetStoragePoolByID(id string, opts ...OptionFunc) (*StoragePool, int, error) { - p := &ListStoragePoolsParams{} - p.p = make(map[string]interface{}) - - p.p["id"] = id - - for _, fn := range opts { - if err := fn(s.cs, p); err != nil { - return nil, -1, err - } - } - - l, err := s.ListStoragePools(p) - if err != nil { - if strings.Contains(err.Error(), fmt.Sprintf( - "Invalid parameter id value=%s due to incorrect long value format, "+ - "or entity does not exist", id)) { - return nil, 0, fmt.Errorf("No match found for %s: %+v", id, l) - } - return nil, -1, err - } - - if l.Count == 0 { - return nil, l.Count, fmt.Errorf("No match found for %s: %+v", id, l) - } - - if l.Count == 1 { - return l.StoragePools[0], l.Count, nil - } - return nil, l.Count, fmt.Errorf("There is more then one result for StoragePool UUID: %s!", id) -} - -// Lists storage pools. -func (s *PoolService) ListStoragePools(p *ListStoragePoolsParams) (*ListStoragePoolsResponse, error) { - resp, err := s.cs.newRequest("listStoragePools", p.toURLValues()) - if err != nil { - return nil, err - } - - var r ListStoragePoolsResponse - if err := json.Unmarshal(resp, &r); err != nil { - return nil, err - } - return &r, nil -} - -type ListStoragePoolsResponse struct { - Count int `json:"count"` - StoragePools []*StoragePool `json:"storagepool"` -} - -type StoragePool struct { - Capacityiops int64 `json:"capacityiops,omitempty"` - Clusterid string `json:"clusterid,omitempty"` - Clustername string `json:"clustername,omitempty"` - Created string `json:"created,omitempty"` - Disksizeallocated int64 `json:"disksizeallocated,omitempty"` - Disksizetotal int64 `json:"disksizetotal,omitempty"` - Disksizeused int64 `json:"disksizeused,omitempty"` - Hypervisor string `json:"hypervisor,omitempty"` - Id string `json:"id,omitempty"` - Ipaddress string `json:"ipaddress,omitempty"` - Name string `json:"name,omitempty"` - Overprovisionfactor string `json:"overprovisionfactor,omitempty"` - Path string `json:"path,omitempty"` - Podid string `json:"podid,omitempty"` - Podname string `json:"podname,omitempty"` - Scope string `json:"scope,omitempty"` - State string `json:"state,omitempty"` - Storagecapabilities map[string]string `json:"storagecapabilities,omitempty"` - Suitableformigration bool `json:"suitableformigration,omitempty"` - Tags string `json:"tags,omitempty"` - Type string `json:"type,omitempty"` - Zoneid string `json:"zoneid,omitempty"` - Zonename string `json:"zonename,omitempty"` -} - type CreateStoragePoolParams struct { p map[string]interface{} } @@ -318,8 +47,7 @@ func (p *CreateStoragePoolParams) toURLValues() url.Values { if v, found := p.p["details"]; found { i := 0 for k, vv := range v.(map[string]string) { - u.Set(fmt.Sprintf("details[%d].key", i), k) - u.Set(fmt.Sprintf("details[%d].value", i), vv) + u.Set(fmt.Sprintf("details[%d].%s", i, k), vv) i++ } } @@ -480,33 +208,503 @@ func (s *PoolService) CreateStoragePool(p *CreateStoragePoolParams) (*CreateStor if err := json.Unmarshal(resp, &r); err != nil { return nil, err } + return &r, nil } type CreateStoragePoolResponse struct { - Capacityiops int64 `json:"capacityiops,omitempty"` - Clusterid string `json:"clusterid,omitempty"` - Clustername string `json:"clustername,omitempty"` - Created string `json:"created,omitempty"` - Disksizeallocated int64 `json:"disksizeallocated,omitempty"` - Disksizetotal int64 `json:"disksizetotal,omitempty"` - Disksizeused int64 `json:"disksizeused,omitempty"` - Hypervisor string `json:"hypervisor,omitempty"` - Id string `json:"id,omitempty"` - Ipaddress string `json:"ipaddress,omitempty"` - Name string `json:"name,omitempty"` - Overprovisionfactor string `json:"overprovisionfactor,omitempty"` - Path string `json:"path,omitempty"` - Podid string `json:"podid,omitempty"` - Podname string `json:"podname,omitempty"` - Scope string `json:"scope,omitempty"` - State string `json:"state,omitempty"` - Storagecapabilities map[string]string `json:"storagecapabilities,omitempty"` - Suitableformigration bool `json:"suitableformigration,omitempty"` - Tags string `json:"tags,omitempty"` - Type string `json:"type,omitempty"` - Zoneid string `json:"zoneid,omitempty"` - Zonename string `json:"zonename,omitempty"` + Allocatediops int64 `json:"allocatediops"` + Capacityiops int64 `json:"capacityiops"` + Clusterid string `json:"clusterid"` + Clustername string `json:"clustername"` + Created string `json:"created"` + Disksizeallocated int64 `json:"disksizeallocated"` + Disksizetotal int64 `json:"disksizetotal"` + Disksizeused int64 `json:"disksizeused"` + Hypervisor string `json:"hypervisor"` + Id string `json:"id"` + Ipaddress string `json:"ipaddress"` + Name string `json:"name"` + Overprovisionfactor string `json:"overprovisionfactor"` + Path string `json:"path"` + Podid string `json:"podid"` + Podname string `json:"podname"` + Provider string `json:"provider"` + Scope string `json:"scope"` + State string `json:"state"` + Storagecapabilities map[string]string `json:"storagecapabilities"` + Suitableformigration bool `json:"suitableformigration"` + Tags string `json:"tags"` + Type string `json:"type"` + Zoneid string `json:"zoneid"` + Zonename string `json:"zonename"` +} + +type DeleteStoragePoolParams struct { + p map[string]interface{} +} + +func (p *DeleteStoragePoolParams) toURLValues() url.Values { + u := url.Values{} + if p.p == nil { + return u + } + if v, found := p.p["forced"]; found { + vv := strconv.FormatBool(v.(bool)) + u.Set("forced", vv) + } + if v, found := p.p["id"]; found { + u.Set("id", v.(string)) + } + return u +} + +func (p *DeleteStoragePoolParams) SetForced(v bool) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["forced"] = v + return +} + +func (p *DeleteStoragePoolParams) SetId(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["id"] = v + return +} + +// You should always use this function to get a new DeleteStoragePoolParams instance, +// as then you are sure you have configured all required params +func (s *PoolService) NewDeleteStoragePoolParams(id string) *DeleteStoragePoolParams { + p := &DeleteStoragePoolParams{} + p.p = make(map[string]interface{}) + p.p["id"] = id + return p +} + +// Deletes a storage pool. +func (s *PoolService) DeleteStoragePool(p *DeleteStoragePoolParams) (*DeleteStoragePoolResponse, error) { + resp, err := s.cs.newRequest("deleteStoragePool", p.toURLValues()) + if err != nil { + return nil, err + } + + var r DeleteStoragePoolResponse + if err := json.Unmarshal(resp, &r); err != nil { + return nil, err + } + + return &r, nil +} + +type DeleteStoragePoolResponse struct { + Displaytext string `json:"displaytext"` + Success bool `json:"success"` +} + +func (r *DeleteStoragePoolResponse) UnmarshalJSON(b []byte) error { + var m map[string]interface{} + err := json.Unmarshal(b, &m) + if err != nil { + return err + } + + if success, ok := m["success"].(string); ok { + m["success"] = success == "true" + b, err = json.Marshal(m) + if err != nil { + return err + } + } + + type alias DeleteStoragePoolResponse + return json.Unmarshal(b, (*alias)(r)) +} + +type FindStoragePoolsForMigrationParams struct { + p map[string]interface{} +} + +func (p *FindStoragePoolsForMigrationParams) toURLValues() url.Values { + u := url.Values{} + if p.p == nil { + return u + } + if v, found := p.p["id"]; found { + u.Set("id", v.(string)) + } + if v, found := p.p["keyword"]; found { + u.Set("keyword", v.(string)) + } + if v, found := p.p["page"]; found { + vv := strconv.Itoa(v.(int)) + u.Set("page", vv) + } + if v, found := p.p["pagesize"]; found { + vv := strconv.Itoa(v.(int)) + u.Set("pagesize", vv) + } + return u +} + +func (p *FindStoragePoolsForMigrationParams) SetId(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["id"] = v + return +} + +func (p *FindStoragePoolsForMigrationParams) SetKeyword(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["keyword"] = v + return +} + +func (p *FindStoragePoolsForMigrationParams) SetPage(v int) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["page"] = v + return +} + +func (p *FindStoragePoolsForMigrationParams) SetPagesize(v int) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["pagesize"] = v + return +} + +// You should always use this function to get a new FindStoragePoolsForMigrationParams instance, +// as then you are sure you have configured all required params +func (s *PoolService) NewFindStoragePoolsForMigrationParams(id string) *FindStoragePoolsForMigrationParams { + p := &FindStoragePoolsForMigrationParams{} + p.p = make(map[string]interface{}) + p.p["id"] = id + return p +} + +// Lists storage pools available for migration of a volume. +func (s *PoolService) FindStoragePoolsForMigration(p *FindStoragePoolsForMigrationParams) (*FindStoragePoolsForMigrationResponse, error) { + resp, err := s.cs.newRequest("findStoragePoolsForMigration", p.toURLValues()) + if err != nil { + return nil, err + } + + var r FindStoragePoolsForMigrationResponse + if err := json.Unmarshal(resp, &r); err != nil { + return nil, err + } + + return &r, nil +} + +type FindStoragePoolsForMigrationResponse struct { + Allocatediops int64 `json:"allocatediops"` + Capacityiops int64 `json:"capacityiops"` + Clusterid string `json:"clusterid"` + Clustername string `json:"clustername"` + Created string `json:"created"` + Disksizeallocated int64 `json:"disksizeallocated"` + Disksizetotal int64 `json:"disksizetotal"` + Disksizeused int64 `json:"disksizeused"` + Hypervisor string `json:"hypervisor"` + Id string `json:"id"` + Ipaddress string `json:"ipaddress"` + Name string `json:"name"` + Overprovisionfactor string `json:"overprovisionfactor"` + Path string `json:"path"` + Podid string `json:"podid"` + Podname string `json:"podname"` + Provider string `json:"provider"` + Scope string `json:"scope"` + State string `json:"state"` + Storagecapabilities map[string]string `json:"storagecapabilities"` + Suitableformigration bool `json:"suitableformigration"` + Tags string `json:"tags"` + Type string `json:"type"` + Zoneid string `json:"zoneid"` + Zonename string `json:"zonename"` +} + +type ListStoragePoolsParams struct { + p map[string]interface{} +} + +func (p *ListStoragePoolsParams) toURLValues() url.Values { + u := url.Values{} + if p.p == nil { + return u + } + if v, found := p.p["clusterid"]; found { + u.Set("clusterid", v.(string)) + } + if v, found := p.p["id"]; found { + u.Set("id", v.(string)) + } + if v, found := p.p["ipaddress"]; found { + u.Set("ipaddress", v.(string)) + } + if v, found := p.p["keyword"]; found { + u.Set("keyword", v.(string)) + } + if v, found := p.p["name"]; found { + u.Set("name", v.(string)) + } + if v, found := p.p["page"]; found { + vv := strconv.Itoa(v.(int)) + u.Set("page", vv) + } + if v, found := p.p["pagesize"]; found { + vv := strconv.Itoa(v.(int)) + u.Set("pagesize", vv) + } + if v, found := p.p["path"]; found { + u.Set("path", v.(string)) + } + if v, found := p.p["podid"]; found { + u.Set("podid", v.(string)) + } + if v, found := p.p["scope"]; found { + u.Set("scope", v.(string)) + } + if v, found := p.p["zoneid"]; found { + u.Set("zoneid", v.(string)) + } + return u +} + +func (p *ListStoragePoolsParams) SetClusterid(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["clusterid"] = v + return +} + +func (p *ListStoragePoolsParams) SetId(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["id"] = v + return +} + +func (p *ListStoragePoolsParams) SetIpaddress(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["ipaddress"] = v + return +} + +func (p *ListStoragePoolsParams) SetKeyword(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["keyword"] = v + return +} + +func (p *ListStoragePoolsParams) SetName(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["name"] = v + return +} + +func (p *ListStoragePoolsParams) SetPage(v int) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["page"] = v + return +} + +func (p *ListStoragePoolsParams) SetPagesize(v int) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["pagesize"] = v + return +} + +func (p *ListStoragePoolsParams) SetPath(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["path"] = v + return +} + +func (p *ListStoragePoolsParams) SetPodid(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["podid"] = v + return +} + +func (p *ListStoragePoolsParams) SetScope(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["scope"] = v + return +} + +func (p *ListStoragePoolsParams) SetZoneid(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["zoneid"] = v + return +} + +// You should always use this function to get a new ListStoragePoolsParams instance, +// as then you are sure you have configured all required params +func (s *PoolService) NewListStoragePoolsParams() *ListStoragePoolsParams { + p := &ListStoragePoolsParams{} + p.p = make(map[string]interface{}) + return p +} + +// This is a courtesy helper function, which in some cases may not work as expected! +func (s *PoolService) GetStoragePoolID(name string, opts ...OptionFunc) (string, int, error) { + p := &ListStoragePoolsParams{} + p.p = make(map[string]interface{}) + + p.p["name"] = name + + for _, fn := range append(s.cs.options, opts...) { + if err := fn(s.cs, p); err != nil { + return "", -1, err + } + } + + l, err := s.ListStoragePools(p) + if err != nil { + return "", -1, err + } + + if l.Count == 0 { + return "", l.Count, fmt.Errorf("No match found for %s: %+v", name, l) + } + + if l.Count == 1 { + return l.StoragePools[0].Id, l.Count, nil + } + + if l.Count > 1 { + for _, v := range l.StoragePools { + if v.Name == name { + return v.Id, l.Count, nil + } + } + } + return "", l.Count, fmt.Errorf("Could not find an exact match for %s: %+v", name, l) +} + +// This is a courtesy helper function, which in some cases may not work as expected! +func (s *PoolService) GetStoragePoolByName(name string, opts ...OptionFunc) (*StoragePool, int, error) { + id, count, err := s.GetStoragePoolID(name, opts...) + if err != nil { + return nil, count, err + } + + r, count, err := s.GetStoragePoolByID(id, opts...) + if err != nil { + return nil, count, err + } + return r, count, nil +} + +// This is a courtesy helper function, which in some cases may not work as expected! +func (s *PoolService) GetStoragePoolByID(id string, opts ...OptionFunc) (*StoragePool, int, error) { + p := &ListStoragePoolsParams{} + p.p = make(map[string]interface{}) + + p.p["id"] = id + + for _, fn := range append(s.cs.options, opts...) { + if err := fn(s.cs, p); err != nil { + return nil, -1, err + } + } + + l, err := s.ListStoragePools(p) + if err != nil { + if strings.Contains(err.Error(), fmt.Sprintf( + "Invalid parameter id value=%s due to incorrect long value format, "+ + "or entity does not exist", id)) { + return nil, 0, fmt.Errorf("No match found for %s: %+v", id, l) + } + return nil, -1, err + } + + if l.Count == 0 { + return nil, l.Count, fmt.Errorf("No match found for %s: %+v", id, l) + } + + if l.Count == 1 { + return l.StoragePools[0], l.Count, nil + } + return nil, l.Count, fmt.Errorf("There is more then one result for StoragePool UUID: %s!", id) +} + +// Lists storage pools. +func (s *PoolService) ListStoragePools(p *ListStoragePoolsParams) (*ListStoragePoolsResponse, error) { + resp, err := s.cs.newRequest("listStoragePools", p.toURLValues()) + if err != nil { + return nil, err + } + + var r ListStoragePoolsResponse + if err := json.Unmarshal(resp, &r); err != nil { + return nil, err + } + + return &r, nil +} + +type ListStoragePoolsResponse struct { + Count int `json:"count"` + StoragePools []*StoragePool `json:"storagepool"` +} + +type StoragePool struct { + Allocatediops int64 `json:"allocatediops"` + Capacityiops int64 `json:"capacityiops"` + Clusterid string `json:"clusterid"` + Clustername string `json:"clustername"` + Created string `json:"created"` + Disksizeallocated int64 `json:"disksizeallocated"` + Disksizetotal int64 `json:"disksizetotal"` + Disksizeused int64 `json:"disksizeused"` + Hypervisor string `json:"hypervisor"` + Id string `json:"id"` + Ipaddress string `json:"ipaddress"` + Name string `json:"name"` + Overprovisionfactor string `json:"overprovisionfactor"` + Path string `json:"path"` + Podid string `json:"podid"` + Podname string `json:"podname"` + Provider string `json:"provider"` + Scope string `json:"scope"` + State string `json:"state"` + Storagecapabilities map[string]string `json:"storagecapabilities"` + Suitableformigration bool `json:"suitableformigration"` + Tags string `json:"tags"` + Type string `json:"type"` + Zoneid string `json:"zoneid"` + Zonename string `json:"zonename"` } type UpdateStoragePoolParams struct { @@ -600,201 +798,34 @@ func (s *PoolService) UpdateStoragePool(p *UpdateStoragePoolParams) (*UpdateStor if err := json.Unmarshal(resp, &r); err != nil { return nil, err } + return &r, nil } type UpdateStoragePoolResponse struct { - Capacityiops int64 `json:"capacityiops,omitempty"` - Clusterid string `json:"clusterid,omitempty"` - Clustername string `json:"clustername,omitempty"` - Created string `json:"created,omitempty"` - Disksizeallocated int64 `json:"disksizeallocated,omitempty"` - Disksizetotal int64 `json:"disksizetotal,omitempty"` - Disksizeused int64 `json:"disksizeused,omitempty"` - Hypervisor string `json:"hypervisor,omitempty"` - Id string `json:"id,omitempty"` - Ipaddress string `json:"ipaddress,omitempty"` - Name string `json:"name,omitempty"` - Overprovisionfactor string `json:"overprovisionfactor,omitempty"` - Path string `json:"path,omitempty"` - Podid string `json:"podid,omitempty"` - Podname string `json:"podname,omitempty"` - Scope string `json:"scope,omitempty"` - State string `json:"state,omitempty"` - Storagecapabilities map[string]string `json:"storagecapabilities,omitempty"` - Suitableformigration bool `json:"suitableformigration,omitempty"` - Tags string `json:"tags,omitempty"` - Type string `json:"type,omitempty"` - Zoneid string `json:"zoneid,omitempty"` - Zonename string `json:"zonename,omitempty"` -} - -type DeleteStoragePoolParams struct { - p map[string]interface{} -} - -func (p *DeleteStoragePoolParams) toURLValues() url.Values { - u := url.Values{} - if p.p == nil { - return u - } - if v, found := p.p["forced"]; found { - vv := strconv.FormatBool(v.(bool)) - u.Set("forced", vv) - } - if v, found := p.p["id"]; found { - u.Set("id", v.(string)) - } - return u -} - -func (p *DeleteStoragePoolParams) SetForced(v bool) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["forced"] = v - return -} - -func (p *DeleteStoragePoolParams) SetId(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["id"] = v - return -} - -// You should always use this function to get a new DeleteStoragePoolParams instance, -// as then you are sure you have configured all required params -func (s *PoolService) NewDeleteStoragePoolParams(id string) *DeleteStoragePoolParams { - p := &DeleteStoragePoolParams{} - p.p = make(map[string]interface{}) - p.p["id"] = id - return p -} - -// Deletes a storage pool. -func (s *PoolService) DeleteStoragePool(p *DeleteStoragePoolParams) (*DeleteStoragePoolResponse, error) { - resp, err := s.cs.newRequest("deleteStoragePool", p.toURLValues()) - if err != nil { - return nil, err - } - - var r DeleteStoragePoolResponse - if err := json.Unmarshal(resp, &r); err != nil { - return nil, err - } - return &r, nil -} - -type DeleteStoragePoolResponse struct { - Displaytext string `json:"displaytext,omitempty"` - Success string `json:"success,omitempty"` -} - -type FindStoragePoolsForMigrationParams struct { - p map[string]interface{} -} - -func (p *FindStoragePoolsForMigrationParams) toURLValues() url.Values { - u := url.Values{} - if p.p == nil { - return u - } - if v, found := p.p["id"]; found { - u.Set("id", v.(string)) - } - if v, found := p.p["keyword"]; found { - u.Set("keyword", v.(string)) - } - if v, found := p.p["page"]; found { - vv := strconv.Itoa(v.(int)) - u.Set("page", vv) - } - if v, found := p.p["pagesize"]; found { - vv := strconv.Itoa(v.(int)) - u.Set("pagesize", vv) - } - return u -} - -func (p *FindStoragePoolsForMigrationParams) SetId(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["id"] = v - return -} - -func (p *FindStoragePoolsForMigrationParams) SetKeyword(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["keyword"] = v - return -} - -func (p *FindStoragePoolsForMigrationParams) SetPage(v int) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["page"] = v - return -} - -func (p *FindStoragePoolsForMigrationParams) SetPagesize(v int) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["pagesize"] = v - return -} - -// You should always use this function to get a new FindStoragePoolsForMigrationParams instance, -// as then you are sure you have configured all required params -func (s *PoolService) NewFindStoragePoolsForMigrationParams(id string) *FindStoragePoolsForMigrationParams { - p := &FindStoragePoolsForMigrationParams{} - p.p = make(map[string]interface{}) - p.p["id"] = id - return p -} - -// Lists storage pools available for migration of a volume. -func (s *PoolService) FindStoragePoolsForMigration(p *FindStoragePoolsForMigrationParams) (*FindStoragePoolsForMigrationResponse, error) { - resp, err := s.cs.newRequest("findStoragePoolsForMigration", p.toURLValues()) - if err != nil { - return nil, err - } - - var r FindStoragePoolsForMigrationResponse - if err := json.Unmarshal(resp, &r); err != nil { - return nil, err - } - return &r, nil -} - -type FindStoragePoolsForMigrationResponse struct { - Capacityiops int64 `json:"capacityiops,omitempty"` - Clusterid string `json:"clusterid,omitempty"` - Clustername string `json:"clustername,omitempty"` - Created string `json:"created,omitempty"` - Disksizeallocated int64 `json:"disksizeallocated,omitempty"` - Disksizetotal int64 `json:"disksizetotal,omitempty"` - Disksizeused int64 `json:"disksizeused,omitempty"` - Hypervisor string `json:"hypervisor,omitempty"` - Id string `json:"id,omitempty"` - Ipaddress string `json:"ipaddress,omitempty"` - Name string `json:"name,omitempty"` - Overprovisionfactor string `json:"overprovisionfactor,omitempty"` - Path string `json:"path,omitempty"` - Podid string `json:"podid,omitempty"` - Podname string `json:"podname,omitempty"` - Scope string `json:"scope,omitempty"` - State string `json:"state,omitempty"` - Storagecapabilities map[string]string `json:"storagecapabilities,omitempty"` - Suitableformigration bool `json:"suitableformigration,omitempty"` - Tags string `json:"tags,omitempty"` - Type string `json:"type,omitempty"` - Zoneid string `json:"zoneid,omitempty"` - Zonename string `json:"zonename,omitempty"` + Allocatediops int64 `json:"allocatediops"` + Capacityiops int64 `json:"capacityiops"` + Clusterid string `json:"clusterid"` + Clustername string `json:"clustername"` + Created string `json:"created"` + Disksizeallocated int64 `json:"disksizeallocated"` + Disksizetotal int64 `json:"disksizetotal"` + Disksizeused int64 `json:"disksizeused"` + Hypervisor string `json:"hypervisor"` + Id string `json:"id"` + Ipaddress string `json:"ipaddress"` + Name string `json:"name"` + Overprovisionfactor string `json:"overprovisionfactor"` + Path string `json:"path"` + Podid string `json:"podid"` + Podname string `json:"podname"` + Provider string `json:"provider"` + Scope string `json:"scope"` + State string `json:"state"` + Storagecapabilities map[string]string `json:"storagecapabilities"` + Suitableformigration bool `json:"suitableformigration"` + Tags string `json:"tags"` + Type string `json:"type"` + Zoneid string `json:"zoneid"` + Zonename string `json:"zonename"` } diff --git a/vendor/github.com/xanzy/go-cloudstack/cloudstack/PortableIPService.go b/vendor/github.com/xanzy/go-cloudstack/cloudstack/PortableIPService.go index 2896ae2bb..6a9ddf782 100644 --- a/vendor/github.com/xanzy/go-cloudstack/cloudstack/PortableIPService.go +++ b/vendor/github.com/xanzy/go-cloudstack/cloudstack/PortableIPService.go @@ -1,5 +1,5 @@ // -// Copyright 2016, Sander van Harmelen +// Copyright 2018, Sander van Harmelen // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -147,30 +147,33 @@ func (s *PortableIPService) CreatePortableIpRange(p *CreatePortableIpRangeParams return nil, err } } + return &r, nil } type CreatePortableIpRangeResponse struct { - JobID string `json:"jobid,omitempty"` - Endip string `json:"endip,omitempty"` - Gateway string `json:"gateway,omitempty"` - Id string `json:"id,omitempty"` - Netmask string `json:"netmask,omitempty"` - Portableipaddress []struct { - Accountid string `json:"accountid,omitempty"` - Allocated string `json:"allocated,omitempty"` - Domainid string `json:"domainid,omitempty"` - Ipaddress string `json:"ipaddress,omitempty"` - Networkid string `json:"networkid,omitempty"` - Physicalnetworkid string `json:"physicalnetworkid,omitempty"` - Regionid int `json:"regionid,omitempty"` - State string `json:"state,omitempty"` - Vpcid string `json:"vpcid,omitempty"` - Zoneid string `json:"zoneid,omitempty"` - } `json:"portableipaddress,omitempty"` - Regionid int `json:"regionid,omitempty"` - Startip string `json:"startip,omitempty"` - Vlan string `json:"vlan,omitempty"` + JobID string `json:"jobid"` + Endip string `json:"endip"` + Gateway string `json:"gateway"` + Id string `json:"id"` + Netmask string `json:"netmask"` + Portableipaddress []CreatePortableIpRangeResponsePortableipaddress `json:"portableipaddress"` + Regionid int `json:"regionid"` + Startip string `json:"startip"` + Vlan string `json:"vlan"` +} + +type CreatePortableIpRangeResponsePortableipaddress struct { + Accountid string `json:"accountid"` + Allocated string `json:"allocated"` + Domainid string `json:"domainid"` + Ipaddress string `json:"ipaddress"` + Networkid string `json:"networkid"` + Physicalnetworkid string `json:"physicalnetworkid"` + Regionid int `json:"regionid"` + State string `json:"state"` + Vpcid string `json:"vpcid"` + Zoneid string `json:"zoneid"` } type DeletePortableIpRangeParams struct { @@ -231,13 +234,14 @@ func (s *PortableIPService) DeletePortableIpRange(p *DeletePortableIpRangeParams return nil, err } } + return &r, nil } type DeletePortableIpRangeResponse struct { - JobID string `json:"jobid,omitempty"` - Displaytext string `json:"displaytext,omitempty"` - Success bool `json:"success,omitempty"` + JobID string `json:"jobid"` + Displaytext string `json:"displaytext"` + Success bool `json:"success"` } type ListPortableIpRangesParams struct { @@ -325,7 +329,7 @@ func (s *PortableIPService) GetPortableIpRangeByID(id string, opts ...OptionFunc p.p["id"] = id - for _, fn := range opts { + for _, fn := range append(s.cs.options, opts...) { if err := fn(s.cs, p); err != nil { return nil, -1, err } @@ -362,6 +366,7 @@ func (s *PortableIPService) ListPortableIpRanges(p *ListPortableIpRangesParams) if err := json.Unmarshal(resp, &r); err != nil { return nil, err } + return &r, nil } @@ -371,23 +376,25 @@ type ListPortableIpRangesResponse struct { } type PortableIpRange struct { - Endip string `json:"endip,omitempty"` - Gateway string `json:"gateway,omitempty"` - Id string `json:"id,omitempty"` - Netmask string `json:"netmask,omitempty"` - Portableipaddress []struct { - Accountid string `json:"accountid,omitempty"` - Allocated string `json:"allocated,omitempty"` - Domainid string `json:"domainid,omitempty"` - Ipaddress string `json:"ipaddress,omitempty"` - Networkid string `json:"networkid,omitempty"` - Physicalnetworkid string `json:"physicalnetworkid,omitempty"` - Regionid int `json:"regionid,omitempty"` - State string `json:"state,omitempty"` - Vpcid string `json:"vpcid,omitempty"` - Zoneid string `json:"zoneid,omitempty"` - } `json:"portableipaddress,omitempty"` - Regionid int `json:"regionid,omitempty"` - Startip string `json:"startip,omitempty"` - Vlan string `json:"vlan,omitempty"` + Endip string `json:"endip"` + Gateway string `json:"gateway"` + Id string `json:"id"` + Netmask string `json:"netmask"` + Portableipaddress []PortableIpRangePortableipaddress `json:"portableipaddress"` + Regionid int `json:"regionid"` + Startip string `json:"startip"` + Vlan string `json:"vlan"` +} + +type PortableIpRangePortableipaddress struct { + Accountid string `json:"accountid"` + Allocated string `json:"allocated"` + Domainid string `json:"domainid"` + Ipaddress string `json:"ipaddress"` + Networkid string `json:"networkid"` + Physicalnetworkid string `json:"physicalnetworkid"` + Regionid int `json:"regionid"` + State string `json:"state"` + Vpcid string `json:"vpcid"` + Zoneid string `json:"zoneid"` } diff --git a/vendor/github.com/xanzy/go-cloudstack/cloudstack/ProjectService.go b/vendor/github.com/xanzy/go-cloudstack/cloudstack/ProjectService.go index 8b9c0e86f..de767a106 100644 --- a/vendor/github.com/xanzy/go-cloudstack/cloudstack/ProjectService.go +++ b/vendor/github.com/xanzy/go-cloudstack/cloudstack/ProjectService.go @@ -1,5 +1,5 @@ // -// Copyright 2016, Sander van Harmelen +// Copyright 2018, Sander van Harmelen // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -24,6 +24,121 @@ import ( "strings" ) +type ActivateProjectParams struct { + p map[string]interface{} +} + +func (p *ActivateProjectParams) toURLValues() url.Values { + u := url.Values{} + if p.p == nil { + return u + } + if v, found := p.p["id"]; found { + u.Set("id", v.(string)) + } + return u +} + +func (p *ActivateProjectParams) SetId(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["id"] = v + return +} + +// You should always use this function to get a new ActivateProjectParams instance, +// as then you are sure you have configured all required params +func (s *ProjectService) NewActivateProjectParams(id string) *ActivateProjectParams { + p := &ActivateProjectParams{} + p.p = make(map[string]interface{}) + p.p["id"] = id + return p +} + +// Activates a project +func (s *ProjectService) ActivateProject(p *ActivateProjectParams) (*ActivateProjectResponse, error) { + resp, err := s.cs.newRequest("activateProject", p.toURLValues()) + if err != nil { + return nil, err + } + + var r ActivateProjectResponse + if err := json.Unmarshal(resp, &r); err != nil { + return nil, err + } + + // If we have a async client, we need to wait for the async result + if s.cs.async { + b, err := s.cs.GetAsyncJobResult(r.JobID, s.cs.timeout) + if err != nil { + if err == AsyncTimeoutErr { + return &r, err + } + return nil, err + } + + b, err = getRawValue(b) + if err != nil { + return nil, err + } + + if err := json.Unmarshal(b, &r); err != nil { + return nil, err + } + } + + return &r, nil +} + +type ActivateProjectResponse struct { + JobID string `json:"jobid"` + Account string `json:"account"` + Cpuavailable string `json:"cpuavailable"` + Cpulimit string `json:"cpulimit"` + Cputotal int64 `json:"cputotal"` + Displaytext string `json:"displaytext"` + Domain string `json:"domain"` + Domainid string `json:"domainid"` + Id string `json:"id"` + Ipavailable string `json:"ipavailable"` + Iplimit string `json:"iplimit"` + Iptotal int64 `json:"iptotal"` + Memoryavailable string `json:"memoryavailable"` + Memorylimit string `json:"memorylimit"` + Memorytotal int64 `json:"memorytotal"` + Name string `json:"name"` + Networkavailable string `json:"networkavailable"` + Networklimit string `json:"networklimit"` + Networktotal int64 `json:"networktotal"` + Primarystorageavailable string `json:"primarystorageavailable"` + Primarystoragelimit string `json:"primarystoragelimit"` + Primarystoragetotal int64 `json:"primarystoragetotal"` + Projectaccountname string `json:"projectaccountname"` + Secondarystorageavailable string `json:"secondarystorageavailable"` + Secondarystoragelimit string `json:"secondarystoragelimit"` + Secondarystoragetotal float64 `json:"secondarystoragetotal"` + Snapshotavailable string `json:"snapshotavailable"` + Snapshotlimit string `json:"snapshotlimit"` + Snapshottotal int64 `json:"snapshottotal"` + State string `json:"state"` + Tags []Tags `json:"tags"` + Templateavailable string `json:"templateavailable"` + Templatelimit string `json:"templatelimit"` + Templatetotal int64 `json:"templatetotal"` + Vmavailable string `json:"vmavailable"` + Vmlimit string `json:"vmlimit"` + Vmrunning int `json:"vmrunning"` + Vmstopped int `json:"vmstopped"` + Vmtotal int64 `json:"vmtotal"` + Volumeavailable string `json:"volumeavailable"` + Volumelimit string `json:"volumelimit"` + Volumetotal int64 `json:"volumetotal"` + Vpcavailable string `json:"vpcavailable"` + Vpclimit string `json:"vpclimit"` + Vpctotal int64 `json:"vpctotal"` +} + type CreateProjectParams struct { p map[string]interface{} } @@ -121,65 +236,56 @@ func (s *ProjectService) CreateProject(p *CreateProjectParams) (*CreateProjectRe return nil, err } } + return &r, nil } type CreateProjectResponse struct { - JobID string `json:"jobid,omitempty"` - Account string `json:"account,omitempty"` - Cpuavailable string `json:"cpuavailable,omitempty"` - Cpulimit string `json:"cpulimit,omitempty"` - Cputotal int64 `json:"cputotal,omitempty"` - Displaytext string `json:"displaytext,omitempty"` - Domain string `json:"domain,omitempty"` - Domainid string `json:"domainid,omitempty"` - Id string `json:"id,omitempty"` - Ipavailable string `json:"ipavailable,omitempty"` - Iplimit string `json:"iplimit,omitempty"` - Iptotal int64 `json:"iptotal,omitempty"` - Memoryavailable string `json:"memoryavailable,omitempty"` - Memorylimit string `json:"memorylimit,omitempty"` - Memorytotal int64 `json:"memorytotal,omitempty"` - Name string `json:"name,omitempty"` - Networkavailable string `json:"networkavailable,omitempty"` - Networklimit string `json:"networklimit,omitempty"` - Networktotal int64 `json:"networktotal,omitempty"` - Primarystorageavailable string `json:"primarystorageavailable,omitempty"` - Primarystoragelimit string `json:"primarystoragelimit,omitempty"` - Primarystoragetotal int64 `json:"primarystoragetotal,omitempty"` - Secondarystorageavailable string `json:"secondarystorageavailable,omitempty"` - Secondarystoragelimit string `json:"secondarystoragelimit,omitempty"` - Secondarystoragetotal int64 `json:"secondarystoragetotal,omitempty"` - Snapshotavailable string `json:"snapshotavailable,omitempty"` - Snapshotlimit string `json:"snapshotlimit,omitempty"` - Snapshottotal int64 `json:"snapshottotal,omitempty"` - State string `json:"state,omitempty"` - Tags []struct { - Account string `json:"account,omitempty"` - Customer string `json:"customer,omitempty"` - Domain string `json:"domain,omitempty"` - Domainid string `json:"domainid,omitempty"` - Key string `json:"key,omitempty"` - Project string `json:"project,omitempty"` - Projectid string `json:"projectid,omitempty"` - Resourceid string `json:"resourceid,omitempty"` - Resourcetype string `json:"resourcetype,omitempty"` - Value string `json:"value,omitempty"` - } `json:"tags,omitempty"` - Templateavailable string `json:"templateavailable,omitempty"` - Templatelimit string `json:"templatelimit,omitempty"` - Templatetotal int64 `json:"templatetotal,omitempty"` - Vmavailable string `json:"vmavailable,omitempty"` - Vmlimit string `json:"vmlimit,omitempty"` - Vmrunning int `json:"vmrunning,omitempty"` - Vmstopped int `json:"vmstopped,omitempty"` - Vmtotal int64 `json:"vmtotal,omitempty"` - Volumeavailable string `json:"volumeavailable,omitempty"` - Volumelimit string `json:"volumelimit,omitempty"` - Volumetotal int64 `json:"volumetotal,omitempty"` - Vpcavailable string `json:"vpcavailable,omitempty"` - Vpclimit string `json:"vpclimit,omitempty"` - Vpctotal int64 `json:"vpctotal,omitempty"` + JobID string `json:"jobid"` + Account string `json:"account"` + Cpuavailable string `json:"cpuavailable"` + Cpulimit string `json:"cpulimit"` + Cputotal int64 `json:"cputotal"` + Displaytext string `json:"displaytext"` + Domain string `json:"domain"` + Domainid string `json:"domainid"` + Id string `json:"id"` + Ipavailable string `json:"ipavailable"` + Iplimit string `json:"iplimit"` + Iptotal int64 `json:"iptotal"` + Memoryavailable string `json:"memoryavailable"` + Memorylimit string `json:"memorylimit"` + Memorytotal int64 `json:"memorytotal"` + Name string `json:"name"` + Networkavailable string `json:"networkavailable"` + Networklimit string `json:"networklimit"` + Networktotal int64 `json:"networktotal"` + Primarystorageavailable string `json:"primarystorageavailable"` + Primarystoragelimit string `json:"primarystoragelimit"` + Primarystoragetotal int64 `json:"primarystoragetotal"` + Projectaccountname string `json:"projectaccountname"` + Secondarystorageavailable string `json:"secondarystorageavailable"` + Secondarystoragelimit string `json:"secondarystoragelimit"` + Secondarystoragetotal float64 `json:"secondarystoragetotal"` + Snapshotavailable string `json:"snapshotavailable"` + Snapshotlimit string `json:"snapshotlimit"` + Snapshottotal int64 `json:"snapshottotal"` + State string `json:"state"` + Tags []Tags `json:"tags"` + Templateavailable string `json:"templateavailable"` + Templatelimit string `json:"templatelimit"` + Templatetotal int64 `json:"templatetotal"` + Vmavailable string `json:"vmavailable"` + Vmlimit string `json:"vmlimit"` + Vmrunning int `json:"vmrunning"` + Vmstopped int `json:"vmstopped"` + Vmtotal int64 `json:"vmtotal"` + Volumeavailable string `json:"volumeavailable"` + Volumelimit string `json:"volumelimit"` + Volumetotal int64 `json:"volumetotal"` + Vpcavailable string `json:"vpcavailable"` + Vpclimit string `json:"vpclimit"` + Vpctotal int64 `json:"vpctotal"` } type DeleteProjectParams struct { @@ -240,20 +346,89 @@ func (s *ProjectService) DeleteProject(p *DeleteProjectParams) (*DeleteProjectRe return nil, err } } + return &r, nil } type DeleteProjectResponse struct { - JobID string `json:"jobid,omitempty"` - Displaytext string `json:"displaytext,omitempty"` - Success bool `json:"success,omitempty"` + JobID string `json:"jobid"` + Displaytext string `json:"displaytext"` + Success bool `json:"success"` } -type UpdateProjectParams struct { +type DeleteProjectInvitationParams struct { p map[string]interface{} } -func (p *UpdateProjectParams) toURLValues() url.Values { +func (p *DeleteProjectInvitationParams) toURLValues() url.Values { + u := url.Values{} + if p.p == nil { + return u + } + if v, found := p.p["id"]; found { + u.Set("id", v.(string)) + } + return u +} + +func (p *DeleteProjectInvitationParams) SetId(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["id"] = v + return +} + +// You should always use this function to get a new DeleteProjectInvitationParams instance, +// as then you are sure you have configured all required params +func (s *ProjectService) NewDeleteProjectInvitationParams(id string) *DeleteProjectInvitationParams { + p := &DeleteProjectInvitationParams{} + p.p = make(map[string]interface{}) + p.p["id"] = id + return p +} + +// Deletes project invitation +func (s *ProjectService) DeleteProjectInvitation(p *DeleteProjectInvitationParams) (*DeleteProjectInvitationResponse, error) { + resp, err := s.cs.newRequest("deleteProjectInvitation", p.toURLValues()) + if err != nil { + return nil, err + } + + var r DeleteProjectInvitationResponse + if err := json.Unmarshal(resp, &r); err != nil { + return nil, err + } + + // If we have a async client, we need to wait for the async result + if s.cs.async { + b, err := s.cs.GetAsyncJobResult(r.JobID, s.cs.timeout) + if err != nil { + if err == AsyncTimeoutErr { + return &r, err + } + return nil, err + } + + if err := json.Unmarshal(b, &r); err != nil { + return nil, err + } + } + + return &r, nil +} + +type DeleteProjectInvitationResponse struct { + JobID string `json:"jobid"` + Displaytext string `json:"displaytext"` + Success bool `json:"success"` +} + +type ListProjectInvitationsParams struct { + p map[string]interface{} +} + +func (p *ListProjectInvitationsParams) toURLValues() url.Values { u := url.Values{} if p.p == nil { return u @@ -261,16 +436,45 @@ func (p *UpdateProjectParams) toURLValues() url.Values { if v, found := p.p["account"]; found { u.Set("account", v.(string)) } - if v, found := p.p["displaytext"]; found { - u.Set("displaytext", v.(string)) + if v, found := p.p["activeonly"]; found { + vv := strconv.FormatBool(v.(bool)) + u.Set("activeonly", vv) + } + if v, found := p.p["domainid"]; found { + u.Set("domainid", v.(string)) } if v, found := p.p["id"]; found { u.Set("id", v.(string)) } + if v, found := p.p["isrecursive"]; found { + vv := strconv.FormatBool(v.(bool)) + u.Set("isrecursive", vv) + } + if v, found := p.p["keyword"]; found { + u.Set("keyword", v.(string)) + } + if v, found := p.p["listall"]; found { + vv := strconv.FormatBool(v.(bool)) + u.Set("listall", vv) + } + if v, found := p.p["page"]; found { + vv := strconv.Itoa(v.(int)) + u.Set("page", vv) + } + if v, found := p.p["pagesize"]; found { + vv := strconv.Itoa(v.(int)) + u.Set("pagesize", vv) + } + if v, found := p.p["projectid"]; found { + u.Set("projectid", v.(string)) + } + if v, found := p.p["state"]; found { + u.Set("state", v.(string)) + } return u } -func (p *UpdateProjectParams) SetAccount(v string) { +func (p *ListProjectInvitationsParams) SetAccount(v string) { if p.p == nil { p.p = make(map[string]interface{}) } @@ -278,15 +482,23 @@ func (p *UpdateProjectParams) SetAccount(v string) { return } -func (p *UpdateProjectParams) SetDisplaytext(v string) { +func (p *ListProjectInvitationsParams) SetActiveonly(v bool) { if p.p == nil { p.p = make(map[string]interface{}) } - p.p["displaytext"] = v + p.p["activeonly"] = v return } -func (p *UpdateProjectParams) SetId(v string) { +func (p *ListProjectInvitationsParams) SetDomainid(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["domainid"] = v + return +} + +func (p *ListProjectInvitationsParams) SetId(v string) { if p.p == nil { p.p = make(map[string]interface{}) } @@ -294,353 +506,132 @@ func (p *UpdateProjectParams) SetId(v string) { return } -// You should always use this function to get a new UpdateProjectParams instance, -// as then you are sure you have configured all required params -func (s *ProjectService) NewUpdateProjectParams(id string) *UpdateProjectParams { - p := &UpdateProjectParams{} - p.p = make(map[string]interface{}) - p.p["id"] = id - return p -} - -// Updates a project -func (s *ProjectService) UpdateProject(p *UpdateProjectParams) (*UpdateProjectResponse, error) { - resp, err := s.cs.newRequest("updateProject", p.toURLValues()) - if err != nil { - return nil, err - } - - var r UpdateProjectResponse - if err := json.Unmarshal(resp, &r); err != nil { - return nil, err - } - - // If we have a async client, we need to wait for the async result - if s.cs.async { - b, err := s.cs.GetAsyncJobResult(r.JobID, s.cs.timeout) - if err != nil { - if err == AsyncTimeoutErr { - return &r, err - } - return nil, err - } - - b, err = getRawValue(b) - if err != nil { - return nil, err - } - - if err := json.Unmarshal(b, &r); err != nil { - return nil, err - } - } - return &r, nil -} - -type UpdateProjectResponse struct { - JobID string `json:"jobid,omitempty"` - Account string `json:"account,omitempty"` - Cpuavailable string `json:"cpuavailable,omitempty"` - Cpulimit string `json:"cpulimit,omitempty"` - Cputotal int64 `json:"cputotal,omitempty"` - Displaytext string `json:"displaytext,omitempty"` - Domain string `json:"domain,omitempty"` - Domainid string `json:"domainid,omitempty"` - Id string `json:"id,omitempty"` - Ipavailable string `json:"ipavailable,omitempty"` - Iplimit string `json:"iplimit,omitempty"` - Iptotal int64 `json:"iptotal,omitempty"` - Memoryavailable string `json:"memoryavailable,omitempty"` - Memorylimit string `json:"memorylimit,omitempty"` - Memorytotal int64 `json:"memorytotal,omitempty"` - Name string `json:"name,omitempty"` - Networkavailable string `json:"networkavailable,omitempty"` - Networklimit string `json:"networklimit,omitempty"` - Networktotal int64 `json:"networktotal,omitempty"` - Primarystorageavailable string `json:"primarystorageavailable,omitempty"` - Primarystoragelimit string `json:"primarystoragelimit,omitempty"` - Primarystoragetotal int64 `json:"primarystoragetotal,omitempty"` - Secondarystorageavailable string `json:"secondarystorageavailable,omitempty"` - Secondarystoragelimit string `json:"secondarystoragelimit,omitempty"` - Secondarystoragetotal int64 `json:"secondarystoragetotal,omitempty"` - Snapshotavailable string `json:"snapshotavailable,omitempty"` - Snapshotlimit string `json:"snapshotlimit,omitempty"` - Snapshottotal int64 `json:"snapshottotal,omitempty"` - State string `json:"state,omitempty"` - Tags []struct { - Account string `json:"account,omitempty"` - Customer string `json:"customer,omitempty"` - Domain string `json:"domain,omitempty"` - Domainid string `json:"domainid,omitempty"` - Key string `json:"key,omitempty"` - Project string `json:"project,omitempty"` - Projectid string `json:"projectid,omitempty"` - Resourceid string `json:"resourceid,omitempty"` - Resourcetype string `json:"resourcetype,omitempty"` - Value string `json:"value,omitempty"` - } `json:"tags,omitempty"` - Templateavailable string `json:"templateavailable,omitempty"` - Templatelimit string `json:"templatelimit,omitempty"` - Templatetotal int64 `json:"templatetotal,omitempty"` - Vmavailable string `json:"vmavailable,omitempty"` - Vmlimit string `json:"vmlimit,omitempty"` - Vmrunning int `json:"vmrunning,omitempty"` - Vmstopped int `json:"vmstopped,omitempty"` - Vmtotal int64 `json:"vmtotal,omitempty"` - Volumeavailable string `json:"volumeavailable,omitempty"` - Volumelimit string `json:"volumelimit,omitempty"` - Volumetotal int64 `json:"volumetotal,omitempty"` - Vpcavailable string `json:"vpcavailable,omitempty"` - Vpclimit string `json:"vpclimit,omitempty"` - Vpctotal int64 `json:"vpctotal,omitempty"` -} - -type ActivateProjectParams struct { - p map[string]interface{} -} - -func (p *ActivateProjectParams) toURLValues() url.Values { - u := url.Values{} - if p.p == nil { - return u - } - if v, found := p.p["id"]; found { - u.Set("id", v.(string)) - } - return u -} - -func (p *ActivateProjectParams) SetId(v string) { +func (p *ListProjectInvitationsParams) SetIsrecursive(v bool) { if p.p == nil { p.p = make(map[string]interface{}) } - p.p["id"] = v + p.p["isrecursive"] = v return } -// You should always use this function to get a new ActivateProjectParams instance, -// as then you are sure you have configured all required params -func (s *ProjectService) NewActivateProjectParams(id string) *ActivateProjectParams { - p := &ActivateProjectParams{} - p.p = make(map[string]interface{}) - p.p["id"] = id - return p -} - -// Activates a project -func (s *ProjectService) ActivateProject(p *ActivateProjectParams) (*ActivateProjectResponse, error) { - resp, err := s.cs.newRequest("activateProject", p.toURLValues()) - if err != nil { - return nil, err - } - - var r ActivateProjectResponse - if err := json.Unmarshal(resp, &r); err != nil { - return nil, err - } - - // If we have a async client, we need to wait for the async result - if s.cs.async { - b, err := s.cs.GetAsyncJobResult(r.JobID, s.cs.timeout) - if err != nil { - if err == AsyncTimeoutErr { - return &r, err - } - return nil, err - } - - b, err = getRawValue(b) - if err != nil { - return nil, err - } - - if err := json.Unmarshal(b, &r); err != nil { - return nil, err - } - } - return &r, nil -} - -type ActivateProjectResponse struct { - JobID string `json:"jobid,omitempty"` - Account string `json:"account,omitempty"` - Cpuavailable string `json:"cpuavailable,omitempty"` - Cpulimit string `json:"cpulimit,omitempty"` - Cputotal int64 `json:"cputotal,omitempty"` - Displaytext string `json:"displaytext,omitempty"` - Domain string `json:"domain,omitempty"` - Domainid string `json:"domainid,omitempty"` - Id string `json:"id,omitempty"` - Ipavailable string `json:"ipavailable,omitempty"` - Iplimit string `json:"iplimit,omitempty"` - Iptotal int64 `json:"iptotal,omitempty"` - Memoryavailable string `json:"memoryavailable,omitempty"` - Memorylimit string `json:"memorylimit,omitempty"` - Memorytotal int64 `json:"memorytotal,omitempty"` - Name string `json:"name,omitempty"` - Networkavailable string `json:"networkavailable,omitempty"` - Networklimit string `json:"networklimit,omitempty"` - Networktotal int64 `json:"networktotal,omitempty"` - Primarystorageavailable string `json:"primarystorageavailable,omitempty"` - Primarystoragelimit string `json:"primarystoragelimit,omitempty"` - Primarystoragetotal int64 `json:"primarystoragetotal,omitempty"` - Secondarystorageavailable string `json:"secondarystorageavailable,omitempty"` - Secondarystoragelimit string `json:"secondarystoragelimit,omitempty"` - Secondarystoragetotal int64 `json:"secondarystoragetotal,omitempty"` - Snapshotavailable string `json:"snapshotavailable,omitempty"` - Snapshotlimit string `json:"snapshotlimit,omitempty"` - Snapshottotal int64 `json:"snapshottotal,omitempty"` - State string `json:"state,omitempty"` - Tags []struct { - Account string `json:"account,omitempty"` - Customer string `json:"customer,omitempty"` - Domain string `json:"domain,omitempty"` - Domainid string `json:"domainid,omitempty"` - Key string `json:"key,omitempty"` - Project string `json:"project,omitempty"` - Projectid string `json:"projectid,omitempty"` - Resourceid string `json:"resourceid,omitempty"` - Resourcetype string `json:"resourcetype,omitempty"` - Value string `json:"value,omitempty"` - } `json:"tags,omitempty"` - Templateavailable string `json:"templateavailable,omitempty"` - Templatelimit string `json:"templatelimit,omitempty"` - Templatetotal int64 `json:"templatetotal,omitempty"` - Vmavailable string `json:"vmavailable,omitempty"` - Vmlimit string `json:"vmlimit,omitempty"` - Vmrunning int `json:"vmrunning,omitempty"` - Vmstopped int `json:"vmstopped,omitempty"` - Vmtotal int64 `json:"vmtotal,omitempty"` - Volumeavailable string `json:"volumeavailable,omitempty"` - Volumelimit string `json:"volumelimit,omitempty"` - Volumetotal int64 `json:"volumetotal,omitempty"` - Vpcavailable string `json:"vpcavailable,omitempty"` - Vpclimit string `json:"vpclimit,omitempty"` - Vpctotal int64 `json:"vpctotal,omitempty"` -} - -type SuspendProjectParams struct { - p map[string]interface{} -} - -func (p *SuspendProjectParams) toURLValues() url.Values { - u := url.Values{} - if p.p == nil { - return u - } - if v, found := p.p["id"]; found { - u.Set("id", v.(string)) - } - return u -} - -func (p *SuspendProjectParams) SetId(v string) { +func (p *ListProjectInvitationsParams) SetKeyword(v string) { if p.p == nil { p.p = make(map[string]interface{}) } - p.p["id"] = v + p.p["keyword"] = v return } -// You should always use this function to get a new SuspendProjectParams instance, +func (p *ListProjectInvitationsParams) SetListall(v bool) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["listall"] = v + return +} + +func (p *ListProjectInvitationsParams) SetPage(v int) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["page"] = v + return +} + +func (p *ListProjectInvitationsParams) SetPagesize(v int) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["pagesize"] = v + return +} + +func (p *ListProjectInvitationsParams) SetProjectid(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["projectid"] = v + return +} + +func (p *ListProjectInvitationsParams) SetState(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["state"] = v + return +} + +// You should always use this function to get a new ListProjectInvitationsParams instance, // as then you are sure you have configured all required params -func (s *ProjectService) NewSuspendProjectParams(id string) *SuspendProjectParams { - p := &SuspendProjectParams{} +func (s *ProjectService) NewListProjectInvitationsParams() *ListProjectInvitationsParams { + p := &ListProjectInvitationsParams{} p.p = make(map[string]interface{}) - p.p["id"] = id return p } -// Suspends a project -func (s *ProjectService) SuspendProject(p *SuspendProjectParams) (*SuspendProjectResponse, error) { - resp, err := s.cs.newRequest("suspendProject", p.toURLValues()) +// This is a courtesy helper function, which in some cases may not work as expected! +func (s *ProjectService) GetProjectInvitationByID(id string, opts ...OptionFunc) (*ProjectInvitation, int, error) { + p := &ListProjectInvitationsParams{} + p.p = make(map[string]interface{}) + + p.p["id"] = id + + for _, fn := range append(s.cs.options, opts...) { + if err := fn(s.cs, p); err != nil { + return nil, -1, err + } + } + + l, err := s.ListProjectInvitations(p) + if err != nil { + if strings.Contains(err.Error(), fmt.Sprintf( + "Invalid parameter id value=%s due to incorrect long value format, "+ + "or entity does not exist", id)) { + return nil, 0, fmt.Errorf("No match found for %s: %+v", id, l) + } + return nil, -1, err + } + + if l.Count == 0 { + return nil, l.Count, fmt.Errorf("No match found for %s: %+v", id, l) + } + + if l.Count == 1 { + return l.ProjectInvitations[0], l.Count, nil + } + return nil, l.Count, fmt.Errorf("There is more then one result for ProjectInvitation UUID: %s!", id) +} + +// Lists project invitations and provides detailed information for listed invitations +func (s *ProjectService) ListProjectInvitations(p *ListProjectInvitationsParams) (*ListProjectInvitationsResponse, error) { + resp, err := s.cs.newRequest("listProjectInvitations", p.toURLValues()) if err != nil { return nil, err } - var r SuspendProjectResponse + var r ListProjectInvitationsResponse if err := json.Unmarshal(resp, &r); err != nil { return nil, err } - // If we have a async client, we need to wait for the async result - if s.cs.async { - b, err := s.cs.GetAsyncJobResult(r.JobID, s.cs.timeout) - if err != nil { - if err == AsyncTimeoutErr { - return &r, err - } - return nil, err - } - - b, err = getRawValue(b) - if err != nil { - return nil, err - } - - if err := json.Unmarshal(b, &r); err != nil { - return nil, err - } - } return &r, nil } -type SuspendProjectResponse struct { - JobID string `json:"jobid,omitempty"` - Account string `json:"account,omitempty"` - Cpuavailable string `json:"cpuavailable,omitempty"` - Cpulimit string `json:"cpulimit,omitempty"` - Cputotal int64 `json:"cputotal,omitempty"` - Displaytext string `json:"displaytext,omitempty"` - Domain string `json:"domain,omitempty"` - Domainid string `json:"domainid,omitempty"` - Id string `json:"id,omitempty"` - Ipavailable string `json:"ipavailable,omitempty"` - Iplimit string `json:"iplimit,omitempty"` - Iptotal int64 `json:"iptotal,omitempty"` - Memoryavailable string `json:"memoryavailable,omitempty"` - Memorylimit string `json:"memorylimit,omitempty"` - Memorytotal int64 `json:"memorytotal,omitempty"` - Name string `json:"name,omitempty"` - Networkavailable string `json:"networkavailable,omitempty"` - Networklimit string `json:"networklimit,omitempty"` - Networktotal int64 `json:"networktotal,omitempty"` - Primarystorageavailable string `json:"primarystorageavailable,omitempty"` - Primarystoragelimit string `json:"primarystoragelimit,omitempty"` - Primarystoragetotal int64 `json:"primarystoragetotal,omitempty"` - Secondarystorageavailable string `json:"secondarystorageavailable,omitempty"` - Secondarystoragelimit string `json:"secondarystoragelimit,omitempty"` - Secondarystoragetotal int64 `json:"secondarystoragetotal,omitempty"` - Snapshotavailable string `json:"snapshotavailable,omitempty"` - Snapshotlimit string `json:"snapshotlimit,omitempty"` - Snapshottotal int64 `json:"snapshottotal,omitempty"` - State string `json:"state,omitempty"` - Tags []struct { - Account string `json:"account,omitempty"` - Customer string `json:"customer,omitempty"` - Domain string `json:"domain,omitempty"` - Domainid string `json:"domainid,omitempty"` - Key string `json:"key,omitempty"` - Project string `json:"project,omitempty"` - Projectid string `json:"projectid,omitempty"` - Resourceid string `json:"resourceid,omitempty"` - Resourcetype string `json:"resourcetype,omitempty"` - Value string `json:"value,omitempty"` - } `json:"tags,omitempty"` - Templateavailable string `json:"templateavailable,omitempty"` - Templatelimit string `json:"templatelimit,omitempty"` - Templatetotal int64 `json:"templatetotal,omitempty"` - Vmavailable string `json:"vmavailable,omitempty"` - Vmlimit string `json:"vmlimit,omitempty"` - Vmrunning int `json:"vmrunning,omitempty"` - Vmstopped int `json:"vmstopped,omitempty"` - Vmtotal int64 `json:"vmtotal,omitempty"` - Volumeavailable string `json:"volumeavailable,omitempty"` - Volumelimit string `json:"volumelimit,omitempty"` - Volumetotal int64 `json:"volumetotal,omitempty"` - Vpcavailable string `json:"vpcavailable,omitempty"` - Vpclimit string `json:"vpclimit,omitempty"` - Vpctotal int64 `json:"vpctotal,omitempty"` +type ListProjectInvitationsResponse struct { + Count int `json:"count"` + ProjectInvitations []*ProjectInvitation `json:"projectinvitation"` +} + +type ProjectInvitation struct { + Account string `json:"account"` + Domain string `json:"domain"` + Domainid string `json:"domainid"` + Email string `json:"email"` + Id string `json:"id"` + Project string `json:"project"` + Projectid string `json:"projectid"` + State string `json:"state"` } type ListProjectsParams struct { @@ -811,7 +802,7 @@ func (s *ProjectService) GetProjectID(name string, opts ...OptionFunc) (string, p.p["name"] = name - for _, fn := range opts { + for _, fn := range append(s.cs.options, opts...) { if err := fn(s.cs, p); err != nil { return "", -1, err } @@ -861,7 +852,7 @@ func (s *ProjectService) GetProjectByID(id string, opts ...OptionFunc) (*Project p.p["id"] = id - for _, fn := range opts { + for _, fn := range append(s.cs.options, opts...) { if err := fn(s.cs, p); err != nil { return nil, -1, err } @@ -898,6 +889,7 @@ func (s *ProjectService) ListProjects(p *ListProjectsParams) (*ListProjectsRespo if err := json.Unmarshal(resp, &r); err != nil { return nil, err } + return &r, nil } @@ -907,137 +899,68 @@ type ListProjectsResponse struct { } type Project struct { - Account string `json:"account,omitempty"` - Cpuavailable string `json:"cpuavailable,omitempty"` - Cpulimit string `json:"cpulimit,omitempty"` - Cputotal int64 `json:"cputotal,omitempty"` - Displaytext string `json:"displaytext,omitempty"` - Domain string `json:"domain,omitempty"` - Domainid string `json:"domainid,omitempty"` - Id string `json:"id,omitempty"` - Ipavailable string `json:"ipavailable,omitempty"` - Iplimit string `json:"iplimit,omitempty"` - Iptotal int64 `json:"iptotal,omitempty"` - Memoryavailable string `json:"memoryavailable,omitempty"` - Memorylimit string `json:"memorylimit,omitempty"` - Memorytotal int64 `json:"memorytotal,omitempty"` - Name string `json:"name,omitempty"` - Networkavailable string `json:"networkavailable,omitempty"` - Networklimit string `json:"networklimit,omitempty"` - Networktotal int64 `json:"networktotal,omitempty"` - Primarystorageavailable string `json:"primarystorageavailable,omitempty"` - Primarystoragelimit string `json:"primarystoragelimit,omitempty"` - Primarystoragetotal int64 `json:"primarystoragetotal,omitempty"` - Secondarystorageavailable string `json:"secondarystorageavailable,omitempty"` - Secondarystoragelimit string `json:"secondarystoragelimit,omitempty"` - Secondarystoragetotal int64 `json:"secondarystoragetotal,omitempty"` - Snapshotavailable string `json:"snapshotavailable,omitempty"` - Snapshotlimit string `json:"snapshotlimit,omitempty"` - Snapshottotal int64 `json:"snapshottotal,omitempty"` - State string `json:"state,omitempty"` - Tags []struct { - Account string `json:"account,omitempty"` - Customer string `json:"customer,omitempty"` - Domain string `json:"domain,omitempty"` - Domainid string `json:"domainid,omitempty"` - Key string `json:"key,omitempty"` - Project string `json:"project,omitempty"` - Projectid string `json:"projectid,omitempty"` - Resourceid string `json:"resourceid,omitempty"` - Resourcetype string `json:"resourcetype,omitempty"` - Value string `json:"value,omitempty"` - } `json:"tags,omitempty"` - Templateavailable string `json:"templateavailable,omitempty"` - Templatelimit string `json:"templatelimit,omitempty"` - Templatetotal int64 `json:"templatetotal,omitempty"` - Vmavailable string `json:"vmavailable,omitempty"` - Vmlimit string `json:"vmlimit,omitempty"` - Vmrunning int `json:"vmrunning,omitempty"` - Vmstopped int `json:"vmstopped,omitempty"` - Vmtotal int64 `json:"vmtotal,omitempty"` - Volumeavailable string `json:"volumeavailable,omitempty"` - Volumelimit string `json:"volumelimit,omitempty"` - Volumetotal int64 `json:"volumetotal,omitempty"` - Vpcavailable string `json:"vpcavailable,omitempty"` - Vpclimit string `json:"vpclimit,omitempty"` - Vpctotal int64 `json:"vpctotal,omitempty"` + Account string `json:"account"` + Cpuavailable string `json:"cpuavailable"` + Cpulimit string `json:"cpulimit"` + Cputotal int64 `json:"cputotal"` + Displaytext string `json:"displaytext"` + Domain string `json:"domain"` + Domainid string `json:"domainid"` + Id string `json:"id"` + Ipavailable string `json:"ipavailable"` + Iplimit string `json:"iplimit"` + Iptotal int64 `json:"iptotal"` + Memoryavailable string `json:"memoryavailable"` + Memorylimit string `json:"memorylimit"` + Memorytotal int64 `json:"memorytotal"` + Name string `json:"name"` + Networkavailable string `json:"networkavailable"` + Networklimit string `json:"networklimit"` + Networktotal int64 `json:"networktotal"` + Primarystorageavailable string `json:"primarystorageavailable"` + Primarystoragelimit string `json:"primarystoragelimit"` + Primarystoragetotal int64 `json:"primarystoragetotal"` + Projectaccountname string `json:"projectaccountname"` + Secondarystorageavailable string `json:"secondarystorageavailable"` + Secondarystoragelimit string `json:"secondarystoragelimit"` + Secondarystoragetotal float64 `json:"secondarystoragetotal"` + Snapshotavailable string `json:"snapshotavailable"` + Snapshotlimit string `json:"snapshotlimit"` + Snapshottotal int64 `json:"snapshottotal"` + State string `json:"state"` + Tags []Tags `json:"tags"` + Templateavailable string `json:"templateavailable"` + Templatelimit string `json:"templatelimit"` + Templatetotal int64 `json:"templatetotal"` + Vmavailable string `json:"vmavailable"` + Vmlimit string `json:"vmlimit"` + Vmrunning int `json:"vmrunning"` + Vmstopped int `json:"vmstopped"` + Vmtotal int64 `json:"vmtotal"` + Volumeavailable string `json:"volumeavailable"` + Volumelimit string `json:"volumelimit"` + Volumetotal int64 `json:"volumetotal"` + Vpcavailable string `json:"vpcavailable"` + Vpclimit string `json:"vpclimit"` + Vpctotal int64 `json:"vpctotal"` } -type ListProjectInvitationsParams struct { +type SuspendProjectParams struct { p map[string]interface{} } -func (p *ListProjectInvitationsParams) toURLValues() url.Values { +func (p *SuspendProjectParams) toURLValues() url.Values { u := url.Values{} if p.p == nil { return u } - if v, found := p.p["account"]; found { - u.Set("account", v.(string)) - } - if v, found := p.p["activeonly"]; found { - vv := strconv.FormatBool(v.(bool)) - u.Set("activeonly", vv) - } - if v, found := p.p["domainid"]; found { - u.Set("domainid", v.(string)) - } if v, found := p.p["id"]; found { u.Set("id", v.(string)) } - if v, found := p.p["isrecursive"]; found { - vv := strconv.FormatBool(v.(bool)) - u.Set("isrecursive", vv) - } - if v, found := p.p["keyword"]; found { - u.Set("keyword", v.(string)) - } - if v, found := p.p["listall"]; found { - vv := strconv.FormatBool(v.(bool)) - u.Set("listall", vv) - } - if v, found := p.p["page"]; found { - vv := strconv.Itoa(v.(int)) - u.Set("page", vv) - } - if v, found := p.p["pagesize"]; found { - vv := strconv.Itoa(v.(int)) - u.Set("pagesize", vv) - } - if v, found := p.p["projectid"]; found { - u.Set("projectid", v.(string)) - } - if v, found := p.p["state"]; found { - u.Set("state", v.(string)) - } return u } -func (p *ListProjectInvitationsParams) SetAccount(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["account"] = v - return -} - -func (p *ListProjectInvitationsParams) SetActiveonly(v bool) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["activeonly"] = v - return -} - -func (p *ListProjectInvitationsParams) SetDomainid(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["domainid"] = v - return -} - -func (p *ListProjectInvitationsParams) SetId(v string) { +func (p *SuspendProjectParams) SetId(v string) { if p.p == nil { p.p = make(map[string]interface{}) } @@ -1045,131 +968,233 @@ func (p *ListProjectInvitationsParams) SetId(v string) { return } -func (p *ListProjectInvitationsParams) SetIsrecursive(v bool) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["isrecursive"] = v - return -} - -func (p *ListProjectInvitationsParams) SetKeyword(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["keyword"] = v - return -} - -func (p *ListProjectInvitationsParams) SetListall(v bool) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["listall"] = v - return -} - -func (p *ListProjectInvitationsParams) SetPage(v int) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["page"] = v - return -} - -func (p *ListProjectInvitationsParams) SetPagesize(v int) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["pagesize"] = v - return -} - -func (p *ListProjectInvitationsParams) SetProjectid(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["projectid"] = v - return -} - -func (p *ListProjectInvitationsParams) SetState(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["state"] = v - return -} - -// You should always use this function to get a new ListProjectInvitationsParams instance, +// You should always use this function to get a new SuspendProjectParams instance, // as then you are sure you have configured all required params -func (s *ProjectService) NewListProjectInvitationsParams() *ListProjectInvitationsParams { - p := &ListProjectInvitationsParams{} +func (s *ProjectService) NewSuspendProjectParams(id string) *SuspendProjectParams { + p := &SuspendProjectParams{} p.p = make(map[string]interface{}) + p.p["id"] = id return p } -// This is a courtesy helper function, which in some cases may not work as expected! -func (s *ProjectService) GetProjectInvitationByID(id string, opts ...OptionFunc) (*ProjectInvitation, int, error) { - p := &ListProjectInvitationsParams{} - p.p = make(map[string]interface{}) - - p.p["id"] = id - - for _, fn := range opts { - if err := fn(s.cs, p); err != nil { - return nil, -1, err - } - } - - l, err := s.ListProjectInvitations(p) - if err != nil { - if strings.Contains(err.Error(), fmt.Sprintf( - "Invalid parameter id value=%s due to incorrect long value format, "+ - "or entity does not exist", id)) { - return nil, 0, fmt.Errorf("No match found for %s: %+v", id, l) - } - return nil, -1, err - } - - if l.Count == 0 { - return nil, l.Count, fmt.Errorf("No match found for %s: %+v", id, l) - } - - if l.Count == 1 { - return l.ProjectInvitations[0], l.Count, nil - } - return nil, l.Count, fmt.Errorf("There is more then one result for ProjectInvitation UUID: %s!", id) -} - -// Lists project invitations and provides detailed information for listed invitations -func (s *ProjectService) ListProjectInvitations(p *ListProjectInvitationsParams) (*ListProjectInvitationsResponse, error) { - resp, err := s.cs.newRequest("listProjectInvitations", p.toURLValues()) +// Suspends a project +func (s *ProjectService) SuspendProject(p *SuspendProjectParams) (*SuspendProjectResponse, error) { + resp, err := s.cs.newRequest("suspendProject", p.toURLValues()) if err != nil { return nil, err } - var r ListProjectInvitationsResponse + var r SuspendProjectResponse if err := json.Unmarshal(resp, &r); err != nil { return nil, err } + + // If we have a async client, we need to wait for the async result + if s.cs.async { + b, err := s.cs.GetAsyncJobResult(r.JobID, s.cs.timeout) + if err != nil { + if err == AsyncTimeoutErr { + return &r, err + } + return nil, err + } + + b, err = getRawValue(b) + if err != nil { + return nil, err + } + + if err := json.Unmarshal(b, &r); err != nil { + return nil, err + } + } + return &r, nil } -type ListProjectInvitationsResponse struct { - Count int `json:"count"` - ProjectInvitations []*ProjectInvitation `json:"projectinvitation"` +type SuspendProjectResponse struct { + JobID string `json:"jobid"` + Account string `json:"account"` + Cpuavailable string `json:"cpuavailable"` + Cpulimit string `json:"cpulimit"` + Cputotal int64 `json:"cputotal"` + Displaytext string `json:"displaytext"` + Domain string `json:"domain"` + Domainid string `json:"domainid"` + Id string `json:"id"` + Ipavailable string `json:"ipavailable"` + Iplimit string `json:"iplimit"` + Iptotal int64 `json:"iptotal"` + Memoryavailable string `json:"memoryavailable"` + Memorylimit string `json:"memorylimit"` + Memorytotal int64 `json:"memorytotal"` + Name string `json:"name"` + Networkavailable string `json:"networkavailable"` + Networklimit string `json:"networklimit"` + Networktotal int64 `json:"networktotal"` + Primarystorageavailable string `json:"primarystorageavailable"` + Primarystoragelimit string `json:"primarystoragelimit"` + Primarystoragetotal int64 `json:"primarystoragetotal"` + Projectaccountname string `json:"projectaccountname"` + Secondarystorageavailable string `json:"secondarystorageavailable"` + Secondarystoragelimit string `json:"secondarystoragelimit"` + Secondarystoragetotal float64 `json:"secondarystoragetotal"` + Snapshotavailable string `json:"snapshotavailable"` + Snapshotlimit string `json:"snapshotlimit"` + Snapshottotal int64 `json:"snapshottotal"` + State string `json:"state"` + Tags []Tags `json:"tags"` + Templateavailable string `json:"templateavailable"` + Templatelimit string `json:"templatelimit"` + Templatetotal int64 `json:"templatetotal"` + Vmavailable string `json:"vmavailable"` + Vmlimit string `json:"vmlimit"` + Vmrunning int `json:"vmrunning"` + Vmstopped int `json:"vmstopped"` + Vmtotal int64 `json:"vmtotal"` + Volumeavailable string `json:"volumeavailable"` + Volumelimit string `json:"volumelimit"` + Volumetotal int64 `json:"volumetotal"` + Vpcavailable string `json:"vpcavailable"` + Vpclimit string `json:"vpclimit"` + Vpctotal int64 `json:"vpctotal"` } -type ProjectInvitation struct { - Account string `json:"account,omitempty"` - Domain string `json:"domain,omitempty"` - Domainid string `json:"domainid,omitempty"` - Email string `json:"email,omitempty"` - Id string `json:"id,omitempty"` - Project string `json:"project,omitempty"` - Projectid string `json:"projectid,omitempty"` - State string `json:"state,omitempty"` +type UpdateProjectParams struct { + p map[string]interface{} +} + +func (p *UpdateProjectParams) toURLValues() url.Values { + u := url.Values{} + if p.p == nil { + return u + } + if v, found := p.p["account"]; found { + u.Set("account", v.(string)) + } + if v, found := p.p["displaytext"]; found { + u.Set("displaytext", v.(string)) + } + if v, found := p.p["id"]; found { + u.Set("id", v.(string)) + } + return u +} + +func (p *UpdateProjectParams) SetAccount(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["account"] = v + return +} + +func (p *UpdateProjectParams) SetDisplaytext(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["displaytext"] = v + return +} + +func (p *UpdateProjectParams) SetId(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["id"] = v + return +} + +// You should always use this function to get a new UpdateProjectParams instance, +// as then you are sure you have configured all required params +func (s *ProjectService) NewUpdateProjectParams(id string) *UpdateProjectParams { + p := &UpdateProjectParams{} + p.p = make(map[string]interface{}) + p.p["id"] = id + return p +} + +// Updates a project +func (s *ProjectService) UpdateProject(p *UpdateProjectParams) (*UpdateProjectResponse, error) { + resp, err := s.cs.newRequest("updateProject", p.toURLValues()) + if err != nil { + return nil, err + } + + var r UpdateProjectResponse + if err := json.Unmarshal(resp, &r); err != nil { + return nil, err + } + + // If we have a async client, we need to wait for the async result + if s.cs.async { + b, err := s.cs.GetAsyncJobResult(r.JobID, s.cs.timeout) + if err != nil { + if err == AsyncTimeoutErr { + return &r, err + } + return nil, err + } + + b, err = getRawValue(b) + if err != nil { + return nil, err + } + + if err := json.Unmarshal(b, &r); err != nil { + return nil, err + } + } + + return &r, nil +} + +type UpdateProjectResponse struct { + JobID string `json:"jobid"` + Account string `json:"account"` + Cpuavailable string `json:"cpuavailable"` + Cpulimit string `json:"cpulimit"` + Cputotal int64 `json:"cputotal"` + Displaytext string `json:"displaytext"` + Domain string `json:"domain"` + Domainid string `json:"domainid"` + Id string `json:"id"` + Ipavailable string `json:"ipavailable"` + Iplimit string `json:"iplimit"` + Iptotal int64 `json:"iptotal"` + Memoryavailable string `json:"memoryavailable"` + Memorylimit string `json:"memorylimit"` + Memorytotal int64 `json:"memorytotal"` + Name string `json:"name"` + Networkavailable string `json:"networkavailable"` + Networklimit string `json:"networklimit"` + Networktotal int64 `json:"networktotal"` + Primarystorageavailable string `json:"primarystorageavailable"` + Primarystoragelimit string `json:"primarystoragelimit"` + Primarystoragetotal int64 `json:"primarystoragetotal"` + Projectaccountname string `json:"projectaccountname"` + Secondarystorageavailable string `json:"secondarystorageavailable"` + Secondarystoragelimit string `json:"secondarystoragelimit"` + Secondarystoragetotal float64 `json:"secondarystoragetotal"` + Snapshotavailable string `json:"snapshotavailable"` + Snapshotlimit string `json:"snapshotlimit"` + Snapshottotal int64 `json:"snapshottotal"` + State string `json:"state"` + Tags []Tags `json:"tags"` + Templateavailable string `json:"templateavailable"` + Templatelimit string `json:"templatelimit"` + Templatetotal int64 `json:"templatetotal"` + Vmavailable string `json:"vmavailable"` + Vmlimit string `json:"vmlimit"` + Vmrunning int `json:"vmrunning"` + Vmstopped int `json:"vmstopped"` + Vmtotal int64 `json:"vmtotal"` + Volumeavailable string `json:"volumeavailable"` + Volumelimit string `json:"volumelimit"` + Volumetotal int64 `json:"volumetotal"` + Vpcavailable string `json:"vpcavailable"` + Vpclimit string `json:"vpclimit"` + Vpctotal int64 `json:"vpctotal"` } type UpdateProjectInvitationParams struct { @@ -1264,78 +1289,12 @@ func (s *ProjectService) UpdateProjectInvitation(p *UpdateProjectInvitationParam return nil, err } } + return &r, nil } type UpdateProjectInvitationResponse struct { - JobID string `json:"jobid,omitempty"` - Displaytext string `json:"displaytext,omitempty"` - Success bool `json:"success,omitempty"` -} - -type DeleteProjectInvitationParams struct { - p map[string]interface{} -} - -func (p *DeleteProjectInvitationParams) toURLValues() url.Values { - u := url.Values{} - if p.p == nil { - return u - } - if v, found := p.p["id"]; found { - u.Set("id", v.(string)) - } - return u -} - -func (p *DeleteProjectInvitationParams) SetId(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["id"] = v - return -} - -// You should always use this function to get a new DeleteProjectInvitationParams instance, -// as then you are sure you have configured all required params -func (s *ProjectService) NewDeleteProjectInvitationParams(id string) *DeleteProjectInvitationParams { - p := &DeleteProjectInvitationParams{} - p.p = make(map[string]interface{}) - p.p["id"] = id - return p -} - -// Deletes project invitation -func (s *ProjectService) DeleteProjectInvitation(p *DeleteProjectInvitationParams) (*DeleteProjectInvitationResponse, error) { - resp, err := s.cs.newRequest("deleteProjectInvitation", p.toURLValues()) - if err != nil { - return nil, err - } - - var r DeleteProjectInvitationResponse - if err := json.Unmarshal(resp, &r); err != nil { - return nil, err - } - - // If we have a async client, we need to wait for the async result - if s.cs.async { - b, err := s.cs.GetAsyncJobResult(r.JobID, s.cs.timeout) - if err != nil { - if err == AsyncTimeoutErr { - return &r, err - } - return nil, err - } - - if err := json.Unmarshal(b, &r); err != nil { - return nil, err - } - } - return &r, nil -} - -type DeleteProjectInvitationResponse struct { - JobID string `json:"jobid,omitempty"` - Displaytext string `json:"displaytext,omitempty"` - Success bool `json:"success,omitempty"` + JobID string `json:"jobid"` + Displaytext string `json:"displaytext"` + Success bool `json:"success"` } diff --git a/vendor/github.com/xanzy/go-cloudstack/cloudstack/QuotaService.go b/vendor/github.com/xanzy/go-cloudstack/cloudstack/QuotaService.go index 896a4d798..2e2f26ac7 100644 --- a/vendor/github.com/xanzy/go-cloudstack/cloudstack/QuotaService.go +++ b/vendor/github.com/xanzy/go-cloudstack/cloudstack/QuotaService.go @@ -1,5 +1,5 @@ // -// Copyright 2016, Sander van Harmelen +// Copyright 2018, Sander van Harmelen // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -52,9 +52,10 @@ func (s *QuotaService) QuotaIsEnabled(p *QuotaIsEnabledParams) (*QuotaIsEnabledR if err := json.Unmarshal(resp, &r); err != nil { return nil, err } + return &r, nil } type QuotaIsEnabledResponse struct { - Isenabled bool `json:"isenabled,omitempty"` + Isenabled bool `json:"isenabled"` } diff --git a/vendor/github.com/xanzy/go-cloudstack/cloudstack/RegionService.go b/vendor/github.com/xanzy/go-cloudstack/cloudstack/RegionService.go index a434f8513..244a8fa0c 100644 --- a/vendor/github.com/xanzy/go-cloudstack/cloudstack/RegionService.go +++ b/vendor/github.com/xanzy/go-cloudstack/cloudstack/RegionService.go @@ -1,5 +1,5 @@ // -// Copyright 2016, Sander van Harmelen +// Copyright 2018, Sander van Harmelen // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -90,144 +90,16 @@ func (s *RegionService) AddRegion(p *AddRegionParams) (*AddRegionResponse, error if err := json.Unmarshal(resp, &r); err != nil { return nil, err } + return &r, nil } type AddRegionResponse struct { - Endpoint string `json:"endpoint,omitempty"` - Gslbserviceenabled bool `json:"gslbserviceenabled,omitempty"` - Id int `json:"id,omitempty"` - Name string `json:"name,omitempty"` - Portableipserviceenabled bool `json:"portableipserviceenabled,omitempty"` -} - -type UpdateRegionParams struct { - p map[string]interface{} -} - -func (p *UpdateRegionParams) toURLValues() url.Values { - u := url.Values{} - if p.p == nil { - return u - } - if v, found := p.p["endpoint"]; found { - u.Set("endpoint", v.(string)) - } - if v, found := p.p["id"]; found { - vv := strconv.Itoa(v.(int)) - u.Set("id", vv) - } - if v, found := p.p["name"]; found { - u.Set("name", v.(string)) - } - return u -} - -func (p *UpdateRegionParams) SetEndpoint(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["endpoint"] = v - return -} - -func (p *UpdateRegionParams) SetId(v int) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["id"] = v - return -} - -func (p *UpdateRegionParams) SetName(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["name"] = v - return -} - -// You should always use this function to get a new UpdateRegionParams instance, -// as then you are sure you have configured all required params -func (s *RegionService) NewUpdateRegionParams(id int) *UpdateRegionParams { - p := &UpdateRegionParams{} - p.p = make(map[string]interface{}) - p.p["id"] = id - return p -} - -// Updates a region -func (s *RegionService) UpdateRegion(p *UpdateRegionParams) (*UpdateRegionResponse, error) { - resp, err := s.cs.newRequest("updateRegion", p.toURLValues()) - if err != nil { - return nil, err - } - - var r UpdateRegionResponse - if err := json.Unmarshal(resp, &r); err != nil { - return nil, err - } - return &r, nil -} - -type UpdateRegionResponse struct { - Endpoint string `json:"endpoint,omitempty"` - Gslbserviceenabled bool `json:"gslbserviceenabled,omitempty"` - Id int `json:"id,omitempty"` - Name string `json:"name,omitempty"` - Portableipserviceenabled bool `json:"portableipserviceenabled,omitempty"` -} - -type RemoveRegionParams struct { - p map[string]interface{} -} - -func (p *RemoveRegionParams) toURLValues() url.Values { - u := url.Values{} - if p.p == nil { - return u - } - if v, found := p.p["id"]; found { - vv := strconv.Itoa(v.(int)) - u.Set("id", vv) - } - return u -} - -func (p *RemoveRegionParams) SetId(v int) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["id"] = v - return -} - -// You should always use this function to get a new RemoveRegionParams instance, -// as then you are sure you have configured all required params -func (s *RegionService) NewRemoveRegionParams(id int) *RemoveRegionParams { - p := &RemoveRegionParams{} - p.p = make(map[string]interface{}) - p.p["id"] = id - return p -} - -// Removes specified region -func (s *RegionService) RemoveRegion(p *RemoveRegionParams) (*RemoveRegionResponse, error) { - resp, err := s.cs.newRequest("removeRegion", p.toURLValues()) - if err != nil { - return nil, err - } - - var r RemoveRegionResponse - if err := json.Unmarshal(resp, &r); err != nil { - return nil, err - } - return &r, nil -} - -type RemoveRegionResponse struct { - Displaytext string `json:"displaytext,omitempty"` - Success string `json:"success,omitempty"` + Endpoint string `json:"endpoint"` + Gslbserviceenabled bool `json:"gslbserviceenabled"` + Id int `json:"id"` + Name string `json:"name"` + Portableipserviceenabled bool `json:"portableipserviceenabled"` } type ListRegionsParams struct { @@ -319,6 +191,7 @@ func (s *RegionService) ListRegions(p *ListRegionsParams) (*ListRegionsResponse, if err := json.Unmarshal(resp, &r); err != nil { return nil, err } + return &r, nil } @@ -328,9 +201,159 @@ type ListRegionsResponse struct { } type Region struct { - Endpoint string `json:"endpoint,omitempty"` - Gslbserviceenabled bool `json:"gslbserviceenabled,omitempty"` - Id int `json:"id,omitempty"` - Name string `json:"name,omitempty"` - Portableipserviceenabled bool `json:"portableipserviceenabled,omitempty"` + Endpoint string `json:"endpoint"` + Gslbserviceenabled bool `json:"gslbserviceenabled"` + Id int `json:"id"` + Name string `json:"name"` + Portableipserviceenabled bool `json:"portableipserviceenabled"` +} + +type RemoveRegionParams struct { + p map[string]interface{} +} + +func (p *RemoveRegionParams) toURLValues() url.Values { + u := url.Values{} + if p.p == nil { + return u + } + if v, found := p.p["id"]; found { + vv := strconv.Itoa(v.(int)) + u.Set("id", vv) + } + return u +} + +func (p *RemoveRegionParams) SetId(v int) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["id"] = v + return +} + +// You should always use this function to get a new RemoveRegionParams instance, +// as then you are sure you have configured all required params +func (s *RegionService) NewRemoveRegionParams(id int) *RemoveRegionParams { + p := &RemoveRegionParams{} + p.p = make(map[string]interface{}) + p.p["id"] = id + return p +} + +// Removes specified region +func (s *RegionService) RemoveRegion(p *RemoveRegionParams) (*RemoveRegionResponse, error) { + resp, err := s.cs.newRequest("removeRegion", p.toURLValues()) + if err != nil { + return nil, err + } + + var r RemoveRegionResponse + if err := json.Unmarshal(resp, &r); err != nil { + return nil, err + } + + return &r, nil +} + +type RemoveRegionResponse struct { + Displaytext string `json:"displaytext"` + Success bool `json:"success"` +} + +func (r *RemoveRegionResponse) UnmarshalJSON(b []byte) error { + var m map[string]interface{} + err := json.Unmarshal(b, &m) + if err != nil { + return err + } + + if success, ok := m["success"].(string); ok { + m["success"] = success == "true" + b, err = json.Marshal(m) + if err != nil { + return err + } + } + + type alias RemoveRegionResponse + return json.Unmarshal(b, (*alias)(r)) +} + +type UpdateRegionParams struct { + p map[string]interface{} +} + +func (p *UpdateRegionParams) toURLValues() url.Values { + u := url.Values{} + if p.p == nil { + return u + } + if v, found := p.p["endpoint"]; found { + u.Set("endpoint", v.(string)) + } + if v, found := p.p["id"]; found { + vv := strconv.Itoa(v.(int)) + u.Set("id", vv) + } + if v, found := p.p["name"]; found { + u.Set("name", v.(string)) + } + return u +} + +func (p *UpdateRegionParams) SetEndpoint(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["endpoint"] = v + return +} + +func (p *UpdateRegionParams) SetId(v int) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["id"] = v + return +} + +func (p *UpdateRegionParams) SetName(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["name"] = v + return +} + +// You should always use this function to get a new UpdateRegionParams instance, +// as then you are sure you have configured all required params +func (s *RegionService) NewUpdateRegionParams(id int) *UpdateRegionParams { + p := &UpdateRegionParams{} + p.p = make(map[string]interface{}) + p.p["id"] = id + return p +} + +// Updates a region +func (s *RegionService) UpdateRegion(p *UpdateRegionParams) (*UpdateRegionResponse, error) { + resp, err := s.cs.newRequest("updateRegion", p.toURLValues()) + if err != nil { + return nil, err + } + + var r UpdateRegionResponse + if err := json.Unmarshal(resp, &r); err != nil { + return nil, err + } + + return &r, nil +} + +type UpdateRegionResponse struct { + Endpoint string `json:"endpoint"` + Gslbserviceenabled bool `json:"gslbserviceenabled"` + Id int `json:"id"` + Name string `json:"name"` + Portableipserviceenabled bool `json:"portableipserviceenabled"` } diff --git a/vendor/github.com/xanzy/go-cloudstack/cloudstack/ResourcemetadataService.go b/vendor/github.com/xanzy/go-cloudstack/cloudstack/ResourcemetadataService.go index 136b9d3b1..6eef886fa 100644 --- a/vendor/github.com/xanzy/go-cloudstack/cloudstack/ResourcemetadataService.go +++ b/vendor/github.com/xanzy/go-cloudstack/cloudstack/ResourcemetadataService.go @@ -1,5 +1,5 @@ // -// Copyright 2016, Sander van Harmelen +// Copyright 2018, Sander van Harmelen // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -35,8 +35,7 @@ func (p *AddResourceDetailParams) toURLValues() url.Values { if v, found := p.p["details"]; found { i := 0 for k, vv := range v.(map[string]string) { - u.Set(fmt.Sprintf("details[%d].key", i), k) - u.Set(fmt.Sprintf("details[%d].value", i), vv) + u.Set(fmt.Sprintf("details[%d].%s", i, k), vv) i++ } } @@ -122,103 +121,65 @@ func (s *ResourcemetadataService) AddResourceDetail(p *AddResourceDetailParams) return nil, err } } + return &r, nil } type AddResourceDetailResponse struct { - JobID string `json:"jobid,omitempty"` - Displaytext string `json:"displaytext,omitempty"` - Success bool `json:"success,omitempty"` + JobID string `json:"jobid"` + Displaytext string `json:"displaytext"` + Success bool `json:"success"` } -type RemoveResourceDetailParams struct { +type GetVolumeSnapshotDetailsParams struct { p map[string]interface{} } -func (p *RemoveResourceDetailParams) toURLValues() url.Values { +func (p *GetVolumeSnapshotDetailsParams) toURLValues() url.Values { u := url.Values{} if p.p == nil { return u } - if v, found := p.p["key"]; found { - u.Set("key", v.(string)) - } - if v, found := p.p["resourceid"]; found { - u.Set("resourceid", v.(string)) - } - if v, found := p.p["resourcetype"]; found { - u.Set("resourcetype", v.(string)) + if v, found := p.p["snapshotid"]; found { + u.Set("snapshotid", v.(string)) } return u } -func (p *RemoveResourceDetailParams) SetKey(v string) { +func (p *GetVolumeSnapshotDetailsParams) SetSnapshotid(v string) { if p.p == nil { p.p = make(map[string]interface{}) } - p.p["key"] = v + p.p["snapshotid"] = v return } -func (p *RemoveResourceDetailParams) SetResourceid(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["resourceid"] = v - return -} - -func (p *RemoveResourceDetailParams) SetResourcetype(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["resourcetype"] = v - return -} - -// You should always use this function to get a new RemoveResourceDetailParams instance, +// You should always use this function to get a new GetVolumeSnapshotDetailsParams instance, // as then you are sure you have configured all required params -func (s *ResourcemetadataService) NewRemoveResourceDetailParams(resourceid string, resourcetype string) *RemoveResourceDetailParams { - p := &RemoveResourceDetailParams{} +func (s *ResourcemetadataService) NewGetVolumeSnapshotDetailsParams(snapshotid string) *GetVolumeSnapshotDetailsParams { + p := &GetVolumeSnapshotDetailsParams{} p.p = make(map[string]interface{}) - p.p["resourceid"] = resourceid - p.p["resourcetype"] = resourcetype + p.p["snapshotid"] = snapshotid return p } -// Removes detail for the Resource. -func (s *ResourcemetadataService) RemoveResourceDetail(p *RemoveResourceDetailParams) (*RemoveResourceDetailResponse, error) { - resp, err := s.cs.newRequest("removeResourceDetail", p.toURLValues()) +// Get Volume Snapshot Details +func (s *ResourcemetadataService) GetVolumeSnapshotDetails(p *GetVolumeSnapshotDetailsParams) (*GetVolumeSnapshotDetailsResponse, error) { + resp, err := s.cs.newRequest("getVolumeSnapshotDetails", p.toURLValues()) if err != nil { return nil, err } - var r RemoveResourceDetailResponse + var r GetVolumeSnapshotDetailsResponse if err := json.Unmarshal(resp, &r); err != nil { return nil, err } - // If we have a async client, we need to wait for the async result - if s.cs.async { - b, err := s.cs.GetAsyncJobResult(r.JobID, s.cs.timeout) - if err != nil { - if err == AsyncTimeoutErr { - return &r, err - } - return nil, err - } - - if err := json.Unmarshal(b, &r); err != nil { - return nil, err - } - } return &r, nil } -type RemoveResourceDetailResponse struct { - JobID string `json:"jobid,omitempty"` - Displaytext string `json:"displaytext,omitempty"` - Success bool `json:"success,omitempty"` +type GetVolumeSnapshotDetailsResponse struct { + VolumeiScsiName string `json:"volumeiScsiName"` } type ListResourceDetailsParams struct { @@ -401,6 +362,7 @@ func (s *ResourcemetadataService) ListResourceDetails(p *ListResourceDetailsPara if err := json.Unmarshal(resp, &r); err != nil { return nil, err } + return &r, nil } @@ -410,14 +372,105 @@ type ListResourceDetailsResponse struct { } type ResourceDetail struct { - Account string `json:"account,omitempty"` - Customer string `json:"customer,omitempty"` - Domain string `json:"domain,omitempty"` - Domainid string `json:"domainid,omitempty"` - Key string `json:"key,omitempty"` - Project string `json:"project,omitempty"` - Projectid string `json:"projectid,omitempty"` - Resourceid string `json:"resourceid,omitempty"` - Resourcetype string `json:"resourcetype,omitempty"` - Value string `json:"value,omitempty"` + Account string `json:"account"` + Customer string `json:"customer"` + Domain string `json:"domain"` + Domainid string `json:"domainid"` + Key string `json:"key"` + Project string `json:"project"` + Projectid string `json:"projectid"` + Resourceid string `json:"resourceid"` + Resourcetype string `json:"resourcetype"` + Value string `json:"value"` +} + +type RemoveResourceDetailParams struct { + p map[string]interface{} +} + +func (p *RemoveResourceDetailParams) toURLValues() url.Values { + u := url.Values{} + if p.p == nil { + return u + } + if v, found := p.p["key"]; found { + u.Set("key", v.(string)) + } + if v, found := p.p["resourceid"]; found { + u.Set("resourceid", v.(string)) + } + if v, found := p.p["resourcetype"]; found { + u.Set("resourcetype", v.(string)) + } + return u +} + +func (p *RemoveResourceDetailParams) SetKey(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["key"] = v + return +} + +func (p *RemoveResourceDetailParams) SetResourceid(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["resourceid"] = v + return +} + +func (p *RemoveResourceDetailParams) SetResourcetype(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["resourcetype"] = v + return +} + +// You should always use this function to get a new RemoveResourceDetailParams instance, +// as then you are sure you have configured all required params +func (s *ResourcemetadataService) NewRemoveResourceDetailParams(resourceid string, resourcetype string) *RemoveResourceDetailParams { + p := &RemoveResourceDetailParams{} + p.p = make(map[string]interface{}) + p.p["resourceid"] = resourceid + p.p["resourcetype"] = resourcetype + return p +} + +// Removes detail for the Resource. +func (s *ResourcemetadataService) RemoveResourceDetail(p *RemoveResourceDetailParams) (*RemoveResourceDetailResponse, error) { + resp, err := s.cs.newRequest("removeResourceDetail", p.toURLValues()) + if err != nil { + return nil, err + } + + var r RemoveResourceDetailResponse + if err := json.Unmarshal(resp, &r); err != nil { + return nil, err + } + + // If we have a async client, we need to wait for the async result + if s.cs.async { + b, err := s.cs.GetAsyncJobResult(r.JobID, s.cs.timeout) + if err != nil { + if err == AsyncTimeoutErr { + return &r, err + } + return nil, err + } + + if err := json.Unmarshal(b, &r); err != nil { + return nil, err + } + } + + return &r, nil +} + +type RemoveResourceDetailResponse struct { + JobID string `json:"jobid"` + Displaytext string `json:"displaytext"` + Success bool `json:"success"` } diff --git a/vendor/github.com/xanzy/go-cloudstack/cloudstack/ResourcetagsService.go b/vendor/github.com/xanzy/go-cloudstack/cloudstack/ResourcetagsService.go index b285a2466..e49d26563 100644 --- a/vendor/github.com/xanzy/go-cloudstack/cloudstack/ResourcetagsService.go +++ b/vendor/github.com/xanzy/go-cloudstack/cloudstack/ResourcetagsService.go @@ -1,5 +1,5 @@ // -// Copyright 2016, Sander van Harmelen +// Copyright 2018, Sander van Harmelen // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -24,122 +24,6 @@ import ( "strings" ) -type ListStorageTagsParams struct { - p map[string]interface{} -} - -func (p *ListStorageTagsParams) toURLValues() url.Values { - u := url.Values{} - if p.p == nil { - return u - } - if v, found := p.p["keyword"]; found { - u.Set("keyword", v.(string)) - } - if v, found := p.p["page"]; found { - vv := strconv.Itoa(v.(int)) - u.Set("page", vv) - } - if v, found := p.p["pagesize"]; found { - vv := strconv.Itoa(v.(int)) - u.Set("pagesize", vv) - } - return u -} - -func (p *ListStorageTagsParams) SetKeyword(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["keyword"] = v - return -} - -func (p *ListStorageTagsParams) SetPage(v int) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["page"] = v - return -} - -func (p *ListStorageTagsParams) SetPagesize(v int) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["pagesize"] = v - return -} - -// You should always use this function to get a new ListStorageTagsParams instance, -// as then you are sure you have configured all required params -func (s *ResourcetagsService) NewListStorageTagsParams() *ListStorageTagsParams { - p := &ListStorageTagsParams{} - p.p = make(map[string]interface{}) - return p -} - -// This is a courtesy helper function, which in some cases may not work as expected! -func (s *ResourcetagsService) GetStorageTagID(keyword string, opts ...OptionFunc) (string, int, error) { - p := &ListStorageTagsParams{} - p.p = make(map[string]interface{}) - - p.p["keyword"] = keyword - - for _, fn := range opts { - if err := fn(s.cs, p); err != nil { - return "", -1, err - } - } - - l, err := s.ListStorageTags(p) - if err != nil { - return "", -1, err - } - - if l.Count == 0 { - return "", l.Count, fmt.Errorf("No match found for %s: %+v", keyword, l) - } - - if l.Count == 1 { - return l.StorageTags[0].Id, l.Count, nil - } - - if l.Count > 1 { - for _, v := range l.StorageTags { - if v.Name == keyword { - return v.Id, l.Count, nil - } - } - } - return "", l.Count, fmt.Errorf("Could not find an exact match for %s: %+v", keyword, l) -} - -// Lists storage tags -func (s *ResourcetagsService) ListStorageTags(p *ListStorageTagsParams) (*ListStorageTagsResponse, error) { - resp, err := s.cs.newRequest("listStorageTags", p.toURLValues()) - if err != nil { - return nil, err - } - - var r ListStorageTagsResponse - if err := json.Unmarshal(resp, &r); err != nil { - return nil, err - } - return &r, nil -} - -type ListStorageTagsResponse struct { - Count int `json:"count"` - StorageTags []*StorageTag `json:"storagetag"` -} - -type StorageTag struct { - Id string `json:"id,omitempty"` - Name string `json:"name,omitempty"` - Poolid int64 `json:"poolid,omitempty"` -} - type CreateTagsParams struct { p map[string]interface{} } @@ -239,13 +123,14 @@ func (s *ResourcetagsService) CreateTags(p *CreateTagsParams) (*CreateTagsRespon return nil, err } } + return &r, nil } type CreateTagsResponse struct { - JobID string `json:"jobid,omitempty"` - Displaytext string `json:"displaytext,omitempty"` - Success bool `json:"success,omitempty"` + JobID string `json:"jobid"` + Displaytext string `json:"displaytext"` + Success bool `json:"success"` } type DeleteTagsParams struct { @@ -335,13 +220,131 @@ func (s *ResourcetagsService) DeleteTags(p *DeleteTagsParams) (*DeleteTagsRespon return nil, err } } + return &r, nil } type DeleteTagsResponse struct { - JobID string `json:"jobid,omitempty"` - Displaytext string `json:"displaytext,omitempty"` - Success bool `json:"success,omitempty"` + JobID string `json:"jobid"` + Displaytext string `json:"displaytext"` + Success bool `json:"success"` +} + +type ListStorageTagsParams struct { + p map[string]interface{} +} + +func (p *ListStorageTagsParams) toURLValues() url.Values { + u := url.Values{} + if p.p == nil { + return u + } + if v, found := p.p["keyword"]; found { + u.Set("keyword", v.(string)) + } + if v, found := p.p["page"]; found { + vv := strconv.Itoa(v.(int)) + u.Set("page", vv) + } + if v, found := p.p["pagesize"]; found { + vv := strconv.Itoa(v.(int)) + u.Set("pagesize", vv) + } + return u +} + +func (p *ListStorageTagsParams) SetKeyword(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["keyword"] = v + return +} + +func (p *ListStorageTagsParams) SetPage(v int) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["page"] = v + return +} + +func (p *ListStorageTagsParams) SetPagesize(v int) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["pagesize"] = v + return +} + +// You should always use this function to get a new ListStorageTagsParams instance, +// as then you are sure you have configured all required params +func (s *ResourcetagsService) NewListStorageTagsParams() *ListStorageTagsParams { + p := &ListStorageTagsParams{} + p.p = make(map[string]interface{}) + return p +} + +// This is a courtesy helper function, which in some cases may not work as expected! +func (s *ResourcetagsService) GetStorageTagID(keyword string, opts ...OptionFunc) (string, int, error) { + p := &ListStorageTagsParams{} + p.p = make(map[string]interface{}) + + p.p["keyword"] = keyword + + for _, fn := range append(s.cs.options, opts...) { + if err := fn(s.cs, p); err != nil { + return "", -1, err + } + } + + l, err := s.ListStorageTags(p) + if err != nil { + return "", -1, err + } + + if l.Count == 0 { + return "", l.Count, fmt.Errorf("No match found for %s: %+v", keyword, l) + } + + if l.Count == 1 { + return l.StorageTags[0].Id, l.Count, nil + } + + if l.Count > 1 { + for _, v := range l.StorageTags { + if v.Name == keyword { + return v.Id, l.Count, nil + } + } + } + return "", l.Count, fmt.Errorf("Could not find an exact match for %s: %+v", keyword, l) +} + +// Lists storage tags +func (s *ResourcetagsService) ListStorageTags(p *ListStorageTagsParams) (*ListStorageTagsResponse, error) { + resp, err := s.cs.newRequest("listStorageTags", p.toURLValues()) + if err != nil { + return nil, err + } + + var r ListStorageTagsResponse + if err := json.Unmarshal(resp, &r); err != nil { + return nil, err + } + + return &r, nil +} + +type ListStorageTagsResponse struct { + Count int `json:"count"` + StorageTags []*StorageTag `json:"storagetag"` +} + +type StorageTag struct { + Id string `json:"id"` + Name string `json:"name"` + Poolid int64 `json:"poolid"` } type ListTagsParams struct { @@ -522,6 +525,7 @@ func (s *ResourcetagsService) ListTags(p *ListTagsParams) (*ListTagsResponse, er if err := json.Unmarshal(resp, &r); err != nil { return nil, err } + return &r, nil } @@ -531,14 +535,14 @@ type ListTagsResponse struct { } type Tag struct { - Account string `json:"account,omitempty"` - Customer string `json:"customer,omitempty"` - Domain string `json:"domain,omitempty"` - Domainid string `json:"domainid,omitempty"` - Key string `json:"key,omitempty"` - Project string `json:"project,omitempty"` - Projectid string `json:"projectid,omitempty"` - Resourceid string `json:"resourceid,omitempty"` - Resourcetype string `json:"resourcetype,omitempty"` - Value string `json:"value,omitempty"` + Account string `json:"account"` + Customer string `json:"customer"` + Domain string `json:"domain"` + Domainid string `json:"domainid"` + Key string `json:"key"` + Project string `json:"project"` + Projectid string `json:"projectid"` + Resourceid string `json:"resourceid"` + Resourcetype string `json:"resourcetype"` + Value string `json:"value"` } diff --git a/vendor/github.com/xanzy/go-cloudstack/cloudstack/RoleService.go b/vendor/github.com/xanzy/go-cloudstack/cloudstack/RoleService.go new file mode 100644 index 000000000..f348b1d6f --- /dev/null +++ b/vendor/github.com/xanzy/go-cloudstack/cloudstack/RoleService.go @@ -0,0 +1,749 @@ +// +// Copyright 2018, Sander van Harmelen +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// + +package cloudstack + +import ( + "encoding/json" + "fmt" + "net/url" + "strings" +) + +type CreateRoleParams struct { + p map[string]interface{} +} + +func (p *CreateRoleParams) toURLValues() url.Values { + u := url.Values{} + if p.p == nil { + return u + } + if v, found := p.p["description"]; found { + u.Set("description", v.(string)) + } + if v, found := p.p["name"]; found { + u.Set("name", v.(string)) + } + if v, found := p.p["type"]; found { + u.Set("type", v.(string)) + } + return u +} + +func (p *CreateRoleParams) SetDescription(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["description"] = v + return +} + +func (p *CreateRoleParams) SetName(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["name"] = v + return +} + +func (p *CreateRoleParams) SetType(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["type"] = v + return +} + +// You should always use this function to get a new CreateRoleParams instance, +// as then you are sure you have configured all required params +func (s *RoleService) NewCreateRoleParams(name string, roleType string) *CreateRoleParams { + p := &CreateRoleParams{} + p.p = make(map[string]interface{}) + p.p["name"] = name + p.p["type"] = roleType + return p +} + +// Creates a role +func (s *RoleService) CreateRole(p *CreateRoleParams) (*CreateRoleResponse, error) { + resp, err := s.cs.newRequest("createRole", p.toURLValues()) + if err != nil { + return nil, err + } + + var r CreateRoleResponse + if err := json.Unmarshal(resp, &r); err != nil { + return nil, err + } + + return &r, nil +} + +type CreateRoleResponse struct { + Description string `json:"description"` + Id string `json:"id"` + Name string `json:"name"` + Type string `json:"type"` +} + +type CreateRolePermissionParams struct { + p map[string]interface{} +} + +func (p *CreateRolePermissionParams) toURLValues() url.Values { + u := url.Values{} + if p.p == nil { + return u + } + if v, found := p.p["description"]; found { + u.Set("description", v.(string)) + } + if v, found := p.p["permission"]; found { + u.Set("permission", v.(string)) + } + if v, found := p.p["roleid"]; found { + u.Set("roleid", v.(string)) + } + if v, found := p.p["rule"]; found { + u.Set("rule", v.(string)) + } + return u +} + +func (p *CreateRolePermissionParams) SetDescription(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["description"] = v + return +} + +func (p *CreateRolePermissionParams) SetPermission(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["permission"] = v + return +} + +func (p *CreateRolePermissionParams) SetRoleid(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["roleid"] = v + return +} + +func (p *CreateRolePermissionParams) SetRule(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["rule"] = v + return +} + +// You should always use this function to get a new CreateRolePermissionParams instance, +// as then you are sure you have configured all required params +func (s *RoleService) NewCreateRolePermissionParams(permission string, roleid string, rule string) *CreateRolePermissionParams { + p := &CreateRolePermissionParams{} + p.p = make(map[string]interface{}) + p.p["permission"] = permission + p.p["roleid"] = roleid + p.p["rule"] = rule + return p +} + +// Adds a API permission to a role +func (s *RoleService) CreateRolePermission(p *CreateRolePermissionParams) (*CreateRolePermissionResponse, error) { + resp, err := s.cs.newRequest("createRolePermission", p.toURLValues()) + if err != nil { + return nil, err + } + + var r CreateRolePermissionResponse + if err := json.Unmarshal(resp, &r); err != nil { + return nil, err + } + + return &r, nil +} + +type CreateRolePermissionResponse struct { + Description string `json:"description"` + Id string `json:"id"` + Permission string `json:"permission"` + Roleid string `json:"roleid"` + Rolename string `json:"rolename"` + Rule string `json:"rule"` +} + +type DeleteRoleParams struct { + p map[string]interface{} +} + +func (p *DeleteRoleParams) toURLValues() url.Values { + u := url.Values{} + if p.p == nil { + return u + } + if v, found := p.p["id"]; found { + u.Set("id", v.(string)) + } + return u +} + +func (p *DeleteRoleParams) SetId(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["id"] = v + return +} + +// You should always use this function to get a new DeleteRoleParams instance, +// as then you are sure you have configured all required params +func (s *RoleService) NewDeleteRoleParams(id string) *DeleteRoleParams { + p := &DeleteRoleParams{} + p.p = make(map[string]interface{}) + p.p["id"] = id + return p +} + +// Deletes a role +func (s *RoleService) DeleteRole(p *DeleteRoleParams) (*DeleteRoleResponse, error) { + resp, err := s.cs.newRequest("deleteRole", p.toURLValues()) + if err != nil { + return nil, err + } + + var r DeleteRoleResponse + if err := json.Unmarshal(resp, &r); err != nil { + return nil, err + } + + return &r, nil +} + +type DeleteRoleResponse struct { + Displaytext string `json:"displaytext"` + Success bool `json:"success"` +} + +func (r *DeleteRoleResponse) UnmarshalJSON(b []byte) error { + var m map[string]interface{} + err := json.Unmarshal(b, &m) + if err != nil { + return err + } + + if success, ok := m["success"].(string); ok { + m["success"] = success == "true" + b, err = json.Marshal(m) + if err != nil { + return err + } + } + + type alias DeleteRoleResponse + return json.Unmarshal(b, (*alias)(r)) +} + +type DeleteRolePermissionParams struct { + p map[string]interface{} +} + +func (p *DeleteRolePermissionParams) toURLValues() url.Values { + u := url.Values{} + if p.p == nil { + return u + } + if v, found := p.p["id"]; found { + u.Set("id", v.(string)) + } + return u +} + +func (p *DeleteRolePermissionParams) SetId(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["id"] = v + return +} + +// You should always use this function to get a new DeleteRolePermissionParams instance, +// as then you are sure you have configured all required params +func (s *RoleService) NewDeleteRolePermissionParams(id string) *DeleteRolePermissionParams { + p := &DeleteRolePermissionParams{} + p.p = make(map[string]interface{}) + p.p["id"] = id + return p +} + +// Deletes a role permission +func (s *RoleService) DeleteRolePermission(p *DeleteRolePermissionParams) (*DeleteRolePermissionResponse, error) { + resp, err := s.cs.newRequest("deleteRolePermission", p.toURLValues()) + if err != nil { + return nil, err + } + + var r DeleteRolePermissionResponse + if err := json.Unmarshal(resp, &r); err != nil { + return nil, err + } + + return &r, nil +} + +type DeleteRolePermissionResponse struct { + Displaytext string `json:"displaytext"` + Success bool `json:"success"` +} + +func (r *DeleteRolePermissionResponse) UnmarshalJSON(b []byte) error { + var m map[string]interface{} + err := json.Unmarshal(b, &m) + if err != nil { + return err + } + + if success, ok := m["success"].(string); ok { + m["success"] = success == "true" + b, err = json.Marshal(m) + if err != nil { + return err + } + } + + type alias DeleteRolePermissionResponse + return json.Unmarshal(b, (*alias)(r)) +} + +type ListRolePermissionsParams struct { + p map[string]interface{} +} + +func (p *ListRolePermissionsParams) toURLValues() url.Values { + u := url.Values{} + if p.p == nil { + return u + } + if v, found := p.p["roleid"]; found { + u.Set("roleid", v.(string)) + } + return u +} + +func (p *ListRolePermissionsParams) SetRoleid(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["roleid"] = v + return +} + +// You should always use this function to get a new ListRolePermissionsParams instance, +// as then you are sure you have configured all required params +func (s *RoleService) NewListRolePermissionsParams() *ListRolePermissionsParams { + p := &ListRolePermissionsParams{} + p.p = make(map[string]interface{}) + return p +} + +// Lists role permissions +func (s *RoleService) ListRolePermissions(p *ListRolePermissionsParams) (*ListRolePermissionsResponse, error) { + resp, err := s.cs.newRequest("listRolePermissions", p.toURLValues()) + if err != nil { + return nil, err + } + + var r ListRolePermissionsResponse + if err := json.Unmarshal(resp, &r); err != nil { + return nil, err + } + + return &r, nil +} + +type ListRolePermissionsResponse struct { + Count int `json:"count"` + RolePermissions []*RolePermission `json:"rolepermission"` +} + +type RolePermission struct { + Description string `json:"description"` + Id string `json:"id"` + Permission string `json:"permission"` + Roleid string `json:"roleid"` + Rolename string `json:"rolename"` + Rule string `json:"rule"` +} + +type ListRolesParams struct { + p map[string]interface{} +} + +func (p *ListRolesParams) toURLValues() url.Values { + u := url.Values{} + if p.p == nil { + return u + } + if v, found := p.p["id"]; found { + u.Set("id", v.(string)) + } + if v, found := p.p["name"]; found { + u.Set("name", v.(string)) + } + if v, found := p.p["type"]; found { + u.Set("type", v.(string)) + } + return u +} + +func (p *ListRolesParams) SetId(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["id"] = v + return +} + +func (p *ListRolesParams) SetName(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["name"] = v + return +} + +func (p *ListRolesParams) SetType(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["type"] = v + return +} + +// You should always use this function to get a new ListRolesParams instance, +// as then you are sure you have configured all required params +func (s *RoleService) NewListRolesParams() *ListRolesParams { + p := &ListRolesParams{} + p.p = make(map[string]interface{}) + return p +} + +// This is a courtesy helper function, which in some cases may not work as expected! +func (s *RoleService) GetRoleID(name string, opts ...OptionFunc) (string, int, error) { + p := &ListRolesParams{} + p.p = make(map[string]interface{}) + + p.p["name"] = name + + for _, fn := range append(s.cs.options, opts...) { + if err := fn(s.cs, p); err != nil { + return "", -1, err + } + } + + l, err := s.ListRoles(p) + if err != nil { + return "", -1, err + } + + if l.Count == 0 { + return "", l.Count, fmt.Errorf("No match found for %s: %+v", name, l) + } + + if l.Count == 1 { + return l.Roles[0].Id, l.Count, nil + } + + if l.Count > 1 { + for _, v := range l.Roles { + if v.Name == name { + return v.Id, l.Count, nil + } + } + } + return "", l.Count, fmt.Errorf("Could not find an exact match for %s: %+v", name, l) +} + +// This is a courtesy helper function, which in some cases may not work as expected! +func (s *RoleService) GetRoleByName(name string, opts ...OptionFunc) (*Role, int, error) { + id, count, err := s.GetRoleID(name, opts...) + if err != nil { + return nil, count, err + } + + r, count, err := s.GetRoleByID(id, opts...) + if err != nil { + return nil, count, err + } + return r, count, nil +} + +// This is a courtesy helper function, which in some cases may not work as expected! +func (s *RoleService) GetRoleByID(id string, opts ...OptionFunc) (*Role, int, error) { + p := &ListRolesParams{} + p.p = make(map[string]interface{}) + + p.p["id"] = id + + for _, fn := range append(s.cs.options, opts...) { + if err := fn(s.cs, p); err != nil { + return nil, -1, err + } + } + + l, err := s.ListRoles(p) + if err != nil { + if strings.Contains(err.Error(), fmt.Sprintf( + "Invalid parameter id value=%s due to incorrect long value format, "+ + "or entity does not exist", id)) { + return nil, 0, fmt.Errorf("No match found for %s: %+v", id, l) + } + return nil, -1, err + } + + if l.Count == 0 { + return nil, l.Count, fmt.Errorf("No match found for %s: %+v", id, l) + } + + if l.Count == 1 { + return l.Roles[0], l.Count, nil + } + return nil, l.Count, fmt.Errorf("There is more then one result for Role UUID: %s!", id) +} + +// Lists dynamic roles in CloudStack +func (s *RoleService) ListRoles(p *ListRolesParams) (*ListRolesResponse, error) { + resp, err := s.cs.newRequest("listRoles", p.toURLValues()) + if err != nil { + return nil, err + } + + var r ListRolesResponse + if err := json.Unmarshal(resp, &r); err != nil { + return nil, err + } + + return &r, nil +} + +type ListRolesResponse struct { + Count int `json:"count"` + Roles []*Role `json:"role"` +} + +type Role struct { + Description string `json:"description"` + Id string `json:"id"` + Name string `json:"name"` + Type string `json:"type"` +} + +type UpdateRoleParams struct { + p map[string]interface{} +} + +func (p *UpdateRoleParams) toURLValues() url.Values { + u := url.Values{} + if p.p == nil { + return u + } + if v, found := p.p["description"]; found { + u.Set("description", v.(string)) + } + if v, found := p.p["id"]; found { + u.Set("id", v.(string)) + } + if v, found := p.p["name"]; found { + u.Set("name", v.(string)) + } + if v, found := p.p["type"]; found { + u.Set("type", v.(string)) + } + return u +} + +func (p *UpdateRoleParams) SetDescription(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["description"] = v + return +} + +func (p *UpdateRoleParams) SetId(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["id"] = v + return +} + +func (p *UpdateRoleParams) SetName(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["name"] = v + return +} + +func (p *UpdateRoleParams) SetType(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["type"] = v + return +} + +// You should always use this function to get a new UpdateRoleParams instance, +// as then you are sure you have configured all required params +func (s *RoleService) NewUpdateRoleParams(id string) *UpdateRoleParams { + p := &UpdateRoleParams{} + p.p = make(map[string]interface{}) + p.p["id"] = id + return p +} + +// Updates a role +func (s *RoleService) UpdateRole(p *UpdateRoleParams) (*UpdateRoleResponse, error) { + resp, err := s.cs.newRequest("updateRole", p.toURLValues()) + if err != nil { + return nil, err + } + + var r UpdateRoleResponse + if err := json.Unmarshal(resp, &r); err != nil { + return nil, err + } + + return &r, nil +} + +type UpdateRoleResponse struct { + Description string `json:"description"` + Id string `json:"id"` + Name string `json:"name"` + Type string `json:"type"` +} + +type UpdateRolePermissionParams struct { + p map[string]interface{} +} + +func (p *UpdateRolePermissionParams) toURLValues() url.Values { + u := url.Values{} + if p.p == nil { + return u + } + if v, found := p.p["permission"]; found { + u.Set("permission", v.(string)) + } + if v, found := p.p["roleid"]; found { + u.Set("roleid", v.(string)) + } + if v, found := p.p["ruleid"]; found { + u.Set("ruleid", v.(string)) + } + if v, found := p.p["ruleorder"]; found { + vv := strings.Join(v.([]string), ",") + u.Set("ruleorder", vv) + } + return u +} + +func (p *UpdateRolePermissionParams) SetPermission(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["permission"] = v + return +} + +func (p *UpdateRolePermissionParams) SetRoleid(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["roleid"] = v + return +} + +func (p *UpdateRolePermissionParams) SetRuleid(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["ruleid"] = v + return +} + +func (p *UpdateRolePermissionParams) SetRuleorder(v []string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["ruleorder"] = v + return +} + +// You should always use this function to get a new UpdateRolePermissionParams instance, +// as then you are sure you have configured all required params +func (s *RoleService) NewUpdateRolePermissionParams(roleid string) *UpdateRolePermissionParams { + p := &UpdateRolePermissionParams{} + p.p = make(map[string]interface{}) + p.p["roleid"] = roleid + return p +} + +// Updates a role permission order +func (s *RoleService) UpdateRolePermission(p *UpdateRolePermissionParams) (*UpdateRolePermissionResponse, error) { + resp, err := s.cs.newRequest("updateRolePermission", p.toURLValues()) + if err != nil { + return nil, err + } + + var r UpdateRolePermissionResponse + if err := json.Unmarshal(resp, &r); err != nil { + return nil, err + } + + return &r, nil +} + +type UpdateRolePermissionResponse struct { + Displaytext string `json:"displaytext"` + Success bool `json:"success"` +} + +func (r *UpdateRolePermissionResponse) UnmarshalJSON(b []byte) error { + var m map[string]interface{} + err := json.Unmarshal(b, &m) + if err != nil { + return err + } + + if success, ok := m["success"].(string); ok { + m["success"] = success == "true" + b, err = json.Marshal(m) + if err != nil { + return err + } + } + + type alias UpdateRolePermissionResponse + return json.Unmarshal(b, (*alias)(r)) +} diff --git a/vendor/github.com/xanzy/go-cloudstack/cloudstack/RouterService.go b/vendor/github.com/xanzy/go-cloudstack/cloudstack/RouterService.go index 05496b530..bf37d75e5 100644 --- a/vendor/github.com/xanzy/go-cloudstack/cloudstack/RouterService.go +++ b/vendor/github.com/xanzy/go-cloudstack/cloudstack/RouterService.go @@ -1,5 +1,5 @@ // -// Copyright 2016, Sander van Harmelen +// Copyright 2018, Sander van Harmelen // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -24,11 +24,11 @@ import ( "strings" ) -type StartRouterParams struct { +type ChangeServiceForRouterParams struct { p map[string]interface{} } -func (p *StartRouterParams) toURLValues() url.Values { +func (p *ChangeServiceForRouterParams) toURLValues() url.Values { u := url.Values{} if p.p == nil { return u @@ -36,10 +36,13 @@ func (p *StartRouterParams) toURLValues() url.Values { if v, found := p.p["id"]; found { u.Set("id", v.(string)) } + if v, found := p.p["serviceofferingid"]; found { + u.Set("serviceofferingid", v.(string)) + } return u } -func (p *StartRouterParams) SetId(v string) { +func (p *ChangeServiceForRouterParams) SetId(v string) { if p.p == nil { p.p = make(map[string]interface{}) } @@ -47,271 +50,100 @@ func (p *StartRouterParams) SetId(v string) { return } -// You should always use this function to get a new StartRouterParams instance, -// as then you are sure you have configured all required params -func (s *RouterService) NewStartRouterParams(id string) *StartRouterParams { - p := &StartRouterParams{} - p.p = make(map[string]interface{}) - p.p["id"] = id - return p -} - -// Starts a router. -func (s *RouterService) StartRouter(p *StartRouterParams) (*StartRouterResponse, error) { - resp, err := s.cs.newRequest("startRouter", p.toURLValues()) - if err != nil { - return nil, err - } - - var r StartRouterResponse - if err := json.Unmarshal(resp, &r); err != nil { - return nil, err - } - - // If we have a async client, we need to wait for the async result - if s.cs.async { - b, err := s.cs.GetAsyncJobResult(r.JobID, s.cs.timeout) - if err != nil { - if err == AsyncTimeoutErr { - return &r, err - } - return nil, err - } - - b, err = getRawValue(b) - if err != nil { - return nil, err - } - - if err := json.Unmarshal(b, &r); err != nil { - return nil, err - } - } - return &r, nil -} - -type StartRouterResponse struct { - JobID string `json:"jobid,omitempty"` - Account string `json:"account,omitempty"` - Created string `json:"created,omitempty"` - Dns1 string `json:"dns1,omitempty"` - Dns2 string `json:"dns2,omitempty"` - Domain string `json:"domain,omitempty"` - Domainid string `json:"domainid,omitempty"` - Gateway string `json:"gateway,omitempty"` - Guestipaddress string `json:"guestipaddress,omitempty"` - Guestmacaddress string `json:"guestmacaddress,omitempty"` - Guestnetmask string `json:"guestnetmask,omitempty"` - Guestnetworkid string `json:"guestnetworkid,omitempty"` - Guestnetworkname string `json:"guestnetworkname,omitempty"` - Hostid string `json:"hostid,omitempty"` - Hostname string `json:"hostname,omitempty"` - Hypervisor string `json:"hypervisor,omitempty"` - Id string `json:"id,omitempty"` - Ip6dns1 string `json:"ip6dns1,omitempty"` - Ip6dns2 string `json:"ip6dns2,omitempty"` - Isredundantrouter bool `json:"isredundantrouter,omitempty"` - Linklocalip string `json:"linklocalip,omitempty"` - Linklocalmacaddress string `json:"linklocalmacaddress,omitempty"` - Linklocalnetmask string `json:"linklocalnetmask,omitempty"` - Linklocalnetworkid string `json:"linklocalnetworkid,omitempty"` - Name string `json:"name,omitempty"` - Networkdomain string `json:"networkdomain,omitempty"` - Nic []struct { - Broadcasturi string `json:"broadcasturi,omitempty"` - Deviceid string `json:"deviceid,omitempty"` - Gateway string `json:"gateway,omitempty"` - Id string `json:"id,omitempty"` - Ip6address string `json:"ip6address,omitempty"` - Ip6cidr string `json:"ip6cidr,omitempty"` - Ip6gateway string `json:"ip6gateway,omitempty"` - Ipaddress string `json:"ipaddress,omitempty"` - Isdefault bool `json:"isdefault,omitempty"` - Isolationuri string `json:"isolationuri,omitempty"` - Macaddress string `json:"macaddress,omitempty"` - Netmask string `json:"netmask,omitempty"` - Networkid string `json:"networkid,omitempty"` - Networkname string `json:"networkname,omitempty"` - Secondaryip []struct { - Id string `json:"id,omitempty"` - Ipaddress string `json:"ipaddress,omitempty"` - } `json:"secondaryip,omitempty"` - Traffictype string `json:"traffictype,omitempty"` - Type string `json:"type,omitempty"` - Virtualmachineid string `json:"virtualmachineid,omitempty"` - } `json:"nic,omitempty"` - Podid string `json:"podid,omitempty"` - Project string `json:"project,omitempty"` - Projectid string `json:"projectid,omitempty"` - Publicip string `json:"publicip,omitempty"` - Publicmacaddress string `json:"publicmacaddress,omitempty"` - Publicnetmask string `json:"publicnetmask,omitempty"` - Publicnetworkid string `json:"publicnetworkid,omitempty"` - Redundantstate string `json:"redundantstate,omitempty"` - Requiresupgrade bool `json:"requiresupgrade,omitempty"` - Role string `json:"role,omitempty"` - Scriptsversion string `json:"scriptsversion,omitempty"` - Serviceofferingid string `json:"serviceofferingid,omitempty"` - Serviceofferingname string `json:"serviceofferingname,omitempty"` - State string `json:"state,omitempty"` - Templateid string `json:"templateid,omitempty"` - Version string `json:"version,omitempty"` - Vpcid string `json:"vpcid,omitempty"` - Vpcname string `json:"vpcname,omitempty"` - Zoneid string `json:"zoneid,omitempty"` - Zonename string `json:"zonename,omitempty"` -} - -type RebootRouterParams struct { - p map[string]interface{} -} - -func (p *RebootRouterParams) toURLValues() url.Values { - u := url.Values{} - if p.p == nil { - return u - } - if v, found := p.p["id"]; found { - u.Set("id", v.(string)) - } - return u -} - -func (p *RebootRouterParams) SetId(v string) { +func (p *ChangeServiceForRouterParams) SetServiceofferingid(v string) { if p.p == nil { p.p = make(map[string]interface{}) } - p.p["id"] = v + p.p["serviceofferingid"] = v return } -// You should always use this function to get a new RebootRouterParams instance, +// You should always use this function to get a new ChangeServiceForRouterParams instance, // as then you are sure you have configured all required params -func (s *RouterService) NewRebootRouterParams(id string) *RebootRouterParams { - p := &RebootRouterParams{} +func (s *RouterService) NewChangeServiceForRouterParams(id string, serviceofferingid string) *ChangeServiceForRouterParams { + p := &ChangeServiceForRouterParams{} p.p = make(map[string]interface{}) p.p["id"] = id + p.p["serviceofferingid"] = serviceofferingid return p } -// Starts a router. -func (s *RouterService) RebootRouter(p *RebootRouterParams) (*RebootRouterResponse, error) { - resp, err := s.cs.newRequest("rebootRouter", p.toURLValues()) +// Upgrades domain router to a new service offering +func (s *RouterService) ChangeServiceForRouter(p *ChangeServiceForRouterParams) (*ChangeServiceForRouterResponse, error) { + resp, err := s.cs.newRequest("changeServiceForRouter", p.toURLValues()) if err != nil { return nil, err } - var r RebootRouterResponse + var r ChangeServiceForRouterResponse if err := json.Unmarshal(resp, &r); err != nil { return nil, err } - // If we have a async client, we need to wait for the async result - if s.cs.async { - b, err := s.cs.GetAsyncJobResult(r.JobID, s.cs.timeout) - if err != nil { - if err == AsyncTimeoutErr { - return &r, err - } - return nil, err - } - - b, err = getRawValue(b) - if err != nil { - return nil, err - } - - if err := json.Unmarshal(b, &r); err != nil { - return nil, err - } - } return &r, nil } -type RebootRouterResponse struct { - JobID string `json:"jobid,omitempty"` - Account string `json:"account,omitempty"` - Created string `json:"created,omitempty"` - Dns1 string `json:"dns1,omitempty"` - Dns2 string `json:"dns2,omitempty"` - Domain string `json:"domain,omitempty"` - Domainid string `json:"domainid,omitempty"` - Gateway string `json:"gateway,omitempty"` - Guestipaddress string `json:"guestipaddress,omitempty"` - Guestmacaddress string `json:"guestmacaddress,omitempty"` - Guestnetmask string `json:"guestnetmask,omitempty"` - Guestnetworkid string `json:"guestnetworkid,omitempty"` - Guestnetworkname string `json:"guestnetworkname,omitempty"` - Hostid string `json:"hostid,omitempty"` - Hostname string `json:"hostname,omitempty"` - Hypervisor string `json:"hypervisor,omitempty"` - Id string `json:"id,omitempty"` - Ip6dns1 string `json:"ip6dns1,omitempty"` - Ip6dns2 string `json:"ip6dns2,omitempty"` - Isredundantrouter bool `json:"isredundantrouter,omitempty"` - Linklocalip string `json:"linklocalip,omitempty"` - Linklocalmacaddress string `json:"linklocalmacaddress,omitempty"` - Linklocalnetmask string `json:"linklocalnetmask,omitempty"` - Linklocalnetworkid string `json:"linklocalnetworkid,omitempty"` - Name string `json:"name,omitempty"` - Networkdomain string `json:"networkdomain,omitempty"` - Nic []struct { - Broadcasturi string `json:"broadcasturi,omitempty"` - Deviceid string `json:"deviceid,omitempty"` - Gateway string `json:"gateway,omitempty"` - Id string `json:"id,omitempty"` - Ip6address string `json:"ip6address,omitempty"` - Ip6cidr string `json:"ip6cidr,omitempty"` - Ip6gateway string `json:"ip6gateway,omitempty"` - Ipaddress string `json:"ipaddress,omitempty"` - Isdefault bool `json:"isdefault,omitempty"` - Isolationuri string `json:"isolationuri,omitempty"` - Macaddress string `json:"macaddress,omitempty"` - Netmask string `json:"netmask,omitempty"` - Networkid string `json:"networkid,omitempty"` - Networkname string `json:"networkname,omitempty"` - Secondaryip []struct { - Id string `json:"id,omitempty"` - Ipaddress string `json:"ipaddress,omitempty"` - } `json:"secondaryip,omitempty"` - Traffictype string `json:"traffictype,omitempty"` - Type string `json:"type,omitempty"` - Virtualmachineid string `json:"virtualmachineid,omitempty"` - } `json:"nic,omitempty"` - Podid string `json:"podid,omitempty"` - Project string `json:"project,omitempty"` - Projectid string `json:"projectid,omitempty"` - Publicip string `json:"publicip,omitempty"` - Publicmacaddress string `json:"publicmacaddress,omitempty"` - Publicnetmask string `json:"publicnetmask,omitempty"` - Publicnetworkid string `json:"publicnetworkid,omitempty"` - Redundantstate string `json:"redundantstate,omitempty"` - Requiresupgrade bool `json:"requiresupgrade,omitempty"` - Role string `json:"role,omitempty"` - Scriptsversion string `json:"scriptsversion,omitempty"` - Serviceofferingid string `json:"serviceofferingid,omitempty"` - Serviceofferingname string `json:"serviceofferingname,omitempty"` - State string `json:"state,omitempty"` - Templateid string `json:"templateid,omitempty"` - Version string `json:"version,omitempty"` - Vpcid string `json:"vpcid,omitempty"` - Vpcname string `json:"vpcname,omitempty"` - Zoneid string `json:"zoneid,omitempty"` - Zonename string `json:"zonename,omitempty"` +type ChangeServiceForRouterResponse struct { + Account string `json:"account"` + Created string `json:"created"` + Dns1 string `json:"dns1"` + Dns2 string `json:"dns2"` + Domain string `json:"domain"` + Domainid string `json:"domainid"` + Gateway string `json:"gateway"` + Guestipaddress string `json:"guestipaddress"` + Guestmacaddress string `json:"guestmacaddress"` + Guestnetmask string `json:"guestnetmask"` + Guestnetworkid string `json:"guestnetworkid"` + Guestnetworkname string `json:"guestnetworkname"` + Hostid string `json:"hostid"` + Hostname string `json:"hostname"` + Hypervisor string `json:"hypervisor"` + Id string `json:"id"` + Ip6dns1 string `json:"ip6dns1"` + Ip6dns2 string `json:"ip6dns2"` + Isredundantrouter bool `json:"isredundantrouter"` + Linklocalip string `json:"linklocalip"` + Linklocalmacaddress string `json:"linklocalmacaddress"` + Linklocalnetmask string `json:"linklocalnetmask"` + Linklocalnetworkid string `json:"linklocalnetworkid"` + Name string `json:"name"` + Networkdomain string `json:"networkdomain"` + Nic []Nic `json:"nic"` + Podid string `json:"podid"` + Project string `json:"project"` + Projectid string `json:"projectid"` + Publicip string `json:"publicip"` + Publicmacaddress string `json:"publicmacaddress"` + Publicnetmask string `json:"publicnetmask"` + Publicnetworkid string `json:"publicnetworkid"` + Redundantstate string `json:"redundantstate"` + Requiresupgrade bool `json:"requiresupgrade"` + Role string `json:"role"` + Scriptsversion string `json:"scriptsversion"` + Serviceofferingid string `json:"serviceofferingid"` + Serviceofferingname string `json:"serviceofferingname"` + State string `json:"state"` + Templateid string `json:"templateid"` + Version string `json:"version"` + Vpcid string `json:"vpcid"` + Vpcname string `json:"vpcname"` + Zoneid string `json:"zoneid"` + Zonename string `json:"zonename"` } -type StopRouterParams struct { +type ConfigureVirtualRouterElementParams struct { p map[string]interface{} } -func (p *StopRouterParams) toURLValues() url.Values { +func (p *ConfigureVirtualRouterElementParams) toURLValues() url.Values { u := url.Values{} if p.p == nil { return u } - if v, found := p.p["forced"]; found { + if v, found := p.p["enabled"]; found { vv := strconv.FormatBool(v.(bool)) - u.Set("forced", vv) + u.Set("enabled", vv) } if v, found := p.p["id"]; found { u.Set("id", v.(string)) @@ -319,15 +151,15 @@ func (p *StopRouterParams) toURLValues() url.Values { return u } -func (p *StopRouterParams) SetForced(v bool) { +func (p *ConfigureVirtualRouterElementParams) SetEnabled(v bool) { if p.p == nil { p.p = make(map[string]interface{}) } - p.p["forced"] = v + p.p["enabled"] = v return } -func (p *StopRouterParams) SetId(v string) { +func (p *ConfigureVirtualRouterElementParams) SetId(v string) { if p.p == nil { p.p = make(map[string]interface{}) } @@ -335,23 +167,24 @@ func (p *StopRouterParams) SetId(v string) { return } -// You should always use this function to get a new StopRouterParams instance, +// You should always use this function to get a new ConfigureVirtualRouterElementParams instance, // as then you are sure you have configured all required params -func (s *RouterService) NewStopRouterParams(id string) *StopRouterParams { - p := &StopRouterParams{} +func (s *RouterService) NewConfigureVirtualRouterElementParams(enabled bool, id string) *ConfigureVirtualRouterElementParams { + p := &ConfigureVirtualRouterElementParams{} p.p = make(map[string]interface{}) + p.p["enabled"] = enabled p.p["id"] = id return p } -// Stops a router. -func (s *RouterService) StopRouter(p *StopRouterParams) (*StopRouterResponse, error) { - resp, err := s.cs.newRequest("stopRouter", p.toURLValues()) +// Configures a virtual router element. +func (s *RouterService) ConfigureVirtualRouterElement(p *ConfigureVirtualRouterElementParams) (*VirtualRouterElementResponse, error) { + resp, err := s.cs.newRequest("configureVirtualRouterElement", p.toURLValues()) if err != nil { return nil, err } - var r StopRouterResponse + var r VirtualRouterElementResponse if err := json.Unmarshal(resp, &r); err != nil { return nil, err } @@ -375,79 +208,110 @@ func (s *RouterService) StopRouter(p *StopRouterParams) (*StopRouterResponse, er return nil, err } } + return &r, nil } -type StopRouterResponse struct { - JobID string `json:"jobid,omitempty"` - Account string `json:"account,omitempty"` - Created string `json:"created,omitempty"` - Dns1 string `json:"dns1,omitempty"` - Dns2 string `json:"dns2,omitempty"` - Domain string `json:"domain,omitempty"` - Domainid string `json:"domainid,omitempty"` - Gateway string `json:"gateway,omitempty"` - Guestipaddress string `json:"guestipaddress,omitempty"` - Guestmacaddress string `json:"guestmacaddress,omitempty"` - Guestnetmask string `json:"guestnetmask,omitempty"` - Guestnetworkid string `json:"guestnetworkid,omitempty"` - Guestnetworkname string `json:"guestnetworkname,omitempty"` - Hostid string `json:"hostid,omitempty"` - Hostname string `json:"hostname,omitempty"` - Hypervisor string `json:"hypervisor,omitempty"` - Id string `json:"id,omitempty"` - Ip6dns1 string `json:"ip6dns1,omitempty"` - Ip6dns2 string `json:"ip6dns2,omitempty"` - Isredundantrouter bool `json:"isredundantrouter,omitempty"` - Linklocalip string `json:"linklocalip,omitempty"` - Linklocalmacaddress string `json:"linklocalmacaddress,omitempty"` - Linklocalnetmask string `json:"linklocalnetmask,omitempty"` - Linklocalnetworkid string `json:"linklocalnetworkid,omitempty"` - Name string `json:"name,omitempty"` - Networkdomain string `json:"networkdomain,omitempty"` - Nic []struct { - Broadcasturi string `json:"broadcasturi,omitempty"` - Deviceid string `json:"deviceid,omitempty"` - Gateway string `json:"gateway,omitempty"` - Id string `json:"id,omitempty"` - Ip6address string `json:"ip6address,omitempty"` - Ip6cidr string `json:"ip6cidr,omitempty"` - Ip6gateway string `json:"ip6gateway,omitempty"` - Ipaddress string `json:"ipaddress,omitempty"` - Isdefault bool `json:"isdefault,omitempty"` - Isolationuri string `json:"isolationuri,omitempty"` - Macaddress string `json:"macaddress,omitempty"` - Netmask string `json:"netmask,omitempty"` - Networkid string `json:"networkid,omitempty"` - Networkname string `json:"networkname,omitempty"` - Secondaryip []struct { - Id string `json:"id,omitempty"` - Ipaddress string `json:"ipaddress,omitempty"` - } `json:"secondaryip,omitempty"` - Traffictype string `json:"traffictype,omitempty"` - Type string `json:"type,omitempty"` - Virtualmachineid string `json:"virtualmachineid,omitempty"` - } `json:"nic,omitempty"` - Podid string `json:"podid,omitempty"` - Project string `json:"project,omitempty"` - Projectid string `json:"projectid,omitempty"` - Publicip string `json:"publicip,omitempty"` - Publicmacaddress string `json:"publicmacaddress,omitempty"` - Publicnetmask string `json:"publicnetmask,omitempty"` - Publicnetworkid string `json:"publicnetworkid,omitempty"` - Redundantstate string `json:"redundantstate,omitempty"` - Requiresupgrade bool `json:"requiresupgrade,omitempty"` - Role string `json:"role,omitempty"` - Scriptsversion string `json:"scriptsversion,omitempty"` - Serviceofferingid string `json:"serviceofferingid,omitempty"` - Serviceofferingname string `json:"serviceofferingname,omitempty"` - State string `json:"state,omitempty"` - Templateid string `json:"templateid,omitempty"` - Version string `json:"version,omitempty"` - Vpcid string `json:"vpcid,omitempty"` - Vpcname string `json:"vpcname,omitempty"` - Zoneid string `json:"zoneid,omitempty"` - Zonename string `json:"zonename,omitempty"` +type VirtualRouterElementResponse struct { + JobID string `json:"jobid"` + Account string `json:"account"` + Domain string `json:"domain"` + Domainid string `json:"domainid"` + Enabled bool `json:"enabled"` + Id string `json:"id"` + Nspid string `json:"nspid"` + Project string `json:"project"` + Projectid string `json:"projectid"` +} + +type CreateVirtualRouterElementParams struct { + p map[string]interface{} +} + +func (p *CreateVirtualRouterElementParams) toURLValues() url.Values { + u := url.Values{} + if p.p == nil { + return u + } + if v, found := p.p["nspid"]; found { + u.Set("nspid", v.(string)) + } + if v, found := p.p["providertype"]; found { + u.Set("providertype", v.(string)) + } + return u +} + +func (p *CreateVirtualRouterElementParams) SetNspid(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["nspid"] = v + return +} + +func (p *CreateVirtualRouterElementParams) SetProvidertype(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["providertype"] = v + return +} + +// You should always use this function to get a new CreateVirtualRouterElementParams instance, +// as then you are sure you have configured all required params +func (s *RouterService) NewCreateVirtualRouterElementParams(nspid string) *CreateVirtualRouterElementParams { + p := &CreateVirtualRouterElementParams{} + p.p = make(map[string]interface{}) + p.p["nspid"] = nspid + return p +} + +// Create a virtual router element. +func (s *RouterService) CreateVirtualRouterElement(p *CreateVirtualRouterElementParams) (*CreateVirtualRouterElementResponse, error) { + resp, err := s.cs.newRequest("createVirtualRouterElement", p.toURLValues()) + if err != nil { + return nil, err + } + + var r CreateVirtualRouterElementResponse + if err := json.Unmarshal(resp, &r); err != nil { + return nil, err + } + + // If we have a async client, we need to wait for the async result + if s.cs.async { + b, err := s.cs.GetAsyncJobResult(r.JobID, s.cs.timeout) + if err != nil { + if err == AsyncTimeoutErr { + return &r, err + } + return nil, err + } + + b, err = getRawValue(b) + if err != nil { + return nil, err + } + + if err := json.Unmarshal(b, &r); err != nil { + return nil, err + } + } + + return &r, nil +} + +type CreateVirtualRouterElementResponse struct { + JobID string `json:"jobid"` + Account string `json:"account"` + Domain string `json:"domain"` + Domainid string `json:"domainid"` + Enabled bool `json:"enabled"` + Id string `json:"id"` + Nspid string `json:"nspid"` + Project string `json:"project"` + Projectid string `json:"projectid"` } type DestroyRouterParams struct { @@ -513,208 +377,58 @@ func (s *RouterService) DestroyRouter(p *DestroyRouterParams) (*DestroyRouterRes return nil, err } } + return &r, nil } type DestroyRouterResponse struct { - JobID string `json:"jobid,omitempty"` - Account string `json:"account,omitempty"` - Created string `json:"created,omitempty"` - Dns1 string `json:"dns1,omitempty"` - Dns2 string `json:"dns2,omitempty"` - Domain string `json:"domain,omitempty"` - Domainid string `json:"domainid,omitempty"` - Gateway string `json:"gateway,omitempty"` - Guestipaddress string `json:"guestipaddress,omitempty"` - Guestmacaddress string `json:"guestmacaddress,omitempty"` - Guestnetmask string `json:"guestnetmask,omitempty"` - Guestnetworkid string `json:"guestnetworkid,omitempty"` - Guestnetworkname string `json:"guestnetworkname,omitempty"` - Hostid string `json:"hostid,omitempty"` - Hostname string `json:"hostname,omitempty"` - Hypervisor string `json:"hypervisor,omitempty"` - Id string `json:"id,omitempty"` - Ip6dns1 string `json:"ip6dns1,omitempty"` - Ip6dns2 string `json:"ip6dns2,omitempty"` - Isredundantrouter bool `json:"isredundantrouter,omitempty"` - Linklocalip string `json:"linklocalip,omitempty"` - Linklocalmacaddress string `json:"linklocalmacaddress,omitempty"` - Linklocalnetmask string `json:"linklocalnetmask,omitempty"` - Linklocalnetworkid string `json:"linklocalnetworkid,omitempty"` - Name string `json:"name,omitempty"` - Networkdomain string `json:"networkdomain,omitempty"` - Nic []struct { - Broadcasturi string `json:"broadcasturi,omitempty"` - Deviceid string `json:"deviceid,omitempty"` - Gateway string `json:"gateway,omitempty"` - Id string `json:"id,omitempty"` - Ip6address string `json:"ip6address,omitempty"` - Ip6cidr string `json:"ip6cidr,omitempty"` - Ip6gateway string `json:"ip6gateway,omitempty"` - Ipaddress string `json:"ipaddress,omitempty"` - Isdefault bool `json:"isdefault,omitempty"` - Isolationuri string `json:"isolationuri,omitempty"` - Macaddress string `json:"macaddress,omitempty"` - Netmask string `json:"netmask,omitempty"` - Networkid string `json:"networkid,omitempty"` - Networkname string `json:"networkname,omitempty"` - Secondaryip []struct { - Id string `json:"id,omitempty"` - Ipaddress string `json:"ipaddress,omitempty"` - } `json:"secondaryip,omitempty"` - Traffictype string `json:"traffictype,omitempty"` - Type string `json:"type,omitempty"` - Virtualmachineid string `json:"virtualmachineid,omitempty"` - } `json:"nic,omitempty"` - Podid string `json:"podid,omitempty"` - Project string `json:"project,omitempty"` - Projectid string `json:"projectid,omitempty"` - Publicip string `json:"publicip,omitempty"` - Publicmacaddress string `json:"publicmacaddress,omitempty"` - Publicnetmask string `json:"publicnetmask,omitempty"` - Publicnetworkid string `json:"publicnetworkid,omitempty"` - Redundantstate string `json:"redundantstate,omitempty"` - Requiresupgrade bool `json:"requiresupgrade,omitempty"` - Role string `json:"role,omitempty"` - Scriptsversion string `json:"scriptsversion,omitempty"` - Serviceofferingid string `json:"serviceofferingid,omitempty"` - Serviceofferingname string `json:"serviceofferingname,omitempty"` - State string `json:"state,omitempty"` - Templateid string `json:"templateid,omitempty"` - Version string `json:"version,omitempty"` - Vpcid string `json:"vpcid,omitempty"` - Vpcname string `json:"vpcname,omitempty"` - Zoneid string `json:"zoneid,omitempty"` - Zonename string `json:"zonename,omitempty"` -} - -type ChangeServiceForRouterParams struct { - p map[string]interface{} -} - -func (p *ChangeServiceForRouterParams) toURLValues() url.Values { - u := url.Values{} - if p.p == nil { - return u - } - if v, found := p.p["id"]; found { - u.Set("id", v.(string)) - } - if v, found := p.p["serviceofferingid"]; found { - u.Set("serviceofferingid", v.(string)) - } - return u -} - -func (p *ChangeServiceForRouterParams) SetId(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["id"] = v - return -} - -func (p *ChangeServiceForRouterParams) SetServiceofferingid(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["serviceofferingid"] = v - return -} - -// You should always use this function to get a new ChangeServiceForRouterParams instance, -// as then you are sure you have configured all required params -func (s *RouterService) NewChangeServiceForRouterParams(id string, serviceofferingid string) *ChangeServiceForRouterParams { - p := &ChangeServiceForRouterParams{} - p.p = make(map[string]interface{}) - p.p["id"] = id - p.p["serviceofferingid"] = serviceofferingid - return p -} - -// Upgrades domain router to a new service offering -func (s *RouterService) ChangeServiceForRouter(p *ChangeServiceForRouterParams) (*ChangeServiceForRouterResponse, error) { - resp, err := s.cs.newRequest("changeServiceForRouter", p.toURLValues()) - if err != nil { - return nil, err - } - - var r ChangeServiceForRouterResponse - if err := json.Unmarshal(resp, &r); err != nil { - return nil, err - } - return &r, nil -} - -type ChangeServiceForRouterResponse struct { - Account string `json:"account,omitempty"` - Created string `json:"created,omitempty"` - Dns1 string `json:"dns1,omitempty"` - Dns2 string `json:"dns2,omitempty"` - Domain string `json:"domain,omitempty"` - Domainid string `json:"domainid,omitempty"` - Gateway string `json:"gateway,omitempty"` - Guestipaddress string `json:"guestipaddress,omitempty"` - Guestmacaddress string `json:"guestmacaddress,omitempty"` - Guestnetmask string `json:"guestnetmask,omitempty"` - Guestnetworkid string `json:"guestnetworkid,omitempty"` - Guestnetworkname string `json:"guestnetworkname,omitempty"` - Hostid string `json:"hostid,omitempty"` - Hostname string `json:"hostname,omitempty"` - Hypervisor string `json:"hypervisor,omitempty"` - Id string `json:"id,omitempty"` - Ip6dns1 string `json:"ip6dns1,omitempty"` - Ip6dns2 string `json:"ip6dns2,omitempty"` - Isredundantrouter bool `json:"isredundantrouter,omitempty"` - Linklocalip string `json:"linklocalip,omitempty"` - Linklocalmacaddress string `json:"linklocalmacaddress,omitempty"` - Linklocalnetmask string `json:"linklocalnetmask,omitempty"` - Linklocalnetworkid string `json:"linklocalnetworkid,omitempty"` - Name string `json:"name,omitempty"` - Networkdomain string `json:"networkdomain,omitempty"` - Nic []struct { - Broadcasturi string `json:"broadcasturi,omitempty"` - Deviceid string `json:"deviceid,omitempty"` - Gateway string `json:"gateway,omitempty"` - Id string `json:"id,omitempty"` - Ip6address string `json:"ip6address,omitempty"` - Ip6cidr string `json:"ip6cidr,omitempty"` - Ip6gateway string `json:"ip6gateway,omitempty"` - Ipaddress string `json:"ipaddress,omitempty"` - Isdefault bool `json:"isdefault,omitempty"` - Isolationuri string `json:"isolationuri,omitempty"` - Macaddress string `json:"macaddress,omitempty"` - Netmask string `json:"netmask,omitempty"` - Networkid string `json:"networkid,omitempty"` - Networkname string `json:"networkname,omitempty"` - Secondaryip []struct { - Id string `json:"id,omitempty"` - Ipaddress string `json:"ipaddress,omitempty"` - } `json:"secondaryip,omitempty"` - Traffictype string `json:"traffictype,omitempty"` - Type string `json:"type,omitempty"` - Virtualmachineid string `json:"virtualmachineid,omitempty"` - } `json:"nic,omitempty"` - Podid string `json:"podid,omitempty"` - Project string `json:"project,omitempty"` - Projectid string `json:"projectid,omitempty"` - Publicip string `json:"publicip,omitempty"` - Publicmacaddress string `json:"publicmacaddress,omitempty"` - Publicnetmask string `json:"publicnetmask,omitempty"` - Publicnetworkid string `json:"publicnetworkid,omitempty"` - Redundantstate string `json:"redundantstate,omitempty"` - Requiresupgrade bool `json:"requiresupgrade,omitempty"` - Role string `json:"role,omitempty"` - Scriptsversion string `json:"scriptsversion,omitempty"` - Serviceofferingid string `json:"serviceofferingid,omitempty"` - Serviceofferingname string `json:"serviceofferingname,omitempty"` - State string `json:"state,omitempty"` - Templateid string `json:"templateid,omitempty"` - Version string `json:"version,omitempty"` - Vpcid string `json:"vpcid,omitempty"` - Vpcname string `json:"vpcname,omitempty"` - Zoneid string `json:"zoneid,omitempty"` - Zonename string `json:"zonename,omitempty"` + JobID string `json:"jobid"` + Account string `json:"account"` + Created string `json:"created"` + Dns1 string `json:"dns1"` + Dns2 string `json:"dns2"` + Domain string `json:"domain"` + Domainid string `json:"domainid"` + Gateway string `json:"gateway"` + Guestipaddress string `json:"guestipaddress"` + Guestmacaddress string `json:"guestmacaddress"` + Guestnetmask string `json:"guestnetmask"` + Guestnetworkid string `json:"guestnetworkid"` + Guestnetworkname string `json:"guestnetworkname"` + Hostid string `json:"hostid"` + Hostname string `json:"hostname"` + Hypervisor string `json:"hypervisor"` + Id string `json:"id"` + Ip6dns1 string `json:"ip6dns1"` + Ip6dns2 string `json:"ip6dns2"` + Isredundantrouter bool `json:"isredundantrouter"` + Linklocalip string `json:"linklocalip"` + Linklocalmacaddress string `json:"linklocalmacaddress"` + Linklocalnetmask string `json:"linklocalnetmask"` + Linklocalnetworkid string `json:"linklocalnetworkid"` + Name string `json:"name"` + Networkdomain string `json:"networkdomain"` + Nic []Nic `json:"nic"` + Podid string `json:"podid"` + Project string `json:"project"` + Projectid string `json:"projectid"` + Publicip string `json:"publicip"` + Publicmacaddress string `json:"publicmacaddress"` + Publicnetmask string `json:"publicnetmask"` + Publicnetworkid string `json:"publicnetworkid"` + Redundantstate string `json:"redundantstate"` + Requiresupgrade bool `json:"requiresupgrade"` + Role string `json:"role"` + Scriptsversion string `json:"scriptsversion"` + Serviceofferingid string `json:"serviceofferingid"` + Serviceofferingname string `json:"serviceofferingname"` + State string `json:"state"` + Templateid string `json:"templateid"` + Version string `json:"version"` + Vpcid string `json:"vpcid"` + Vpcname string `json:"vpcname"` + Zoneid string `json:"zoneid"` + Zonename string `json:"zonename"` } type ListRoutersParams struct { @@ -958,7 +672,7 @@ func (s *RouterService) GetRouterID(name string, opts ...OptionFunc) (string, in p.p["name"] = name - for _, fn := range opts { + for _, fn := range append(s.cs.options, opts...) { if err := fn(s.cs, p); err != nil { return "", -1, err } @@ -1008,7 +722,7 @@ func (s *RouterService) GetRouterByID(id string, opts ...OptionFunc) (*Router, i p.p["id"] = id - for _, fn := range opts { + for _, fn := range append(s.cs.options, opts...) { if err := fn(s.cs, p); err != nil { return nil, -1, err } @@ -1045,6 +759,7 @@ func (s *RouterService) ListRouters(p *ListRoutersParams) (*ListRoutersResponse, if err := json.Unmarshal(resp, &r); err != nil { return nil, err } + return &r, nil } @@ -1054,74 +769,52 @@ type ListRoutersResponse struct { } type Router struct { - Account string `json:"account,omitempty"` - Created string `json:"created,omitempty"` - Dns1 string `json:"dns1,omitempty"` - Dns2 string `json:"dns2,omitempty"` - Domain string `json:"domain,omitempty"` - Domainid string `json:"domainid,omitempty"` - Gateway string `json:"gateway,omitempty"` - Guestipaddress string `json:"guestipaddress,omitempty"` - Guestmacaddress string `json:"guestmacaddress,omitempty"` - Guestnetmask string `json:"guestnetmask,omitempty"` - Guestnetworkid string `json:"guestnetworkid,omitempty"` - Guestnetworkname string `json:"guestnetworkname,omitempty"` - Hostid string `json:"hostid,omitempty"` - Hostname string `json:"hostname,omitempty"` - Hypervisor string `json:"hypervisor,omitempty"` - Id string `json:"id,omitempty"` - Ip6dns1 string `json:"ip6dns1,omitempty"` - Ip6dns2 string `json:"ip6dns2,omitempty"` - Isredundantrouter bool `json:"isredundantrouter,omitempty"` - Linklocalip string `json:"linklocalip,omitempty"` - Linklocalmacaddress string `json:"linklocalmacaddress,omitempty"` - Linklocalnetmask string `json:"linklocalnetmask,omitempty"` - Linklocalnetworkid string `json:"linklocalnetworkid,omitempty"` - Name string `json:"name,omitempty"` - Networkdomain string `json:"networkdomain,omitempty"` - Nic []struct { - Broadcasturi string `json:"broadcasturi,omitempty"` - Deviceid string `json:"deviceid,omitempty"` - Gateway string `json:"gateway,omitempty"` - Id string `json:"id,omitempty"` - Ip6address string `json:"ip6address,omitempty"` - Ip6cidr string `json:"ip6cidr,omitempty"` - Ip6gateway string `json:"ip6gateway,omitempty"` - Ipaddress string `json:"ipaddress,omitempty"` - Isdefault bool `json:"isdefault,omitempty"` - Isolationuri string `json:"isolationuri,omitempty"` - Macaddress string `json:"macaddress,omitempty"` - Netmask string `json:"netmask,omitempty"` - Networkid string `json:"networkid,omitempty"` - Networkname string `json:"networkname,omitempty"` - Secondaryip []struct { - Id string `json:"id,omitempty"` - Ipaddress string `json:"ipaddress,omitempty"` - } `json:"secondaryip,omitempty"` - Traffictype string `json:"traffictype,omitempty"` - Type string `json:"type,omitempty"` - Virtualmachineid string `json:"virtualmachineid,omitempty"` - } `json:"nic,omitempty"` - Podid string `json:"podid,omitempty"` - Project string `json:"project,omitempty"` - Projectid string `json:"projectid,omitempty"` - Publicip string `json:"publicip,omitempty"` - Publicmacaddress string `json:"publicmacaddress,omitempty"` - Publicnetmask string `json:"publicnetmask,omitempty"` - Publicnetworkid string `json:"publicnetworkid,omitempty"` - Redundantstate string `json:"redundantstate,omitempty"` - Requiresupgrade bool `json:"requiresupgrade,omitempty"` - Role string `json:"role,omitempty"` - Scriptsversion string `json:"scriptsversion,omitempty"` - Serviceofferingid string `json:"serviceofferingid,omitempty"` - Serviceofferingname string `json:"serviceofferingname,omitempty"` - State string `json:"state,omitempty"` - Templateid string `json:"templateid,omitempty"` - Version string `json:"version,omitempty"` - Vpcid string `json:"vpcid,omitempty"` - Vpcname string `json:"vpcname,omitempty"` - Zoneid string `json:"zoneid,omitempty"` - Zonename string `json:"zonename,omitempty"` + Account string `json:"account"` + Created string `json:"created"` + Dns1 string `json:"dns1"` + Dns2 string `json:"dns2"` + Domain string `json:"domain"` + Domainid string `json:"domainid"` + Gateway string `json:"gateway"` + Guestipaddress string `json:"guestipaddress"` + Guestmacaddress string `json:"guestmacaddress"` + Guestnetmask string `json:"guestnetmask"` + Guestnetworkid string `json:"guestnetworkid"` + Guestnetworkname string `json:"guestnetworkname"` + Hostid string `json:"hostid"` + Hostname string `json:"hostname"` + Hypervisor string `json:"hypervisor"` + Id string `json:"id"` + Ip6dns1 string `json:"ip6dns1"` + Ip6dns2 string `json:"ip6dns2"` + Isredundantrouter bool `json:"isredundantrouter"` + Linklocalip string `json:"linklocalip"` + Linklocalmacaddress string `json:"linklocalmacaddress"` + Linklocalnetmask string `json:"linklocalnetmask"` + Linklocalnetworkid string `json:"linklocalnetworkid"` + Name string `json:"name"` + Networkdomain string `json:"networkdomain"` + Nic []Nic `json:"nic"` + Podid string `json:"podid"` + Project string `json:"project"` + Projectid string `json:"projectid"` + Publicip string `json:"publicip"` + Publicmacaddress string `json:"publicmacaddress"` + Publicnetmask string `json:"publicnetmask"` + Publicnetworkid string `json:"publicnetworkid"` + Redundantstate string `json:"redundantstate"` + Requiresupgrade bool `json:"requiresupgrade"` + Role string `json:"role"` + Scriptsversion string `json:"scriptsversion"` + Serviceofferingid string `json:"serviceofferingid"` + Serviceofferingname string `json:"serviceofferingname"` + State string `json:"state"` + Templateid string `json:"templateid"` + Version string `json:"version"` + Vpcid string `json:"vpcid"` + Vpcname string `json:"vpcname"` + Zoneid string `json:"zoneid"` + Zonename string `json:"zonename"` } type ListVirtualRouterElementsParams struct { @@ -1220,7 +913,7 @@ func (s *RouterService) GetVirtualRouterElementByID(id string, opts ...OptionFun p.p["id"] = id - for _, fn := range opts { + for _, fn := range append(s.cs.options, opts...) { if err := fn(s.cs, p); err != nil { return nil, -1, err } @@ -1257,6 +950,7 @@ func (s *RouterService) ListVirtualRouterElements(p *ListVirtualRouterElementsPa if err := json.Unmarshal(resp, &r); err != nil { return nil, err } + return &r, nil } @@ -1266,44 +960,32 @@ type ListVirtualRouterElementsResponse struct { } type VirtualRouterElement struct { - Account string `json:"account,omitempty"` - Domain string `json:"domain,omitempty"` - Domainid string `json:"domainid,omitempty"` - Enabled bool `json:"enabled,omitempty"` - Id string `json:"id,omitempty"` - Nspid string `json:"nspid,omitempty"` - Project string `json:"project,omitempty"` - Projectid string `json:"projectid,omitempty"` + Account string `json:"account"` + Domain string `json:"domain"` + Domainid string `json:"domainid"` + Enabled bool `json:"enabled"` + Id string `json:"id"` + Nspid string `json:"nspid"` + Project string `json:"project"` + Projectid string `json:"projectid"` } -type ConfigureVirtualRouterElementParams struct { +type RebootRouterParams struct { p map[string]interface{} } -func (p *ConfigureVirtualRouterElementParams) toURLValues() url.Values { +func (p *RebootRouterParams) toURLValues() url.Values { u := url.Values{} if p.p == nil { return u } - if v, found := p.p["enabled"]; found { - vv := strconv.FormatBool(v.(bool)) - u.Set("enabled", vv) - } if v, found := p.p["id"]; found { u.Set("id", v.(string)) } return u } -func (p *ConfigureVirtualRouterElementParams) SetEnabled(v bool) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["enabled"] = v - return -} - -func (p *ConfigureVirtualRouterElementParams) SetId(v string) { +func (p *RebootRouterParams) SetId(v string) { if p.p == nil { p.p = make(map[string]interface{}) } @@ -1311,24 +993,23 @@ func (p *ConfigureVirtualRouterElementParams) SetId(v string) { return } -// You should always use this function to get a new ConfigureVirtualRouterElementParams instance, +// You should always use this function to get a new RebootRouterParams instance, // as then you are sure you have configured all required params -func (s *RouterService) NewConfigureVirtualRouterElementParams(enabled bool, id string) *ConfigureVirtualRouterElementParams { - p := &ConfigureVirtualRouterElementParams{} +func (s *RouterService) NewRebootRouterParams(id string) *RebootRouterParams { + p := &RebootRouterParams{} p.p = make(map[string]interface{}) - p.p["enabled"] = enabled p.p["id"] = id return p } -// Configures a virtual router element. -func (s *RouterService) ConfigureVirtualRouterElement(p *ConfigureVirtualRouterElementParams) (*ConfigureVirtualRouterElementResponse, error) { - resp, err := s.cs.newRequest("configureVirtualRouterElement", p.toURLValues()) +// Starts a router. +func (s *RouterService) RebootRouter(p *RebootRouterParams) (*RebootRouterResponse, error) { + resp, err := s.cs.newRequest("rebootRouter", p.toURLValues()) if err != nil { return nil, err } - var r ConfigureVirtualRouterElementResponse + var r RebootRouterResponse if err := json.Unmarshal(resp, &r); err != nil { return nil, err } @@ -1352,72 +1033,100 @@ func (s *RouterService) ConfigureVirtualRouterElement(p *ConfigureVirtualRouterE return nil, err } } + return &r, nil } -type ConfigureVirtualRouterElementResponse struct { - JobID string `json:"jobid,omitempty"` - Account string `json:"account,omitempty"` - Domain string `json:"domain,omitempty"` - Domainid string `json:"domainid,omitempty"` - Enabled bool `json:"enabled,omitempty"` - Id string `json:"id,omitempty"` - Nspid string `json:"nspid,omitempty"` - Project string `json:"project,omitempty"` - Projectid string `json:"projectid,omitempty"` +type RebootRouterResponse struct { + JobID string `json:"jobid"` + Account string `json:"account"` + Created string `json:"created"` + Dns1 string `json:"dns1"` + Dns2 string `json:"dns2"` + Domain string `json:"domain"` + Domainid string `json:"domainid"` + Gateway string `json:"gateway"` + Guestipaddress string `json:"guestipaddress"` + Guestmacaddress string `json:"guestmacaddress"` + Guestnetmask string `json:"guestnetmask"` + Guestnetworkid string `json:"guestnetworkid"` + Guestnetworkname string `json:"guestnetworkname"` + Hostid string `json:"hostid"` + Hostname string `json:"hostname"` + Hypervisor string `json:"hypervisor"` + Id string `json:"id"` + Ip6dns1 string `json:"ip6dns1"` + Ip6dns2 string `json:"ip6dns2"` + Isredundantrouter bool `json:"isredundantrouter"` + Linklocalip string `json:"linklocalip"` + Linklocalmacaddress string `json:"linklocalmacaddress"` + Linklocalnetmask string `json:"linklocalnetmask"` + Linklocalnetworkid string `json:"linklocalnetworkid"` + Name string `json:"name"` + Networkdomain string `json:"networkdomain"` + Nic []Nic `json:"nic"` + Podid string `json:"podid"` + Project string `json:"project"` + Projectid string `json:"projectid"` + Publicip string `json:"publicip"` + Publicmacaddress string `json:"publicmacaddress"` + Publicnetmask string `json:"publicnetmask"` + Publicnetworkid string `json:"publicnetworkid"` + Redundantstate string `json:"redundantstate"` + Requiresupgrade bool `json:"requiresupgrade"` + Role string `json:"role"` + Scriptsversion string `json:"scriptsversion"` + Serviceofferingid string `json:"serviceofferingid"` + Serviceofferingname string `json:"serviceofferingname"` + State string `json:"state"` + Templateid string `json:"templateid"` + Version string `json:"version"` + Vpcid string `json:"vpcid"` + Vpcname string `json:"vpcname"` + Zoneid string `json:"zoneid"` + Zonename string `json:"zonename"` } -type CreateVirtualRouterElementParams struct { +type StartRouterParams struct { p map[string]interface{} } -func (p *CreateVirtualRouterElementParams) toURLValues() url.Values { +func (p *StartRouterParams) toURLValues() url.Values { u := url.Values{} if p.p == nil { return u } - if v, found := p.p["nspid"]; found { - u.Set("nspid", v.(string)) - } - if v, found := p.p["providertype"]; found { - u.Set("providertype", v.(string)) + if v, found := p.p["id"]; found { + u.Set("id", v.(string)) } return u } -func (p *CreateVirtualRouterElementParams) SetNspid(v string) { +func (p *StartRouterParams) SetId(v string) { if p.p == nil { p.p = make(map[string]interface{}) } - p.p["nspid"] = v + p.p["id"] = v return } -func (p *CreateVirtualRouterElementParams) SetProvidertype(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["providertype"] = v - return -} - -// You should always use this function to get a new CreateVirtualRouterElementParams instance, +// You should always use this function to get a new StartRouterParams instance, // as then you are sure you have configured all required params -func (s *RouterService) NewCreateVirtualRouterElementParams(nspid string) *CreateVirtualRouterElementParams { - p := &CreateVirtualRouterElementParams{} +func (s *RouterService) NewStartRouterParams(id string) *StartRouterParams { + p := &StartRouterParams{} p.p = make(map[string]interface{}) - p.p["nspid"] = nspid + p.p["id"] = id return p } -// Create a virtual router element. -func (s *RouterService) CreateVirtualRouterElement(p *CreateVirtualRouterElementParams) (*CreateVirtualRouterElementResponse, error) { - resp, err := s.cs.newRequest("createVirtualRouterElement", p.toURLValues()) +// Starts a router. +func (s *RouterService) StartRouter(p *StartRouterParams) (*StartRouterResponse, error) { + resp, err := s.cs.newRequest("startRouter", p.toURLValues()) if err != nil { return nil, err } - var r CreateVirtualRouterElementResponse + var r StartRouterResponse if err := json.Unmarshal(resp, &r); err != nil { return nil, err } @@ -1441,17 +1150,185 @@ func (s *RouterService) CreateVirtualRouterElement(p *CreateVirtualRouterElement return nil, err } } + return &r, nil } -type CreateVirtualRouterElementResponse struct { - JobID string `json:"jobid,omitempty"` - Account string `json:"account,omitempty"` - Domain string `json:"domain,omitempty"` - Domainid string `json:"domainid,omitempty"` - Enabled bool `json:"enabled,omitempty"` - Id string `json:"id,omitempty"` - Nspid string `json:"nspid,omitempty"` - Project string `json:"project,omitempty"` - Projectid string `json:"projectid,omitempty"` +type StartRouterResponse struct { + JobID string `json:"jobid"` + Account string `json:"account"` + Created string `json:"created"` + Dns1 string `json:"dns1"` + Dns2 string `json:"dns2"` + Domain string `json:"domain"` + Domainid string `json:"domainid"` + Gateway string `json:"gateway"` + Guestipaddress string `json:"guestipaddress"` + Guestmacaddress string `json:"guestmacaddress"` + Guestnetmask string `json:"guestnetmask"` + Guestnetworkid string `json:"guestnetworkid"` + Guestnetworkname string `json:"guestnetworkname"` + Hostid string `json:"hostid"` + Hostname string `json:"hostname"` + Hypervisor string `json:"hypervisor"` + Id string `json:"id"` + Ip6dns1 string `json:"ip6dns1"` + Ip6dns2 string `json:"ip6dns2"` + Isredundantrouter bool `json:"isredundantrouter"` + Linklocalip string `json:"linklocalip"` + Linklocalmacaddress string `json:"linklocalmacaddress"` + Linklocalnetmask string `json:"linklocalnetmask"` + Linklocalnetworkid string `json:"linklocalnetworkid"` + Name string `json:"name"` + Networkdomain string `json:"networkdomain"` + Nic []Nic `json:"nic"` + Podid string `json:"podid"` + Project string `json:"project"` + Projectid string `json:"projectid"` + Publicip string `json:"publicip"` + Publicmacaddress string `json:"publicmacaddress"` + Publicnetmask string `json:"publicnetmask"` + Publicnetworkid string `json:"publicnetworkid"` + Redundantstate string `json:"redundantstate"` + Requiresupgrade bool `json:"requiresupgrade"` + Role string `json:"role"` + Scriptsversion string `json:"scriptsversion"` + Serviceofferingid string `json:"serviceofferingid"` + Serviceofferingname string `json:"serviceofferingname"` + State string `json:"state"` + Templateid string `json:"templateid"` + Version string `json:"version"` + Vpcid string `json:"vpcid"` + Vpcname string `json:"vpcname"` + Zoneid string `json:"zoneid"` + Zonename string `json:"zonename"` +} + +type StopRouterParams struct { + p map[string]interface{} +} + +func (p *StopRouterParams) toURLValues() url.Values { + u := url.Values{} + if p.p == nil { + return u + } + if v, found := p.p["forced"]; found { + vv := strconv.FormatBool(v.(bool)) + u.Set("forced", vv) + } + if v, found := p.p["id"]; found { + u.Set("id", v.(string)) + } + return u +} + +func (p *StopRouterParams) SetForced(v bool) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["forced"] = v + return +} + +func (p *StopRouterParams) SetId(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["id"] = v + return +} + +// You should always use this function to get a new StopRouterParams instance, +// as then you are sure you have configured all required params +func (s *RouterService) NewStopRouterParams(id string) *StopRouterParams { + p := &StopRouterParams{} + p.p = make(map[string]interface{}) + p.p["id"] = id + return p +} + +// Stops a router. +func (s *RouterService) StopRouter(p *StopRouterParams) (*StopRouterResponse, error) { + resp, err := s.cs.newRequest("stopRouter", p.toURLValues()) + if err != nil { + return nil, err + } + + var r StopRouterResponse + if err := json.Unmarshal(resp, &r); err != nil { + return nil, err + } + + // If we have a async client, we need to wait for the async result + if s.cs.async { + b, err := s.cs.GetAsyncJobResult(r.JobID, s.cs.timeout) + if err != nil { + if err == AsyncTimeoutErr { + return &r, err + } + return nil, err + } + + b, err = getRawValue(b) + if err != nil { + return nil, err + } + + if err := json.Unmarshal(b, &r); err != nil { + return nil, err + } + } + + return &r, nil +} + +type StopRouterResponse struct { + JobID string `json:"jobid"` + Account string `json:"account"` + Created string `json:"created"` + Dns1 string `json:"dns1"` + Dns2 string `json:"dns2"` + Domain string `json:"domain"` + Domainid string `json:"domainid"` + Gateway string `json:"gateway"` + Guestipaddress string `json:"guestipaddress"` + Guestmacaddress string `json:"guestmacaddress"` + Guestnetmask string `json:"guestnetmask"` + Guestnetworkid string `json:"guestnetworkid"` + Guestnetworkname string `json:"guestnetworkname"` + Hostid string `json:"hostid"` + Hostname string `json:"hostname"` + Hypervisor string `json:"hypervisor"` + Id string `json:"id"` + Ip6dns1 string `json:"ip6dns1"` + Ip6dns2 string `json:"ip6dns2"` + Isredundantrouter bool `json:"isredundantrouter"` + Linklocalip string `json:"linklocalip"` + Linklocalmacaddress string `json:"linklocalmacaddress"` + Linklocalnetmask string `json:"linklocalnetmask"` + Linklocalnetworkid string `json:"linklocalnetworkid"` + Name string `json:"name"` + Networkdomain string `json:"networkdomain"` + Nic []Nic `json:"nic"` + Podid string `json:"podid"` + Project string `json:"project"` + Projectid string `json:"projectid"` + Publicip string `json:"publicip"` + Publicmacaddress string `json:"publicmacaddress"` + Publicnetmask string `json:"publicnetmask"` + Publicnetworkid string `json:"publicnetworkid"` + Redundantstate string `json:"redundantstate"` + Requiresupgrade bool `json:"requiresupgrade"` + Role string `json:"role"` + Scriptsversion string `json:"scriptsversion"` + Serviceofferingid string `json:"serviceofferingid"` + Serviceofferingname string `json:"serviceofferingname"` + State string `json:"state"` + Templateid string `json:"templateid"` + Version string `json:"version"` + Vpcid string `json:"vpcid"` + Vpcname string `json:"vpcname"` + Zoneid string `json:"zoneid"` + Zonename string `json:"zonename"` } diff --git a/vendor/github.com/xanzy/go-cloudstack/cloudstack/SSHService.go b/vendor/github.com/xanzy/go-cloudstack/cloudstack/SSHService.go index 2221a5921..f1f4ab48f 100644 --- a/vendor/github.com/xanzy/go-cloudstack/cloudstack/SSHService.go +++ b/vendor/github.com/xanzy/go-cloudstack/cloudstack/SSHService.go @@ -1,5 +1,5 @@ // -// Copyright 2016, Sander van Harmelen +// Copyright 2018, Sander van Harmelen // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -22,397 +22,6 @@ import ( "strconv" ) -type ResetSSHKeyForVirtualMachineParams struct { - p map[string]interface{} -} - -func (p *ResetSSHKeyForVirtualMachineParams) toURLValues() url.Values { - u := url.Values{} - if p.p == nil { - return u - } - if v, found := p.p["account"]; found { - u.Set("account", v.(string)) - } - if v, found := p.p["domainid"]; found { - u.Set("domainid", v.(string)) - } - if v, found := p.p["id"]; found { - u.Set("id", v.(string)) - } - if v, found := p.p["keypair"]; found { - u.Set("keypair", v.(string)) - } - if v, found := p.p["projectid"]; found { - u.Set("projectid", v.(string)) - } - return u -} - -func (p *ResetSSHKeyForVirtualMachineParams) SetAccount(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["account"] = v - return -} - -func (p *ResetSSHKeyForVirtualMachineParams) SetDomainid(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["domainid"] = v - return -} - -func (p *ResetSSHKeyForVirtualMachineParams) SetId(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["id"] = v - return -} - -func (p *ResetSSHKeyForVirtualMachineParams) SetKeypair(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["keypair"] = v - return -} - -func (p *ResetSSHKeyForVirtualMachineParams) SetProjectid(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["projectid"] = v - return -} - -// You should always use this function to get a new ResetSSHKeyForVirtualMachineParams instance, -// as then you are sure you have configured all required params -func (s *SSHService) NewResetSSHKeyForVirtualMachineParams(id string, keypair string) *ResetSSHKeyForVirtualMachineParams { - p := &ResetSSHKeyForVirtualMachineParams{} - p.p = make(map[string]interface{}) - p.p["id"] = id - p.p["keypair"] = keypair - return p -} - -// Resets the SSH Key for virtual machine. The virtual machine must be in a "Stopped" state. [async] -func (s *SSHService) ResetSSHKeyForVirtualMachine(p *ResetSSHKeyForVirtualMachineParams) (*ResetSSHKeyForVirtualMachineResponse, error) { - resp, err := s.cs.newRequest("resetSSHKeyForVirtualMachine", p.toURLValues()) - if err != nil { - return nil, err - } - - var r ResetSSHKeyForVirtualMachineResponse - if err := json.Unmarshal(resp, &r); err != nil { - return nil, err - } - - // If we have a async client, we need to wait for the async result - if s.cs.async { - b, err := s.cs.GetAsyncJobResult(r.JobID, s.cs.timeout) - if err != nil { - if err == AsyncTimeoutErr { - return &r, err - } - return nil, err - } - - b, err = getRawValue(b) - if err != nil { - return nil, err - } - - if err := json.Unmarshal(b, &r); err != nil { - return nil, err - } - } - return &r, nil -} - -type ResetSSHKeyForVirtualMachineResponse struct { - JobID string `json:"jobid,omitempty"` - Account string `json:"account,omitempty"` - Affinitygroup []struct { - Account string `json:"account,omitempty"` - Description string `json:"description,omitempty"` - Domain string `json:"domain,omitempty"` - Domainid string `json:"domainid,omitempty"` - Id string `json:"id,omitempty"` - Name string `json:"name,omitempty"` - Project string `json:"project,omitempty"` - Projectid string `json:"projectid,omitempty"` - Type string `json:"type,omitempty"` - VirtualmachineIds []string `json:"virtualmachineIds,omitempty"` - } `json:"affinitygroup,omitempty"` - Cpunumber int `json:"cpunumber,omitempty"` - Cpuspeed int `json:"cpuspeed,omitempty"` - Cpuused string `json:"cpuused,omitempty"` - Created string `json:"created,omitempty"` - Details map[string]string `json:"details,omitempty"` - Diskioread int64 `json:"diskioread,omitempty"` - Diskiowrite int64 `json:"diskiowrite,omitempty"` - Diskkbsread int64 `json:"diskkbsread,omitempty"` - Diskkbswrite int64 `json:"diskkbswrite,omitempty"` - Diskofferingid string `json:"diskofferingid,omitempty"` - Diskofferingname string `json:"diskofferingname,omitempty"` - Displayname string `json:"displayname,omitempty"` - Displayvm bool `json:"displayvm,omitempty"` - Domain string `json:"domain,omitempty"` - Domainid string `json:"domainid,omitempty"` - Forvirtualnetwork bool `json:"forvirtualnetwork,omitempty"` - Group string `json:"group,omitempty"` - Groupid string `json:"groupid,omitempty"` - Guestosid string `json:"guestosid,omitempty"` - Haenable bool `json:"haenable,omitempty"` - Hostid string `json:"hostid,omitempty"` - Hostname string `json:"hostname,omitempty"` - Hypervisor string `json:"hypervisor,omitempty"` - Id string `json:"id,omitempty"` - Instancename string `json:"instancename,omitempty"` - Isdynamicallyscalable bool `json:"isdynamicallyscalable,omitempty"` - Isodisplaytext string `json:"isodisplaytext,omitempty"` - Isoid string `json:"isoid,omitempty"` - Isoname string `json:"isoname,omitempty"` - Keypair string `json:"keypair,omitempty"` - Memory int `json:"memory,omitempty"` - Name string `json:"name,omitempty"` - Networkkbsread int64 `json:"networkkbsread,omitempty"` - Networkkbswrite int64 `json:"networkkbswrite,omitempty"` - Nic []struct { - Broadcasturi string `json:"broadcasturi,omitempty"` - Deviceid string `json:"deviceid,omitempty"` - Gateway string `json:"gateway,omitempty"` - Id string `json:"id,omitempty"` - Ip6address string `json:"ip6address,omitempty"` - Ip6cidr string `json:"ip6cidr,omitempty"` - Ip6gateway string `json:"ip6gateway,omitempty"` - Ipaddress string `json:"ipaddress,omitempty"` - Isdefault bool `json:"isdefault,omitempty"` - Isolationuri string `json:"isolationuri,omitempty"` - Macaddress string `json:"macaddress,omitempty"` - Netmask string `json:"netmask,omitempty"` - Networkid string `json:"networkid,omitempty"` - Networkname string `json:"networkname,omitempty"` - Secondaryip []struct { - Id string `json:"id,omitempty"` - Ipaddress string `json:"ipaddress,omitempty"` - } `json:"secondaryip,omitempty"` - Traffictype string `json:"traffictype,omitempty"` - Type string `json:"type,omitempty"` - Virtualmachineid string `json:"virtualmachineid,omitempty"` - } `json:"nic,omitempty"` - Ostypeid int64 `json:"ostypeid,omitempty"` - Password string `json:"password,omitempty"` - Passwordenabled bool `json:"passwordenabled,omitempty"` - Project string `json:"project,omitempty"` - Projectid string `json:"projectid,omitempty"` - Publicip string `json:"publicip,omitempty"` - Publicipid string `json:"publicipid,omitempty"` - Rootdeviceid int64 `json:"rootdeviceid,omitempty"` - Rootdevicetype string `json:"rootdevicetype,omitempty"` - Securitygroup []struct { - Account string `json:"account,omitempty"` - Description string `json:"description,omitempty"` - Domain string `json:"domain,omitempty"` - Domainid string `json:"domainid,omitempty"` - Egressrule []struct { - Account string `json:"account,omitempty"` - Cidr string `json:"cidr,omitempty"` - Endport int `json:"endport,omitempty"` - Icmpcode int `json:"icmpcode,omitempty"` - Icmptype int `json:"icmptype,omitempty"` - Protocol string `json:"protocol,omitempty"` - Ruleid string `json:"ruleid,omitempty"` - Securitygroupname string `json:"securitygroupname,omitempty"` - Startport int `json:"startport,omitempty"` - Tags []struct { - Account string `json:"account,omitempty"` - Customer string `json:"customer,omitempty"` - Domain string `json:"domain,omitempty"` - Domainid string `json:"domainid,omitempty"` - Key string `json:"key,omitempty"` - Project string `json:"project,omitempty"` - Projectid string `json:"projectid,omitempty"` - Resourceid string `json:"resourceid,omitempty"` - Resourcetype string `json:"resourcetype,omitempty"` - Value string `json:"value,omitempty"` - } `json:"tags,omitempty"` - } `json:"egressrule,omitempty"` - Id string `json:"id,omitempty"` - Ingressrule []struct { - Account string `json:"account,omitempty"` - Cidr string `json:"cidr,omitempty"` - Endport int `json:"endport,omitempty"` - Icmpcode int `json:"icmpcode,omitempty"` - Icmptype int `json:"icmptype,omitempty"` - Protocol string `json:"protocol,omitempty"` - Ruleid string `json:"ruleid,omitempty"` - Securitygroupname string `json:"securitygroupname,omitempty"` - Startport int `json:"startport,omitempty"` - Tags []struct { - Account string `json:"account,omitempty"` - Customer string `json:"customer,omitempty"` - Domain string `json:"domain,omitempty"` - Domainid string `json:"domainid,omitempty"` - Key string `json:"key,omitempty"` - Project string `json:"project,omitempty"` - Projectid string `json:"projectid,omitempty"` - Resourceid string `json:"resourceid,omitempty"` - Resourcetype string `json:"resourcetype,omitempty"` - Value string `json:"value,omitempty"` - } `json:"tags,omitempty"` - } `json:"ingressrule,omitempty"` - Name string `json:"name,omitempty"` - Project string `json:"project,omitempty"` - Projectid string `json:"projectid,omitempty"` - Tags []struct { - Account string `json:"account,omitempty"` - Customer string `json:"customer,omitempty"` - Domain string `json:"domain,omitempty"` - Domainid string `json:"domainid,omitempty"` - Key string `json:"key,omitempty"` - Project string `json:"project,omitempty"` - Projectid string `json:"projectid,omitempty"` - Resourceid string `json:"resourceid,omitempty"` - Resourcetype string `json:"resourcetype,omitempty"` - Value string `json:"value,omitempty"` - } `json:"tags,omitempty"` - Virtualmachinecount int `json:"virtualmachinecount,omitempty"` - Virtualmachineids []string `json:"virtualmachineids,omitempty"` - } `json:"securitygroup,omitempty"` - Serviceofferingid string `json:"serviceofferingid,omitempty"` - Serviceofferingname string `json:"serviceofferingname,omitempty"` - Servicestate string `json:"servicestate,omitempty"` - State string `json:"state,omitempty"` - Tags []struct { - Account string `json:"account,omitempty"` - Customer string `json:"customer,omitempty"` - Domain string `json:"domain,omitempty"` - Domainid string `json:"domainid,omitempty"` - Key string `json:"key,omitempty"` - Project string `json:"project,omitempty"` - Projectid string `json:"projectid,omitempty"` - Resourceid string `json:"resourceid,omitempty"` - Resourcetype string `json:"resourcetype,omitempty"` - Value string `json:"value,omitempty"` - } `json:"tags,omitempty"` - Templatedisplaytext string `json:"templatedisplaytext,omitempty"` - Templateid string `json:"templateid,omitempty"` - Templatename string `json:"templatename,omitempty"` - Userid string `json:"userid,omitempty"` - Username string `json:"username,omitempty"` - Vgpu string `json:"vgpu,omitempty"` - Zoneid string `json:"zoneid,omitempty"` - Zonename string `json:"zonename,omitempty"` -} - -type RegisterSSHKeyPairParams struct { - p map[string]interface{} -} - -func (p *RegisterSSHKeyPairParams) toURLValues() url.Values { - u := url.Values{} - if p.p == nil { - return u - } - if v, found := p.p["account"]; found { - u.Set("account", v.(string)) - } - if v, found := p.p["domainid"]; found { - u.Set("domainid", v.(string)) - } - if v, found := p.p["name"]; found { - u.Set("name", v.(string)) - } - if v, found := p.p["projectid"]; found { - u.Set("projectid", v.(string)) - } - if v, found := p.p["publickey"]; found { - u.Set("publickey", v.(string)) - } - return u -} - -func (p *RegisterSSHKeyPairParams) SetAccount(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["account"] = v - return -} - -func (p *RegisterSSHKeyPairParams) SetDomainid(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["domainid"] = v - return -} - -func (p *RegisterSSHKeyPairParams) SetName(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["name"] = v - return -} - -func (p *RegisterSSHKeyPairParams) SetProjectid(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["projectid"] = v - return -} - -func (p *RegisterSSHKeyPairParams) SetPublickey(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["publickey"] = v - return -} - -// You should always use this function to get a new RegisterSSHKeyPairParams instance, -// as then you are sure you have configured all required params -func (s *SSHService) NewRegisterSSHKeyPairParams(name string, publickey string) *RegisterSSHKeyPairParams { - p := &RegisterSSHKeyPairParams{} - p.p = make(map[string]interface{}) - p.p["name"] = name - p.p["publickey"] = publickey - return p -} - -// Register a public key in a keypair under a certain name -func (s *SSHService) RegisterSSHKeyPair(p *RegisterSSHKeyPairParams) (*RegisterSSHKeyPairResponse, error) { - resp, err := s.cs.newRequest("registerSSHKeyPair", p.toURLValues()) - if err != nil { - return nil, err - } - - if resp, err = getRawValue(resp); err != nil { - return nil, err - } - - var r RegisterSSHKeyPairResponse - if err := json.Unmarshal(resp, &r); err != nil { - return nil, err - } - return &r, nil -} - -type RegisterSSHKeyPairResponse struct { - Account string `json:"account,omitempty"` - Domain string `json:"domain,omitempty"` - Domainid string `json:"domainid,omitempty"` - Fingerprint string `json:"fingerprint,omitempty"` - Name string `json:"name,omitempty"` -} - type CreateSSHKeyPairParams struct { p map[string]interface{} } @@ -493,11 +102,12 @@ func (s *SSHService) CreateSSHKeyPair(p *CreateSSHKeyPairParams) (*CreateSSHKeyP if err := json.Unmarshal(resp, &r); err != nil { return nil, err } + return &r, nil } type CreateSSHKeyPairResponse struct { - Privatekey string `json:"privatekey,omitempty"` + Privatekey string `json:"privatekey"` } type DeleteSSHKeyPairParams struct { @@ -576,12 +186,32 @@ func (s *SSHService) DeleteSSHKeyPair(p *DeleteSSHKeyPairParams) (*DeleteSSHKeyP if err := json.Unmarshal(resp, &r); err != nil { return nil, err } + return &r, nil } type DeleteSSHKeyPairResponse struct { - Displaytext string `json:"displaytext,omitempty"` - Success string `json:"success,omitempty"` + Displaytext string `json:"displaytext"` + Success bool `json:"success"` +} + +func (r *DeleteSSHKeyPairResponse) UnmarshalJSON(b []byte) error { + var m map[string]interface{} + err := json.Unmarshal(b, &m) + if err != nil { + return err + } + + if success, ok := m["success"].(string); ok { + m["success"] = success == "true" + b, err = json.Marshal(m) + if err != nil { + return err + } + } + + type alias DeleteSSHKeyPairResponse + return json.Unmarshal(b, (*alias)(r)) } type ListSSHKeyPairsParams struct { @@ -729,6 +359,7 @@ func (s *SSHService) ListSSHKeyPairs(p *ListSSHKeyPairsParams) (*ListSSHKeyPairs if err := json.Unmarshal(resp, &r); err != nil { return nil, err } + return &r, nil } @@ -738,9 +369,333 @@ type ListSSHKeyPairsResponse struct { } type SSHKeyPair struct { - Account string `json:"account,omitempty"` - Domain string `json:"domain,omitempty"` - Domainid string `json:"domainid,omitempty"` - Fingerprint string `json:"fingerprint,omitempty"` - Name string `json:"name,omitempty"` + Account string `json:"account"` + Domain string `json:"domain"` + Domainid string `json:"domainid"` + Fingerprint string `json:"fingerprint"` + Name string `json:"name"` +} + +type RegisterSSHKeyPairParams struct { + p map[string]interface{} +} + +func (p *RegisterSSHKeyPairParams) toURLValues() url.Values { + u := url.Values{} + if p.p == nil { + return u + } + if v, found := p.p["account"]; found { + u.Set("account", v.(string)) + } + if v, found := p.p["domainid"]; found { + u.Set("domainid", v.(string)) + } + if v, found := p.p["name"]; found { + u.Set("name", v.(string)) + } + if v, found := p.p["projectid"]; found { + u.Set("projectid", v.(string)) + } + if v, found := p.p["publickey"]; found { + u.Set("publickey", v.(string)) + } + return u +} + +func (p *RegisterSSHKeyPairParams) SetAccount(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["account"] = v + return +} + +func (p *RegisterSSHKeyPairParams) SetDomainid(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["domainid"] = v + return +} + +func (p *RegisterSSHKeyPairParams) SetName(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["name"] = v + return +} + +func (p *RegisterSSHKeyPairParams) SetProjectid(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["projectid"] = v + return +} + +func (p *RegisterSSHKeyPairParams) SetPublickey(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["publickey"] = v + return +} + +// You should always use this function to get a new RegisterSSHKeyPairParams instance, +// as then you are sure you have configured all required params +func (s *SSHService) NewRegisterSSHKeyPairParams(name string, publickey string) *RegisterSSHKeyPairParams { + p := &RegisterSSHKeyPairParams{} + p.p = make(map[string]interface{}) + p.p["name"] = name + p.p["publickey"] = publickey + return p +} + +// Register a public key in a keypair under a certain name +func (s *SSHService) RegisterSSHKeyPair(p *RegisterSSHKeyPairParams) (*RegisterSSHKeyPairResponse, error) { + resp, err := s.cs.newRequest("registerSSHKeyPair", p.toURLValues()) + if err != nil { + return nil, err + } + + if resp, err = getRawValue(resp); err != nil { + return nil, err + } + + var r RegisterSSHKeyPairResponse + if err := json.Unmarshal(resp, &r); err != nil { + return nil, err + } + + return &r, nil +} + +type RegisterSSHKeyPairResponse struct { + Account string `json:"account"` + Domain string `json:"domain"` + Domainid string `json:"domainid"` + Fingerprint string `json:"fingerprint"` + Name string `json:"name"` +} + +type ResetSSHKeyForVirtualMachineParams struct { + p map[string]interface{} +} + +func (p *ResetSSHKeyForVirtualMachineParams) toURLValues() url.Values { + u := url.Values{} + if p.p == nil { + return u + } + if v, found := p.p["account"]; found { + u.Set("account", v.(string)) + } + if v, found := p.p["domainid"]; found { + u.Set("domainid", v.(string)) + } + if v, found := p.p["id"]; found { + u.Set("id", v.(string)) + } + if v, found := p.p["keypair"]; found { + u.Set("keypair", v.(string)) + } + if v, found := p.p["projectid"]; found { + u.Set("projectid", v.(string)) + } + return u +} + +func (p *ResetSSHKeyForVirtualMachineParams) SetAccount(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["account"] = v + return +} + +func (p *ResetSSHKeyForVirtualMachineParams) SetDomainid(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["domainid"] = v + return +} + +func (p *ResetSSHKeyForVirtualMachineParams) SetId(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["id"] = v + return +} + +func (p *ResetSSHKeyForVirtualMachineParams) SetKeypair(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["keypair"] = v + return +} + +func (p *ResetSSHKeyForVirtualMachineParams) SetProjectid(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["projectid"] = v + return +} + +// You should always use this function to get a new ResetSSHKeyForVirtualMachineParams instance, +// as then you are sure you have configured all required params +func (s *SSHService) NewResetSSHKeyForVirtualMachineParams(id string, keypair string) *ResetSSHKeyForVirtualMachineParams { + p := &ResetSSHKeyForVirtualMachineParams{} + p.p = make(map[string]interface{}) + p.p["id"] = id + p.p["keypair"] = keypair + return p +} + +// Resets the SSH Key for virtual machine. The virtual machine must be in a "Stopped" state. [async] +func (s *SSHService) ResetSSHKeyForVirtualMachine(p *ResetSSHKeyForVirtualMachineParams) (*ResetSSHKeyForVirtualMachineResponse, error) { + resp, err := s.cs.newRequest("resetSSHKeyForVirtualMachine", p.toURLValues()) + if err != nil { + return nil, err + } + + var r ResetSSHKeyForVirtualMachineResponse + if err := json.Unmarshal(resp, &r); err != nil { + return nil, err + } + + // If we have a async client, we need to wait for the async result + if s.cs.async { + b, err := s.cs.GetAsyncJobResult(r.JobID, s.cs.timeout) + if err != nil { + if err == AsyncTimeoutErr { + return &r, err + } + return nil, err + } + + b, err = getRawValue(b) + if err != nil { + return nil, err + } + + if err := json.Unmarshal(b, &r); err != nil { + return nil, err + } + } + + return &r, nil +} + +type ResetSSHKeyForVirtualMachineResponse struct { + JobID string `json:"jobid"` + Account string `json:"account"` + Affinitygroup []ResetSSHKeyForVirtualMachineResponseAffinitygroup `json:"affinitygroup"` + Cpunumber int `json:"cpunumber"` + Cpuspeed int `json:"cpuspeed"` + Cpuused string `json:"cpuused"` + Created string `json:"created"` + Details map[string]string `json:"details"` + Diskioread int64 `json:"diskioread"` + Diskiowrite int64 `json:"diskiowrite"` + Diskkbsread int64 `json:"diskkbsread"` + Diskkbswrite int64 `json:"diskkbswrite"` + Diskofferingid string `json:"diskofferingid"` + Diskofferingname string `json:"diskofferingname"` + Displayname string `json:"displayname"` + Displayvm bool `json:"displayvm"` + Domain string `json:"domain"` + Domainid string `json:"domainid"` + Forvirtualnetwork bool `json:"forvirtualnetwork"` + Group string `json:"group"` + Groupid string `json:"groupid"` + Guestosid string `json:"guestosid"` + Haenable bool `json:"haenable"` + Hostid string `json:"hostid"` + Hostname string `json:"hostname"` + Hypervisor string `json:"hypervisor"` + Id string `json:"id"` + Instancename string `json:"instancename"` + Isdynamicallyscalable bool `json:"isdynamicallyscalable"` + Isodisplaytext string `json:"isodisplaytext"` + Isoid string `json:"isoid"` + Isoname string `json:"isoname"` + Keypair string `json:"keypair"` + Memory int `json:"memory"` + Memoryintfreekbs int64 `json:"memoryintfreekbs"` + Memorykbs int64 `json:"memorykbs"` + Memorytargetkbs int64 `json:"memorytargetkbs"` + Name string `json:"name"` + Networkkbsread int64 `json:"networkkbsread"` + Networkkbswrite int64 `json:"networkkbswrite"` + Nic []Nic `json:"nic"` + Ostypeid int64 `json:"ostypeid"` + Password string `json:"password"` + Passwordenabled bool `json:"passwordenabled"` + Project string `json:"project"` + Projectid string `json:"projectid"` + Publicip string `json:"publicip"` + Publicipid string `json:"publicipid"` + Rootdeviceid int64 `json:"rootdeviceid"` + Rootdevicetype string `json:"rootdevicetype"` + Securitygroup []ResetSSHKeyForVirtualMachineResponseSecuritygroup `json:"securitygroup"` + Serviceofferingid string `json:"serviceofferingid"` + Serviceofferingname string `json:"serviceofferingname"` + Servicestate string `json:"servicestate"` + State string `json:"state"` + Templatedisplaytext string `json:"templatedisplaytext"` + Templateid string `json:"templateid"` + Templatename string `json:"templatename"` + Userid string `json:"userid"` + Username string `json:"username"` + Vgpu string `json:"vgpu"` + Zoneid string `json:"zoneid"` + Zonename string `json:"zonename"` +} + +type ResetSSHKeyForVirtualMachineResponseSecuritygroup struct { + Account string `json:"account"` + Description string `json:"description"` + Domain string `json:"domain"` + Domainid string `json:"domainid"` + Egressrule []ResetSSHKeyForVirtualMachineResponseSecuritygroupRule `json:"egressrule"` + Id string `json:"id"` + Ingressrule []ResetSSHKeyForVirtualMachineResponseSecuritygroupRule `json:"ingressrule"` + Name string `json:"name"` + Project string `json:"project"` + Projectid string `json:"projectid"` + Tags []Tags `json:"tags"` + Virtualmachinecount int `json:"virtualmachinecount"` + Virtualmachineids []interface{} `json:"virtualmachineids"` +} + +type ResetSSHKeyForVirtualMachineResponseSecuritygroupRule struct { + Account string `json:"account"` + Cidr string `json:"cidr"` + Endport int `json:"endport"` + Icmpcode int `json:"icmpcode"` + Icmptype int `json:"icmptype"` + Protocol string `json:"protocol"` + Ruleid string `json:"ruleid"` + Securitygroupname string `json:"securitygroupname"` + Startport int `json:"startport"` + Tags []Tags `json:"tags"` +} + +type ResetSSHKeyForVirtualMachineResponseAffinitygroup struct { + Account string `json:"account"` + Description string `json:"description"` + Domain string `json:"domain"` + Domainid string `json:"domainid"` + Id string `json:"id"` + Name string `json:"name"` + Project string `json:"project"` + Projectid string `json:"projectid"` + Type string `json:"type"` + VirtualmachineIds []string `json:"virtualmachineIds"` } diff --git a/vendor/github.com/xanzy/go-cloudstack/cloudstack/SecurityGroupService.go b/vendor/github.com/xanzy/go-cloudstack/cloudstack/SecurityGroupService.go index 4ca4e9bb2..125750474 100644 --- a/vendor/github.com/xanzy/go-cloudstack/cloudstack/SecurityGroupService.go +++ b/vendor/github.com/xanzy/go-cloudstack/cloudstack/SecurityGroupService.go @@ -1,5 +1,5 @@ // -// Copyright 2016, Sander van Harmelen +// Copyright 2018, Sander van Harmelen // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -24,551 +24,36 @@ import ( "strings" ) -type CreateSecurityGroupParams struct { - p map[string]interface{} -} - -func (p *CreateSecurityGroupParams) toURLValues() url.Values { - u := url.Values{} - if p.p == nil { - return u +// Helper function for maintaining backwards compatibility +func convertAuthorizeSecurityGroupIngressResponse(b []byte) ([]byte, error) { + var raw struct { + Ingressrule []interface{} `json:"ingressrule"` } - if v, found := p.p["account"]; found { - u.Set("account", v.(string)) - } - if v, found := p.p["description"]; found { - u.Set("description", v.(string)) - } - if v, found := p.p["domainid"]; found { - u.Set("domainid", v.(string)) - } - if v, found := p.p["name"]; found { - u.Set("name", v.(string)) - } - if v, found := p.p["projectid"]; found { - u.Set("projectid", v.(string)) - } - return u -} - -func (p *CreateSecurityGroupParams) SetAccount(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["account"] = v - return -} - -func (p *CreateSecurityGroupParams) SetDescription(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["description"] = v - return -} - -func (p *CreateSecurityGroupParams) SetDomainid(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["domainid"] = v - return -} - -func (p *CreateSecurityGroupParams) SetName(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["name"] = v - return -} - -func (p *CreateSecurityGroupParams) SetProjectid(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["projectid"] = v - return -} - -// You should always use this function to get a new CreateSecurityGroupParams instance, -// as then you are sure you have configured all required params -func (s *SecurityGroupService) NewCreateSecurityGroupParams(name string) *CreateSecurityGroupParams { - p := &CreateSecurityGroupParams{} - p.p = make(map[string]interface{}) - p.p["name"] = name - return p -} - -// Creates a security group -func (s *SecurityGroupService) CreateSecurityGroup(p *CreateSecurityGroupParams) (*CreateSecurityGroupResponse, error) { - resp, err := s.cs.newRequest("createSecurityGroup", p.toURLValues()) - if err != nil { + if err := json.Unmarshal(b, &raw); err != nil { return nil, err } - if resp, err = getRawValue(resp); err != nil { + if len(raw.Ingressrule) != 1 { + return b, nil + } + + return json.Marshal(raw.Ingressrule[0]) +} + +// Helper function for maintaining backwards compatibility +func convertAuthorizeSecurityGroupEgressResponse(b []byte) ([]byte, error) { + var raw struct { + Egressrule []interface{} `json:"egressrule"` + } + if err := json.Unmarshal(b, &raw); err != nil { return nil, err } - var r CreateSecurityGroupResponse - if err := json.Unmarshal(resp, &r); err != nil { - return nil, err - } - return &r, nil -} - -type CreateSecurityGroupResponse struct { - Account string `json:"account,omitempty"` - Description string `json:"description,omitempty"` - Domain string `json:"domain,omitempty"` - Domainid string `json:"domainid,omitempty"` - Egressrule []struct { - Account string `json:"account,omitempty"` - Cidr string `json:"cidr,omitempty"` - Endport int `json:"endport,omitempty"` - Icmpcode int `json:"icmpcode,omitempty"` - Icmptype int `json:"icmptype,omitempty"` - Protocol string `json:"protocol,omitempty"` - Ruleid string `json:"ruleid,omitempty"` - Securitygroupname string `json:"securitygroupname,omitempty"` - Startport int `json:"startport,omitempty"` - Tags []struct { - Account string `json:"account,omitempty"` - Customer string `json:"customer,omitempty"` - Domain string `json:"domain,omitempty"` - Domainid string `json:"domainid,omitempty"` - Key string `json:"key,omitempty"` - Project string `json:"project,omitempty"` - Projectid string `json:"projectid,omitempty"` - Resourceid string `json:"resourceid,omitempty"` - Resourcetype string `json:"resourcetype,omitempty"` - Value string `json:"value,omitempty"` - } `json:"tags,omitempty"` - } `json:"egressrule,omitempty"` - Id string `json:"id,omitempty"` - Ingressrule []struct { - Account string `json:"account,omitempty"` - Cidr string `json:"cidr,omitempty"` - Endport int `json:"endport,omitempty"` - Icmpcode int `json:"icmpcode,omitempty"` - Icmptype int `json:"icmptype,omitempty"` - Protocol string `json:"protocol,omitempty"` - Ruleid string `json:"ruleid,omitempty"` - Securitygroupname string `json:"securitygroupname,omitempty"` - Startport int `json:"startport,omitempty"` - Tags []struct { - Account string `json:"account,omitempty"` - Customer string `json:"customer,omitempty"` - Domain string `json:"domain,omitempty"` - Domainid string `json:"domainid,omitempty"` - Key string `json:"key,omitempty"` - Project string `json:"project,omitempty"` - Projectid string `json:"projectid,omitempty"` - Resourceid string `json:"resourceid,omitempty"` - Resourcetype string `json:"resourcetype,omitempty"` - Value string `json:"value,omitempty"` - } `json:"tags,omitempty"` - } `json:"ingressrule,omitempty"` - Name string `json:"name,omitempty"` - Project string `json:"project,omitempty"` - Projectid string `json:"projectid,omitempty"` - Tags []struct { - Account string `json:"account,omitempty"` - Customer string `json:"customer,omitempty"` - Domain string `json:"domain,omitempty"` - Domainid string `json:"domainid,omitempty"` - Key string `json:"key,omitempty"` - Project string `json:"project,omitempty"` - Projectid string `json:"projectid,omitempty"` - Resourceid string `json:"resourceid,omitempty"` - Resourcetype string `json:"resourcetype,omitempty"` - Value string `json:"value,omitempty"` - } `json:"tags,omitempty"` - Virtualmachinecount int `json:"virtualmachinecount,omitempty"` - Virtualmachineids []string `json:"virtualmachineids,omitempty"` -} - -type DeleteSecurityGroupParams struct { - p map[string]interface{} -} - -func (p *DeleteSecurityGroupParams) toURLValues() url.Values { - u := url.Values{} - if p.p == nil { - return u - } - if v, found := p.p["account"]; found { - u.Set("account", v.(string)) - } - if v, found := p.p["domainid"]; found { - u.Set("domainid", v.(string)) - } - if v, found := p.p["id"]; found { - u.Set("id", v.(string)) - } - if v, found := p.p["name"]; found { - u.Set("name", v.(string)) - } - if v, found := p.p["projectid"]; found { - u.Set("projectid", v.(string)) - } - return u -} - -func (p *DeleteSecurityGroupParams) SetAccount(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["account"] = v - return -} - -func (p *DeleteSecurityGroupParams) SetDomainid(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["domainid"] = v - return -} - -func (p *DeleteSecurityGroupParams) SetId(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["id"] = v - return -} - -func (p *DeleteSecurityGroupParams) SetName(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["name"] = v - return -} - -func (p *DeleteSecurityGroupParams) SetProjectid(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["projectid"] = v - return -} - -// You should always use this function to get a new DeleteSecurityGroupParams instance, -// as then you are sure you have configured all required params -func (s *SecurityGroupService) NewDeleteSecurityGroupParams() *DeleteSecurityGroupParams { - p := &DeleteSecurityGroupParams{} - p.p = make(map[string]interface{}) - return p -} - -// Deletes security group -func (s *SecurityGroupService) DeleteSecurityGroup(p *DeleteSecurityGroupParams) (*DeleteSecurityGroupResponse, error) { - resp, err := s.cs.newRequest("deleteSecurityGroup", p.toURLValues()) - if err != nil { - return nil, err + if len(raw.Egressrule) != 1 { + return b, nil } - var r DeleteSecurityGroupResponse - if err := json.Unmarshal(resp, &r); err != nil { - return nil, err - } - return &r, nil -} - -type DeleteSecurityGroupResponse struct { - Displaytext string `json:"displaytext,omitempty"` - Success string `json:"success,omitempty"` -} - -type AuthorizeSecurityGroupIngressParams struct { - p map[string]interface{} -} - -func (p *AuthorizeSecurityGroupIngressParams) toURLValues() url.Values { - u := url.Values{} - if p.p == nil { - return u - } - if v, found := p.p["account"]; found { - u.Set("account", v.(string)) - } - if v, found := p.p["cidrlist"]; found { - vv := strings.Join(v.([]string), ",") - u.Set("cidrlist", vv) - } - if v, found := p.p["domainid"]; found { - u.Set("domainid", v.(string)) - } - if v, found := p.p["endport"]; found { - vv := strconv.Itoa(v.(int)) - u.Set("endport", vv) - } - if v, found := p.p["icmpcode"]; found { - vv := strconv.Itoa(v.(int)) - u.Set("icmpcode", vv) - } - if v, found := p.p["icmptype"]; found { - vv := strconv.Itoa(v.(int)) - u.Set("icmptype", vv) - } - if v, found := p.p["projectid"]; found { - u.Set("projectid", v.(string)) - } - if v, found := p.p["protocol"]; found { - u.Set("protocol", v.(string)) - } - if v, found := p.p["securitygroupid"]; found { - u.Set("securitygroupid", v.(string)) - } - if v, found := p.p["securitygroupname"]; found { - u.Set("securitygroupname", v.(string)) - } - if v, found := p.p["startport"]; found { - vv := strconv.Itoa(v.(int)) - u.Set("startport", vv) - } - if v, found := p.p["usersecuritygrouplist"]; found { - i := 0 - for k, vv := range v.(map[string]string) { - u.Set(fmt.Sprintf("usersecuritygrouplist[%d].key", i), k) - u.Set(fmt.Sprintf("usersecuritygrouplist[%d].value", i), vv) - i++ - } - } - return u -} - -func (p *AuthorizeSecurityGroupIngressParams) SetAccount(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["account"] = v - return -} - -func (p *AuthorizeSecurityGroupIngressParams) SetCidrlist(v []string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["cidrlist"] = v - return -} - -func (p *AuthorizeSecurityGroupIngressParams) SetDomainid(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["domainid"] = v - return -} - -func (p *AuthorizeSecurityGroupIngressParams) SetEndport(v int) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["endport"] = v - return -} - -func (p *AuthorizeSecurityGroupIngressParams) SetIcmpcode(v int) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["icmpcode"] = v - return -} - -func (p *AuthorizeSecurityGroupIngressParams) SetIcmptype(v int) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["icmptype"] = v - return -} - -func (p *AuthorizeSecurityGroupIngressParams) SetProjectid(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["projectid"] = v - return -} - -func (p *AuthorizeSecurityGroupIngressParams) SetProtocol(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["protocol"] = v - return -} - -func (p *AuthorizeSecurityGroupIngressParams) SetSecuritygroupid(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["securitygroupid"] = v - return -} - -func (p *AuthorizeSecurityGroupIngressParams) SetSecuritygroupname(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["securitygroupname"] = v - return -} - -func (p *AuthorizeSecurityGroupIngressParams) SetStartport(v int) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["startport"] = v - return -} - -func (p *AuthorizeSecurityGroupIngressParams) SetUsersecuritygrouplist(v map[string]string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["usersecuritygrouplist"] = v - return -} - -// You should always use this function to get a new AuthorizeSecurityGroupIngressParams instance, -// as then you are sure you have configured all required params -func (s *SecurityGroupService) NewAuthorizeSecurityGroupIngressParams() *AuthorizeSecurityGroupIngressParams { - p := &AuthorizeSecurityGroupIngressParams{} - p.p = make(map[string]interface{}) - return p -} - -// Authorizes a particular ingress rule for this security group -func (s *SecurityGroupService) AuthorizeSecurityGroupIngress(p *AuthorizeSecurityGroupIngressParams) (*AuthorizeSecurityGroupIngressResponse, error) { - resp, err := s.cs.newRequest("authorizeSecurityGroupIngress", p.toURLValues()) - if err != nil { - return nil, err - } - - var r AuthorizeSecurityGroupIngressResponse - if err := json.Unmarshal(resp, &r); err != nil { - return nil, err - } - - // If we have a async client, we need to wait for the async result - if s.cs.async { - b, err := s.cs.GetAsyncJobResult(r.JobID, s.cs.timeout) - if err != nil { - if err == AsyncTimeoutErr { - return &r, err - } - return nil, err - } - - b, err = getRawValue(b) - if err != nil { - return nil, err - } - - if err := json.Unmarshal(b, &r); err != nil { - return nil, err - } - } - return &r, nil -} - -type AuthorizeSecurityGroupIngressResponse struct { - JobID string `json:"jobid,omitempty"` - Account string `json:"account,omitempty"` - Cidr string `json:"cidr,omitempty"` - Endport int `json:"endport,omitempty"` - Icmpcode int `json:"icmpcode,omitempty"` - Icmptype int `json:"icmptype,omitempty"` - Protocol string `json:"protocol,omitempty"` - Ruleid string `json:"ruleid,omitempty"` - Securitygroupname string `json:"securitygroupname,omitempty"` - Startport int `json:"startport,omitempty"` - Tags []struct { - Account string `json:"account,omitempty"` - Customer string `json:"customer,omitempty"` - Domain string `json:"domain,omitempty"` - Domainid string `json:"domainid,omitempty"` - Key string `json:"key,omitempty"` - Project string `json:"project,omitempty"` - Projectid string `json:"projectid,omitempty"` - Resourceid string `json:"resourceid,omitempty"` - Resourcetype string `json:"resourcetype,omitempty"` - Value string `json:"value,omitempty"` - } `json:"tags,omitempty"` -} - -type RevokeSecurityGroupIngressParams struct { - p map[string]interface{} -} - -func (p *RevokeSecurityGroupIngressParams) toURLValues() url.Values { - u := url.Values{} - if p.p == nil { - return u - } - if v, found := p.p["id"]; found { - u.Set("id", v.(string)) - } - return u -} - -func (p *RevokeSecurityGroupIngressParams) SetId(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["id"] = v - return -} - -// You should always use this function to get a new RevokeSecurityGroupIngressParams instance, -// as then you are sure you have configured all required params -func (s *SecurityGroupService) NewRevokeSecurityGroupIngressParams(id string) *RevokeSecurityGroupIngressParams { - p := &RevokeSecurityGroupIngressParams{} - p.p = make(map[string]interface{}) - p.p["id"] = id - return p -} - -// Deletes a particular ingress rule from this security group -func (s *SecurityGroupService) RevokeSecurityGroupIngress(p *RevokeSecurityGroupIngressParams) (*RevokeSecurityGroupIngressResponse, error) { - resp, err := s.cs.newRequest("revokeSecurityGroupIngress", p.toURLValues()) - if err != nil { - return nil, err - } - - var r RevokeSecurityGroupIngressResponse - if err := json.Unmarshal(resp, &r); err != nil { - return nil, err - } - - // If we have a async client, we need to wait for the async result - if s.cs.async { - b, err := s.cs.GetAsyncJobResult(r.JobID, s.cs.timeout) - if err != nil { - if err == AsyncTimeoutErr { - return &r, err - } - return nil, err - } - - if err := json.Unmarshal(b, &r); err != nil { - return nil, err - } - } - return &r, nil -} - -type RevokeSecurityGroupIngressResponse struct { - JobID string `json:"jobid,omitempty"` - Displaytext string `json:"displaytext,omitempty"` - Success bool `json:"success,omitempty"` + return json.Marshal(raw.Egressrule[0]) } type AuthorizeSecurityGroupEgressParams struct { @@ -621,8 +106,8 @@ func (p *AuthorizeSecurityGroupEgressParams) toURLValues() url.Values { if v, found := p.p["usersecuritygrouplist"]; found { i := 0 for k, vv := range v.(map[string]string) { - u.Set(fmt.Sprintf("usersecuritygrouplist[%d].key", i), k) - u.Set(fmt.Sprintf("usersecuritygrouplist[%d].value", i), vv) + u.Set(fmt.Sprintf("usersecuritygrouplist[%d].account", i), k) + u.Set(fmt.Sprintf("usersecuritygrouplist[%d].group", i), vv) i++ } } @@ -760,78 +245,203 @@ func (s *SecurityGroupService) AuthorizeSecurityGroupEgress(p *AuthorizeSecurity return nil, err } + b, err = convertAuthorizeSecurityGroupEgressResponse(b) + if err != nil { + return nil, err + } + if err := json.Unmarshal(b, &r); err != nil { return nil, err } } + return &r, nil } type AuthorizeSecurityGroupEgressResponse struct { - JobID string `json:"jobid,omitempty"` - Account string `json:"account,omitempty"` - Cidr string `json:"cidr,omitempty"` - Endport int `json:"endport,omitempty"` - Icmpcode int `json:"icmpcode,omitempty"` - Icmptype int `json:"icmptype,omitempty"` - Protocol string `json:"protocol,omitempty"` - Ruleid string `json:"ruleid,omitempty"` - Securitygroupname string `json:"securitygroupname,omitempty"` - Startport int `json:"startport,omitempty"` - Tags []struct { - Account string `json:"account,omitempty"` - Customer string `json:"customer,omitempty"` - Domain string `json:"domain,omitempty"` - Domainid string `json:"domainid,omitempty"` - Key string `json:"key,omitempty"` - Project string `json:"project,omitempty"` - Projectid string `json:"projectid,omitempty"` - Resourceid string `json:"resourceid,omitempty"` - Resourcetype string `json:"resourcetype,omitempty"` - Value string `json:"value,omitempty"` - } `json:"tags,omitempty"` + JobID string `json:"jobid"` + Account string `json:"account"` + Cidr string `json:"cidr"` + Endport int `json:"endport"` + Icmpcode int `json:"icmpcode"` + Icmptype int `json:"icmptype"` + Protocol string `json:"protocol"` + Ruleid string `json:"ruleid"` + Securitygroupname string `json:"securitygroupname"` + Startport int `json:"startport"` + Tags []Tags `json:"tags"` } -type RevokeSecurityGroupEgressParams struct { +type AuthorizeSecurityGroupIngressParams struct { p map[string]interface{} } -func (p *RevokeSecurityGroupEgressParams) toURLValues() url.Values { +func (p *AuthorizeSecurityGroupIngressParams) toURLValues() url.Values { u := url.Values{} if p.p == nil { return u } - if v, found := p.p["id"]; found { - u.Set("id", v.(string)) + if v, found := p.p["account"]; found { + u.Set("account", v.(string)) + } + if v, found := p.p["cidrlist"]; found { + vv := strings.Join(v.([]string), ",") + u.Set("cidrlist", vv) + } + if v, found := p.p["domainid"]; found { + u.Set("domainid", v.(string)) + } + if v, found := p.p["endport"]; found { + vv := strconv.Itoa(v.(int)) + u.Set("endport", vv) + } + if v, found := p.p["icmpcode"]; found { + vv := strconv.Itoa(v.(int)) + u.Set("icmpcode", vv) + } + if v, found := p.p["icmptype"]; found { + vv := strconv.Itoa(v.(int)) + u.Set("icmptype", vv) + } + if v, found := p.p["projectid"]; found { + u.Set("projectid", v.(string)) + } + if v, found := p.p["protocol"]; found { + u.Set("protocol", v.(string)) + } + if v, found := p.p["securitygroupid"]; found { + u.Set("securitygroupid", v.(string)) + } + if v, found := p.p["securitygroupname"]; found { + u.Set("securitygroupname", v.(string)) + } + if v, found := p.p["startport"]; found { + vv := strconv.Itoa(v.(int)) + u.Set("startport", vv) + } + if v, found := p.p["usersecuritygrouplist"]; found { + i := 0 + for k, vv := range v.(map[string]string) { + u.Set(fmt.Sprintf("usersecuritygrouplist[%d].account", i), k) + u.Set(fmt.Sprintf("usersecuritygrouplist[%d].group", i), vv) + i++ + } } return u } -func (p *RevokeSecurityGroupEgressParams) SetId(v string) { +func (p *AuthorizeSecurityGroupIngressParams) SetAccount(v string) { if p.p == nil { p.p = make(map[string]interface{}) } - p.p["id"] = v + p.p["account"] = v return } -// You should always use this function to get a new RevokeSecurityGroupEgressParams instance, +func (p *AuthorizeSecurityGroupIngressParams) SetCidrlist(v []string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["cidrlist"] = v + return +} + +func (p *AuthorizeSecurityGroupIngressParams) SetDomainid(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["domainid"] = v + return +} + +func (p *AuthorizeSecurityGroupIngressParams) SetEndport(v int) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["endport"] = v + return +} + +func (p *AuthorizeSecurityGroupIngressParams) SetIcmpcode(v int) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["icmpcode"] = v + return +} + +func (p *AuthorizeSecurityGroupIngressParams) SetIcmptype(v int) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["icmptype"] = v + return +} + +func (p *AuthorizeSecurityGroupIngressParams) SetProjectid(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["projectid"] = v + return +} + +func (p *AuthorizeSecurityGroupIngressParams) SetProtocol(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["protocol"] = v + return +} + +func (p *AuthorizeSecurityGroupIngressParams) SetSecuritygroupid(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["securitygroupid"] = v + return +} + +func (p *AuthorizeSecurityGroupIngressParams) SetSecuritygroupname(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["securitygroupname"] = v + return +} + +func (p *AuthorizeSecurityGroupIngressParams) SetStartport(v int) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["startport"] = v + return +} + +func (p *AuthorizeSecurityGroupIngressParams) SetUsersecuritygrouplist(v map[string]string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["usersecuritygrouplist"] = v + return +} + +// You should always use this function to get a new AuthorizeSecurityGroupIngressParams instance, // as then you are sure you have configured all required params -func (s *SecurityGroupService) NewRevokeSecurityGroupEgressParams(id string) *RevokeSecurityGroupEgressParams { - p := &RevokeSecurityGroupEgressParams{} +func (s *SecurityGroupService) NewAuthorizeSecurityGroupIngressParams() *AuthorizeSecurityGroupIngressParams { + p := &AuthorizeSecurityGroupIngressParams{} p.p = make(map[string]interface{}) - p.p["id"] = id return p } -// Deletes a particular egress rule from this security group -func (s *SecurityGroupService) RevokeSecurityGroupEgress(p *RevokeSecurityGroupEgressParams) (*RevokeSecurityGroupEgressResponse, error) { - resp, err := s.cs.newRequest("revokeSecurityGroupEgress", p.toURLValues()) +// Authorizes a particular ingress rule for this security group +func (s *SecurityGroupService) AuthorizeSecurityGroupIngress(p *AuthorizeSecurityGroupIngressParams) (*AuthorizeSecurityGroupIngressResponse, error) { + resp, err := s.cs.newRequest("authorizeSecurityGroupIngress", p.toURLValues()) if err != nil { return nil, err } - var r RevokeSecurityGroupEgressResponse + var r AuthorizeSecurityGroupIngressResponse if err := json.Unmarshal(resp, &r); err != nil { return nil, err } @@ -846,17 +456,274 @@ func (s *SecurityGroupService) RevokeSecurityGroupEgress(p *RevokeSecurityGroupE return nil, err } + b, err = getRawValue(b) + if err != nil { + return nil, err + } + + b, err = convertAuthorizeSecurityGroupIngressResponse(b) + if err != nil { + return nil, err + } + if err := json.Unmarshal(b, &r); err != nil { return nil, err } } + return &r, nil } -type RevokeSecurityGroupEgressResponse struct { - JobID string `json:"jobid,omitempty"` - Displaytext string `json:"displaytext,omitempty"` - Success bool `json:"success,omitempty"` +type AuthorizeSecurityGroupIngressResponse struct { + JobID string `json:"jobid"` + Account string `json:"account"` + Cidr string `json:"cidr"` + Endport int `json:"endport"` + Icmpcode int `json:"icmpcode"` + Icmptype int `json:"icmptype"` + Protocol string `json:"protocol"` + Ruleid string `json:"ruleid"` + Securitygroupname string `json:"securitygroupname"` + Startport int `json:"startport"` + Tags []Tags `json:"tags"` +} + +type CreateSecurityGroupParams struct { + p map[string]interface{} +} + +func (p *CreateSecurityGroupParams) toURLValues() url.Values { + u := url.Values{} + if p.p == nil { + return u + } + if v, found := p.p["account"]; found { + u.Set("account", v.(string)) + } + if v, found := p.p["description"]; found { + u.Set("description", v.(string)) + } + if v, found := p.p["domainid"]; found { + u.Set("domainid", v.(string)) + } + if v, found := p.p["name"]; found { + u.Set("name", v.(string)) + } + if v, found := p.p["projectid"]; found { + u.Set("projectid", v.(string)) + } + return u +} + +func (p *CreateSecurityGroupParams) SetAccount(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["account"] = v + return +} + +func (p *CreateSecurityGroupParams) SetDescription(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["description"] = v + return +} + +func (p *CreateSecurityGroupParams) SetDomainid(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["domainid"] = v + return +} + +func (p *CreateSecurityGroupParams) SetName(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["name"] = v + return +} + +func (p *CreateSecurityGroupParams) SetProjectid(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["projectid"] = v + return +} + +// You should always use this function to get a new CreateSecurityGroupParams instance, +// as then you are sure you have configured all required params +func (s *SecurityGroupService) NewCreateSecurityGroupParams(name string) *CreateSecurityGroupParams { + p := &CreateSecurityGroupParams{} + p.p = make(map[string]interface{}) + p.p["name"] = name + return p +} + +// Creates a security group +func (s *SecurityGroupService) CreateSecurityGroup(p *CreateSecurityGroupParams) (*CreateSecurityGroupResponse, error) { + resp, err := s.cs.newRequest("createSecurityGroup", p.toURLValues()) + if err != nil { + return nil, err + } + + if resp, err = getRawValue(resp); err != nil { + return nil, err + } + + var r CreateSecurityGroupResponse + if err := json.Unmarshal(resp, &r); err != nil { + return nil, err + } + + return &r, nil +} + +type CreateSecurityGroupResponse struct { + Account string `json:"account"` + Description string `json:"description"` + Domain string `json:"domain"` + Domainid string `json:"domainid"` + Egressrule []CreateSecurityGroupResponseRule `json:"egressrule"` + Id string `json:"id"` + Ingressrule []CreateSecurityGroupResponseRule `json:"ingressrule"` + Name string `json:"name"` + Project string `json:"project"` + Projectid string `json:"projectid"` + Tags []Tags `json:"tags"` + Virtualmachinecount int `json:"virtualmachinecount"` + Virtualmachineids []interface{} `json:"virtualmachineids"` +} + +type CreateSecurityGroupResponseRule struct { + Account string `json:"account"` + Cidr string `json:"cidr"` + Endport int `json:"endport"` + Icmpcode int `json:"icmpcode"` + Icmptype int `json:"icmptype"` + Protocol string `json:"protocol"` + Ruleid string `json:"ruleid"` + Securitygroupname string `json:"securitygroupname"` + Startport int `json:"startport"` + Tags []Tags `json:"tags"` +} + +type DeleteSecurityGroupParams struct { + p map[string]interface{} +} + +func (p *DeleteSecurityGroupParams) toURLValues() url.Values { + u := url.Values{} + if p.p == nil { + return u + } + if v, found := p.p["account"]; found { + u.Set("account", v.(string)) + } + if v, found := p.p["domainid"]; found { + u.Set("domainid", v.(string)) + } + if v, found := p.p["id"]; found { + u.Set("id", v.(string)) + } + if v, found := p.p["name"]; found { + u.Set("name", v.(string)) + } + if v, found := p.p["projectid"]; found { + u.Set("projectid", v.(string)) + } + return u +} + +func (p *DeleteSecurityGroupParams) SetAccount(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["account"] = v + return +} + +func (p *DeleteSecurityGroupParams) SetDomainid(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["domainid"] = v + return +} + +func (p *DeleteSecurityGroupParams) SetId(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["id"] = v + return +} + +func (p *DeleteSecurityGroupParams) SetName(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["name"] = v + return +} + +func (p *DeleteSecurityGroupParams) SetProjectid(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["projectid"] = v + return +} + +// You should always use this function to get a new DeleteSecurityGroupParams instance, +// as then you are sure you have configured all required params +func (s *SecurityGroupService) NewDeleteSecurityGroupParams() *DeleteSecurityGroupParams { + p := &DeleteSecurityGroupParams{} + p.p = make(map[string]interface{}) + return p +} + +// Deletes security group +func (s *SecurityGroupService) DeleteSecurityGroup(p *DeleteSecurityGroupParams) (*DeleteSecurityGroupResponse, error) { + resp, err := s.cs.newRequest("deleteSecurityGroup", p.toURLValues()) + if err != nil { + return nil, err + } + + var r DeleteSecurityGroupResponse + if err := json.Unmarshal(resp, &r); err != nil { + return nil, err + } + + return &r, nil +} + +type DeleteSecurityGroupResponse struct { + Displaytext string `json:"displaytext"` + Success bool `json:"success"` +} + +func (r *DeleteSecurityGroupResponse) UnmarshalJSON(b []byte) error { + var m map[string]interface{} + err := json.Unmarshal(b, &m) + if err != nil { + return err + } + + if success, ok := m["success"].(string); ok { + m["success"] = success == "true" + b, err = json.Marshal(m) + if err != nil { + return err + } + } + + type alias DeleteSecurityGroupResponse + return json.Unmarshal(b, (*alias)(r)) } type ListSecurityGroupsParams struct { @@ -1027,7 +894,7 @@ func (s *SecurityGroupService) GetSecurityGroupID(keyword string, opts ...Option p.p["keyword"] = keyword - for _, fn := range opts { + for _, fn := range append(s.cs.options, opts...) { if err := fn(s.cs, p); err != nil { return "", -1, err } @@ -1077,7 +944,7 @@ func (s *SecurityGroupService) GetSecurityGroupByID(id string, opts ...OptionFun p.p["id"] = id - for _, fn := range opts { + for _, fn := range append(s.cs.options, opts...) { if err := fn(s.cs, p); err != nil { return nil, -1, err } @@ -1114,6 +981,7 @@ func (s *SecurityGroupService) ListSecurityGroups(p *ListSecurityGroupsParams) ( if err := json.Unmarshal(resp, &r); err != nil { return nil, err } + return &r, nil } @@ -1123,72 +991,166 @@ type ListSecurityGroupsResponse struct { } type SecurityGroup struct { - Account string `json:"account,omitempty"` - Description string `json:"description,omitempty"` - Domain string `json:"domain,omitempty"` - Domainid string `json:"domainid,omitempty"` - Egressrule []struct { - Account string `json:"account,omitempty"` - Cidr string `json:"cidr,omitempty"` - Endport int `json:"endport,omitempty"` - Icmpcode int `json:"icmpcode,omitempty"` - Icmptype int `json:"icmptype,omitempty"` - Protocol string `json:"protocol,omitempty"` - Ruleid string `json:"ruleid,omitempty"` - Securitygroupname string `json:"securitygroupname,omitempty"` - Startport int `json:"startport,omitempty"` - Tags []struct { - Account string `json:"account,omitempty"` - Customer string `json:"customer,omitempty"` - Domain string `json:"domain,omitempty"` - Domainid string `json:"domainid,omitempty"` - Key string `json:"key,omitempty"` - Project string `json:"project,omitempty"` - Projectid string `json:"projectid,omitempty"` - Resourceid string `json:"resourceid,omitempty"` - Resourcetype string `json:"resourcetype,omitempty"` - Value string `json:"value,omitempty"` - } `json:"tags,omitempty"` - } `json:"egressrule,omitempty"` - Id string `json:"id,omitempty"` - Ingressrule []struct { - Account string `json:"account,omitempty"` - Cidr string `json:"cidr,omitempty"` - Endport int `json:"endport,omitempty"` - Icmpcode int `json:"icmpcode,omitempty"` - Icmptype int `json:"icmptype,omitempty"` - Protocol string `json:"protocol,omitempty"` - Ruleid string `json:"ruleid,omitempty"` - Securitygroupname string `json:"securitygroupname,omitempty"` - Startport int `json:"startport,omitempty"` - Tags []struct { - Account string `json:"account,omitempty"` - Customer string `json:"customer,omitempty"` - Domain string `json:"domain,omitempty"` - Domainid string `json:"domainid,omitempty"` - Key string `json:"key,omitempty"` - Project string `json:"project,omitempty"` - Projectid string `json:"projectid,omitempty"` - Resourceid string `json:"resourceid,omitempty"` - Resourcetype string `json:"resourcetype,omitempty"` - Value string `json:"value,omitempty"` - } `json:"tags,omitempty"` - } `json:"ingressrule,omitempty"` - Name string `json:"name,omitempty"` - Project string `json:"project,omitempty"` - Projectid string `json:"projectid,omitempty"` - Tags []struct { - Account string `json:"account,omitempty"` - Customer string `json:"customer,omitempty"` - Domain string `json:"domain,omitempty"` - Domainid string `json:"domainid,omitempty"` - Key string `json:"key,omitempty"` - Project string `json:"project,omitempty"` - Projectid string `json:"projectid,omitempty"` - Resourceid string `json:"resourceid,omitempty"` - Resourcetype string `json:"resourcetype,omitempty"` - Value string `json:"value,omitempty"` - } `json:"tags,omitempty"` - Virtualmachinecount int `json:"virtualmachinecount,omitempty"` - Virtualmachineids []string `json:"virtualmachineids,omitempty"` + Account string `json:"account"` + Description string `json:"description"` + Domain string `json:"domain"` + Domainid string `json:"domainid"` + Egressrule []SecurityGroupRule `json:"egressrule"` + Id string `json:"id"` + Ingressrule []SecurityGroupRule `json:"ingressrule"` + Name string `json:"name"` + Project string `json:"project"` + Projectid string `json:"projectid"` + Tags []Tags `json:"tags"` + Virtualmachinecount int `json:"virtualmachinecount"` + Virtualmachineids []interface{} `json:"virtualmachineids"` +} + +type SecurityGroupRule struct { + Account string `json:"account"` + Cidr string `json:"cidr"` + Endport int `json:"endport"` + Icmpcode int `json:"icmpcode"` + Icmptype int `json:"icmptype"` + Protocol string `json:"protocol"` + Ruleid string `json:"ruleid"` + Securitygroupname string `json:"securitygroupname"` + Startport int `json:"startport"` + Tags []Tags `json:"tags"` +} + +type RevokeSecurityGroupEgressParams struct { + p map[string]interface{} +} + +func (p *RevokeSecurityGroupEgressParams) toURLValues() url.Values { + u := url.Values{} + if p.p == nil { + return u + } + if v, found := p.p["id"]; found { + u.Set("id", v.(string)) + } + return u +} + +func (p *RevokeSecurityGroupEgressParams) SetId(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["id"] = v + return +} + +// You should always use this function to get a new RevokeSecurityGroupEgressParams instance, +// as then you are sure you have configured all required params +func (s *SecurityGroupService) NewRevokeSecurityGroupEgressParams(id string) *RevokeSecurityGroupEgressParams { + p := &RevokeSecurityGroupEgressParams{} + p.p = make(map[string]interface{}) + p.p["id"] = id + return p +} + +// Deletes a particular egress rule from this security group +func (s *SecurityGroupService) RevokeSecurityGroupEgress(p *RevokeSecurityGroupEgressParams) (*RevokeSecurityGroupEgressResponse, error) { + resp, err := s.cs.newRequest("revokeSecurityGroupEgress", p.toURLValues()) + if err != nil { + return nil, err + } + + var r RevokeSecurityGroupEgressResponse + if err := json.Unmarshal(resp, &r); err != nil { + return nil, err + } + + // If we have a async client, we need to wait for the async result + if s.cs.async { + b, err := s.cs.GetAsyncJobResult(r.JobID, s.cs.timeout) + if err != nil { + if err == AsyncTimeoutErr { + return &r, err + } + return nil, err + } + + if err := json.Unmarshal(b, &r); err != nil { + return nil, err + } + } + + return &r, nil +} + +type RevokeSecurityGroupEgressResponse struct { + JobID string `json:"jobid"` + Displaytext string `json:"displaytext"` + Success bool `json:"success"` +} + +type RevokeSecurityGroupIngressParams struct { + p map[string]interface{} +} + +func (p *RevokeSecurityGroupIngressParams) toURLValues() url.Values { + u := url.Values{} + if p.p == nil { + return u + } + if v, found := p.p["id"]; found { + u.Set("id", v.(string)) + } + return u +} + +func (p *RevokeSecurityGroupIngressParams) SetId(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["id"] = v + return +} + +// You should always use this function to get a new RevokeSecurityGroupIngressParams instance, +// as then you are sure you have configured all required params +func (s *SecurityGroupService) NewRevokeSecurityGroupIngressParams(id string) *RevokeSecurityGroupIngressParams { + p := &RevokeSecurityGroupIngressParams{} + p.p = make(map[string]interface{}) + p.p["id"] = id + return p +} + +// Deletes a particular ingress rule from this security group +func (s *SecurityGroupService) RevokeSecurityGroupIngress(p *RevokeSecurityGroupIngressParams) (*RevokeSecurityGroupIngressResponse, error) { + resp, err := s.cs.newRequest("revokeSecurityGroupIngress", p.toURLValues()) + if err != nil { + return nil, err + } + + var r RevokeSecurityGroupIngressResponse + if err := json.Unmarshal(resp, &r); err != nil { + return nil, err + } + + // If we have a async client, we need to wait for the async result + if s.cs.async { + b, err := s.cs.GetAsyncJobResult(r.JobID, s.cs.timeout) + if err != nil { + if err == AsyncTimeoutErr { + return &r, err + } + return nil, err + } + + if err := json.Unmarshal(b, &r); err != nil { + return nil, err + } + } + + return &r, nil +} + +type RevokeSecurityGroupIngressResponse struct { + JobID string `json:"jobid"` + Displaytext string `json:"displaytext"` + Success bool `json:"success"` } diff --git a/vendor/github.com/xanzy/go-cloudstack/cloudstack/ServiceOfferingService.go b/vendor/github.com/xanzy/go-cloudstack/cloudstack/ServiceOfferingService.go index 95e764703..1700f8d94 100644 --- a/vendor/github.com/xanzy/go-cloudstack/cloudstack/ServiceOfferingService.go +++ b/vendor/github.com/xanzy/go-cloudstack/cloudstack/ServiceOfferingService.go @@ -1,5 +1,5 @@ // -// Copyright 2016, Sander van Harmelen +// Copyright 2018, Sander van Harmelen // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -368,41 +368,42 @@ func (s *ServiceOfferingService) CreateServiceOffering(p *CreateServiceOfferingP if err := json.Unmarshal(resp, &r); err != nil { return nil, err } + return &r, nil } type CreateServiceOfferingResponse struct { - Cpunumber int `json:"cpunumber,omitempty"` - Cpuspeed int `json:"cpuspeed,omitempty"` - Created string `json:"created,omitempty"` - Defaultuse bool `json:"defaultuse,omitempty"` - Deploymentplanner string `json:"deploymentplanner,omitempty"` - DiskBytesReadRate int64 `json:"diskBytesReadRate,omitempty"` - DiskBytesWriteRate int64 `json:"diskBytesWriteRate,omitempty"` - DiskIopsReadRate int64 `json:"diskIopsReadRate,omitempty"` - DiskIopsWriteRate int64 `json:"diskIopsWriteRate,omitempty"` - Displaytext string `json:"displaytext,omitempty"` - Domain string `json:"domain,omitempty"` - Domainid string `json:"domainid,omitempty"` - Hosttags string `json:"hosttags,omitempty"` - Hypervisorsnapshotreserve int `json:"hypervisorsnapshotreserve,omitempty"` - Id string `json:"id,omitempty"` - Iscustomized bool `json:"iscustomized,omitempty"` - Iscustomizediops bool `json:"iscustomizediops,omitempty"` - Issystem bool `json:"issystem,omitempty"` - Isvolatile bool `json:"isvolatile,omitempty"` - Limitcpuuse bool `json:"limitcpuuse,omitempty"` - Maxiops int64 `json:"maxiops,omitempty"` - Memory int `json:"memory,omitempty"` - Miniops int64 `json:"miniops,omitempty"` - Name string `json:"name,omitempty"` - Networkrate int `json:"networkrate,omitempty"` - Offerha bool `json:"offerha,omitempty"` - Provisioningtype string `json:"provisioningtype,omitempty"` - Serviceofferingdetails map[string]string `json:"serviceofferingdetails,omitempty"` - Storagetype string `json:"storagetype,omitempty"` - Systemvmtype string `json:"systemvmtype,omitempty"` - Tags string `json:"tags,omitempty"` + Cpunumber int `json:"cpunumber"` + Cpuspeed int `json:"cpuspeed"` + Created string `json:"created"` + Defaultuse bool `json:"defaultuse"` + Deploymentplanner string `json:"deploymentplanner"` + DiskBytesReadRate int64 `json:"diskBytesReadRate"` + DiskBytesWriteRate int64 `json:"diskBytesWriteRate"` + DiskIopsReadRate int64 `json:"diskIopsReadRate"` + DiskIopsWriteRate int64 `json:"diskIopsWriteRate"` + Displaytext string `json:"displaytext"` + Domain string `json:"domain"` + Domainid string `json:"domainid"` + Hosttags string `json:"hosttags"` + Hypervisorsnapshotreserve int `json:"hypervisorsnapshotreserve"` + Id string `json:"id"` + Iscustomized bool `json:"iscustomized"` + Iscustomizediops bool `json:"iscustomizediops"` + Issystem bool `json:"issystem"` + Isvolatile bool `json:"isvolatile"` + Limitcpuuse bool `json:"limitcpuuse"` + Maxiops int64 `json:"maxiops"` + Memory int `json:"memory"` + Miniops int64 `json:"miniops"` + Name string `json:"name"` + Networkrate int `json:"networkrate"` + Offerha bool `json:"offerha"` + Provisioningtype string `json:"provisioningtype"` + Serviceofferingdetails map[string]string `json:"serviceofferingdetails"` + Storagetype string `json:"storagetype"` + Systemvmtype string `json:"systemvmtype"` + Tags string `json:"tags"` } type DeleteServiceOfferingParams struct { @@ -448,126 +449,32 @@ func (s *ServiceOfferingService) DeleteServiceOffering(p *DeleteServiceOfferingP if err := json.Unmarshal(resp, &r); err != nil { return nil, err } + return &r, nil } type DeleteServiceOfferingResponse struct { - Displaytext string `json:"displaytext,omitempty"` - Success string `json:"success,omitempty"` + Displaytext string `json:"displaytext"` + Success bool `json:"success"` } -type UpdateServiceOfferingParams struct { - p map[string]interface{} -} - -func (p *UpdateServiceOfferingParams) toURLValues() url.Values { - u := url.Values{} - if p.p == nil { - return u - } - if v, found := p.p["displaytext"]; found { - u.Set("displaytext", v.(string)) - } - if v, found := p.p["id"]; found { - u.Set("id", v.(string)) - } - if v, found := p.p["name"]; found { - u.Set("name", v.(string)) - } - if v, found := p.p["sortkey"]; found { - vv := strconv.Itoa(v.(int)) - u.Set("sortkey", vv) - } - return u -} - -func (p *UpdateServiceOfferingParams) SetDisplaytext(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["displaytext"] = v - return -} - -func (p *UpdateServiceOfferingParams) SetId(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["id"] = v - return -} - -func (p *UpdateServiceOfferingParams) SetName(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["name"] = v - return -} - -func (p *UpdateServiceOfferingParams) SetSortkey(v int) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["sortkey"] = v - return -} - -// You should always use this function to get a new UpdateServiceOfferingParams instance, -// as then you are sure you have configured all required params -func (s *ServiceOfferingService) NewUpdateServiceOfferingParams(id string) *UpdateServiceOfferingParams { - p := &UpdateServiceOfferingParams{} - p.p = make(map[string]interface{}) - p.p["id"] = id - return p -} - -// Updates a service offering. -func (s *ServiceOfferingService) UpdateServiceOffering(p *UpdateServiceOfferingParams) (*UpdateServiceOfferingResponse, error) { - resp, err := s.cs.newRequest("updateServiceOffering", p.toURLValues()) +func (r *DeleteServiceOfferingResponse) UnmarshalJSON(b []byte) error { + var m map[string]interface{} + err := json.Unmarshal(b, &m) if err != nil { - return nil, err + return err } - var r UpdateServiceOfferingResponse - if err := json.Unmarshal(resp, &r); err != nil { - return nil, err + if success, ok := m["success"].(string); ok { + m["success"] = success == "true" + b, err = json.Marshal(m) + if err != nil { + return err + } } - return &r, nil -} -type UpdateServiceOfferingResponse struct { - Cpunumber int `json:"cpunumber,omitempty"` - Cpuspeed int `json:"cpuspeed,omitempty"` - Created string `json:"created,omitempty"` - Defaultuse bool `json:"defaultuse,omitempty"` - Deploymentplanner string `json:"deploymentplanner,omitempty"` - DiskBytesReadRate int64 `json:"diskBytesReadRate,omitempty"` - DiskBytesWriteRate int64 `json:"diskBytesWriteRate,omitempty"` - DiskIopsReadRate int64 `json:"diskIopsReadRate,omitempty"` - DiskIopsWriteRate int64 `json:"diskIopsWriteRate,omitempty"` - Displaytext string `json:"displaytext,omitempty"` - Domain string `json:"domain,omitempty"` - Domainid string `json:"domainid,omitempty"` - Hosttags string `json:"hosttags,omitempty"` - Hypervisorsnapshotreserve int `json:"hypervisorsnapshotreserve,omitempty"` - Id string `json:"id,omitempty"` - Iscustomized bool `json:"iscustomized,omitempty"` - Iscustomizediops bool `json:"iscustomizediops,omitempty"` - Issystem bool `json:"issystem,omitempty"` - Isvolatile bool `json:"isvolatile,omitempty"` - Limitcpuuse bool `json:"limitcpuuse,omitempty"` - Maxiops int64 `json:"maxiops,omitempty"` - Memory int `json:"memory,omitempty"` - Miniops int64 `json:"miniops,omitempty"` - Name string `json:"name,omitempty"` - Networkrate int `json:"networkrate,omitempty"` - Offerha bool `json:"offerha,omitempty"` - Provisioningtype string `json:"provisioningtype,omitempty"` - Serviceofferingdetails map[string]string `json:"serviceofferingdetails,omitempty"` - Storagetype string `json:"storagetype,omitempty"` - Systemvmtype string `json:"systemvmtype,omitempty"` - Tags string `json:"tags,omitempty"` + type alias DeleteServiceOfferingResponse + return json.Unmarshal(b, (*alias)(r)) } type ListServiceOfferingsParams struct { @@ -723,7 +630,7 @@ func (s *ServiceOfferingService) GetServiceOfferingID(name string, opts ...Optio p.p["name"] = name - for _, fn := range opts { + for _, fn := range append(s.cs.options, opts...) { if err := fn(s.cs, p); err != nil { return "", -1, err } @@ -773,7 +680,7 @@ func (s *ServiceOfferingService) GetServiceOfferingByID(id string, opts ...Optio p.p["id"] = id - for _, fn := range opts { + for _, fn := range append(s.cs.options, opts...) { if err := fn(s.cs, p); err != nil { return nil, -1, err } @@ -810,6 +717,7 @@ func (s *ServiceOfferingService) ListServiceOfferings(p *ListServiceOfferingsPar if err := json.Unmarshal(resp, &r); err != nil { return nil, err } + return &r, nil } @@ -819,35 +727,150 @@ type ListServiceOfferingsResponse struct { } type ServiceOffering struct { - Cpunumber int `json:"cpunumber,omitempty"` - Cpuspeed int `json:"cpuspeed,omitempty"` - Created string `json:"created,omitempty"` - Defaultuse bool `json:"defaultuse,omitempty"` - Deploymentplanner string `json:"deploymentplanner,omitempty"` - DiskBytesReadRate int64 `json:"diskBytesReadRate,omitempty"` - DiskBytesWriteRate int64 `json:"diskBytesWriteRate,omitempty"` - DiskIopsReadRate int64 `json:"diskIopsReadRate,omitempty"` - DiskIopsWriteRate int64 `json:"diskIopsWriteRate,omitempty"` - Displaytext string `json:"displaytext,omitempty"` - Domain string `json:"domain,omitempty"` - Domainid string `json:"domainid,omitempty"` - Hosttags string `json:"hosttags,omitempty"` - Hypervisorsnapshotreserve int `json:"hypervisorsnapshotreserve,omitempty"` - Id string `json:"id,omitempty"` - Iscustomized bool `json:"iscustomized,omitempty"` - Iscustomizediops bool `json:"iscustomizediops,omitempty"` - Issystem bool `json:"issystem,omitempty"` - Isvolatile bool `json:"isvolatile,omitempty"` - Limitcpuuse bool `json:"limitcpuuse,omitempty"` - Maxiops int64 `json:"maxiops,omitempty"` - Memory int `json:"memory,omitempty"` - Miniops int64 `json:"miniops,omitempty"` - Name string `json:"name,omitempty"` - Networkrate int `json:"networkrate,omitempty"` - Offerha bool `json:"offerha,omitempty"` - Provisioningtype string `json:"provisioningtype,omitempty"` - Serviceofferingdetails map[string]string `json:"serviceofferingdetails,omitempty"` - Storagetype string `json:"storagetype,omitempty"` - Systemvmtype string `json:"systemvmtype,omitempty"` - Tags string `json:"tags,omitempty"` + Cpunumber int `json:"cpunumber"` + Cpuspeed int `json:"cpuspeed"` + Created string `json:"created"` + Defaultuse bool `json:"defaultuse"` + Deploymentplanner string `json:"deploymentplanner"` + DiskBytesReadRate int64 `json:"diskBytesReadRate"` + DiskBytesWriteRate int64 `json:"diskBytesWriteRate"` + DiskIopsReadRate int64 `json:"diskIopsReadRate"` + DiskIopsWriteRate int64 `json:"diskIopsWriteRate"` + Displaytext string `json:"displaytext"` + Domain string `json:"domain"` + Domainid string `json:"domainid"` + Hosttags string `json:"hosttags"` + Hypervisorsnapshotreserve int `json:"hypervisorsnapshotreserve"` + Id string `json:"id"` + Iscustomized bool `json:"iscustomized"` + Iscustomizediops bool `json:"iscustomizediops"` + Issystem bool `json:"issystem"` + Isvolatile bool `json:"isvolatile"` + Limitcpuuse bool `json:"limitcpuuse"` + Maxiops int64 `json:"maxiops"` + Memory int `json:"memory"` + Miniops int64 `json:"miniops"` + Name string `json:"name"` + Networkrate int `json:"networkrate"` + Offerha bool `json:"offerha"` + Provisioningtype string `json:"provisioningtype"` + Serviceofferingdetails map[string]string `json:"serviceofferingdetails"` + Storagetype string `json:"storagetype"` + Systemvmtype string `json:"systemvmtype"` + Tags string `json:"tags"` +} + +type UpdateServiceOfferingParams struct { + p map[string]interface{} +} + +func (p *UpdateServiceOfferingParams) toURLValues() url.Values { + u := url.Values{} + if p.p == nil { + return u + } + if v, found := p.p["displaytext"]; found { + u.Set("displaytext", v.(string)) + } + if v, found := p.p["id"]; found { + u.Set("id", v.(string)) + } + if v, found := p.p["name"]; found { + u.Set("name", v.(string)) + } + if v, found := p.p["sortkey"]; found { + vv := strconv.Itoa(v.(int)) + u.Set("sortkey", vv) + } + return u +} + +func (p *UpdateServiceOfferingParams) SetDisplaytext(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["displaytext"] = v + return +} + +func (p *UpdateServiceOfferingParams) SetId(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["id"] = v + return +} + +func (p *UpdateServiceOfferingParams) SetName(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["name"] = v + return +} + +func (p *UpdateServiceOfferingParams) SetSortkey(v int) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["sortkey"] = v + return +} + +// You should always use this function to get a new UpdateServiceOfferingParams instance, +// as then you are sure you have configured all required params +func (s *ServiceOfferingService) NewUpdateServiceOfferingParams(id string) *UpdateServiceOfferingParams { + p := &UpdateServiceOfferingParams{} + p.p = make(map[string]interface{}) + p.p["id"] = id + return p +} + +// Updates a service offering. +func (s *ServiceOfferingService) UpdateServiceOffering(p *UpdateServiceOfferingParams) (*UpdateServiceOfferingResponse, error) { + resp, err := s.cs.newRequest("updateServiceOffering", p.toURLValues()) + if err != nil { + return nil, err + } + + var r UpdateServiceOfferingResponse + if err := json.Unmarshal(resp, &r); err != nil { + return nil, err + } + + return &r, nil +} + +type UpdateServiceOfferingResponse struct { + Cpunumber int `json:"cpunumber"` + Cpuspeed int `json:"cpuspeed"` + Created string `json:"created"` + Defaultuse bool `json:"defaultuse"` + Deploymentplanner string `json:"deploymentplanner"` + DiskBytesReadRate int64 `json:"diskBytesReadRate"` + DiskBytesWriteRate int64 `json:"diskBytesWriteRate"` + DiskIopsReadRate int64 `json:"diskIopsReadRate"` + DiskIopsWriteRate int64 `json:"diskIopsWriteRate"` + Displaytext string `json:"displaytext"` + Domain string `json:"domain"` + Domainid string `json:"domainid"` + Hosttags string `json:"hosttags"` + Hypervisorsnapshotreserve int `json:"hypervisorsnapshotreserve"` + Id string `json:"id"` + Iscustomized bool `json:"iscustomized"` + Iscustomizediops bool `json:"iscustomizediops"` + Issystem bool `json:"issystem"` + Isvolatile bool `json:"isvolatile"` + Limitcpuuse bool `json:"limitcpuuse"` + Maxiops int64 `json:"maxiops"` + Memory int `json:"memory"` + Miniops int64 `json:"miniops"` + Name string `json:"name"` + Networkrate int `json:"networkrate"` + Offerha bool `json:"offerha"` + Provisioningtype string `json:"provisioningtype"` + Serviceofferingdetails map[string]string `json:"serviceofferingdetails"` + Storagetype string `json:"storagetype"` + Systemvmtype string `json:"systemvmtype"` + Tags string `json:"tags"` } diff --git a/vendor/github.com/xanzy/go-cloudstack/cloudstack/SnapshotService.go b/vendor/github.com/xanzy/go-cloudstack/cloudstack/SnapshotService.go index c81dea323..e3186e7e2 100644 --- a/vendor/github.com/xanzy/go-cloudstack/cloudstack/SnapshotService.go +++ b/vendor/github.com/xanzy/go-cloudstack/cloudstack/SnapshotService.go @@ -1,5 +1,5 @@ // -// Copyright 2016, Sander van Harmelen +// Copyright 2018, Sander van Harmelen // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -36,9 +36,16 @@ func (p *CreateSnapshotParams) toURLValues() url.Values { if v, found := p.p["account"]; found { u.Set("account", v.(string)) } + if v, found := p.p["asyncbackup"]; found { + vv := strconv.FormatBool(v.(bool)) + u.Set("asyncbackup", vv) + } if v, found := p.p["domainid"]; found { u.Set("domainid", v.(string)) } + if v, found := p.p["locationtype"]; found { + u.Set("locationtype", v.(string)) + } if v, found := p.p["name"]; found { u.Set("name", v.(string)) } @@ -63,6 +70,14 @@ func (p *CreateSnapshotParams) SetAccount(v string) { return } +func (p *CreateSnapshotParams) SetAsyncbackup(v bool) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["asyncbackup"] = v + return +} + func (p *CreateSnapshotParams) SetDomainid(v string) { if p.p == nil { p.p = make(map[string]interface{}) @@ -71,6 +86,14 @@ func (p *CreateSnapshotParams) SetDomainid(v string) { return } +func (p *CreateSnapshotParams) SetLocationtype(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["locationtype"] = v + return +} + func (p *CreateSnapshotParams) SetName(v string) { if p.p == nil { p.p = make(map[string]interface{}) @@ -143,40 +166,656 @@ func (s *SnapshotService) CreateSnapshot(p *CreateSnapshotParams) (*CreateSnapsh return nil, err } } + return &r, nil } type CreateSnapshotResponse struct { - JobID string `json:"jobid,omitempty"` - Account string `json:"account,omitempty"` - Created string `json:"created,omitempty"` - Domain string `json:"domain,omitempty"` - Domainid string `json:"domainid,omitempty"` - Id string `json:"id,omitempty"` - Intervaltype string `json:"intervaltype,omitempty"` - Name string `json:"name,omitempty"` - Physicalsize int64 `json:"physicalsize,omitempty"` - Project string `json:"project,omitempty"` - Projectid string `json:"projectid,omitempty"` - Revertable bool `json:"revertable,omitempty"` - Snapshottype string `json:"snapshottype,omitempty"` - State string `json:"state,omitempty"` - Tags []struct { - Account string `json:"account,omitempty"` - Customer string `json:"customer,omitempty"` - Domain string `json:"domain,omitempty"` - Domainid string `json:"domainid,omitempty"` - Key string `json:"key,omitempty"` - Project string `json:"project,omitempty"` - Projectid string `json:"projectid,omitempty"` - Resourceid string `json:"resourceid,omitempty"` - Resourcetype string `json:"resourcetype,omitempty"` - Value string `json:"value,omitempty"` - } `json:"tags,omitempty"` - Volumeid string `json:"volumeid,omitempty"` - Volumename string `json:"volumename,omitempty"` - Volumetype string `json:"volumetype,omitempty"` - Zoneid string `json:"zoneid,omitempty"` + JobID string `json:"jobid"` + Account string `json:"account"` + Created string `json:"created"` + Domain string `json:"domain"` + Domainid string `json:"domainid"` + Id string `json:"id"` + Intervaltype string `json:"intervaltype"` + Locationtype string `json:"locationtype"` + Name string `json:"name"` + Osdisplayname string `json:"osdisplayname"` + Ostypeid string `json:"ostypeid"` + Physicalsize int64 `json:"physicalsize"` + Project string `json:"project"` + Projectid string `json:"projectid"` + Revertable bool `json:"revertable"` + Snapshottype string `json:"snapshottype"` + State string `json:"state"` + Tags []Tags `json:"tags"` + Virtualsize int64 `json:"virtualsize"` + Volumeid string `json:"volumeid"` + Volumename string `json:"volumename"` + Volumetype string `json:"volumetype"` + Zoneid string `json:"zoneid"` +} + +type CreateSnapshotPolicyParams struct { + p map[string]interface{} +} + +func (p *CreateSnapshotPolicyParams) toURLValues() url.Values { + u := url.Values{} + if p.p == nil { + return u + } + if v, found := p.p["fordisplay"]; found { + vv := strconv.FormatBool(v.(bool)) + u.Set("fordisplay", vv) + } + if v, found := p.p["intervaltype"]; found { + u.Set("intervaltype", v.(string)) + } + if v, found := p.p["maxsnaps"]; found { + vv := strconv.Itoa(v.(int)) + u.Set("maxsnaps", vv) + } + if v, found := p.p["schedule"]; found { + u.Set("schedule", v.(string)) + } + if v, found := p.p["timezone"]; found { + u.Set("timezone", v.(string)) + } + if v, found := p.p["volumeid"]; found { + u.Set("volumeid", v.(string)) + } + return u +} + +func (p *CreateSnapshotPolicyParams) SetFordisplay(v bool) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["fordisplay"] = v + return +} + +func (p *CreateSnapshotPolicyParams) SetIntervaltype(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["intervaltype"] = v + return +} + +func (p *CreateSnapshotPolicyParams) SetMaxsnaps(v int) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["maxsnaps"] = v + return +} + +func (p *CreateSnapshotPolicyParams) SetSchedule(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["schedule"] = v + return +} + +func (p *CreateSnapshotPolicyParams) SetTimezone(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["timezone"] = v + return +} + +func (p *CreateSnapshotPolicyParams) SetVolumeid(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["volumeid"] = v + return +} + +// You should always use this function to get a new CreateSnapshotPolicyParams instance, +// as then you are sure you have configured all required params +func (s *SnapshotService) NewCreateSnapshotPolicyParams(intervaltype string, maxsnaps int, schedule string, timezone string, volumeid string) *CreateSnapshotPolicyParams { + p := &CreateSnapshotPolicyParams{} + p.p = make(map[string]interface{}) + p.p["intervaltype"] = intervaltype + p.p["maxsnaps"] = maxsnaps + p.p["schedule"] = schedule + p.p["timezone"] = timezone + p.p["volumeid"] = volumeid + return p +} + +// Creates a snapshot policy for the account. +func (s *SnapshotService) CreateSnapshotPolicy(p *CreateSnapshotPolicyParams) (*CreateSnapshotPolicyResponse, error) { + resp, err := s.cs.newRequest("createSnapshotPolicy", p.toURLValues()) + if err != nil { + return nil, err + } + + var r CreateSnapshotPolicyResponse + if err := json.Unmarshal(resp, &r); err != nil { + return nil, err + } + + return &r, nil +} + +type CreateSnapshotPolicyResponse struct { + Fordisplay bool `json:"fordisplay"` + Id string `json:"id"` + Intervaltype int `json:"intervaltype"` + Maxsnaps int `json:"maxsnaps"` + Schedule string `json:"schedule"` + Timezone string `json:"timezone"` + Volumeid string `json:"volumeid"` +} + +type CreateVMSnapshotParams struct { + p map[string]interface{} +} + +func (p *CreateVMSnapshotParams) toURLValues() url.Values { + u := url.Values{} + if p.p == nil { + return u + } + if v, found := p.p["description"]; found { + u.Set("description", v.(string)) + } + if v, found := p.p["name"]; found { + u.Set("name", v.(string)) + } + if v, found := p.p["quiescevm"]; found { + vv := strconv.FormatBool(v.(bool)) + u.Set("quiescevm", vv) + } + if v, found := p.p["snapshotmemory"]; found { + vv := strconv.FormatBool(v.(bool)) + u.Set("snapshotmemory", vv) + } + if v, found := p.p["virtualmachineid"]; found { + u.Set("virtualmachineid", v.(string)) + } + return u +} + +func (p *CreateVMSnapshotParams) SetDescription(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["description"] = v + return +} + +func (p *CreateVMSnapshotParams) SetName(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["name"] = v + return +} + +func (p *CreateVMSnapshotParams) SetQuiescevm(v bool) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["quiescevm"] = v + return +} + +func (p *CreateVMSnapshotParams) SetSnapshotmemory(v bool) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["snapshotmemory"] = v + return +} + +func (p *CreateVMSnapshotParams) SetVirtualmachineid(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["virtualmachineid"] = v + return +} + +// You should always use this function to get a new CreateVMSnapshotParams instance, +// as then you are sure you have configured all required params +func (s *SnapshotService) NewCreateVMSnapshotParams(virtualmachineid string) *CreateVMSnapshotParams { + p := &CreateVMSnapshotParams{} + p.p = make(map[string]interface{}) + p.p["virtualmachineid"] = virtualmachineid + return p +} + +// Creates snapshot for a vm. +func (s *SnapshotService) CreateVMSnapshot(p *CreateVMSnapshotParams) (*CreateVMSnapshotResponse, error) { + resp, err := s.cs.newRequest("createVMSnapshot", p.toURLValues()) + if err != nil { + return nil, err + } + + var r CreateVMSnapshotResponse + if err := json.Unmarshal(resp, &r); err != nil { + return nil, err + } + + // If we have a async client, we need to wait for the async result + if s.cs.async { + b, err := s.cs.GetAsyncJobResult(r.JobID, s.cs.timeout) + if err != nil { + if err == AsyncTimeoutErr { + return &r, err + } + return nil, err + } + + b, err = getRawValue(b) + if err != nil { + return nil, err + } + + if err := json.Unmarshal(b, &r); err != nil { + return nil, err + } + } + + return &r, nil +} + +type CreateVMSnapshotResponse struct { + JobID string `json:"jobid"` + Account string `json:"account"` + Created string `json:"created"` + Current bool `json:"current"` + Description string `json:"description"` + Displayname string `json:"displayname"` + Domain string `json:"domain"` + Domainid string `json:"domainid"` + Id string `json:"id"` + Name string `json:"name"` + Parent string `json:"parent"` + ParentName string `json:"parentName"` + Project string `json:"project"` + Projectid string `json:"projectid"` + State string `json:"state"` + Type string `json:"type"` + Virtualmachineid string `json:"virtualmachineid"` + Zoneid string `json:"zoneid"` +} + +type DeleteSnapshotParams struct { + p map[string]interface{} +} + +func (p *DeleteSnapshotParams) toURLValues() url.Values { + u := url.Values{} + if p.p == nil { + return u + } + if v, found := p.p["id"]; found { + u.Set("id", v.(string)) + } + return u +} + +func (p *DeleteSnapshotParams) SetId(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["id"] = v + return +} + +// You should always use this function to get a new DeleteSnapshotParams instance, +// as then you are sure you have configured all required params +func (s *SnapshotService) NewDeleteSnapshotParams(id string) *DeleteSnapshotParams { + p := &DeleteSnapshotParams{} + p.p = make(map[string]interface{}) + p.p["id"] = id + return p +} + +// Deletes a snapshot of a disk volume. +func (s *SnapshotService) DeleteSnapshot(p *DeleteSnapshotParams) (*DeleteSnapshotResponse, error) { + resp, err := s.cs.newRequest("deleteSnapshot", p.toURLValues()) + if err != nil { + return nil, err + } + + var r DeleteSnapshotResponse + if err := json.Unmarshal(resp, &r); err != nil { + return nil, err + } + + // If we have a async client, we need to wait for the async result + if s.cs.async { + b, err := s.cs.GetAsyncJobResult(r.JobID, s.cs.timeout) + if err != nil { + if err == AsyncTimeoutErr { + return &r, err + } + return nil, err + } + + if err := json.Unmarshal(b, &r); err != nil { + return nil, err + } + } + + return &r, nil +} + +type DeleteSnapshotResponse struct { + JobID string `json:"jobid"` + Displaytext string `json:"displaytext"` + Success bool `json:"success"` +} + +type DeleteSnapshotPoliciesParams struct { + p map[string]interface{} +} + +func (p *DeleteSnapshotPoliciesParams) toURLValues() url.Values { + u := url.Values{} + if p.p == nil { + return u + } + if v, found := p.p["id"]; found { + u.Set("id", v.(string)) + } + if v, found := p.p["ids"]; found { + vv := strings.Join(v.([]string), ",") + u.Set("ids", vv) + } + return u +} + +func (p *DeleteSnapshotPoliciesParams) SetId(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["id"] = v + return +} + +func (p *DeleteSnapshotPoliciesParams) SetIds(v []string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["ids"] = v + return +} + +// You should always use this function to get a new DeleteSnapshotPoliciesParams instance, +// as then you are sure you have configured all required params +func (s *SnapshotService) NewDeleteSnapshotPoliciesParams() *DeleteSnapshotPoliciesParams { + p := &DeleteSnapshotPoliciesParams{} + p.p = make(map[string]interface{}) + return p +} + +// Deletes snapshot policies for the account. +func (s *SnapshotService) DeleteSnapshotPolicies(p *DeleteSnapshotPoliciesParams) (*DeleteSnapshotPoliciesResponse, error) { + resp, err := s.cs.newRequest("deleteSnapshotPolicies", p.toURLValues()) + if err != nil { + return nil, err + } + + var r DeleteSnapshotPoliciesResponse + if err := json.Unmarshal(resp, &r); err != nil { + return nil, err + } + + return &r, nil +} + +type DeleteSnapshotPoliciesResponse struct { + Displaytext string `json:"displaytext"` + Success bool `json:"success"` +} + +func (r *DeleteSnapshotPoliciesResponse) UnmarshalJSON(b []byte) error { + var m map[string]interface{} + err := json.Unmarshal(b, &m) + if err != nil { + return err + } + + if success, ok := m["success"].(string); ok { + m["success"] = success == "true" + b, err = json.Marshal(m) + if err != nil { + return err + } + } + + type alias DeleteSnapshotPoliciesResponse + return json.Unmarshal(b, (*alias)(r)) +} + +type DeleteVMSnapshotParams struct { + p map[string]interface{} +} + +func (p *DeleteVMSnapshotParams) toURLValues() url.Values { + u := url.Values{} + if p.p == nil { + return u + } + if v, found := p.p["vmsnapshotid"]; found { + u.Set("vmsnapshotid", v.(string)) + } + return u +} + +func (p *DeleteVMSnapshotParams) SetVmsnapshotid(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["vmsnapshotid"] = v + return +} + +// You should always use this function to get a new DeleteVMSnapshotParams instance, +// as then you are sure you have configured all required params +func (s *SnapshotService) NewDeleteVMSnapshotParams(vmsnapshotid string) *DeleteVMSnapshotParams { + p := &DeleteVMSnapshotParams{} + p.p = make(map[string]interface{}) + p.p["vmsnapshotid"] = vmsnapshotid + return p +} + +// Deletes a vmsnapshot. +func (s *SnapshotService) DeleteVMSnapshot(p *DeleteVMSnapshotParams) (*DeleteVMSnapshotResponse, error) { + resp, err := s.cs.newRequest("deleteVMSnapshot", p.toURLValues()) + if err != nil { + return nil, err + } + + var r DeleteVMSnapshotResponse + if err := json.Unmarshal(resp, &r); err != nil { + return nil, err + } + + // If we have a async client, we need to wait for the async result + if s.cs.async { + b, err := s.cs.GetAsyncJobResult(r.JobID, s.cs.timeout) + if err != nil { + if err == AsyncTimeoutErr { + return &r, err + } + return nil, err + } + + if err := json.Unmarshal(b, &r); err != nil { + return nil, err + } + } + + return &r, nil +} + +type DeleteVMSnapshotResponse struct { + JobID string `json:"jobid"` + Displaytext string `json:"displaytext"` + Success bool `json:"success"` +} + +type ListSnapshotPoliciesParams struct { + p map[string]interface{} +} + +func (p *ListSnapshotPoliciesParams) toURLValues() url.Values { + u := url.Values{} + if p.p == nil { + return u + } + if v, found := p.p["fordisplay"]; found { + vv := strconv.FormatBool(v.(bool)) + u.Set("fordisplay", vv) + } + if v, found := p.p["id"]; found { + u.Set("id", v.(string)) + } + if v, found := p.p["keyword"]; found { + u.Set("keyword", v.(string)) + } + if v, found := p.p["page"]; found { + vv := strconv.Itoa(v.(int)) + u.Set("page", vv) + } + if v, found := p.p["pagesize"]; found { + vv := strconv.Itoa(v.(int)) + u.Set("pagesize", vv) + } + if v, found := p.p["volumeid"]; found { + u.Set("volumeid", v.(string)) + } + return u +} + +func (p *ListSnapshotPoliciesParams) SetFordisplay(v bool) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["fordisplay"] = v + return +} + +func (p *ListSnapshotPoliciesParams) SetId(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["id"] = v + return +} + +func (p *ListSnapshotPoliciesParams) SetKeyword(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["keyword"] = v + return +} + +func (p *ListSnapshotPoliciesParams) SetPage(v int) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["page"] = v + return +} + +func (p *ListSnapshotPoliciesParams) SetPagesize(v int) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["pagesize"] = v + return +} + +func (p *ListSnapshotPoliciesParams) SetVolumeid(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["volumeid"] = v + return +} + +// You should always use this function to get a new ListSnapshotPoliciesParams instance, +// as then you are sure you have configured all required params +func (s *SnapshotService) NewListSnapshotPoliciesParams() *ListSnapshotPoliciesParams { + p := &ListSnapshotPoliciesParams{} + p.p = make(map[string]interface{}) + return p +} + +// This is a courtesy helper function, which in some cases may not work as expected! +func (s *SnapshotService) GetSnapshotPolicyByID(id string, opts ...OptionFunc) (*SnapshotPolicy, int, error) { + p := &ListSnapshotPoliciesParams{} + p.p = make(map[string]interface{}) + + p.p["id"] = id + + for _, fn := range append(s.cs.options, opts...) { + if err := fn(s.cs, p); err != nil { + return nil, -1, err + } + } + + l, err := s.ListSnapshotPolicies(p) + if err != nil { + if strings.Contains(err.Error(), fmt.Sprintf( + "Invalid parameter id value=%s due to incorrect long value format, "+ + "or entity does not exist", id)) { + return nil, 0, fmt.Errorf("No match found for %s: %+v", id, l) + } + return nil, -1, err + } + + if l.Count == 0 { + return nil, l.Count, fmt.Errorf("No match found for %s: %+v", id, l) + } + + if l.Count == 1 { + return l.SnapshotPolicies[0], l.Count, nil + } + return nil, l.Count, fmt.Errorf("There is more then one result for SnapshotPolicy UUID: %s!", id) +} + +// Lists snapshot policies. +func (s *SnapshotService) ListSnapshotPolicies(p *ListSnapshotPoliciesParams) (*ListSnapshotPoliciesResponse, error) { + resp, err := s.cs.newRequest("listSnapshotPolicies", p.toURLValues()) + if err != nil { + return nil, err + } + + var r ListSnapshotPoliciesResponse + if err := json.Unmarshal(resp, &r); err != nil { + return nil, err + } + + return &r, nil +} + +type ListSnapshotPoliciesResponse struct { + Count int `json:"count"` + SnapshotPolicies []*SnapshotPolicy `json:"snapshotpolicy"` +} + +type SnapshotPolicy struct { + Fordisplay bool `json:"fordisplay"` + Id string `json:"id"` + Intervaltype int `json:"intervaltype"` + Maxsnaps int `json:"maxsnaps"` + Schedule string `json:"schedule"` + Timezone string `json:"timezone"` + Volumeid string `json:"volumeid"` } type ListSnapshotsParams struct { @@ -197,6 +836,10 @@ func (p *ListSnapshotsParams) toURLValues() url.Values { if v, found := p.p["id"]; found { u.Set("id", v.(string)) } + if v, found := p.p["ids"]; found { + vv := strings.Join(v.([]string), ",") + u.Set("ids", vv) + } if v, found := p.p["intervaltype"]; found { u.Set("intervaltype", v.(string)) } @@ -269,6 +912,14 @@ func (p *ListSnapshotsParams) SetId(v string) { return } +func (p *ListSnapshotsParams) SetIds(v []string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["ids"] = v + return +} + func (p *ListSnapshotsParams) SetIntervaltype(v string) { if p.p == nil { p.p = make(map[string]interface{}) @@ -380,7 +1031,7 @@ func (s *SnapshotService) GetSnapshotID(name string, opts ...OptionFunc) (string p.p["name"] = name - for _, fn := range opts { + for _, fn := range append(s.cs.options, opts...) { if err := fn(s.cs, p); err != nil { return "", -1, err } @@ -430,7 +1081,7 @@ func (s *SnapshotService) GetSnapshotByID(id string, opts ...OptionFunc) (*Snaps p.p["id"] = id - for _, fn := range opts { + for _, fn := range append(s.cs.options, opts...) { if err := fn(s.cs, p); err != nil { return nil, -1, err } @@ -467,6 +1118,7 @@ func (s *SnapshotService) ListSnapshots(p *ListSnapshotsParams) (*ListSnapshotsR if err := json.Unmarshal(resp, &r); err != nil { return nil, err } + return &r, nil } @@ -476,630 +1128,28 @@ type ListSnapshotsResponse struct { } type Snapshot struct { - Account string `json:"account,omitempty"` - Created string `json:"created,omitempty"` - Domain string `json:"domain,omitempty"` - Domainid string `json:"domainid,omitempty"` - Id string `json:"id,omitempty"` - Intervaltype string `json:"intervaltype,omitempty"` - Name string `json:"name,omitempty"` - Physicalsize int64 `json:"physicalsize,omitempty"` - Project string `json:"project,omitempty"` - Projectid string `json:"projectid,omitempty"` - Revertable bool `json:"revertable,omitempty"` - Snapshottype string `json:"snapshottype,omitempty"` - State string `json:"state,omitempty"` - Tags []struct { - Account string `json:"account,omitempty"` - Customer string `json:"customer,omitempty"` - Domain string `json:"domain,omitempty"` - Domainid string `json:"domainid,omitempty"` - Key string `json:"key,omitempty"` - Project string `json:"project,omitempty"` - Projectid string `json:"projectid,omitempty"` - Resourceid string `json:"resourceid,omitempty"` - Resourcetype string `json:"resourcetype,omitempty"` - Value string `json:"value,omitempty"` - } `json:"tags,omitempty"` - Volumeid string `json:"volumeid,omitempty"` - Volumename string `json:"volumename,omitempty"` - Volumetype string `json:"volumetype,omitempty"` - Zoneid string `json:"zoneid,omitempty"` -} - -type DeleteSnapshotParams struct { - p map[string]interface{} -} - -func (p *DeleteSnapshotParams) toURLValues() url.Values { - u := url.Values{} - if p.p == nil { - return u - } - if v, found := p.p["id"]; found { - u.Set("id", v.(string)) - } - return u -} - -func (p *DeleteSnapshotParams) SetId(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["id"] = v - return -} - -// You should always use this function to get a new DeleteSnapshotParams instance, -// as then you are sure you have configured all required params -func (s *SnapshotService) NewDeleteSnapshotParams(id string) *DeleteSnapshotParams { - p := &DeleteSnapshotParams{} - p.p = make(map[string]interface{}) - p.p["id"] = id - return p -} - -// Deletes a snapshot of a disk volume. -func (s *SnapshotService) DeleteSnapshot(p *DeleteSnapshotParams) (*DeleteSnapshotResponse, error) { - resp, err := s.cs.newRequest("deleteSnapshot", p.toURLValues()) - if err != nil { - return nil, err - } - - var r DeleteSnapshotResponse - if err := json.Unmarshal(resp, &r); err != nil { - return nil, err - } - - // If we have a async client, we need to wait for the async result - if s.cs.async { - b, err := s.cs.GetAsyncJobResult(r.JobID, s.cs.timeout) - if err != nil { - if err == AsyncTimeoutErr { - return &r, err - } - return nil, err - } - - if err := json.Unmarshal(b, &r); err != nil { - return nil, err - } - } - return &r, nil -} - -type DeleteSnapshotResponse struct { - JobID string `json:"jobid,omitempty"` - Displaytext string `json:"displaytext,omitempty"` - Success bool `json:"success,omitempty"` -} - -type CreateSnapshotPolicyParams struct { - p map[string]interface{} -} - -func (p *CreateSnapshotPolicyParams) toURLValues() url.Values { - u := url.Values{} - if p.p == nil { - return u - } - if v, found := p.p["fordisplay"]; found { - vv := strconv.FormatBool(v.(bool)) - u.Set("fordisplay", vv) - } - if v, found := p.p["intervaltype"]; found { - u.Set("intervaltype", v.(string)) - } - if v, found := p.p["maxsnaps"]; found { - vv := strconv.Itoa(v.(int)) - u.Set("maxsnaps", vv) - } - if v, found := p.p["schedule"]; found { - u.Set("schedule", v.(string)) - } - if v, found := p.p["timezone"]; found { - u.Set("timezone", v.(string)) - } - if v, found := p.p["volumeid"]; found { - u.Set("volumeid", v.(string)) - } - return u -} - -func (p *CreateSnapshotPolicyParams) SetFordisplay(v bool) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["fordisplay"] = v - return -} - -func (p *CreateSnapshotPolicyParams) SetIntervaltype(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["intervaltype"] = v - return -} - -func (p *CreateSnapshotPolicyParams) SetMaxsnaps(v int) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["maxsnaps"] = v - return -} - -func (p *CreateSnapshotPolicyParams) SetSchedule(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["schedule"] = v - return -} - -func (p *CreateSnapshotPolicyParams) SetTimezone(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["timezone"] = v - return -} - -func (p *CreateSnapshotPolicyParams) SetVolumeid(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["volumeid"] = v - return -} - -// You should always use this function to get a new CreateSnapshotPolicyParams instance, -// as then you are sure you have configured all required params -func (s *SnapshotService) NewCreateSnapshotPolicyParams(intervaltype string, maxsnaps int, schedule string, timezone string, volumeid string) *CreateSnapshotPolicyParams { - p := &CreateSnapshotPolicyParams{} - p.p = make(map[string]interface{}) - p.p["intervaltype"] = intervaltype - p.p["maxsnaps"] = maxsnaps - p.p["schedule"] = schedule - p.p["timezone"] = timezone - p.p["volumeid"] = volumeid - return p -} - -// Creates a snapshot policy for the account. -func (s *SnapshotService) CreateSnapshotPolicy(p *CreateSnapshotPolicyParams) (*CreateSnapshotPolicyResponse, error) { - resp, err := s.cs.newRequest("createSnapshotPolicy", p.toURLValues()) - if err != nil { - return nil, err - } - - var r CreateSnapshotPolicyResponse - if err := json.Unmarshal(resp, &r); err != nil { - return nil, err - } - return &r, nil -} - -type CreateSnapshotPolicyResponse struct { - Fordisplay bool `json:"fordisplay,omitempty"` - Id string `json:"id,omitempty"` - Intervaltype int `json:"intervaltype,omitempty"` - Maxsnaps int `json:"maxsnaps,omitempty"` - Schedule string `json:"schedule,omitempty"` - Timezone string `json:"timezone,omitempty"` - Volumeid string `json:"volumeid,omitempty"` -} - -type UpdateSnapshotPolicyParams struct { - p map[string]interface{} -} - -func (p *UpdateSnapshotPolicyParams) toURLValues() url.Values { - u := url.Values{} - if p.p == nil { - return u - } - if v, found := p.p["customid"]; found { - u.Set("customid", v.(string)) - } - if v, found := p.p["fordisplay"]; found { - vv := strconv.FormatBool(v.(bool)) - u.Set("fordisplay", vv) - } - if v, found := p.p["id"]; found { - u.Set("id", v.(string)) - } - return u -} - -func (p *UpdateSnapshotPolicyParams) SetCustomid(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["customid"] = v - return -} - -func (p *UpdateSnapshotPolicyParams) SetFordisplay(v bool) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["fordisplay"] = v - return -} - -func (p *UpdateSnapshotPolicyParams) SetId(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["id"] = v - return -} - -// You should always use this function to get a new UpdateSnapshotPolicyParams instance, -// as then you are sure you have configured all required params -func (s *SnapshotService) NewUpdateSnapshotPolicyParams() *UpdateSnapshotPolicyParams { - p := &UpdateSnapshotPolicyParams{} - p.p = make(map[string]interface{}) - return p -} - -// Updates the snapshot policy. -func (s *SnapshotService) UpdateSnapshotPolicy(p *UpdateSnapshotPolicyParams) (*UpdateSnapshotPolicyResponse, error) { - resp, err := s.cs.newRequest("updateSnapshotPolicy", p.toURLValues()) - if err != nil { - return nil, err - } - - var r UpdateSnapshotPolicyResponse - if err := json.Unmarshal(resp, &r); err != nil { - return nil, err - } - - // If we have a async client, we need to wait for the async result - if s.cs.async { - b, err := s.cs.GetAsyncJobResult(r.JobID, s.cs.timeout) - if err != nil { - if err == AsyncTimeoutErr { - return &r, err - } - return nil, err - } - - b, err = getRawValue(b) - if err != nil { - return nil, err - } - - if err := json.Unmarshal(b, &r); err != nil { - return nil, err - } - } - return &r, nil -} - -type UpdateSnapshotPolicyResponse struct { - JobID string `json:"jobid,omitempty"` - Fordisplay bool `json:"fordisplay,omitempty"` - Id string `json:"id,omitempty"` - Intervaltype int `json:"intervaltype,omitempty"` - Maxsnaps int `json:"maxsnaps,omitempty"` - Schedule string `json:"schedule,omitempty"` - Timezone string `json:"timezone,omitempty"` - Volumeid string `json:"volumeid,omitempty"` -} - -type DeleteSnapshotPoliciesParams struct { - p map[string]interface{} -} - -func (p *DeleteSnapshotPoliciesParams) toURLValues() url.Values { - u := url.Values{} - if p.p == nil { - return u - } - if v, found := p.p["id"]; found { - u.Set("id", v.(string)) - } - if v, found := p.p["ids"]; found { - vv := strings.Join(v.([]string), ",") - u.Set("ids", vv) - } - return u -} - -func (p *DeleteSnapshotPoliciesParams) SetId(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["id"] = v - return -} - -func (p *DeleteSnapshotPoliciesParams) SetIds(v []string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["ids"] = v - return -} - -// You should always use this function to get a new DeleteSnapshotPoliciesParams instance, -// as then you are sure you have configured all required params -func (s *SnapshotService) NewDeleteSnapshotPoliciesParams() *DeleteSnapshotPoliciesParams { - p := &DeleteSnapshotPoliciesParams{} - p.p = make(map[string]interface{}) - return p -} - -// Deletes snapshot policies for the account. -func (s *SnapshotService) DeleteSnapshotPolicies(p *DeleteSnapshotPoliciesParams) (*DeleteSnapshotPoliciesResponse, error) { - resp, err := s.cs.newRequest("deleteSnapshotPolicies", p.toURLValues()) - if err != nil { - return nil, err - } - - var r DeleteSnapshotPoliciesResponse - if err := json.Unmarshal(resp, &r); err != nil { - return nil, err - } - return &r, nil -} - -type DeleteSnapshotPoliciesResponse struct { - Displaytext string `json:"displaytext,omitempty"` - Success string `json:"success,omitempty"` -} - -type ListSnapshotPoliciesParams struct { - p map[string]interface{} -} - -func (p *ListSnapshotPoliciesParams) toURLValues() url.Values { - u := url.Values{} - if p.p == nil { - return u - } - if v, found := p.p["fordisplay"]; found { - vv := strconv.FormatBool(v.(bool)) - u.Set("fordisplay", vv) - } - if v, found := p.p["id"]; found { - u.Set("id", v.(string)) - } - if v, found := p.p["keyword"]; found { - u.Set("keyword", v.(string)) - } - if v, found := p.p["page"]; found { - vv := strconv.Itoa(v.(int)) - u.Set("page", vv) - } - if v, found := p.p["pagesize"]; found { - vv := strconv.Itoa(v.(int)) - u.Set("pagesize", vv) - } - if v, found := p.p["volumeid"]; found { - u.Set("volumeid", v.(string)) - } - return u -} - -func (p *ListSnapshotPoliciesParams) SetFordisplay(v bool) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["fordisplay"] = v - return -} - -func (p *ListSnapshotPoliciesParams) SetId(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["id"] = v - return -} - -func (p *ListSnapshotPoliciesParams) SetKeyword(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["keyword"] = v - return -} - -func (p *ListSnapshotPoliciesParams) SetPage(v int) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["page"] = v - return -} - -func (p *ListSnapshotPoliciesParams) SetPagesize(v int) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["pagesize"] = v - return -} - -func (p *ListSnapshotPoliciesParams) SetVolumeid(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["volumeid"] = v - return -} - -// You should always use this function to get a new ListSnapshotPoliciesParams instance, -// as then you are sure you have configured all required params -func (s *SnapshotService) NewListSnapshotPoliciesParams() *ListSnapshotPoliciesParams { - p := &ListSnapshotPoliciesParams{} - p.p = make(map[string]interface{}) - return p -} - -// This is a courtesy helper function, which in some cases may not work as expected! -func (s *SnapshotService) GetSnapshotPolicyByID(id string, opts ...OptionFunc) (*SnapshotPolicy, int, error) { - p := &ListSnapshotPoliciesParams{} - p.p = make(map[string]interface{}) - - p.p["id"] = id - - for _, fn := range opts { - if err := fn(s.cs, p); err != nil { - return nil, -1, err - } - } - - l, err := s.ListSnapshotPolicies(p) - if err != nil { - if strings.Contains(err.Error(), fmt.Sprintf( - "Invalid parameter id value=%s due to incorrect long value format, "+ - "or entity does not exist", id)) { - return nil, 0, fmt.Errorf("No match found for %s: %+v", id, l) - } - return nil, -1, err - } - - if l.Count == 0 { - return nil, l.Count, fmt.Errorf("No match found for %s: %+v", id, l) - } - - if l.Count == 1 { - return l.SnapshotPolicies[0], l.Count, nil - } - return nil, l.Count, fmt.Errorf("There is more then one result for SnapshotPolicy UUID: %s!", id) -} - -// Lists snapshot policies. -func (s *SnapshotService) ListSnapshotPolicies(p *ListSnapshotPoliciesParams) (*ListSnapshotPoliciesResponse, error) { - resp, err := s.cs.newRequest("listSnapshotPolicies", p.toURLValues()) - if err != nil { - return nil, err - } - - var r ListSnapshotPoliciesResponse - if err := json.Unmarshal(resp, &r); err != nil { - return nil, err - } - return &r, nil -} - -type ListSnapshotPoliciesResponse struct { - Count int `json:"count"` - SnapshotPolicies []*SnapshotPolicy `json:"snapshotpolicy"` -} - -type SnapshotPolicy struct { - Fordisplay bool `json:"fordisplay,omitempty"` - Id string `json:"id,omitempty"` - Intervaltype int `json:"intervaltype,omitempty"` - Maxsnaps int `json:"maxsnaps,omitempty"` - Schedule string `json:"schedule,omitempty"` - Timezone string `json:"timezone,omitempty"` - Volumeid string `json:"volumeid,omitempty"` -} - -type RevertSnapshotParams struct { - p map[string]interface{} -} - -func (p *RevertSnapshotParams) toURLValues() url.Values { - u := url.Values{} - if p.p == nil { - return u - } - if v, found := p.p["id"]; found { - u.Set("id", v.(string)) - } - return u -} - -func (p *RevertSnapshotParams) SetId(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["id"] = v - return -} - -// You should always use this function to get a new RevertSnapshotParams instance, -// as then you are sure you have configured all required params -func (s *SnapshotService) NewRevertSnapshotParams(id string) *RevertSnapshotParams { - p := &RevertSnapshotParams{} - p.p = make(map[string]interface{}) - p.p["id"] = id - return p -} - -// revert a volume snapshot. -func (s *SnapshotService) RevertSnapshot(p *RevertSnapshotParams) (*RevertSnapshotResponse, error) { - resp, err := s.cs.newRequest("revertSnapshot", p.toURLValues()) - if err != nil { - return nil, err - } - - var r RevertSnapshotResponse - if err := json.Unmarshal(resp, &r); err != nil { - return nil, err - } - - // If we have a async client, we need to wait for the async result - if s.cs.async { - b, err := s.cs.GetAsyncJobResult(r.JobID, s.cs.timeout) - if err != nil { - if err == AsyncTimeoutErr { - return &r, err - } - return nil, err - } - - b, err = getRawValue(b) - if err != nil { - return nil, err - } - - if err := json.Unmarshal(b, &r); err != nil { - return nil, err - } - } - return &r, nil -} - -type RevertSnapshotResponse struct { - JobID string `json:"jobid,omitempty"` - Account string `json:"account,omitempty"` - Created string `json:"created,omitempty"` - Domain string `json:"domain,omitempty"` - Domainid string `json:"domainid,omitempty"` - Id string `json:"id,omitempty"` - Intervaltype string `json:"intervaltype,omitempty"` - Name string `json:"name,omitempty"` - Physicalsize int64 `json:"physicalsize,omitempty"` - Project string `json:"project,omitempty"` - Projectid string `json:"projectid,omitempty"` - Revertable bool `json:"revertable,omitempty"` - Snapshottype string `json:"snapshottype,omitempty"` - State string `json:"state,omitempty"` - Tags []struct { - Account string `json:"account,omitempty"` - Customer string `json:"customer,omitempty"` - Domain string `json:"domain,omitempty"` - Domainid string `json:"domainid,omitempty"` - Key string `json:"key,omitempty"` - Project string `json:"project,omitempty"` - Projectid string `json:"projectid,omitempty"` - Resourceid string `json:"resourceid,omitempty"` - Resourcetype string `json:"resourcetype,omitempty"` - Value string `json:"value,omitempty"` - } `json:"tags,omitempty"` - Volumeid string `json:"volumeid,omitempty"` - Volumename string `json:"volumename,omitempty"` - Volumetype string `json:"volumetype,omitempty"` - Zoneid string `json:"zoneid,omitempty"` + Account string `json:"account"` + Created string `json:"created"` + Domain string `json:"domain"` + Domainid string `json:"domainid"` + Id string `json:"id"` + Intervaltype string `json:"intervaltype"` + Locationtype string `json:"locationtype"` + Name string `json:"name"` + Osdisplayname string `json:"osdisplayname"` + Ostypeid string `json:"ostypeid"` + Physicalsize int64 `json:"physicalsize"` + Project string `json:"project"` + Projectid string `json:"projectid"` + Revertable bool `json:"revertable"` + Snapshottype string `json:"snapshottype"` + State string `json:"state"` + Tags []Tags `json:"tags"` + Virtualsize int64 `json:"virtualsize"` + Volumeid string `json:"volumeid"` + Volumename string `json:"volumename"` + Volumetype string `json:"volumetype"` + Zoneid string `json:"zoneid"` } type ListVMSnapshotParams struct { @@ -1159,6 +1209,10 @@ func (p *ListVMSnapshotParams) toURLValues() url.Values { if v, found := p.p["vmsnapshotid"]; found { u.Set("vmsnapshotid", v.(string)) } + if v, found := p.p["vmsnapshotids"]; found { + vv := strings.Join(v.([]string), ",") + u.Set("vmsnapshotids", vv) + } return u } @@ -1266,6 +1320,14 @@ func (p *ListVMSnapshotParams) SetVmsnapshotid(v string) { return } +func (p *ListVMSnapshotParams) SetVmsnapshotids(v []string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["vmsnapshotids"] = v + return +} + // You should always use this function to get a new ListVMSnapshotParams instance, // as then you are sure you have configured all required params func (s *SnapshotService) NewListVMSnapshotParams() *ListVMSnapshotParams { @@ -1281,7 +1343,7 @@ func (s *SnapshotService) GetVMSnapshotID(name string, opts ...OptionFunc) (stri p.p["name"] = name - for _, fn := range opts { + for _, fn := range append(s.cs.options, opts...) { if err := fn(s.cs, p); err != nil { return "", -1, err } @@ -1321,6 +1383,7 @@ func (s *SnapshotService) ListVMSnapshot(p *ListVMSnapshotParams) (*ListVMSnapsh if err := json.Unmarshal(resp, &r); err != nil { return nil, err } + return &r, nil } @@ -1330,111 +1393,65 @@ type ListVMSnapshotResponse struct { } type VMSnapshot struct { - Account string `json:"account,omitempty"` - Created string `json:"created,omitempty"` - Current bool `json:"current,omitempty"` - Description string `json:"description,omitempty"` - Displayname string `json:"displayname,omitempty"` - Domain string `json:"domain,omitempty"` - Domainid string `json:"domainid,omitempty"` - Id string `json:"id,omitempty"` - Name string `json:"name,omitempty"` - Parent string `json:"parent,omitempty"` - ParentName string `json:"parentName,omitempty"` - Project string `json:"project,omitempty"` - Projectid string `json:"projectid,omitempty"` - State string `json:"state,omitempty"` - Type string `json:"type,omitempty"` - Virtualmachineid string `json:"virtualmachineid,omitempty"` - Zoneid string `json:"zoneid,omitempty"` + Account string `json:"account"` + Created string `json:"created"` + Current bool `json:"current"` + Description string `json:"description"` + Displayname string `json:"displayname"` + Domain string `json:"domain"` + Domainid string `json:"domainid"` + Id string `json:"id"` + Name string `json:"name"` + Parent string `json:"parent"` + ParentName string `json:"parentName"` + Project string `json:"project"` + Projectid string `json:"projectid"` + State string `json:"state"` + Type string `json:"type"` + Virtualmachineid string `json:"virtualmachineid"` + Zoneid string `json:"zoneid"` } -type CreateVMSnapshotParams struct { +type RevertSnapshotParams struct { p map[string]interface{} } -func (p *CreateVMSnapshotParams) toURLValues() url.Values { +func (p *RevertSnapshotParams) toURLValues() url.Values { u := url.Values{} if p.p == nil { return u } - if v, found := p.p["description"]; found { - u.Set("description", v.(string)) - } - if v, found := p.p["name"]; found { - u.Set("name", v.(string)) - } - if v, found := p.p["quiescevm"]; found { - vv := strconv.FormatBool(v.(bool)) - u.Set("quiescevm", vv) - } - if v, found := p.p["snapshotmemory"]; found { - vv := strconv.FormatBool(v.(bool)) - u.Set("snapshotmemory", vv) - } - if v, found := p.p["virtualmachineid"]; found { - u.Set("virtualmachineid", v.(string)) + if v, found := p.p["id"]; found { + u.Set("id", v.(string)) } return u } -func (p *CreateVMSnapshotParams) SetDescription(v string) { +func (p *RevertSnapshotParams) SetId(v string) { if p.p == nil { p.p = make(map[string]interface{}) } - p.p["description"] = v + p.p["id"] = v return } -func (p *CreateVMSnapshotParams) SetName(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["name"] = v - return -} - -func (p *CreateVMSnapshotParams) SetQuiescevm(v bool) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["quiescevm"] = v - return -} - -func (p *CreateVMSnapshotParams) SetSnapshotmemory(v bool) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["snapshotmemory"] = v - return -} - -func (p *CreateVMSnapshotParams) SetVirtualmachineid(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["virtualmachineid"] = v - return -} - -// You should always use this function to get a new CreateVMSnapshotParams instance, +// You should always use this function to get a new RevertSnapshotParams instance, // as then you are sure you have configured all required params -func (s *SnapshotService) NewCreateVMSnapshotParams(virtualmachineid string) *CreateVMSnapshotParams { - p := &CreateVMSnapshotParams{} +func (s *SnapshotService) NewRevertSnapshotParams(id string) *RevertSnapshotParams { + p := &RevertSnapshotParams{} p.p = make(map[string]interface{}) - p.p["virtualmachineid"] = virtualmachineid + p.p["id"] = id return p } -// Creates snapshot for a vm. -func (s *SnapshotService) CreateVMSnapshot(p *CreateVMSnapshotParams) (*CreateVMSnapshotResponse, error) { - resp, err := s.cs.newRequest("createVMSnapshot", p.toURLValues()) +// This is supposed to revert a volume snapshot. This command is only supported with KVM so far +func (s *SnapshotService) RevertSnapshot(p *RevertSnapshotParams) (*RevertSnapshotResponse, error) { + resp, err := s.cs.newRequest("revertSnapshot", p.toURLValues()) if err != nil { return nil, err } - var r CreateVMSnapshotResponse + var r RevertSnapshotResponse if err := json.Unmarshal(resp, &r); err != nil { return nil, err } @@ -1458,95 +1475,34 @@ func (s *SnapshotService) CreateVMSnapshot(p *CreateVMSnapshotParams) (*CreateVM return nil, err } } + return &r, nil } -type CreateVMSnapshotResponse struct { - JobID string `json:"jobid,omitempty"` - Account string `json:"account,omitempty"` - Created string `json:"created,omitempty"` - Current bool `json:"current,omitempty"` - Description string `json:"description,omitempty"` - Displayname string `json:"displayname,omitempty"` - Domain string `json:"domain,omitempty"` - Domainid string `json:"domainid,omitempty"` - Id string `json:"id,omitempty"` - Name string `json:"name,omitempty"` - Parent string `json:"parent,omitempty"` - ParentName string `json:"parentName,omitempty"` - Project string `json:"project,omitempty"` - Projectid string `json:"projectid,omitempty"` - State string `json:"state,omitempty"` - Type string `json:"type,omitempty"` - Virtualmachineid string `json:"virtualmachineid,omitempty"` - Zoneid string `json:"zoneid,omitempty"` -} - -type DeleteVMSnapshotParams struct { - p map[string]interface{} -} - -func (p *DeleteVMSnapshotParams) toURLValues() url.Values { - u := url.Values{} - if p.p == nil { - return u - } - if v, found := p.p["vmsnapshotid"]; found { - u.Set("vmsnapshotid", v.(string)) - } - return u -} - -func (p *DeleteVMSnapshotParams) SetVmsnapshotid(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["vmsnapshotid"] = v - return -} - -// You should always use this function to get a new DeleteVMSnapshotParams instance, -// as then you are sure you have configured all required params -func (s *SnapshotService) NewDeleteVMSnapshotParams(vmsnapshotid string) *DeleteVMSnapshotParams { - p := &DeleteVMSnapshotParams{} - p.p = make(map[string]interface{}) - p.p["vmsnapshotid"] = vmsnapshotid - return p -} - -// Deletes a vmsnapshot. -func (s *SnapshotService) DeleteVMSnapshot(p *DeleteVMSnapshotParams) (*DeleteVMSnapshotResponse, error) { - resp, err := s.cs.newRequest("deleteVMSnapshot", p.toURLValues()) - if err != nil { - return nil, err - } - - var r DeleteVMSnapshotResponse - if err := json.Unmarshal(resp, &r); err != nil { - return nil, err - } - - // If we have a async client, we need to wait for the async result - if s.cs.async { - b, err := s.cs.GetAsyncJobResult(r.JobID, s.cs.timeout) - if err != nil { - if err == AsyncTimeoutErr { - return &r, err - } - return nil, err - } - - if err := json.Unmarshal(b, &r); err != nil { - return nil, err - } - } - return &r, nil -} - -type DeleteVMSnapshotResponse struct { - JobID string `json:"jobid,omitempty"` - Displaytext string `json:"displaytext,omitempty"` - Success bool `json:"success,omitempty"` +type RevertSnapshotResponse struct { + JobID string `json:"jobid"` + Account string `json:"account"` + Created string `json:"created"` + Domain string `json:"domain"` + Domainid string `json:"domainid"` + Id string `json:"id"` + Intervaltype string `json:"intervaltype"` + Locationtype string `json:"locationtype"` + Name string `json:"name"` + Osdisplayname string `json:"osdisplayname"` + Ostypeid string `json:"ostypeid"` + Physicalsize int64 `json:"physicalsize"` + Project string `json:"project"` + Projectid string `json:"projectid"` + Revertable bool `json:"revertable"` + Snapshottype string `json:"snapshottype"` + State string `json:"state"` + Tags []Tags `json:"tags"` + Virtualsize int64 `json:"virtualsize"` + Volumeid string `json:"volumeid"` + Volumename string `json:"volumename"` + Volumetype string `json:"volumetype"` + Zoneid string `json:"zoneid"` } type RevertToVMSnapshotParams struct { @@ -1612,182 +1568,214 @@ func (s *SnapshotService) RevertToVMSnapshot(p *RevertToVMSnapshotParams) (*Reve return nil, err } } + return &r, nil } type RevertToVMSnapshotResponse struct { - JobID string `json:"jobid,omitempty"` - Account string `json:"account,omitempty"` - Affinitygroup []struct { - Account string `json:"account,omitempty"` - Description string `json:"description,omitempty"` - Domain string `json:"domain,omitempty"` - Domainid string `json:"domainid,omitempty"` - Id string `json:"id,omitempty"` - Name string `json:"name,omitempty"` - Project string `json:"project,omitempty"` - Projectid string `json:"projectid,omitempty"` - Type string `json:"type,omitempty"` - VirtualmachineIds []string `json:"virtualmachineIds,omitempty"` - } `json:"affinitygroup,omitempty"` - Cpunumber int `json:"cpunumber,omitempty"` - Cpuspeed int `json:"cpuspeed,omitempty"` - Cpuused string `json:"cpuused,omitempty"` - Created string `json:"created,omitempty"` - Details map[string]string `json:"details,omitempty"` - Diskioread int64 `json:"diskioread,omitempty"` - Diskiowrite int64 `json:"diskiowrite,omitempty"` - Diskkbsread int64 `json:"diskkbsread,omitempty"` - Diskkbswrite int64 `json:"diskkbswrite,omitempty"` - Diskofferingid string `json:"diskofferingid,omitempty"` - Diskofferingname string `json:"diskofferingname,omitempty"` - Displayname string `json:"displayname,omitempty"` - Displayvm bool `json:"displayvm,omitempty"` - Domain string `json:"domain,omitempty"` - Domainid string `json:"domainid,omitempty"` - Forvirtualnetwork bool `json:"forvirtualnetwork,omitempty"` - Group string `json:"group,omitempty"` - Groupid string `json:"groupid,omitempty"` - Guestosid string `json:"guestosid,omitempty"` - Haenable bool `json:"haenable,omitempty"` - Hostid string `json:"hostid,omitempty"` - Hostname string `json:"hostname,omitempty"` - Hypervisor string `json:"hypervisor,omitempty"` - Id string `json:"id,omitempty"` - Instancename string `json:"instancename,omitempty"` - Isdynamicallyscalable bool `json:"isdynamicallyscalable,omitempty"` - Isodisplaytext string `json:"isodisplaytext,omitempty"` - Isoid string `json:"isoid,omitempty"` - Isoname string `json:"isoname,omitempty"` - Keypair string `json:"keypair,omitempty"` - Memory int `json:"memory,omitempty"` - Name string `json:"name,omitempty"` - Networkkbsread int64 `json:"networkkbsread,omitempty"` - Networkkbswrite int64 `json:"networkkbswrite,omitempty"` - Nic []struct { - Broadcasturi string `json:"broadcasturi,omitempty"` - Deviceid string `json:"deviceid,omitempty"` - Gateway string `json:"gateway,omitempty"` - Id string `json:"id,omitempty"` - Ip6address string `json:"ip6address,omitempty"` - Ip6cidr string `json:"ip6cidr,omitempty"` - Ip6gateway string `json:"ip6gateway,omitempty"` - Ipaddress string `json:"ipaddress,omitempty"` - Isdefault bool `json:"isdefault,omitempty"` - Isolationuri string `json:"isolationuri,omitempty"` - Macaddress string `json:"macaddress,omitempty"` - Netmask string `json:"netmask,omitempty"` - Networkid string `json:"networkid,omitempty"` - Networkname string `json:"networkname,omitempty"` - Secondaryip []struct { - Id string `json:"id,omitempty"` - Ipaddress string `json:"ipaddress,omitempty"` - } `json:"secondaryip,omitempty"` - Traffictype string `json:"traffictype,omitempty"` - Type string `json:"type,omitempty"` - Virtualmachineid string `json:"virtualmachineid,omitempty"` - } `json:"nic,omitempty"` - Ostypeid int64 `json:"ostypeid,omitempty"` - Password string `json:"password,omitempty"` - Passwordenabled bool `json:"passwordenabled,omitempty"` - Project string `json:"project,omitempty"` - Projectid string `json:"projectid,omitempty"` - Publicip string `json:"publicip,omitempty"` - Publicipid string `json:"publicipid,omitempty"` - Rootdeviceid int64 `json:"rootdeviceid,omitempty"` - Rootdevicetype string `json:"rootdevicetype,omitempty"` - Securitygroup []struct { - Account string `json:"account,omitempty"` - Description string `json:"description,omitempty"` - Domain string `json:"domain,omitempty"` - Domainid string `json:"domainid,omitempty"` - Egressrule []struct { - Account string `json:"account,omitempty"` - Cidr string `json:"cidr,omitempty"` - Endport int `json:"endport,omitempty"` - Icmpcode int `json:"icmpcode,omitempty"` - Icmptype int `json:"icmptype,omitempty"` - Protocol string `json:"protocol,omitempty"` - Ruleid string `json:"ruleid,omitempty"` - Securitygroupname string `json:"securitygroupname,omitempty"` - Startport int `json:"startport,omitempty"` - Tags []struct { - Account string `json:"account,omitempty"` - Customer string `json:"customer,omitempty"` - Domain string `json:"domain,omitempty"` - Domainid string `json:"domainid,omitempty"` - Key string `json:"key,omitempty"` - Project string `json:"project,omitempty"` - Projectid string `json:"projectid,omitempty"` - Resourceid string `json:"resourceid,omitempty"` - Resourcetype string `json:"resourcetype,omitempty"` - Value string `json:"value,omitempty"` - } `json:"tags,omitempty"` - } `json:"egressrule,omitempty"` - Id string `json:"id,omitempty"` - Ingressrule []struct { - Account string `json:"account,omitempty"` - Cidr string `json:"cidr,omitempty"` - Endport int `json:"endport,omitempty"` - Icmpcode int `json:"icmpcode,omitempty"` - Icmptype int `json:"icmptype,omitempty"` - Protocol string `json:"protocol,omitempty"` - Ruleid string `json:"ruleid,omitempty"` - Securitygroupname string `json:"securitygroupname,omitempty"` - Startport int `json:"startport,omitempty"` - Tags []struct { - Account string `json:"account,omitempty"` - Customer string `json:"customer,omitempty"` - Domain string `json:"domain,omitempty"` - Domainid string `json:"domainid,omitempty"` - Key string `json:"key,omitempty"` - Project string `json:"project,omitempty"` - Projectid string `json:"projectid,omitempty"` - Resourceid string `json:"resourceid,omitempty"` - Resourcetype string `json:"resourcetype,omitempty"` - Value string `json:"value,omitempty"` - } `json:"tags,omitempty"` - } `json:"ingressrule,omitempty"` - Name string `json:"name,omitempty"` - Project string `json:"project,omitempty"` - Projectid string `json:"projectid,omitempty"` - Tags []struct { - Account string `json:"account,omitempty"` - Customer string `json:"customer,omitempty"` - Domain string `json:"domain,omitempty"` - Domainid string `json:"domainid,omitempty"` - Key string `json:"key,omitempty"` - Project string `json:"project,omitempty"` - Projectid string `json:"projectid,omitempty"` - Resourceid string `json:"resourceid,omitempty"` - Resourcetype string `json:"resourcetype,omitempty"` - Value string `json:"value,omitempty"` - } `json:"tags,omitempty"` - Virtualmachinecount int `json:"virtualmachinecount,omitempty"` - Virtualmachineids []string `json:"virtualmachineids,omitempty"` - } `json:"securitygroup,omitempty"` - Serviceofferingid string `json:"serviceofferingid,omitempty"` - Serviceofferingname string `json:"serviceofferingname,omitempty"` - Servicestate string `json:"servicestate,omitempty"` - State string `json:"state,omitempty"` - Tags []struct { - Account string `json:"account,omitempty"` - Customer string `json:"customer,omitempty"` - Domain string `json:"domain,omitempty"` - Domainid string `json:"domainid,omitempty"` - Key string `json:"key,omitempty"` - Project string `json:"project,omitempty"` - Projectid string `json:"projectid,omitempty"` - Resourceid string `json:"resourceid,omitempty"` - Resourcetype string `json:"resourcetype,omitempty"` - Value string `json:"value,omitempty"` - } `json:"tags,omitempty"` - Templatedisplaytext string `json:"templatedisplaytext,omitempty"` - Templateid string `json:"templateid,omitempty"` - Templatename string `json:"templatename,omitempty"` - Userid string `json:"userid,omitempty"` - Username string `json:"username,omitempty"` - Vgpu string `json:"vgpu,omitempty"` - Zoneid string `json:"zoneid,omitempty"` - Zonename string `json:"zonename,omitempty"` + JobID string `json:"jobid"` + Account string `json:"account"` + Affinitygroup []RevertToVMSnapshotResponseAffinitygroup `json:"affinitygroup"` + Cpunumber int `json:"cpunumber"` + Cpuspeed int `json:"cpuspeed"` + Cpuused string `json:"cpuused"` + Created string `json:"created"` + Details map[string]string `json:"details"` + Diskioread int64 `json:"diskioread"` + Diskiowrite int64 `json:"diskiowrite"` + Diskkbsread int64 `json:"diskkbsread"` + Diskkbswrite int64 `json:"diskkbswrite"` + Diskofferingid string `json:"diskofferingid"` + Diskofferingname string `json:"diskofferingname"` + Displayname string `json:"displayname"` + Displayvm bool `json:"displayvm"` + Domain string `json:"domain"` + Domainid string `json:"domainid"` + Forvirtualnetwork bool `json:"forvirtualnetwork"` + Group string `json:"group"` + Groupid string `json:"groupid"` + Guestosid string `json:"guestosid"` + Haenable bool `json:"haenable"` + Hostid string `json:"hostid"` + Hostname string `json:"hostname"` + Hypervisor string `json:"hypervisor"` + Id string `json:"id"` + Instancename string `json:"instancename"` + Isdynamicallyscalable bool `json:"isdynamicallyscalable"` + Isodisplaytext string `json:"isodisplaytext"` + Isoid string `json:"isoid"` + Isoname string `json:"isoname"` + Keypair string `json:"keypair"` + Memory int `json:"memory"` + Memoryintfreekbs int64 `json:"memoryintfreekbs"` + Memorykbs int64 `json:"memorykbs"` + Memorytargetkbs int64 `json:"memorytargetkbs"` + Name string `json:"name"` + Networkkbsread int64 `json:"networkkbsread"` + Networkkbswrite int64 `json:"networkkbswrite"` + Nic []Nic `json:"nic"` + Ostypeid int64 `json:"ostypeid"` + Password string `json:"password"` + Passwordenabled bool `json:"passwordenabled"` + Project string `json:"project"` + Projectid string `json:"projectid"` + Publicip string `json:"publicip"` + Publicipid string `json:"publicipid"` + Rootdeviceid int64 `json:"rootdeviceid"` + Rootdevicetype string `json:"rootdevicetype"` + Securitygroup []RevertToVMSnapshotResponseSecuritygroup `json:"securitygroup"` + Serviceofferingid string `json:"serviceofferingid"` + Serviceofferingname string `json:"serviceofferingname"` + Servicestate string `json:"servicestate"` + State string `json:"state"` + Templatedisplaytext string `json:"templatedisplaytext"` + Templateid string `json:"templateid"` + Templatename string `json:"templatename"` + Userid string `json:"userid"` + Username string `json:"username"` + Vgpu string `json:"vgpu"` + Zoneid string `json:"zoneid"` + Zonename string `json:"zonename"` +} + +type RevertToVMSnapshotResponseSecuritygroup struct { + Account string `json:"account"` + Description string `json:"description"` + Domain string `json:"domain"` + Domainid string `json:"domainid"` + Egressrule []RevertToVMSnapshotResponseSecuritygroupRule `json:"egressrule"` + Id string `json:"id"` + Ingressrule []RevertToVMSnapshotResponseSecuritygroupRule `json:"ingressrule"` + Name string `json:"name"` + Project string `json:"project"` + Projectid string `json:"projectid"` + Tags []Tags `json:"tags"` + Virtualmachinecount int `json:"virtualmachinecount"` + Virtualmachineids []interface{} `json:"virtualmachineids"` +} + +type RevertToVMSnapshotResponseSecuritygroupRule struct { + Account string `json:"account"` + Cidr string `json:"cidr"` + Endport int `json:"endport"` + Icmpcode int `json:"icmpcode"` + Icmptype int `json:"icmptype"` + Protocol string `json:"protocol"` + Ruleid string `json:"ruleid"` + Securitygroupname string `json:"securitygroupname"` + Startport int `json:"startport"` + Tags []Tags `json:"tags"` +} + +type RevertToVMSnapshotResponseAffinitygroup struct { + Account string `json:"account"` + Description string `json:"description"` + Domain string `json:"domain"` + Domainid string `json:"domainid"` + Id string `json:"id"` + Name string `json:"name"` + Project string `json:"project"` + Projectid string `json:"projectid"` + Type string `json:"type"` + VirtualmachineIds []string `json:"virtualmachineIds"` +} + +type UpdateSnapshotPolicyParams struct { + p map[string]interface{} +} + +func (p *UpdateSnapshotPolicyParams) toURLValues() url.Values { + u := url.Values{} + if p.p == nil { + return u + } + if v, found := p.p["customid"]; found { + u.Set("customid", v.(string)) + } + if v, found := p.p["fordisplay"]; found { + vv := strconv.FormatBool(v.(bool)) + u.Set("fordisplay", vv) + } + if v, found := p.p["id"]; found { + u.Set("id", v.(string)) + } + return u +} + +func (p *UpdateSnapshotPolicyParams) SetCustomid(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["customid"] = v + return +} + +func (p *UpdateSnapshotPolicyParams) SetFordisplay(v bool) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["fordisplay"] = v + return +} + +func (p *UpdateSnapshotPolicyParams) SetId(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["id"] = v + return +} + +// You should always use this function to get a new UpdateSnapshotPolicyParams instance, +// as then you are sure you have configured all required params +func (s *SnapshotService) NewUpdateSnapshotPolicyParams() *UpdateSnapshotPolicyParams { + p := &UpdateSnapshotPolicyParams{} + p.p = make(map[string]interface{}) + return p +} + +// Updates the snapshot policy. +func (s *SnapshotService) UpdateSnapshotPolicy(p *UpdateSnapshotPolicyParams) (*UpdateSnapshotPolicyResponse, error) { + resp, err := s.cs.newRequest("updateSnapshotPolicy", p.toURLValues()) + if err != nil { + return nil, err + } + + var r UpdateSnapshotPolicyResponse + if err := json.Unmarshal(resp, &r); err != nil { + return nil, err + } + + // If we have a async client, we need to wait for the async result + if s.cs.async { + b, err := s.cs.GetAsyncJobResult(r.JobID, s.cs.timeout) + if err != nil { + if err == AsyncTimeoutErr { + return &r, err + } + return nil, err + } + + b, err = getRawValue(b) + if err != nil { + return nil, err + } + + if err := json.Unmarshal(b, &r); err != nil { + return nil, err + } + } + + return &r, nil +} + +type UpdateSnapshotPolicyResponse struct { + JobID string `json:"jobid"` + Fordisplay bool `json:"fordisplay"` + Id string `json:"id"` + Intervaltype int `json:"intervaltype"` + Maxsnaps int `json:"maxsnaps"` + Schedule string `json:"schedule"` + Timezone string `json:"timezone"` + Volumeid string `json:"volumeid"` } diff --git a/vendor/github.com/xanzy/go-cloudstack/cloudstack/StoragePoolService.go b/vendor/github.com/xanzy/go-cloudstack/cloudstack/StoragePoolService.go index 227678fe0..4938f14ff 100644 --- a/vendor/github.com/xanzy/go-cloudstack/cloudstack/StoragePoolService.go +++ b/vendor/github.com/xanzy/go-cloudstack/cloudstack/StoragePoolService.go @@ -1,5 +1,5 @@ // -// Copyright 2016, Sander van Harmelen +// Copyright 2018, Sander van Harmelen // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -22,6 +22,198 @@ import ( "strconv" ) +type CancelStorageMaintenanceParams struct { + p map[string]interface{} +} + +func (p *CancelStorageMaintenanceParams) toURLValues() url.Values { + u := url.Values{} + if p.p == nil { + return u + } + if v, found := p.p["id"]; found { + u.Set("id", v.(string)) + } + return u +} + +func (p *CancelStorageMaintenanceParams) SetId(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["id"] = v + return +} + +// You should always use this function to get a new CancelStorageMaintenanceParams instance, +// as then you are sure you have configured all required params +func (s *StoragePoolService) NewCancelStorageMaintenanceParams(id string) *CancelStorageMaintenanceParams { + p := &CancelStorageMaintenanceParams{} + p.p = make(map[string]interface{}) + p.p["id"] = id + return p +} + +// Cancels maintenance for primary storage +func (s *StoragePoolService) CancelStorageMaintenance(p *CancelStorageMaintenanceParams) (*CancelStorageMaintenanceResponse, error) { + resp, err := s.cs.newRequest("cancelStorageMaintenance", p.toURLValues()) + if err != nil { + return nil, err + } + + var r CancelStorageMaintenanceResponse + if err := json.Unmarshal(resp, &r); err != nil { + return nil, err + } + + // If we have a async client, we need to wait for the async result + if s.cs.async { + b, err := s.cs.GetAsyncJobResult(r.JobID, s.cs.timeout) + if err != nil { + if err == AsyncTimeoutErr { + return &r, err + } + return nil, err + } + + b, err = getRawValue(b) + if err != nil { + return nil, err + } + + if err := json.Unmarshal(b, &r); err != nil { + return nil, err + } + } + + return &r, nil +} + +type CancelStorageMaintenanceResponse struct { + JobID string `json:"jobid"` + Allocatediops int64 `json:"allocatediops"` + Capacityiops int64 `json:"capacityiops"` + Clusterid string `json:"clusterid"` + Clustername string `json:"clustername"` + Created string `json:"created"` + Disksizeallocated int64 `json:"disksizeallocated"` + Disksizetotal int64 `json:"disksizetotal"` + Disksizeused int64 `json:"disksizeused"` + Hypervisor string `json:"hypervisor"` + Id string `json:"id"` + Ipaddress string `json:"ipaddress"` + Name string `json:"name"` + Overprovisionfactor string `json:"overprovisionfactor"` + Path string `json:"path"` + Podid string `json:"podid"` + Podname string `json:"podname"` + Provider string `json:"provider"` + Scope string `json:"scope"` + State string `json:"state"` + Storagecapabilities map[string]string `json:"storagecapabilities"` + Suitableformigration bool `json:"suitableformigration"` + Tags string `json:"tags"` + Type string `json:"type"` + Zoneid string `json:"zoneid"` + Zonename string `json:"zonename"` +} + +type EnableStorageMaintenanceParams struct { + p map[string]interface{} +} + +func (p *EnableStorageMaintenanceParams) toURLValues() url.Values { + u := url.Values{} + if p.p == nil { + return u + } + if v, found := p.p["id"]; found { + u.Set("id", v.(string)) + } + return u +} + +func (p *EnableStorageMaintenanceParams) SetId(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["id"] = v + return +} + +// You should always use this function to get a new EnableStorageMaintenanceParams instance, +// as then you are sure you have configured all required params +func (s *StoragePoolService) NewEnableStorageMaintenanceParams(id string) *EnableStorageMaintenanceParams { + p := &EnableStorageMaintenanceParams{} + p.p = make(map[string]interface{}) + p.p["id"] = id + return p +} + +// Puts storage pool into maintenance state +func (s *StoragePoolService) EnableStorageMaintenance(p *EnableStorageMaintenanceParams) (*EnableStorageMaintenanceResponse, error) { + resp, err := s.cs.newRequest("enableStorageMaintenance", p.toURLValues()) + if err != nil { + return nil, err + } + + var r EnableStorageMaintenanceResponse + if err := json.Unmarshal(resp, &r); err != nil { + return nil, err + } + + // If we have a async client, we need to wait for the async result + if s.cs.async { + b, err := s.cs.GetAsyncJobResult(r.JobID, s.cs.timeout) + if err != nil { + if err == AsyncTimeoutErr { + return &r, err + } + return nil, err + } + + b, err = getRawValue(b) + if err != nil { + return nil, err + } + + if err := json.Unmarshal(b, &r); err != nil { + return nil, err + } + } + + return &r, nil +} + +type EnableStorageMaintenanceResponse struct { + JobID string `json:"jobid"` + Allocatediops int64 `json:"allocatediops"` + Capacityiops int64 `json:"capacityiops"` + Clusterid string `json:"clusterid"` + Clustername string `json:"clustername"` + Created string `json:"created"` + Disksizeallocated int64 `json:"disksizeallocated"` + Disksizetotal int64 `json:"disksizetotal"` + Disksizeused int64 `json:"disksizeused"` + Hypervisor string `json:"hypervisor"` + Id string `json:"id"` + Ipaddress string `json:"ipaddress"` + Name string `json:"name"` + Overprovisionfactor string `json:"overprovisionfactor"` + Path string `json:"path"` + Podid string `json:"podid"` + Podname string `json:"podname"` + Provider string `json:"provider"` + Scope string `json:"scope"` + State string `json:"state"` + Storagecapabilities map[string]string `json:"storagecapabilities"` + Suitableformigration bool `json:"suitableformigration"` + Tags string `json:"tags"` + Type string `json:"type"` + Zoneid string `json:"zoneid"` + Zonename string `json:"zonename"` +} + type ListStorageProvidersParams struct { p map[string]interface{} } @@ -100,6 +292,7 @@ func (s *StoragePoolService) ListStorageProviders(p *ListStorageProvidersParams) if err := json.Unmarshal(resp, &r); err != nil { return nil, err } + return &r, nil } @@ -109,192 +302,6 @@ type ListStorageProvidersResponse struct { } type StorageProvider struct { - Name string `json:"name,omitempty"` - Type string `json:"type,omitempty"` -} - -type EnableStorageMaintenanceParams struct { - p map[string]interface{} -} - -func (p *EnableStorageMaintenanceParams) toURLValues() url.Values { - u := url.Values{} - if p.p == nil { - return u - } - if v, found := p.p["id"]; found { - u.Set("id", v.(string)) - } - return u -} - -func (p *EnableStorageMaintenanceParams) SetId(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["id"] = v - return -} - -// You should always use this function to get a new EnableStorageMaintenanceParams instance, -// as then you are sure you have configured all required params -func (s *StoragePoolService) NewEnableStorageMaintenanceParams(id string) *EnableStorageMaintenanceParams { - p := &EnableStorageMaintenanceParams{} - p.p = make(map[string]interface{}) - p.p["id"] = id - return p -} - -// Puts storage pool into maintenance state -func (s *StoragePoolService) EnableStorageMaintenance(p *EnableStorageMaintenanceParams) (*EnableStorageMaintenanceResponse, error) { - resp, err := s.cs.newRequest("enableStorageMaintenance", p.toURLValues()) - if err != nil { - return nil, err - } - - var r EnableStorageMaintenanceResponse - if err := json.Unmarshal(resp, &r); err != nil { - return nil, err - } - - // If we have a async client, we need to wait for the async result - if s.cs.async { - b, err := s.cs.GetAsyncJobResult(r.JobID, s.cs.timeout) - if err != nil { - if err == AsyncTimeoutErr { - return &r, err - } - return nil, err - } - - b, err = getRawValue(b) - if err != nil { - return nil, err - } - - if err := json.Unmarshal(b, &r); err != nil { - return nil, err - } - } - return &r, nil -} - -type EnableStorageMaintenanceResponse struct { - JobID string `json:"jobid,omitempty"` - Capacityiops int64 `json:"capacityiops,omitempty"` - Clusterid string `json:"clusterid,omitempty"` - Clustername string `json:"clustername,omitempty"` - Created string `json:"created,omitempty"` - Disksizeallocated int64 `json:"disksizeallocated,omitempty"` - Disksizetotal int64 `json:"disksizetotal,omitempty"` - Disksizeused int64 `json:"disksizeused,omitempty"` - Hypervisor string `json:"hypervisor,omitempty"` - Id string `json:"id,omitempty"` - Ipaddress string `json:"ipaddress,omitempty"` - Name string `json:"name,omitempty"` - Overprovisionfactor string `json:"overprovisionfactor,omitempty"` - Path string `json:"path,omitempty"` - Podid string `json:"podid,omitempty"` - Podname string `json:"podname,omitempty"` - Scope string `json:"scope,omitempty"` - State string `json:"state,omitempty"` - Storagecapabilities map[string]string `json:"storagecapabilities,omitempty"` - Suitableformigration bool `json:"suitableformigration,omitempty"` - Tags string `json:"tags,omitempty"` - Type string `json:"type,omitempty"` - Zoneid string `json:"zoneid,omitempty"` - Zonename string `json:"zonename,omitempty"` -} - -type CancelStorageMaintenanceParams struct { - p map[string]interface{} -} - -func (p *CancelStorageMaintenanceParams) toURLValues() url.Values { - u := url.Values{} - if p.p == nil { - return u - } - if v, found := p.p["id"]; found { - u.Set("id", v.(string)) - } - return u -} - -func (p *CancelStorageMaintenanceParams) SetId(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["id"] = v - return -} - -// You should always use this function to get a new CancelStorageMaintenanceParams instance, -// as then you are sure you have configured all required params -func (s *StoragePoolService) NewCancelStorageMaintenanceParams(id string) *CancelStorageMaintenanceParams { - p := &CancelStorageMaintenanceParams{} - p.p = make(map[string]interface{}) - p.p["id"] = id - return p -} - -// Cancels maintenance for primary storage -func (s *StoragePoolService) CancelStorageMaintenance(p *CancelStorageMaintenanceParams) (*CancelStorageMaintenanceResponse, error) { - resp, err := s.cs.newRequest("cancelStorageMaintenance", p.toURLValues()) - if err != nil { - return nil, err - } - - var r CancelStorageMaintenanceResponse - if err := json.Unmarshal(resp, &r); err != nil { - return nil, err - } - - // If we have a async client, we need to wait for the async result - if s.cs.async { - b, err := s.cs.GetAsyncJobResult(r.JobID, s.cs.timeout) - if err != nil { - if err == AsyncTimeoutErr { - return &r, err - } - return nil, err - } - - b, err = getRawValue(b) - if err != nil { - return nil, err - } - - if err := json.Unmarshal(b, &r); err != nil { - return nil, err - } - } - return &r, nil -} - -type CancelStorageMaintenanceResponse struct { - JobID string `json:"jobid,omitempty"` - Capacityiops int64 `json:"capacityiops,omitempty"` - Clusterid string `json:"clusterid,omitempty"` - Clustername string `json:"clustername,omitempty"` - Created string `json:"created,omitempty"` - Disksizeallocated int64 `json:"disksizeallocated,omitempty"` - Disksizetotal int64 `json:"disksizetotal,omitempty"` - Disksizeused int64 `json:"disksizeused,omitempty"` - Hypervisor string `json:"hypervisor,omitempty"` - Id string `json:"id,omitempty"` - Ipaddress string `json:"ipaddress,omitempty"` - Name string `json:"name,omitempty"` - Overprovisionfactor string `json:"overprovisionfactor,omitempty"` - Path string `json:"path,omitempty"` - Podid string `json:"podid,omitempty"` - Podname string `json:"podname,omitempty"` - Scope string `json:"scope,omitempty"` - State string `json:"state,omitempty"` - Storagecapabilities map[string]string `json:"storagecapabilities,omitempty"` - Suitableformigration bool `json:"suitableformigration,omitempty"` - Tags string `json:"tags,omitempty"` - Type string `json:"type,omitempty"` - Zoneid string `json:"zoneid,omitempty"` - Zonename string `json:"zonename,omitempty"` + Name string `json:"name"` + Type string `json:"type"` } diff --git a/vendor/github.com/xanzy/go-cloudstack/cloudstack/StratosphereSSPService.go b/vendor/github.com/xanzy/go-cloudstack/cloudstack/StratosphereSSPService.go index 4e638f843..8a4d4914c 100644 --- a/vendor/github.com/xanzy/go-cloudstack/cloudstack/StratosphereSSPService.go +++ b/vendor/github.com/xanzy/go-cloudstack/cloudstack/StratosphereSSPService.go @@ -1,5 +1,5 @@ // -// Copyright 2016, Sander van Harmelen +// Copyright 2018, Sander van Harmelen // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -121,12 +121,84 @@ func (s *StratosphereSSPService) AddStratosphereSsp(p *AddStratosphereSspParams) if err := json.Unmarshal(resp, &r); err != nil { return nil, err } + return &r, nil } type AddStratosphereSspResponse struct { - Hostid string `json:"hostid,omitempty"` - Name string `json:"name,omitempty"` - Url string `json:"url,omitempty"` - Zoneid string `json:"zoneid,omitempty"` + Hostid string `json:"hostid"` + Name string `json:"name"` + Url string `json:"url"` + Zoneid string `json:"zoneid"` +} + +type DeleteStratosphereSspParams struct { + p map[string]interface{} +} + +func (p *DeleteStratosphereSspParams) toURLValues() url.Values { + u := url.Values{} + if p.p == nil { + return u + } + if v, found := p.p["hostid"]; found { + u.Set("hostid", v.(string)) + } + return u +} + +func (p *DeleteStratosphereSspParams) SetHostid(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["hostid"] = v + return +} + +// You should always use this function to get a new DeleteStratosphereSspParams instance, +// as then you are sure you have configured all required params +func (s *StratosphereSSPService) NewDeleteStratosphereSspParams(hostid string) *DeleteStratosphereSspParams { + p := &DeleteStratosphereSspParams{} + p.p = make(map[string]interface{}) + p.p["hostid"] = hostid + return p +} + +// Removes stratosphere ssp server +func (s *StratosphereSSPService) DeleteStratosphereSsp(p *DeleteStratosphereSspParams) (*DeleteStratosphereSspResponse, error) { + resp, err := s.cs.newRequest("deleteStratosphereSsp", p.toURLValues()) + if err != nil { + return nil, err + } + + var r DeleteStratosphereSspResponse + if err := json.Unmarshal(resp, &r); err != nil { + return nil, err + } + + return &r, nil +} + +type DeleteStratosphereSspResponse struct { + Displaytext string `json:"displaytext"` + Success bool `json:"success"` +} + +func (r *DeleteStratosphereSspResponse) UnmarshalJSON(b []byte) error { + var m map[string]interface{} + err := json.Unmarshal(b, &m) + if err != nil { + return err + } + + if success, ok := m["success"].(string); ok { + m["success"] = success == "true" + b, err = json.Marshal(m) + if err != nil { + return err + } + } + + type alias DeleteStratosphereSspResponse + return json.Unmarshal(b, (*alias)(r)) } diff --git a/vendor/github.com/xanzy/go-cloudstack/cloudstack/SwiftService.go b/vendor/github.com/xanzy/go-cloudstack/cloudstack/SwiftService.go index 72bcfc608..e3161d95c 100644 --- a/vendor/github.com/xanzy/go-cloudstack/cloudstack/SwiftService.go +++ b/vendor/github.com/xanzy/go-cloudstack/cloudstack/SwiftService.go @@ -1,5 +1,5 @@ // -// Copyright 2016, Sander van Harmelen +// Copyright 2018, Sander van Harmelen // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -99,19 +99,19 @@ func (s *SwiftService) AddSwift(p *AddSwiftParams) (*AddSwiftResponse, error) { if err := json.Unmarshal(resp, &r); err != nil { return nil, err } + return &r, nil } type AddSwiftResponse struct { - Details []string `json:"details,omitempty"` - Id string `json:"id,omitempty"` - Name string `json:"name,omitempty"` - Protocol string `json:"protocol,omitempty"` - Providername string `json:"providername,omitempty"` - Scope string `json:"scope,omitempty"` - Url string `json:"url,omitempty"` - Zoneid string `json:"zoneid,omitempty"` - Zonename string `json:"zonename,omitempty"` + Id string `json:"id"` + Name string `json:"name"` + Protocol string `json:"protocol"` + Providername string `json:"providername"` + Scope string `json:"scope"` + Url string `json:"url"` + Zoneid string `json:"zoneid"` + Zonename string `json:"zonename"` } type ListSwiftsParams struct { @@ -188,7 +188,7 @@ func (s *SwiftService) GetSwiftID(keyword string, opts ...OptionFunc) (string, i p.p["keyword"] = keyword - for _, fn := range opts { + for _, fn := range append(s.cs.options, opts...) { if err := fn(s.cs, p); err != nil { return "", -1, err } @@ -228,6 +228,7 @@ func (s *SwiftService) ListSwifts(p *ListSwiftsParams) (*ListSwiftsResponse, err if err := json.Unmarshal(resp, &r); err != nil { return nil, err } + return &r, nil } @@ -237,13 +238,12 @@ type ListSwiftsResponse struct { } type Swift struct { - Details []string `json:"details,omitempty"` - Id string `json:"id,omitempty"` - Name string `json:"name,omitempty"` - Protocol string `json:"protocol,omitempty"` - Providername string `json:"providername,omitempty"` - Scope string `json:"scope,omitempty"` - Url string `json:"url,omitempty"` - Zoneid string `json:"zoneid,omitempty"` - Zonename string `json:"zonename,omitempty"` + Id string `json:"id"` + Name string `json:"name"` + Protocol string `json:"protocol"` + Providername string `json:"providername"` + Scope string `json:"scope"` + Url string `json:"url"` + Zoneid string `json:"zoneid"` + Zonename string `json:"zonename"` } diff --git a/vendor/github.com/xanzy/go-cloudstack/cloudstack/SystemCapacityService.go b/vendor/github.com/xanzy/go-cloudstack/cloudstack/SystemCapacityService.go index fc30665c3..686521c51 100644 --- a/vendor/github.com/xanzy/go-cloudstack/cloudstack/SystemCapacityService.go +++ b/vendor/github.com/xanzy/go-cloudstack/cloudstack/SystemCapacityService.go @@ -1,5 +1,5 @@ // -// Copyright 2016, Sander van Harmelen +// Copyright 2018, Sander van Harmelen // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -156,6 +156,7 @@ func (s *SystemCapacityService) ListCapacity(p *ListCapacityParams) (*ListCapaci if err := json.Unmarshal(resp, &r); err != nil { return nil, err } + return &r, nil } @@ -165,14 +166,16 @@ type ListCapacityResponse struct { } type Capacity struct { - Capacitytotal int64 `json:"capacitytotal,omitempty"` - Capacityused int64 `json:"capacityused,omitempty"` - Clusterid string `json:"clusterid,omitempty"` - Clustername string `json:"clustername,omitempty"` - Percentused string `json:"percentused,omitempty"` - Podid string `json:"podid,omitempty"` - Podname string `json:"podname,omitempty"` - Type int `json:"type,omitempty"` - Zoneid string `json:"zoneid,omitempty"` - Zonename string `json:"zonename,omitempty"` + Capacityallocated int64 `json:"capacityallocated"` + Capacitytotal int64 `json:"capacitytotal"` + Capacityused int64 `json:"capacityused"` + Clusterid string `json:"clusterid"` + Clustername string `json:"clustername"` + Name string `json:"name"` + Percentused string `json:"percentused"` + Podid string `json:"podid"` + Podname string `json:"podname"` + Type int `json:"type"` + Zoneid string `json:"zoneid"` + Zonename string `json:"zonename"` } diff --git a/vendor/github.com/xanzy/go-cloudstack/cloudstack/SystemVMService.go b/vendor/github.com/xanzy/go-cloudstack/cloudstack/SystemVMService.go index 18b697a85..4f1a65164 100644 --- a/vendor/github.com/xanzy/go-cloudstack/cloudstack/SystemVMService.go +++ b/vendor/github.com/xanzy/go-cloudstack/cloudstack/SystemVMService.go @@ -1,5 +1,5 @@ // -// Copyright 2016, Sander van Harmelen +// Copyright 2018, Sander van Harmelen // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -24,22 +24,40 @@ import ( "strings" ) -type StartSystemVmParams struct { +type ChangeServiceForSystemVmParams struct { p map[string]interface{} } -func (p *StartSystemVmParams) toURLValues() url.Values { +func (p *ChangeServiceForSystemVmParams) toURLValues() url.Values { u := url.Values{} if p.p == nil { return u } + if v, found := p.p["details"]; found { + i := 0 + for k, vv := range v.(map[string]string) { + u.Set(fmt.Sprintf("details[%d].%s", i, k), vv) + i++ + } + } if v, found := p.p["id"]; found { u.Set("id", v.(string)) } + if v, found := p.p["serviceofferingid"]; found { + u.Set("serviceofferingid", v.(string)) + } return u } -func (p *StartSystemVmParams) SetId(v string) { +func (p *ChangeServiceForSystemVmParams) SetDetails(v map[string]string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["details"] = v + return +} + +func (p *ChangeServiceForSystemVmParams) SetId(v string) { if p.p == nil { p.p = make(map[string]interface{}) } @@ -47,287 +65,70 @@ func (p *StartSystemVmParams) SetId(v string) { return } -// You should always use this function to get a new StartSystemVmParams instance, +func (p *ChangeServiceForSystemVmParams) SetServiceofferingid(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["serviceofferingid"] = v + return +} + +// You should always use this function to get a new ChangeServiceForSystemVmParams instance, // as then you are sure you have configured all required params -func (s *SystemVMService) NewStartSystemVmParams(id string) *StartSystemVmParams { - p := &StartSystemVmParams{} +func (s *SystemVMService) NewChangeServiceForSystemVmParams(id string, serviceofferingid string) *ChangeServiceForSystemVmParams { + p := &ChangeServiceForSystemVmParams{} p.p = make(map[string]interface{}) p.p["id"] = id + p.p["serviceofferingid"] = serviceofferingid return p } -// Starts a system virtual machine. -func (s *SystemVMService) StartSystemVm(p *StartSystemVmParams) (*StartSystemVmResponse, error) { - resp, err := s.cs.newRequest("startSystemVm", p.toURLValues()) +// Changes the service offering for a system vm (console proxy or secondary storage). The system vm must be in a "Stopped" state for this command to take effect. +func (s *SystemVMService) ChangeServiceForSystemVm(p *ChangeServiceForSystemVmParams) (*ChangeServiceForSystemVmResponse, error) { + resp, err := s.cs.newRequest("changeServiceForSystemVm", p.toURLValues()) if err != nil { return nil, err } - var r StartSystemVmResponse + var r ChangeServiceForSystemVmResponse if err := json.Unmarshal(resp, &r); err != nil { return nil, err } - // If we have a async client, we need to wait for the async result - if s.cs.async { - b, err := s.cs.GetAsyncJobResult(r.JobID, s.cs.timeout) - if err != nil { - if err == AsyncTimeoutErr { - return &r, err - } - return nil, err - } - - b, err = getRawValue(b) - if err != nil { - return nil, err - } - - if err := json.Unmarshal(b, &r); err != nil { - return nil, err - } - } return &r, nil } -type StartSystemVmResponse struct { - JobID string `json:"jobid,omitempty"` - Activeviewersessions int `json:"activeviewersessions,omitempty"` - Created string `json:"created,omitempty"` - Dns1 string `json:"dns1,omitempty"` - Dns2 string `json:"dns2,omitempty"` - Gateway string `json:"gateway,omitempty"` - Hostid string `json:"hostid,omitempty"` - Hostname string `json:"hostname,omitempty"` - Hypervisor string `json:"hypervisor,omitempty"` - Id string `json:"id,omitempty"` - Jobid string `json:"jobid,omitempty"` - Jobstatus int `json:"jobstatus,omitempty"` - Linklocalip string `json:"linklocalip,omitempty"` - Linklocalmacaddress string `json:"linklocalmacaddress,omitempty"` - Linklocalnetmask string `json:"linklocalnetmask,omitempty"` - Name string `json:"name,omitempty"` - Networkdomain string `json:"networkdomain,omitempty"` - Podid string `json:"podid,omitempty"` - Privateip string `json:"privateip,omitempty"` - Privatemacaddress string `json:"privatemacaddress,omitempty"` - Privatenetmask string `json:"privatenetmask,omitempty"` - Publicip string `json:"publicip,omitempty"` - Publicmacaddress string `json:"publicmacaddress,omitempty"` - Publicnetmask string `json:"publicnetmask,omitempty"` - State string `json:"state,omitempty"` - Systemvmtype string `json:"systemvmtype,omitempty"` - Templateid string `json:"templateid,omitempty"` - Zoneid string `json:"zoneid,omitempty"` - Zonename string `json:"zonename,omitempty"` -} - -type RebootSystemVmParams struct { - p map[string]interface{} -} - -func (p *RebootSystemVmParams) toURLValues() url.Values { - u := url.Values{} - if p.p == nil { - return u - } - if v, found := p.p["id"]; found { - u.Set("id", v.(string)) - } - return u -} - -func (p *RebootSystemVmParams) SetId(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["id"] = v - return -} - -// You should always use this function to get a new RebootSystemVmParams instance, -// as then you are sure you have configured all required params -func (s *SystemVMService) NewRebootSystemVmParams(id string) *RebootSystemVmParams { - p := &RebootSystemVmParams{} - p.p = make(map[string]interface{}) - p.p["id"] = id - return p -} - -// Reboots a system VM. -func (s *SystemVMService) RebootSystemVm(p *RebootSystemVmParams) (*RebootSystemVmResponse, error) { - resp, err := s.cs.newRequest("rebootSystemVm", p.toURLValues()) - if err != nil { - return nil, err - } - - var r RebootSystemVmResponse - if err := json.Unmarshal(resp, &r); err != nil { - return nil, err - } - - // If we have a async client, we need to wait for the async result - if s.cs.async { - b, err := s.cs.GetAsyncJobResult(r.JobID, s.cs.timeout) - if err != nil { - if err == AsyncTimeoutErr { - return &r, err - } - return nil, err - } - - b, err = getRawValue(b) - if err != nil { - return nil, err - } - - if err := json.Unmarshal(b, &r); err != nil { - return nil, err - } - } - return &r, nil -} - -type RebootSystemVmResponse struct { - JobID string `json:"jobid,omitempty"` - Activeviewersessions int `json:"activeviewersessions,omitempty"` - Created string `json:"created,omitempty"` - Dns1 string `json:"dns1,omitempty"` - Dns2 string `json:"dns2,omitempty"` - Gateway string `json:"gateway,omitempty"` - Hostid string `json:"hostid,omitempty"` - Hostname string `json:"hostname,omitempty"` - Hypervisor string `json:"hypervisor,omitempty"` - Id string `json:"id,omitempty"` - Jobid string `json:"jobid,omitempty"` - Jobstatus int `json:"jobstatus,omitempty"` - Linklocalip string `json:"linklocalip,omitempty"` - Linklocalmacaddress string `json:"linklocalmacaddress,omitempty"` - Linklocalnetmask string `json:"linklocalnetmask,omitempty"` - Name string `json:"name,omitempty"` - Networkdomain string `json:"networkdomain,omitempty"` - Podid string `json:"podid,omitempty"` - Privateip string `json:"privateip,omitempty"` - Privatemacaddress string `json:"privatemacaddress,omitempty"` - Privatenetmask string `json:"privatenetmask,omitempty"` - Publicip string `json:"publicip,omitempty"` - Publicmacaddress string `json:"publicmacaddress,omitempty"` - Publicnetmask string `json:"publicnetmask,omitempty"` - State string `json:"state,omitempty"` - Systemvmtype string `json:"systemvmtype,omitempty"` - Templateid string `json:"templateid,omitempty"` - Zoneid string `json:"zoneid,omitempty"` - Zonename string `json:"zonename,omitempty"` -} - -type StopSystemVmParams struct { - p map[string]interface{} -} - -func (p *StopSystemVmParams) toURLValues() url.Values { - u := url.Values{} - if p.p == nil { - return u - } - if v, found := p.p["forced"]; found { - vv := strconv.FormatBool(v.(bool)) - u.Set("forced", vv) - } - if v, found := p.p["id"]; found { - u.Set("id", v.(string)) - } - return u -} - -func (p *StopSystemVmParams) SetForced(v bool) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["forced"] = v - return -} - -func (p *StopSystemVmParams) SetId(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["id"] = v - return -} - -// You should always use this function to get a new StopSystemVmParams instance, -// as then you are sure you have configured all required params -func (s *SystemVMService) NewStopSystemVmParams(id string) *StopSystemVmParams { - p := &StopSystemVmParams{} - p.p = make(map[string]interface{}) - p.p["id"] = id - return p -} - -// Stops a system VM. -func (s *SystemVMService) StopSystemVm(p *StopSystemVmParams) (*StopSystemVmResponse, error) { - resp, err := s.cs.newRequest("stopSystemVm", p.toURLValues()) - if err != nil { - return nil, err - } - - var r StopSystemVmResponse - if err := json.Unmarshal(resp, &r); err != nil { - return nil, err - } - - // If we have a async client, we need to wait for the async result - if s.cs.async { - b, err := s.cs.GetAsyncJobResult(r.JobID, s.cs.timeout) - if err != nil { - if err == AsyncTimeoutErr { - return &r, err - } - return nil, err - } - - b, err = getRawValue(b) - if err != nil { - return nil, err - } - - if err := json.Unmarshal(b, &r); err != nil { - return nil, err - } - } - return &r, nil -} - -type StopSystemVmResponse struct { - JobID string `json:"jobid,omitempty"` - Activeviewersessions int `json:"activeviewersessions,omitempty"` - Created string `json:"created,omitempty"` - Dns1 string `json:"dns1,omitempty"` - Dns2 string `json:"dns2,omitempty"` - Gateway string `json:"gateway,omitempty"` - Hostid string `json:"hostid,omitempty"` - Hostname string `json:"hostname,omitempty"` - Hypervisor string `json:"hypervisor,omitempty"` - Id string `json:"id,omitempty"` - Jobid string `json:"jobid,omitempty"` - Jobstatus int `json:"jobstatus,omitempty"` - Linklocalip string `json:"linklocalip,omitempty"` - Linklocalmacaddress string `json:"linklocalmacaddress,omitempty"` - Linklocalnetmask string `json:"linklocalnetmask,omitempty"` - Name string `json:"name,omitempty"` - Networkdomain string `json:"networkdomain,omitempty"` - Podid string `json:"podid,omitempty"` - Privateip string `json:"privateip,omitempty"` - Privatemacaddress string `json:"privatemacaddress,omitempty"` - Privatenetmask string `json:"privatenetmask,omitempty"` - Publicip string `json:"publicip,omitempty"` - Publicmacaddress string `json:"publicmacaddress,omitempty"` - Publicnetmask string `json:"publicnetmask,omitempty"` - State string `json:"state,omitempty"` - Systemvmtype string `json:"systemvmtype,omitempty"` - Templateid string `json:"templateid,omitempty"` - Zoneid string `json:"zoneid,omitempty"` - Zonename string `json:"zonename,omitempty"` +type ChangeServiceForSystemVmResponse struct { + Activeviewersessions int `json:"activeviewersessions"` + Created string `json:"created"` + Dns1 string `json:"dns1"` + Dns2 string `json:"dns2"` + Gateway string `json:"gateway"` + Guestvlan string `json:"guestvlan"` + Hostid string `json:"hostid"` + Hostname string `json:"hostname"` + Hypervisor string `json:"hypervisor"` + Id string `json:"id"` + JobID string `json:"jobid"` + Jobstatus int `json:"jobstatus"` + Linklocalip string `json:"linklocalip"` + Linklocalmacaddress string `json:"linklocalmacaddress"` + Linklocalnetmask string `json:"linklocalnetmask"` + Name string `json:"name"` + Networkdomain string `json:"networkdomain"` + Podid string `json:"podid"` + Privateip string `json:"privateip"` + Privatemacaddress string `json:"privatemacaddress"` + Privatenetmask string `json:"privatenetmask"` + Publicip string `json:"publicip"` + Publicmacaddress string `json:"publicmacaddress"` + Publicnetmask string `json:"publicnetmask"` + Publicvlan []string `json:"publicvlan"` + State string `json:"state"` + Systemvmtype string `json:"systemvmtype"` + Templateid string `json:"templateid"` + Zoneid string `json:"zoneid"` + Zonename string `json:"zonename"` } type DestroySystemVmParams struct { @@ -393,39 +194,41 @@ func (s *SystemVMService) DestroySystemVm(p *DestroySystemVmParams) (*DestroySys return nil, err } } + return &r, nil } type DestroySystemVmResponse struct { - JobID string `json:"jobid,omitempty"` - Activeviewersessions int `json:"activeviewersessions,omitempty"` - Created string `json:"created,omitempty"` - Dns1 string `json:"dns1,omitempty"` - Dns2 string `json:"dns2,omitempty"` - Gateway string `json:"gateway,omitempty"` - Hostid string `json:"hostid,omitempty"` - Hostname string `json:"hostname,omitempty"` - Hypervisor string `json:"hypervisor,omitempty"` - Id string `json:"id,omitempty"` - Jobid string `json:"jobid,omitempty"` - Jobstatus int `json:"jobstatus,omitempty"` - Linklocalip string `json:"linklocalip,omitempty"` - Linklocalmacaddress string `json:"linklocalmacaddress,omitempty"` - Linklocalnetmask string `json:"linklocalnetmask,omitempty"` - Name string `json:"name,omitempty"` - Networkdomain string `json:"networkdomain,omitempty"` - Podid string `json:"podid,omitempty"` - Privateip string `json:"privateip,omitempty"` - Privatemacaddress string `json:"privatemacaddress,omitempty"` - Privatenetmask string `json:"privatenetmask,omitempty"` - Publicip string `json:"publicip,omitempty"` - Publicmacaddress string `json:"publicmacaddress,omitempty"` - Publicnetmask string `json:"publicnetmask,omitempty"` - State string `json:"state,omitempty"` - Systemvmtype string `json:"systemvmtype,omitempty"` - Templateid string `json:"templateid,omitempty"` - Zoneid string `json:"zoneid,omitempty"` - Zonename string `json:"zonename,omitempty"` + Activeviewersessions int `json:"activeviewersessions"` + Created string `json:"created"` + Dns1 string `json:"dns1"` + Dns2 string `json:"dns2"` + Gateway string `json:"gateway"` + Guestvlan string `json:"guestvlan"` + Hostid string `json:"hostid"` + Hostname string `json:"hostname"` + Hypervisor string `json:"hypervisor"` + Id string `json:"id"` + JobID string `json:"jobid"` + Jobstatus int `json:"jobstatus"` + Linklocalip string `json:"linklocalip"` + Linklocalmacaddress string `json:"linklocalmacaddress"` + Linklocalnetmask string `json:"linklocalnetmask"` + Name string `json:"name"` + Networkdomain string `json:"networkdomain"` + Podid string `json:"podid"` + Privateip string `json:"privateip"` + Privatemacaddress string `json:"privatemacaddress"` + Privatenetmask string `json:"privatenetmask"` + Publicip string `json:"publicip"` + Publicmacaddress string `json:"publicmacaddress"` + Publicnetmask string `json:"publicnetmask"` + Publicvlan []string `json:"publicvlan"` + State string `json:"state"` + Systemvmtype string `json:"systemvmtype"` + Templateid string `json:"templateid"` + Zoneid string `json:"zoneid"` + Zonename string `json:"zonename"` } type ListSystemVmsParams struct { @@ -578,7 +381,7 @@ func (s *SystemVMService) GetSystemVmID(name string, opts ...OptionFunc) (string p.p["name"] = name - for _, fn := range opts { + for _, fn := range append(s.cs.options, opts...) { if err := fn(s.cs, p); err != nil { return "", -1, err } @@ -628,7 +431,7 @@ func (s *SystemVMService) GetSystemVmByID(id string, opts ...OptionFunc) (*Syste p.p["id"] = id - for _, fn := range opts { + for _, fn := range append(s.cs.options, opts...) { if err := fn(s.cs, p); err != nil { return nil, -1, err } @@ -665,6 +468,7 @@ func (s *SystemVMService) ListSystemVms(p *ListSystemVmsParams) (*ListSystemVmsR if err := json.Unmarshal(resp, &r); err != nil { return nil, err } + return &r, nil } @@ -674,34 +478,36 @@ type ListSystemVmsResponse struct { } type SystemVm struct { - Activeviewersessions int `json:"activeviewersessions,omitempty"` - Created string `json:"created,omitempty"` - Dns1 string `json:"dns1,omitempty"` - Dns2 string `json:"dns2,omitempty"` - Gateway string `json:"gateway,omitempty"` - Hostid string `json:"hostid,omitempty"` - Hostname string `json:"hostname,omitempty"` - Hypervisor string `json:"hypervisor,omitempty"` - Id string `json:"id,omitempty"` - Jobid string `json:"jobid,omitempty"` - Jobstatus int `json:"jobstatus,omitempty"` - Linklocalip string `json:"linklocalip,omitempty"` - Linklocalmacaddress string `json:"linklocalmacaddress,omitempty"` - Linklocalnetmask string `json:"linklocalnetmask,omitempty"` - Name string `json:"name,omitempty"` - Networkdomain string `json:"networkdomain,omitempty"` - Podid string `json:"podid,omitempty"` - Privateip string `json:"privateip,omitempty"` - Privatemacaddress string `json:"privatemacaddress,omitempty"` - Privatenetmask string `json:"privatenetmask,omitempty"` - Publicip string `json:"publicip,omitempty"` - Publicmacaddress string `json:"publicmacaddress,omitempty"` - Publicnetmask string `json:"publicnetmask,omitempty"` - State string `json:"state,omitempty"` - Systemvmtype string `json:"systemvmtype,omitempty"` - Templateid string `json:"templateid,omitempty"` - Zoneid string `json:"zoneid,omitempty"` - Zonename string `json:"zonename,omitempty"` + Activeviewersessions int `json:"activeviewersessions"` + Created string `json:"created"` + Dns1 string `json:"dns1"` + Dns2 string `json:"dns2"` + Gateway string `json:"gateway"` + Guestvlan string `json:"guestvlan"` + Hostid string `json:"hostid"` + Hostname string `json:"hostname"` + Hypervisor string `json:"hypervisor"` + Id string `json:"id"` + JobID string `json:"jobid"` + Jobstatus int `json:"jobstatus"` + Linklocalip string `json:"linklocalip"` + Linklocalmacaddress string `json:"linklocalmacaddress"` + Linklocalnetmask string `json:"linklocalnetmask"` + Name string `json:"name"` + Networkdomain string `json:"networkdomain"` + Podid string `json:"podid"` + Privateip string `json:"privateip"` + Privatemacaddress string `json:"privatemacaddress"` + Privatenetmask string `json:"privatenetmask"` + Publicip string `json:"publicip"` + Publicmacaddress string `json:"publicmacaddress"` + Publicnetmask string `json:"publicnetmask"` + Publicvlan []string `json:"publicvlan"` + State string `json:"state"` + Systemvmtype string `json:"systemvmtype"` + Templateid string `json:"templateid"` + Zoneid string `json:"zoneid"` + Zonename string `json:"zonename"` } type MigrateSystemVmParams struct { @@ -779,76 +585,59 @@ func (s *SystemVMService) MigrateSystemVm(p *MigrateSystemVmParams) (*MigrateSys return nil, err } } + return &r, nil } type MigrateSystemVmResponse struct { - JobID string `json:"jobid,omitempty"` - Activeviewersessions int `json:"activeviewersessions,omitempty"` - Created string `json:"created,omitempty"` - Dns1 string `json:"dns1,omitempty"` - Dns2 string `json:"dns2,omitempty"` - Gateway string `json:"gateway,omitempty"` - Hostid string `json:"hostid,omitempty"` - Hostname string `json:"hostname,omitempty"` - Hypervisor string `json:"hypervisor,omitempty"` - Id string `json:"id,omitempty"` - Jobid string `json:"jobid,omitempty"` - Jobstatus int `json:"jobstatus,omitempty"` - Linklocalip string `json:"linklocalip,omitempty"` - Linklocalmacaddress string `json:"linklocalmacaddress,omitempty"` - Linklocalnetmask string `json:"linklocalnetmask,omitempty"` - Name string `json:"name,omitempty"` - Networkdomain string `json:"networkdomain,omitempty"` - Podid string `json:"podid,omitempty"` - Privateip string `json:"privateip,omitempty"` - Privatemacaddress string `json:"privatemacaddress,omitempty"` - Privatenetmask string `json:"privatenetmask,omitempty"` - Publicip string `json:"publicip,omitempty"` - Publicmacaddress string `json:"publicmacaddress,omitempty"` - Publicnetmask string `json:"publicnetmask,omitempty"` - State string `json:"state,omitempty"` - Systemvmtype string `json:"systemvmtype,omitempty"` - Templateid string `json:"templateid,omitempty"` - Zoneid string `json:"zoneid,omitempty"` - Zonename string `json:"zonename,omitempty"` + Activeviewersessions int `json:"activeviewersessions"` + Created string `json:"created"` + Dns1 string `json:"dns1"` + Dns2 string `json:"dns2"` + Gateway string `json:"gateway"` + Guestvlan string `json:"guestvlan"` + Hostid string `json:"hostid"` + Hostname string `json:"hostname"` + Hypervisor string `json:"hypervisor"` + Id string `json:"id"` + JobID string `json:"jobid"` + Jobstatus int `json:"jobstatus"` + Linklocalip string `json:"linklocalip"` + Linklocalmacaddress string `json:"linklocalmacaddress"` + Linklocalnetmask string `json:"linklocalnetmask"` + Name string `json:"name"` + Networkdomain string `json:"networkdomain"` + Podid string `json:"podid"` + Privateip string `json:"privateip"` + Privatemacaddress string `json:"privatemacaddress"` + Privatenetmask string `json:"privatenetmask"` + Publicip string `json:"publicip"` + Publicmacaddress string `json:"publicmacaddress"` + Publicnetmask string `json:"publicnetmask"` + Publicvlan []string `json:"publicvlan"` + State string `json:"state"` + Systemvmtype string `json:"systemvmtype"` + Templateid string `json:"templateid"` + Zoneid string `json:"zoneid"` + Zonename string `json:"zonename"` } -type ChangeServiceForSystemVmParams struct { +type RebootSystemVmParams struct { p map[string]interface{} } -func (p *ChangeServiceForSystemVmParams) toURLValues() url.Values { +func (p *RebootSystemVmParams) toURLValues() url.Values { u := url.Values{} if p.p == nil { return u } - if v, found := p.p["details"]; found { - i := 0 - for k, vv := range v.(map[string]string) { - u.Set(fmt.Sprintf("details[%d].key", i), k) - u.Set(fmt.Sprintf("details[%d].value", i), vv) - i++ - } - } if v, found := p.p["id"]; found { u.Set("id", v.(string)) } - if v, found := p.p["serviceofferingid"]; found { - u.Set("serviceofferingid", v.(string)) - } return u } -func (p *ChangeServiceForSystemVmParams) SetDetails(v map[string]string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["details"] = v - return -} - -func (p *ChangeServiceForSystemVmParams) SetId(v string) { +func (p *RebootSystemVmParams) SetId(v string) { if p.p == nil { p.p = make(map[string]interface{}) } @@ -856,67 +645,81 @@ func (p *ChangeServiceForSystemVmParams) SetId(v string) { return } -func (p *ChangeServiceForSystemVmParams) SetServiceofferingid(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["serviceofferingid"] = v - return -} - -// You should always use this function to get a new ChangeServiceForSystemVmParams instance, +// You should always use this function to get a new RebootSystemVmParams instance, // as then you are sure you have configured all required params -func (s *SystemVMService) NewChangeServiceForSystemVmParams(id string, serviceofferingid string) *ChangeServiceForSystemVmParams { - p := &ChangeServiceForSystemVmParams{} +func (s *SystemVMService) NewRebootSystemVmParams(id string) *RebootSystemVmParams { + p := &RebootSystemVmParams{} p.p = make(map[string]interface{}) p.p["id"] = id - p.p["serviceofferingid"] = serviceofferingid return p } -// Changes the service offering for a system vm (console proxy or secondary storage). The system vm must be in a "Stopped" state for this command to take effect. -func (s *SystemVMService) ChangeServiceForSystemVm(p *ChangeServiceForSystemVmParams) (*ChangeServiceForSystemVmResponse, error) { - resp, err := s.cs.newRequest("changeServiceForSystemVm", p.toURLValues()) +// Reboots a system VM. +func (s *SystemVMService) RebootSystemVm(p *RebootSystemVmParams) (*RebootSystemVmResponse, error) { + resp, err := s.cs.newRequest("rebootSystemVm", p.toURLValues()) if err != nil { return nil, err } - var r ChangeServiceForSystemVmResponse + var r RebootSystemVmResponse if err := json.Unmarshal(resp, &r); err != nil { return nil, err } + + // If we have a async client, we need to wait for the async result + if s.cs.async { + b, err := s.cs.GetAsyncJobResult(r.JobID, s.cs.timeout) + if err != nil { + if err == AsyncTimeoutErr { + return &r, err + } + return nil, err + } + + b, err = getRawValue(b) + if err != nil { + return nil, err + } + + if err := json.Unmarshal(b, &r); err != nil { + return nil, err + } + } + return &r, nil } -type ChangeServiceForSystemVmResponse struct { - Activeviewersessions int `json:"activeviewersessions,omitempty"` - Created string `json:"created,omitempty"` - Dns1 string `json:"dns1,omitempty"` - Dns2 string `json:"dns2,omitempty"` - Gateway string `json:"gateway,omitempty"` - Hostid string `json:"hostid,omitempty"` - Hostname string `json:"hostname,omitempty"` - Hypervisor string `json:"hypervisor,omitempty"` - Id string `json:"id,omitempty"` - Jobid string `json:"jobid,omitempty"` - Jobstatus int `json:"jobstatus,omitempty"` - Linklocalip string `json:"linklocalip,omitempty"` - Linklocalmacaddress string `json:"linklocalmacaddress,omitempty"` - Linklocalnetmask string `json:"linklocalnetmask,omitempty"` - Name string `json:"name,omitempty"` - Networkdomain string `json:"networkdomain,omitempty"` - Podid string `json:"podid,omitempty"` - Privateip string `json:"privateip,omitempty"` - Privatemacaddress string `json:"privatemacaddress,omitempty"` - Privatenetmask string `json:"privatenetmask,omitempty"` - Publicip string `json:"publicip,omitempty"` - Publicmacaddress string `json:"publicmacaddress,omitempty"` - Publicnetmask string `json:"publicnetmask,omitempty"` - State string `json:"state,omitempty"` - Systemvmtype string `json:"systemvmtype,omitempty"` - Templateid string `json:"templateid,omitempty"` - Zoneid string `json:"zoneid,omitempty"` - Zonename string `json:"zonename,omitempty"` +type RebootSystemVmResponse struct { + Activeviewersessions int `json:"activeviewersessions"` + Created string `json:"created"` + Dns1 string `json:"dns1"` + Dns2 string `json:"dns2"` + Gateway string `json:"gateway"` + Guestvlan string `json:"guestvlan"` + Hostid string `json:"hostid"` + Hostname string `json:"hostname"` + Hypervisor string `json:"hypervisor"` + Id string `json:"id"` + JobID string `json:"jobid"` + Jobstatus int `json:"jobstatus"` + Linklocalip string `json:"linklocalip"` + Linklocalmacaddress string `json:"linklocalmacaddress"` + Linklocalnetmask string `json:"linklocalnetmask"` + Name string `json:"name"` + Networkdomain string `json:"networkdomain"` + Podid string `json:"podid"` + Privateip string `json:"privateip"` + Privatemacaddress string `json:"privatemacaddress"` + Privatenetmask string `json:"privatenetmask"` + Publicip string `json:"publicip"` + Publicmacaddress string `json:"publicmacaddress"` + Publicnetmask string `json:"publicnetmask"` + Publicvlan []string `json:"publicvlan"` + State string `json:"state"` + Systemvmtype string `json:"systemvmtype"` + Templateid string `json:"templateid"` + Zoneid string `json:"zoneid"` + Zonename string `json:"zonename"` } type ScaleSystemVmParams struct { @@ -931,8 +734,7 @@ func (p *ScaleSystemVmParams) toURLValues() url.Values { if v, found := p.p["details"]; found { i := 0 for k, vv := range v.(map[string]string) { - u.Set(fmt.Sprintf("details[%d].key", i), k) - u.Set(fmt.Sprintf("details[%d].value", i), vv) + u.Set(fmt.Sprintf("details[%d].%s", i, k), vv) i++ } } @@ -1010,37 +812,251 @@ func (s *SystemVMService) ScaleSystemVm(p *ScaleSystemVmParams) (*ScaleSystemVmR return nil, err } } + return &r, nil } type ScaleSystemVmResponse struct { - JobID string `json:"jobid,omitempty"` - Activeviewersessions int `json:"activeviewersessions,omitempty"` - Created string `json:"created,omitempty"` - Dns1 string `json:"dns1,omitempty"` - Dns2 string `json:"dns2,omitempty"` - Gateway string `json:"gateway,omitempty"` - Hostid string `json:"hostid,omitempty"` - Hostname string `json:"hostname,omitempty"` - Hypervisor string `json:"hypervisor,omitempty"` - Id string `json:"id,omitempty"` - Jobid string `json:"jobid,omitempty"` - Jobstatus int `json:"jobstatus,omitempty"` - Linklocalip string `json:"linklocalip,omitempty"` - Linklocalmacaddress string `json:"linklocalmacaddress,omitempty"` - Linklocalnetmask string `json:"linklocalnetmask,omitempty"` - Name string `json:"name,omitempty"` - Networkdomain string `json:"networkdomain,omitempty"` - Podid string `json:"podid,omitempty"` - Privateip string `json:"privateip,omitempty"` - Privatemacaddress string `json:"privatemacaddress,omitempty"` - Privatenetmask string `json:"privatenetmask,omitempty"` - Publicip string `json:"publicip,omitempty"` - Publicmacaddress string `json:"publicmacaddress,omitempty"` - Publicnetmask string `json:"publicnetmask,omitempty"` - State string `json:"state,omitempty"` - Systemvmtype string `json:"systemvmtype,omitempty"` - Templateid string `json:"templateid,omitempty"` - Zoneid string `json:"zoneid,omitempty"` - Zonename string `json:"zonename,omitempty"` + Activeviewersessions int `json:"activeviewersessions"` + Created string `json:"created"` + Dns1 string `json:"dns1"` + Dns2 string `json:"dns2"` + Gateway string `json:"gateway"` + Guestvlan string `json:"guestvlan"` + Hostid string `json:"hostid"` + Hostname string `json:"hostname"` + Hypervisor string `json:"hypervisor"` + Id string `json:"id"` + JobID string `json:"jobid"` + Jobstatus int `json:"jobstatus"` + Linklocalip string `json:"linklocalip"` + Linklocalmacaddress string `json:"linklocalmacaddress"` + Linklocalnetmask string `json:"linklocalnetmask"` + Name string `json:"name"` + Networkdomain string `json:"networkdomain"` + Podid string `json:"podid"` + Privateip string `json:"privateip"` + Privatemacaddress string `json:"privatemacaddress"` + Privatenetmask string `json:"privatenetmask"` + Publicip string `json:"publicip"` + Publicmacaddress string `json:"publicmacaddress"` + Publicnetmask string `json:"publicnetmask"` + Publicvlan []string `json:"publicvlan"` + State string `json:"state"` + Systemvmtype string `json:"systemvmtype"` + Templateid string `json:"templateid"` + Zoneid string `json:"zoneid"` + Zonename string `json:"zonename"` +} + +type StartSystemVmParams struct { + p map[string]interface{} +} + +func (p *StartSystemVmParams) toURLValues() url.Values { + u := url.Values{} + if p.p == nil { + return u + } + if v, found := p.p["id"]; found { + u.Set("id", v.(string)) + } + return u +} + +func (p *StartSystemVmParams) SetId(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["id"] = v + return +} + +// You should always use this function to get a new StartSystemVmParams instance, +// as then you are sure you have configured all required params +func (s *SystemVMService) NewStartSystemVmParams(id string) *StartSystemVmParams { + p := &StartSystemVmParams{} + p.p = make(map[string]interface{}) + p.p["id"] = id + return p +} + +// Starts a system virtual machine. +func (s *SystemVMService) StartSystemVm(p *StartSystemVmParams) (*StartSystemVmResponse, error) { + resp, err := s.cs.newRequest("startSystemVm", p.toURLValues()) + if err != nil { + return nil, err + } + + var r StartSystemVmResponse + if err := json.Unmarshal(resp, &r); err != nil { + return nil, err + } + + // If we have a async client, we need to wait for the async result + if s.cs.async { + b, err := s.cs.GetAsyncJobResult(r.JobID, s.cs.timeout) + if err != nil { + if err == AsyncTimeoutErr { + return &r, err + } + return nil, err + } + + b, err = getRawValue(b) + if err != nil { + return nil, err + } + + if err := json.Unmarshal(b, &r); err != nil { + return nil, err + } + } + + return &r, nil +} + +type StartSystemVmResponse struct { + Activeviewersessions int `json:"activeviewersessions"` + Created string `json:"created"` + Dns1 string `json:"dns1"` + Dns2 string `json:"dns2"` + Gateway string `json:"gateway"` + Guestvlan string `json:"guestvlan"` + Hostid string `json:"hostid"` + Hostname string `json:"hostname"` + Hypervisor string `json:"hypervisor"` + Id string `json:"id"` + JobID string `json:"jobid"` + Jobstatus int `json:"jobstatus"` + Linklocalip string `json:"linklocalip"` + Linklocalmacaddress string `json:"linklocalmacaddress"` + Linklocalnetmask string `json:"linklocalnetmask"` + Name string `json:"name"` + Networkdomain string `json:"networkdomain"` + Podid string `json:"podid"` + Privateip string `json:"privateip"` + Privatemacaddress string `json:"privatemacaddress"` + Privatenetmask string `json:"privatenetmask"` + Publicip string `json:"publicip"` + Publicmacaddress string `json:"publicmacaddress"` + Publicnetmask string `json:"publicnetmask"` + Publicvlan []string `json:"publicvlan"` + State string `json:"state"` + Systemvmtype string `json:"systemvmtype"` + Templateid string `json:"templateid"` + Zoneid string `json:"zoneid"` + Zonename string `json:"zonename"` +} + +type StopSystemVmParams struct { + p map[string]interface{} +} + +func (p *StopSystemVmParams) toURLValues() url.Values { + u := url.Values{} + if p.p == nil { + return u + } + if v, found := p.p["forced"]; found { + vv := strconv.FormatBool(v.(bool)) + u.Set("forced", vv) + } + if v, found := p.p["id"]; found { + u.Set("id", v.(string)) + } + return u +} + +func (p *StopSystemVmParams) SetForced(v bool) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["forced"] = v + return +} + +func (p *StopSystemVmParams) SetId(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["id"] = v + return +} + +// You should always use this function to get a new StopSystemVmParams instance, +// as then you are sure you have configured all required params +func (s *SystemVMService) NewStopSystemVmParams(id string) *StopSystemVmParams { + p := &StopSystemVmParams{} + p.p = make(map[string]interface{}) + p.p["id"] = id + return p +} + +// Stops a system VM. +func (s *SystemVMService) StopSystemVm(p *StopSystemVmParams) (*StopSystemVmResponse, error) { + resp, err := s.cs.newRequest("stopSystemVm", p.toURLValues()) + if err != nil { + return nil, err + } + + var r StopSystemVmResponse + if err := json.Unmarshal(resp, &r); err != nil { + return nil, err + } + + // If we have a async client, we need to wait for the async result + if s.cs.async { + b, err := s.cs.GetAsyncJobResult(r.JobID, s.cs.timeout) + if err != nil { + if err == AsyncTimeoutErr { + return &r, err + } + return nil, err + } + + b, err = getRawValue(b) + if err != nil { + return nil, err + } + + if err := json.Unmarshal(b, &r); err != nil { + return nil, err + } + } + + return &r, nil +} + +type StopSystemVmResponse struct { + Activeviewersessions int `json:"activeviewersessions"` + Created string `json:"created"` + Dns1 string `json:"dns1"` + Dns2 string `json:"dns2"` + Gateway string `json:"gateway"` + Guestvlan string `json:"guestvlan"` + Hostid string `json:"hostid"` + Hostname string `json:"hostname"` + Hypervisor string `json:"hypervisor"` + Id string `json:"id"` + JobID string `json:"jobid"` + Jobstatus int `json:"jobstatus"` + Linklocalip string `json:"linklocalip"` + Linklocalmacaddress string `json:"linklocalmacaddress"` + Linklocalnetmask string `json:"linklocalnetmask"` + Name string `json:"name"` + Networkdomain string `json:"networkdomain"` + Podid string `json:"podid"` + Privateip string `json:"privateip"` + Privatemacaddress string `json:"privatemacaddress"` + Privatenetmask string `json:"privatenetmask"` + Publicip string `json:"publicip"` + Publicmacaddress string `json:"publicmacaddress"` + Publicnetmask string `json:"publicnetmask"` + Publicvlan []string `json:"publicvlan"` + State string `json:"state"` + Systemvmtype string `json:"systemvmtype"` + Templateid string `json:"templateid"` + Zoneid string `json:"zoneid"` + Zonename string `json:"zonename"` } diff --git a/vendor/github.com/xanzy/go-cloudstack/cloudstack/TemplateService.go b/vendor/github.com/xanzy/go-cloudstack/cloudstack/TemplateService.go index 30498c7c6..2c40bbdee 100644 --- a/vendor/github.com/xanzy/go-cloudstack/cloudstack/TemplateService.go +++ b/vendor/github.com/xanzy/go-cloudstack/cloudstack/TemplateService.go @@ -1,5 +1,5 @@ // -// Copyright 2016, Sander van Harmelen +// Copyright 2018, Sander van Harmelen // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -24,6 +24,151 @@ import ( "strings" ) +type CopyTemplateParams struct { + p map[string]interface{} +} + +func (p *CopyTemplateParams) toURLValues() url.Values { + u := url.Values{} + if p.p == nil { + return u + } + if v, found := p.p["destzoneid"]; found { + u.Set("destzoneid", v.(string)) + } + if v, found := p.p["destzoneids"]; found { + vv := strings.Join(v.([]string), ",") + u.Set("destzoneids", vv) + } + if v, found := p.p["id"]; found { + u.Set("id", v.(string)) + } + if v, found := p.p["sourcezoneid"]; found { + u.Set("sourcezoneid", v.(string)) + } + return u +} + +func (p *CopyTemplateParams) SetDestzoneid(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["destzoneid"] = v + return +} + +func (p *CopyTemplateParams) SetDestzoneids(v []string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["destzoneids"] = v + return +} + +func (p *CopyTemplateParams) SetId(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["id"] = v + return +} + +func (p *CopyTemplateParams) SetSourcezoneid(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["sourcezoneid"] = v + return +} + +// You should always use this function to get a new CopyTemplateParams instance, +// as then you are sure you have configured all required params +func (s *TemplateService) NewCopyTemplateParams(id string) *CopyTemplateParams { + p := &CopyTemplateParams{} + p.p = make(map[string]interface{}) + p.p["id"] = id + return p +} + +// Copies a template from one zone to another. +func (s *TemplateService) CopyTemplate(p *CopyTemplateParams) (*CopyTemplateResponse, error) { + resp, err := s.cs.newRequest("copyTemplate", p.toURLValues()) + if err != nil { + return nil, err + } + + var r CopyTemplateResponse + if err := json.Unmarshal(resp, &r); err != nil { + return nil, err + } + + // If we have a async client, we need to wait for the async result + if s.cs.async { + b, err := s.cs.GetAsyncJobResult(r.JobID, s.cs.timeout) + if err != nil { + if err == AsyncTimeoutErr { + return &r, err + } + return nil, err + } + + b, err = getRawValue(b) + if err != nil { + return nil, err + } + + if err := json.Unmarshal(b, &r); err != nil { + return nil, err + } + } + + return &r, nil +} + +type CopyTemplateResponse struct { + JobID string `json:"jobid"` + Account string `json:"account"` + Accountid string `json:"accountid"` + Bits int `json:"bits"` + Bootable bool `json:"bootable"` + Checksum string `json:"checksum"` + Childtemplates []interface{} `json:"childtemplates"` + Created string `json:"created"` + CrossZones bool `json:"crossZones"` + Details map[string]string `json:"details"` + Directdownload bool `json:"directdownload"` + Displaytext string `json:"displaytext"` + Domain string `json:"domain"` + Domainid string `json:"domainid"` + Format string `json:"format"` + Hostid string `json:"hostid"` + Hostname string `json:"hostname"` + Hypervisor string `json:"hypervisor"` + Id string `json:"id"` + Isdynamicallyscalable bool `json:"isdynamicallyscalable"` + Isextractable bool `json:"isextractable"` + Isfeatured bool `json:"isfeatured"` + Ispublic bool `json:"ispublic"` + Isready bool `json:"isready"` + Name string `json:"name"` + Ostypeid string `json:"ostypeid"` + Ostypename string `json:"ostypename"` + Parenttemplateid string `json:"parenttemplateid"` + Passwordenabled bool `json:"passwordenabled"` + Physicalsize int64 `json:"physicalsize"` + Project string `json:"project"` + Projectid string `json:"projectid"` + Removed string `json:"removed"` + Size int64 `json:"size"` + Sourcetemplateid string `json:"sourcetemplateid"` + Sshkeyenabled bool `json:"sshkeyenabled"` + Status string `json:"status"` + Templatetag string `json:"templatetag"` + Templatetype string `json:"templatetype"` + Zoneid string `json:"zoneid"` + Zonename string `json:"zonename"` +} + type CreateTemplateParams struct { p map[string]interface{} } @@ -40,8 +185,7 @@ func (p *CreateTemplateParams) toURLValues() url.Values { if v, found := p.p["details"]; found { i := 0 for k, vv := range v.(map[string]string) { - u.Set(fmt.Sprintf("details[%d].key", i), k) - u.Set(fmt.Sprintf("details[%d].value", i), vv) + u.Set(fmt.Sprintf("details[%d].%s", i, k), vv) i++ } } @@ -265,778 +409,52 @@ func (s *TemplateService) CreateTemplate(p *CreateTemplateParams) (*CreateTempla return nil, err } } + return &r, nil } type CreateTemplateResponse struct { - JobID string `json:"jobid,omitempty"` - Account string `json:"account,omitempty"` - Accountid string `json:"accountid,omitempty"` - Bootable bool `json:"bootable,omitempty"` - Checksum string `json:"checksum,omitempty"` - Created string `json:"created,omitempty"` - CrossZones bool `json:"crossZones,omitempty"` - Details map[string]string `json:"details,omitempty"` - Displaytext string `json:"displaytext,omitempty"` - Domain string `json:"domain,omitempty"` - Domainid string `json:"domainid,omitempty"` - Format string `json:"format,omitempty"` - Hostid string `json:"hostid,omitempty"` - Hostname string `json:"hostname,omitempty"` - Hypervisor string `json:"hypervisor,omitempty"` - Id string `json:"id,omitempty"` - Isdynamicallyscalable bool `json:"isdynamicallyscalable,omitempty"` - Isextractable bool `json:"isextractable,omitempty"` - Isfeatured bool `json:"isfeatured,omitempty"` - Ispublic bool `json:"ispublic,omitempty"` - Isready bool `json:"isready,omitempty"` - Name string `json:"name,omitempty"` - Ostypeid string `json:"ostypeid,omitempty"` - Ostypename string `json:"ostypename,omitempty"` - Passwordenabled bool `json:"passwordenabled,omitempty"` - Project string `json:"project,omitempty"` - Projectid string `json:"projectid,omitempty"` - Removed string `json:"removed,omitempty"` - Size int64 `json:"size,omitempty"` - Sourcetemplateid string `json:"sourcetemplateid,omitempty"` - Sshkeyenabled bool `json:"sshkeyenabled,omitempty"` - Status string `json:"status,omitempty"` - Tags []struct { - Account string `json:"account,omitempty"` - Customer string `json:"customer,omitempty"` - Domain string `json:"domain,omitempty"` - Domainid string `json:"domainid,omitempty"` - Key string `json:"key,omitempty"` - Project string `json:"project,omitempty"` - Projectid string `json:"projectid,omitempty"` - Resourceid string `json:"resourceid,omitempty"` - Resourcetype string `json:"resourcetype,omitempty"` - Value string `json:"value,omitempty"` - } `json:"tags,omitempty"` - Templatetag string `json:"templatetag,omitempty"` - Templatetype string `json:"templatetype,omitempty"` - Zoneid string `json:"zoneid,omitempty"` - Zonename string `json:"zonename,omitempty"` -} - -type RegisterTemplateParams struct { - p map[string]interface{} -} - -func (p *RegisterTemplateParams) toURLValues() url.Values { - u := url.Values{} - if p.p == nil { - return u - } - if v, found := p.p["account"]; found { - u.Set("account", v.(string)) - } - if v, found := p.p["bits"]; found { - vv := strconv.Itoa(v.(int)) - u.Set("bits", vv) - } - if v, found := p.p["checksum"]; found { - u.Set("checksum", v.(string)) - } - if v, found := p.p["details"]; found { - i := 0 - for k, vv := range v.(map[string]string) { - u.Set(fmt.Sprintf("details[%d].key", i), k) - u.Set(fmt.Sprintf("details[%d].value", i), vv) - i++ - } - } - if v, found := p.p["displaytext"]; found { - u.Set("displaytext", v.(string)) - } - if v, found := p.p["domainid"]; found { - u.Set("domainid", v.(string)) - } - if v, found := p.p["format"]; found { - u.Set("format", v.(string)) - } - if v, found := p.p["hypervisor"]; found { - u.Set("hypervisor", v.(string)) - } - if v, found := p.p["isdynamicallyscalable"]; found { - vv := strconv.FormatBool(v.(bool)) - u.Set("isdynamicallyscalable", vv) - } - if v, found := p.p["isextractable"]; found { - vv := strconv.FormatBool(v.(bool)) - u.Set("isextractable", vv) - } - if v, found := p.p["isfeatured"]; found { - vv := strconv.FormatBool(v.(bool)) - u.Set("isfeatured", vv) - } - if v, found := p.p["ispublic"]; found { - vv := strconv.FormatBool(v.(bool)) - u.Set("ispublic", vv) - } - if v, found := p.p["isrouting"]; found { - vv := strconv.FormatBool(v.(bool)) - u.Set("isrouting", vv) - } - if v, found := p.p["name"]; found { - u.Set("name", v.(string)) - } - if v, found := p.p["ostypeid"]; found { - u.Set("ostypeid", v.(string)) - } - if v, found := p.p["passwordenabled"]; found { - vv := strconv.FormatBool(v.(bool)) - u.Set("passwordenabled", vv) - } - if v, found := p.p["projectid"]; found { - u.Set("projectid", v.(string)) - } - if v, found := p.p["requireshvm"]; found { - vv := strconv.FormatBool(v.(bool)) - u.Set("requireshvm", vv) - } - if v, found := p.p["sshkeyenabled"]; found { - vv := strconv.FormatBool(v.(bool)) - u.Set("sshkeyenabled", vv) - } - if v, found := p.p["templatetag"]; found { - u.Set("templatetag", v.(string)) - } - if v, found := p.p["url"]; found { - u.Set("url", v.(string)) - } - if v, found := p.p["zoneid"]; found { - u.Set("zoneid", v.(string)) - } - return u -} - -func (p *RegisterTemplateParams) SetAccount(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["account"] = v - return -} - -func (p *RegisterTemplateParams) SetBits(v int) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["bits"] = v - return -} - -func (p *RegisterTemplateParams) SetChecksum(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["checksum"] = v - return -} - -func (p *RegisterTemplateParams) SetDetails(v map[string]string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["details"] = v - return -} - -func (p *RegisterTemplateParams) SetDisplaytext(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["displaytext"] = v - return -} - -func (p *RegisterTemplateParams) SetDomainid(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["domainid"] = v - return -} - -func (p *RegisterTemplateParams) SetFormat(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["format"] = v - return -} - -func (p *RegisterTemplateParams) SetHypervisor(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["hypervisor"] = v - return -} - -func (p *RegisterTemplateParams) SetIsdynamicallyscalable(v bool) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["isdynamicallyscalable"] = v - return -} - -func (p *RegisterTemplateParams) SetIsextractable(v bool) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["isextractable"] = v - return -} - -func (p *RegisterTemplateParams) SetIsfeatured(v bool) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["isfeatured"] = v - return -} - -func (p *RegisterTemplateParams) SetIspublic(v bool) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["ispublic"] = v - return -} - -func (p *RegisterTemplateParams) SetIsrouting(v bool) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["isrouting"] = v - return -} - -func (p *RegisterTemplateParams) SetName(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["name"] = v - return -} - -func (p *RegisterTemplateParams) SetOstypeid(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["ostypeid"] = v - return -} - -func (p *RegisterTemplateParams) SetPasswordenabled(v bool) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["passwordenabled"] = v - return -} - -func (p *RegisterTemplateParams) SetProjectid(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["projectid"] = v - return -} - -func (p *RegisterTemplateParams) SetRequireshvm(v bool) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["requireshvm"] = v - return -} - -func (p *RegisterTemplateParams) SetSshkeyenabled(v bool) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["sshkeyenabled"] = v - return -} - -func (p *RegisterTemplateParams) SetTemplatetag(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["templatetag"] = v - return -} - -func (p *RegisterTemplateParams) SetUrl(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["url"] = v - return -} - -func (p *RegisterTemplateParams) SetZoneid(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["zoneid"] = v - return -} - -// You should always use this function to get a new RegisterTemplateParams instance, -// as then you are sure you have configured all required params -func (s *TemplateService) NewRegisterTemplateParams(displaytext string, format string, hypervisor string, name string, ostypeid string, url string, zoneid string) *RegisterTemplateParams { - p := &RegisterTemplateParams{} - p.p = make(map[string]interface{}) - p.p["displaytext"] = displaytext - p.p["format"] = format - p.p["hypervisor"] = hypervisor - p.p["name"] = name - p.p["ostypeid"] = ostypeid - p.p["url"] = url - p.p["zoneid"] = zoneid - return p -} - -// Registers an existing template into the CloudStack cloud. -func (s *TemplateService) RegisterTemplate(p *RegisterTemplateParams) (*RegisterTemplateResponse, error) { - resp, err := s.cs.newRequest("registerTemplate", p.toURLValues()) - if err != nil { - return nil, err - } - - var r RegisterTemplateResponse - if err := json.Unmarshal(resp, &r); err != nil { - return nil, err - } - return &r, nil -} - -type RegisterTemplateResponse struct { - Count int `json:"count"` - RegisterTemplate []*RegisterTemplate `json:"template"` -} - -type RegisterTemplate struct { - Account string `json:"account,omitempty"` - Accountid string `json:"accountid,omitempty"` - Bootable bool `json:"bootable,omitempty"` - Checksum string `json:"checksum,omitempty"` - Created string `json:"created,omitempty"` - CrossZones bool `json:"crossZones,omitempty"` - Details map[string]string `json:"details,omitempty"` - Displaytext string `json:"displaytext,omitempty"` - Domain string `json:"domain,omitempty"` - Domainid string `json:"domainid,omitempty"` - Format string `json:"format,omitempty"` - Hostid string `json:"hostid,omitempty"` - Hostname string `json:"hostname,omitempty"` - Hypervisor string `json:"hypervisor,omitempty"` - Id string `json:"id,omitempty"` - Isdynamicallyscalable bool `json:"isdynamicallyscalable,omitempty"` - Isextractable bool `json:"isextractable,omitempty"` - Isfeatured bool `json:"isfeatured,omitempty"` - Ispublic bool `json:"ispublic,omitempty"` - Isready bool `json:"isready,omitempty"` - Name string `json:"name,omitempty"` - Ostypeid string `json:"ostypeid,omitempty"` - Ostypename string `json:"ostypename,omitempty"` - Passwordenabled bool `json:"passwordenabled,omitempty"` - Project string `json:"project,omitempty"` - Projectid string `json:"projectid,omitempty"` - Removed string `json:"removed,omitempty"` - Size int64 `json:"size,omitempty"` - Sourcetemplateid string `json:"sourcetemplateid,omitempty"` - Sshkeyenabled bool `json:"sshkeyenabled,omitempty"` - Status string `json:"status,omitempty"` - Tags []struct { - Account string `json:"account,omitempty"` - Customer string `json:"customer,omitempty"` - Domain string `json:"domain,omitempty"` - Domainid string `json:"domainid,omitempty"` - Key string `json:"key,omitempty"` - Project string `json:"project,omitempty"` - Projectid string `json:"projectid,omitempty"` - Resourceid string `json:"resourceid,omitempty"` - Resourcetype string `json:"resourcetype,omitempty"` - Value string `json:"value,omitempty"` - } `json:"tags,omitempty"` - Templatetag string `json:"templatetag,omitempty"` - Templatetype string `json:"templatetype,omitempty"` - Zoneid string `json:"zoneid,omitempty"` - Zonename string `json:"zonename,omitempty"` -} - -type UpdateTemplateParams struct { - p map[string]interface{} -} - -func (p *UpdateTemplateParams) toURLValues() url.Values { - u := url.Values{} - if p.p == nil { - return u - } - if v, found := p.p["bootable"]; found { - vv := strconv.FormatBool(v.(bool)) - u.Set("bootable", vv) - } - if v, found := p.p["details"]; found { - i := 0 - for k, vv := range v.(map[string]string) { - u.Set(fmt.Sprintf("details[%d].key", i), k) - u.Set(fmt.Sprintf("details[%d].value", i), vv) - i++ - } - } - if v, found := p.p["displaytext"]; found { - u.Set("displaytext", v.(string)) - } - if v, found := p.p["format"]; found { - u.Set("format", v.(string)) - } - if v, found := p.p["id"]; found { - u.Set("id", v.(string)) - } - if v, found := p.p["isdynamicallyscalable"]; found { - vv := strconv.FormatBool(v.(bool)) - u.Set("isdynamicallyscalable", vv) - } - if v, found := p.p["isrouting"]; found { - vv := strconv.FormatBool(v.(bool)) - u.Set("isrouting", vv) - } - if v, found := p.p["name"]; found { - u.Set("name", v.(string)) - } - if v, found := p.p["ostypeid"]; found { - u.Set("ostypeid", v.(string)) - } - if v, found := p.p["passwordenabled"]; found { - vv := strconv.FormatBool(v.(bool)) - u.Set("passwordenabled", vv) - } - if v, found := p.p["requireshvm"]; found { - vv := strconv.FormatBool(v.(bool)) - u.Set("requireshvm", vv) - } - if v, found := p.p["sortkey"]; found { - vv := strconv.Itoa(v.(int)) - u.Set("sortkey", vv) - } - return u -} - -func (p *UpdateTemplateParams) SetBootable(v bool) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["bootable"] = v - return -} - -func (p *UpdateTemplateParams) SetDetails(v map[string]string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["details"] = v - return -} - -func (p *UpdateTemplateParams) SetDisplaytext(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["displaytext"] = v - return -} - -func (p *UpdateTemplateParams) SetFormat(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["format"] = v - return -} - -func (p *UpdateTemplateParams) SetId(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["id"] = v - return -} - -func (p *UpdateTemplateParams) SetIsdynamicallyscalable(v bool) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["isdynamicallyscalable"] = v - return -} - -func (p *UpdateTemplateParams) SetIsrouting(v bool) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["isrouting"] = v - return -} - -func (p *UpdateTemplateParams) SetName(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["name"] = v - return -} - -func (p *UpdateTemplateParams) SetOstypeid(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["ostypeid"] = v - return -} - -func (p *UpdateTemplateParams) SetPasswordenabled(v bool) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["passwordenabled"] = v - return -} - -func (p *UpdateTemplateParams) SetRequireshvm(v bool) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["requireshvm"] = v - return -} - -func (p *UpdateTemplateParams) SetSortkey(v int) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["sortkey"] = v - return -} - -// You should always use this function to get a new UpdateTemplateParams instance, -// as then you are sure you have configured all required params -func (s *TemplateService) NewUpdateTemplateParams(id string) *UpdateTemplateParams { - p := &UpdateTemplateParams{} - p.p = make(map[string]interface{}) - p.p["id"] = id - return p -} - -// Updates attributes of a template. -func (s *TemplateService) UpdateTemplate(p *UpdateTemplateParams) (*UpdateTemplateResponse, error) { - resp, err := s.cs.newRequest("updateTemplate", p.toURLValues()) - if err != nil { - return nil, err - } - - var r UpdateTemplateResponse - if err := json.Unmarshal(resp, &r); err != nil { - return nil, err - } - return &r, nil -} - -type UpdateTemplateResponse struct { - Account string `json:"account,omitempty"` - Accountid string `json:"accountid,omitempty"` - Bootable bool `json:"bootable,omitempty"` - Checksum string `json:"checksum,omitempty"` - Created string `json:"created,omitempty"` - CrossZones bool `json:"crossZones,omitempty"` - Details map[string]string `json:"details,omitempty"` - Displaytext string `json:"displaytext,omitempty"` - Domain string `json:"domain,omitempty"` - Domainid string `json:"domainid,omitempty"` - Format string `json:"format,omitempty"` - Hostid string `json:"hostid,omitempty"` - Hostname string `json:"hostname,omitempty"` - Hypervisor string `json:"hypervisor,omitempty"` - Id string `json:"id,omitempty"` - Isdynamicallyscalable bool `json:"isdynamicallyscalable,omitempty"` - Isextractable bool `json:"isextractable,omitempty"` - Isfeatured bool `json:"isfeatured,omitempty"` - Ispublic bool `json:"ispublic,omitempty"` - Isready bool `json:"isready,omitempty"` - Name string `json:"name,omitempty"` - Ostypeid string `json:"ostypeid,omitempty"` - Ostypename string `json:"ostypename,omitempty"` - Passwordenabled bool `json:"passwordenabled,omitempty"` - Project string `json:"project,omitempty"` - Projectid string `json:"projectid,omitempty"` - Removed string `json:"removed,omitempty"` - Size int64 `json:"size,omitempty"` - Sourcetemplateid string `json:"sourcetemplateid,omitempty"` - Sshkeyenabled bool `json:"sshkeyenabled,omitempty"` - Status string `json:"status,omitempty"` - Tags []struct { - Account string `json:"account,omitempty"` - Customer string `json:"customer,omitempty"` - Domain string `json:"domain,omitempty"` - Domainid string `json:"domainid,omitempty"` - Key string `json:"key,omitempty"` - Project string `json:"project,omitempty"` - Projectid string `json:"projectid,omitempty"` - Resourceid string `json:"resourceid,omitempty"` - Resourcetype string `json:"resourcetype,omitempty"` - Value string `json:"value,omitempty"` - } `json:"tags,omitempty"` - Templatetag string `json:"templatetag,omitempty"` - Templatetype string `json:"templatetype,omitempty"` - Zoneid string `json:"zoneid,omitempty"` - Zonename string `json:"zonename,omitempty"` -} - -type CopyTemplateParams struct { - p map[string]interface{} -} - -func (p *CopyTemplateParams) toURLValues() url.Values { - u := url.Values{} - if p.p == nil { - return u - } - if v, found := p.p["destzoneid"]; found { - u.Set("destzoneid", v.(string)) - } - if v, found := p.p["id"]; found { - u.Set("id", v.(string)) - } - if v, found := p.p["sourcezoneid"]; found { - u.Set("sourcezoneid", v.(string)) - } - return u -} - -func (p *CopyTemplateParams) SetDestzoneid(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["destzoneid"] = v - return -} - -func (p *CopyTemplateParams) SetId(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["id"] = v - return -} - -func (p *CopyTemplateParams) SetSourcezoneid(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["sourcezoneid"] = v - return -} - -// You should always use this function to get a new CopyTemplateParams instance, -// as then you are sure you have configured all required params -func (s *TemplateService) NewCopyTemplateParams(destzoneid string, id string) *CopyTemplateParams { - p := &CopyTemplateParams{} - p.p = make(map[string]interface{}) - p.p["destzoneid"] = destzoneid - p.p["id"] = id - return p -} - -// Copies a template from one zone to another. -func (s *TemplateService) CopyTemplate(p *CopyTemplateParams) (*CopyTemplateResponse, error) { - resp, err := s.cs.newRequest("copyTemplate", p.toURLValues()) - if err != nil { - return nil, err - } - - var r CopyTemplateResponse - if err := json.Unmarshal(resp, &r); err != nil { - return nil, err - } - - // If we have a async client, we need to wait for the async result - if s.cs.async { - b, err := s.cs.GetAsyncJobResult(r.JobID, s.cs.timeout) - if err != nil { - if err == AsyncTimeoutErr { - return &r, err - } - return nil, err - } - - b, err = getRawValue(b) - if err != nil { - return nil, err - } - - if err := json.Unmarshal(b, &r); err != nil { - return nil, err - } - } - return &r, nil -} - -type CopyTemplateResponse struct { - JobID string `json:"jobid,omitempty"` - Account string `json:"account,omitempty"` - Accountid string `json:"accountid,omitempty"` - Bootable bool `json:"bootable,omitempty"` - Checksum string `json:"checksum,omitempty"` - Created string `json:"created,omitempty"` - CrossZones bool `json:"crossZones,omitempty"` - Details map[string]string `json:"details,omitempty"` - Displaytext string `json:"displaytext,omitempty"` - Domain string `json:"domain,omitempty"` - Domainid string `json:"domainid,omitempty"` - Format string `json:"format,omitempty"` - Hostid string `json:"hostid,omitempty"` - Hostname string `json:"hostname,omitempty"` - Hypervisor string `json:"hypervisor,omitempty"` - Id string `json:"id,omitempty"` - Isdynamicallyscalable bool `json:"isdynamicallyscalable,omitempty"` - Isextractable bool `json:"isextractable,omitempty"` - Isfeatured bool `json:"isfeatured,omitempty"` - Ispublic bool `json:"ispublic,omitempty"` - Isready bool `json:"isready,omitempty"` - Name string `json:"name,omitempty"` - Ostypeid string `json:"ostypeid,omitempty"` - Ostypename string `json:"ostypename,omitempty"` - Passwordenabled bool `json:"passwordenabled,omitempty"` - Project string `json:"project,omitempty"` - Projectid string `json:"projectid,omitempty"` - Removed string `json:"removed,omitempty"` - Size int64 `json:"size,omitempty"` - Sourcetemplateid string `json:"sourcetemplateid,omitempty"` - Sshkeyenabled bool `json:"sshkeyenabled,omitempty"` - Status string `json:"status,omitempty"` - Tags []struct { - Account string `json:"account,omitempty"` - Customer string `json:"customer,omitempty"` - Domain string `json:"domain,omitempty"` - Domainid string `json:"domainid,omitempty"` - Key string `json:"key,omitempty"` - Project string `json:"project,omitempty"` - Projectid string `json:"projectid,omitempty"` - Resourceid string `json:"resourceid,omitempty"` - Resourcetype string `json:"resourcetype,omitempty"` - Value string `json:"value,omitempty"` - } `json:"tags,omitempty"` - Templatetag string `json:"templatetag,omitempty"` - Templatetype string `json:"templatetype,omitempty"` - Zoneid string `json:"zoneid,omitempty"` - Zonename string `json:"zonename,omitempty"` + JobID string `json:"jobid"` + Account string `json:"account"` + Accountid string `json:"accountid"` + Bits int `json:"bits"` + Bootable bool `json:"bootable"` + Checksum string `json:"checksum"` + Childtemplates []interface{} `json:"childtemplates"` + Created string `json:"created"` + CrossZones bool `json:"crossZones"` + Details map[string]string `json:"details"` + Directdownload bool `json:"directdownload"` + Displaytext string `json:"displaytext"` + Domain string `json:"domain"` + Domainid string `json:"domainid"` + Format string `json:"format"` + Hostid string `json:"hostid"` + Hostname string `json:"hostname"` + Hypervisor string `json:"hypervisor"` + Id string `json:"id"` + Isdynamicallyscalable bool `json:"isdynamicallyscalable"` + Isextractable bool `json:"isextractable"` + Isfeatured bool `json:"isfeatured"` + Ispublic bool `json:"ispublic"` + Isready bool `json:"isready"` + Name string `json:"name"` + Ostypeid string `json:"ostypeid"` + Ostypename string `json:"ostypename"` + Parenttemplateid string `json:"parenttemplateid"` + Passwordenabled bool `json:"passwordenabled"` + Physicalsize int64 `json:"physicalsize"` + Project string `json:"project"` + Projectid string `json:"projectid"` + Removed string `json:"removed"` + Size int64 `json:"size"` + Sourcetemplateid string `json:"sourcetemplateid"` + Sshkeyenabled bool `json:"sshkeyenabled"` + Status string `json:"status"` + Templatetag string `json:"templatetag"` + Templatetype string `json:"templatetype"` + Zoneid string `json:"zoneid"` + Zonename string `json:"zonename"` } type DeleteTemplateParams struct { @@ -1048,6 +466,10 @@ func (p *DeleteTemplateParams) toURLValues() url.Values { if p.p == nil { return u } + if v, found := p.p["forced"]; found { + vv := strconv.FormatBool(v.(bool)) + u.Set("forced", vv) + } if v, found := p.p["id"]; found { u.Set("id", v.(string)) } @@ -1057,6 +479,14 @@ func (p *DeleteTemplateParams) toURLValues() url.Values { return u } +func (p *DeleteTemplateParams) SetForced(v bool) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["forced"] = v + return +} + func (p *DeleteTemplateParams) SetId(v string) { if p.p == nil { p.p = make(map[string]interface{}) @@ -1108,578 +538,14 @@ func (s *TemplateService) DeleteTemplate(p *DeleteTemplateParams) (*DeleteTempla return nil, err } } + return &r, nil } type DeleteTemplateResponse struct { - JobID string `json:"jobid,omitempty"` - Displaytext string `json:"displaytext,omitempty"` - Success bool `json:"success,omitempty"` -} - -type ListTemplatesParams struct { - p map[string]interface{} -} - -func (p *ListTemplatesParams) toURLValues() url.Values { - u := url.Values{} - if p.p == nil { - return u - } - if v, found := p.p["account"]; found { - u.Set("account", v.(string)) - } - if v, found := p.p["domainid"]; found { - u.Set("domainid", v.(string)) - } - if v, found := p.p["hypervisor"]; found { - u.Set("hypervisor", v.(string)) - } - if v, found := p.p["id"]; found { - u.Set("id", v.(string)) - } - if v, found := p.p["isrecursive"]; found { - vv := strconv.FormatBool(v.(bool)) - u.Set("isrecursive", vv) - } - if v, found := p.p["keyword"]; found { - u.Set("keyword", v.(string)) - } - if v, found := p.p["listall"]; found { - vv := strconv.FormatBool(v.(bool)) - u.Set("listall", vv) - } - if v, found := p.p["name"]; found { - u.Set("name", v.(string)) - } - if v, found := p.p["page"]; found { - vv := strconv.Itoa(v.(int)) - u.Set("page", vv) - } - if v, found := p.p["pagesize"]; found { - vv := strconv.Itoa(v.(int)) - u.Set("pagesize", vv) - } - if v, found := p.p["projectid"]; found { - u.Set("projectid", v.(string)) - } - if v, found := p.p["showremoved"]; found { - vv := strconv.FormatBool(v.(bool)) - u.Set("showremoved", vv) - } - if v, found := p.p["tags"]; found { - i := 0 - for k, vv := range v.(map[string]string) { - u.Set(fmt.Sprintf("tags[%d].key", i), k) - u.Set(fmt.Sprintf("tags[%d].value", i), vv) - i++ - } - } - if v, found := p.p["templatefilter"]; found { - u.Set("templatefilter", v.(string)) - } - if v, found := p.p["zoneid"]; found { - u.Set("zoneid", v.(string)) - } - return u -} - -func (p *ListTemplatesParams) SetAccount(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["account"] = v - return -} - -func (p *ListTemplatesParams) SetDomainid(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["domainid"] = v - return -} - -func (p *ListTemplatesParams) SetHypervisor(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["hypervisor"] = v - return -} - -func (p *ListTemplatesParams) SetId(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["id"] = v - return -} - -func (p *ListTemplatesParams) SetIsrecursive(v bool) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["isrecursive"] = v - return -} - -func (p *ListTemplatesParams) SetKeyword(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["keyword"] = v - return -} - -func (p *ListTemplatesParams) SetListall(v bool) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["listall"] = v - return -} - -func (p *ListTemplatesParams) SetName(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["name"] = v - return -} - -func (p *ListTemplatesParams) SetPage(v int) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["page"] = v - return -} - -func (p *ListTemplatesParams) SetPagesize(v int) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["pagesize"] = v - return -} - -func (p *ListTemplatesParams) SetProjectid(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["projectid"] = v - return -} - -func (p *ListTemplatesParams) SetShowremoved(v bool) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["showremoved"] = v - return -} - -func (p *ListTemplatesParams) SetTags(v map[string]string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["tags"] = v - return -} - -func (p *ListTemplatesParams) SetTemplatefilter(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["templatefilter"] = v - return -} - -func (p *ListTemplatesParams) SetZoneid(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["zoneid"] = v - return -} - -// You should always use this function to get a new ListTemplatesParams instance, -// as then you are sure you have configured all required params -func (s *TemplateService) NewListTemplatesParams(templatefilter string) *ListTemplatesParams { - p := &ListTemplatesParams{} - p.p = make(map[string]interface{}) - p.p["templatefilter"] = templatefilter - return p -} - -// This is a courtesy helper function, which in some cases may not work as expected! -func (s *TemplateService) GetTemplateID(name string, templatefilter string, zoneid string, opts ...OptionFunc) (string, int, error) { - p := &ListTemplatesParams{} - p.p = make(map[string]interface{}) - - p.p["name"] = name - p.p["templatefilter"] = templatefilter - p.p["zoneid"] = zoneid - - for _, fn := range opts { - if err := fn(s.cs, p); err != nil { - return "", -1, err - } - } - - l, err := s.ListTemplates(p) - if err != nil { - return "", -1, err - } - - if l.Count == 0 { - return "", l.Count, fmt.Errorf("No match found for %s: %+v", name, l) - } - - if l.Count == 1 { - return l.Templates[0].Id, l.Count, nil - } - - if l.Count > 1 { - for _, v := range l.Templates { - if v.Name == name { - return v.Id, l.Count, nil - } - } - } - return "", l.Count, fmt.Errorf("Could not find an exact match for %s: %+v", name, l) -} - -// This is a courtesy helper function, which in some cases may not work as expected! -func (s *TemplateService) GetTemplateByName(name string, templatefilter string, zoneid string, opts ...OptionFunc) (*Template, int, error) { - id, count, err := s.GetTemplateID(name, templatefilter, zoneid, opts...) - if err != nil { - return nil, count, err - } - - r, count, err := s.GetTemplateByID(id, templatefilter, opts...) - if err != nil { - return nil, count, err - } - return r, count, nil -} - -// This is a courtesy helper function, which in some cases may not work as expected! -func (s *TemplateService) GetTemplateByID(id string, templatefilter string, opts ...OptionFunc) (*Template, int, error) { - p := &ListTemplatesParams{} - p.p = make(map[string]interface{}) - - p.p["id"] = id - p.p["templatefilter"] = templatefilter - - for _, fn := range opts { - if err := fn(s.cs, p); err != nil { - return nil, -1, err - } - } - - l, err := s.ListTemplates(p) - if err != nil { - if strings.Contains(err.Error(), fmt.Sprintf( - "Invalid parameter id value=%s due to incorrect long value format, "+ - "or entity does not exist", id)) { - return nil, 0, fmt.Errorf("No match found for %s: %+v", id, l) - } - return nil, -1, err - } - - if l.Count == 0 { - return nil, l.Count, fmt.Errorf("No match found for %s: %+v", id, l) - } - - if l.Count == 1 { - return l.Templates[0], l.Count, nil - } - return nil, l.Count, fmt.Errorf("There is more then one result for Template UUID: %s!", id) -} - -// List all public, private, and privileged templates. -func (s *TemplateService) ListTemplates(p *ListTemplatesParams) (*ListTemplatesResponse, error) { - resp, err := s.cs.newRequest("listTemplates", p.toURLValues()) - if err != nil { - return nil, err - } - - var r ListTemplatesResponse - if err := json.Unmarshal(resp, &r); err != nil { - return nil, err - } - return &r, nil -} - -type ListTemplatesResponse struct { - Count int `json:"count"` - Templates []*Template `json:"template"` -} - -type Template struct { - Account string `json:"account,omitempty"` - Accountid string `json:"accountid,omitempty"` - Bootable bool `json:"bootable,omitempty"` - Checksum string `json:"checksum,omitempty"` - Created string `json:"created,omitempty"` - CrossZones bool `json:"crossZones,omitempty"` - Details map[string]string `json:"details,omitempty"` - Displaytext string `json:"displaytext,omitempty"` - Domain string `json:"domain,omitempty"` - Domainid string `json:"domainid,omitempty"` - Format string `json:"format,omitempty"` - Hostid string `json:"hostid,omitempty"` - Hostname string `json:"hostname,omitempty"` - Hypervisor string `json:"hypervisor,omitempty"` - Id string `json:"id,omitempty"` - Isdynamicallyscalable bool `json:"isdynamicallyscalable,omitempty"` - Isextractable bool `json:"isextractable,omitempty"` - Isfeatured bool `json:"isfeatured,omitempty"` - Ispublic bool `json:"ispublic,omitempty"` - Isready bool `json:"isready,omitempty"` - Name string `json:"name,omitempty"` - Ostypeid string `json:"ostypeid,omitempty"` - Ostypename string `json:"ostypename,omitempty"` - Passwordenabled bool `json:"passwordenabled,omitempty"` - Project string `json:"project,omitempty"` - Projectid string `json:"projectid,omitempty"` - Removed string `json:"removed,omitempty"` - Size int64 `json:"size,omitempty"` - Sourcetemplateid string `json:"sourcetemplateid,omitempty"` - Sshkeyenabled bool `json:"sshkeyenabled,omitempty"` - Status string `json:"status,omitempty"` - Tags []struct { - Account string `json:"account,omitempty"` - Customer string `json:"customer,omitempty"` - Domain string `json:"domain,omitempty"` - Domainid string `json:"domainid,omitempty"` - Key string `json:"key,omitempty"` - Project string `json:"project,omitempty"` - Projectid string `json:"projectid,omitempty"` - Resourceid string `json:"resourceid,omitempty"` - Resourcetype string `json:"resourcetype,omitempty"` - Value string `json:"value,omitempty"` - } `json:"tags,omitempty"` - Templatetag string `json:"templatetag,omitempty"` - Templatetype string `json:"templatetype,omitempty"` - Zoneid string `json:"zoneid,omitempty"` - Zonename string `json:"zonename,omitempty"` -} - -type UpdateTemplatePermissionsParams struct { - p map[string]interface{} -} - -func (p *UpdateTemplatePermissionsParams) toURLValues() url.Values { - u := url.Values{} - if p.p == nil { - return u - } - if v, found := p.p["accounts"]; found { - vv := strings.Join(v.([]string), ",") - u.Set("accounts", vv) - } - if v, found := p.p["id"]; found { - u.Set("id", v.(string)) - } - if v, found := p.p["isextractable"]; found { - vv := strconv.FormatBool(v.(bool)) - u.Set("isextractable", vv) - } - if v, found := p.p["isfeatured"]; found { - vv := strconv.FormatBool(v.(bool)) - u.Set("isfeatured", vv) - } - if v, found := p.p["ispublic"]; found { - vv := strconv.FormatBool(v.(bool)) - u.Set("ispublic", vv) - } - if v, found := p.p["op"]; found { - u.Set("op", v.(string)) - } - if v, found := p.p["projectids"]; found { - vv := strings.Join(v.([]string), ",") - u.Set("projectids", vv) - } - return u -} - -func (p *UpdateTemplatePermissionsParams) SetAccounts(v []string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["accounts"] = v - return -} - -func (p *UpdateTemplatePermissionsParams) SetId(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["id"] = v - return -} - -func (p *UpdateTemplatePermissionsParams) SetIsextractable(v bool) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["isextractable"] = v - return -} - -func (p *UpdateTemplatePermissionsParams) SetIsfeatured(v bool) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["isfeatured"] = v - return -} - -func (p *UpdateTemplatePermissionsParams) SetIspublic(v bool) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["ispublic"] = v - return -} - -func (p *UpdateTemplatePermissionsParams) SetOp(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["op"] = v - return -} - -func (p *UpdateTemplatePermissionsParams) SetProjectids(v []string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["projectids"] = v - return -} - -// You should always use this function to get a new UpdateTemplatePermissionsParams instance, -// as then you are sure you have configured all required params -func (s *TemplateService) NewUpdateTemplatePermissionsParams(id string) *UpdateTemplatePermissionsParams { - p := &UpdateTemplatePermissionsParams{} - p.p = make(map[string]interface{}) - p.p["id"] = id - return p -} - -// Updates a template visibility permissions. A public template is visible to all accounts within the same domain. A private template is visible only to the owner of the template. A priviledged template is a private template with account permissions added. Only accounts specified under the template permissions are visible to them. -func (s *TemplateService) UpdateTemplatePermissions(p *UpdateTemplatePermissionsParams) (*UpdateTemplatePermissionsResponse, error) { - resp, err := s.cs.newRequest("updateTemplatePermissions", p.toURLValues()) - if err != nil { - return nil, err - } - - var r UpdateTemplatePermissionsResponse - if err := json.Unmarshal(resp, &r); err != nil { - return nil, err - } - return &r, nil -} - -type UpdateTemplatePermissionsResponse struct { - Displaytext string `json:"displaytext,omitempty"` - Success string `json:"success,omitempty"` -} - -type ListTemplatePermissionsParams struct { - p map[string]interface{} -} - -func (p *ListTemplatePermissionsParams) toURLValues() url.Values { - u := url.Values{} - if p.p == nil { - return u - } - if v, found := p.p["id"]; found { - u.Set("id", v.(string)) - } - return u -} - -func (p *ListTemplatePermissionsParams) SetId(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["id"] = v - return -} - -// You should always use this function to get a new ListTemplatePermissionsParams instance, -// as then you are sure you have configured all required params -func (s *TemplateService) NewListTemplatePermissionsParams(id string) *ListTemplatePermissionsParams { - p := &ListTemplatePermissionsParams{} - p.p = make(map[string]interface{}) - p.p["id"] = id - return p -} - -// This is a courtesy helper function, which in some cases may not work as expected! -func (s *TemplateService) GetTemplatePermissionByID(id string, opts ...OptionFunc) (*TemplatePermission, int, error) { - p := &ListTemplatePermissionsParams{} - p.p = make(map[string]interface{}) - - p.p["id"] = id - - for _, fn := range opts { - if err := fn(s.cs, p); err != nil { - return nil, -1, err - } - } - - l, err := s.ListTemplatePermissions(p) - if err != nil { - if strings.Contains(err.Error(), fmt.Sprintf( - "Invalid parameter id value=%s due to incorrect long value format, "+ - "or entity does not exist", id)) { - return nil, 0, fmt.Errorf("No match found for %s: %+v", id, l) - } - return nil, -1, err - } - - if l.Count == 0 { - return nil, l.Count, fmt.Errorf("No match found for %s: %+v", id, l) - } - - if l.Count == 1 { - return l.TemplatePermissions[0], l.Count, nil - } - return nil, l.Count, fmt.Errorf("There is more then one result for TemplatePermission UUID: %s!", id) -} - -// List template visibility and all accounts that have permissions to view this template. -func (s *TemplateService) ListTemplatePermissions(p *ListTemplatePermissionsParams) (*ListTemplatePermissionsResponse, error) { - resp, err := s.cs.newRequest("listTemplatePermissions", p.toURLValues()) - if err != nil { - return nil, err - } - - var r ListTemplatePermissionsResponse - if err := json.Unmarshal(resp, &r); err != nil { - return nil, err - } - return &r, nil -} - -type ListTemplatePermissionsResponse struct { - Count int `json:"count"` - TemplatePermissions []*TemplatePermission `json:"templatepermission"` -} - -type TemplatePermission struct { - Account []string `json:"account,omitempty"` - Domainid string `json:"domainid,omitempty"` - Id string `json:"id,omitempty"` - Ispublic bool `json:"ispublic,omitempty"` - Projectids []string `json:"projectids,omitempty"` + JobID string `json:"jobid"` + Displaytext string `json:"displaytext"` + Success bool `json:"success"` } type ExtractTemplateParams struct { @@ -1779,249 +645,26 @@ func (s *TemplateService) ExtractTemplate(p *ExtractTemplateParams) (*ExtractTem return nil, err } } + return &r, nil } type ExtractTemplateResponse struct { - JobID string `json:"jobid,omitempty"` - Accountid string `json:"accountid,omitempty"` - Created string `json:"created,omitempty"` - ExtractId string `json:"extractId,omitempty"` - ExtractMode string `json:"extractMode,omitempty"` - Id string `json:"id,omitempty"` - Name string `json:"name,omitempty"` - Resultstring string `json:"resultstring,omitempty"` - State string `json:"state,omitempty"` - Status string `json:"status,omitempty"` - Storagetype string `json:"storagetype,omitempty"` - Uploadpercentage int `json:"uploadpercentage,omitempty"` - Url string `json:"url,omitempty"` - Zoneid string `json:"zoneid,omitempty"` - Zonename string `json:"zonename,omitempty"` -} - -type PrepareTemplateParams struct { - p map[string]interface{} -} - -func (p *PrepareTemplateParams) toURLValues() url.Values { - u := url.Values{} - if p.p == nil { - return u - } - if v, found := p.p["storageid"]; found { - u.Set("storageid", v.(string)) - } - if v, found := p.p["templateid"]; found { - u.Set("templateid", v.(string)) - } - if v, found := p.p["zoneid"]; found { - u.Set("zoneid", v.(string)) - } - return u -} - -func (p *PrepareTemplateParams) SetStorageid(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["storageid"] = v - return -} - -func (p *PrepareTemplateParams) SetTemplateid(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["templateid"] = v - return -} - -func (p *PrepareTemplateParams) SetZoneid(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["zoneid"] = v - return -} - -// You should always use this function to get a new PrepareTemplateParams instance, -// as then you are sure you have configured all required params -func (s *TemplateService) NewPrepareTemplateParams(templateid string, zoneid string) *PrepareTemplateParams { - p := &PrepareTemplateParams{} - p.p = make(map[string]interface{}) - p.p["templateid"] = templateid - p.p["zoneid"] = zoneid - return p -} - -// load template into primary storage -func (s *TemplateService) PrepareTemplate(p *PrepareTemplateParams) (*PrepareTemplateResponse, error) { - resp, err := s.cs.newRequest("prepareTemplate", p.toURLValues()) - if err != nil { - return nil, err - } - - var r PrepareTemplateResponse - if err := json.Unmarshal(resp, &r); err != nil { - return nil, err - } - return &r, nil -} - -type PrepareTemplateResponse struct { - Account string `json:"account,omitempty"` - Accountid string `json:"accountid,omitempty"` - Bootable bool `json:"bootable,omitempty"` - Checksum string `json:"checksum,omitempty"` - Created string `json:"created,omitempty"` - CrossZones bool `json:"crossZones,omitempty"` - Details map[string]string `json:"details,omitempty"` - Displaytext string `json:"displaytext,omitempty"` - Domain string `json:"domain,omitempty"` - Domainid string `json:"domainid,omitempty"` - Format string `json:"format,omitempty"` - Hostid string `json:"hostid,omitempty"` - Hostname string `json:"hostname,omitempty"` - Hypervisor string `json:"hypervisor,omitempty"` - Id string `json:"id,omitempty"` - Isdynamicallyscalable bool `json:"isdynamicallyscalable,omitempty"` - Isextractable bool `json:"isextractable,omitempty"` - Isfeatured bool `json:"isfeatured,omitempty"` - Ispublic bool `json:"ispublic,omitempty"` - Isready bool `json:"isready,omitempty"` - Name string `json:"name,omitempty"` - Ostypeid string `json:"ostypeid,omitempty"` - Ostypename string `json:"ostypename,omitempty"` - Passwordenabled bool `json:"passwordenabled,omitempty"` - Project string `json:"project,omitempty"` - Projectid string `json:"projectid,omitempty"` - Removed string `json:"removed,omitempty"` - Size int64 `json:"size,omitempty"` - Sourcetemplateid string `json:"sourcetemplateid,omitempty"` - Sshkeyenabled bool `json:"sshkeyenabled,omitempty"` - Status string `json:"status,omitempty"` - Tags []struct { - Account string `json:"account,omitempty"` - Customer string `json:"customer,omitempty"` - Domain string `json:"domain,omitempty"` - Domainid string `json:"domainid,omitempty"` - Key string `json:"key,omitempty"` - Project string `json:"project,omitempty"` - Projectid string `json:"projectid,omitempty"` - Resourceid string `json:"resourceid,omitempty"` - Resourcetype string `json:"resourcetype,omitempty"` - Value string `json:"value,omitempty"` - } `json:"tags,omitempty"` - Templatetag string `json:"templatetag,omitempty"` - Templatetype string `json:"templatetype,omitempty"` - Zoneid string `json:"zoneid,omitempty"` - Zonename string `json:"zonename,omitempty"` -} - -type UpgradeRouterTemplateParams struct { - p map[string]interface{} -} - -func (p *UpgradeRouterTemplateParams) toURLValues() url.Values { - u := url.Values{} - if p.p == nil { - return u - } - if v, found := p.p["account"]; found { - u.Set("account", v.(string)) - } - if v, found := p.p["clusterid"]; found { - u.Set("clusterid", v.(string)) - } - if v, found := p.p["domainid"]; found { - u.Set("domainid", v.(string)) - } - if v, found := p.p["id"]; found { - u.Set("id", v.(string)) - } - if v, found := p.p["podid"]; found { - u.Set("podid", v.(string)) - } - if v, found := p.p["zoneid"]; found { - u.Set("zoneid", v.(string)) - } - return u -} - -func (p *UpgradeRouterTemplateParams) SetAccount(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["account"] = v - return -} - -func (p *UpgradeRouterTemplateParams) SetClusterid(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["clusterid"] = v - return -} - -func (p *UpgradeRouterTemplateParams) SetDomainid(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["domainid"] = v - return -} - -func (p *UpgradeRouterTemplateParams) SetId(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["id"] = v - return -} - -func (p *UpgradeRouterTemplateParams) SetPodid(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["podid"] = v - return -} - -func (p *UpgradeRouterTemplateParams) SetZoneid(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["zoneid"] = v - return -} - -// You should always use this function to get a new UpgradeRouterTemplateParams instance, -// as then you are sure you have configured all required params -func (s *TemplateService) NewUpgradeRouterTemplateParams() *UpgradeRouterTemplateParams { - p := &UpgradeRouterTemplateParams{} - p.p = make(map[string]interface{}) - return p -} - -// Upgrades router to use newer template -func (s *TemplateService) UpgradeRouterTemplate(p *UpgradeRouterTemplateParams) (*UpgradeRouterTemplateResponse, error) { - resp, err := s.cs.newRequest("upgradeRouterTemplate", p.toURLValues()) - if err != nil { - return nil, err - } - - var r UpgradeRouterTemplateResponse - if err := json.Unmarshal(resp, &r); err != nil { - return nil, err - } - return &r, nil -} - -type UpgradeRouterTemplateResponse struct { - Jobid string `json:"jobid,omitempty"` - Jobstatus int `json:"jobstatus,omitempty"` + JobID string `json:"jobid"` + Accountid string `json:"accountid"` + Created string `json:"created"` + ExtractId string `json:"extractId"` + ExtractMode string `json:"extractMode"` + Id string `json:"id"` + Name string `json:"name"` + Resultstring string `json:"resultstring"` + State string `json:"state"` + Status string `json:"status"` + Storagetype string `json:"storagetype"` + Uploadpercentage int `json:"uploadpercentage"` + Url string `json:"url"` + Zoneid string `json:"zoneid"` + Zonename string `json:"zonename"` } type GetUploadParamsForTemplateParams struct { @@ -2046,8 +689,7 @@ func (p *GetUploadParamsForTemplateParams) toURLValues() url.Values { if v, found := p.p["details"]; found { i := 0 for k, vv := range v.(map[string]string) { - u.Set(fmt.Sprintf("details[%d].key", i), k) - u.Set(fmt.Sprintf("details[%d].value", i), vv) + u.Set(fmt.Sprintf("details[%d].%s", i, k), vv) i++ } } @@ -2306,13 +948,1437 @@ func (s *TemplateService) GetUploadParamsForTemplate(p *GetUploadParamsForTempla if err := json.Unmarshal(resp, &r); err != nil { return nil, err } + return &r, nil } type GetUploadParamsForTemplateResponse struct { - Expires string `json:"expires,omitempty"` - Id string `json:"id,omitempty"` - Metadata string `json:"metadata,omitempty"` - PostURL string `json:"postURL,omitempty"` - Signature string `json:"signature,omitempty"` + Expires string `json:"expires"` + Id string `json:"id"` + Metadata string `json:"metadata"` + PostURL string `json:"postURL"` + Signature string `json:"signature"` +} + +type ListTemplatePermissionsParams struct { + p map[string]interface{} +} + +func (p *ListTemplatePermissionsParams) toURLValues() url.Values { + u := url.Values{} + if p.p == nil { + return u + } + if v, found := p.p["id"]; found { + u.Set("id", v.(string)) + } + return u +} + +func (p *ListTemplatePermissionsParams) SetId(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["id"] = v + return +} + +// You should always use this function to get a new ListTemplatePermissionsParams instance, +// as then you are sure you have configured all required params +func (s *TemplateService) NewListTemplatePermissionsParams(id string) *ListTemplatePermissionsParams { + p := &ListTemplatePermissionsParams{} + p.p = make(map[string]interface{}) + p.p["id"] = id + return p +} + +// This is a courtesy helper function, which in some cases may not work as expected! +func (s *TemplateService) GetTemplatePermissionByID(id string, opts ...OptionFunc) (*TemplatePermission, int, error) { + p := &ListTemplatePermissionsParams{} + p.p = make(map[string]interface{}) + + p.p["id"] = id + + for _, fn := range append(s.cs.options, opts...) { + if err := fn(s.cs, p); err != nil { + return nil, -1, err + } + } + + l, err := s.ListTemplatePermissions(p) + if err != nil { + if strings.Contains(err.Error(), fmt.Sprintf( + "Invalid parameter id value=%s due to incorrect long value format, "+ + "or entity does not exist", id)) { + return nil, 0, fmt.Errorf("No match found for %s: %+v", id, l) + } + return nil, -1, err + } + + if l.Count == 0 { + return nil, l.Count, fmt.Errorf("No match found for %s: %+v", id, l) + } + + if l.Count == 1 { + return l.TemplatePermissions[0], l.Count, nil + } + return nil, l.Count, fmt.Errorf("There is more then one result for TemplatePermission UUID: %s!", id) +} + +// List template visibility and all accounts that have permissions to view this template. +func (s *TemplateService) ListTemplatePermissions(p *ListTemplatePermissionsParams) (*ListTemplatePermissionsResponse, error) { + resp, err := s.cs.newRequest("listTemplatePermissions", p.toURLValues()) + if err != nil { + return nil, err + } + + var r ListTemplatePermissionsResponse + if err := json.Unmarshal(resp, &r); err != nil { + return nil, err + } + + return &r, nil +} + +type ListTemplatePermissionsResponse struct { + Count int `json:"count"` + TemplatePermissions []*TemplatePermission `json:"templatepermission"` +} + +type TemplatePermission struct { + Account []string `json:"account"` + Domainid string `json:"domainid"` + Id string `json:"id"` + Ispublic bool `json:"ispublic"` + Projectids []string `json:"projectids"` +} + +type ListTemplatesParams struct { + p map[string]interface{} +} + +func (p *ListTemplatesParams) toURLValues() url.Values { + u := url.Values{} + if p.p == nil { + return u + } + if v, found := p.p["account"]; found { + u.Set("account", v.(string)) + } + if v, found := p.p["domainid"]; found { + u.Set("domainid", v.(string)) + } + if v, found := p.p["hypervisor"]; found { + u.Set("hypervisor", v.(string)) + } + if v, found := p.p["id"]; found { + u.Set("id", v.(string)) + } + if v, found := p.p["ids"]; found { + vv := strings.Join(v.([]string), ",") + u.Set("ids", vv) + } + if v, found := p.p["isrecursive"]; found { + vv := strconv.FormatBool(v.(bool)) + u.Set("isrecursive", vv) + } + if v, found := p.p["keyword"]; found { + u.Set("keyword", v.(string)) + } + if v, found := p.p["listall"]; found { + vv := strconv.FormatBool(v.(bool)) + u.Set("listall", vv) + } + if v, found := p.p["name"]; found { + u.Set("name", v.(string)) + } + if v, found := p.p["page"]; found { + vv := strconv.Itoa(v.(int)) + u.Set("page", vv) + } + if v, found := p.p["pagesize"]; found { + vv := strconv.Itoa(v.(int)) + u.Set("pagesize", vv) + } + if v, found := p.p["parenttemplateid"]; found { + u.Set("parenttemplateid", v.(string)) + } + if v, found := p.p["projectid"]; found { + u.Set("projectid", v.(string)) + } + if v, found := p.p["showremoved"]; found { + vv := strconv.FormatBool(v.(bool)) + u.Set("showremoved", vv) + } + if v, found := p.p["tags"]; found { + i := 0 + for k, vv := range v.(map[string]string) { + u.Set(fmt.Sprintf("tags[%d].key", i), k) + u.Set(fmt.Sprintf("tags[%d].value", i), vv) + i++ + } + } + if v, found := p.p["templatefilter"]; found { + u.Set("templatefilter", v.(string)) + } + if v, found := p.p["zoneid"]; found { + u.Set("zoneid", v.(string)) + } + return u +} + +func (p *ListTemplatesParams) SetAccount(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["account"] = v + return +} + +func (p *ListTemplatesParams) SetDomainid(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["domainid"] = v + return +} + +func (p *ListTemplatesParams) SetHypervisor(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["hypervisor"] = v + return +} + +func (p *ListTemplatesParams) SetId(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["id"] = v + return +} + +func (p *ListTemplatesParams) SetIds(v []string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["ids"] = v + return +} + +func (p *ListTemplatesParams) SetIsrecursive(v bool) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["isrecursive"] = v + return +} + +func (p *ListTemplatesParams) SetKeyword(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["keyword"] = v + return +} + +func (p *ListTemplatesParams) SetListall(v bool) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["listall"] = v + return +} + +func (p *ListTemplatesParams) SetName(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["name"] = v + return +} + +func (p *ListTemplatesParams) SetPage(v int) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["page"] = v + return +} + +func (p *ListTemplatesParams) SetPagesize(v int) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["pagesize"] = v + return +} + +func (p *ListTemplatesParams) SetParenttemplateid(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["parenttemplateid"] = v + return +} + +func (p *ListTemplatesParams) SetProjectid(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["projectid"] = v + return +} + +func (p *ListTemplatesParams) SetShowremoved(v bool) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["showremoved"] = v + return +} + +func (p *ListTemplatesParams) SetTags(v map[string]string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["tags"] = v + return +} + +func (p *ListTemplatesParams) SetTemplatefilter(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["templatefilter"] = v + return +} + +func (p *ListTemplatesParams) SetZoneid(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["zoneid"] = v + return +} + +// You should always use this function to get a new ListTemplatesParams instance, +// as then you are sure you have configured all required params +func (s *TemplateService) NewListTemplatesParams(templatefilter string) *ListTemplatesParams { + p := &ListTemplatesParams{} + p.p = make(map[string]interface{}) + p.p["templatefilter"] = templatefilter + return p +} + +// This is a courtesy helper function, which in some cases may not work as expected! +func (s *TemplateService) GetTemplateID(name string, templatefilter string, zoneid string, opts ...OptionFunc) (string, int, error) { + p := &ListTemplatesParams{} + p.p = make(map[string]interface{}) + + p.p["name"] = name + p.p["templatefilter"] = templatefilter + p.p["zoneid"] = zoneid + + for _, fn := range append(s.cs.options, opts...) { + if err := fn(s.cs, p); err != nil { + return "", -1, err + } + } + + l, err := s.ListTemplates(p) + if err != nil { + return "", -1, err + } + + if l.Count == 0 { + return "", l.Count, fmt.Errorf("No match found for %s: %+v", name, l) + } + + if l.Count == 1 { + return l.Templates[0].Id, l.Count, nil + } + + if l.Count > 1 { + for _, v := range l.Templates { + if v.Name == name { + return v.Id, l.Count, nil + } + } + } + return "", l.Count, fmt.Errorf("Could not find an exact match for %s: %+v", name, l) +} + +// This is a courtesy helper function, which in some cases may not work as expected! +func (s *TemplateService) GetTemplateByName(name string, templatefilter string, zoneid string, opts ...OptionFunc) (*Template, int, error) { + id, count, err := s.GetTemplateID(name, templatefilter, zoneid, opts...) + if err != nil { + return nil, count, err + } + + r, count, err := s.GetTemplateByID(id, templatefilter, opts...) + if err != nil { + return nil, count, err + } + return r, count, nil +} + +// This is a courtesy helper function, which in some cases may not work as expected! +func (s *TemplateService) GetTemplateByID(id string, templatefilter string, opts ...OptionFunc) (*Template, int, error) { + p := &ListTemplatesParams{} + p.p = make(map[string]interface{}) + + p.p["id"] = id + p.p["templatefilter"] = templatefilter + + for _, fn := range append(s.cs.options, opts...) { + if err := fn(s.cs, p); err != nil { + return nil, -1, err + } + } + + l, err := s.ListTemplates(p) + if err != nil { + if strings.Contains(err.Error(), fmt.Sprintf( + "Invalid parameter id value=%s due to incorrect long value format, "+ + "or entity does not exist", id)) { + return nil, 0, fmt.Errorf("No match found for %s: %+v", id, l) + } + return nil, -1, err + } + + if l.Count == 0 { + return nil, l.Count, fmt.Errorf("No match found for %s: %+v", id, l) + } + + if l.Count == 1 { + return l.Templates[0], l.Count, nil + } + return nil, l.Count, fmt.Errorf("There is more then one result for Template UUID: %s!", id) +} + +// List all public, private, and privileged templates. +func (s *TemplateService) ListTemplates(p *ListTemplatesParams) (*ListTemplatesResponse, error) { + resp, err := s.cs.newRequest("listTemplates", p.toURLValues()) + if err != nil { + return nil, err + } + + var r ListTemplatesResponse + if err := json.Unmarshal(resp, &r); err != nil { + return nil, err + } + + return &r, nil +} + +type ListTemplatesResponse struct { + Count int `json:"count"` + Templates []*Template `json:"template"` +} + +type Template struct { + Account string `json:"account"` + Accountid string `json:"accountid"` + Bits int `json:"bits"` + Bootable bool `json:"bootable"` + Checksum string `json:"checksum"` + Childtemplates []interface{} `json:"childtemplates"` + Created string `json:"created"` + CrossZones bool `json:"crossZones"` + Details map[string]string `json:"details"` + Directdownload bool `json:"directdownload"` + Displaytext string `json:"displaytext"` + Domain string `json:"domain"` + Domainid string `json:"domainid"` + Format string `json:"format"` + Hostid string `json:"hostid"` + Hostname string `json:"hostname"` + Hypervisor string `json:"hypervisor"` + Id string `json:"id"` + Isdynamicallyscalable bool `json:"isdynamicallyscalable"` + Isextractable bool `json:"isextractable"` + Isfeatured bool `json:"isfeatured"` + Ispublic bool `json:"ispublic"` + Isready bool `json:"isready"` + Name string `json:"name"` + Ostypeid string `json:"ostypeid"` + Ostypename string `json:"ostypename"` + Parenttemplateid string `json:"parenttemplateid"` + Passwordenabled bool `json:"passwordenabled"` + Physicalsize int64 `json:"physicalsize"` + Project string `json:"project"` + Projectid string `json:"projectid"` + Removed string `json:"removed"` + Size int64 `json:"size"` + Sourcetemplateid string `json:"sourcetemplateid"` + Sshkeyenabled bool `json:"sshkeyenabled"` + Status string `json:"status"` + Templatetag string `json:"templatetag"` + Templatetype string `json:"templatetype"` + Zoneid string `json:"zoneid"` + Zonename string `json:"zonename"` +} + +type PrepareTemplateParams struct { + p map[string]interface{} +} + +func (p *PrepareTemplateParams) toURLValues() url.Values { + u := url.Values{} + if p.p == nil { + return u + } + if v, found := p.p["storageid"]; found { + u.Set("storageid", v.(string)) + } + if v, found := p.p["templateid"]; found { + u.Set("templateid", v.(string)) + } + if v, found := p.p["zoneid"]; found { + u.Set("zoneid", v.(string)) + } + return u +} + +func (p *PrepareTemplateParams) SetStorageid(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["storageid"] = v + return +} + +func (p *PrepareTemplateParams) SetTemplateid(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["templateid"] = v + return +} + +func (p *PrepareTemplateParams) SetZoneid(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["zoneid"] = v + return +} + +// You should always use this function to get a new PrepareTemplateParams instance, +// as then you are sure you have configured all required params +func (s *TemplateService) NewPrepareTemplateParams(templateid string, zoneid string) *PrepareTemplateParams { + p := &PrepareTemplateParams{} + p.p = make(map[string]interface{}) + p.p["templateid"] = templateid + p.p["zoneid"] = zoneid + return p +} + +// load template into primary storage +func (s *TemplateService) PrepareTemplate(p *PrepareTemplateParams) (*PrepareTemplateResponse, error) { + resp, err := s.cs.newRequest("prepareTemplate", p.toURLValues()) + if err != nil { + return nil, err + } + + var r PrepareTemplateResponse + if err := json.Unmarshal(resp, &r); err != nil { + return nil, err + } + + return &r, nil +} + +type PrepareTemplateResponse struct { + Account string `json:"account"` + Accountid string `json:"accountid"` + Bits int `json:"bits"` + Bootable bool `json:"bootable"` + Checksum string `json:"checksum"` + Childtemplates []interface{} `json:"childtemplates"` + Created string `json:"created"` + CrossZones bool `json:"crossZones"` + Details map[string]string `json:"details"` + Directdownload bool `json:"directdownload"` + Displaytext string `json:"displaytext"` + Domain string `json:"domain"` + Domainid string `json:"domainid"` + Format string `json:"format"` + Hostid string `json:"hostid"` + Hostname string `json:"hostname"` + Hypervisor string `json:"hypervisor"` + Id string `json:"id"` + Isdynamicallyscalable bool `json:"isdynamicallyscalable"` + Isextractable bool `json:"isextractable"` + Isfeatured bool `json:"isfeatured"` + Ispublic bool `json:"ispublic"` + Isready bool `json:"isready"` + Name string `json:"name"` + Ostypeid string `json:"ostypeid"` + Ostypename string `json:"ostypename"` + Parenttemplateid string `json:"parenttemplateid"` + Passwordenabled bool `json:"passwordenabled"` + Physicalsize int64 `json:"physicalsize"` + Project string `json:"project"` + Projectid string `json:"projectid"` + Removed string `json:"removed"` + Size int64 `json:"size"` + Sourcetemplateid string `json:"sourcetemplateid"` + Sshkeyenabled bool `json:"sshkeyenabled"` + Status string `json:"status"` + Templatetag string `json:"templatetag"` + Templatetype string `json:"templatetype"` + Zoneid string `json:"zoneid"` + Zonename string `json:"zonename"` +} + +type RegisterTemplateParams struct { + p map[string]interface{} +} + +func (p *RegisterTemplateParams) toURLValues() url.Values { + u := url.Values{} + if p.p == nil { + return u + } + if v, found := p.p["account"]; found { + u.Set("account", v.(string)) + } + if v, found := p.p["bits"]; found { + vv := strconv.Itoa(v.(int)) + u.Set("bits", vv) + } + if v, found := p.p["checksum"]; found { + u.Set("checksum", v.(string)) + } + if v, found := p.p["details"]; found { + i := 0 + for k, vv := range v.(map[string]string) { + u.Set(fmt.Sprintf("details[%d].%s", i, k), vv) + i++ + } + } + if v, found := p.p["directdownload"]; found { + vv := strconv.FormatBool(v.(bool)) + u.Set("directdownload", vv) + } + if v, found := p.p["displaytext"]; found { + u.Set("displaytext", v.(string)) + } + if v, found := p.p["domainid"]; found { + u.Set("domainid", v.(string)) + } + if v, found := p.p["format"]; found { + u.Set("format", v.(string)) + } + if v, found := p.p["hypervisor"]; found { + u.Set("hypervisor", v.(string)) + } + if v, found := p.p["isdynamicallyscalable"]; found { + vv := strconv.FormatBool(v.(bool)) + u.Set("isdynamicallyscalable", vv) + } + if v, found := p.p["isextractable"]; found { + vv := strconv.FormatBool(v.(bool)) + u.Set("isextractable", vv) + } + if v, found := p.p["isfeatured"]; found { + vv := strconv.FormatBool(v.(bool)) + u.Set("isfeatured", vv) + } + if v, found := p.p["ispublic"]; found { + vv := strconv.FormatBool(v.(bool)) + u.Set("ispublic", vv) + } + if v, found := p.p["isrouting"]; found { + vv := strconv.FormatBool(v.(bool)) + u.Set("isrouting", vv) + } + if v, found := p.p["name"]; found { + u.Set("name", v.(string)) + } + if v, found := p.p["ostypeid"]; found { + u.Set("ostypeid", v.(string)) + } + if v, found := p.p["passwordenabled"]; found { + vv := strconv.FormatBool(v.(bool)) + u.Set("passwordenabled", vv) + } + if v, found := p.p["projectid"]; found { + u.Set("projectid", v.(string)) + } + if v, found := p.p["requireshvm"]; found { + vv := strconv.FormatBool(v.(bool)) + u.Set("requireshvm", vv) + } + if v, found := p.p["sshkeyenabled"]; found { + vv := strconv.FormatBool(v.(bool)) + u.Set("sshkeyenabled", vv) + } + if v, found := p.p["templatetag"]; found { + u.Set("templatetag", v.(string)) + } + if v, found := p.p["url"]; found { + u.Set("url", v.(string)) + } + if v, found := p.p["zoneid"]; found { + u.Set("zoneid", v.(string)) + } + if v, found := p.p["zoneids"]; found { + vv := strings.Join(v.([]string), ",") + u.Set("zoneids", vv) + } + return u +} + +func (p *RegisterTemplateParams) SetAccount(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["account"] = v + return +} + +func (p *RegisterTemplateParams) SetBits(v int) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["bits"] = v + return +} + +func (p *RegisterTemplateParams) SetChecksum(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["checksum"] = v + return +} + +func (p *RegisterTemplateParams) SetDetails(v map[string]string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["details"] = v + return +} + +func (p *RegisterTemplateParams) SetDirectdownload(v bool) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["directdownload"] = v + return +} + +func (p *RegisterTemplateParams) SetDisplaytext(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["displaytext"] = v + return +} + +func (p *RegisterTemplateParams) SetDomainid(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["domainid"] = v + return +} + +func (p *RegisterTemplateParams) SetFormat(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["format"] = v + return +} + +func (p *RegisterTemplateParams) SetHypervisor(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["hypervisor"] = v + return +} + +func (p *RegisterTemplateParams) SetIsdynamicallyscalable(v bool) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["isdynamicallyscalable"] = v + return +} + +func (p *RegisterTemplateParams) SetIsextractable(v bool) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["isextractable"] = v + return +} + +func (p *RegisterTemplateParams) SetIsfeatured(v bool) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["isfeatured"] = v + return +} + +func (p *RegisterTemplateParams) SetIspublic(v bool) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["ispublic"] = v + return +} + +func (p *RegisterTemplateParams) SetIsrouting(v bool) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["isrouting"] = v + return +} + +func (p *RegisterTemplateParams) SetName(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["name"] = v + return +} + +func (p *RegisterTemplateParams) SetOstypeid(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["ostypeid"] = v + return +} + +func (p *RegisterTemplateParams) SetPasswordenabled(v bool) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["passwordenabled"] = v + return +} + +func (p *RegisterTemplateParams) SetProjectid(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["projectid"] = v + return +} + +func (p *RegisterTemplateParams) SetRequireshvm(v bool) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["requireshvm"] = v + return +} + +func (p *RegisterTemplateParams) SetSshkeyenabled(v bool) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["sshkeyenabled"] = v + return +} + +func (p *RegisterTemplateParams) SetTemplatetag(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["templatetag"] = v + return +} + +func (p *RegisterTemplateParams) SetUrl(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["url"] = v + return +} + +func (p *RegisterTemplateParams) SetZoneid(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["zoneid"] = v + return +} + +func (p *RegisterTemplateParams) SetZoneids(v []string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["zoneids"] = v + return +} + +// You should always use this function to get a new RegisterTemplateParams instance, +// as then you are sure you have configured all required params +func (s *TemplateService) NewRegisterTemplateParams(displaytext string, format string, hypervisor string, name string, ostypeid string, url string) *RegisterTemplateParams { + p := &RegisterTemplateParams{} + p.p = make(map[string]interface{}) + p.p["displaytext"] = displaytext + p.p["format"] = format + p.p["hypervisor"] = hypervisor + p.p["name"] = name + p.p["ostypeid"] = ostypeid + p.p["url"] = url + return p +} + +// Registers an existing template into the CloudStack cloud. +func (s *TemplateService) RegisterTemplate(p *RegisterTemplateParams) (*RegisterTemplateResponse, error) { + resp, err := s.cs.newRequest("registerTemplate", p.toURLValues()) + if err != nil { + return nil, err + } + + var r RegisterTemplateResponse + if err := json.Unmarshal(resp, &r); err != nil { + return nil, err + } + + return &r, nil +} + +type RegisterTemplateResponse struct { + Count int `json:"count"` + RegisterTemplate []*RegisterTemplate `json:"template"` +} + +type RegisterTemplate struct { + Account string `json:"account"` + Accountid string `json:"accountid"` + Bits int `json:"bits"` + Bootable bool `json:"bootable"` + Checksum string `json:"checksum"` + Childtemplates []interface{} `json:"childtemplates"` + Created string `json:"created"` + CrossZones bool `json:"crossZones"` + Details map[string]string `json:"details"` + Directdownload bool `json:"directdownload"` + Displaytext string `json:"displaytext"` + Domain string `json:"domain"` + Domainid string `json:"domainid"` + Format string `json:"format"` + Hostid string `json:"hostid"` + Hostname string `json:"hostname"` + Hypervisor string `json:"hypervisor"` + Id string `json:"id"` + Isdynamicallyscalable bool `json:"isdynamicallyscalable"` + Isextractable bool `json:"isextractable"` + Isfeatured bool `json:"isfeatured"` + Ispublic bool `json:"ispublic"` + Isready bool `json:"isready"` + Name string `json:"name"` + Ostypeid string `json:"ostypeid"` + Ostypename string `json:"ostypename"` + Parenttemplateid string `json:"parenttemplateid"` + Passwordenabled bool `json:"passwordenabled"` + Physicalsize int64 `json:"physicalsize"` + Project string `json:"project"` + Projectid string `json:"projectid"` + Removed string `json:"removed"` + Size int64 `json:"size"` + Sourcetemplateid string `json:"sourcetemplateid"` + Sshkeyenabled bool `json:"sshkeyenabled"` + Status string `json:"status"` + Templatetag string `json:"templatetag"` + Templatetype string `json:"templatetype"` + Zoneid string `json:"zoneid"` + Zonename string `json:"zonename"` +} + +type UpdateTemplateParams struct { + p map[string]interface{} +} + +func (p *UpdateTemplateParams) toURLValues() url.Values { + u := url.Values{} + if p.p == nil { + return u + } + if v, found := p.p["bootable"]; found { + vv := strconv.FormatBool(v.(bool)) + u.Set("bootable", vv) + } + if v, found := p.p["cleanupdetails"]; found { + vv := strconv.FormatBool(v.(bool)) + u.Set("cleanupdetails", vv) + } + if v, found := p.p["details"]; found { + i := 0 + for k, vv := range v.(map[string]string) { + u.Set(fmt.Sprintf("details[%d].%s", i, k), vv) + i++ + } + } + if v, found := p.p["displaytext"]; found { + u.Set("displaytext", v.(string)) + } + if v, found := p.p["format"]; found { + u.Set("format", v.(string)) + } + if v, found := p.p["id"]; found { + u.Set("id", v.(string)) + } + if v, found := p.p["isdynamicallyscalable"]; found { + vv := strconv.FormatBool(v.(bool)) + u.Set("isdynamicallyscalable", vv) + } + if v, found := p.p["isrouting"]; found { + vv := strconv.FormatBool(v.(bool)) + u.Set("isrouting", vv) + } + if v, found := p.p["name"]; found { + u.Set("name", v.(string)) + } + if v, found := p.p["ostypeid"]; found { + u.Set("ostypeid", v.(string)) + } + if v, found := p.p["passwordenabled"]; found { + vv := strconv.FormatBool(v.(bool)) + u.Set("passwordenabled", vv) + } + if v, found := p.p["requireshvm"]; found { + vv := strconv.FormatBool(v.(bool)) + u.Set("requireshvm", vv) + } + if v, found := p.p["sortkey"]; found { + vv := strconv.Itoa(v.(int)) + u.Set("sortkey", vv) + } + return u +} + +func (p *UpdateTemplateParams) SetBootable(v bool) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["bootable"] = v + return +} + +func (p *UpdateTemplateParams) SetCleanupdetails(v bool) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["cleanupdetails"] = v + return +} + +func (p *UpdateTemplateParams) SetDetails(v map[string]string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["details"] = v + return +} + +func (p *UpdateTemplateParams) SetDisplaytext(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["displaytext"] = v + return +} + +func (p *UpdateTemplateParams) SetFormat(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["format"] = v + return +} + +func (p *UpdateTemplateParams) SetId(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["id"] = v + return +} + +func (p *UpdateTemplateParams) SetIsdynamicallyscalable(v bool) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["isdynamicallyscalable"] = v + return +} + +func (p *UpdateTemplateParams) SetIsrouting(v bool) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["isrouting"] = v + return +} + +func (p *UpdateTemplateParams) SetName(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["name"] = v + return +} + +func (p *UpdateTemplateParams) SetOstypeid(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["ostypeid"] = v + return +} + +func (p *UpdateTemplateParams) SetPasswordenabled(v bool) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["passwordenabled"] = v + return +} + +func (p *UpdateTemplateParams) SetRequireshvm(v bool) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["requireshvm"] = v + return +} + +func (p *UpdateTemplateParams) SetSortkey(v int) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["sortkey"] = v + return +} + +// You should always use this function to get a new UpdateTemplateParams instance, +// as then you are sure you have configured all required params +func (s *TemplateService) NewUpdateTemplateParams(id string) *UpdateTemplateParams { + p := &UpdateTemplateParams{} + p.p = make(map[string]interface{}) + p.p["id"] = id + return p +} + +// Updates attributes of a template. +func (s *TemplateService) UpdateTemplate(p *UpdateTemplateParams) (*UpdateTemplateResponse, error) { + resp, err := s.cs.newRequest("updateTemplate", p.toURLValues()) + if err != nil { + return nil, err + } + + var r UpdateTemplateResponse + if err := json.Unmarshal(resp, &r); err != nil { + return nil, err + } + + return &r, nil +} + +type UpdateTemplateResponse struct { + Account string `json:"account"` + Accountid string `json:"accountid"` + Bits int `json:"bits"` + Bootable bool `json:"bootable"` + Checksum string `json:"checksum"` + Childtemplates []interface{} `json:"childtemplates"` + Created string `json:"created"` + CrossZones bool `json:"crossZones"` + Details map[string]string `json:"details"` + Directdownload bool `json:"directdownload"` + Displaytext string `json:"displaytext"` + Domain string `json:"domain"` + Domainid string `json:"domainid"` + Format string `json:"format"` + Hostid string `json:"hostid"` + Hostname string `json:"hostname"` + Hypervisor string `json:"hypervisor"` + Id string `json:"id"` + Isdynamicallyscalable bool `json:"isdynamicallyscalable"` + Isextractable bool `json:"isextractable"` + Isfeatured bool `json:"isfeatured"` + Ispublic bool `json:"ispublic"` + Isready bool `json:"isready"` + Name string `json:"name"` + Ostypeid string `json:"ostypeid"` + Ostypename string `json:"ostypename"` + Parenttemplateid string `json:"parenttemplateid"` + Passwordenabled bool `json:"passwordenabled"` + Physicalsize int64 `json:"physicalsize"` + Project string `json:"project"` + Projectid string `json:"projectid"` + Removed string `json:"removed"` + Size int64 `json:"size"` + Sourcetemplateid string `json:"sourcetemplateid"` + Sshkeyenabled bool `json:"sshkeyenabled"` + Status string `json:"status"` + Templatetag string `json:"templatetag"` + Templatetype string `json:"templatetype"` + Zoneid string `json:"zoneid"` + Zonename string `json:"zonename"` +} + +type UpdateTemplatePermissionsParams struct { + p map[string]interface{} +} + +func (p *UpdateTemplatePermissionsParams) toURLValues() url.Values { + u := url.Values{} + if p.p == nil { + return u + } + if v, found := p.p["accounts"]; found { + vv := strings.Join(v.([]string), ",") + u.Set("accounts", vv) + } + if v, found := p.p["id"]; found { + u.Set("id", v.(string)) + } + if v, found := p.p["isextractable"]; found { + vv := strconv.FormatBool(v.(bool)) + u.Set("isextractable", vv) + } + if v, found := p.p["isfeatured"]; found { + vv := strconv.FormatBool(v.(bool)) + u.Set("isfeatured", vv) + } + if v, found := p.p["ispublic"]; found { + vv := strconv.FormatBool(v.(bool)) + u.Set("ispublic", vv) + } + if v, found := p.p["op"]; found { + u.Set("op", v.(string)) + } + if v, found := p.p["projectids"]; found { + vv := strings.Join(v.([]string), ",") + u.Set("projectids", vv) + } + return u +} + +func (p *UpdateTemplatePermissionsParams) SetAccounts(v []string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["accounts"] = v + return +} + +func (p *UpdateTemplatePermissionsParams) SetId(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["id"] = v + return +} + +func (p *UpdateTemplatePermissionsParams) SetIsextractable(v bool) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["isextractable"] = v + return +} + +func (p *UpdateTemplatePermissionsParams) SetIsfeatured(v bool) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["isfeatured"] = v + return +} + +func (p *UpdateTemplatePermissionsParams) SetIspublic(v bool) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["ispublic"] = v + return +} + +func (p *UpdateTemplatePermissionsParams) SetOp(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["op"] = v + return +} + +func (p *UpdateTemplatePermissionsParams) SetProjectids(v []string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["projectids"] = v + return +} + +// You should always use this function to get a new UpdateTemplatePermissionsParams instance, +// as then you are sure you have configured all required params +func (s *TemplateService) NewUpdateTemplatePermissionsParams(id string) *UpdateTemplatePermissionsParams { + p := &UpdateTemplatePermissionsParams{} + p.p = make(map[string]interface{}) + p.p["id"] = id + return p +} + +// Updates a template visibility permissions. A public template is visible to all accounts within the same domain. A private template is visible only to the owner of the template. A priviledged template is a private template with account permissions added. Only accounts specified under the template permissions are visible to them. +func (s *TemplateService) UpdateTemplatePermissions(p *UpdateTemplatePermissionsParams) (*UpdateTemplatePermissionsResponse, error) { + resp, err := s.cs.newRequest("updateTemplatePermissions", p.toURLValues()) + if err != nil { + return nil, err + } + + var r UpdateTemplatePermissionsResponse + if err := json.Unmarshal(resp, &r); err != nil { + return nil, err + } + + return &r, nil +} + +type UpdateTemplatePermissionsResponse struct { + Displaytext string `json:"displaytext"` + Success bool `json:"success"` +} + +func (r *UpdateTemplatePermissionsResponse) UnmarshalJSON(b []byte) error { + var m map[string]interface{} + err := json.Unmarshal(b, &m) + if err != nil { + return err + } + + if success, ok := m["success"].(string); ok { + m["success"] = success == "true" + b, err = json.Marshal(m) + if err != nil { + return err + } + } + + type alias UpdateTemplatePermissionsResponse + return json.Unmarshal(b, (*alias)(r)) +} + +type UpgradeRouterTemplateParams struct { + p map[string]interface{} +} + +func (p *UpgradeRouterTemplateParams) toURLValues() url.Values { + u := url.Values{} + if p.p == nil { + return u + } + if v, found := p.p["account"]; found { + u.Set("account", v.(string)) + } + if v, found := p.p["clusterid"]; found { + u.Set("clusterid", v.(string)) + } + if v, found := p.p["domainid"]; found { + u.Set("domainid", v.(string)) + } + if v, found := p.p["id"]; found { + u.Set("id", v.(string)) + } + if v, found := p.p["podid"]; found { + u.Set("podid", v.(string)) + } + if v, found := p.p["zoneid"]; found { + u.Set("zoneid", v.(string)) + } + return u +} + +func (p *UpgradeRouterTemplateParams) SetAccount(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["account"] = v + return +} + +func (p *UpgradeRouterTemplateParams) SetClusterid(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["clusterid"] = v + return +} + +func (p *UpgradeRouterTemplateParams) SetDomainid(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["domainid"] = v + return +} + +func (p *UpgradeRouterTemplateParams) SetId(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["id"] = v + return +} + +func (p *UpgradeRouterTemplateParams) SetPodid(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["podid"] = v + return +} + +func (p *UpgradeRouterTemplateParams) SetZoneid(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["zoneid"] = v + return +} + +// You should always use this function to get a new UpgradeRouterTemplateParams instance, +// as then you are sure you have configured all required params +func (s *TemplateService) NewUpgradeRouterTemplateParams() *UpgradeRouterTemplateParams { + p := &UpgradeRouterTemplateParams{} + p.p = make(map[string]interface{}) + return p +} + +// Upgrades router to use newer template +func (s *TemplateService) UpgradeRouterTemplate(p *UpgradeRouterTemplateParams) (*UpgradeRouterTemplateResponse, error) { + resp, err := s.cs.newRequest("upgradeRouterTemplate", p.toURLValues()) + if err != nil { + return nil, err + } + + var r UpgradeRouterTemplateResponse + if err := json.Unmarshal(resp, &r); err != nil { + return nil, err + } + + return &r, nil +} + +type UpgradeRouterTemplateResponse struct { + JobID string `json:"jobid"` + Jobstatus int `json:"jobstatus"` } diff --git a/vendor/github.com/xanzy/go-cloudstack/cloudstack/UCSService.go b/vendor/github.com/xanzy/go-cloudstack/cloudstack/UCSService.go index 3d5fbd33a..c3e1ed449 100644 --- a/vendor/github.com/xanzy/go-cloudstack/cloudstack/UCSService.go +++ b/vendor/github.com/xanzy/go-cloudstack/cloudstack/UCSService.go @@ -1,5 +1,5 @@ // -// Copyright 2016, Sander van Harmelen +// Copyright 2018, Sander van Harmelen // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -114,384 +114,15 @@ func (s *UCSService) AddUcsManager(p *AddUcsManagerParams) (*AddUcsManagerRespon if err := json.Unmarshal(resp, &r); err != nil { return nil, err } + return &r, nil } type AddUcsManagerResponse struct { - Id string `json:"id,omitempty"` - Name string `json:"name,omitempty"` - Url string `json:"url,omitempty"` - Zoneid string `json:"zoneid,omitempty"` -} - -type ListUcsManagersParams struct { - p map[string]interface{} -} - -func (p *ListUcsManagersParams) toURLValues() url.Values { - u := url.Values{} - if p.p == nil { - return u - } - if v, found := p.p["id"]; found { - u.Set("id", v.(string)) - } - if v, found := p.p["keyword"]; found { - u.Set("keyword", v.(string)) - } - if v, found := p.p["page"]; found { - vv := strconv.Itoa(v.(int)) - u.Set("page", vv) - } - if v, found := p.p["pagesize"]; found { - vv := strconv.Itoa(v.(int)) - u.Set("pagesize", vv) - } - if v, found := p.p["zoneid"]; found { - u.Set("zoneid", v.(string)) - } - return u -} - -func (p *ListUcsManagersParams) SetId(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["id"] = v - return -} - -func (p *ListUcsManagersParams) SetKeyword(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["keyword"] = v - return -} - -func (p *ListUcsManagersParams) SetPage(v int) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["page"] = v - return -} - -func (p *ListUcsManagersParams) SetPagesize(v int) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["pagesize"] = v - return -} - -func (p *ListUcsManagersParams) SetZoneid(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["zoneid"] = v - return -} - -// You should always use this function to get a new ListUcsManagersParams instance, -// as then you are sure you have configured all required params -func (s *UCSService) NewListUcsManagersParams() *ListUcsManagersParams { - p := &ListUcsManagersParams{} - p.p = make(map[string]interface{}) - return p -} - -// This is a courtesy helper function, which in some cases may not work as expected! -func (s *UCSService) GetUcsManagerID(keyword string, opts ...OptionFunc) (string, int, error) { - p := &ListUcsManagersParams{} - p.p = make(map[string]interface{}) - - p.p["keyword"] = keyword - - for _, fn := range opts { - if err := fn(s.cs, p); err != nil { - return "", -1, err - } - } - - l, err := s.ListUcsManagers(p) - if err != nil { - return "", -1, err - } - - if l.Count == 0 { - return "", l.Count, fmt.Errorf("No match found for %s: %+v", keyword, l) - } - - if l.Count == 1 { - return l.UcsManagers[0].Id, l.Count, nil - } - - if l.Count > 1 { - for _, v := range l.UcsManagers { - if v.Name == keyword { - return v.Id, l.Count, nil - } - } - } - return "", l.Count, fmt.Errorf("Could not find an exact match for %s: %+v", keyword, l) -} - -// This is a courtesy helper function, which in some cases may not work as expected! -func (s *UCSService) GetUcsManagerByName(name string, opts ...OptionFunc) (*UcsManager, int, error) { - id, count, err := s.GetUcsManagerID(name, opts...) - if err != nil { - return nil, count, err - } - - r, count, err := s.GetUcsManagerByID(id, opts...) - if err != nil { - return nil, count, err - } - return r, count, nil -} - -// This is a courtesy helper function, which in some cases may not work as expected! -func (s *UCSService) GetUcsManagerByID(id string, opts ...OptionFunc) (*UcsManager, int, error) { - p := &ListUcsManagersParams{} - p.p = make(map[string]interface{}) - - p.p["id"] = id - - for _, fn := range opts { - if err := fn(s.cs, p); err != nil { - return nil, -1, err - } - } - - l, err := s.ListUcsManagers(p) - if err != nil { - if strings.Contains(err.Error(), fmt.Sprintf( - "Invalid parameter id value=%s due to incorrect long value format, "+ - "or entity does not exist", id)) { - return nil, 0, fmt.Errorf("No match found for %s: %+v", id, l) - } - return nil, -1, err - } - - if l.Count == 0 { - return nil, l.Count, fmt.Errorf("No match found for %s: %+v", id, l) - } - - if l.Count == 1 { - return l.UcsManagers[0], l.Count, nil - } - return nil, l.Count, fmt.Errorf("There is more then one result for UcsManager UUID: %s!", id) -} - -// List ucs manager -func (s *UCSService) ListUcsManagers(p *ListUcsManagersParams) (*ListUcsManagersResponse, error) { - resp, err := s.cs.newRequest("listUcsManagers", p.toURLValues()) - if err != nil { - return nil, err - } - - var r ListUcsManagersResponse - if err := json.Unmarshal(resp, &r); err != nil { - return nil, err - } - return &r, nil -} - -type ListUcsManagersResponse struct { - Count int `json:"count"` - UcsManagers []*UcsManager `json:"ucsmanager"` -} - -type UcsManager struct { - Id string `json:"id,omitempty"` - Name string `json:"name,omitempty"` - Url string `json:"url,omitempty"` - Zoneid string `json:"zoneid,omitempty"` -} - -type ListUcsProfilesParams struct { - p map[string]interface{} -} - -func (p *ListUcsProfilesParams) toURLValues() url.Values { - u := url.Values{} - if p.p == nil { - return u - } - if v, found := p.p["keyword"]; found { - u.Set("keyword", v.(string)) - } - if v, found := p.p["page"]; found { - vv := strconv.Itoa(v.(int)) - u.Set("page", vv) - } - if v, found := p.p["pagesize"]; found { - vv := strconv.Itoa(v.(int)) - u.Set("pagesize", vv) - } - if v, found := p.p["ucsmanagerid"]; found { - u.Set("ucsmanagerid", v.(string)) - } - return u -} - -func (p *ListUcsProfilesParams) SetKeyword(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["keyword"] = v - return -} - -func (p *ListUcsProfilesParams) SetPage(v int) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["page"] = v - return -} - -func (p *ListUcsProfilesParams) SetPagesize(v int) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["pagesize"] = v - return -} - -func (p *ListUcsProfilesParams) SetUcsmanagerid(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["ucsmanagerid"] = v - return -} - -// You should always use this function to get a new ListUcsProfilesParams instance, -// as then you are sure you have configured all required params -func (s *UCSService) NewListUcsProfilesParams(ucsmanagerid string) *ListUcsProfilesParams { - p := &ListUcsProfilesParams{} - p.p = make(map[string]interface{}) - p.p["ucsmanagerid"] = ucsmanagerid - return p -} - -// List profile in ucs manager -func (s *UCSService) ListUcsProfiles(p *ListUcsProfilesParams) (*ListUcsProfilesResponse, error) { - resp, err := s.cs.newRequest("listUcsProfiles", p.toURLValues()) - if err != nil { - return nil, err - } - - var r ListUcsProfilesResponse - if err := json.Unmarshal(resp, &r); err != nil { - return nil, err - } - return &r, nil -} - -type ListUcsProfilesResponse struct { - Count int `json:"count"` - UcsProfiles []*UcsProfile `json:"ucsprofile"` -} - -type UcsProfile struct { - Ucsdn string `json:"ucsdn,omitempty"` -} - -type ListUcsBladesParams struct { - p map[string]interface{} -} - -func (p *ListUcsBladesParams) toURLValues() url.Values { - u := url.Values{} - if p.p == nil { - return u - } - if v, found := p.p["keyword"]; found { - u.Set("keyword", v.(string)) - } - if v, found := p.p["page"]; found { - vv := strconv.Itoa(v.(int)) - u.Set("page", vv) - } - if v, found := p.p["pagesize"]; found { - vv := strconv.Itoa(v.(int)) - u.Set("pagesize", vv) - } - if v, found := p.p["ucsmanagerid"]; found { - u.Set("ucsmanagerid", v.(string)) - } - return u -} - -func (p *ListUcsBladesParams) SetKeyword(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["keyword"] = v - return -} - -func (p *ListUcsBladesParams) SetPage(v int) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["page"] = v - return -} - -func (p *ListUcsBladesParams) SetPagesize(v int) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["pagesize"] = v - return -} - -func (p *ListUcsBladesParams) SetUcsmanagerid(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["ucsmanagerid"] = v - return -} - -// You should always use this function to get a new ListUcsBladesParams instance, -// as then you are sure you have configured all required params -func (s *UCSService) NewListUcsBladesParams(ucsmanagerid string) *ListUcsBladesParams { - p := &ListUcsBladesParams{} - p.p = make(map[string]interface{}) - p.p["ucsmanagerid"] = ucsmanagerid - return p -} - -// List ucs blades -func (s *UCSService) ListUcsBlades(p *ListUcsBladesParams) (*ListUcsBladesResponse, error) { - resp, err := s.cs.newRequest("listUcsBlades", p.toURLValues()) - if err != nil { - return nil, err - } - - var r ListUcsBladesResponse - if err := json.Unmarshal(resp, &r); err != nil { - return nil, err - } - return &r, nil -} - -type ListUcsBladesResponse struct { - Count int `json:"count"` - UcsBlades []*UcsBlade `json:"ucsblade"` -} - -type UcsBlade struct { - Bladedn string `json:"bladedn,omitempty"` - Hostid string `json:"hostid,omitempty"` - Id string `json:"id,omitempty"` - Profiledn string `json:"profiledn,omitempty"` - Ucsmanagerid string `json:"ucsmanagerid,omitempty"` + Id string `json:"id"` + Name string `json:"name"` + Url string `json:"url"` + Zoneid string `json:"zoneid"` } type AssociateUcsProfileToBladeParams struct { @@ -581,14 +212,459 @@ func (s *UCSService) AssociateUcsProfileToBlade(p *AssociateUcsProfileToBladePar return nil, err } } + return &r, nil } type AssociateUcsProfileToBladeResponse struct { - JobID string `json:"jobid,omitempty"` - Bladedn string `json:"bladedn,omitempty"` - Hostid string `json:"hostid,omitempty"` - Id string `json:"id,omitempty"` - Profiledn string `json:"profiledn,omitempty"` - Ucsmanagerid string `json:"ucsmanagerid,omitempty"` + JobID string `json:"jobid"` + Bladedn string `json:"bladedn"` + Hostid string `json:"hostid"` + Id string `json:"id"` + Profiledn string `json:"profiledn"` + Ucsmanagerid string `json:"ucsmanagerid"` +} + +type DeleteUcsManagerParams struct { + p map[string]interface{} +} + +func (p *DeleteUcsManagerParams) toURLValues() url.Values { + u := url.Values{} + if p.p == nil { + return u + } + if v, found := p.p["ucsmanagerid"]; found { + u.Set("ucsmanagerid", v.(string)) + } + return u +} + +func (p *DeleteUcsManagerParams) SetUcsmanagerid(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["ucsmanagerid"] = v + return +} + +// You should always use this function to get a new DeleteUcsManagerParams instance, +// as then you are sure you have configured all required params +func (s *UCSService) NewDeleteUcsManagerParams(ucsmanagerid string) *DeleteUcsManagerParams { + p := &DeleteUcsManagerParams{} + p.p = make(map[string]interface{}) + p.p["ucsmanagerid"] = ucsmanagerid + return p +} + +// Delete a Ucs manager +func (s *UCSService) DeleteUcsManager(p *DeleteUcsManagerParams) (*DeleteUcsManagerResponse, error) { + resp, err := s.cs.newRequest("deleteUcsManager", p.toURLValues()) + if err != nil { + return nil, err + } + + var r DeleteUcsManagerResponse + if err := json.Unmarshal(resp, &r); err != nil { + return nil, err + } + + return &r, nil +} + +type DeleteUcsManagerResponse struct { + Displaytext string `json:"displaytext"` + Success bool `json:"success"` +} + +func (r *DeleteUcsManagerResponse) UnmarshalJSON(b []byte) error { + var m map[string]interface{} + err := json.Unmarshal(b, &m) + if err != nil { + return err + } + + if success, ok := m["success"].(string); ok { + m["success"] = success == "true" + b, err = json.Marshal(m) + if err != nil { + return err + } + } + + type alias DeleteUcsManagerResponse + return json.Unmarshal(b, (*alias)(r)) +} + +type ListUcsBladesParams struct { + p map[string]interface{} +} + +func (p *ListUcsBladesParams) toURLValues() url.Values { + u := url.Values{} + if p.p == nil { + return u + } + if v, found := p.p["keyword"]; found { + u.Set("keyword", v.(string)) + } + if v, found := p.p["page"]; found { + vv := strconv.Itoa(v.(int)) + u.Set("page", vv) + } + if v, found := p.p["pagesize"]; found { + vv := strconv.Itoa(v.(int)) + u.Set("pagesize", vv) + } + if v, found := p.p["ucsmanagerid"]; found { + u.Set("ucsmanagerid", v.(string)) + } + return u +} + +func (p *ListUcsBladesParams) SetKeyword(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["keyword"] = v + return +} + +func (p *ListUcsBladesParams) SetPage(v int) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["page"] = v + return +} + +func (p *ListUcsBladesParams) SetPagesize(v int) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["pagesize"] = v + return +} + +func (p *ListUcsBladesParams) SetUcsmanagerid(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["ucsmanagerid"] = v + return +} + +// You should always use this function to get a new ListUcsBladesParams instance, +// as then you are sure you have configured all required params +func (s *UCSService) NewListUcsBladesParams(ucsmanagerid string) *ListUcsBladesParams { + p := &ListUcsBladesParams{} + p.p = make(map[string]interface{}) + p.p["ucsmanagerid"] = ucsmanagerid + return p +} + +// List ucs blades +func (s *UCSService) ListUcsBlades(p *ListUcsBladesParams) (*ListUcsBladesResponse, error) { + resp, err := s.cs.newRequest("listUcsBlades", p.toURLValues()) + if err != nil { + return nil, err + } + + var r ListUcsBladesResponse + if err := json.Unmarshal(resp, &r); err != nil { + return nil, err + } + + return &r, nil +} + +type ListUcsBladesResponse struct { + Count int `json:"count"` + UcsBlades []*UcsBlade `json:"ucsblade"` +} + +type UcsBlade struct { + Bladedn string `json:"bladedn"` + Hostid string `json:"hostid"` + Id string `json:"id"` + Profiledn string `json:"profiledn"` + Ucsmanagerid string `json:"ucsmanagerid"` +} + +type ListUcsManagersParams struct { + p map[string]interface{} +} + +func (p *ListUcsManagersParams) toURLValues() url.Values { + u := url.Values{} + if p.p == nil { + return u + } + if v, found := p.p["id"]; found { + u.Set("id", v.(string)) + } + if v, found := p.p["keyword"]; found { + u.Set("keyword", v.(string)) + } + if v, found := p.p["page"]; found { + vv := strconv.Itoa(v.(int)) + u.Set("page", vv) + } + if v, found := p.p["pagesize"]; found { + vv := strconv.Itoa(v.(int)) + u.Set("pagesize", vv) + } + if v, found := p.p["zoneid"]; found { + u.Set("zoneid", v.(string)) + } + return u +} + +func (p *ListUcsManagersParams) SetId(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["id"] = v + return +} + +func (p *ListUcsManagersParams) SetKeyword(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["keyword"] = v + return +} + +func (p *ListUcsManagersParams) SetPage(v int) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["page"] = v + return +} + +func (p *ListUcsManagersParams) SetPagesize(v int) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["pagesize"] = v + return +} + +func (p *ListUcsManagersParams) SetZoneid(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["zoneid"] = v + return +} + +// You should always use this function to get a new ListUcsManagersParams instance, +// as then you are sure you have configured all required params +func (s *UCSService) NewListUcsManagersParams() *ListUcsManagersParams { + p := &ListUcsManagersParams{} + p.p = make(map[string]interface{}) + return p +} + +// This is a courtesy helper function, which in some cases may not work as expected! +func (s *UCSService) GetUcsManagerID(keyword string, opts ...OptionFunc) (string, int, error) { + p := &ListUcsManagersParams{} + p.p = make(map[string]interface{}) + + p.p["keyword"] = keyword + + for _, fn := range append(s.cs.options, opts...) { + if err := fn(s.cs, p); err != nil { + return "", -1, err + } + } + + l, err := s.ListUcsManagers(p) + if err != nil { + return "", -1, err + } + + if l.Count == 0 { + return "", l.Count, fmt.Errorf("No match found for %s: %+v", keyword, l) + } + + if l.Count == 1 { + return l.UcsManagers[0].Id, l.Count, nil + } + + if l.Count > 1 { + for _, v := range l.UcsManagers { + if v.Name == keyword { + return v.Id, l.Count, nil + } + } + } + return "", l.Count, fmt.Errorf("Could not find an exact match for %s: %+v", keyword, l) +} + +// This is a courtesy helper function, which in some cases may not work as expected! +func (s *UCSService) GetUcsManagerByName(name string, opts ...OptionFunc) (*UcsManager, int, error) { + id, count, err := s.GetUcsManagerID(name, opts...) + if err != nil { + return nil, count, err + } + + r, count, err := s.GetUcsManagerByID(id, opts...) + if err != nil { + return nil, count, err + } + return r, count, nil +} + +// This is a courtesy helper function, which in some cases may not work as expected! +func (s *UCSService) GetUcsManagerByID(id string, opts ...OptionFunc) (*UcsManager, int, error) { + p := &ListUcsManagersParams{} + p.p = make(map[string]interface{}) + + p.p["id"] = id + + for _, fn := range append(s.cs.options, opts...) { + if err := fn(s.cs, p); err != nil { + return nil, -1, err + } + } + + l, err := s.ListUcsManagers(p) + if err != nil { + if strings.Contains(err.Error(), fmt.Sprintf( + "Invalid parameter id value=%s due to incorrect long value format, "+ + "or entity does not exist", id)) { + return nil, 0, fmt.Errorf("No match found for %s: %+v", id, l) + } + return nil, -1, err + } + + if l.Count == 0 { + return nil, l.Count, fmt.Errorf("No match found for %s: %+v", id, l) + } + + if l.Count == 1 { + return l.UcsManagers[0], l.Count, nil + } + return nil, l.Count, fmt.Errorf("There is more then one result for UcsManager UUID: %s!", id) +} + +// List ucs manager +func (s *UCSService) ListUcsManagers(p *ListUcsManagersParams) (*ListUcsManagersResponse, error) { + resp, err := s.cs.newRequest("listUcsManagers", p.toURLValues()) + if err != nil { + return nil, err + } + + var r ListUcsManagersResponse + if err := json.Unmarshal(resp, &r); err != nil { + return nil, err + } + + return &r, nil +} + +type ListUcsManagersResponse struct { + Count int `json:"count"` + UcsManagers []*UcsManager `json:"ucsmanager"` +} + +type UcsManager struct { + Id string `json:"id"` + Name string `json:"name"` + Url string `json:"url"` + Zoneid string `json:"zoneid"` +} + +type ListUcsProfilesParams struct { + p map[string]interface{} +} + +func (p *ListUcsProfilesParams) toURLValues() url.Values { + u := url.Values{} + if p.p == nil { + return u + } + if v, found := p.p["keyword"]; found { + u.Set("keyword", v.(string)) + } + if v, found := p.p["page"]; found { + vv := strconv.Itoa(v.(int)) + u.Set("page", vv) + } + if v, found := p.p["pagesize"]; found { + vv := strconv.Itoa(v.(int)) + u.Set("pagesize", vv) + } + if v, found := p.p["ucsmanagerid"]; found { + u.Set("ucsmanagerid", v.(string)) + } + return u +} + +func (p *ListUcsProfilesParams) SetKeyword(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["keyword"] = v + return +} + +func (p *ListUcsProfilesParams) SetPage(v int) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["page"] = v + return +} + +func (p *ListUcsProfilesParams) SetPagesize(v int) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["pagesize"] = v + return +} + +func (p *ListUcsProfilesParams) SetUcsmanagerid(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["ucsmanagerid"] = v + return +} + +// You should always use this function to get a new ListUcsProfilesParams instance, +// as then you are sure you have configured all required params +func (s *UCSService) NewListUcsProfilesParams(ucsmanagerid string) *ListUcsProfilesParams { + p := &ListUcsProfilesParams{} + p.p = make(map[string]interface{}) + p.p["ucsmanagerid"] = ucsmanagerid + return p +} + +// List profile in ucs manager +func (s *UCSService) ListUcsProfiles(p *ListUcsProfilesParams) (*ListUcsProfilesResponse, error) { + resp, err := s.cs.newRequest("listUcsProfiles", p.toURLValues()) + if err != nil { + return nil, err + } + + var r ListUcsProfilesResponse + if err := json.Unmarshal(resp, &r); err != nil { + return nil, err + } + + return &r, nil +} + +type ListUcsProfilesResponse struct { + Count int `json:"count"` + UcsProfiles []*UcsProfile `json:"ucsprofile"` +} + +type UcsProfile struct { + Ucsdn string `json:"ucsdn"` } diff --git a/vendor/github.com/xanzy/go-cloudstack/cloudstack/UsageService.go b/vendor/github.com/xanzy/go-cloudstack/cloudstack/UsageService.go index fb6e34306..63a99ae5a 100644 --- a/vendor/github.com/xanzy/go-cloudstack/cloudstack/UsageService.go +++ b/vendor/github.com/xanzy/go-cloudstack/cloudstack/UsageService.go @@ -1,5 +1,5 @@ // -// Copyright 2016, Sander van Harmelen +// Copyright 2018, Sander van Harmelen // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -23,6 +23,95 @@ import ( "strconv" ) +type AddTrafficMonitorParams struct { + p map[string]interface{} +} + +func (p *AddTrafficMonitorParams) toURLValues() url.Values { + u := url.Values{} + if p.p == nil { + return u + } + if v, found := p.p["excludezones"]; found { + u.Set("excludezones", v.(string)) + } + if v, found := p.p["includezones"]; found { + u.Set("includezones", v.(string)) + } + if v, found := p.p["url"]; found { + u.Set("url", v.(string)) + } + if v, found := p.p["zoneid"]; found { + u.Set("zoneid", v.(string)) + } + return u +} + +func (p *AddTrafficMonitorParams) SetExcludezones(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["excludezones"] = v + return +} + +func (p *AddTrafficMonitorParams) SetIncludezones(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["includezones"] = v + return +} + +func (p *AddTrafficMonitorParams) SetUrl(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["url"] = v + return +} + +func (p *AddTrafficMonitorParams) SetZoneid(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["zoneid"] = v + return +} + +// You should always use this function to get a new AddTrafficMonitorParams instance, +// as then you are sure you have configured all required params +func (s *UsageService) NewAddTrafficMonitorParams(url string, zoneid string) *AddTrafficMonitorParams { + p := &AddTrafficMonitorParams{} + p.p = make(map[string]interface{}) + p.p["url"] = url + p.p["zoneid"] = zoneid + return p +} + +// Adds Traffic Monitor Host for Direct Network Usage +func (s *UsageService) AddTrafficMonitor(p *AddTrafficMonitorParams) (*AddTrafficMonitorResponse, error) { + resp, err := s.cs.newRequest("addTrafficMonitor", p.toURLValues()) + if err != nil { + return nil, err + } + + var r AddTrafficMonitorResponse + if err := json.Unmarshal(resp, &r); err != nil { + return nil, err + } + + return &r, nil +} + +type AddTrafficMonitorResponse struct { + Id string `json:"id"` + Ipaddress string `json:"ipaddress"` + Numretries string `json:"numretries"` + Timeout string `json:"timeout"` + Zoneid string `json:"zoneid"` +} + type AddTrafficTypeParams struct { p map[string]interface{} } @@ -175,19 +264,91 @@ func (s *UsageService) AddTrafficType(p *AddTrafficTypeParams) (*AddTrafficTypeR return nil, err } } + return &r, nil } type AddTrafficTypeResponse struct { - JobID string `json:"jobid,omitempty"` - Hypervnetworklabel string `json:"hypervnetworklabel,omitempty"` - Id string `json:"id,omitempty"` - Kvmnetworklabel string `json:"kvmnetworklabel,omitempty"` - Ovm3networklabel string `json:"ovm3networklabel,omitempty"` - Physicalnetworkid string `json:"physicalnetworkid,omitempty"` - Traffictype string `json:"traffictype,omitempty"` - Vmwarenetworklabel string `json:"vmwarenetworklabel,omitempty"` - Xennetworklabel string `json:"xennetworklabel,omitempty"` + JobID string `json:"jobid"` + Hypervnetworklabel string `json:"hypervnetworklabel"` + Id string `json:"id"` + Kvmnetworklabel string `json:"kvmnetworklabel"` + Ovm3networklabel string `json:"ovm3networklabel"` + Physicalnetworkid string `json:"physicalnetworkid"` + Traffictype string `json:"traffictype"` + Vmwarenetworklabel string `json:"vmwarenetworklabel"` + Xennetworklabel string `json:"xennetworklabel"` +} + +type DeleteTrafficMonitorParams struct { + p map[string]interface{} +} + +func (p *DeleteTrafficMonitorParams) toURLValues() url.Values { + u := url.Values{} + if p.p == nil { + return u + } + if v, found := p.p["id"]; found { + u.Set("id", v.(string)) + } + return u +} + +func (p *DeleteTrafficMonitorParams) SetId(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["id"] = v + return +} + +// You should always use this function to get a new DeleteTrafficMonitorParams instance, +// as then you are sure you have configured all required params +func (s *UsageService) NewDeleteTrafficMonitorParams(id string) *DeleteTrafficMonitorParams { + p := &DeleteTrafficMonitorParams{} + p.p = make(map[string]interface{}) + p.p["id"] = id + return p +} + +// Deletes an traffic monitor host. +func (s *UsageService) DeleteTrafficMonitor(p *DeleteTrafficMonitorParams) (*DeleteTrafficMonitorResponse, error) { + resp, err := s.cs.newRequest("deleteTrafficMonitor", p.toURLValues()) + if err != nil { + return nil, err + } + + var r DeleteTrafficMonitorResponse + if err := json.Unmarshal(resp, &r); err != nil { + return nil, err + } + + return &r, nil +} + +type DeleteTrafficMonitorResponse struct { + Displaytext string `json:"displaytext"` + Success bool `json:"success"` +} + +func (r *DeleteTrafficMonitorResponse) UnmarshalJSON(b []byte) error { + var m map[string]interface{} + err := json.Unmarshal(b, &m) + if err != nil { + return err + } + + if success, ok := m["success"].(string); ok { + m["success"] = success == "true" + b, err = json.Marshal(m) + if err != nil { + return err + } + } + + type alias DeleteTrafficMonitorResponse + return json.Unmarshal(b, (*alias)(r)) } type DeleteTrafficTypeParams struct { @@ -248,13 +409,294 @@ func (s *UsageService) DeleteTrafficType(p *DeleteTrafficTypeParams) (*DeleteTra return nil, err } } + return &r, nil } type DeleteTrafficTypeResponse struct { - JobID string `json:"jobid,omitempty"` - Displaytext string `json:"displaytext,omitempty"` - Success bool `json:"success,omitempty"` + JobID string `json:"jobid"` + Displaytext string `json:"displaytext"` + Success bool `json:"success"` +} + +type GenerateUsageRecordsParams struct { + p map[string]interface{} +} + +func (p *GenerateUsageRecordsParams) toURLValues() url.Values { + u := url.Values{} + if p.p == nil { + return u + } + if v, found := p.p["domainid"]; found { + u.Set("domainid", v.(string)) + } + if v, found := p.p["enddate"]; found { + u.Set("enddate", v.(string)) + } + if v, found := p.p["startdate"]; found { + u.Set("startdate", v.(string)) + } + return u +} + +func (p *GenerateUsageRecordsParams) SetDomainid(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["domainid"] = v + return +} + +func (p *GenerateUsageRecordsParams) SetEnddate(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["enddate"] = v + return +} + +func (p *GenerateUsageRecordsParams) SetStartdate(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["startdate"] = v + return +} + +// You should always use this function to get a new GenerateUsageRecordsParams instance, +// as then you are sure you have configured all required params +func (s *UsageService) NewGenerateUsageRecordsParams(enddate string, startdate string) *GenerateUsageRecordsParams { + p := &GenerateUsageRecordsParams{} + p.p = make(map[string]interface{}) + p.p["enddate"] = enddate + p.p["startdate"] = startdate + return p +} + +// Generates usage records. This will generate records only if there any records to be generated, i.e if the scheduled usage job was not run or failed +func (s *UsageService) GenerateUsageRecords(p *GenerateUsageRecordsParams) (*GenerateUsageRecordsResponse, error) { + resp, err := s.cs.newRequest("generateUsageRecords", p.toURLValues()) + if err != nil { + return nil, err + } + + var r GenerateUsageRecordsResponse + if err := json.Unmarshal(resp, &r); err != nil { + return nil, err + } + + return &r, nil +} + +type GenerateUsageRecordsResponse struct { + Displaytext string `json:"displaytext"` + Success bool `json:"success"` +} + +func (r *GenerateUsageRecordsResponse) UnmarshalJSON(b []byte) error { + var m map[string]interface{} + err := json.Unmarshal(b, &m) + if err != nil { + return err + } + + if success, ok := m["success"].(string); ok { + m["success"] = success == "true" + b, err = json.Marshal(m) + if err != nil { + return err + } + } + + type alias GenerateUsageRecordsResponse + return json.Unmarshal(b, (*alias)(r)) +} + +type ListTrafficMonitorsParams struct { + p map[string]interface{} +} + +func (p *ListTrafficMonitorsParams) toURLValues() url.Values { + u := url.Values{} + if p.p == nil { + return u + } + if v, found := p.p["keyword"]; found { + u.Set("keyword", v.(string)) + } + if v, found := p.p["page"]; found { + vv := strconv.Itoa(v.(int)) + u.Set("page", vv) + } + if v, found := p.p["pagesize"]; found { + vv := strconv.Itoa(v.(int)) + u.Set("pagesize", vv) + } + if v, found := p.p["zoneid"]; found { + u.Set("zoneid", v.(string)) + } + return u +} + +func (p *ListTrafficMonitorsParams) SetKeyword(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["keyword"] = v + return +} + +func (p *ListTrafficMonitorsParams) SetPage(v int) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["page"] = v + return +} + +func (p *ListTrafficMonitorsParams) SetPagesize(v int) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["pagesize"] = v + return +} + +func (p *ListTrafficMonitorsParams) SetZoneid(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["zoneid"] = v + return +} + +// You should always use this function to get a new ListTrafficMonitorsParams instance, +// as then you are sure you have configured all required params +func (s *UsageService) NewListTrafficMonitorsParams(zoneid string) *ListTrafficMonitorsParams { + p := &ListTrafficMonitorsParams{} + p.p = make(map[string]interface{}) + p.p["zoneid"] = zoneid + return p +} + +// List traffic monitor Hosts. +func (s *UsageService) ListTrafficMonitors(p *ListTrafficMonitorsParams) (*ListTrafficMonitorsResponse, error) { + resp, err := s.cs.newRequest("listTrafficMonitors", p.toURLValues()) + if err != nil { + return nil, err + } + + var r ListTrafficMonitorsResponse + if err := json.Unmarshal(resp, &r); err != nil { + return nil, err + } + + return &r, nil +} + +type ListTrafficMonitorsResponse struct { + Count int `json:"count"` + TrafficMonitors []*TrafficMonitor `json:"trafficmonitor"` +} + +type TrafficMonitor struct { + Id string `json:"id"` + Ipaddress string `json:"ipaddress"` + Numretries string `json:"numretries"` + Timeout string `json:"timeout"` + Zoneid string `json:"zoneid"` +} + +type ListTrafficTypeImplementorsParams struct { + p map[string]interface{} +} + +func (p *ListTrafficTypeImplementorsParams) toURLValues() url.Values { + u := url.Values{} + if p.p == nil { + return u + } + if v, found := p.p["keyword"]; found { + u.Set("keyword", v.(string)) + } + if v, found := p.p["page"]; found { + vv := strconv.Itoa(v.(int)) + u.Set("page", vv) + } + if v, found := p.p["pagesize"]; found { + vv := strconv.Itoa(v.(int)) + u.Set("pagesize", vv) + } + if v, found := p.p["traffictype"]; found { + u.Set("traffictype", v.(string)) + } + return u +} + +func (p *ListTrafficTypeImplementorsParams) SetKeyword(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["keyword"] = v + return +} + +func (p *ListTrafficTypeImplementorsParams) SetPage(v int) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["page"] = v + return +} + +func (p *ListTrafficTypeImplementorsParams) SetPagesize(v int) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["pagesize"] = v + return +} + +func (p *ListTrafficTypeImplementorsParams) SetTraffictype(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["traffictype"] = v + return +} + +// You should always use this function to get a new ListTrafficTypeImplementorsParams instance, +// as then you are sure you have configured all required params +func (s *UsageService) NewListTrafficTypeImplementorsParams() *ListTrafficTypeImplementorsParams { + p := &ListTrafficTypeImplementorsParams{} + p.p = make(map[string]interface{}) + return p +} + +// Lists implementors of implementor of a network traffic type or implementors of all network traffic types +func (s *UsageService) ListTrafficTypeImplementors(p *ListTrafficTypeImplementorsParams) (*ListTrafficTypeImplementorsResponse, error) { + resp, err := s.cs.newRequest("listTrafficTypeImplementors", p.toURLValues()) + if err != nil { + return nil, err + } + + var r ListTrafficTypeImplementorsResponse + if err := json.Unmarshal(resp, &r); err != nil { + return nil, err + } + + return &r, nil +} + +type ListTrafficTypeImplementorsResponse struct { + Count int `json:"count"` + TrafficTypeImplementors []*TrafficTypeImplementor `json:"traffictypeimplementor"` +} + +type TrafficTypeImplementor struct { + Traffictype string `json:"traffictype"` + Traffictypeimplementor string `json:"traffictypeimplementor"` } type ListTrafficTypesParams struct { @@ -332,7 +774,7 @@ func (s *UsageService) GetTrafficTypeID(keyword string, physicalnetworkid string p.p["keyword"] = keyword p.p["physicalnetworkid"] = physicalnetworkid - for _, fn := range opts { + for _, fn := range append(s.cs.options, opts...) { if err := fn(s.cs, p); err != nil { return "", -1, err } @@ -372,6 +814,7 @@ func (s *UsageService) ListTrafficTypes(p *ListTrafficTypesParams) (*ListTraffic if err := json.Unmarshal(resp, &r); err != nil { return nil, err } + return &r, nil } @@ -381,13 +824,339 @@ type ListTrafficTypesResponse struct { } type TrafficType struct { - Canenableindividualservice bool `json:"canenableindividualservice,omitempty"` - Destinationphysicalnetworkid string `json:"destinationphysicalnetworkid,omitempty"` - Id string `json:"id,omitempty"` - Name string `json:"name,omitempty"` - Physicalnetworkid string `json:"physicalnetworkid,omitempty"` - Servicelist []string `json:"servicelist,omitempty"` - State string `json:"state,omitempty"` + Canenableindividualservice bool `json:"canenableindividualservice"` + Destinationphysicalnetworkid string `json:"destinationphysicalnetworkid"` + Id string `json:"id"` + Name string `json:"name"` + Physicalnetworkid string `json:"physicalnetworkid"` + Servicelist []string `json:"servicelist"` + State string `json:"state"` +} + +type ListUsageRecordsParams struct { + p map[string]interface{} +} + +func (p *ListUsageRecordsParams) toURLValues() url.Values { + u := url.Values{} + if p.p == nil { + return u + } + if v, found := p.p["account"]; found { + u.Set("account", v.(string)) + } + if v, found := p.p["accountid"]; found { + u.Set("accountid", v.(string)) + } + if v, found := p.p["domainid"]; found { + u.Set("domainid", v.(string)) + } + if v, found := p.p["enddate"]; found { + u.Set("enddate", v.(string)) + } + if v, found := p.p["includetags"]; found { + vv := strconv.FormatBool(v.(bool)) + u.Set("includetags", vv) + } + if v, found := p.p["keyword"]; found { + u.Set("keyword", v.(string)) + } + if v, found := p.p["page"]; found { + vv := strconv.Itoa(v.(int)) + u.Set("page", vv) + } + if v, found := p.p["pagesize"]; found { + vv := strconv.Itoa(v.(int)) + u.Set("pagesize", vv) + } + if v, found := p.p["projectid"]; found { + u.Set("projectid", v.(string)) + } + if v, found := p.p["startdate"]; found { + u.Set("startdate", v.(string)) + } + if v, found := p.p["type"]; found { + vv := strconv.FormatInt(v.(int64), 10) + u.Set("type", vv) + } + if v, found := p.p["usageid"]; found { + u.Set("usageid", v.(string)) + } + return u +} + +func (p *ListUsageRecordsParams) SetAccount(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["account"] = v + return +} + +func (p *ListUsageRecordsParams) SetAccountid(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["accountid"] = v + return +} + +func (p *ListUsageRecordsParams) SetDomainid(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["domainid"] = v + return +} + +func (p *ListUsageRecordsParams) SetEnddate(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["enddate"] = v + return +} + +func (p *ListUsageRecordsParams) SetIncludetags(v bool) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["includetags"] = v + return +} + +func (p *ListUsageRecordsParams) SetKeyword(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["keyword"] = v + return +} + +func (p *ListUsageRecordsParams) SetPage(v int) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["page"] = v + return +} + +func (p *ListUsageRecordsParams) SetPagesize(v int) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["pagesize"] = v + return +} + +func (p *ListUsageRecordsParams) SetProjectid(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["projectid"] = v + return +} + +func (p *ListUsageRecordsParams) SetStartdate(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["startdate"] = v + return +} + +func (p *ListUsageRecordsParams) SetType(v int64) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["type"] = v + return +} + +func (p *ListUsageRecordsParams) SetUsageid(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["usageid"] = v + return +} + +// You should always use this function to get a new ListUsageRecordsParams instance, +// as then you are sure you have configured all required params +func (s *UsageService) NewListUsageRecordsParams(enddate string, startdate string) *ListUsageRecordsParams { + p := &ListUsageRecordsParams{} + p.p = make(map[string]interface{}) + p.p["enddate"] = enddate + p.p["startdate"] = startdate + return p +} + +// Lists usage records for accounts +func (s *UsageService) ListUsageRecords(p *ListUsageRecordsParams) (*ListUsageRecordsResponse, error) { + resp, err := s.cs.newRequest("listUsageRecords", p.toURLValues()) + if err != nil { + return nil, err + } + + var r ListUsageRecordsResponse + if err := json.Unmarshal(resp, &r); err != nil { + return nil, err + } + + return &r, nil +} + +type ListUsageRecordsResponse struct { + Count int `json:"count"` + UsageRecords []*UsageRecord `json:"usagerecord"` +} + +type UsageRecord struct { + Account string `json:"account"` + Accountid string `json:"accountid"` + Cpunumber int64 `json:"cpunumber"` + Cpuspeed int64 `json:"cpuspeed"` + Description string `json:"description"` + Domain string `json:"domain"` + Domainid string `json:"domainid"` + Enddate string `json:"enddate"` + Isdefault bool `json:"isdefault"` + Issourcenat bool `json:"issourcenat"` + Issystem bool `json:"issystem"` + Memory int64 `json:"memory"` + Name string `json:"name"` + Networkid string `json:"networkid"` + Offeringid string `json:"offeringid"` + Project string `json:"project"` + Projectid string `json:"projectid"` + Rawusage string `json:"rawusage"` + Size int64 `json:"size"` + Startdate string `json:"startdate"` + Templateid string `json:"templateid"` + Type string `json:"type"` + Usage string `json:"usage"` + Usageid string `json:"usageid"` + Usagetype int `json:"usagetype"` + Virtualmachineid string `json:"virtualmachineid"` + Virtualsize int64 `json:"virtualsize"` + Zoneid string `json:"zoneid"` +} + +type ListUsageTypesParams struct { + p map[string]interface{} +} + +func (p *ListUsageTypesParams) toURLValues() url.Values { + u := url.Values{} + if p.p == nil { + return u + } + return u +} + +// You should always use this function to get a new ListUsageTypesParams instance, +// as then you are sure you have configured all required params +func (s *UsageService) NewListUsageTypesParams() *ListUsageTypesParams { + p := &ListUsageTypesParams{} + p.p = make(map[string]interface{}) + return p +} + +// List Usage Types +func (s *UsageService) ListUsageTypes(p *ListUsageTypesParams) (*ListUsageTypesResponse, error) { + resp, err := s.cs.newRequest("listUsageTypes", p.toURLValues()) + if err != nil { + return nil, err + } + + var r ListUsageTypesResponse + if err := json.Unmarshal(resp, &r); err != nil { + return nil, err + } + + return &r, nil +} + +type ListUsageTypesResponse struct { + Count int `json:"count"` + UsageTypes []*UsageType `json:"usagetype"` +} + +type UsageType struct { + Description string `json:"description"` + Usagetypeid int `json:"usagetypeid"` +} + +type RemoveRawUsageRecordsParams struct { + p map[string]interface{} +} + +func (p *RemoveRawUsageRecordsParams) toURLValues() url.Values { + u := url.Values{} + if p.p == nil { + return u + } + if v, found := p.p["interval"]; found { + vv := strconv.Itoa(v.(int)) + u.Set("interval", vv) + } + return u +} + +func (p *RemoveRawUsageRecordsParams) SetInterval(v int) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["interval"] = v + return +} + +// You should always use this function to get a new RemoveRawUsageRecordsParams instance, +// as then you are sure you have configured all required params +func (s *UsageService) NewRemoveRawUsageRecordsParams(interval int) *RemoveRawUsageRecordsParams { + p := &RemoveRawUsageRecordsParams{} + p.p = make(map[string]interface{}) + p.p["interval"] = interval + return p +} + +// Safely removes raw records from cloud_usage table +func (s *UsageService) RemoveRawUsageRecords(p *RemoveRawUsageRecordsParams) (*RemoveRawUsageRecordsResponse, error) { + resp, err := s.cs.newRequest("removeRawUsageRecords", p.toURLValues()) + if err != nil { + return nil, err + } + + var r RemoveRawUsageRecordsResponse + if err := json.Unmarshal(resp, &r); err != nil { + return nil, err + } + + return &r, nil +} + +type RemoveRawUsageRecordsResponse struct { + Displaytext string `json:"displaytext"` + Success bool `json:"success"` +} + +func (r *RemoveRawUsageRecordsResponse) UnmarshalJSON(b []byte) error { + var m map[string]interface{} + err := json.Unmarshal(b, &m) + if err != nil { + return err + } + + if success, ok := m["success"].(string); ok { + m["success"] = success == "true" + b, err = json.Marshal(m) + if err != nil { + return err + } + } + + type alias RemoveRawUsageRecordsResponse + return json.Unmarshal(b, (*alias)(r)) } type UpdateTrafficTypeParams struct { @@ -508,706 +1277,18 @@ func (s *UsageService) UpdateTrafficType(p *UpdateTrafficTypeParams) (*UpdateTra return nil, err } } + return &r, nil } type UpdateTrafficTypeResponse struct { - JobID string `json:"jobid,omitempty"` - Hypervnetworklabel string `json:"hypervnetworklabel,omitempty"` - Id string `json:"id,omitempty"` - Kvmnetworklabel string `json:"kvmnetworklabel,omitempty"` - Ovm3networklabel string `json:"ovm3networklabel,omitempty"` - Physicalnetworkid string `json:"physicalnetworkid,omitempty"` - Traffictype string `json:"traffictype,omitempty"` - Vmwarenetworklabel string `json:"vmwarenetworklabel,omitempty"` - Xennetworklabel string `json:"xennetworklabel,omitempty"` -} - -type ListTrafficTypeImplementorsParams struct { - p map[string]interface{} -} - -func (p *ListTrafficTypeImplementorsParams) toURLValues() url.Values { - u := url.Values{} - if p.p == nil { - return u - } - if v, found := p.p["keyword"]; found { - u.Set("keyword", v.(string)) - } - if v, found := p.p["page"]; found { - vv := strconv.Itoa(v.(int)) - u.Set("page", vv) - } - if v, found := p.p["pagesize"]; found { - vv := strconv.Itoa(v.(int)) - u.Set("pagesize", vv) - } - if v, found := p.p["traffictype"]; found { - u.Set("traffictype", v.(string)) - } - return u -} - -func (p *ListTrafficTypeImplementorsParams) SetKeyword(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["keyword"] = v - return -} - -func (p *ListTrafficTypeImplementorsParams) SetPage(v int) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["page"] = v - return -} - -func (p *ListTrafficTypeImplementorsParams) SetPagesize(v int) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["pagesize"] = v - return -} - -func (p *ListTrafficTypeImplementorsParams) SetTraffictype(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["traffictype"] = v - return -} - -// You should always use this function to get a new ListTrafficTypeImplementorsParams instance, -// as then you are sure you have configured all required params -func (s *UsageService) NewListTrafficTypeImplementorsParams() *ListTrafficTypeImplementorsParams { - p := &ListTrafficTypeImplementorsParams{} - p.p = make(map[string]interface{}) - return p -} - -// Lists implementors of implementor of a network traffic type or implementors of all network traffic types -func (s *UsageService) ListTrafficTypeImplementors(p *ListTrafficTypeImplementorsParams) (*ListTrafficTypeImplementorsResponse, error) { - resp, err := s.cs.newRequest("listTrafficTypeImplementors", p.toURLValues()) - if err != nil { - return nil, err - } - - var r ListTrafficTypeImplementorsResponse - if err := json.Unmarshal(resp, &r); err != nil { - return nil, err - } - return &r, nil -} - -type ListTrafficTypeImplementorsResponse struct { - Count int `json:"count"` - TrafficTypeImplementors []*TrafficTypeImplementor `json:"traffictypeimplementor"` -} - -type TrafficTypeImplementor struct { - Traffictype string `json:"traffictype,omitempty"` - Traffictypeimplementor string `json:"traffictypeimplementor,omitempty"` -} - -type GenerateUsageRecordsParams struct { - p map[string]interface{} -} - -func (p *GenerateUsageRecordsParams) toURLValues() url.Values { - u := url.Values{} - if p.p == nil { - return u - } - if v, found := p.p["domainid"]; found { - u.Set("domainid", v.(string)) - } - if v, found := p.p["enddate"]; found { - u.Set("enddate", v.(string)) - } - if v, found := p.p["startdate"]; found { - u.Set("startdate", v.(string)) - } - return u -} - -func (p *GenerateUsageRecordsParams) SetDomainid(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["domainid"] = v - return -} - -func (p *GenerateUsageRecordsParams) SetEnddate(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["enddate"] = v - return -} - -func (p *GenerateUsageRecordsParams) SetStartdate(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["startdate"] = v - return -} - -// You should always use this function to get a new GenerateUsageRecordsParams instance, -// as then you are sure you have configured all required params -func (s *UsageService) NewGenerateUsageRecordsParams(enddate string, startdate string) *GenerateUsageRecordsParams { - p := &GenerateUsageRecordsParams{} - p.p = make(map[string]interface{}) - p.p["enddate"] = enddate - p.p["startdate"] = startdate - return p -} - -// Generates usage records. This will generate records only if there any records to be generated, i.e if the scheduled usage job was not run or failed -func (s *UsageService) GenerateUsageRecords(p *GenerateUsageRecordsParams) (*GenerateUsageRecordsResponse, error) { - resp, err := s.cs.newRequest("generateUsageRecords", p.toURLValues()) - if err != nil { - return nil, err - } - - var r GenerateUsageRecordsResponse - if err := json.Unmarshal(resp, &r); err != nil { - return nil, err - } - return &r, nil -} - -type GenerateUsageRecordsResponse struct { - Displaytext string `json:"displaytext,omitempty"` - Success string `json:"success,omitempty"` -} - -type ListUsageRecordsParams struct { - p map[string]interface{} -} - -func (p *ListUsageRecordsParams) toURLValues() url.Values { - u := url.Values{} - if p.p == nil { - return u - } - if v, found := p.p["account"]; found { - u.Set("account", v.(string)) - } - if v, found := p.p["accountid"]; found { - u.Set("accountid", v.(string)) - } - if v, found := p.p["domainid"]; found { - u.Set("domainid", v.(string)) - } - if v, found := p.p["enddate"]; found { - u.Set("enddate", v.(string)) - } - if v, found := p.p["keyword"]; found { - u.Set("keyword", v.(string)) - } - if v, found := p.p["page"]; found { - vv := strconv.Itoa(v.(int)) - u.Set("page", vv) - } - if v, found := p.p["pagesize"]; found { - vv := strconv.Itoa(v.(int)) - u.Set("pagesize", vv) - } - if v, found := p.p["projectid"]; found { - u.Set("projectid", v.(string)) - } - if v, found := p.p["startdate"]; found { - u.Set("startdate", v.(string)) - } - if v, found := p.p["type"]; found { - vv := strconv.FormatInt(v.(int64), 10) - u.Set("type", vv) - } - if v, found := p.p["usageid"]; found { - u.Set("usageid", v.(string)) - } - return u -} - -func (p *ListUsageRecordsParams) SetAccount(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["account"] = v - return -} - -func (p *ListUsageRecordsParams) SetAccountid(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["accountid"] = v - return -} - -func (p *ListUsageRecordsParams) SetDomainid(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["domainid"] = v - return -} - -func (p *ListUsageRecordsParams) SetEnddate(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["enddate"] = v - return -} - -func (p *ListUsageRecordsParams) SetKeyword(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["keyword"] = v - return -} - -func (p *ListUsageRecordsParams) SetPage(v int) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["page"] = v - return -} - -func (p *ListUsageRecordsParams) SetPagesize(v int) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["pagesize"] = v - return -} - -func (p *ListUsageRecordsParams) SetProjectid(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["projectid"] = v - return -} - -func (p *ListUsageRecordsParams) SetStartdate(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["startdate"] = v - return -} - -func (p *ListUsageRecordsParams) SetType(v int64) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["type"] = v - return -} - -func (p *ListUsageRecordsParams) SetUsageid(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["usageid"] = v - return -} - -// You should always use this function to get a new ListUsageRecordsParams instance, -// as then you are sure you have configured all required params -func (s *UsageService) NewListUsageRecordsParams(enddate string, startdate string) *ListUsageRecordsParams { - p := &ListUsageRecordsParams{} - p.p = make(map[string]interface{}) - p.p["enddate"] = enddate - p.p["startdate"] = startdate - return p -} - -// Lists usage records for accounts -func (s *UsageService) ListUsageRecords(p *ListUsageRecordsParams) (*ListUsageRecordsResponse, error) { - resp, err := s.cs.newRequest("listUsageRecords", p.toURLValues()) - if err != nil { - return nil, err - } - - var r ListUsageRecordsResponse - if err := json.Unmarshal(resp, &r); err != nil { - return nil, err - } - return &r, nil -} - -type ListUsageRecordsResponse struct { - Count int `json:"count"` - UsageRecords []*UsageRecord `json:"usagerecord"` -} - -type UsageRecord struct { - Account string `json:"account,omitempty"` - Accountid string `json:"accountid,omitempty"` - Cpunumber int64 `json:"cpunumber,omitempty"` - Cpuspeed int64 `json:"cpuspeed,omitempty"` - Description string `json:"description,omitempty"` - Domain string `json:"domain,omitempty"` - Domainid string `json:"domainid,omitempty"` - Enddate string `json:"enddate,omitempty"` - Isdefault bool `json:"isdefault,omitempty"` - Issourcenat bool `json:"issourcenat,omitempty"` - Issystem bool `json:"issystem,omitempty"` - Memory int64 `json:"memory,omitempty"` - Name string `json:"name,omitempty"` - Networkid string `json:"networkid,omitempty"` - Offeringid string `json:"offeringid,omitempty"` - Project string `json:"project,omitempty"` - Projectid string `json:"projectid,omitempty"` - Rawusage string `json:"rawusage,omitempty"` - Size int64 `json:"size,omitempty"` - Startdate string `json:"startdate,omitempty"` - Templateid string `json:"templateid,omitempty"` - Type string `json:"type,omitempty"` - Usage string `json:"usage,omitempty"` - Usageid string `json:"usageid,omitempty"` - Usagetype int `json:"usagetype,omitempty"` - Virtualmachineid string `json:"virtualmachineid,omitempty"` - Virtualsize int64 `json:"virtualsize,omitempty"` - Zoneid string `json:"zoneid,omitempty"` -} - -type ListUsageTypesParams struct { - p map[string]interface{} -} - -func (p *ListUsageTypesParams) toURLValues() url.Values { - u := url.Values{} - if p.p == nil { - return u - } - return u -} - -// You should always use this function to get a new ListUsageTypesParams instance, -// as then you are sure you have configured all required params -func (s *UsageService) NewListUsageTypesParams() *ListUsageTypesParams { - p := &ListUsageTypesParams{} - p.p = make(map[string]interface{}) - return p -} - -// List Usage Types -func (s *UsageService) ListUsageTypes(p *ListUsageTypesParams) (*ListUsageTypesResponse, error) { - resp, err := s.cs.newRequest("listUsageTypes", p.toURLValues()) - if err != nil { - return nil, err - } - - var r ListUsageTypesResponse - if err := json.Unmarshal(resp, &r); err != nil { - return nil, err - } - return &r, nil -} - -type ListUsageTypesResponse struct { - Count int `json:"count"` - UsageTypes []*UsageType `json:"usagetype"` -} - -type UsageType struct { - Description string `json:"description,omitempty"` - Usagetypeid int `json:"usagetypeid,omitempty"` -} - -type RemoveRawUsageRecordsParams struct { - p map[string]interface{} -} - -func (p *RemoveRawUsageRecordsParams) toURLValues() url.Values { - u := url.Values{} - if p.p == nil { - return u - } - if v, found := p.p["interval"]; found { - vv := strconv.Itoa(v.(int)) - u.Set("interval", vv) - } - return u -} - -func (p *RemoveRawUsageRecordsParams) SetInterval(v int) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["interval"] = v - return -} - -// You should always use this function to get a new RemoveRawUsageRecordsParams instance, -// as then you are sure you have configured all required params -func (s *UsageService) NewRemoveRawUsageRecordsParams(interval int) *RemoveRawUsageRecordsParams { - p := &RemoveRawUsageRecordsParams{} - p.p = make(map[string]interface{}) - p.p["interval"] = interval - return p -} - -// Safely removes raw records from cloud_usage table -func (s *UsageService) RemoveRawUsageRecords(p *RemoveRawUsageRecordsParams) (*RemoveRawUsageRecordsResponse, error) { - resp, err := s.cs.newRequest("removeRawUsageRecords", p.toURLValues()) - if err != nil { - return nil, err - } - - var r RemoveRawUsageRecordsResponse - if err := json.Unmarshal(resp, &r); err != nil { - return nil, err - } - return &r, nil -} - -type RemoveRawUsageRecordsResponse struct { - Displaytext string `json:"displaytext,omitempty"` - Success string `json:"success,omitempty"` -} - -type AddTrafficMonitorParams struct { - p map[string]interface{} -} - -func (p *AddTrafficMonitorParams) toURLValues() url.Values { - u := url.Values{} - if p.p == nil { - return u - } - if v, found := p.p["excludezones"]; found { - u.Set("excludezones", v.(string)) - } - if v, found := p.p["includezones"]; found { - u.Set("includezones", v.(string)) - } - if v, found := p.p["url"]; found { - u.Set("url", v.(string)) - } - if v, found := p.p["zoneid"]; found { - u.Set("zoneid", v.(string)) - } - return u -} - -func (p *AddTrafficMonitorParams) SetExcludezones(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["excludezones"] = v - return -} - -func (p *AddTrafficMonitorParams) SetIncludezones(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["includezones"] = v - return -} - -func (p *AddTrafficMonitorParams) SetUrl(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["url"] = v - return -} - -func (p *AddTrafficMonitorParams) SetZoneid(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["zoneid"] = v - return -} - -// You should always use this function to get a new AddTrafficMonitorParams instance, -// as then you are sure you have configured all required params -func (s *UsageService) NewAddTrafficMonitorParams(url string, zoneid string) *AddTrafficMonitorParams { - p := &AddTrafficMonitorParams{} - p.p = make(map[string]interface{}) - p.p["url"] = url - p.p["zoneid"] = zoneid - return p -} - -// Adds Traffic Monitor Host for Direct Network Usage -func (s *UsageService) AddTrafficMonitor(p *AddTrafficMonitorParams) (*AddTrafficMonitorResponse, error) { - resp, err := s.cs.newRequest("addTrafficMonitor", p.toURLValues()) - if err != nil { - return nil, err - } - - var r AddTrafficMonitorResponse - if err := json.Unmarshal(resp, &r); err != nil { - return nil, err - } - return &r, nil -} - -type AddTrafficMonitorResponse struct { - Id string `json:"id,omitempty"` - Ipaddress string `json:"ipaddress,omitempty"` - Numretries string `json:"numretries,omitempty"` - Timeout string `json:"timeout,omitempty"` - Zoneid string `json:"zoneid,omitempty"` -} - -type DeleteTrafficMonitorParams struct { - p map[string]interface{} -} - -func (p *DeleteTrafficMonitorParams) toURLValues() url.Values { - u := url.Values{} - if p.p == nil { - return u - } - if v, found := p.p["id"]; found { - u.Set("id", v.(string)) - } - return u -} - -func (p *DeleteTrafficMonitorParams) SetId(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["id"] = v - return -} - -// You should always use this function to get a new DeleteTrafficMonitorParams instance, -// as then you are sure you have configured all required params -func (s *UsageService) NewDeleteTrafficMonitorParams(id string) *DeleteTrafficMonitorParams { - p := &DeleteTrafficMonitorParams{} - p.p = make(map[string]interface{}) - p.p["id"] = id - return p -} - -// Deletes an traffic monitor host. -func (s *UsageService) DeleteTrafficMonitor(p *DeleteTrafficMonitorParams) (*DeleteTrafficMonitorResponse, error) { - resp, err := s.cs.newRequest("deleteTrafficMonitor", p.toURLValues()) - if err != nil { - return nil, err - } - - var r DeleteTrafficMonitorResponse - if err := json.Unmarshal(resp, &r); err != nil { - return nil, err - } - return &r, nil -} - -type DeleteTrafficMonitorResponse struct { - Displaytext string `json:"displaytext,omitempty"` - Success string `json:"success,omitempty"` -} - -type ListTrafficMonitorsParams struct { - p map[string]interface{} -} - -func (p *ListTrafficMonitorsParams) toURLValues() url.Values { - u := url.Values{} - if p.p == nil { - return u - } - if v, found := p.p["keyword"]; found { - u.Set("keyword", v.(string)) - } - if v, found := p.p["page"]; found { - vv := strconv.Itoa(v.(int)) - u.Set("page", vv) - } - if v, found := p.p["pagesize"]; found { - vv := strconv.Itoa(v.(int)) - u.Set("pagesize", vv) - } - if v, found := p.p["zoneid"]; found { - u.Set("zoneid", v.(string)) - } - return u -} - -func (p *ListTrafficMonitorsParams) SetKeyword(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["keyword"] = v - return -} - -func (p *ListTrafficMonitorsParams) SetPage(v int) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["page"] = v - return -} - -func (p *ListTrafficMonitorsParams) SetPagesize(v int) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["pagesize"] = v - return -} - -func (p *ListTrafficMonitorsParams) SetZoneid(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["zoneid"] = v - return -} - -// You should always use this function to get a new ListTrafficMonitorsParams instance, -// as then you are sure you have configured all required params -func (s *UsageService) NewListTrafficMonitorsParams(zoneid string) *ListTrafficMonitorsParams { - p := &ListTrafficMonitorsParams{} - p.p = make(map[string]interface{}) - p.p["zoneid"] = zoneid - return p -} - -// List traffic monitor Hosts. -func (s *UsageService) ListTrafficMonitors(p *ListTrafficMonitorsParams) (*ListTrafficMonitorsResponse, error) { - resp, err := s.cs.newRequest("listTrafficMonitors", p.toURLValues()) - if err != nil { - return nil, err - } - - var r ListTrafficMonitorsResponse - if err := json.Unmarshal(resp, &r); err != nil { - return nil, err - } - return &r, nil -} - -type ListTrafficMonitorsResponse struct { - Count int `json:"count"` - TrafficMonitors []*TrafficMonitor `json:"trafficmonitor"` -} - -type TrafficMonitor struct { - Id string `json:"id,omitempty"` - Ipaddress string `json:"ipaddress,omitempty"` - Numretries string `json:"numretries,omitempty"` - Timeout string `json:"timeout,omitempty"` - Zoneid string `json:"zoneid,omitempty"` + JobID string `json:"jobid"` + Hypervnetworklabel string `json:"hypervnetworklabel"` + Id string `json:"id"` + Kvmnetworklabel string `json:"kvmnetworklabel"` + Ovm3networklabel string `json:"ovm3networklabel"` + Physicalnetworkid string `json:"physicalnetworkid"` + Traffictype string `json:"traffictype"` + Vmwarenetworklabel string `json:"vmwarenetworklabel"` + Xennetworklabel string `json:"xennetworklabel"` } diff --git a/vendor/github.com/xanzy/go-cloudstack/cloudstack/UserService.go b/vendor/github.com/xanzy/go-cloudstack/cloudstack/UserService.go index cf091225d..ba98845b3 100644 --- a/vendor/github.com/xanzy/go-cloudstack/cloudstack/UserService.go +++ b/vendor/github.com/xanzy/go-cloudstack/cloudstack/UserService.go @@ -1,5 +1,5 @@ // -// Copyright 2016, Sander van Harmelen +// Copyright 2018, Sander van Harmelen // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -156,31 +156,40 @@ func (s *UserService) CreateUser(p *CreateUserParams) (*CreateUserResponse, erro return nil, err } + if resp, err = getRawValue(resp); err != nil { + return nil, err + } + var r CreateUserResponse if err := json.Unmarshal(resp, &r); err != nil { return nil, err } + return &r, nil } type CreateUserResponse struct { - Account string `json:"account,omitempty"` - Accountid string `json:"accountid,omitempty"` - Accounttype int `json:"accounttype,omitempty"` - Apikey string `json:"apikey,omitempty"` - Created string `json:"created,omitempty"` - Domain string `json:"domain,omitempty"` - Domainid string `json:"domainid,omitempty"` - Email string `json:"email,omitempty"` - Firstname string `json:"firstname,omitempty"` - Id string `json:"id,omitempty"` - Iscallerchilddomain bool `json:"iscallerchilddomain,omitempty"` - Isdefault bool `json:"isdefault,omitempty"` - Lastname string `json:"lastname,omitempty"` - Secretkey string `json:"secretkey,omitempty"` - State string `json:"state,omitempty"` - Timezone string `json:"timezone,omitempty"` - Username string `json:"username,omitempty"` + Account string `json:"account"` + Accountid string `json:"accountid"` + Accounttype int `json:"accounttype"` + Apikey string `json:"apikey"` + Created string `json:"created"` + Domain string `json:"domain"` + Domainid string `json:"domainid"` + Email string `json:"email"` + Firstname string `json:"firstname"` + Id string `json:"id"` + Iscallerchilddomain bool `json:"iscallerchilddomain"` + Isdefault bool `json:"isdefault"` + Lastname string `json:"lastname"` + Roleid string `json:"roleid"` + Rolename string `json:"rolename"` + Roletype string `json:"roletype"` + Secretkey string `json:"secretkey"` + State string `json:"state"` + Timezone string `json:"timezone"` + Username string `json:"username"` + Usersource string `json:"usersource"` } type DeleteUserParams struct { @@ -226,70 +235,50 @@ func (s *UserService) DeleteUser(p *DeleteUserParams) (*DeleteUserResponse, erro if err := json.Unmarshal(resp, &r); err != nil { return nil, err } + return &r, nil } type DeleteUserResponse struct { - Displaytext string `json:"displaytext,omitempty"` - Success string `json:"success,omitempty"` + Displaytext string `json:"displaytext"` + Success bool `json:"success"` } -type UpdateUserParams struct { +func (r *DeleteUserResponse) UnmarshalJSON(b []byte) error { + var m map[string]interface{} + err := json.Unmarshal(b, &m) + if err != nil { + return err + } + + if success, ok := m["success"].(string); ok { + m["success"] = success == "true" + b, err = json.Marshal(m) + if err != nil { + return err + } + } + + type alias DeleteUserResponse + return json.Unmarshal(b, (*alias)(r)) +} + +type DisableUserParams struct { p map[string]interface{} } -func (p *UpdateUserParams) toURLValues() url.Values { +func (p *DisableUserParams) toURLValues() url.Values { u := url.Values{} if p.p == nil { return u } - if v, found := p.p["email"]; found { - u.Set("email", v.(string)) - } - if v, found := p.p["firstname"]; found { - u.Set("firstname", v.(string)) - } if v, found := p.p["id"]; found { u.Set("id", v.(string)) } - if v, found := p.p["lastname"]; found { - u.Set("lastname", v.(string)) - } - if v, found := p.p["password"]; found { - u.Set("password", v.(string)) - } - if v, found := p.p["timezone"]; found { - u.Set("timezone", v.(string)) - } - if v, found := p.p["userapikey"]; found { - u.Set("userapikey", v.(string)) - } - if v, found := p.p["username"]; found { - u.Set("username", v.(string)) - } - if v, found := p.p["usersecretkey"]; found { - u.Set("usersecretkey", v.(string)) - } return u } -func (p *UpdateUserParams) SetEmail(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["email"] = v - return -} - -func (p *UpdateUserParams) SetFirstname(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["firstname"] = v - return -} - -func (p *UpdateUserParams) SetId(v string) { +func (p *DisableUserParams) SetId(v string) { if p.p == nil { p.p = make(map[string]interface{}) } @@ -297,31 +286,162 @@ func (p *UpdateUserParams) SetId(v string) { return } -func (p *UpdateUserParams) SetLastname(v string) { +// You should always use this function to get a new DisableUserParams instance, +// as then you are sure you have configured all required params +func (s *UserService) NewDisableUserParams(id string) *DisableUserParams { + p := &DisableUserParams{} + p.p = make(map[string]interface{}) + p.p["id"] = id + return p +} + +// Disables a user account +func (s *UserService) DisableUser(p *DisableUserParams) (*DisableUserResponse, error) { + resp, err := s.cs.newRequest("disableUser", p.toURLValues()) + if err != nil { + return nil, err + } + + var r DisableUserResponse + if err := json.Unmarshal(resp, &r); err != nil { + return nil, err + } + + // If we have a async client, we need to wait for the async result + if s.cs.async { + b, err := s.cs.GetAsyncJobResult(r.JobID, s.cs.timeout) + if err != nil { + if err == AsyncTimeoutErr { + return &r, err + } + return nil, err + } + + b, err = getRawValue(b) + if err != nil { + return nil, err + } + + if err := json.Unmarshal(b, &r); err != nil { + return nil, err + } + } + + return &r, nil +} + +type DisableUserResponse struct { + JobID string `json:"jobid"` + Account string `json:"account"` + Accountid string `json:"accountid"` + Accounttype int `json:"accounttype"` + Apikey string `json:"apikey"` + Created string `json:"created"` + Domain string `json:"domain"` + Domainid string `json:"domainid"` + Email string `json:"email"` + Firstname string `json:"firstname"` + Id string `json:"id"` + Iscallerchilddomain bool `json:"iscallerchilddomain"` + Isdefault bool `json:"isdefault"` + Lastname string `json:"lastname"` + Roleid string `json:"roleid"` + Rolename string `json:"rolename"` + Roletype string `json:"roletype"` + Secretkey string `json:"secretkey"` + State string `json:"state"` + Timezone string `json:"timezone"` + Username string `json:"username"` + Usersource string `json:"usersource"` +} + +type EnableUserParams struct { + p map[string]interface{} +} + +func (p *EnableUserParams) toURLValues() url.Values { + u := url.Values{} + if p.p == nil { + return u + } + if v, found := p.p["id"]; found { + u.Set("id", v.(string)) + } + return u +} + +func (p *EnableUserParams) SetId(v string) { if p.p == nil { p.p = make(map[string]interface{}) } - p.p["lastname"] = v + p.p["id"] = v return } -func (p *UpdateUserParams) SetPassword(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) +// You should always use this function to get a new EnableUserParams instance, +// as then you are sure you have configured all required params +func (s *UserService) NewEnableUserParams(id string) *EnableUserParams { + p := &EnableUserParams{} + p.p = make(map[string]interface{}) + p.p["id"] = id + return p +} + +// Enables a user account +func (s *UserService) EnableUser(p *EnableUserParams) (*EnableUserResponse, error) { + resp, err := s.cs.newRequest("enableUser", p.toURLValues()) + if err != nil { + return nil, err } - p.p["password"] = v - return -} -func (p *UpdateUserParams) SetTimezone(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) + var r EnableUserResponse + if err := json.Unmarshal(resp, &r); err != nil { + return nil, err } - p.p["timezone"] = v - return + + return &r, nil } -func (p *UpdateUserParams) SetUserapikey(v string) { +type EnableUserResponse struct { + Account string `json:"account"` + Accountid string `json:"accountid"` + Accounttype int `json:"accounttype"` + Apikey string `json:"apikey"` + Created string `json:"created"` + Domain string `json:"domain"` + Domainid string `json:"domainid"` + Email string `json:"email"` + Firstname string `json:"firstname"` + Id string `json:"id"` + Iscallerchilddomain bool `json:"iscallerchilddomain"` + Isdefault bool `json:"isdefault"` + Lastname string `json:"lastname"` + Roleid string `json:"roleid"` + Rolename string `json:"rolename"` + Roletype string `json:"roletype"` + Secretkey string `json:"secretkey"` + State string `json:"state"` + Timezone string `json:"timezone"` + Username string `json:"username"` + Usersource string `json:"usersource"` +} + +type GetUserParams struct { + p map[string]interface{} +} + +func (p *GetUserParams) toURLValues() url.Values { + u := url.Values{} + if p.p == nil { + return u + } + if v, found := p.p["userapikey"]; found { + u.Set("userapikey", v.(string)) + } + return u +} + +func (p *GetUserParams) SetUserapikey(v string) { if p.p == nil { p.p = make(map[string]interface{}) } @@ -329,63 +449,104 @@ func (p *UpdateUserParams) SetUserapikey(v string) { return } -func (p *UpdateUserParams) SetUsername(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["username"] = v - return -} - -func (p *UpdateUserParams) SetUsersecretkey(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["usersecretkey"] = v - return -} - -// You should always use this function to get a new UpdateUserParams instance, +// You should always use this function to get a new GetUserParams instance, // as then you are sure you have configured all required params -func (s *UserService) NewUpdateUserParams(id string) *UpdateUserParams { - p := &UpdateUserParams{} +func (s *UserService) NewGetUserParams(userapikey string) *GetUserParams { + p := &GetUserParams{} p.p = make(map[string]interface{}) - p.p["id"] = id + p.p["userapikey"] = userapikey return p } -// Updates a user account -func (s *UserService) UpdateUser(p *UpdateUserParams) (*UpdateUserResponse, error) { - resp, err := s.cs.newRequest("updateUser", p.toURLValues()) +// Find user account by API key +func (s *UserService) GetUser(p *GetUserParams) (*GetUserResponse, error) { + resp, err := s.cs.newRequest("getUser", p.toURLValues()) if err != nil { return nil, err } - var r UpdateUserResponse + var r GetUserResponse if err := json.Unmarshal(resp, &r); err != nil { return nil, err } + return &r, nil } -type UpdateUserResponse struct { - Account string `json:"account,omitempty"` - Accountid string `json:"accountid,omitempty"` - Accounttype int `json:"accounttype,omitempty"` - Apikey string `json:"apikey,omitempty"` - Created string `json:"created,omitempty"` - Domain string `json:"domain,omitempty"` - Domainid string `json:"domainid,omitempty"` - Email string `json:"email,omitempty"` - Firstname string `json:"firstname,omitempty"` - Id string `json:"id,omitempty"` - Iscallerchilddomain bool `json:"iscallerchilddomain,omitempty"` - Isdefault bool `json:"isdefault,omitempty"` - Lastname string `json:"lastname,omitempty"` - Secretkey string `json:"secretkey,omitempty"` - State string `json:"state,omitempty"` - Timezone string `json:"timezone,omitempty"` - Username string `json:"username,omitempty"` +type GetUserResponse struct { + Account string `json:"account"` + Accountid string `json:"accountid"` + Accounttype int `json:"accounttype"` + Apikey string `json:"apikey"` + Created string `json:"created"` + Domain string `json:"domain"` + Domainid string `json:"domainid"` + Email string `json:"email"` + Firstname string `json:"firstname"` + Id string `json:"id"` + Iscallerchilddomain bool `json:"iscallerchilddomain"` + Isdefault bool `json:"isdefault"` + Lastname string `json:"lastname"` + Roleid string `json:"roleid"` + Rolename string `json:"rolename"` + Roletype string `json:"roletype"` + Secretkey string `json:"secretkey"` + State string `json:"state"` + Timezone string `json:"timezone"` + Username string `json:"username"` + Usersource string `json:"usersource"` +} + +type GetVirtualMachineUserDataParams struct { + p map[string]interface{} +} + +func (p *GetVirtualMachineUserDataParams) toURLValues() url.Values { + u := url.Values{} + if p.p == nil { + return u + } + if v, found := p.p["virtualmachineid"]; found { + u.Set("virtualmachineid", v.(string)) + } + return u +} + +func (p *GetVirtualMachineUserDataParams) SetVirtualmachineid(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["virtualmachineid"] = v + return +} + +// You should always use this function to get a new GetVirtualMachineUserDataParams instance, +// as then you are sure you have configured all required params +func (s *UserService) NewGetVirtualMachineUserDataParams(virtualmachineid string) *GetVirtualMachineUserDataParams { + p := &GetVirtualMachineUserDataParams{} + p.p = make(map[string]interface{}) + p.p["virtualmachineid"] = virtualmachineid + return p +} + +// Returns user data associated with the VM +func (s *UserService) GetVirtualMachineUserData(p *GetVirtualMachineUserDataParams) (*GetVirtualMachineUserDataResponse, error) { + resp, err := s.cs.newRequest("getVirtualMachineUserData", p.toURLValues()) + if err != nil { + return nil, err + } + + var r GetVirtualMachineUserDataResponse + if err := json.Unmarshal(resp, &r); err != nil { + return nil, err + } + + return &r, nil +} + +type GetVirtualMachineUserDataResponse struct { + Userdata string `json:"userdata"` + Virtualmachineid string `json:"virtualmachineid"` } type ListUsersParams struct { @@ -541,7 +702,7 @@ func (s *UserService) GetUserByID(id string, opts ...OptionFunc) (*User, int, er p.p["id"] = id - for _, fn := range opts { + for _, fn := range append(s.cs.options, opts...) { if err := fn(s.cs, p); err != nil { return nil, -1, err } @@ -578,6 +739,7 @@ func (s *UserService) ListUsers(p *ListUsersParams) (*ListUsersResponse, error) if err := json.Unmarshal(resp, &r); err != nil { return nil, err } + return &r, nil } @@ -587,23 +749,27 @@ type ListUsersResponse struct { } type User struct { - Account string `json:"account,omitempty"` - Accountid string `json:"accountid,omitempty"` - Accounttype int `json:"accounttype,omitempty"` - Apikey string `json:"apikey,omitempty"` - Created string `json:"created,omitempty"` - Domain string `json:"domain,omitempty"` - Domainid string `json:"domainid,omitempty"` - Email string `json:"email,omitempty"` - Firstname string `json:"firstname,omitempty"` - Id string `json:"id,omitempty"` - Iscallerchilddomain bool `json:"iscallerchilddomain,omitempty"` - Isdefault bool `json:"isdefault,omitempty"` - Lastname string `json:"lastname,omitempty"` - Secretkey string `json:"secretkey,omitempty"` - State string `json:"state,omitempty"` - Timezone string `json:"timezone,omitempty"` - Username string `json:"username,omitempty"` + Account string `json:"account"` + Accountid string `json:"accountid"` + Accounttype int `json:"accounttype"` + Apikey string `json:"apikey"` + Created string `json:"created"` + Domain string `json:"domain"` + Domainid string `json:"domainid"` + Email string `json:"email"` + Firstname string `json:"firstname"` + Id string `json:"id"` + Iscallerchilddomain bool `json:"iscallerchilddomain"` + Isdefault bool `json:"isdefault"` + Lastname string `json:"lastname"` + Roleid string `json:"roleid"` + Rolename string `json:"rolename"` + Roletype string `json:"roletype"` + Secretkey string `json:"secretkey"` + State string `json:"state"` + Timezone string `json:"timezone"` + Username string `json:"username"` + Usersource string `json:"usersource"` } type LockUserParams struct { @@ -649,297 +815,32 @@ func (s *UserService) LockUser(p *LockUserParams) (*LockUserResponse, error) { if err := json.Unmarshal(resp, &r); err != nil { return nil, err } + return &r, nil } type LockUserResponse struct { - Account string `json:"account,omitempty"` - Accountid string `json:"accountid,omitempty"` - Accounttype int `json:"accounttype,omitempty"` - Apikey string `json:"apikey,omitempty"` - Created string `json:"created,omitempty"` - Domain string `json:"domain,omitempty"` - Domainid string `json:"domainid,omitempty"` - Email string `json:"email,omitempty"` - Firstname string `json:"firstname,omitempty"` - Id string `json:"id,omitempty"` - Iscallerchilddomain bool `json:"iscallerchilddomain,omitempty"` - Isdefault bool `json:"isdefault,omitempty"` - Lastname string `json:"lastname,omitempty"` - Secretkey string `json:"secretkey,omitempty"` - State string `json:"state,omitempty"` - Timezone string `json:"timezone,omitempty"` - Username string `json:"username,omitempty"` -} - -type DisableUserParams struct { - p map[string]interface{} -} - -func (p *DisableUserParams) toURLValues() url.Values { - u := url.Values{} - if p.p == nil { - return u - } - if v, found := p.p["id"]; found { - u.Set("id", v.(string)) - } - return u -} - -func (p *DisableUserParams) SetId(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["id"] = v - return -} - -// You should always use this function to get a new DisableUserParams instance, -// as then you are sure you have configured all required params -func (s *UserService) NewDisableUserParams(id string) *DisableUserParams { - p := &DisableUserParams{} - p.p = make(map[string]interface{}) - p.p["id"] = id - return p -} - -// Disables a user account -func (s *UserService) DisableUser(p *DisableUserParams) (*DisableUserResponse, error) { - resp, err := s.cs.newRequest("disableUser", p.toURLValues()) - if err != nil { - return nil, err - } - - var r DisableUserResponse - if err := json.Unmarshal(resp, &r); err != nil { - return nil, err - } - - // If we have a async client, we need to wait for the async result - if s.cs.async { - b, err := s.cs.GetAsyncJobResult(r.JobID, s.cs.timeout) - if err != nil { - if err == AsyncTimeoutErr { - return &r, err - } - return nil, err - } - - b, err = getRawValue(b) - if err != nil { - return nil, err - } - - if err := json.Unmarshal(b, &r); err != nil { - return nil, err - } - } - return &r, nil -} - -type DisableUserResponse struct { - JobID string `json:"jobid,omitempty"` - Account string `json:"account,omitempty"` - Accountid string `json:"accountid,omitempty"` - Accounttype int `json:"accounttype,omitempty"` - Apikey string `json:"apikey,omitempty"` - Created string `json:"created,omitempty"` - Domain string `json:"domain,omitempty"` - Domainid string `json:"domainid,omitempty"` - Email string `json:"email,omitempty"` - Firstname string `json:"firstname,omitempty"` - Id string `json:"id,omitempty"` - Iscallerchilddomain bool `json:"iscallerchilddomain,omitempty"` - Isdefault bool `json:"isdefault,omitempty"` - Lastname string `json:"lastname,omitempty"` - Secretkey string `json:"secretkey,omitempty"` - State string `json:"state,omitempty"` - Timezone string `json:"timezone,omitempty"` - Username string `json:"username,omitempty"` -} - -type EnableUserParams struct { - p map[string]interface{} -} - -func (p *EnableUserParams) toURLValues() url.Values { - u := url.Values{} - if p.p == nil { - return u - } - if v, found := p.p["id"]; found { - u.Set("id", v.(string)) - } - return u -} - -func (p *EnableUserParams) SetId(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["id"] = v - return -} - -// You should always use this function to get a new EnableUserParams instance, -// as then you are sure you have configured all required params -func (s *UserService) NewEnableUserParams(id string) *EnableUserParams { - p := &EnableUserParams{} - p.p = make(map[string]interface{}) - p.p["id"] = id - return p -} - -// Enables a user account -func (s *UserService) EnableUser(p *EnableUserParams) (*EnableUserResponse, error) { - resp, err := s.cs.newRequest("enableUser", p.toURLValues()) - if err != nil { - return nil, err - } - - var r EnableUserResponse - if err := json.Unmarshal(resp, &r); err != nil { - return nil, err - } - return &r, nil -} - -type EnableUserResponse struct { - Account string `json:"account,omitempty"` - Accountid string `json:"accountid,omitempty"` - Accounttype int `json:"accounttype,omitempty"` - Apikey string `json:"apikey,omitempty"` - Created string `json:"created,omitempty"` - Domain string `json:"domain,omitempty"` - Domainid string `json:"domainid,omitempty"` - Email string `json:"email,omitempty"` - Firstname string `json:"firstname,omitempty"` - Id string `json:"id,omitempty"` - Iscallerchilddomain bool `json:"iscallerchilddomain,omitempty"` - Isdefault bool `json:"isdefault,omitempty"` - Lastname string `json:"lastname,omitempty"` - Secretkey string `json:"secretkey,omitempty"` - State string `json:"state,omitempty"` - Timezone string `json:"timezone,omitempty"` - Username string `json:"username,omitempty"` -} - -type GetUserParams struct { - p map[string]interface{} -} - -func (p *GetUserParams) toURLValues() url.Values { - u := url.Values{} - if p.p == nil { - return u - } - if v, found := p.p["userapikey"]; found { - u.Set("userapikey", v.(string)) - } - return u -} - -func (p *GetUserParams) SetUserapikey(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["userapikey"] = v - return -} - -// You should always use this function to get a new GetUserParams instance, -// as then you are sure you have configured all required params -func (s *UserService) NewGetUserParams(userapikey string) *GetUserParams { - p := &GetUserParams{} - p.p = make(map[string]interface{}) - p.p["userapikey"] = userapikey - return p -} - -// Find user account by API key -func (s *UserService) GetUser(p *GetUserParams) (*GetUserResponse, error) { - resp, err := s.cs.newRequest("getUser", p.toURLValues()) - if err != nil { - return nil, err - } - - var r GetUserResponse - if err := json.Unmarshal(resp, &r); err != nil { - return nil, err - } - return &r, nil -} - -type GetUserResponse struct { - Account string `json:"account,omitempty"` - Accountid string `json:"accountid,omitempty"` - Accounttype int `json:"accounttype,omitempty"` - Apikey string `json:"apikey,omitempty"` - Created string `json:"created,omitempty"` - Domain string `json:"domain,omitempty"` - Domainid string `json:"domainid,omitempty"` - Email string `json:"email,omitempty"` - Firstname string `json:"firstname,omitempty"` - Id string `json:"id,omitempty"` - Iscallerchilddomain bool `json:"iscallerchilddomain,omitempty"` - Isdefault bool `json:"isdefault,omitempty"` - Lastname string `json:"lastname,omitempty"` - Secretkey string `json:"secretkey,omitempty"` - State string `json:"state,omitempty"` - Timezone string `json:"timezone,omitempty"` - Username string `json:"username,omitempty"` -} - -type GetVirtualMachineUserDataParams struct { - p map[string]interface{} -} - -func (p *GetVirtualMachineUserDataParams) toURLValues() url.Values { - u := url.Values{} - if p.p == nil { - return u - } - if v, found := p.p["virtualmachineid"]; found { - u.Set("virtualmachineid", v.(string)) - } - return u -} - -func (p *GetVirtualMachineUserDataParams) SetVirtualmachineid(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["virtualmachineid"] = v - return -} - -// You should always use this function to get a new GetVirtualMachineUserDataParams instance, -// as then you are sure you have configured all required params -func (s *UserService) NewGetVirtualMachineUserDataParams(virtualmachineid string) *GetVirtualMachineUserDataParams { - p := &GetVirtualMachineUserDataParams{} - p.p = make(map[string]interface{}) - p.p["virtualmachineid"] = virtualmachineid - return p -} - -// Returns user data associated with the VM -func (s *UserService) GetVirtualMachineUserData(p *GetVirtualMachineUserDataParams) (*GetVirtualMachineUserDataResponse, error) { - resp, err := s.cs.newRequest("getVirtualMachineUserData", p.toURLValues()) - if err != nil { - return nil, err - } - - var r GetVirtualMachineUserDataResponse - if err := json.Unmarshal(resp, &r); err != nil { - return nil, err - } - return &r, nil -} - -type GetVirtualMachineUserDataResponse struct { - Userdata string `json:"userdata,omitempty"` - Virtualmachineid string `json:"virtualmachineid,omitempty"` + Account string `json:"account"` + Accountid string `json:"accountid"` + Accounttype int `json:"accounttype"` + Apikey string `json:"apikey"` + Created string `json:"created"` + Domain string `json:"domain"` + Domainid string `json:"domainid"` + Email string `json:"email"` + Firstname string `json:"firstname"` + Id string `json:"id"` + Iscallerchilddomain bool `json:"iscallerchilddomain"` + Isdefault bool `json:"isdefault"` + Lastname string `json:"lastname"` + Roleid string `json:"roleid"` + Rolename string `json:"rolename"` + Roletype string `json:"roletype"` + Secretkey string `json:"secretkey"` + State string `json:"state"` + Timezone string `json:"timezone"` + Username string `json:"username"` + Usersource string `json:"usersource"` } type RegisterUserKeysParams struct { @@ -981,224 +882,103 @@ func (s *UserService) RegisterUserKeys(p *RegisterUserKeysParams) (*RegisterUser return nil, err } + if resp, err = getRawValue(resp); err != nil { + return nil, err + } + var r RegisterUserKeysResponse if err := json.Unmarshal(resp, &r); err != nil { return nil, err } + return &r, nil } type RegisterUserKeysResponse struct { - Apikey string `json:"apikey,omitempty"` - Secretkey string `json:"secretkey,omitempty"` + Apikey string `json:"apikey"` + Secretkey string `json:"secretkey"` } -type ListLdapUsersParams struct { +type UpdateUserParams struct { p map[string]interface{} } -func (p *ListLdapUsersParams) toURLValues() url.Values { +func (p *UpdateUserParams) toURLValues() url.Values { u := url.Values{} if p.p == nil { return u } - if v, found := p.p["keyword"]; found { - u.Set("keyword", v.(string)) + if v, found := p.p["email"]; found { + u.Set("email", v.(string)) } - if v, found := p.p["listtype"]; found { - u.Set("listtype", v.(string)) + if v, found := p.p["firstname"]; found { + u.Set("firstname", v.(string)) } - if v, found := p.p["page"]; found { - vv := strconv.Itoa(v.(int)) - u.Set("page", vv) + if v, found := p.p["id"]; found { + u.Set("id", v.(string)) } - if v, found := p.p["pagesize"]; found { - vv := strconv.Itoa(v.(int)) - u.Set("pagesize", vv) + if v, found := p.p["lastname"]; found { + u.Set("lastname", v.(string)) } - return u -} - -func (p *ListLdapUsersParams) SetKeyword(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["keyword"] = v - return -} - -func (p *ListLdapUsersParams) SetListtype(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["listtype"] = v - return -} - -func (p *ListLdapUsersParams) SetPage(v int) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["page"] = v - return -} - -func (p *ListLdapUsersParams) SetPagesize(v int) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["pagesize"] = v - return -} - -// You should always use this function to get a new ListLdapUsersParams instance, -// as then you are sure you have configured all required params -func (s *UserService) NewListLdapUsersParams() *ListLdapUsersParams { - p := &ListLdapUsersParams{} - p.p = make(map[string]interface{}) - return p -} - -// Lists all LDAP Users -func (s *UserService) ListLdapUsers(p *ListLdapUsersParams) (*ListLdapUsersResponse, error) { - resp, err := s.cs.newRequest("listLdapUsers", p.toURLValues()) - if err != nil { - return nil, err - } - - var r ListLdapUsersResponse - if err := json.Unmarshal(resp, &r); err != nil { - return nil, err - } - return &r, nil -} - -type ListLdapUsersResponse struct { - Count int `json:"count"` - LdapUsers []*LdapUser `json:"ldapuser"` -} - -type LdapUser struct { - Domain string `json:"domain,omitempty"` - Email string `json:"email,omitempty"` - Firstname string `json:"firstname,omitempty"` - Lastname string `json:"lastname,omitempty"` - Principal string `json:"principal,omitempty"` - Username string `json:"username,omitempty"` -} - -type ImportLdapUsersParams struct { - p map[string]interface{} -} - -func (p *ImportLdapUsersParams) toURLValues() url.Values { - u := url.Values{} - if p.p == nil { - return u - } - if v, found := p.p["account"]; found { - u.Set("account", v.(string)) - } - if v, found := p.p["accountdetails"]; found { - i := 0 - for k, vv := range v.(map[string]string) { - u.Set(fmt.Sprintf("accountdetails[%d].key", i), k) - u.Set(fmt.Sprintf("accountdetails[%d].value", i), vv) - i++ - } - } - if v, found := p.p["accounttype"]; found { - vv := strconv.Itoa(v.(int)) - u.Set("accounttype", vv) - } - if v, found := p.p["domainid"]; found { - u.Set("domainid", v.(string)) - } - if v, found := p.p["group"]; found { - u.Set("group", v.(string)) - } - if v, found := p.p["keyword"]; found { - u.Set("keyword", v.(string)) - } - if v, found := p.p["page"]; found { - vv := strconv.Itoa(v.(int)) - u.Set("page", vv) - } - if v, found := p.p["pagesize"]; found { - vv := strconv.Itoa(v.(int)) - u.Set("pagesize", vv) + if v, found := p.p["password"]; found { + u.Set("password", v.(string)) } if v, found := p.p["timezone"]; found { u.Set("timezone", v.(string)) } + if v, found := p.p["userapikey"]; found { + u.Set("userapikey", v.(string)) + } + if v, found := p.p["username"]; found { + u.Set("username", v.(string)) + } + if v, found := p.p["usersecretkey"]; found { + u.Set("usersecretkey", v.(string)) + } return u } -func (p *ImportLdapUsersParams) SetAccount(v string) { +func (p *UpdateUserParams) SetEmail(v string) { if p.p == nil { p.p = make(map[string]interface{}) } - p.p["account"] = v + p.p["email"] = v return } -func (p *ImportLdapUsersParams) SetAccountdetails(v map[string]string) { +func (p *UpdateUserParams) SetFirstname(v string) { if p.p == nil { p.p = make(map[string]interface{}) } - p.p["accountdetails"] = v + p.p["firstname"] = v return } -func (p *ImportLdapUsersParams) SetAccounttype(v int) { +func (p *UpdateUserParams) SetId(v string) { if p.p == nil { p.p = make(map[string]interface{}) } - p.p["accounttype"] = v + p.p["id"] = v return } -func (p *ImportLdapUsersParams) SetDomainid(v string) { +func (p *UpdateUserParams) SetLastname(v string) { if p.p == nil { p.p = make(map[string]interface{}) } - p.p["domainid"] = v + p.p["lastname"] = v return } -func (p *ImportLdapUsersParams) SetGroup(v string) { +func (p *UpdateUserParams) SetPassword(v string) { if p.p == nil { p.p = make(map[string]interface{}) } - p.p["group"] = v + p.p["password"] = v return } -func (p *ImportLdapUsersParams) SetKeyword(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["keyword"] = v - return -} - -func (p *ImportLdapUsersParams) SetPage(v int) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["page"] = v - return -} - -func (p *ImportLdapUsersParams) SetPagesize(v int) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["pagesize"] = v - return -} - -func (p *ImportLdapUsersParams) SetTimezone(v string) { +func (p *UpdateUserParams) SetTimezone(v string) { if p.p == nil { p.p = make(map[string]interface{}) } @@ -1206,34 +986,74 @@ func (p *ImportLdapUsersParams) SetTimezone(v string) { return } -// You should always use this function to get a new ImportLdapUsersParams instance, +func (p *UpdateUserParams) SetUserapikey(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["userapikey"] = v + return +} + +func (p *UpdateUserParams) SetUsername(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["username"] = v + return +} + +func (p *UpdateUserParams) SetUsersecretkey(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["usersecretkey"] = v + return +} + +// You should always use this function to get a new UpdateUserParams instance, // as then you are sure you have configured all required params -func (s *UserService) NewImportLdapUsersParams(accounttype int) *ImportLdapUsersParams { - p := &ImportLdapUsersParams{} +func (s *UserService) NewUpdateUserParams(id string) *UpdateUserParams { + p := &UpdateUserParams{} p.p = make(map[string]interface{}) - p.p["accounttype"] = accounttype + p.p["id"] = id return p } -// Import LDAP users -func (s *UserService) ImportLdapUsers(p *ImportLdapUsersParams) (*ImportLdapUsersResponse, error) { - resp, err := s.cs.newRequest("importLdapUsers", p.toURLValues()) +// Updates a user account +func (s *UserService) UpdateUser(p *UpdateUserParams) (*UpdateUserResponse, error) { + resp, err := s.cs.newRequest("updateUser", p.toURLValues()) if err != nil { return nil, err } - var r ImportLdapUsersResponse + var r UpdateUserResponse if err := json.Unmarshal(resp, &r); err != nil { return nil, err } + return &r, nil } -type ImportLdapUsersResponse struct { - Domain string `json:"domain,omitempty"` - Email string `json:"email,omitempty"` - Firstname string `json:"firstname,omitempty"` - Lastname string `json:"lastname,omitempty"` - Principal string `json:"principal,omitempty"` - Username string `json:"username,omitempty"` +type UpdateUserResponse struct { + Account string `json:"account"` + Accountid string `json:"accountid"` + Accounttype int `json:"accounttype"` + Apikey string `json:"apikey"` + Created string `json:"created"` + Domain string `json:"domain"` + Domainid string `json:"domainid"` + Email string `json:"email"` + Firstname string `json:"firstname"` + Id string `json:"id"` + Iscallerchilddomain bool `json:"iscallerchilddomain"` + Isdefault bool `json:"isdefault"` + Lastname string `json:"lastname"` + Roleid string `json:"roleid"` + Rolename string `json:"rolename"` + Roletype string `json:"roletype"` + Secretkey string `json:"secretkey"` + State string `json:"state"` + Timezone string `json:"timezone"` + Username string `json:"username"` + Usersource string `json:"usersource"` } diff --git a/vendor/github.com/xanzy/go-cloudstack/cloudstack/VLANService.go b/vendor/github.com/xanzy/go-cloudstack/cloudstack/VLANService.go index 0809b6dae..754b19e7d 100644 --- a/vendor/github.com/xanzy/go-cloudstack/cloudstack/VLANService.go +++ b/vendor/github.com/xanzy/go-cloudstack/cloudstack/VLANService.go @@ -1,5 +1,5 @@ // -// Copyright 2016, Sander van Harmelen +// Copyright 2018, Sander van Harmelen // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -45,6 +45,10 @@ func (p *CreateVlanIpRangeParams) toURLValues() url.Values { if v, found := p.p["endipv6"]; found { u.Set("endipv6", v.(string)) } + if v, found := p.p["forsystemvms"]; found { + vv := strconv.FormatBool(v.(bool)) + u.Set("forsystemvms", vv) + } if v, found := p.p["forvirtualnetwork"]; found { vv := strconv.FormatBool(v.(bool)) u.Set("forvirtualnetwork", vv) @@ -120,6 +124,14 @@ func (p *CreateVlanIpRangeParams) SetEndipv6(v string) { return } +func (p *CreateVlanIpRangeParams) SetForsystemvms(v bool) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["forsystemvms"] = v + return +} + func (p *CreateVlanIpRangeParams) SetForvirtualnetwork(v bool) { if p.p == nil { p.p = make(map[string]interface{}) @@ -243,32 +255,138 @@ func (s *VLANService) CreateVlanIpRange(p *CreateVlanIpRangeParams) (*CreateVlan if err := json.Unmarshal(resp, &r); err != nil { return nil, err } + return &r, nil } type CreateVlanIpRangeResponse struct { - Account string `json:"account,omitempty"` - Description string `json:"description,omitempty"` - Domain string `json:"domain,omitempty"` - Domainid string `json:"domainid,omitempty"` - Endip string `json:"endip,omitempty"` - Endipv6 string `json:"endipv6,omitempty"` - Forvirtualnetwork bool `json:"forvirtualnetwork,omitempty"` - Gateway string `json:"gateway,omitempty"` - Id string `json:"id,omitempty"` - Ip6cidr string `json:"ip6cidr,omitempty"` - Ip6gateway string `json:"ip6gateway,omitempty"` - Netmask string `json:"netmask,omitempty"` - Networkid string `json:"networkid,omitempty"` - Physicalnetworkid string `json:"physicalnetworkid,omitempty"` - Podid string `json:"podid,omitempty"` - Podname string `json:"podname,omitempty"` - Project string `json:"project,omitempty"` - Projectid string `json:"projectid,omitempty"` - Startip string `json:"startip,omitempty"` - Startipv6 string `json:"startipv6,omitempty"` - Vlan string `json:"vlan,omitempty"` - Zoneid string `json:"zoneid,omitempty"` + Account string `json:"account"` + Description string `json:"description"` + Domain string `json:"domain"` + Domainid string `json:"domainid"` + Endip string `json:"endip"` + Endipv6 string `json:"endipv6"` + Forsystemvms bool `json:"forsystemvms"` + Forvirtualnetwork bool `json:"forvirtualnetwork"` + Gateway string `json:"gateway"` + Id string `json:"id"` + Ip6cidr string `json:"ip6cidr"` + Ip6gateway string `json:"ip6gateway"` + Netmask string `json:"netmask"` + Networkid string `json:"networkid"` + Physicalnetworkid string `json:"physicalnetworkid"` + Podid string `json:"podid"` + Podname string `json:"podname"` + Project string `json:"project"` + Projectid string `json:"projectid"` + Startip string `json:"startip"` + Startipv6 string `json:"startipv6"` + Vlan string `json:"vlan"` + Zoneid string `json:"zoneid"` +} + +type DedicateGuestVlanRangeParams struct { + p map[string]interface{} +} + +func (p *DedicateGuestVlanRangeParams) toURLValues() url.Values { + u := url.Values{} + if p.p == nil { + return u + } + if v, found := p.p["account"]; found { + u.Set("account", v.(string)) + } + if v, found := p.p["domainid"]; found { + u.Set("domainid", v.(string)) + } + if v, found := p.p["physicalnetworkid"]; found { + u.Set("physicalnetworkid", v.(string)) + } + if v, found := p.p["projectid"]; found { + u.Set("projectid", v.(string)) + } + if v, found := p.p["vlanrange"]; found { + u.Set("vlanrange", v.(string)) + } + return u +} + +func (p *DedicateGuestVlanRangeParams) SetAccount(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["account"] = v + return +} + +func (p *DedicateGuestVlanRangeParams) SetDomainid(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["domainid"] = v + return +} + +func (p *DedicateGuestVlanRangeParams) SetPhysicalnetworkid(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["physicalnetworkid"] = v + return +} + +func (p *DedicateGuestVlanRangeParams) SetProjectid(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["projectid"] = v + return +} + +func (p *DedicateGuestVlanRangeParams) SetVlanrange(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["vlanrange"] = v + return +} + +// You should always use this function to get a new DedicateGuestVlanRangeParams instance, +// as then you are sure you have configured all required params +func (s *VLANService) NewDedicateGuestVlanRangeParams(physicalnetworkid string, vlanrange string) *DedicateGuestVlanRangeParams { + p := &DedicateGuestVlanRangeParams{} + p.p = make(map[string]interface{}) + p.p["physicalnetworkid"] = physicalnetworkid + p.p["vlanrange"] = vlanrange + return p +} + +// Dedicates a guest vlan range to an account +func (s *VLANService) DedicateGuestVlanRange(p *DedicateGuestVlanRangeParams) (*DedicateGuestVlanRangeResponse, error) { + resp, err := s.cs.newRequest("dedicateGuestVlanRange", p.toURLValues()) + if err != nil { + return nil, err + } + + var r DedicateGuestVlanRangeResponse + if err := json.Unmarshal(resp, &r); err != nil { + return nil, err + } + + return &r, nil +} + +type DedicateGuestVlanRangeResponse struct { + Account string `json:"account"` + Domain string `json:"domain"` + Domainid string `json:"domainid"` + Guestvlanrange string `json:"guestvlanrange"` + Id string `json:"id"` + Physicalnetworkid int64 `json:"physicalnetworkid"` + Project string `json:"project"` + Projectid string `json:"projectid"` + Zoneid int64 `json:"zoneid"` } type DeleteVlanIpRangeParams struct { @@ -314,12 +432,229 @@ func (s *VLANService) DeleteVlanIpRange(p *DeleteVlanIpRangeParams) (*DeleteVlan if err := json.Unmarshal(resp, &r); err != nil { return nil, err } + return &r, nil } type DeleteVlanIpRangeResponse struct { - Displaytext string `json:"displaytext,omitempty"` - Success string `json:"success,omitempty"` + Displaytext string `json:"displaytext"` + Success bool `json:"success"` +} + +func (r *DeleteVlanIpRangeResponse) UnmarshalJSON(b []byte) error { + var m map[string]interface{} + err := json.Unmarshal(b, &m) + if err != nil { + return err + } + + if success, ok := m["success"].(string); ok { + m["success"] = success == "true" + b, err = json.Marshal(m) + if err != nil { + return err + } + } + + type alias DeleteVlanIpRangeResponse + return json.Unmarshal(b, (*alias)(r)) +} + +type ListDedicatedGuestVlanRangesParams struct { + p map[string]interface{} +} + +func (p *ListDedicatedGuestVlanRangesParams) toURLValues() url.Values { + u := url.Values{} + if p.p == nil { + return u + } + if v, found := p.p["account"]; found { + u.Set("account", v.(string)) + } + if v, found := p.p["domainid"]; found { + u.Set("domainid", v.(string)) + } + if v, found := p.p["guestvlanrange"]; found { + u.Set("guestvlanrange", v.(string)) + } + if v, found := p.p["id"]; found { + u.Set("id", v.(string)) + } + if v, found := p.p["keyword"]; found { + u.Set("keyword", v.(string)) + } + if v, found := p.p["page"]; found { + vv := strconv.Itoa(v.(int)) + u.Set("page", vv) + } + if v, found := p.p["pagesize"]; found { + vv := strconv.Itoa(v.(int)) + u.Set("pagesize", vv) + } + if v, found := p.p["physicalnetworkid"]; found { + u.Set("physicalnetworkid", v.(string)) + } + if v, found := p.p["projectid"]; found { + u.Set("projectid", v.(string)) + } + if v, found := p.p["zoneid"]; found { + u.Set("zoneid", v.(string)) + } + return u +} + +func (p *ListDedicatedGuestVlanRangesParams) SetAccount(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["account"] = v + return +} + +func (p *ListDedicatedGuestVlanRangesParams) SetDomainid(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["domainid"] = v + return +} + +func (p *ListDedicatedGuestVlanRangesParams) SetGuestvlanrange(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["guestvlanrange"] = v + return +} + +func (p *ListDedicatedGuestVlanRangesParams) SetId(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["id"] = v + return +} + +func (p *ListDedicatedGuestVlanRangesParams) SetKeyword(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["keyword"] = v + return +} + +func (p *ListDedicatedGuestVlanRangesParams) SetPage(v int) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["page"] = v + return +} + +func (p *ListDedicatedGuestVlanRangesParams) SetPagesize(v int) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["pagesize"] = v + return +} + +func (p *ListDedicatedGuestVlanRangesParams) SetPhysicalnetworkid(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["physicalnetworkid"] = v + return +} + +func (p *ListDedicatedGuestVlanRangesParams) SetProjectid(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["projectid"] = v + return +} + +func (p *ListDedicatedGuestVlanRangesParams) SetZoneid(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["zoneid"] = v + return +} + +// You should always use this function to get a new ListDedicatedGuestVlanRangesParams instance, +// as then you are sure you have configured all required params +func (s *VLANService) NewListDedicatedGuestVlanRangesParams() *ListDedicatedGuestVlanRangesParams { + p := &ListDedicatedGuestVlanRangesParams{} + p.p = make(map[string]interface{}) + return p +} + +// This is a courtesy helper function, which in some cases may not work as expected! +func (s *VLANService) GetDedicatedGuestVlanRangeByID(id string, opts ...OptionFunc) (*DedicatedGuestVlanRange, int, error) { + p := &ListDedicatedGuestVlanRangesParams{} + p.p = make(map[string]interface{}) + + p.p["id"] = id + + for _, fn := range append(s.cs.options, opts...) { + if err := fn(s.cs, p); err != nil { + return nil, -1, err + } + } + + l, err := s.ListDedicatedGuestVlanRanges(p) + if err != nil { + if strings.Contains(err.Error(), fmt.Sprintf( + "Invalid parameter id value=%s due to incorrect long value format, "+ + "or entity does not exist", id)) { + return nil, 0, fmt.Errorf("No match found for %s: %+v", id, l) + } + return nil, -1, err + } + + if l.Count == 0 { + return nil, l.Count, fmt.Errorf("No match found for %s: %+v", id, l) + } + + if l.Count == 1 { + return l.DedicatedGuestVlanRanges[0], l.Count, nil + } + return nil, l.Count, fmt.Errorf("There is more then one result for DedicatedGuestVlanRange UUID: %s!", id) +} + +// Lists dedicated guest vlan ranges +func (s *VLANService) ListDedicatedGuestVlanRanges(p *ListDedicatedGuestVlanRangesParams) (*ListDedicatedGuestVlanRangesResponse, error) { + resp, err := s.cs.newRequest("listDedicatedGuestVlanRanges", p.toURLValues()) + if err != nil { + return nil, err + } + + var r ListDedicatedGuestVlanRangesResponse + if err := json.Unmarshal(resp, &r); err != nil { + return nil, err + } + + return &r, nil +} + +type ListDedicatedGuestVlanRangesResponse struct { + Count int `json:"count"` + DedicatedGuestVlanRanges []*DedicatedGuestVlanRange `json:"dedicatedguestvlanrange"` +} + +type DedicatedGuestVlanRange struct { + Account string `json:"account"` + Domain string `json:"domain"` + Domainid string `json:"domainid"` + Guestvlanrange string `json:"guestvlanrange"` + Id string `json:"id"` + Physicalnetworkid int64 `json:"physicalnetworkid"` + Project string `json:"project"` + Projectid string `json:"projectid"` + Zoneid int64 `json:"zoneid"` } type ListVlanIpRangesParams struct { @@ -495,7 +830,7 @@ func (s *VLANService) GetVlanIpRangeByID(id string, opts ...OptionFunc) (*VlanIp p.p["id"] = id - for _, fn := range opts { + for _, fn := range append(s.cs.options, opts...) { if err := fn(s.cs, p); err != nil { return nil, -1, err } @@ -532,6 +867,7 @@ func (s *VLANService) ListVlanIpRanges(p *ListVlanIpRangesParams) (*ListVlanIpRa if err := json.Unmarshal(resp, &r); err != nil { return nil, err } + return &r, nil } @@ -541,133 +877,29 @@ type ListVlanIpRangesResponse struct { } type VlanIpRange struct { - Account string `json:"account,omitempty"` - Description string `json:"description,omitempty"` - Domain string `json:"domain,omitempty"` - Domainid string `json:"domainid,omitempty"` - Endip string `json:"endip,omitempty"` - Endipv6 string `json:"endipv6,omitempty"` - Forvirtualnetwork bool `json:"forvirtualnetwork,omitempty"` - Gateway string `json:"gateway,omitempty"` - Id string `json:"id,omitempty"` - Ip6cidr string `json:"ip6cidr,omitempty"` - Ip6gateway string `json:"ip6gateway,omitempty"` - Netmask string `json:"netmask,omitempty"` - Networkid string `json:"networkid,omitempty"` - Physicalnetworkid string `json:"physicalnetworkid,omitempty"` - Podid string `json:"podid,omitempty"` - Podname string `json:"podname,omitempty"` - Project string `json:"project,omitempty"` - Projectid string `json:"projectid,omitempty"` - Startip string `json:"startip,omitempty"` - Startipv6 string `json:"startipv6,omitempty"` - Vlan string `json:"vlan,omitempty"` - Zoneid string `json:"zoneid,omitempty"` -} - -type DedicateGuestVlanRangeParams struct { - p map[string]interface{} -} - -func (p *DedicateGuestVlanRangeParams) toURLValues() url.Values { - u := url.Values{} - if p.p == nil { - return u - } - if v, found := p.p["account"]; found { - u.Set("account", v.(string)) - } - if v, found := p.p["domainid"]; found { - u.Set("domainid", v.(string)) - } - if v, found := p.p["physicalnetworkid"]; found { - u.Set("physicalnetworkid", v.(string)) - } - if v, found := p.p["projectid"]; found { - u.Set("projectid", v.(string)) - } - if v, found := p.p["vlanrange"]; found { - u.Set("vlanrange", v.(string)) - } - return u -} - -func (p *DedicateGuestVlanRangeParams) SetAccount(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["account"] = v - return -} - -func (p *DedicateGuestVlanRangeParams) SetDomainid(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["domainid"] = v - return -} - -func (p *DedicateGuestVlanRangeParams) SetPhysicalnetworkid(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["physicalnetworkid"] = v - return -} - -func (p *DedicateGuestVlanRangeParams) SetProjectid(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["projectid"] = v - return -} - -func (p *DedicateGuestVlanRangeParams) SetVlanrange(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["vlanrange"] = v - return -} - -// You should always use this function to get a new DedicateGuestVlanRangeParams instance, -// as then you are sure you have configured all required params -func (s *VLANService) NewDedicateGuestVlanRangeParams(account string, domainid string, physicalnetworkid string, vlanrange string) *DedicateGuestVlanRangeParams { - p := &DedicateGuestVlanRangeParams{} - p.p = make(map[string]interface{}) - p.p["account"] = account - p.p["domainid"] = domainid - p.p["physicalnetworkid"] = physicalnetworkid - p.p["vlanrange"] = vlanrange - return p -} - -// Dedicates a guest vlan range to an account -func (s *VLANService) DedicateGuestVlanRange(p *DedicateGuestVlanRangeParams) (*DedicateGuestVlanRangeResponse, error) { - resp, err := s.cs.newRequest("dedicateGuestVlanRange", p.toURLValues()) - if err != nil { - return nil, err - } - - var r DedicateGuestVlanRangeResponse - if err := json.Unmarshal(resp, &r); err != nil { - return nil, err - } - return &r, nil -} - -type DedicateGuestVlanRangeResponse struct { - Account string `json:"account,omitempty"` - Domain string `json:"domain,omitempty"` - Domainid string `json:"domainid,omitempty"` - Guestvlanrange string `json:"guestvlanrange,omitempty"` - Id string `json:"id,omitempty"` - Physicalnetworkid int64 `json:"physicalnetworkid,omitempty"` - Project string `json:"project,omitempty"` - Projectid string `json:"projectid,omitempty"` - Zoneid int64 `json:"zoneid,omitempty"` + Account string `json:"account"` + Description string `json:"description"` + Domain string `json:"domain"` + Domainid string `json:"domainid"` + Endip string `json:"endip"` + Endipv6 string `json:"endipv6"` + Forsystemvms bool `json:"forsystemvms"` + Forvirtualnetwork bool `json:"forvirtualnetwork"` + Gateway string `json:"gateway"` + Id string `json:"id"` + Ip6cidr string `json:"ip6cidr"` + Ip6gateway string `json:"ip6gateway"` + Netmask string `json:"netmask"` + Networkid string `json:"networkid"` + Physicalnetworkid string `json:"physicalnetworkid"` + Podid string `json:"podid"` + Podname string `json:"podname"` + Project string `json:"project"` + Projectid string `json:"projectid"` + Startip string `json:"startip"` + Startipv6 string `json:"startipv6"` + Vlan string `json:"vlan"` + Zoneid string `json:"zoneid"` } type ReleaseDedicatedGuestVlanRangeParams struct { @@ -728,207 +960,12 @@ func (s *VLANService) ReleaseDedicatedGuestVlanRange(p *ReleaseDedicatedGuestVla return nil, err } } + return &r, nil } type ReleaseDedicatedGuestVlanRangeResponse struct { - JobID string `json:"jobid,omitempty"` - Displaytext string `json:"displaytext,omitempty"` - Success bool `json:"success,omitempty"` -} - -type ListDedicatedGuestVlanRangesParams struct { - p map[string]interface{} -} - -func (p *ListDedicatedGuestVlanRangesParams) toURLValues() url.Values { - u := url.Values{} - if p.p == nil { - return u - } - if v, found := p.p["account"]; found { - u.Set("account", v.(string)) - } - if v, found := p.p["domainid"]; found { - u.Set("domainid", v.(string)) - } - if v, found := p.p["guestvlanrange"]; found { - u.Set("guestvlanrange", v.(string)) - } - if v, found := p.p["id"]; found { - u.Set("id", v.(string)) - } - if v, found := p.p["keyword"]; found { - u.Set("keyword", v.(string)) - } - if v, found := p.p["page"]; found { - vv := strconv.Itoa(v.(int)) - u.Set("page", vv) - } - if v, found := p.p["pagesize"]; found { - vv := strconv.Itoa(v.(int)) - u.Set("pagesize", vv) - } - if v, found := p.p["physicalnetworkid"]; found { - u.Set("physicalnetworkid", v.(string)) - } - if v, found := p.p["projectid"]; found { - u.Set("projectid", v.(string)) - } - if v, found := p.p["zoneid"]; found { - u.Set("zoneid", v.(string)) - } - return u -} - -func (p *ListDedicatedGuestVlanRangesParams) SetAccount(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["account"] = v - return -} - -func (p *ListDedicatedGuestVlanRangesParams) SetDomainid(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["domainid"] = v - return -} - -func (p *ListDedicatedGuestVlanRangesParams) SetGuestvlanrange(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["guestvlanrange"] = v - return -} - -func (p *ListDedicatedGuestVlanRangesParams) SetId(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["id"] = v - return -} - -func (p *ListDedicatedGuestVlanRangesParams) SetKeyword(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["keyword"] = v - return -} - -func (p *ListDedicatedGuestVlanRangesParams) SetPage(v int) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["page"] = v - return -} - -func (p *ListDedicatedGuestVlanRangesParams) SetPagesize(v int) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["pagesize"] = v - return -} - -func (p *ListDedicatedGuestVlanRangesParams) SetPhysicalnetworkid(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["physicalnetworkid"] = v - return -} - -func (p *ListDedicatedGuestVlanRangesParams) SetProjectid(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["projectid"] = v - return -} - -func (p *ListDedicatedGuestVlanRangesParams) SetZoneid(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["zoneid"] = v - return -} - -// You should always use this function to get a new ListDedicatedGuestVlanRangesParams instance, -// as then you are sure you have configured all required params -func (s *VLANService) NewListDedicatedGuestVlanRangesParams() *ListDedicatedGuestVlanRangesParams { - p := &ListDedicatedGuestVlanRangesParams{} - p.p = make(map[string]interface{}) - return p -} - -// This is a courtesy helper function, which in some cases may not work as expected! -func (s *VLANService) GetDedicatedGuestVlanRangeByID(id string, opts ...OptionFunc) (*DedicatedGuestVlanRange, int, error) { - p := &ListDedicatedGuestVlanRangesParams{} - p.p = make(map[string]interface{}) - - p.p["id"] = id - - for _, fn := range opts { - if err := fn(s.cs, p); err != nil { - return nil, -1, err - } - } - - l, err := s.ListDedicatedGuestVlanRanges(p) - if err != nil { - if strings.Contains(err.Error(), fmt.Sprintf( - "Invalid parameter id value=%s due to incorrect long value format, "+ - "or entity does not exist", id)) { - return nil, 0, fmt.Errorf("No match found for %s: %+v", id, l) - } - return nil, -1, err - } - - if l.Count == 0 { - return nil, l.Count, fmt.Errorf("No match found for %s: %+v", id, l) - } - - if l.Count == 1 { - return l.DedicatedGuestVlanRanges[0], l.Count, nil - } - return nil, l.Count, fmt.Errorf("There is more then one result for DedicatedGuestVlanRange UUID: %s!", id) -} - -// Lists dedicated guest vlan ranges -func (s *VLANService) ListDedicatedGuestVlanRanges(p *ListDedicatedGuestVlanRangesParams) (*ListDedicatedGuestVlanRangesResponse, error) { - resp, err := s.cs.newRequest("listDedicatedGuestVlanRanges", p.toURLValues()) - if err != nil { - return nil, err - } - - var r ListDedicatedGuestVlanRangesResponse - if err := json.Unmarshal(resp, &r); err != nil { - return nil, err - } - return &r, nil -} - -type ListDedicatedGuestVlanRangesResponse struct { - Count int `json:"count"` - DedicatedGuestVlanRanges []*DedicatedGuestVlanRange `json:"dedicatedguestvlanrange"` -} - -type DedicatedGuestVlanRange struct { - Account string `json:"account,omitempty"` - Domain string `json:"domain,omitempty"` - Domainid string `json:"domainid,omitempty"` - Guestvlanrange string `json:"guestvlanrange,omitempty"` - Id string `json:"id,omitempty"` - Physicalnetworkid int64 `json:"physicalnetworkid,omitempty"` - Project string `json:"project,omitempty"` - Projectid string `json:"projectid,omitempty"` - Zoneid int64 `json:"zoneid,omitempty"` + JobID string `json:"jobid"` + Displaytext string `json:"displaytext"` + Success bool `json:"success"` } diff --git a/vendor/github.com/xanzy/go-cloudstack/cloudstack/VMGroupService.go b/vendor/github.com/xanzy/go-cloudstack/cloudstack/VMGroupService.go index d66768447..83c32381c 100644 --- a/vendor/github.com/xanzy/go-cloudstack/cloudstack/VMGroupService.go +++ b/vendor/github.com/xanzy/go-cloudstack/cloudstack/VMGroupService.go @@ -1,5 +1,5 @@ // -// Copyright 2016, Sander van Harmelen +// Copyright 2018, Sander van Harmelen // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -100,18 +100,19 @@ func (s *VMGroupService) CreateInstanceGroup(p *CreateInstanceGroupParams) (*Cre if err := json.Unmarshal(resp, &r); err != nil { return nil, err } + return &r, nil } type CreateInstanceGroupResponse struct { - Account string `json:"account,omitempty"` - Created string `json:"created,omitempty"` - Domain string `json:"domain,omitempty"` - Domainid string `json:"domainid,omitempty"` - Id string `json:"id,omitempty"` - Name string `json:"name,omitempty"` - Project string `json:"project,omitempty"` - Projectid string `json:"projectid,omitempty"` + Account string `json:"account"` + Created string `json:"created"` + Domain string `json:"domain"` + Domainid string `json:"domainid"` + Id string `json:"id"` + Name string `json:"name"` + Project string `json:"project"` + Projectid string `json:"projectid"` } type DeleteInstanceGroupParams struct { @@ -157,80 +158,32 @@ func (s *VMGroupService) DeleteInstanceGroup(p *DeleteInstanceGroupParams) (*Del if err := json.Unmarshal(resp, &r); err != nil { return nil, err } + return &r, nil } type DeleteInstanceGroupResponse struct { - Displaytext string `json:"displaytext,omitempty"` - Success string `json:"success,omitempty"` + Displaytext string `json:"displaytext"` + Success bool `json:"success"` } -type UpdateInstanceGroupParams struct { - p map[string]interface{} -} - -func (p *UpdateInstanceGroupParams) toURLValues() url.Values { - u := url.Values{} - if p.p == nil { - return u - } - if v, found := p.p["id"]; found { - u.Set("id", v.(string)) - } - if v, found := p.p["name"]; found { - u.Set("name", v.(string)) - } - return u -} - -func (p *UpdateInstanceGroupParams) SetId(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["id"] = v - return -} - -func (p *UpdateInstanceGroupParams) SetName(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["name"] = v - return -} - -// You should always use this function to get a new UpdateInstanceGroupParams instance, -// as then you are sure you have configured all required params -func (s *VMGroupService) NewUpdateInstanceGroupParams(id string) *UpdateInstanceGroupParams { - p := &UpdateInstanceGroupParams{} - p.p = make(map[string]interface{}) - p.p["id"] = id - return p -} - -// Updates a vm group -func (s *VMGroupService) UpdateInstanceGroup(p *UpdateInstanceGroupParams) (*UpdateInstanceGroupResponse, error) { - resp, err := s.cs.newRequest("updateInstanceGroup", p.toURLValues()) +func (r *DeleteInstanceGroupResponse) UnmarshalJSON(b []byte) error { + var m map[string]interface{} + err := json.Unmarshal(b, &m) if err != nil { - return nil, err + return err } - var r UpdateInstanceGroupResponse - if err := json.Unmarshal(resp, &r); err != nil { - return nil, err + if success, ok := m["success"].(string); ok { + m["success"] = success == "true" + b, err = json.Marshal(m) + if err != nil { + return err + } } - return &r, nil -} -type UpdateInstanceGroupResponse struct { - Account string `json:"account,omitempty"` - Created string `json:"created,omitempty"` - Domain string `json:"domain,omitempty"` - Domainid string `json:"domainid,omitempty"` - Id string `json:"id,omitempty"` - Name string `json:"name,omitempty"` - Project string `json:"project,omitempty"` - Projectid string `json:"projectid,omitempty"` + type alias DeleteInstanceGroupResponse + return json.Unmarshal(b, (*alias)(r)) } type ListInstanceGroupsParams struct { @@ -374,7 +327,7 @@ func (s *VMGroupService) GetInstanceGroupID(name string, opts ...OptionFunc) (st p.p["name"] = name - for _, fn := range opts { + for _, fn := range append(s.cs.options, opts...) { if err := fn(s.cs, p); err != nil { return "", -1, err } @@ -424,7 +377,7 @@ func (s *VMGroupService) GetInstanceGroupByID(id string, opts ...OptionFunc) (*I p.p["id"] = id - for _, fn := range opts { + for _, fn := range append(s.cs.options, opts...) { if err := fn(s.cs, p); err != nil { return nil, -1, err } @@ -461,6 +414,7 @@ func (s *VMGroupService) ListInstanceGroups(p *ListInstanceGroupsParams) (*ListI if err := json.Unmarshal(resp, &r); err != nil { return nil, err } + return &r, nil } @@ -470,12 +424,81 @@ type ListInstanceGroupsResponse struct { } type InstanceGroup struct { - Account string `json:"account,omitempty"` - Created string `json:"created,omitempty"` - Domain string `json:"domain,omitempty"` - Domainid string `json:"domainid,omitempty"` - Id string `json:"id,omitempty"` - Name string `json:"name,omitempty"` - Project string `json:"project,omitempty"` - Projectid string `json:"projectid,omitempty"` + Account string `json:"account"` + Created string `json:"created"` + Domain string `json:"domain"` + Domainid string `json:"domainid"` + Id string `json:"id"` + Name string `json:"name"` + Project string `json:"project"` + Projectid string `json:"projectid"` +} + +type UpdateInstanceGroupParams struct { + p map[string]interface{} +} + +func (p *UpdateInstanceGroupParams) toURLValues() url.Values { + u := url.Values{} + if p.p == nil { + return u + } + if v, found := p.p["id"]; found { + u.Set("id", v.(string)) + } + if v, found := p.p["name"]; found { + u.Set("name", v.(string)) + } + return u +} + +func (p *UpdateInstanceGroupParams) SetId(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["id"] = v + return +} + +func (p *UpdateInstanceGroupParams) SetName(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["name"] = v + return +} + +// You should always use this function to get a new UpdateInstanceGroupParams instance, +// as then you are sure you have configured all required params +func (s *VMGroupService) NewUpdateInstanceGroupParams(id string) *UpdateInstanceGroupParams { + p := &UpdateInstanceGroupParams{} + p.p = make(map[string]interface{}) + p.p["id"] = id + return p +} + +// Updates a vm group +func (s *VMGroupService) UpdateInstanceGroup(p *UpdateInstanceGroupParams) (*UpdateInstanceGroupResponse, error) { + resp, err := s.cs.newRequest("updateInstanceGroup", p.toURLValues()) + if err != nil { + return nil, err + } + + var r UpdateInstanceGroupResponse + if err := json.Unmarshal(resp, &r); err != nil { + return nil, err + } + + return &r, nil +} + +type UpdateInstanceGroupResponse struct { + Account string `json:"account"` + Created string `json:"created"` + Domain string `json:"domain"` + Domainid string `json:"domainid"` + Id string `json:"id"` + Name string `json:"name"` + Project string `json:"project"` + Projectid string `json:"projectid"` } diff --git a/vendor/github.com/xanzy/go-cloudstack/cloudstack/VPCService.go b/vendor/github.com/xanzy/go-cloudstack/cloudstack/VPCService.go index 86d8a5948..149bb4fe5 100644 --- a/vendor/github.com/xanzy/go-cloudstack/cloudstack/VPCService.go +++ b/vendor/github.com/xanzy/go-cloudstack/cloudstack/VPCService.go @@ -1,5 +1,5 @@ // -// Copyright 2016, Sander van Harmelen +// Copyright 2018, Sander van Harmelen // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -24,6 +24,281 @@ import ( "strings" ) +type CreatePrivateGatewayParams struct { + p map[string]interface{} +} + +func (p *CreatePrivateGatewayParams) toURLValues() url.Values { + u := url.Values{} + if p.p == nil { + return u + } + if v, found := p.p["aclid"]; found { + u.Set("aclid", v.(string)) + } + if v, found := p.p["gateway"]; found { + u.Set("gateway", v.(string)) + } + if v, found := p.p["ipaddress"]; found { + u.Set("ipaddress", v.(string)) + } + if v, found := p.p["netmask"]; found { + u.Set("netmask", v.(string)) + } + if v, found := p.p["networkofferingid"]; found { + u.Set("networkofferingid", v.(string)) + } + if v, found := p.p["physicalnetworkid"]; found { + u.Set("physicalnetworkid", v.(string)) + } + if v, found := p.p["sourcenatsupported"]; found { + vv := strconv.FormatBool(v.(bool)) + u.Set("sourcenatsupported", vv) + } + if v, found := p.p["vlan"]; found { + u.Set("vlan", v.(string)) + } + if v, found := p.p["vpcid"]; found { + u.Set("vpcid", v.(string)) + } + return u +} + +func (p *CreatePrivateGatewayParams) SetAclid(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["aclid"] = v + return +} + +func (p *CreatePrivateGatewayParams) SetGateway(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["gateway"] = v + return +} + +func (p *CreatePrivateGatewayParams) SetIpaddress(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["ipaddress"] = v + return +} + +func (p *CreatePrivateGatewayParams) SetNetmask(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["netmask"] = v + return +} + +func (p *CreatePrivateGatewayParams) SetNetworkofferingid(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["networkofferingid"] = v + return +} + +func (p *CreatePrivateGatewayParams) SetPhysicalnetworkid(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["physicalnetworkid"] = v + return +} + +func (p *CreatePrivateGatewayParams) SetSourcenatsupported(v bool) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["sourcenatsupported"] = v + return +} + +func (p *CreatePrivateGatewayParams) SetVlan(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["vlan"] = v + return +} + +func (p *CreatePrivateGatewayParams) SetVpcid(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["vpcid"] = v + return +} + +// You should always use this function to get a new CreatePrivateGatewayParams instance, +// as then you are sure you have configured all required params +func (s *VPCService) NewCreatePrivateGatewayParams(gateway string, ipaddress string, netmask string, vlan string, vpcid string) *CreatePrivateGatewayParams { + p := &CreatePrivateGatewayParams{} + p.p = make(map[string]interface{}) + p.p["gateway"] = gateway + p.p["ipaddress"] = ipaddress + p.p["netmask"] = netmask + p.p["vlan"] = vlan + p.p["vpcid"] = vpcid + return p +} + +// Creates a private gateway +func (s *VPCService) CreatePrivateGateway(p *CreatePrivateGatewayParams) (*CreatePrivateGatewayResponse, error) { + resp, err := s.cs.newRequest("createPrivateGateway", p.toURLValues()) + if err != nil { + return nil, err + } + + var r CreatePrivateGatewayResponse + if err := json.Unmarshal(resp, &r); err != nil { + return nil, err + } + + // If we have a async client, we need to wait for the async result + if s.cs.async { + b, err := s.cs.GetAsyncJobResult(r.JobID, s.cs.timeout) + if err != nil { + if err == AsyncTimeoutErr { + return &r, err + } + return nil, err + } + + b, err = getRawValue(b) + if err != nil { + return nil, err + } + + if err := json.Unmarshal(b, &r); err != nil { + return nil, err + } + } + + return &r, nil +} + +type CreatePrivateGatewayResponse struct { + JobID string `json:"jobid"` + Account string `json:"account"` + Aclid string `json:"aclid"` + Domain string `json:"domain"` + Domainid string `json:"domainid"` + Gateway string `json:"gateway"` + Id string `json:"id"` + Ipaddress string `json:"ipaddress"` + Netmask string `json:"netmask"` + Physicalnetworkid string `json:"physicalnetworkid"` + Project string `json:"project"` + Projectid string `json:"projectid"` + Sourcenatsupported bool `json:"sourcenatsupported"` + State string `json:"state"` + Vlan string `json:"vlan"` + Vpcid string `json:"vpcid"` + Zoneid string `json:"zoneid"` + Zonename string `json:"zonename"` +} + +type CreateStaticRouteParams struct { + p map[string]interface{} +} + +func (p *CreateStaticRouteParams) toURLValues() url.Values { + u := url.Values{} + if p.p == nil { + return u + } + if v, found := p.p["cidr"]; found { + u.Set("cidr", v.(string)) + } + if v, found := p.p["gatewayid"]; found { + u.Set("gatewayid", v.(string)) + } + return u +} + +func (p *CreateStaticRouteParams) SetCidr(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["cidr"] = v + return +} + +func (p *CreateStaticRouteParams) SetGatewayid(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["gatewayid"] = v + return +} + +// You should always use this function to get a new CreateStaticRouteParams instance, +// as then you are sure you have configured all required params +func (s *VPCService) NewCreateStaticRouteParams(cidr string, gatewayid string) *CreateStaticRouteParams { + p := &CreateStaticRouteParams{} + p.p = make(map[string]interface{}) + p.p["cidr"] = cidr + p.p["gatewayid"] = gatewayid + return p +} + +// Creates a static route +func (s *VPCService) CreateStaticRoute(p *CreateStaticRouteParams) (*CreateStaticRouteResponse, error) { + resp, err := s.cs.newRequest("createStaticRoute", p.toURLValues()) + if err != nil { + return nil, err + } + + var r CreateStaticRouteResponse + if err := json.Unmarshal(resp, &r); err != nil { + return nil, err + } + + // If we have a async client, we need to wait for the async result + if s.cs.async { + b, err := s.cs.GetAsyncJobResult(r.JobID, s.cs.timeout) + if err != nil { + if err == AsyncTimeoutErr { + return &r, err + } + return nil, err + } + + b, err = getRawValue(b) + if err != nil { + return nil, err + } + + if err := json.Unmarshal(b, &r); err != nil { + return nil, err + } + } + + return &r, nil +} + +type CreateStaticRouteResponse struct { + JobID string `json:"jobid"` + Account string `json:"account"` + Cidr string `json:"cidr"` + Domain string `json:"domain"` + Domainid string `json:"domainid"` + Gatewayid string `json:"gatewayid"` + Id string `json:"id"` + Project string `json:"project"` + Projectid string `json:"projectid"` + State string `json:"state"` + Tags []Tags `json:"tags"` + Vpcid string `json:"vpcid"` +} + type CreateVPCParams struct { p map[string]interface{} } @@ -203,137 +478,1302 @@ func (s *VPCService) CreateVPC(p *CreateVPCParams) (*CreateVPCResponse, error) { return nil, err } } + return &r, nil } type CreateVPCResponse struct { - JobID string `json:"jobid,omitempty"` - Account string `json:"account,omitempty"` - Cidr string `json:"cidr,omitempty"` - Created string `json:"created,omitempty"` - Displaytext string `json:"displaytext,omitempty"` - Distributedvpcrouter bool `json:"distributedvpcrouter,omitempty"` - Domain string `json:"domain,omitempty"` - Domainid string `json:"domainid,omitempty"` - Fordisplay bool `json:"fordisplay,omitempty"` - Id string `json:"id,omitempty"` - Name string `json:"name,omitempty"` - Network []struct { - Account string `json:"account,omitempty"` - Aclid string `json:"aclid,omitempty"` - Acltype string `json:"acltype,omitempty"` - Broadcastdomaintype string `json:"broadcastdomaintype,omitempty"` - Broadcasturi string `json:"broadcasturi,omitempty"` - Canusefordeploy bool `json:"canusefordeploy,omitempty"` - Cidr string `json:"cidr,omitempty"` - Displaynetwork bool `json:"displaynetwork,omitempty"` - Displaytext string `json:"displaytext,omitempty"` - Dns1 string `json:"dns1,omitempty"` - Dns2 string `json:"dns2,omitempty"` - Domain string `json:"domain,omitempty"` - Domainid string `json:"domainid,omitempty"` - Gateway string `json:"gateway,omitempty"` - Id string `json:"id,omitempty"` - Ip6cidr string `json:"ip6cidr,omitempty"` - Ip6gateway string `json:"ip6gateway,omitempty"` - Isdefault bool `json:"isdefault,omitempty"` - Ispersistent bool `json:"ispersistent,omitempty"` - Issystem bool `json:"issystem,omitempty"` - Name string `json:"name,omitempty"` - Netmask string `json:"netmask,omitempty"` - Networkcidr string `json:"networkcidr,omitempty"` - Networkdomain string `json:"networkdomain,omitempty"` - Networkofferingavailability string `json:"networkofferingavailability,omitempty"` - Networkofferingconservemode bool `json:"networkofferingconservemode,omitempty"` - Networkofferingdisplaytext string `json:"networkofferingdisplaytext,omitempty"` - Networkofferingid string `json:"networkofferingid,omitempty"` - Networkofferingname string `json:"networkofferingname,omitempty"` - Physicalnetworkid string `json:"physicalnetworkid,omitempty"` - Project string `json:"project,omitempty"` - Projectid string `json:"projectid,omitempty"` - Related string `json:"related,omitempty"` - Reservediprange string `json:"reservediprange,omitempty"` - Restartrequired bool `json:"restartrequired,omitempty"` - Service []struct { - Capability []struct { - Canchooseservicecapability bool `json:"canchooseservicecapability,omitempty"` - Name string `json:"name,omitempty"` - Value string `json:"value,omitempty"` - } `json:"capability,omitempty"` - Name string `json:"name,omitempty"` - Provider []struct { - Canenableindividualservice bool `json:"canenableindividualservice,omitempty"` - Destinationphysicalnetworkid string `json:"destinationphysicalnetworkid,omitempty"` - Id string `json:"id,omitempty"` - Name string `json:"name,omitempty"` - Physicalnetworkid string `json:"physicalnetworkid,omitempty"` - Servicelist []string `json:"servicelist,omitempty"` - State string `json:"state,omitempty"` - } `json:"provider,omitempty"` - } `json:"service,omitempty"` - Specifyipranges bool `json:"specifyipranges,omitempty"` - State string `json:"state,omitempty"` - Strechedl2subnet bool `json:"strechedl2subnet,omitempty"` - Subdomainaccess bool `json:"subdomainaccess,omitempty"` - Tags []struct { - Account string `json:"account,omitempty"` - Customer string `json:"customer,omitempty"` - Domain string `json:"domain,omitempty"` - Domainid string `json:"domainid,omitempty"` - Key string `json:"key,omitempty"` - Project string `json:"project,omitempty"` - Projectid string `json:"projectid,omitempty"` - Resourceid string `json:"resourceid,omitempty"` - Resourcetype string `json:"resourcetype,omitempty"` - Value string `json:"value,omitempty"` - } `json:"tags,omitempty"` - Traffictype string `json:"traffictype,omitempty"` - Type string `json:"type,omitempty"` - Vlan string `json:"vlan,omitempty"` - Vpcid string `json:"vpcid,omitempty"` - Zoneid string `json:"zoneid,omitempty"` - Zonename string `json:"zonename,omitempty"` - Zonesnetworkspans []string `json:"zonesnetworkspans,omitempty"` - } `json:"network,omitempty"` - Networkdomain string `json:"networkdomain,omitempty"` - Project string `json:"project,omitempty"` - Projectid string `json:"projectid,omitempty"` - Redundantvpcrouter bool `json:"redundantvpcrouter,omitempty"` - Regionlevelvpc bool `json:"regionlevelvpc,omitempty"` - Restartrequired bool `json:"restartrequired,omitempty"` - Service []struct { - Capability []struct { - Canchooseservicecapability bool `json:"canchooseservicecapability,omitempty"` - Name string `json:"name,omitempty"` - Value string `json:"value,omitempty"` - } `json:"capability,omitempty"` - Name string `json:"name,omitempty"` - Provider []struct { - Canenableindividualservice bool `json:"canenableindividualservice,omitempty"` - Destinationphysicalnetworkid string `json:"destinationphysicalnetworkid,omitempty"` - Id string `json:"id,omitempty"` - Name string `json:"name,omitempty"` - Physicalnetworkid string `json:"physicalnetworkid,omitempty"` - Servicelist []string `json:"servicelist,omitempty"` - State string `json:"state,omitempty"` - } `json:"provider,omitempty"` - } `json:"service,omitempty"` - State string `json:"state,omitempty"` - Tags []struct { - Account string `json:"account,omitempty"` - Customer string `json:"customer,omitempty"` - Domain string `json:"domain,omitempty"` - Domainid string `json:"domainid,omitempty"` - Key string `json:"key,omitempty"` - Project string `json:"project,omitempty"` - Projectid string `json:"projectid,omitempty"` - Resourceid string `json:"resourceid,omitempty"` - Resourcetype string `json:"resourcetype,omitempty"` - Value string `json:"value,omitempty"` - } `json:"tags,omitempty"` - Vpcofferingid string `json:"vpcofferingid,omitempty"` - Zoneid string `json:"zoneid,omitempty"` - Zonename string `json:"zonename,omitempty"` + JobID string `json:"jobid"` + Account string `json:"account"` + Cidr string `json:"cidr"` + Created string `json:"created"` + Displaytext string `json:"displaytext"` + Distributedvpcrouter bool `json:"distributedvpcrouter"` + Domain string `json:"domain"` + Domainid string `json:"domainid"` + Fordisplay bool `json:"fordisplay"` + Id string `json:"id"` + Name string `json:"name"` + Network []CreateVPCResponseNetwork `json:"network"` + Networkdomain string `json:"networkdomain"` + Project string `json:"project"` + Projectid string `json:"projectid"` + Redundantvpcrouter bool `json:"redundantvpcrouter"` + Regionlevelvpc bool `json:"regionlevelvpc"` + Restartrequired bool `json:"restartrequired"` + Service []CreateVPCResponseService `json:"service"` + State string `json:"state"` + Tags []Tags `json:"tags"` + Vpcofferingid string `json:"vpcofferingid"` + Zoneid string `json:"zoneid"` + Zonename string `json:"zonename"` +} + +type CreateVPCResponseService struct { + Capability []CreateVPCResponseServiceCapability `json:"capability"` + Name string `json:"name"` + Provider []CreateVPCResponseServiceProvider `json:"provider"` +} + +type CreateVPCResponseServiceProvider struct { + Canenableindividualservice bool `json:"canenableindividualservice"` + Destinationphysicalnetworkid string `json:"destinationphysicalnetworkid"` + Id string `json:"id"` + Name string `json:"name"` + Physicalnetworkid string `json:"physicalnetworkid"` + Servicelist []string `json:"servicelist"` + State string `json:"state"` +} + +type CreateVPCResponseServiceCapability struct { + Canchooseservicecapability bool `json:"canchooseservicecapability"` + Name string `json:"name"` + Value string `json:"value"` +} + +type CreateVPCResponseNetwork struct { + Account string `json:"account"` + Aclid string `json:"aclid"` + Acltype string `json:"acltype"` + Broadcastdomaintype string `json:"broadcastdomaintype"` + Broadcasturi string `json:"broadcasturi"` + Canusefordeploy bool `json:"canusefordeploy"` + Cidr string `json:"cidr"` + Displaynetwork bool `json:"displaynetwork"` + Displaytext string `json:"displaytext"` + Dns1 string `json:"dns1"` + Dns2 string `json:"dns2"` + Domain string `json:"domain"` + Domainid string `json:"domainid"` + Externalid string `json:"externalid"` + Gateway string `json:"gateway"` + Id string `json:"id"` + Ip6cidr string `json:"ip6cidr"` + Ip6gateway string `json:"ip6gateway"` + Isdefault bool `json:"isdefault"` + Ispersistent bool `json:"ispersistent"` + Issystem bool `json:"issystem"` + Name string `json:"name"` + Netmask string `json:"netmask"` + Networkcidr string `json:"networkcidr"` + Networkdomain string `json:"networkdomain"` + Networkofferingavailability string `json:"networkofferingavailability"` + Networkofferingconservemode bool `json:"networkofferingconservemode"` + Networkofferingdisplaytext string `json:"networkofferingdisplaytext"` + Networkofferingid string `json:"networkofferingid"` + Networkofferingname string `json:"networkofferingname"` + Physicalnetworkid string `json:"physicalnetworkid"` + Project string `json:"project"` + Projectid string `json:"projectid"` + Redundantrouter bool `json:"redundantrouter"` + Related string `json:"related"` + Reservediprange string `json:"reservediprange"` + Restartrequired bool `json:"restartrequired"` + Service []CreateVPCResponseNetworkService `json:"service"` + Specifyipranges bool `json:"specifyipranges"` + State string `json:"state"` + Strechedl2subnet bool `json:"strechedl2subnet"` + Subdomainaccess bool `json:"subdomainaccess"` + Tags []Tags `json:"tags"` + Traffictype string `json:"traffictype"` + Type string `json:"type"` + Vlan string `json:"vlan"` + Vpcid string `json:"vpcid"` + Zoneid string `json:"zoneid"` + Zonename string `json:"zonename"` + Zonesnetworkspans []interface{} `json:"zonesnetworkspans"` +} + +type CreateVPCResponseNetworkService struct { + Capability []CreateVPCResponseNetworkServiceCapability `json:"capability"` + Name string `json:"name"` + Provider []CreateVPCResponseNetworkServiceProvider `json:"provider"` +} + +type CreateVPCResponseNetworkServiceProvider struct { + Canenableindividualservice bool `json:"canenableindividualservice"` + Destinationphysicalnetworkid string `json:"destinationphysicalnetworkid"` + Id string `json:"id"` + Name string `json:"name"` + Physicalnetworkid string `json:"physicalnetworkid"` + Servicelist []string `json:"servicelist"` + State string `json:"state"` +} + +type CreateVPCResponseNetworkServiceCapability struct { + Canchooseservicecapability bool `json:"canchooseservicecapability"` + Name string `json:"name"` + Value string `json:"value"` +} + +type CreateVPCOfferingParams struct { + p map[string]interface{} +} + +func (p *CreateVPCOfferingParams) toURLValues() url.Values { + u := url.Values{} + if p.p == nil { + return u + } + if v, found := p.p["displaytext"]; found { + u.Set("displaytext", v.(string)) + } + if v, found := p.p["name"]; found { + u.Set("name", v.(string)) + } + if v, found := p.p["servicecapabilitylist"]; found { + i := 0 + for k, vv := range v.(map[string]string) { + u.Set(fmt.Sprintf("servicecapabilitylist[%d].key", i), k) + u.Set(fmt.Sprintf("servicecapabilitylist[%d].value", i), vv) + i++ + } + } + if v, found := p.p["serviceofferingid"]; found { + u.Set("serviceofferingid", v.(string)) + } + if v, found := p.p["serviceproviderlist"]; found { + i := 0 + for k, vv := range v.(map[string]string) { + u.Set(fmt.Sprintf("serviceproviderlist[%d].service", i), k) + u.Set(fmt.Sprintf("serviceproviderlist[%d].provider", i), vv) + i++ + } + } + if v, found := p.p["supportedservices"]; found { + vv := strings.Join(v.([]string), ",") + u.Set("supportedservices", vv) + } + return u +} + +func (p *CreateVPCOfferingParams) SetDisplaytext(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["displaytext"] = v + return +} + +func (p *CreateVPCOfferingParams) SetName(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["name"] = v + return +} + +func (p *CreateVPCOfferingParams) SetServicecapabilitylist(v map[string]string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["servicecapabilitylist"] = v + return +} + +func (p *CreateVPCOfferingParams) SetServiceofferingid(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["serviceofferingid"] = v + return +} + +func (p *CreateVPCOfferingParams) SetServiceproviderlist(v map[string]string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["serviceproviderlist"] = v + return +} + +func (p *CreateVPCOfferingParams) SetSupportedservices(v []string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["supportedservices"] = v + return +} + +// You should always use this function to get a new CreateVPCOfferingParams instance, +// as then you are sure you have configured all required params +func (s *VPCService) NewCreateVPCOfferingParams(displaytext string, name string, supportedservices []string) *CreateVPCOfferingParams { + p := &CreateVPCOfferingParams{} + p.p = make(map[string]interface{}) + p.p["displaytext"] = displaytext + p.p["name"] = name + p.p["supportedservices"] = supportedservices + return p +} + +// Creates VPC offering +func (s *VPCService) CreateVPCOffering(p *CreateVPCOfferingParams) (*CreateVPCOfferingResponse, error) { + resp, err := s.cs.newRequest("createVPCOffering", p.toURLValues()) + if err != nil { + return nil, err + } + + var r CreateVPCOfferingResponse + if err := json.Unmarshal(resp, &r); err != nil { + return nil, err + } + + // If we have a async client, we need to wait for the async result + if s.cs.async { + b, err := s.cs.GetAsyncJobResult(r.JobID, s.cs.timeout) + if err != nil { + if err == AsyncTimeoutErr { + return &r, err + } + return nil, err + } + + b, err = getRawValue(b) + if err != nil { + return nil, err + } + + if err := json.Unmarshal(b, &r); err != nil { + return nil, err + } + } + + return &r, nil +} + +type CreateVPCOfferingResponse struct { + JobID string `json:"jobid"` + Created string `json:"created"` + Displaytext string `json:"displaytext"` + Distributedvpcrouter bool `json:"distributedvpcrouter"` + Id string `json:"id"` + Isdefault bool `json:"isdefault"` + Name string `json:"name"` + Service []CreateVPCOfferingResponseService `json:"service"` + State string `json:"state"` + SupportsregionLevelvpc bool `json:"supportsregionLevelvpc"` +} + +type CreateVPCOfferingResponseService struct { + Capability []CreateVPCOfferingResponseServiceCapability `json:"capability"` + Name string `json:"name"` + Provider []CreateVPCOfferingResponseServiceProvider `json:"provider"` +} + +type CreateVPCOfferingResponseServiceProvider struct { + Canenableindividualservice bool `json:"canenableindividualservice"` + Destinationphysicalnetworkid string `json:"destinationphysicalnetworkid"` + Id string `json:"id"` + Name string `json:"name"` + Physicalnetworkid string `json:"physicalnetworkid"` + Servicelist []string `json:"servicelist"` + State string `json:"state"` +} + +type CreateVPCOfferingResponseServiceCapability struct { + Canchooseservicecapability bool `json:"canchooseservicecapability"` + Name string `json:"name"` + Value string `json:"value"` +} + +type DeletePrivateGatewayParams struct { + p map[string]interface{} +} + +func (p *DeletePrivateGatewayParams) toURLValues() url.Values { + u := url.Values{} + if p.p == nil { + return u + } + if v, found := p.p["id"]; found { + u.Set("id", v.(string)) + } + return u +} + +func (p *DeletePrivateGatewayParams) SetId(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["id"] = v + return +} + +// You should always use this function to get a new DeletePrivateGatewayParams instance, +// as then you are sure you have configured all required params +func (s *VPCService) NewDeletePrivateGatewayParams(id string) *DeletePrivateGatewayParams { + p := &DeletePrivateGatewayParams{} + p.p = make(map[string]interface{}) + p.p["id"] = id + return p +} + +// Deletes a Private gateway +func (s *VPCService) DeletePrivateGateway(p *DeletePrivateGatewayParams) (*DeletePrivateGatewayResponse, error) { + resp, err := s.cs.newRequest("deletePrivateGateway", p.toURLValues()) + if err != nil { + return nil, err + } + + var r DeletePrivateGatewayResponse + if err := json.Unmarshal(resp, &r); err != nil { + return nil, err + } + + // If we have a async client, we need to wait for the async result + if s.cs.async { + b, err := s.cs.GetAsyncJobResult(r.JobID, s.cs.timeout) + if err != nil { + if err == AsyncTimeoutErr { + return &r, err + } + return nil, err + } + + if err := json.Unmarshal(b, &r); err != nil { + return nil, err + } + } + + return &r, nil +} + +type DeletePrivateGatewayResponse struct { + JobID string `json:"jobid"` + Displaytext string `json:"displaytext"` + Success bool `json:"success"` +} + +type DeleteStaticRouteParams struct { + p map[string]interface{} +} + +func (p *DeleteStaticRouteParams) toURLValues() url.Values { + u := url.Values{} + if p.p == nil { + return u + } + if v, found := p.p["id"]; found { + u.Set("id", v.(string)) + } + return u +} + +func (p *DeleteStaticRouteParams) SetId(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["id"] = v + return +} + +// You should always use this function to get a new DeleteStaticRouteParams instance, +// as then you are sure you have configured all required params +func (s *VPCService) NewDeleteStaticRouteParams(id string) *DeleteStaticRouteParams { + p := &DeleteStaticRouteParams{} + p.p = make(map[string]interface{}) + p.p["id"] = id + return p +} + +// Deletes a static route +func (s *VPCService) DeleteStaticRoute(p *DeleteStaticRouteParams) (*DeleteStaticRouteResponse, error) { + resp, err := s.cs.newRequest("deleteStaticRoute", p.toURLValues()) + if err != nil { + return nil, err + } + + var r DeleteStaticRouteResponse + if err := json.Unmarshal(resp, &r); err != nil { + return nil, err + } + + // If we have a async client, we need to wait for the async result + if s.cs.async { + b, err := s.cs.GetAsyncJobResult(r.JobID, s.cs.timeout) + if err != nil { + if err == AsyncTimeoutErr { + return &r, err + } + return nil, err + } + + if err := json.Unmarshal(b, &r); err != nil { + return nil, err + } + } + + return &r, nil +} + +type DeleteStaticRouteResponse struct { + JobID string `json:"jobid"` + Displaytext string `json:"displaytext"` + Success bool `json:"success"` +} + +type DeleteVPCParams struct { + p map[string]interface{} +} + +func (p *DeleteVPCParams) toURLValues() url.Values { + u := url.Values{} + if p.p == nil { + return u + } + if v, found := p.p["id"]; found { + u.Set("id", v.(string)) + } + return u +} + +func (p *DeleteVPCParams) SetId(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["id"] = v + return +} + +// You should always use this function to get a new DeleteVPCParams instance, +// as then you are sure you have configured all required params +func (s *VPCService) NewDeleteVPCParams(id string) *DeleteVPCParams { + p := &DeleteVPCParams{} + p.p = make(map[string]interface{}) + p.p["id"] = id + return p +} + +// Deletes a VPC +func (s *VPCService) DeleteVPC(p *DeleteVPCParams) (*DeleteVPCResponse, error) { + resp, err := s.cs.newRequest("deleteVPC", p.toURLValues()) + if err != nil { + return nil, err + } + + var r DeleteVPCResponse + if err := json.Unmarshal(resp, &r); err != nil { + return nil, err + } + + // If we have a async client, we need to wait for the async result + if s.cs.async { + b, err := s.cs.GetAsyncJobResult(r.JobID, s.cs.timeout) + if err != nil { + if err == AsyncTimeoutErr { + return &r, err + } + return nil, err + } + + if err := json.Unmarshal(b, &r); err != nil { + return nil, err + } + } + + return &r, nil +} + +type DeleteVPCResponse struct { + JobID string `json:"jobid"` + Displaytext string `json:"displaytext"` + Success bool `json:"success"` +} + +type DeleteVPCOfferingParams struct { + p map[string]interface{} +} + +func (p *DeleteVPCOfferingParams) toURLValues() url.Values { + u := url.Values{} + if p.p == nil { + return u + } + if v, found := p.p["id"]; found { + u.Set("id", v.(string)) + } + return u +} + +func (p *DeleteVPCOfferingParams) SetId(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["id"] = v + return +} + +// You should always use this function to get a new DeleteVPCOfferingParams instance, +// as then you are sure you have configured all required params +func (s *VPCService) NewDeleteVPCOfferingParams(id string) *DeleteVPCOfferingParams { + p := &DeleteVPCOfferingParams{} + p.p = make(map[string]interface{}) + p.p["id"] = id + return p +} + +// Deletes VPC offering +func (s *VPCService) DeleteVPCOffering(p *DeleteVPCOfferingParams) (*DeleteVPCOfferingResponse, error) { + resp, err := s.cs.newRequest("deleteVPCOffering", p.toURLValues()) + if err != nil { + return nil, err + } + + var r DeleteVPCOfferingResponse + if err := json.Unmarshal(resp, &r); err != nil { + return nil, err + } + + // If we have a async client, we need to wait for the async result + if s.cs.async { + b, err := s.cs.GetAsyncJobResult(r.JobID, s.cs.timeout) + if err != nil { + if err == AsyncTimeoutErr { + return &r, err + } + return nil, err + } + + if err := json.Unmarshal(b, &r); err != nil { + return nil, err + } + } + + return &r, nil +} + +type DeleteVPCOfferingResponse struct { + JobID string `json:"jobid"` + Displaytext string `json:"displaytext"` + Success bool `json:"success"` +} + +type ListPrivateGatewaysParams struct { + p map[string]interface{} +} + +func (p *ListPrivateGatewaysParams) toURLValues() url.Values { + u := url.Values{} + if p.p == nil { + return u + } + if v, found := p.p["account"]; found { + u.Set("account", v.(string)) + } + if v, found := p.p["domainid"]; found { + u.Set("domainid", v.(string)) + } + if v, found := p.p["id"]; found { + u.Set("id", v.(string)) + } + if v, found := p.p["ipaddress"]; found { + u.Set("ipaddress", v.(string)) + } + if v, found := p.p["isrecursive"]; found { + vv := strconv.FormatBool(v.(bool)) + u.Set("isrecursive", vv) + } + if v, found := p.p["keyword"]; found { + u.Set("keyword", v.(string)) + } + if v, found := p.p["listall"]; found { + vv := strconv.FormatBool(v.(bool)) + u.Set("listall", vv) + } + if v, found := p.p["page"]; found { + vv := strconv.Itoa(v.(int)) + u.Set("page", vv) + } + if v, found := p.p["pagesize"]; found { + vv := strconv.Itoa(v.(int)) + u.Set("pagesize", vv) + } + if v, found := p.p["projectid"]; found { + u.Set("projectid", v.(string)) + } + if v, found := p.p["state"]; found { + u.Set("state", v.(string)) + } + if v, found := p.p["vlan"]; found { + u.Set("vlan", v.(string)) + } + if v, found := p.p["vpcid"]; found { + u.Set("vpcid", v.(string)) + } + return u +} + +func (p *ListPrivateGatewaysParams) SetAccount(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["account"] = v + return +} + +func (p *ListPrivateGatewaysParams) SetDomainid(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["domainid"] = v + return +} + +func (p *ListPrivateGatewaysParams) SetId(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["id"] = v + return +} + +func (p *ListPrivateGatewaysParams) SetIpaddress(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["ipaddress"] = v + return +} + +func (p *ListPrivateGatewaysParams) SetIsrecursive(v bool) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["isrecursive"] = v + return +} + +func (p *ListPrivateGatewaysParams) SetKeyword(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["keyword"] = v + return +} + +func (p *ListPrivateGatewaysParams) SetListall(v bool) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["listall"] = v + return +} + +func (p *ListPrivateGatewaysParams) SetPage(v int) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["page"] = v + return +} + +func (p *ListPrivateGatewaysParams) SetPagesize(v int) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["pagesize"] = v + return +} + +func (p *ListPrivateGatewaysParams) SetProjectid(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["projectid"] = v + return +} + +func (p *ListPrivateGatewaysParams) SetState(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["state"] = v + return +} + +func (p *ListPrivateGatewaysParams) SetVlan(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["vlan"] = v + return +} + +func (p *ListPrivateGatewaysParams) SetVpcid(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["vpcid"] = v + return +} + +// You should always use this function to get a new ListPrivateGatewaysParams instance, +// as then you are sure you have configured all required params +func (s *VPCService) NewListPrivateGatewaysParams() *ListPrivateGatewaysParams { + p := &ListPrivateGatewaysParams{} + p.p = make(map[string]interface{}) + return p +} + +// This is a courtesy helper function, which in some cases may not work as expected! +func (s *VPCService) GetPrivateGatewayByID(id string, opts ...OptionFunc) (*PrivateGateway, int, error) { + p := &ListPrivateGatewaysParams{} + p.p = make(map[string]interface{}) + + p.p["id"] = id + + for _, fn := range append(s.cs.options, opts...) { + if err := fn(s.cs, p); err != nil { + return nil, -1, err + } + } + + l, err := s.ListPrivateGateways(p) + if err != nil { + if strings.Contains(err.Error(), fmt.Sprintf( + "Invalid parameter id value=%s due to incorrect long value format, "+ + "or entity does not exist", id)) { + return nil, 0, fmt.Errorf("No match found for %s: %+v", id, l) + } + return nil, -1, err + } + + if l.Count == 0 { + return nil, l.Count, fmt.Errorf("No match found for %s: %+v", id, l) + } + + if l.Count == 1 { + return l.PrivateGateways[0], l.Count, nil + } + return nil, l.Count, fmt.Errorf("There is more then one result for PrivateGateway UUID: %s!", id) +} + +// List private gateways +func (s *VPCService) ListPrivateGateways(p *ListPrivateGatewaysParams) (*ListPrivateGatewaysResponse, error) { + resp, err := s.cs.newRequest("listPrivateGateways", p.toURLValues()) + if err != nil { + return nil, err + } + + var r ListPrivateGatewaysResponse + if err := json.Unmarshal(resp, &r); err != nil { + return nil, err + } + + return &r, nil +} + +type ListPrivateGatewaysResponse struct { + Count int `json:"count"` + PrivateGateways []*PrivateGateway `json:"privategateway"` +} + +type PrivateGateway struct { + Account string `json:"account"` + Aclid string `json:"aclid"` + Domain string `json:"domain"` + Domainid string `json:"domainid"` + Gateway string `json:"gateway"` + Id string `json:"id"` + Ipaddress string `json:"ipaddress"` + Netmask string `json:"netmask"` + Physicalnetworkid string `json:"physicalnetworkid"` + Project string `json:"project"` + Projectid string `json:"projectid"` + Sourcenatsupported bool `json:"sourcenatsupported"` + State string `json:"state"` + Vlan string `json:"vlan"` + Vpcid string `json:"vpcid"` + Zoneid string `json:"zoneid"` + Zonename string `json:"zonename"` +} + +type ListStaticRoutesParams struct { + p map[string]interface{} +} + +func (p *ListStaticRoutesParams) toURLValues() url.Values { + u := url.Values{} + if p.p == nil { + return u + } + if v, found := p.p["account"]; found { + u.Set("account", v.(string)) + } + if v, found := p.p["domainid"]; found { + u.Set("domainid", v.(string)) + } + if v, found := p.p["gatewayid"]; found { + u.Set("gatewayid", v.(string)) + } + if v, found := p.p["id"]; found { + u.Set("id", v.(string)) + } + if v, found := p.p["isrecursive"]; found { + vv := strconv.FormatBool(v.(bool)) + u.Set("isrecursive", vv) + } + if v, found := p.p["keyword"]; found { + u.Set("keyword", v.(string)) + } + if v, found := p.p["listall"]; found { + vv := strconv.FormatBool(v.(bool)) + u.Set("listall", vv) + } + if v, found := p.p["page"]; found { + vv := strconv.Itoa(v.(int)) + u.Set("page", vv) + } + if v, found := p.p["pagesize"]; found { + vv := strconv.Itoa(v.(int)) + u.Set("pagesize", vv) + } + if v, found := p.p["projectid"]; found { + u.Set("projectid", v.(string)) + } + if v, found := p.p["tags"]; found { + i := 0 + for k, vv := range v.(map[string]string) { + u.Set(fmt.Sprintf("tags[%d].key", i), k) + u.Set(fmt.Sprintf("tags[%d].value", i), vv) + i++ + } + } + if v, found := p.p["vpcid"]; found { + u.Set("vpcid", v.(string)) + } + return u +} + +func (p *ListStaticRoutesParams) SetAccount(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["account"] = v + return +} + +func (p *ListStaticRoutesParams) SetDomainid(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["domainid"] = v + return +} + +func (p *ListStaticRoutesParams) SetGatewayid(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["gatewayid"] = v + return +} + +func (p *ListStaticRoutesParams) SetId(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["id"] = v + return +} + +func (p *ListStaticRoutesParams) SetIsrecursive(v bool) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["isrecursive"] = v + return +} + +func (p *ListStaticRoutesParams) SetKeyword(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["keyword"] = v + return +} + +func (p *ListStaticRoutesParams) SetListall(v bool) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["listall"] = v + return +} + +func (p *ListStaticRoutesParams) SetPage(v int) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["page"] = v + return +} + +func (p *ListStaticRoutesParams) SetPagesize(v int) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["pagesize"] = v + return +} + +func (p *ListStaticRoutesParams) SetProjectid(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["projectid"] = v + return +} + +func (p *ListStaticRoutesParams) SetTags(v map[string]string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["tags"] = v + return +} + +func (p *ListStaticRoutesParams) SetVpcid(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["vpcid"] = v + return +} + +// You should always use this function to get a new ListStaticRoutesParams instance, +// as then you are sure you have configured all required params +func (s *VPCService) NewListStaticRoutesParams() *ListStaticRoutesParams { + p := &ListStaticRoutesParams{} + p.p = make(map[string]interface{}) + return p +} + +// This is a courtesy helper function, which in some cases may not work as expected! +func (s *VPCService) GetStaticRouteByID(id string, opts ...OptionFunc) (*StaticRoute, int, error) { + p := &ListStaticRoutesParams{} + p.p = make(map[string]interface{}) + + p.p["id"] = id + + for _, fn := range append(s.cs.options, opts...) { + if err := fn(s.cs, p); err != nil { + return nil, -1, err + } + } + + l, err := s.ListStaticRoutes(p) + if err != nil { + if strings.Contains(err.Error(), fmt.Sprintf( + "Invalid parameter id value=%s due to incorrect long value format, "+ + "or entity does not exist", id)) { + return nil, 0, fmt.Errorf("No match found for %s: %+v", id, l) + } + return nil, -1, err + } + + if l.Count == 0 { + return nil, l.Count, fmt.Errorf("No match found for %s: %+v", id, l) + } + + if l.Count == 1 { + return l.StaticRoutes[0], l.Count, nil + } + return nil, l.Count, fmt.Errorf("There is more then one result for StaticRoute UUID: %s!", id) +} + +// Lists all static routes +func (s *VPCService) ListStaticRoutes(p *ListStaticRoutesParams) (*ListStaticRoutesResponse, error) { + resp, err := s.cs.newRequest("listStaticRoutes", p.toURLValues()) + if err != nil { + return nil, err + } + + var r ListStaticRoutesResponse + if err := json.Unmarshal(resp, &r); err != nil { + return nil, err + } + + return &r, nil +} + +type ListStaticRoutesResponse struct { + Count int `json:"count"` + StaticRoutes []*StaticRoute `json:"staticroute"` +} + +type StaticRoute struct { + Account string `json:"account"` + Cidr string `json:"cidr"` + Domain string `json:"domain"` + Domainid string `json:"domainid"` + Gatewayid string `json:"gatewayid"` + Id string `json:"id"` + Project string `json:"project"` + Projectid string `json:"projectid"` + State string `json:"state"` + Tags []Tags `json:"tags"` + Vpcid string `json:"vpcid"` +} + +type ListVPCOfferingsParams struct { + p map[string]interface{} +} + +func (p *ListVPCOfferingsParams) toURLValues() url.Values { + u := url.Values{} + if p.p == nil { + return u + } + if v, found := p.p["displaytext"]; found { + u.Set("displaytext", v.(string)) + } + if v, found := p.p["id"]; found { + u.Set("id", v.(string)) + } + if v, found := p.p["isdefault"]; found { + vv := strconv.FormatBool(v.(bool)) + u.Set("isdefault", vv) + } + if v, found := p.p["keyword"]; found { + u.Set("keyword", v.(string)) + } + if v, found := p.p["name"]; found { + u.Set("name", v.(string)) + } + if v, found := p.p["page"]; found { + vv := strconv.Itoa(v.(int)) + u.Set("page", vv) + } + if v, found := p.p["pagesize"]; found { + vv := strconv.Itoa(v.(int)) + u.Set("pagesize", vv) + } + if v, found := p.p["state"]; found { + u.Set("state", v.(string)) + } + if v, found := p.p["supportedservices"]; found { + vv := strings.Join(v.([]string), ",") + u.Set("supportedservices", vv) + } + return u +} + +func (p *ListVPCOfferingsParams) SetDisplaytext(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["displaytext"] = v + return +} + +func (p *ListVPCOfferingsParams) SetId(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["id"] = v + return +} + +func (p *ListVPCOfferingsParams) SetIsdefault(v bool) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["isdefault"] = v + return +} + +func (p *ListVPCOfferingsParams) SetKeyword(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["keyword"] = v + return +} + +func (p *ListVPCOfferingsParams) SetName(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["name"] = v + return +} + +func (p *ListVPCOfferingsParams) SetPage(v int) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["page"] = v + return +} + +func (p *ListVPCOfferingsParams) SetPagesize(v int) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["pagesize"] = v + return +} + +func (p *ListVPCOfferingsParams) SetState(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["state"] = v + return +} + +func (p *ListVPCOfferingsParams) SetSupportedservices(v []string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["supportedservices"] = v + return +} + +// You should always use this function to get a new ListVPCOfferingsParams instance, +// as then you are sure you have configured all required params +func (s *VPCService) NewListVPCOfferingsParams() *ListVPCOfferingsParams { + p := &ListVPCOfferingsParams{} + p.p = make(map[string]interface{}) + return p +} + +// This is a courtesy helper function, which in some cases may not work as expected! +func (s *VPCService) GetVPCOfferingID(name string, opts ...OptionFunc) (string, int, error) { + p := &ListVPCOfferingsParams{} + p.p = make(map[string]interface{}) + + p.p["name"] = name + + for _, fn := range append(s.cs.options, opts...) { + if err := fn(s.cs, p); err != nil { + return "", -1, err + } + } + + l, err := s.ListVPCOfferings(p) + if err != nil { + return "", -1, err + } + + if l.Count == 0 { + return "", l.Count, fmt.Errorf("No match found for %s: %+v", name, l) + } + + if l.Count == 1 { + return l.VPCOfferings[0].Id, l.Count, nil + } + + if l.Count > 1 { + for _, v := range l.VPCOfferings { + if v.Name == name { + return v.Id, l.Count, nil + } + } + } + return "", l.Count, fmt.Errorf("Could not find an exact match for %s: %+v", name, l) +} + +// This is a courtesy helper function, which in some cases may not work as expected! +func (s *VPCService) GetVPCOfferingByName(name string, opts ...OptionFunc) (*VPCOffering, int, error) { + id, count, err := s.GetVPCOfferingID(name, opts...) + if err != nil { + return nil, count, err + } + + r, count, err := s.GetVPCOfferingByID(id, opts...) + if err != nil { + return nil, count, err + } + return r, count, nil +} + +// This is a courtesy helper function, which in some cases may not work as expected! +func (s *VPCService) GetVPCOfferingByID(id string, opts ...OptionFunc) (*VPCOffering, int, error) { + p := &ListVPCOfferingsParams{} + p.p = make(map[string]interface{}) + + p.p["id"] = id + + for _, fn := range append(s.cs.options, opts...) { + if err := fn(s.cs, p); err != nil { + return nil, -1, err + } + } + + l, err := s.ListVPCOfferings(p) + if err != nil { + if strings.Contains(err.Error(), fmt.Sprintf( + "Invalid parameter id value=%s due to incorrect long value format, "+ + "or entity does not exist", id)) { + return nil, 0, fmt.Errorf("No match found for %s: %+v", id, l) + } + return nil, -1, err + } + + if l.Count == 0 { + return nil, l.Count, fmt.Errorf("No match found for %s: %+v", id, l) + } + + if l.Count == 1 { + return l.VPCOfferings[0], l.Count, nil + } + return nil, l.Count, fmt.Errorf("There is more then one result for VPCOffering UUID: %s!", id) +} + +// Lists VPC offerings +func (s *VPCService) ListVPCOfferings(p *ListVPCOfferingsParams) (*ListVPCOfferingsResponse, error) { + resp, err := s.cs.newRequest("listVPCOfferings", p.toURLValues()) + if err != nil { + return nil, err + } + + var r ListVPCOfferingsResponse + if err := json.Unmarshal(resp, &r); err != nil { + return nil, err + } + + return &r, nil +} + +type ListVPCOfferingsResponse struct { + Count int `json:"count"` + VPCOfferings []*VPCOffering `json:"vpcoffering"` +} + +type VPCOffering struct { + Created string `json:"created"` + Displaytext string `json:"displaytext"` + Distributedvpcrouter bool `json:"distributedvpcrouter"` + Id string `json:"id"` + Isdefault bool `json:"isdefault"` + Name string `json:"name"` + Service []VPCOfferingService `json:"service"` + State string `json:"state"` + SupportsregionLevelvpc bool `json:"supportsregionLevelvpc"` +} + +type VPCOfferingService struct { + Capability []VPCOfferingServiceCapability `json:"capability"` + Name string `json:"name"` + Provider []VPCOfferingServiceProvider `json:"provider"` +} + +type VPCOfferingServiceProvider struct { + Canenableindividualservice bool `json:"canenableindividualservice"` + Destinationphysicalnetworkid string `json:"destinationphysicalnetworkid"` + Id string `json:"id"` + Name string `json:"name"` + Physicalnetworkid string `json:"physicalnetworkid"` + Servicelist []string `json:"servicelist"` + State string `json:"state"` +} + +type VPCOfferingServiceCapability struct { + Canchooseservicecapability bool `json:"canchooseservicecapability"` + Name string `json:"name"` + Value string `json:"value"` } type ListVPCsParams struct { @@ -584,7 +2024,7 @@ func (s *VPCService) GetVPCID(name string, opts ...OptionFunc) (string, int, err p.p["name"] = name - for _, fn := range opts { + for _, fn := range append(s.cs.options, opts...) { if err := fn(s.cs, p); err != nil { return "", -1, err } @@ -634,7 +2074,7 @@ func (s *VPCService) GetVPCByID(id string, opts ...OptionFunc) (*VPC, int, error p.p["id"] = id - for _, fn := range opts { + for _, fn := range append(s.cs.options, opts...) { if err := fn(s.cs, p); err != nil { return nil, -1, err } @@ -671,6 +2111,7 @@ func (s *VPCService) ListVPCs(p *ListVPCsParams) (*ListVPCsResponse, error) { if err := json.Unmarshal(resp, &r); err != nil { return nil, err } + return &r, nil } @@ -680,150 +2121,160 @@ type ListVPCsResponse struct { } type VPC struct { - Account string `json:"account,omitempty"` - Cidr string `json:"cidr,omitempty"` - Created string `json:"created,omitempty"` - Displaytext string `json:"displaytext,omitempty"` - Distributedvpcrouter bool `json:"distributedvpcrouter,omitempty"` - Domain string `json:"domain,omitempty"` - Domainid string `json:"domainid,omitempty"` - Fordisplay bool `json:"fordisplay,omitempty"` - Id string `json:"id,omitempty"` - Name string `json:"name,omitempty"` - Network []struct { - Account string `json:"account,omitempty"` - Aclid string `json:"aclid,omitempty"` - Acltype string `json:"acltype,omitempty"` - Broadcastdomaintype string `json:"broadcastdomaintype,omitempty"` - Broadcasturi string `json:"broadcasturi,omitempty"` - Canusefordeploy bool `json:"canusefordeploy,omitempty"` - Cidr string `json:"cidr,omitempty"` - Displaynetwork bool `json:"displaynetwork,omitempty"` - Displaytext string `json:"displaytext,omitempty"` - Dns1 string `json:"dns1,omitempty"` - Dns2 string `json:"dns2,omitempty"` - Domain string `json:"domain,omitempty"` - Domainid string `json:"domainid,omitempty"` - Gateway string `json:"gateway,omitempty"` - Id string `json:"id,omitempty"` - Ip6cidr string `json:"ip6cidr,omitempty"` - Ip6gateway string `json:"ip6gateway,omitempty"` - Isdefault bool `json:"isdefault,omitempty"` - Ispersistent bool `json:"ispersistent,omitempty"` - Issystem bool `json:"issystem,omitempty"` - Name string `json:"name,omitempty"` - Netmask string `json:"netmask,omitempty"` - Networkcidr string `json:"networkcidr,omitempty"` - Networkdomain string `json:"networkdomain,omitempty"` - Networkofferingavailability string `json:"networkofferingavailability,omitempty"` - Networkofferingconservemode bool `json:"networkofferingconservemode,omitempty"` - Networkofferingdisplaytext string `json:"networkofferingdisplaytext,omitempty"` - Networkofferingid string `json:"networkofferingid,omitempty"` - Networkofferingname string `json:"networkofferingname,omitempty"` - Physicalnetworkid string `json:"physicalnetworkid,omitempty"` - Project string `json:"project,omitempty"` - Projectid string `json:"projectid,omitempty"` - Related string `json:"related,omitempty"` - Reservediprange string `json:"reservediprange,omitempty"` - Restartrequired bool `json:"restartrequired,omitempty"` - Service []struct { - Capability []struct { - Canchooseservicecapability bool `json:"canchooseservicecapability,omitempty"` - Name string `json:"name,omitempty"` - Value string `json:"value,omitempty"` - } `json:"capability,omitempty"` - Name string `json:"name,omitempty"` - Provider []struct { - Canenableindividualservice bool `json:"canenableindividualservice,omitempty"` - Destinationphysicalnetworkid string `json:"destinationphysicalnetworkid,omitempty"` - Id string `json:"id,omitempty"` - Name string `json:"name,omitempty"` - Physicalnetworkid string `json:"physicalnetworkid,omitempty"` - Servicelist []string `json:"servicelist,omitempty"` - State string `json:"state,omitempty"` - } `json:"provider,omitempty"` - } `json:"service,omitempty"` - Specifyipranges bool `json:"specifyipranges,omitempty"` - State string `json:"state,omitempty"` - Strechedl2subnet bool `json:"strechedl2subnet,omitempty"` - Subdomainaccess bool `json:"subdomainaccess,omitempty"` - Tags []struct { - Account string `json:"account,omitempty"` - Customer string `json:"customer,omitempty"` - Domain string `json:"domain,omitempty"` - Domainid string `json:"domainid,omitempty"` - Key string `json:"key,omitempty"` - Project string `json:"project,omitempty"` - Projectid string `json:"projectid,omitempty"` - Resourceid string `json:"resourceid,omitempty"` - Resourcetype string `json:"resourcetype,omitempty"` - Value string `json:"value,omitempty"` - } `json:"tags,omitempty"` - Traffictype string `json:"traffictype,omitempty"` - Type string `json:"type,omitempty"` - Vlan string `json:"vlan,omitempty"` - Vpcid string `json:"vpcid,omitempty"` - Zoneid string `json:"zoneid,omitempty"` - Zonename string `json:"zonename,omitempty"` - Zonesnetworkspans []string `json:"zonesnetworkspans,omitempty"` - } `json:"network,omitempty"` - Networkdomain string `json:"networkdomain,omitempty"` - Project string `json:"project,omitempty"` - Projectid string `json:"projectid,omitempty"` - Redundantvpcrouter bool `json:"redundantvpcrouter,omitempty"` - Regionlevelvpc bool `json:"regionlevelvpc,omitempty"` - Restartrequired bool `json:"restartrequired,omitempty"` - Service []struct { - Capability []struct { - Canchooseservicecapability bool `json:"canchooseservicecapability,omitempty"` - Name string `json:"name,omitempty"` - Value string `json:"value,omitempty"` - } `json:"capability,omitempty"` - Name string `json:"name,omitempty"` - Provider []struct { - Canenableindividualservice bool `json:"canenableindividualservice,omitempty"` - Destinationphysicalnetworkid string `json:"destinationphysicalnetworkid,omitempty"` - Id string `json:"id,omitempty"` - Name string `json:"name,omitempty"` - Physicalnetworkid string `json:"physicalnetworkid,omitempty"` - Servicelist []string `json:"servicelist,omitempty"` - State string `json:"state,omitempty"` - } `json:"provider,omitempty"` - } `json:"service,omitempty"` - State string `json:"state,omitempty"` - Tags []struct { - Account string `json:"account,omitempty"` - Customer string `json:"customer,omitempty"` - Domain string `json:"domain,omitempty"` - Domainid string `json:"domainid,omitempty"` - Key string `json:"key,omitempty"` - Project string `json:"project,omitempty"` - Projectid string `json:"projectid,omitempty"` - Resourceid string `json:"resourceid,omitempty"` - Resourcetype string `json:"resourcetype,omitempty"` - Value string `json:"value,omitempty"` - } `json:"tags,omitempty"` - Vpcofferingid string `json:"vpcofferingid,omitempty"` - Zoneid string `json:"zoneid,omitempty"` - Zonename string `json:"zonename,omitempty"` + Account string `json:"account"` + Cidr string `json:"cidr"` + Created string `json:"created"` + Displaytext string `json:"displaytext"` + Distributedvpcrouter bool `json:"distributedvpcrouter"` + Domain string `json:"domain"` + Domainid string `json:"domainid"` + Fordisplay bool `json:"fordisplay"` + Id string `json:"id"` + Name string `json:"name"` + Network []VPCNetwork `json:"network"` + Networkdomain string `json:"networkdomain"` + Project string `json:"project"` + Projectid string `json:"projectid"` + Redundantvpcrouter bool `json:"redundantvpcrouter"` + Regionlevelvpc bool `json:"regionlevelvpc"` + Restartrequired bool `json:"restartrequired"` + Service []VPCServiceInternal `json:"service"` + State string `json:"state"` + Tags []Tags `json:"tags"` + Vpcofferingid string `json:"vpcofferingid"` + Zoneid string `json:"zoneid"` + Zonename string `json:"zonename"` } -type DeleteVPCParams struct { +type VPCServiceInternal struct { + Capability []VPCServiceInternalCapability `json:"capability"` + Name string `json:"name"` + Provider []VPCServiceInternalProvider `json:"provider"` +} + +type VPCServiceInternalProvider struct { + Canenableindividualservice bool `json:"canenableindividualservice"` + Destinationphysicalnetworkid string `json:"destinationphysicalnetworkid"` + Id string `json:"id"` + Name string `json:"name"` + Physicalnetworkid string `json:"physicalnetworkid"` + Servicelist []string `json:"servicelist"` + State string `json:"state"` +} + +type VPCServiceInternalCapability struct { + Canchooseservicecapability bool `json:"canchooseservicecapability"` + Name string `json:"name"` + Value string `json:"value"` +} + +type VPCNetwork struct { + Account string `json:"account"` + Aclid string `json:"aclid"` + Acltype string `json:"acltype"` + Broadcastdomaintype string `json:"broadcastdomaintype"` + Broadcasturi string `json:"broadcasturi"` + Canusefordeploy bool `json:"canusefordeploy"` + Cidr string `json:"cidr"` + Displaynetwork bool `json:"displaynetwork"` + Displaytext string `json:"displaytext"` + Dns1 string `json:"dns1"` + Dns2 string `json:"dns2"` + Domain string `json:"domain"` + Domainid string `json:"domainid"` + Externalid string `json:"externalid"` + Gateway string `json:"gateway"` + Id string `json:"id"` + Ip6cidr string `json:"ip6cidr"` + Ip6gateway string `json:"ip6gateway"` + Isdefault bool `json:"isdefault"` + Ispersistent bool `json:"ispersistent"` + Issystem bool `json:"issystem"` + Name string `json:"name"` + Netmask string `json:"netmask"` + Networkcidr string `json:"networkcidr"` + Networkdomain string `json:"networkdomain"` + Networkofferingavailability string `json:"networkofferingavailability"` + Networkofferingconservemode bool `json:"networkofferingconservemode"` + Networkofferingdisplaytext string `json:"networkofferingdisplaytext"` + Networkofferingid string `json:"networkofferingid"` + Networkofferingname string `json:"networkofferingname"` + Physicalnetworkid string `json:"physicalnetworkid"` + Project string `json:"project"` + Projectid string `json:"projectid"` + Redundantrouter bool `json:"redundantrouter"` + Related string `json:"related"` + Reservediprange string `json:"reservediprange"` + Restartrequired bool `json:"restartrequired"` + Service []VPCNetworkService `json:"service"` + Specifyipranges bool `json:"specifyipranges"` + State string `json:"state"` + Strechedl2subnet bool `json:"strechedl2subnet"` + Subdomainaccess bool `json:"subdomainaccess"` + Tags []Tags `json:"tags"` + Traffictype string `json:"traffictype"` + Type string `json:"type"` + Vlan string `json:"vlan"` + Vpcid string `json:"vpcid"` + Zoneid string `json:"zoneid"` + Zonename string `json:"zonename"` + Zonesnetworkspans []interface{} `json:"zonesnetworkspans"` +} + +type VPCNetworkService struct { + Capability []VPCNetworkServiceCapability `json:"capability"` + Name string `json:"name"` + Provider []VPCNetworkServiceProvider `json:"provider"` +} + +type VPCNetworkServiceProvider struct { + Canenableindividualservice bool `json:"canenableindividualservice"` + Destinationphysicalnetworkid string `json:"destinationphysicalnetworkid"` + Id string `json:"id"` + Name string `json:"name"` + Physicalnetworkid string `json:"physicalnetworkid"` + Servicelist []string `json:"servicelist"` + State string `json:"state"` +} + +type VPCNetworkServiceCapability struct { + Canchooseservicecapability bool `json:"canchooseservicecapability"` + Name string `json:"name"` + Value string `json:"value"` +} + +type RestartVPCParams struct { p map[string]interface{} } -func (p *DeleteVPCParams) toURLValues() url.Values { +func (p *RestartVPCParams) toURLValues() url.Values { u := url.Values{} if p.p == nil { return u } + if v, found := p.p["cleanup"]; found { + vv := strconv.FormatBool(v.(bool)) + u.Set("cleanup", vv) + } if v, found := p.p["id"]; found { u.Set("id", v.(string)) } + if v, found := p.p["makeredundant"]; found { + vv := strconv.FormatBool(v.(bool)) + u.Set("makeredundant", vv) + } return u } -func (p *DeleteVPCParams) SetId(v string) { +func (p *RestartVPCParams) SetCleanup(v bool) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["cleanup"] = v + return +} + +func (p *RestartVPCParams) SetId(v string) { if p.p == nil { p.p = make(map[string]interface{}) } @@ -831,23 +2282,31 @@ func (p *DeleteVPCParams) SetId(v string) { return } -// You should always use this function to get a new DeleteVPCParams instance, +func (p *RestartVPCParams) SetMakeredundant(v bool) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["makeredundant"] = v + return +} + +// You should always use this function to get a new RestartVPCParams instance, // as then you are sure you have configured all required params -func (s *VPCService) NewDeleteVPCParams(id string) *DeleteVPCParams { - p := &DeleteVPCParams{} +func (s *VPCService) NewRestartVPCParams(id string) *RestartVPCParams { + p := &RestartVPCParams{} p.p = make(map[string]interface{}) p.p["id"] = id return p } -// Deletes a VPC -func (s *VPCService) DeleteVPC(p *DeleteVPCParams) (*DeleteVPCResponse, error) { - resp, err := s.cs.newRequest("deleteVPC", p.toURLValues()) +// Restarts a VPC +func (s *VPCService) RestartVPC(p *RestartVPCParams) (*RestartVPCResponse, error) { + resp, err := s.cs.newRequest("restartVPC", p.toURLValues()) if err != nil { return nil, err } - var r DeleteVPCResponse + var r RestartVPCResponse if err := json.Unmarshal(resp, &r); err != nil { return nil, err } @@ -862,17 +2321,141 @@ func (s *VPCService) DeleteVPC(p *DeleteVPCParams) (*DeleteVPCResponse, error) { return nil, err } + b, err = getRawValue(b) + if err != nil { + return nil, err + } + if err := json.Unmarshal(b, &r); err != nil { return nil, err } } + return &r, nil } -type DeleteVPCResponse struct { - JobID string `json:"jobid,omitempty"` - Displaytext string `json:"displaytext,omitempty"` - Success bool `json:"success,omitempty"` +type RestartVPCResponse struct { + JobID string `json:"jobid"` + Account string `json:"account"` + Cidr string `json:"cidr"` + Created string `json:"created"` + Displaytext string `json:"displaytext"` + Distributedvpcrouter bool `json:"distributedvpcrouter"` + Domain string `json:"domain"` + Domainid string `json:"domainid"` + Fordisplay bool `json:"fordisplay"` + Id string `json:"id"` + Name string `json:"name"` + Network []RestartVPCResponseNetwork `json:"network"` + Networkdomain string `json:"networkdomain"` + Project string `json:"project"` + Projectid string `json:"projectid"` + Redundantvpcrouter bool `json:"redundantvpcrouter"` + Regionlevelvpc bool `json:"regionlevelvpc"` + Restartrequired bool `json:"restartrequired"` + Service []RestartVPCResponseService `json:"service"` + State string `json:"state"` + Tags []Tags `json:"tags"` + Vpcofferingid string `json:"vpcofferingid"` + Zoneid string `json:"zoneid"` + Zonename string `json:"zonename"` +} + +type RestartVPCResponseService struct { + Capability []RestartVPCResponseServiceCapability `json:"capability"` + Name string `json:"name"` + Provider []RestartVPCResponseServiceProvider `json:"provider"` +} + +type RestartVPCResponseServiceProvider struct { + Canenableindividualservice bool `json:"canenableindividualservice"` + Destinationphysicalnetworkid string `json:"destinationphysicalnetworkid"` + Id string `json:"id"` + Name string `json:"name"` + Physicalnetworkid string `json:"physicalnetworkid"` + Servicelist []string `json:"servicelist"` + State string `json:"state"` +} + +type RestartVPCResponseServiceCapability struct { + Canchooseservicecapability bool `json:"canchooseservicecapability"` + Name string `json:"name"` + Value string `json:"value"` +} + +type RestartVPCResponseNetwork struct { + Account string `json:"account"` + Aclid string `json:"aclid"` + Acltype string `json:"acltype"` + Broadcastdomaintype string `json:"broadcastdomaintype"` + Broadcasturi string `json:"broadcasturi"` + Canusefordeploy bool `json:"canusefordeploy"` + Cidr string `json:"cidr"` + Displaynetwork bool `json:"displaynetwork"` + Displaytext string `json:"displaytext"` + Dns1 string `json:"dns1"` + Dns2 string `json:"dns2"` + Domain string `json:"domain"` + Domainid string `json:"domainid"` + Externalid string `json:"externalid"` + Gateway string `json:"gateway"` + Id string `json:"id"` + Ip6cidr string `json:"ip6cidr"` + Ip6gateway string `json:"ip6gateway"` + Isdefault bool `json:"isdefault"` + Ispersistent bool `json:"ispersistent"` + Issystem bool `json:"issystem"` + Name string `json:"name"` + Netmask string `json:"netmask"` + Networkcidr string `json:"networkcidr"` + Networkdomain string `json:"networkdomain"` + Networkofferingavailability string `json:"networkofferingavailability"` + Networkofferingconservemode bool `json:"networkofferingconservemode"` + Networkofferingdisplaytext string `json:"networkofferingdisplaytext"` + Networkofferingid string `json:"networkofferingid"` + Networkofferingname string `json:"networkofferingname"` + Physicalnetworkid string `json:"physicalnetworkid"` + Project string `json:"project"` + Projectid string `json:"projectid"` + Redundantrouter bool `json:"redundantrouter"` + Related string `json:"related"` + Reservediprange string `json:"reservediprange"` + Restartrequired bool `json:"restartrequired"` + Service []RestartVPCResponseNetworkService `json:"service"` + Specifyipranges bool `json:"specifyipranges"` + State string `json:"state"` + Strechedl2subnet bool `json:"strechedl2subnet"` + Subdomainaccess bool `json:"subdomainaccess"` + Tags []Tags `json:"tags"` + Traffictype string `json:"traffictype"` + Type string `json:"type"` + Vlan string `json:"vlan"` + Vpcid string `json:"vpcid"` + Zoneid string `json:"zoneid"` + Zonename string `json:"zonename"` + Zonesnetworkspans []interface{} `json:"zonesnetworkspans"` +} + +type RestartVPCResponseNetworkService struct { + Capability []RestartVPCResponseNetworkServiceCapability `json:"capability"` + Name string `json:"name"` + Provider []RestartVPCResponseNetworkServiceProvider `json:"provider"` +} + +type RestartVPCResponseNetworkServiceProvider struct { + Canenableindividualservice bool `json:"canenableindividualservice"` + Destinationphysicalnetworkid string `json:"destinationphysicalnetworkid"` + Id string `json:"id"` + Name string `json:"name"` + Physicalnetworkid string `json:"physicalnetworkid"` + Servicelist []string `json:"servicelist"` + State string `json:"state"` +} + +type RestartVPCResponseNetworkServiceCapability struct { + Canchooseservicecapability bool `json:"canchooseservicecapability"` + Name string `json:"name"` + Value string `json:"value"` } type UpdateVPCParams struct { @@ -983,520 +2566,132 @@ func (s *VPCService) UpdateVPC(p *UpdateVPCParams) (*UpdateVPCResponse, error) { return nil, err } } + return &r, nil } type UpdateVPCResponse struct { - JobID string `json:"jobid,omitempty"` - Account string `json:"account,omitempty"` - Cidr string `json:"cidr,omitempty"` - Created string `json:"created,omitempty"` - Displaytext string `json:"displaytext,omitempty"` - Distributedvpcrouter bool `json:"distributedvpcrouter,omitempty"` - Domain string `json:"domain,omitempty"` - Domainid string `json:"domainid,omitempty"` - Fordisplay bool `json:"fordisplay,omitempty"` - Id string `json:"id,omitempty"` - Name string `json:"name,omitempty"` - Network []struct { - Account string `json:"account,omitempty"` - Aclid string `json:"aclid,omitempty"` - Acltype string `json:"acltype,omitempty"` - Broadcastdomaintype string `json:"broadcastdomaintype,omitempty"` - Broadcasturi string `json:"broadcasturi,omitempty"` - Canusefordeploy bool `json:"canusefordeploy,omitempty"` - Cidr string `json:"cidr,omitempty"` - Displaynetwork bool `json:"displaynetwork,omitempty"` - Displaytext string `json:"displaytext,omitempty"` - Dns1 string `json:"dns1,omitempty"` - Dns2 string `json:"dns2,omitempty"` - Domain string `json:"domain,omitempty"` - Domainid string `json:"domainid,omitempty"` - Gateway string `json:"gateway,omitempty"` - Id string `json:"id,omitempty"` - Ip6cidr string `json:"ip6cidr,omitempty"` - Ip6gateway string `json:"ip6gateway,omitempty"` - Isdefault bool `json:"isdefault,omitempty"` - Ispersistent bool `json:"ispersistent,omitempty"` - Issystem bool `json:"issystem,omitempty"` - Name string `json:"name,omitempty"` - Netmask string `json:"netmask,omitempty"` - Networkcidr string `json:"networkcidr,omitempty"` - Networkdomain string `json:"networkdomain,omitempty"` - Networkofferingavailability string `json:"networkofferingavailability,omitempty"` - Networkofferingconservemode bool `json:"networkofferingconservemode,omitempty"` - Networkofferingdisplaytext string `json:"networkofferingdisplaytext,omitempty"` - Networkofferingid string `json:"networkofferingid,omitempty"` - Networkofferingname string `json:"networkofferingname,omitempty"` - Physicalnetworkid string `json:"physicalnetworkid,omitempty"` - Project string `json:"project,omitempty"` - Projectid string `json:"projectid,omitempty"` - Related string `json:"related,omitempty"` - Reservediprange string `json:"reservediprange,omitempty"` - Restartrequired bool `json:"restartrequired,omitempty"` - Service []struct { - Capability []struct { - Canchooseservicecapability bool `json:"canchooseservicecapability,omitempty"` - Name string `json:"name,omitempty"` - Value string `json:"value,omitempty"` - } `json:"capability,omitempty"` - Name string `json:"name,omitempty"` - Provider []struct { - Canenableindividualservice bool `json:"canenableindividualservice,omitempty"` - Destinationphysicalnetworkid string `json:"destinationphysicalnetworkid,omitempty"` - Id string `json:"id,omitempty"` - Name string `json:"name,omitempty"` - Physicalnetworkid string `json:"physicalnetworkid,omitempty"` - Servicelist []string `json:"servicelist,omitempty"` - State string `json:"state,omitempty"` - } `json:"provider,omitempty"` - } `json:"service,omitempty"` - Specifyipranges bool `json:"specifyipranges,omitempty"` - State string `json:"state,omitempty"` - Strechedl2subnet bool `json:"strechedl2subnet,omitempty"` - Subdomainaccess bool `json:"subdomainaccess,omitempty"` - Tags []struct { - Account string `json:"account,omitempty"` - Customer string `json:"customer,omitempty"` - Domain string `json:"domain,omitempty"` - Domainid string `json:"domainid,omitempty"` - Key string `json:"key,omitempty"` - Project string `json:"project,omitempty"` - Projectid string `json:"projectid,omitempty"` - Resourceid string `json:"resourceid,omitempty"` - Resourcetype string `json:"resourcetype,omitempty"` - Value string `json:"value,omitempty"` - } `json:"tags,omitempty"` - Traffictype string `json:"traffictype,omitempty"` - Type string `json:"type,omitempty"` - Vlan string `json:"vlan,omitempty"` - Vpcid string `json:"vpcid,omitempty"` - Zoneid string `json:"zoneid,omitempty"` - Zonename string `json:"zonename,omitempty"` - Zonesnetworkspans []string `json:"zonesnetworkspans,omitempty"` - } `json:"network,omitempty"` - Networkdomain string `json:"networkdomain,omitempty"` - Project string `json:"project,omitempty"` - Projectid string `json:"projectid,omitempty"` - Redundantvpcrouter bool `json:"redundantvpcrouter,omitempty"` - Regionlevelvpc bool `json:"regionlevelvpc,omitempty"` - Restartrequired bool `json:"restartrequired,omitempty"` - Service []struct { - Capability []struct { - Canchooseservicecapability bool `json:"canchooseservicecapability,omitempty"` - Name string `json:"name,omitempty"` - Value string `json:"value,omitempty"` - } `json:"capability,omitempty"` - Name string `json:"name,omitempty"` - Provider []struct { - Canenableindividualservice bool `json:"canenableindividualservice,omitempty"` - Destinationphysicalnetworkid string `json:"destinationphysicalnetworkid,omitempty"` - Id string `json:"id,omitempty"` - Name string `json:"name,omitempty"` - Physicalnetworkid string `json:"physicalnetworkid,omitempty"` - Servicelist []string `json:"servicelist,omitempty"` - State string `json:"state,omitempty"` - } `json:"provider,omitempty"` - } `json:"service,omitempty"` - State string `json:"state,omitempty"` - Tags []struct { - Account string `json:"account,omitempty"` - Customer string `json:"customer,omitempty"` - Domain string `json:"domain,omitempty"` - Domainid string `json:"domainid,omitempty"` - Key string `json:"key,omitempty"` - Project string `json:"project,omitempty"` - Projectid string `json:"projectid,omitempty"` - Resourceid string `json:"resourceid,omitempty"` - Resourcetype string `json:"resourcetype,omitempty"` - Value string `json:"value,omitempty"` - } `json:"tags,omitempty"` - Vpcofferingid string `json:"vpcofferingid,omitempty"` - Zoneid string `json:"zoneid,omitempty"` - Zonename string `json:"zonename,omitempty"` + JobID string `json:"jobid"` + Account string `json:"account"` + Cidr string `json:"cidr"` + Created string `json:"created"` + Displaytext string `json:"displaytext"` + Distributedvpcrouter bool `json:"distributedvpcrouter"` + Domain string `json:"domain"` + Domainid string `json:"domainid"` + Fordisplay bool `json:"fordisplay"` + Id string `json:"id"` + Name string `json:"name"` + Network []UpdateVPCResponseNetwork `json:"network"` + Networkdomain string `json:"networkdomain"` + Project string `json:"project"` + Projectid string `json:"projectid"` + Redundantvpcrouter bool `json:"redundantvpcrouter"` + Regionlevelvpc bool `json:"regionlevelvpc"` + Restartrequired bool `json:"restartrequired"` + Service []UpdateVPCResponseService `json:"service"` + State string `json:"state"` + Tags []Tags `json:"tags"` + Vpcofferingid string `json:"vpcofferingid"` + Zoneid string `json:"zoneid"` + Zonename string `json:"zonename"` } -type RestartVPCParams struct { - p map[string]interface{} +type UpdateVPCResponseService struct { + Capability []UpdateVPCResponseServiceCapability `json:"capability"` + Name string `json:"name"` + Provider []UpdateVPCResponseServiceProvider `json:"provider"` } -func (p *RestartVPCParams) toURLValues() url.Values { - u := url.Values{} - if p.p == nil { - return u - } - if v, found := p.p["cleanup"]; found { - vv := strconv.FormatBool(v.(bool)) - u.Set("cleanup", vv) - } - if v, found := p.p["id"]; found { - u.Set("id", v.(string)) - } - if v, found := p.p["makeredundant"]; found { - vv := strconv.FormatBool(v.(bool)) - u.Set("makeredundant", vv) - } - return u +type UpdateVPCResponseServiceProvider struct { + Canenableindividualservice bool `json:"canenableindividualservice"` + Destinationphysicalnetworkid string `json:"destinationphysicalnetworkid"` + Id string `json:"id"` + Name string `json:"name"` + Physicalnetworkid string `json:"physicalnetworkid"` + Servicelist []string `json:"servicelist"` + State string `json:"state"` } -func (p *RestartVPCParams) SetCleanup(v bool) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["cleanup"] = v - return +type UpdateVPCResponseServiceCapability struct { + Canchooseservicecapability bool `json:"canchooseservicecapability"` + Name string `json:"name"` + Value string `json:"value"` } -func (p *RestartVPCParams) SetId(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["id"] = v - return +type UpdateVPCResponseNetwork struct { + Account string `json:"account"` + Aclid string `json:"aclid"` + Acltype string `json:"acltype"` + Broadcastdomaintype string `json:"broadcastdomaintype"` + Broadcasturi string `json:"broadcasturi"` + Canusefordeploy bool `json:"canusefordeploy"` + Cidr string `json:"cidr"` + Displaynetwork bool `json:"displaynetwork"` + Displaytext string `json:"displaytext"` + Dns1 string `json:"dns1"` + Dns2 string `json:"dns2"` + Domain string `json:"domain"` + Domainid string `json:"domainid"` + Externalid string `json:"externalid"` + Gateway string `json:"gateway"` + Id string `json:"id"` + Ip6cidr string `json:"ip6cidr"` + Ip6gateway string `json:"ip6gateway"` + Isdefault bool `json:"isdefault"` + Ispersistent bool `json:"ispersistent"` + Issystem bool `json:"issystem"` + Name string `json:"name"` + Netmask string `json:"netmask"` + Networkcidr string `json:"networkcidr"` + Networkdomain string `json:"networkdomain"` + Networkofferingavailability string `json:"networkofferingavailability"` + Networkofferingconservemode bool `json:"networkofferingconservemode"` + Networkofferingdisplaytext string `json:"networkofferingdisplaytext"` + Networkofferingid string `json:"networkofferingid"` + Networkofferingname string `json:"networkofferingname"` + Physicalnetworkid string `json:"physicalnetworkid"` + Project string `json:"project"` + Projectid string `json:"projectid"` + Redundantrouter bool `json:"redundantrouter"` + Related string `json:"related"` + Reservediprange string `json:"reservediprange"` + Restartrequired bool `json:"restartrequired"` + Service []UpdateVPCResponseNetworkService `json:"service"` + Specifyipranges bool `json:"specifyipranges"` + State string `json:"state"` + Strechedl2subnet bool `json:"strechedl2subnet"` + Subdomainaccess bool `json:"subdomainaccess"` + Tags []Tags `json:"tags"` + Traffictype string `json:"traffictype"` + Type string `json:"type"` + Vlan string `json:"vlan"` + Vpcid string `json:"vpcid"` + Zoneid string `json:"zoneid"` + Zonename string `json:"zonename"` + Zonesnetworkspans []interface{} `json:"zonesnetworkspans"` } -func (p *RestartVPCParams) SetMakeredundant(v bool) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["makeredundant"] = v - return +type UpdateVPCResponseNetworkService struct { + Capability []UpdateVPCResponseNetworkServiceCapability `json:"capability"` + Name string `json:"name"` + Provider []UpdateVPCResponseNetworkServiceProvider `json:"provider"` } -// You should always use this function to get a new RestartVPCParams instance, -// as then you are sure you have configured all required params -func (s *VPCService) NewRestartVPCParams(id string) *RestartVPCParams { - p := &RestartVPCParams{} - p.p = make(map[string]interface{}) - p.p["id"] = id - return p +type UpdateVPCResponseNetworkServiceProvider struct { + Canenableindividualservice bool `json:"canenableindividualservice"` + Destinationphysicalnetworkid string `json:"destinationphysicalnetworkid"` + Id string `json:"id"` + Name string `json:"name"` + Physicalnetworkid string `json:"physicalnetworkid"` + Servicelist []string `json:"servicelist"` + State string `json:"state"` } -// Restarts a VPC -func (s *VPCService) RestartVPC(p *RestartVPCParams) (*RestartVPCResponse, error) { - resp, err := s.cs.newRequest("restartVPC", p.toURLValues()) - if err != nil { - return nil, err - } - - var r RestartVPCResponse - if err := json.Unmarshal(resp, &r); err != nil { - return nil, err - } - - // If we have a async client, we need to wait for the async result - if s.cs.async { - b, err := s.cs.GetAsyncJobResult(r.JobID, s.cs.timeout) - if err != nil { - if err == AsyncTimeoutErr { - return &r, err - } - return nil, err - } - - b, err = getRawValue(b) - if err != nil { - return nil, err - } - - if err := json.Unmarshal(b, &r); err != nil { - return nil, err - } - } - return &r, nil -} - -type RestartVPCResponse struct { - JobID string `json:"jobid,omitempty"` - Account string `json:"account,omitempty"` - Cidr string `json:"cidr,omitempty"` - Created string `json:"created,omitempty"` - Displaytext string `json:"displaytext,omitempty"` - Distributedvpcrouter bool `json:"distributedvpcrouter,omitempty"` - Domain string `json:"domain,omitempty"` - Domainid string `json:"domainid,omitempty"` - Fordisplay bool `json:"fordisplay,omitempty"` - Id string `json:"id,omitempty"` - Name string `json:"name,omitempty"` - Network []struct { - Account string `json:"account,omitempty"` - Aclid string `json:"aclid,omitempty"` - Acltype string `json:"acltype,omitempty"` - Broadcastdomaintype string `json:"broadcastdomaintype,omitempty"` - Broadcasturi string `json:"broadcasturi,omitempty"` - Canusefordeploy bool `json:"canusefordeploy,omitempty"` - Cidr string `json:"cidr,omitempty"` - Displaynetwork bool `json:"displaynetwork,omitempty"` - Displaytext string `json:"displaytext,omitempty"` - Dns1 string `json:"dns1,omitempty"` - Dns2 string `json:"dns2,omitempty"` - Domain string `json:"domain,omitempty"` - Domainid string `json:"domainid,omitempty"` - Gateway string `json:"gateway,omitempty"` - Id string `json:"id,omitempty"` - Ip6cidr string `json:"ip6cidr,omitempty"` - Ip6gateway string `json:"ip6gateway,omitempty"` - Isdefault bool `json:"isdefault,omitempty"` - Ispersistent bool `json:"ispersistent,omitempty"` - Issystem bool `json:"issystem,omitempty"` - Name string `json:"name,omitempty"` - Netmask string `json:"netmask,omitempty"` - Networkcidr string `json:"networkcidr,omitempty"` - Networkdomain string `json:"networkdomain,omitempty"` - Networkofferingavailability string `json:"networkofferingavailability,omitempty"` - Networkofferingconservemode bool `json:"networkofferingconservemode,omitempty"` - Networkofferingdisplaytext string `json:"networkofferingdisplaytext,omitempty"` - Networkofferingid string `json:"networkofferingid,omitempty"` - Networkofferingname string `json:"networkofferingname,omitempty"` - Physicalnetworkid string `json:"physicalnetworkid,omitempty"` - Project string `json:"project,omitempty"` - Projectid string `json:"projectid,omitempty"` - Related string `json:"related,omitempty"` - Reservediprange string `json:"reservediprange,omitempty"` - Restartrequired bool `json:"restartrequired,omitempty"` - Service []struct { - Capability []struct { - Canchooseservicecapability bool `json:"canchooseservicecapability,omitempty"` - Name string `json:"name,omitempty"` - Value string `json:"value,omitempty"` - } `json:"capability,omitempty"` - Name string `json:"name,omitempty"` - Provider []struct { - Canenableindividualservice bool `json:"canenableindividualservice,omitempty"` - Destinationphysicalnetworkid string `json:"destinationphysicalnetworkid,omitempty"` - Id string `json:"id,omitempty"` - Name string `json:"name,omitempty"` - Physicalnetworkid string `json:"physicalnetworkid,omitempty"` - Servicelist []string `json:"servicelist,omitempty"` - State string `json:"state,omitempty"` - } `json:"provider,omitempty"` - } `json:"service,omitempty"` - Specifyipranges bool `json:"specifyipranges,omitempty"` - State string `json:"state,omitempty"` - Strechedl2subnet bool `json:"strechedl2subnet,omitempty"` - Subdomainaccess bool `json:"subdomainaccess,omitempty"` - Tags []struct { - Account string `json:"account,omitempty"` - Customer string `json:"customer,omitempty"` - Domain string `json:"domain,omitempty"` - Domainid string `json:"domainid,omitempty"` - Key string `json:"key,omitempty"` - Project string `json:"project,omitempty"` - Projectid string `json:"projectid,omitempty"` - Resourceid string `json:"resourceid,omitempty"` - Resourcetype string `json:"resourcetype,omitempty"` - Value string `json:"value,omitempty"` - } `json:"tags,omitempty"` - Traffictype string `json:"traffictype,omitempty"` - Type string `json:"type,omitempty"` - Vlan string `json:"vlan,omitempty"` - Vpcid string `json:"vpcid,omitempty"` - Zoneid string `json:"zoneid,omitempty"` - Zonename string `json:"zonename,omitempty"` - Zonesnetworkspans []string `json:"zonesnetworkspans,omitempty"` - } `json:"network,omitempty"` - Networkdomain string `json:"networkdomain,omitempty"` - Project string `json:"project,omitempty"` - Projectid string `json:"projectid,omitempty"` - Redundantvpcrouter bool `json:"redundantvpcrouter,omitempty"` - Regionlevelvpc bool `json:"regionlevelvpc,omitempty"` - Restartrequired bool `json:"restartrequired,omitempty"` - Service []struct { - Capability []struct { - Canchooseservicecapability bool `json:"canchooseservicecapability,omitempty"` - Name string `json:"name,omitempty"` - Value string `json:"value,omitempty"` - } `json:"capability,omitempty"` - Name string `json:"name,omitempty"` - Provider []struct { - Canenableindividualservice bool `json:"canenableindividualservice,omitempty"` - Destinationphysicalnetworkid string `json:"destinationphysicalnetworkid,omitempty"` - Id string `json:"id,omitempty"` - Name string `json:"name,omitempty"` - Physicalnetworkid string `json:"physicalnetworkid,omitempty"` - Servicelist []string `json:"servicelist,omitempty"` - State string `json:"state,omitempty"` - } `json:"provider,omitempty"` - } `json:"service,omitempty"` - State string `json:"state,omitempty"` - Tags []struct { - Account string `json:"account,omitempty"` - Customer string `json:"customer,omitempty"` - Domain string `json:"domain,omitempty"` - Domainid string `json:"domainid,omitempty"` - Key string `json:"key,omitempty"` - Project string `json:"project,omitempty"` - Projectid string `json:"projectid,omitempty"` - Resourceid string `json:"resourceid,omitempty"` - Resourcetype string `json:"resourcetype,omitempty"` - Value string `json:"value,omitempty"` - } `json:"tags,omitempty"` - Vpcofferingid string `json:"vpcofferingid,omitempty"` - Zoneid string `json:"zoneid,omitempty"` - Zonename string `json:"zonename,omitempty"` -} - -type CreateVPCOfferingParams struct { - p map[string]interface{} -} - -func (p *CreateVPCOfferingParams) toURLValues() url.Values { - u := url.Values{} - if p.p == nil { - return u - } - if v, found := p.p["displaytext"]; found { - u.Set("displaytext", v.(string)) - } - if v, found := p.p["name"]; found { - u.Set("name", v.(string)) - } - if v, found := p.p["servicecapabilitylist"]; found { - i := 0 - for k, vv := range v.(map[string]string) { - u.Set(fmt.Sprintf("servicecapabilitylist[%d].key", i), k) - u.Set(fmt.Sprintf("servicecapabilitylist[%d].value", i), vv) - i++ - } - } - if v, found := p.p["serviceofferingid"]; found { - u.Set("serviceofferingid", v.(string)) - } - if v, found := p.p["serviceproviderlist"]; found { - i := 0 - for k, vv := range v.(map[string]string) { - u.Set(fmt.Sprintf("serviceproviderlist[%d].service", i), k) - u.Set(fmt.Sprintf("serviceproviderlist[%d].provider", i), vv) - i++ - } - } - if v, found := p.p["supportedservices"]; found { - vv := strings.Join(v.([]string), ",") - u.Set("supportedservices", vv) - } - return u -} - -func (p *CreateVPCOfferingParams) SetDisplaytext(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["displaytext"] = v - return -} - -func (p *CreateVPCOfferingParams) SetName(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["name"] = v - return -} - -func (p *CreateVPCOfferingParams) SetServicecapabilitylist(v map[string]string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["servicecapabilitylist"] = v - return -} - -func (p *CreateVPCOfferingParams) SetServiceofferingid(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["serviceofferingid"] = v - return -} - -func (p *CreateVPCOfferingParams) SetServiceproviderlist(v map[string]string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["serviceproviderlist"] = v - return -} - -func (p *CreateVPCOfferingParams) SetSupportedservices(v []string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["supportedservices"] = v - return -} - -// You should always use this function to get a new CreateVPCOfferingParams instance, -// as then you are sure you have configured all required params -func (s *VPCService) NewCreateVPCOfferingParams(displaytext string, name string, supportedservices []string) *CreateVPCOfferingParams { - p := &CreateVPCOfferingParams{} - p.p = make(map[string]interface{}) - p.p["displaytext"] = displaytext - p.p["name"] = name - p.p["supportedservices"] = supportedservices - return p -} - -// Creates VPC offering -func (s *VPCService) CreateVPCOffering(p *CreateVPCOfferingParams) (*CreateVPCOfferingResponse, error) { - resp, err := s.cs.newRequest("createVPCOffering", p.toURLValues()) - if err != nil { - return nil, err - } - - var r CreateVPCOfferingResponse - if err := json.Unmarshal(resp, &r); err != nil { - return nil, err - } - - // If we have a async client, we need to wait for the async result - if s.cs.async { - b, err := s.cs.GetAsyncJobResult(r.JobID, s.cs.timeout) - if err != nil { - if err == AsyncTimeoutErr { - return &r, err - } - return nil, err - } - - b, err = getRawValue(b) - if err != nil { - return nil, err - } - - if err := json.Unmarshal(b, &r); err != nil { - return nil, err - } - } - return &r, nil -} - -type CreateVPCOfferingResponse struct { - JobID string `json:"jobid,omitempty"` - Created string `json:"created,omitempty"` - Displaytext string `json:"displaytext,omitempty"` - Distributedvpcrouter bool `json:"distributedvpcrouter,omitempty"` - Id string `json:"id,omitempty"` - Isdefault bool `json:"isdefault,omitempty"` - Name string `json:"name,omitempty"` - Service []struct { - Capability []struct { - Canchooseservicecapability bool `json:"canchooseservicecapability,omitempty"` - Name string `json:"name,omitempty"` - Value string `json:"value,omitempty"` - } `json:"capability,omitempty"` - Name string `json:"name,omitempty"` - Provider []struct { - Canenableindividualservice bool `json:"canenableindividualservice,omitempty"` - Destinationphysicalnetworkid string `json:"destinationphysicalnetworkid,omitempty"` - Id string `json:"id,omitempty"` - Name string `json:"name,omitempty"` - Physicalnetworkid string `json:"physicalnetworkid,omitempty"` - Servicelist []string `json:"servicelist,omitempty"` - State string `json:"state,omitempty"` - } `json:"provider,omitempty"` - } `json:"service,omitempty"` - State string `json:"state,omitempty"` - SupportsregionLevelvpc bool `json:"supportsregionLevelvpc,omitempty"` +type UpdateVPCResponseNetworkServiceCapability struct { + Canchooseservicecapability bool `json:"canchooseservicecapability"` + Name string `json:"name"` + Value string `json:"value"` } type UpdateVPCOfferingParams struct { @@ -1595,1249 +2790,41 @@ func (s *VPCService) UpdateVPCOffering(p *UpdateVPCOfferingParams) (*UpdateVPCOf return nil, err } } + return &r, nil } type UpdateVPCOfferingResponse struct { - JobID string `json:"jobid,omitempty"` - Created string `json:"created,omitempty"` - Displaytext string `json:"displaytext,omitempty"` - Distributedvpcrouter bool `json:"distributedvpcrouter,omitempty"` - Id string `json:"id,omitempty"` - Isdefault bool `json:"isdefault,omitempty"` - Name string `json:"name,omitempty"` - Service []struct { - Capability []struct { - Canchooseservicecapability bool `json:"canchooseservicecapability,omitempty"` - Name string `json:"name,omitempty"` - Value string `json:"value,omitempty"` - } `json:"capability,omitempty"` - Name string `json:"name,omitempty"` - Provider []struct { - Canenableindividualservice bool `json:"canenableindividualservice,omitempty"` - Destinationphysicalnetworkid string `json:"destinationphysicalnetworkid,omitempty"` - Id string `json:"id,omitempty"` - Name string `json:"name,omitempty"` - Physicalnetworkid string `json:"physicalnetworkid,omitempty"` - Servicelist []string `json:"servicelist,omitempty"` - State string `json:"state,omitempty"` - } `json:"provider,omitempty"` - } `json:"service,omitempty"` - State string `json:"state,omitempty"` - SupportsregionLevelvpc bool `json:"supportsregionLevelvpc,omitempty"` -} - -type DeleteVPCOfferingParams struct { - p map[string]interface{} -} - -func (p *DeleteVPCOfferingParams) toURLValues() url.Values { - u := url.Values{} - if p.p == nil { - return u - } - if v, found := p.p["id"]; found { - u.Set("id", v.(string)) - } - return u -} - -func (p *DeleteVPCOfferingParams) SetId(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["id"] = v - return -} - -// You should always use this function to get a new DeleteVPCOfferingParams instance, -// as then you are sure you have configured all required params -func (s *VPCService) NewDeleteVPCOfferingParams(id string) *DeleteVPCOfferingParams { - p := &DeleteVPCOfferingParams{} - p.p = make(map[string]interface{}) - p.p["id"] = id - return p -} - -// Deletes VPC offering -func (s *VPCService) DeleteVPCOffering(p *DeleteVPCOfferingParams) (*DeleteVPCOfferingResponse, error) { - resp, err := s.cs.newRequest("deleteVPCOffering", p.toURLValues()) - if err != nil { - return nil, err - } - - var r DeleteVPCOfferingResponse - if err := json.Unmarshal(resp, &r); err != nil { - return nil, err - } - - // If we have a async client, we need to wait for the async result - if s.cs.async { - b, err := s.cs.GetAsyncJobResult(r.JobID, s.cs.timeout) - if err != nil { - if err == AsyncTimeoutErr { - return &r, err - } - return nil, err - } - - if err := json.Unmarshal(b, &r); err != nil { - return nil, err - } - } - return &r, nil -} - -type DeleteVPCOfferingResponse struct { - JobID string `json:"jobid,omitempty"` - Displaytext string `json:"displaytext,omitempty"` - Success bool `json:"success,omitempty"` -} - -type ListVPCOfferingsParams struct { - p map[string]interface{} -} - -func (p *ListVPCOfferingsParams) toURLValues() url.Values { - u := url.Values{} - if p.p == nil { - return u - } - if v, found := p.p["displaytext"]; found { - u.Set("displaytext", v.(string)) - } - if v, found := p.p["id"]; found { - u.Set("id", v.(string)) - } - if v, found := p.p["isdefault"]; found { - vv := strconv.FormatBool(v.(bool)) - u.Set("isdefault", vv) - } - if v, found := p.p["keyword"]; found { - u.Set("keyword", v.(string)) - } - if v, found := p.p["name"]; found { - u.Set("name", v.(string)) - } - if v, found := p.p["page"]; found { - vv := strconv.Itoa(v.(int)) - u.Set("page", vv) - } - if v, found := p.p["pagesize"]; found { - vv := strconv.Itoa(v.(int)) - u.Set("pagesize", vv) - } - if v, found := p.p["state"]; found { - u.Set("state", v.(string)) - } - if v, found := p.p["supportedservices"]; found { - vv := strings.Join(v.([]string), ",") - u.Set("supportedservices", vv) - } - return u -} - -func (p *ListVPCOfferingsParams) SetDisplaytext(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["displaytext"] = v - return -} - -func (p *ListVPCOfferingsParams) SetId(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["id"] = v - return -} - -func (p *ListVPCOfferingsParams) SetIsdefault(v bool) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["isdefault"] = v - return -} - -func (p *ListVPCOfferingsParams) SetKeyword(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["keyword"] = v - return -} - -func (p *ListVPCOfferingsParams) SetName(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["name"] = v - return -} - -func (p *ListVPCOfferingsParams) SetPage(v int) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["page"] = v - return -} - -func (p *ListVPCOfferingsParams) SetPagesize(v int) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["pagesize"] = v - return -} - -func (p *ListVPCOfferingsParams) SetState(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["state"] = v - return -} - -func (p *ListVPCOfferingsParams) SetSupportedservices(v []string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["supportedservices"] = v - return -} - -// You should always use this function to get a new ListVPCOfferingsParams instance, -// as then you are sure you have configured all required params -func (s *VPCService) NewListVPCOfferingsParams() *ListVPCOfferingsParams { - p := &ListVPCOfferingsParams{} - p.p = make(map[string]interface{}) - return p -} - -// This is a courtesy helper function, which in some cases may not work as expected! -func (s *VPCService) GetVPCOfferingID(name string, opts ...OptionFunc) (string, int, error) { - p := &ListVPCOfferingsParams{} - p.p = make(map[string]interface{}) - - p.p["name"] = name - - for _, fn := range opts { - if err := fn(s.cs, p); err != nil { - return "", -1, err - } - } - - l, err := s.ListVPCOfferings(p) - if err != nil { - return "", -1, err - } - - if l.Count == 0 { - return "", l.Count, fmt.Errorf("No match found for %s: %+v", name, l) - } - - if l.Count == 1 { - return l.VPCOfferings[0].Id, l.Count, nil - } - - if l.Count > 1 { - for _, v := range l.VPCOfferings { - if v.Name == name { - return v.Id, l.Count, nil - } - } - } - return "", l.Count, fmt.Errorf("Could not find an exact match for %s: %+v", name, l) -} - -// This is a courtesy helper function, which in some cases may not work as expected! -func (s *VPCService) GetVPCOfferingByName(name string, opts ...OptionFunc) (*VPCOffering, int, error) { - id, count, err := s.GetVPCOfferingID(name, opts...) - if err != nil { - return nil, count, err - } - - r, count, err := s.GetVPCOfferingByID(id, opts...) - if err != nil { - return nil, count, err - } - return r, count, nil -} - -// This is a courtesy helper function, which in some cases may not work as expected! -func (s *VPCService) GetVPCOfferingByID(id string, opts ...OptionFunc) (*VPCOffering, int, error) { - p := &ListVPCOfferingsParams{} - p.p = make(map[string]interface{}) - - p.p["id"] = id - - for _, fn := range opts { - if err := fn(s.cs, p); err != nil { - return nil, -1, err - } - } - - l, err := s.ListVPCOfferings(p) - if err != nil { - if strings.Contains(err.Error(), fmt.Sprintf( - "Invalid parameter id value=%s due to incorrect long value format, "+ - "or entity does not exist", id)) { - return nil, 0, fmt.Errorf("No match found for %s: %+v", id, l) - } - return nil, -1, err - } - - if l.Count == 0 { - return nil, l.Count, fmt.Errorf("No match found for %s: %+v", id, l) - } - - if l.Count == 1 { - return l.VPCOfferings[0], l.Count, nil - } - return nil, l.Count, fmt.Errorf("There is more then one result for VPCOffering UUID: %s!", id) -} - -// Lists VPC offerings -func (s *VPCService) ListVPCOfferings(p *ListVPCOfferingsParams) (*ListVPCOfferingsResponse, error) { - resp, err := s.cs.newRequest("listVPCOfferings", p.toURLValues()) - if err != nil { - return nil, err - } - - var r ListVPCOfferingsResponse - if err := json.Unmarshal(resp, &r); err != nil { - return nil, err - } - return &r, nil -} - -type ListVPCOfferingsResponse struct { - Count int `json:"count"` - VPCOfferings []*VPCOffering `json:"vpcoffering"` -} - -type VPCOffering struct { - Created string `json:"created,omitempty"` - Displaytext string `json:"displaytext,omitempty"` - Distributedvpcrouter bool `json:"distributedvpcrouter,omitempty"` - Id string `json:"id,omitempty"` - Isdefault bool `json:"isdefault,omitempty"` - Name string `json:"name,omitempty"` - Service []struct { - Capability []struct { - Canchooseservicecapability bool `json:"canchooseservicecapability,omitempty"` - Name string `json:"name,omitempty"` - Value string `json:"value,omitempty"` - } `json:"capability,omitempty"` - Name string `json:"name,omitempty"` - Provider []struct { - Canenableindividualservice bool `json:"canenableindividualservice,omitempty"` - Destinationphysicalnetworkid string `json:"destinationphysicalnetworkid,omitempty"` - Id string `json:"id,omitempty"` - Name string `json:"name,omitempty"` - Physicalnetworkid string `json:"physicalnetworkid,omitempty"` - Servicelist []string `json:"servicelist,omitempty"` - State string `json:"state,omitempty"` - } `json:"provider,omitempty"` - } `json:"service,omitempty"` - State string `json:"state,omitempty"` - SupportsregionLevelvpc bool `json:"supportsregionLevelvpc,omitempty"` -} - -type CreatePrivateGatewayParams struct { - p map[string]interface{} -} - -func (p *CreatePrivateGatewayParams) toURLValues() url.Values { - u := url.Values{} - if p.p == nil { - return u - } - if v, found := p.p["aclid"]; found { - u.Set("aclid", v.(string)) - } - if v, found := p.p["gateway"]; found { - u.Set("gateway", v.(string)) - } - if v, found := p.p["ipaddress"]; found { - u.Set("ipaddress", v.(string)) - } - if v, found := p.p["netmask"]; found { - u.Set("netmask", v.(string)) - } - if v, found := p.p["networkofferingid"]; found { - u.Set("networkofferingid", v.(string)) - } - if v, found := p.p["physicalnetworkid"]; found { - u.Set("physicalnetworkid", v.(string)) - } - if v, found := p.p["sourcenatsupported"]; found { - vv := strconv.FormatBool(v.(bool)) - u.Set("sourcenatsupported", vv) - } - if v, found := p.p["vlan"]; found { - u.Set("vlan", v.(string)) - } - if v, found := p.p["vpcid"]; found { - u.Set("vpcid", v.(string)) - } - return u -} - -func (p *CreatePrivateGatewayParams) SetAclid(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["aclid"] = v - return -} - -func (p *CreatePrivateGatewayParams) SetGateway(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["gateway"] = v - return -} - -func (p *CreatePrivateGatewayParams) SetIpaddress(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["ipaddress"] = v - return -} - -func (p *CreatePrivateGatewayParams) SetNetmask(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["netmask"] = v - return -} - -func (p *CreatePrivateGatewayParams) SetNetworkofferingid(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["networkofferingid"] = v - return -} - -func (p *CreatePrivateGatewayParams) SetPhysicalnetworkid(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["physicalnetworkid"] = v - return -} - -func (p *CreatePrivateGatewayParams) SetSourcenatsupported(v bool) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["sourcenatsupported"] = v - return -} - -func (p *CreatePrivateGatewayParams) SetVlan(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["vlan"] = v - return -} - -func (p *CreatePrivateGatewayParams) SetVpcid(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["vpcid"] = v - return -} - -// You should always use this function to get a new CreatePrivateGatewayParams instance, -// as then you are sure you have configured all required params -func (s *VPCService) NewCreatePrivateGatewayParams(gateway string, ipaddress string, netmask string, vlan string, vpcid string) *CreatePrivateGatewayParams { - p := &CreatePrivateGatewayParams{} - p.p = make(map[string]interface{}) - p.p["gateway"] = gateway - p.p["ipaddress"] = ipaddress - p.p["netmask"] = netmask - p.p["vlan"] = vlan - p.p["vpcid"] = vpcid - return p -} - -// Creates a private gateway -func (s *VPCService) CreatePrivateGateway(p *CreatePrivateGatewayParams) (*CreatePrivateGatewayResponse, error) { - resp, err := s.cs.newRequest("createPrivateGateway", p.toURLValues()) - if err != nil { - return nil, err - } - - var r CreatePrivateGatewayResponse - if err := json.Unmarshal(resp, &r); err != nil { - return nil, err - } - - // If we have a async client, we need to wait for the async result - if s.cs.async { - b, err := s.cs.GetAsyncJobResult(r.JobID, s.cs.timeout) - if err != nil { - if err == AsyncTimeoutErr { - return &r, err - } - return nil, err - } - - b, err = getRawValue(b) - if err != nil { - return nil, err - } - - if err := json.Unmarshal(b, &r); err != nil { - return nil, err - } - } - return &r, nil -} - -type CreatePrivateGatewayResponse struct { - JobID string `json:"jobid,omitempty"` - Account string `json:"account,omitempty"` - Aclid string `json:"aclid,omitempty"` - Domain string `json:"domain,omitempty"` - Domainid string `json:"domainid,omitempty"` - Gateway string `json:"gateway,omitempty"` - Id string `json:"id,omitempty"` - Ipaddress string `json:"ipaddress,omitempty"` - Netmask string `json:"netmask,omitempty"` - Physicalnetworkid string `json:"physicalnetworkid,omitempty"` - Project string `json:"project,omitempty"` - Projectid string `json:"projectid,omitempty"` - Sourcenatsupported bool `json:"sourcenatsupported,omitempty"` - State string `json:"state,omitempty"` - Vlan string `json:"vlan,omitempty"` - Vpcid string `json:"vpcid,omitempty"` - Zoneid string `json:"zoneid,omitempty"` - Zonename string `json:"zonename,omitempty"` -} - -type ListPrivateGatewaysParams struct { - p map[string]interface{} -} - -func (p *ListPrivateGatewaysParams) toURLValues() url.Values { - u := url.Values{} - if p.p == nil { - return u - } - if v, found := p.p["account"]; found { - u.Set("account", v.(string)) - } - if v, found := p.p["domainid"]; found { - u.Set("domainid", v.(string)) - } - if v, found := p.p["id"]; found { - u.Set("id", v.(string)) - } - if v, found := p.p["ipaddress"]; found { - u.Set("ipaddress", v.(string)) - } - if v, found := p.p["isrecursive"]; found { - vv := strconv.FormatBool(v.(bool)) - u.Set("isrecursive", vv) - } - if v, found := p.p["keyword"]; found { - u.Set("keyword", v.(string)) - } - if v, found := p.p["listall"]; found { - vv := strconv.FormatBool(v.(bool)) - u.Set("listall", vv) - } - if v, found := p.p["page"]; found { - vv := strconv.Itoa(v.(int)) - u.Set("page", vv) - } - if v, found := p.p["pagesize"]; found { - vv := strconv.Itoa(v.(int)) - u.Set("pagesize", vv) - } - if v, found := p.p["projectid"]; found { - u.Set("projectid", v.(string)) - } - if v, found := p.p["state"]; found { - u.Set("state", v.(string)) - } - if v, found := p.p["vlan"]; found { - u.Set("vlan", v.(string)) - } - if v, found := p.p["vpcid"]; found { - u.Set("vpcid", v.(string)) - } - return u -} - -func (p *ListPrivateGatewaysParams) SetAccount(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["account"] = v - return -} - -func (p *ListPrivateGatewaysParams) SetDomainid(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["domainid"] = v - return -} - -func (p *ListPrivateGatewaysParams) SetId(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["id"] = v - return -} - -func (p *ListPrivateGatewaysParams) SetIpaddress(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["ipaddress"] = v - return -} - -func (p *ListPrivateGatewaysParams) SetIsrecursive(v bool) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["isrecursive"] = v - return -} - -func (p *ListPrivateGatewaysParams) SetKeyword(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["keyword"] = v - return -} - -func (p *ListPrivateGatewaysParams) SetListall(v bool) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["listall"] = v - return -} - -func (p *ListPrivateGatewaysParams) SetPage(v int) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["page"] = v - return -} - -func (p *ListPrivateGatewaysParams) SetPagesize(v int) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["pagesize"] = v - return -} - -func (p *ListPrivateGatewaysParams) SetProjectid(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["projectid"] = v - return -} - -func (p *ListPrivateGatewaysParams) SetState(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["state"] = v - return -} - -func (p *ListPrivateGatewaysParams) SetVlan(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["vlan"] = v - return -} - -func (p *ListPrivateGatewaysParams) SetVpcid(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["vpcid"] = v - return -} - -// You should always use this function to get a new ListPrivateGatewaysParams instance, -// as then you are sure you have configured all required params -func (s *VPCService) NewListPrivateGatewaysParams() *ListPrivateGatewaysParams { - p := &ListPrivateGatewaysParams{} - p.p = make(map[string]interface{}) - return p -} - -// This is a courtesy helper function, which in some cases may not work as expected! -func (s *VPCService) GetPrivateGatewayByID(id string, opts ...OptionFunc) (*PrivateGateway, int, error) { - p := &ListPrivateGatewaysParams{} - p.p = make(map[string]interface{}) - - p.p["id"] = id - - for _, fn := range opts { - if err := fn(s.cs, p); err != nil { - return nil, -1, err - } - } - - l, err := s.ListPrivateGateways(p) - if err != nil { - if strings.Contains(err.Error(), fmt.Sprintf( - "Invalid parameter id value=%s due to incorrect long value format, "+ - "or entity does not exist", id)) { - return nil, 0, fmt.Errorf("No match found for %s: %+v", id, l) - } - return nil, -1, err - } - - if l.Count == 0 { - return nil, l.Count, fmt.Errorf("No match found for %s: %+v", id, l) - } - - if l.Count == 1 { - return l.PrivateGateways[0], l.Count, nil - } - return nil, l.Count, fmt.Errorf("There is more then one result for PrivateGateway UUID: %s!", id) -} - -// List private gateways -func (s *VPCService) ListPrivateGateways(p *ListPrivateGatewaysParams) (*ListPrivateGatewaysResponse, error) { - resp, err := s.cs.newRequest("listPrivateGateways", p.toURLValues()) - if err != nil { - return nil, err - } - - var r ListPrivateGatewaysResponse - if err := json.Unmarshal(resp, &r); err != nil { - return nil, err - } - return &r, nil -} - -type ListPrivateGatewaysResponse struct { - Count int `json:"count"` - PrivateGateways []*PrivateGateway `json:"privategateway"` -} - -type PrivateGateway struct { - Account string `json:"account,omitempty"` - Aclid string `json:"aclid,omitempty"` - Domain string `json:"domain,omitempty"` - Domainid string `json:"domainid,omitempty"` - Gateway string `json:"gateway,omitempty"` - Id string `json:"id,omitempty"` - Ipaddress string `json:"ipaddress,omitempty"` - Netmask string `json:"netmask,omitempty"` - Physicalnetworkid string `json:"physicalnetworkid,omitempty"` - Project string `json:"project,omitempty"` - Projectid string `json:"projectid,omitempty"` - Sourcenatsupported bool `json:"sourcenatsupported,omitempty"` - State string `json:"state,omitempty"` - Vlan string `json:"vlan,omitempty"` - Vpcid string `json:"vpcid,omitempty"` - Zoneid string `json:"zoneid,omitempty"` - Zonename string `json:"zonename,omitempty"` -} - -type DeletePrivateGatewayParams struct { - p map[string]interface{} -} - -func (p *DeletePrivateGatewayParams) toURLValues() url.Values { - u := url.Values{} - if p.p == nil { - return u - } - if v, found := p.p["id"]; found { - u.Set("id", v.(string)) - } - return u -} - -func (p *DeletePrivateGatewayParams) SetId(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["id"] = v - return -} - -// You should always use this function to get a new DeletePrivateGatewayParams instance, -// as then you are sure you have configured all required params -func (s *VPCService) NewDeletePrivateGatewayParams(id string) *DeletePrivateGatewayParams { - p := &DeletePrivateGatewayParams{} - p.p = make(map[string]interface{}) - p.p["id"] = id - return p -} - -// Deletes a Private gateway -func (s *VPCService) DeletePrivateGateway(p *DeletePrivateGatewayParams) (*DeletePrivateGatewayResponse, error) { - resp, err := s.cs.newRequest("deletePrivateGateway", p.toURLValues()) - if err != nil { - return nil, err - } - - var r DeletePrivateGatewayResponse - if err := json.Unmarshal(resp, &r); err != nil { - return nil, err - } - - // If we have a async client, we need to wait for the async result - if s.cs.async { - b, err := s.cs.GetAsyncJobResult(r.JobID, s.cs.timeout) - if err != nil { - if err == AsyncTimeoutErr { - return &r, err - } - return nil, err - } - - if err := json.Unmarshal(b, &r); err != nil { - return nil, err - } - } - return &r, nil -} - -type DeletePrivateGatewayResponse struct { - JobID string `json:"jobid,omitempty"` - Displaytext string `json:"displaytext,omitempty"` - Success bool `json:"success,omitempty"` -} - -type CreateStaticRouteParams struct { - p map[string]interface{} -} - -func (p *CreateStaticRouteParams) toURLValues() url.Values { - u := url.Values{} - if p.p == nil { - return u - } - if v, found := p.p["cidr"]; found { - u.Set("cidr", v.(string)) - } - if v, found := p.p["gatewayid"]; found { - u.Set("gatewayid", v.(string)) - } - return u -} - -func (p *CreateStaticRouteParams) SetCidr(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["cidr"] = v - return -} - -func (p *CreateStaticRouteParams) SetGatewayid(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["gatewayid"] = v - return -} - -// You should always use this function to get a new CreateStaticRouteParams instance, -// as then you are sure you have configured all required params -func (s *VPCService) NewCreateStaticRouteParams(cidr string, gatewayid string) *CreateStaticRouteParams { - p := &CreateStaticRouteParams{} - p.p = make(map[string]interface{}) - p.p["cidr"] = cidr - p.p["gatewayid"] = gatewayid - return p -} - -// Creates a static route -func (s *VPCService) CreateStaticRoute(p *CreateStaticRouteParams) (*CreateStaticRouteResponse, error) { - resp, err := s.cs.newRequest("createStaticRoute", p.toURLValues()) - if err != nil { - return nil, err - } - - var r CreateStaticRouteResponse - if err := json.Unmarshal(resp, &r); err != nil { - return nil, err - } - - // If we have a async client, we need to wait for the async result - if s.cs.async { - b, err := s.cs.GetAsyncJobResult(r.JobID, s.cs.timeout) - if err != nil { - if err == AsyncTimeoutErr { - return &r, err - } - return nil, err - } - - b, err = getRawValue(b) - if err != nil { - return nil, err - } - - if err := json.Unmarshal(b, &r); err != nil { - return nil, err - } - } - return &r, nil -} - -type CreateStaticRouteResponse struct { - JobID string `json:"jobid,omitempty"` - Account string `json:"account,omitempty"` - Cidr string `json:"cidr,omitempty"` - Domain string `json:"domain,omitempty"` - Domainid string `json:"domainid,omitempty"` - Gatewayid string `json:"gatewayid,omitempty"` - Id string `json:"id,omitempty"` - Project string `json:"project,omitempty"` - Projectid string `json:"projectid,omitempty"` - State string `json:"state,omitempty"` - Tags []struct { - Account string `json:"account,omitempty"` - Customer string `json:"customer,omitempty"` - Domain string `json:"domain,omitempty"` - Domainid string `json:"domainid,omitempty"` - Key string `json:"key,omitempty"` - Project string `json:"project,omitempty"` - Projectid string `json:"projectid,omitempty"` - Resourceid string `json:"resourceid,omitempty"` - Resourcetype string `json:"resourcetype,omitempty"` - Value string `json:"value,omitempty"` - } `json:"tags,omitempty"` - Vpcid string `json:"vpcid,omitempty"` -} - -type DeleteStaticRouteParams struct { - p map[string]interface{} -} - -func (p *DeleteStaticRouteParams) toURLValues() url.Values { - u := url.Values{} - if p.p == nil { - return u - } - if v, found := p.p["id"]; found { - u.Set("id", v.(string)) - } - return u -} - -func (p *DeleteStaticRouteParams) SetId(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["id"] = v - return -} - -// You should always use this function to get a new DeleteStaticRouteParams instance, -// as then you are sure you have configured all required params -func (s *VPCService) NewDeleteStaticRouteParams(id string) *DeleteStaticRouteParams { - p := &DeleteStaticRouteParams{} - p.p = make(map[string]interface{}) - p.p["id"] = id - return p -} - -// Deletes a static route -func (s *VPCService) DeleteStaticRoute(p *DeleteStaticRouteParams) (*DeleteStaticRouteResponse, error) { - resp, err := s.cs.newRequest("deleteStaticRoute", p.toURLValues()) - if err != nil { - return nil, err - } - - var r DeleteStaticRouteResponse - if err := json.Unmarshal(resp, &r); err != nil { - return nil, err - } - - // If we have a async client, we need to wait for the async result - if s.cs.async { - b, err := s.cs.GetAsyncJobResult(r.JobID, s.cs.timeout) - if err != nil { - if err == AsyncTimeoutErr { - return &r, err - } - return nil, err - } - - if err := json.Unmarshal(b, &r); err != nil { - return nil, err - } - } - return &r, nil -} - -type DeleteStaticRouteResponse struct { - JobID string `json:"jobid,omitempty"` - Displaytext string `json:"displaytext,omitempty"` - Success bool `json:"success,omitempty"` -} - -type ListStaticRoutesParams struct { - p map[string]interface{} -} - -func (p *ListStaticRoutesParams) toURLValues() url.Values { - u := url.Values{} - if p.p == nil { - return u - } - if v, found := p.p["account"]; found { - u.Set("account", v.(string)) - } - if v, found := p.p["domainid"]; found { - u.Set("domainid", v.(string)) - } - if v, found := p.p["gatewayid"]; found { - u.Set("gatewayid", v.(string)) - } - if v, found := p.p["id"]; found { - u.Set("id", v.(string)) - } - if v, found := p.p["isrecursive"]; found { - vv := strconv.FormatBool(v.(bool)) - u.Set("isrecursive", vv) - } - if v, found := p.p["keyword"]; found { - u.Set("keyword", v.(string)) - } - if v, found := p.p["listall"]; found { - vv := strconv.FormatBool(v.(bool)) - u.Set("listall", vv) - } - if v, found := p.p["page"]; found { - vv := strconv.Itoa(v.(int)) - u.Set("page", vv) - } - if v, found := p.p["pagesize"]; found { - vv := strconv.Itoa(v.(int)) - u.Set("pagesize", vv) - } - if v, found := p.p["projectid"]; found { - u.Set("projectid", v.(string)) - } - if v, found := p.p["tags"]; found { - i := 0 - for k, vv := range v.(map[string]string) { - u.Set(fmt.Sprintf("tags[%d].key", i), k) - u.Set(fmt.Sprintf("tags[%d].value", i), vv) - i++ - } - } - if v, found := p.p["vpcid"]; found { - u.Set("vpcid", v.(string)) - } - return u -} - -func (p *ListStaticRoutesParams) SetAccount(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["account"] = v - return -} - -func (p *ListStaticRoutesParams) SetDomainid(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["domainid"] = v - return -} - -func (p *ListStaticRoutesParams) SetGatewayid(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["gatewayid"] = v - return -} - -func (p *ListStaticRoutesParams) SetId(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["id"] = v - return -} - -func (p *ListStaticRoutesParams) SetIsrecursive(v bool) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["isrecursive"] = v - return -} - -func (p *ListStaticRoutesParams) SetKeyword(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["keyword"] = v - return -} - -func (p *ListStaticRoutesParams) SetListall(v bool) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["listall"] = v - return -} - -func (p *ListStaticRoutesParams) SetPage(v int) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["page"] = v - return -} - -func (p *ListStaticRoutesParams) SetPagesize(v int) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["pagesize"] = v - return -} - -func (p *ListStaticRoutesParams) SetProjectid(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["projectid"] = v - return -} - -func (p *ListStaticRoutesParams) SetTags(v map[string]string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["tags"] = v - return -} - -func (p *ListStaticRoutesParams) SetVpcid(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["vpcid"] = v - return -} - -// You should always use this function to get a new ListStaticRoutesParams instance, -// as then you are sure you have configured all required params -func (s *VPCService) NewListStaticRoutesParams() *ListStaticRoutesParams { - p := &ListStaticRoutesParams{} - p.p = make(map[string]interface{}) - return p -} - -// This is a courtesy helper function, which in some cases may not work as expected! -func (s *VPCService) GetStaticRouteByID(id string, opts ...OptionFunc) (*StaticRoute, int, error) { - p := &ListStaticRoutesParams{} - p.p = make(map[string]interface{}) - - p.p["id"] = id - - for _, fn := range opts { - if err := fn(s.cs, p); err != nil { - return nil, -1, err - } - } - - l, err := s.ListStaticRoutes(p) - if err != nil { - if strings.Contains(err.Error(), fmt.Sprintf( - "Invalid parameter id value=%s due to incorrect long value format, "+ - "or entity does not exist", id)) { - return nil, 0, fmt.Errorf("No match found for %s: %+v", id, l) - } - return nil, -1, err - } - - if l.Count == 0 { - return nil, l.Count, fmt.Errorf("No match found for %s: %+v", id, l) - } - - if l.Count == 1 { - return l.StaticRoutes[0], l.Count, nil - } - return nil, l.Count, fmt.Errorf("There is more then one result for StaticRoute UUID: %s!", id) -} - -// Lists all static routes -func (s *VPCService) ListStaticRoutes(p *ListStaticRoutesParams) (*ListStaticRoutesResponse, error) { - resp, err := s.cs.newRequest("listStaticRoutes", p.toURLValues()) - if err != nil { - return nil, err - } - - var r ListStaticRoutesResponse - if err := json.Unmarshal(resp, &r); err != nil { - return nil, err - } - return &r, nil -} - -type ListStaticRoutesResponse struct { - Count int `json:"count"` - StaticRoutes []*StaticRoute `json:"staticroute"` -} - -type StaticRoute struct { - Account string `json:"account,omitempty"` - Cidr string `json:"cidr,omitempty"` - Domain string `json:"domain,omitempty"` - Domainid string `json:"domainid,omitempty"` - Gatewayid string `json:"gatewayid,omitempty"` - Id string `json:"id,omitempty"` - Project string `json:"project,omitempty"` - Projectid string `json:"projectid,omitempty"` - State string `json:"state,omitempty"` - Tags []struct { - Account string `json:"account,omitempty"` - Customer string `json:"customer,omitempty"` - Domain string `json:"domain,omitempty"` - Domainid string `json:"domainid,omitempty"` - Key string `json:"key,omitempty"` - Project string `json:"project,omitempty"` - Projectid string `json:"projectid,omitempty"` - Resourceid string `json:"resourceid,omitempty"` - Resourcetype string `json:"resourcetype,omitempty"` - Value string `json:"value,omitempty"` - } `json:"tags,omitempty"` - Vpcid string `json:"vpcid,omitempty"` + JobID string `json:"jobid"` + Created string `json:"created"` + Displaytext string `json:"displaytext"` + Distributedvpcrouter bool `json:"distributedvpcrouter"` + Id string `json:"id"` + Isdefault bool `json:"isdefault"` + Name string `json:"name"` + Service []UpdateVPCOfferingResponseService `json:"service"` + State string `json:"state"` + SupportsregionLevelvpc bool `json:"supportsregionLevelvpc"` +} + +type UpdateVPCOfferingResponseService struct { + Capability []UpdateVPCOfferingResponseServiceCapability `json:"capability"` + Name string `json:"name"` + Provider []UpdateVPCOfferingResponseServiceProvider `json:"provider"` +} + +type UpdateVPCOfferingResponseServiceProvider struct { + Canenableindividualservice bool `json:"canenableindividualservice"` + Destinationphysicalnetworkid string `json:"destinationphysicalnetworkid"` + Id string `json:"id"` + Name string `json:"name"` + Physicalnetworkid string `json:"physicalnetworkid"` + Servicelist []string `json:"servicelist"` + State string `json:"state"` +} + +type UpdateVPCOfferingResponseServiceCapability struct { + Canchooseservicecapability bool `json:"canchooseservicecapability"` + Name string `json:"name"` + Value string `json:"value"` } diff --git a/vendor/github.com/xanzy/go-cloudstack/cloudstack/VPNService.go b/vendor/github.com/xanzy/go-cloudstack/cloudstack/VPNService.go index 544b17324..796de853c 100644 --- a/vendor/github.com/xanzy/go-cloudstack/cloudstack/VPNService.go +++ b/vendor/github.com/xanzy/go-cloudstack/cloudstack/VPNService.go @@ -1,5 +1,5 @@ // -// Copyright 2016, Sander van Harmelen +// Copyright 2018, Sander van Harmelen // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -24,6 +24,130 @@ import ( "strings" ) +type AddVpnUserParams struct { + p map[string]interface{} +} + +func (p *AddVpnUserParams) toURLValues() url.Values { + u := url.Values{} + if p.p == nil { + return u + } + if v, found := p.p["account"]; found { + u.Set("account", v.(string)) + } + if v, found := p.p["domainid"]; found { + u.Set("domainid", v.(string)) + } + if v, found := p.p["password"]; found { + u.Set("password", v.(string)) + } + if v, found := p.p["projectid"]; found { + u.Set("projectid", v.(string)) + } + if v, found := p.p["username"]; found { + u.Set("username", v.(string)) + } + return u +} + +func (p *AddVpnUserParams) SetAccount(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["account"] = v + return +} + +func (p *AddVpnUserParams) SetDomainid(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["domainid"] = v + return +} + +func (p *AddVpnUserParams) SetPassword(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["password"] = v + return +} + +func (p *AddVpnUserParams) SetProjectid(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["projectid"] = v + return +} + +func (p *AddVpnUserParams) SetUsername(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["username"] = v + return +} + +// You should always use this function to get a new AddVpnUserParams instance, +// as then you are sure you have configured all required params +func (s *VPNService) NewAddVpnUserParams(password string, username string) *AddVpnUserParams { + p := &AddVpnUserParams{} + p.p = make(map[string]interface{}) + p.p["password"] = password + p.p["username"] = username + return p +} + +// Adds vpn users +func (s *VPNService) AddVpnUser(p *AddVpnUserParams) (*AddVpnUserResponse, error) { + resp, err := s.cs.newRequest("addVpnUser", p.toURLValues()) + if err != nil { + return nil, err + } + + var r AddVpnUserResponse + if err := json.Unmarshal(resp, &r); err != nil { + return nil, err + } + + // If we have a async client, we need to wait for the async result + if s.cs.async { + b, err := s.cs.GetAsyncJobResult(r.JobID, s.cs.timeout) + if err != nil { + if err == AsyncTimeoutErr { + return &r, err + } + return nil, err + } + + b, err = getRawValue(b) + if err != nil { + return nil, err + } + + if err := json.Unmarshal(b, &r); err != nil { + return nil, err + } + } + + return &r, nil +} + +type AddVpnUserResponse struct { + JobID string `json:"jobid"` + Account string `json:"account"` + Domain string `json:"domain"` + Domainid string `json:"domainid"` + Id string `json:"id"` + Project string `json:"project"` + Projectid string `json:"projectid"` + State string `json:"state"` + Username string `json:"username"` +} + type CreateRemoteAccessVpnParams struct { p map[string]interface{} } @@ -144,162 +268,53 @@ func (s *VPNService) CreateRemoteAccessVpn(p *CreateRemoteAccessVpnParams) (*Cre return nil, err } } + return &r, nil } type CreateRemoteAccessVpnResponse struct { - JobID string `json:"jobid,omitempty"` - Account string `json:"account,omitempty"` - Domain string `json:"domain,omitempty"` - Domainid string `json:"domainid,omitempty"` - Fordisplay bool `json:"fordisplay,omitempty"` - Id string `json:"id,omitempty"` - Iprange string `json:"iprange,omitempty"` - Presharedkey string `json:"presharedkey,omitempty"` - Project string `json:"project,omitempty"` - Projectid string `json:"projectid,omitempty"` - Publicip string `json:"publicip,omitempty"` - Publicipid string `json:"publicipid,omitempty"` - State string `json:"state,omitempty"` + JobID string `json:"jobid"` + Account string `json:"account"` + Domain string `json:"domain"` + Domainid string `json:"domainid"` + Fordisplay bool `json:"fordisplay"` + Id string `json:"id"` + Iprange string `json:"iprange"` + Presharedkey string `json:"presharedkey"` + Project string `json:"project"` + Projectid string `json:"projectid"` + Publicip string `json:"publicip"` + Publicipid string `json:"publicipid"` + State string `json:"state"` } -type DeleteRemoteAccessVpnParams struct { +type CreateVpnConnectionParams struct { p map[string]interface{} } -func (p *DeleteRemoteAccessVpnParams) toURLValues() url.Values { +func (p *CreateVpnConnectionParams) toURLValues() url.Values { u := url.Values{} if p.p == nil { return u } - if v, found := p.p["publicipid"]; found { - u.Set("publicipid", v.(string)) - } - return u -} - -func (p *DeleteRemoteAccessVpnParams) SetPublicipid(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["publicipid"] = v - return -} - -// You should always use this function to get a new DeleteRemoteAccessVpnParams instance, -// as then you are sure you have configured all required params -func (s *VPNService) NewDeleteRemoteAccessVpnParams(publicipid string) *DeleteRemoteAccessVpnParams { - p := &DeleteRemoteAccessVpnParams{} - p.p = make(map[string]interface{}) - p.p["publicipid"] = publicipid - return p -} - -// Destroys a l2tp/ipsec remote access vpn -func (s *VPNService) DeleteRemoteAccessVpn(p *DeleteRemoteAccessVpnParams) (*DeleteRemoteAccessVpnResponse, error) { - resp, err := s.cs.newRequest("deleteRemoteAccessVpn", p.toURLValues()) - if err != nil { - return nil, err - } - - var r DeleteRemoteAccessVpnResponse - if err := json.Unmarshal(resp, &r); err != nil { - return nil, err - } - - // If we have a async client, we need to wait for the async result - if s.cs.async { - b, err := s.cs.GetAsyncJobResult(r.JobID, s.cs.timeout) - if err != nil { - if err == AsyncTimeoutErr { - return &r, err - } - return nil, err - } - - if err := json.Unmarshal(b, &r); err != nil { - return nil, err - } - } - return &r, nil -} - -type DeleteRemoteAccessVpnResponse struct { - JobID string `json:"jobid,omitempty"` - Displaytext string `json:"displaytext,omitempty"` - Success bool `json:"success,omitempty"` -} - -type ListRemoteAccessVpnsParams struct { - p map[string]interface{} -} - -func (p *ListRemoteAccessVpnsParams) toURLValues() url.Values { - u := url.Values{} - if p.p == nil { - return u - } - if v, found := p.p["account"]; found { - u.Set("account", v.(string)) - } - if v, found := p.p["domainid"]; found { - u.Set("domainid", v.(string)) - } if v, found := p.p["fordisplay"]; found { vv := strconv.FormatBool(v.(bool)) u.Set("fordisplay", vv) } - if v, found := p.p["id"]; found { - u.Set("id", v.(string)) - } - if v, found := p.p["isrecursive"]; found { + if v, found := p.p["passive"]; found { vv := strconv.FormatBool(v.(bool)) - u.Set("isrecursive", vv) + u.Set("passive", vv) } - if v, found := p.p["keyword"]; found { - u.Set("keyword", v.(string)) + if v, found := p.p["s2scustomergatewayid"]; found { + u.Set("s2scustomergatewayid", v.(string)) } - if v, found := p.p["listall"]; found { - vv := strconv.FormatBool(v.(bool)) - u.Set("listall", vv) - } - if v, found := p.p["networkid"]; found { - u.Set("networkid", v.(string)) - } - if v, found := p.p["page"]; found { - vv := strconv.Itoa(v.(int)) - u.Set("page", vv) - } - if v, found := p.p["pagesize"]; found { - vv := strconv.Itoa(v.(int)) - u.Set("pagesize", vv) - } - if v, found := p.p["projectid"]; found { - u.Set("projectid", v.(string)) - } - if v, found := p.p["publicipid"]; found { - u.Set("publicipid", v.(string)) + if v, found := p.p["s2svpngatewayid"]; found { + u.Set("s2svpngatewayid", v.(string)) } return u } -func (p *ListRemoteAccessVpnsParams) SetAccount(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["account"] = v - return -} - -func (p *ListRemoteAccessVpnsParams) SetDomainid(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["domainid"] = v - return -} - -func (p *ListRemoteAccessVpnsParams) SetFordisplay(v bool) { +func (p *CreateVpnConnectionParams) SetFordisplay(v bool) { if p.p == nil { p.p = make(map[string]interface{}) } @@ -307,216 +322,48 @@ func (p *ListRemoteAccessVpnsParams) SetFordisplay(v bool) { return } -func (p *ListRemoteAccessVpnsParams) SetId(v string) { +func (p *CreateVpnConnectionParams) SetPassive(v bool) { if p.p == nil { p.p = make(map[string]interface{}) } - p.p["id"] = v + p.p["passive"] = v return } -func (p *ListRemoteAccessVpnsParams) SetIsrecursive(v bool) { +func (p *CreateVpnConnectionParams) SetS2scustomergatewayid(v string) { if p.p == nil { p.p = make(map[string]interface{}) } - p.p["isrecursive"] = v + p.p["s2scustomergatewayid"] = v return } -func (p *ListRemoteAccessVpnsParams) SetKeyword(v string) { +func (p *CreateVpnConnectionParams) SetS2svpngatewayid(v string) { if p.p == nil { p.p = make(map[string]interface{}) } - p.p["keyword"] = v + p.p["s2svpngatewayid"] = v return } -func (p *ListRemoteAccessVpnsParams) SetListall(v bool) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["listall"] = v - return -} - -func (p *ListRemoteAccessVpnsParams) SetNetworkid(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["networkid"] = v - return -} - -func (p *ListRemoteAccessVpnsParams) SetPage(v int) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["page"] = v - return -} - -func (p *ListRemoteAccessVpnsParams) SetPagesize(v int) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["pagesize"] = v - return -} - -func (p *ListRemoteAccessVpnsParams) SetProjectid(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["projectid"] = v - return -} - -func (p *ListRemoteAccessVpnsParams) SetPublicipid(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["publicipid"] = v - return -} - -// You should always use this function to get a new ListRemoteAccessVpnsParams instance, +// You should always use this function to get a new CreateVpnConnectionParams instance, // as then you are sure you have configured all required params -func (s *VPNService) NewListRemoteAccessVpnsParams() *ListRemoteAccessVpnsParams { - p := &ListRemoteAccessVpnsParams{} +func (s *VPNService) NewCreateVpnConnectionParams(s2scustomergatewayid string, s2svpngatewayid string) *CreateVpnConnectionParams { + p := &CreateVpnConnectionParams{} p.p = make(map[string]interface{}) + p.p["s2scustomergatewayid"] = s2scustomergatewayid + p.p["s2svpngatewayid"] = s2svpngatewayid return p } -// This is a courtesy helper function, which in some cases may not work as expected! -func (s *VPNService) GetRemoteAccessVpnByID(id string, opts ...OptionFunc) (*RemoteAccessVpn, int, error) { - p := &ListRemoteAccessVpnsParams{} - p.p = make(map[string]interface{}) - - p.p["id"] = id - - for _, fn := range opts { - if err := fn(s.cs, p); err != nil { - return nil, -1, err - } - } - - l, err := s.ListRemoteAccessVpns(p) - if err != nil { - if strings.Contains(err.Error(), fmt.Sprintf( - "Invalid parameter id value=%s due to incorrect long value format, "+ - "or entity does not exist", id)) { - return nil, 0, fmt.Errorf("No match found for %s: %+v", id, l) - } - return nil, -1, err - } - - if l.Count == 0 { - return nil, l.Count, fmt.Errorf("No match found for %s: %+v", id, l) - } - - if l.Count == 1 { - return l.RemoteAccessVpns[0], l.Count, nil - } - return nil, l.Count, fmt.Errorf("There is more then one result for RemoteAccessVpn UUID: %s!", id) -} - -// Lists remote access vpns -func (s *VPNService) ListRemoteAccessVpns(p *ListRemoteAccessVpnsParams) (*ListRemoteAccessVpnsResponse, error) { - resp, err := s.cs.newRequest("listRemoteAccessVpns", p.toURLValues()) +// Create site to site vpn connection +func (s *VPNService) CreateVpnConnection(p *CreateVpnConnectionParams) (*CreateVpnConnectionResponse, error) { + resp, err := s.cs.newRequest("createVpnConnection", p.toURLValues()) if err != nil { return nil, err } - var r ListRemoteAccessVpnsResponse - if err := json.Unmarshal(resp, &r); err != nil { - return nil, err - } - return &r, nil -} - -type ListRemoteAccessVpnsResponse struct { - Count int `json:"count"` - RemoteAccessVpns []*RemoteAccessVpn `json:"remoteaccessvpn"` -} - -type RemoteAccessVpn struct { - Account string `json:"account,omitempty"` - Domain string `json:"domain,omitempty"` - Domainid string `json:"domainid,omitempty"` - Fordisplay bool `json:"fordisplay,omitempty"` - Id string `json:"id,omitempty"` - Iprange string `json:"iprange,omitempty"` - Presharedkey string `json:"presharedkey,omitempty"` - Project string `json:"project,omitempty"` - Projectid string `json:"projectid,omitempty"` - Publicip string `json:"publicip,omitempty"` - Publicipid string `json:"publicipid,omitempty"` - State string `json:"state,omitempty"` -} - -type UpdateRemoteAccessVpnParams struct { - p map[string]interface{} -} - -func (p *UpdateRemoteAccessVpnParams) toURLValues() url.Values { - u := url.Values{} - if p.p == nil { - return u - } - if v, found := p.p["customid"]; found { - u.Set("customid", v.(string)) - } - if v, found := p.p["fordisplay"]; found { - vv := strconv.FormatBool(v.(bool)) - u.Set("fordisplay", vv) - } - if v, found := p.p["id"]; found { - u.Set("id", v.(string)) - } - return u -} - -func (p *UpdateRemoteAccessVpnParams) SetCustomid(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["customid"] = v - return -} - -func (p *UpdateRemoteAccessVpnParams) SetFordisplay(v bool) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["fordisplay"] = v - return -} - -func (p *UpdateRemoteAccessVpnParams) SetId(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["id"] = v - return -} - -// You should always use this function to get a new UpdateRemoteAccessVpnParams instance, -// as then you are sure you have configured all required params -func (s *VPNService) NewUpdateRemoteAccessVpnParams(id string) *UpdateRemoteAccessVpnParams { - p := &UpdateRemoteAccessVpnParams{} - p.p = make(map[string]interface{}) - p.p["id"] = id - return p -} - -// Updates remote access vpn -func (s *VPNService) UpdateRemoteAccessVpn(p *UpdateRemoteAccessVpnParams) (*UpdateRemoteAccessVpnResponse, error) { - resp, err := s.cs.newRequest("updateRemoteAccessVpn", p.toURLValues()) - if err != nil { - return nil, err - } - - var r UpdateRemoteAccessVpnResponse + var r CreateVpnConnectionResponse if err := json.Unmarshal(resp, &r); err != nil { return nil, err } @@ -540,443 +387,35 @@ func (s *VPNService) UpdateRemoteAccessVpn(p *UpdateRemoteAccessVpnParams) (*Upd return nil, err } } + return &r, nil } -type UpdateRemoteAccessVpnResponse struct { - JobID string `json:"jobid,omitempty"` - Account string `json:"account,omitempty"` - Domain string `json:"domain,omitempty"` - Domainid string `json:"domainid,omitempty"` - Fordisplay bool `json:"fordisplay,omitempty"` - Id string `json:"id,omitempty"` - Iprange string `json:"iprange,omitempty"` - Presharedkey string `json:"presharedkey,omitempty"` - Project string `json:"project,omitempty"` - Projectid string `json:"projectid,omitempty"` - Publicip string `json:"publicip,omitempty"` - Publicipid string `json:"publicipid,omitempty"` - State string `json:"state,omitempty"` -} - -type AddVpnUserParams struct { - p map[string]interface{} -} - -func (p *AddVpnUserParams) toURLValues() url.Values { - u := url.Values{} - if p.p == nil { - return u - } - if v, found := p.p["account"]; found { - u.Set("account", v.(string)) - } - if v, found := p.p["domainid"]; found { - u.Set("domainid", v.(string)) - } - if v, found := p.p["password"]; found { - u.Set("password", v.(string)) - } - if v, found := p.p["projectid"]; found { - u.Set("projectid", v.(string)) - } - if v, found := p.p["username"]; found { - u.Set("username", v.(string)) - } - return u -} - -func (p *AddVpnUserParams) SetAccount(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["account"] = v - return -} - -func (p *AddVpnUserParams) SetDomainid(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["domainid"] = v - return -} - -func (p *AddVpnUserParams) SetPassword(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["password"] = v - return -} - -func (p *AddVpnUserParams) SetProjectid(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["projectid"] = v - return -} - -func (p *AddVpnUserParams) SetUsername(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["username"] = v - return -} - -// You should always use this function to get a new AddVpnUserParams instance, -// as then you are sure you have configured all required params -func (s *VPNService) NewAddVpnUserParams(password string, username string) *AddVpnUserParams { - p := &AddVpnUserParams{} - p.p = make(map[string]interface{}) - p.p["password"] = password - p.p["username"] = username - return p -} - -// Adds vpn users -func (s *VPNService) AddVpnUser(p *AddVpnUserParams) (*AddVpnUserResponse, error) { - resp, err := s.cs.newRequest("addVpnUser", p.toURLValues()) - if err != nil { - return nil, err - } - - var r AddVpnUserResponse - if err := json.Unmarshal(resp, &r); err != nil { - return nil, err - } - - // If we have a async client, we need to wait for the async result - if s.cs.async { - b, err := s.cs.GetAsyncJobResult(r.JobID, s.cs.timeout) - if err != nil { - if err == AsyncTimeoutErr { - return &r, err - } - return nil, err - } - - b, err = getRawValue(b) - if err != nil { - return nil, err - } - - if err := json.Unmarshal(b, &r); err != nil { - return nil, err - } - } - return &r, nil -} - -type AddVpnUserResponse struct { - JobID string `json:"jobid,omitempty"` - Account string `json:"account,omitempty"` - Domain string `json:"domain,omitempty"` - Domainid string `json:"domainid,omitempty"` - Id string `json:"id,omitempty"` - Project string `json:"project,omitempty"` - Projectid string `json:"projectid,omitempty"` - State string `json:"state,omitempty"` - Username string `json:"username,omitempty"` -} - -type RemoveVpnUserParams struct { - p map[string]interface{} -} - -func (p *RemoveVpnUserParams) toURLValues() url.Values { - u := url.Values{} - if p.p == nil { - return u - } - if v, found := p.p["account"]; found { - u.Set("account", v.(string)) - } - if v, found := p.p["domainid"]; found { - u.Set("domainid", v.(string)) - } - if v, found := p.p["projectid"]; found { - u.Set("projectid", v.(string)) - } - if v, found := p.p["username"]; found { - u.Set("username", v.(string)) - } - return u -} - -func (p *RemoveVpnUserParams) SetAccount(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["account"] = v - return -} - -func (p *RemoveVpnUserParams) SetDomainid(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["domainid"] = v - return -} - -func (p *RemoveVpnUserParams) SetProjectid(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["projectid"] = v - return -} - -func (p *RemoveVpnUserParams) SetUsername(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["username"] = v - return -} - -// You should always use this function to get a new RemoveVpnUserParams instance, -// as then you are sure you have configured all required params -func (s *VPNService) NewRemoveVpnUserParams(username string) *RemoveVpnUserParams { - p := &RemoveVpnUserParams{} - p.p = make(map[string]interface{}) - p.p["username"] = username - return p -} - -// Removes vpn user -func (s *VPNService) RemoveVpnUser(p *RemoveVpnUserParams) (*RemoveVpnUserResponse, error) { - resp, err := s.cs.newRequest("removeVpnUser", p.toURLValues()) - if err != nil { - return nil, err - } - - var r RemoveVpnUserResponse - if err := json.Unmarshal(resp, &r); err != nil { - return nil, err - } - - // If we have a async client, we need to wait for the async result - if s.cs.async { - b, err := s.cs.GetAsyncJobResult(r.JobID, s.cs.timeout) - if err != nil { - if err == AsyncTimeoutErr { - return &r, err - } - return nil, err - } - - if err := json.Unmarshal(b, &r); err != nil { - return nil, err - } - } - return &r, nil -} - -type RemoveVpnUserResponse struct { - JobID string `json:"jobid,omitempty"` - Displaytext string `json:"displaytext,omitempty"` - Success bool `json:"success,omitempty"` -} - -type ListVpnUsersParams struct { - p map[string]interface{} -} - -func (p *ListVpnUsersParams) toURLValues() url.Values { - u := url.Values{} - if p.p == nil { - return u - } - if v, found := p.p["account"]; found { - u.Set("account", v.(string)) - } - if v, found := p.p["domainid"]; found { - u.Set("domainid", v.(string)) - } - if v, found := p.p["id"]; found { - u.Set("id", v.(string)) - } - if v, found := p.p["isrecursive"]; found { - vv := strconv.FormatBool(v.(bool)) - u.Set("isrecursive", vv) - } - if v, found := p.p["keyword"]; found { - u.Set("keyword", v.(string)) - } - if v, found := p.p["listall"]; found { - vv := strconv.FormatBool(v.(bool)) - u.Set("listall", vv) - } - if v, found := p.p["page"]; found { - vv := strconv.Itoa(v.(int)) - u.Set("page", vv) - } - if v, found := p.p["pagesize"]; found { - vv := strconv.Itoa(v.(int)) - u.Set("pagesize", vv) - } - if v, found := p.p["projectid"]; found { - u.Set("projectid", v.(string)) - } - if v, found := p.p["username"]; found { - u.Set("username", v.(string)) - } - return u -} - -func (p *ListVpnUsersParams) SetAccount(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["account"] = v - return -} - -func (p *ListVpnUsersParams) SetDomainid(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["domainid"] = v - return -} - -func (p *ListVpnUsersParams) SetId(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["id"] = v - return -} - -func (p *ListVpnUsersParams) SetIsrecursive(v bool) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["isrecursive"] = v - return -} - -func (p *ListVpnUsersParams) SetKeyword(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["keyword"] = v - return -} - -func (p *ListVpnUsersParams) SetListall(v bool) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["listall"] = v - return -} - -func (p *ListVpnUsersParams) SetPage(v int) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["page"] = v - return -} - -func (p *ListVpnUsersParams) SetPagesize(v int) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["pagesize"] = v - return -} - -func (p *ListVpnUsersParams) SetProjectid(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["projectid"] = v - return -} - -func (p *ListVpnUsersParams) SetUsername(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["username"] = v - return -} - -// You should always use this function to get a new ListVpnUsersParams instance, -// as then you are sure you have configured all required params -func (s *VPNService) NewListVpnUsersParams() *ListVpnUsersParams { - p := &ListVpnUsersParams{} - p.p = make(map[string]interface{}) - return p -} - -// This is a courtesy helper function, which in some cases may not work as expected! -func (s *VPNService) GetVpnUserByID(id string, opts ...OptionFunc) (*VpnUser, int, error) { - p := &ListVpnUsersParams{} - p.p = make(map[string]interface{}) - - p.p["id"] = id - - for _, fn := range opts { - if err := fn(s.cs, p); err != nil { - return nil, -1, err - } - } - - l, err := s.ListVpnUsers(p) - if err != nil { - if strings.Contains(err.Error(), fmt.Sprintf( - "Invalid parameter id value=%s due to incorrect long value format, "+ - "or entity does not exist", id)) { - return nil, 0, fmt.Errorf("No match found for %s: %+v", id, l) - } - return nil, -1, err - } - - if l.Count == 0 { - return nil, l.Count, fmt.Errorf("No match found for %s: %+v", id, l) - } - - if l.Count == 1 { - return l.VpnUsers[0], l.Count, nil - } - return nil, l.Count, fmt.Errorf("There is more then one result for VpnUser UUID: %s!", id) -} - -// Lists vpn users -func (s *VPNService) ListVpnUsers(p *ListVpnUsersParams) (*ListVpnUsersResponse, error) { - resp, err := s.cs.newRequest("listVpnUsers", p.toURLValues()) - if err != nil { - return nil, err - } - - var r ListVpnUsersResponse - if err := json.Unmarshal(resp, &r); err != nil { - return nil, err - } - return &r, nil -} - -type ListVpnUsersResponse struct { - Count int `json:"count"` - VpnUsers []*VpnUser `json:"vpnuser"` -} - -type VpnUser struct { - Account string `json:"account,omitempty"` - Domain string `json:"domain,omitempty"` - Domainid string `json:"domainid,omitempty"` - Id string `json:"id,omitempty"` - Project string `json:"project,omitempty"` - Projectid string `json:"projectid,omitempty"` - State string `json:"state,omitempty"` - Username string `json:"username,omitempty"` +type CreateVpnConnectionResponse struct { + JobID string `json:"jobid"` + Account string `json:"account"` + Cidrlist string `json:"cidrlist"` + Created string `json:"created"` + Domain string `json:"domain"` + Domainid string `json:"domainid"` + Dpd bool `json:"dpd"` + Esplifetime int64 `json:"esplifetime"` + Esppolicy string `json:"esppolicy"` + Forceencap bool `json:"forceencap"` + Fordisplay bool `json:"fordisplay"` + Gateway string `json:"gateway"` + Id string `json:"id"` + Ikelifetime int64 `json:"ikelifetime"` + Ikepolicy string `json:"ikepolicy"` + Ipsecpsk string `json:"ipsecpsk"` + Passive bool `json:"passive"` + Project string `json:"project"` + Projectid string `json:"projectid"` + Publicip string `json:"publicip"` + Removed string `json:"removed"` + S2scustomergatewayid string `json:"s2scustomergatewayid"` + S2svpngatewayid string `json:"s2svpngatewayid"` + State string `json:"state"` } type CreateVpnCustomerGatewayParams struct { @@ -1182,29 +621,30 @@ func (s *VPNService) CreateVpnCustomerGateway(p *CreateVpnCustomerGatewayParams) return nil, err } } + return &r, nil } type CreateVpnCustomerGatewayResponse struct { - JobID string `json:"jobid,omitempty"` - Account string `json:"account,omitempty"` - Cidrlist string `json:"cidrlist,omitempty"` - Domain string `json:"domain,omitempty"` - Domainid string `json:"domainid,omitempty"` - Dpd bool `json:"dpd,omitempty"` - Esplifetime int64 `json:"esplifetime,omitempty"` - Esppolicy string `json:"esppolicy,omitempty"` - Forceencap bool `json:"forceencap,omitempty"` - Gateway string `json:"gateway,omitempty"` - Id string `json:"id,omitempty"` - Ikelifetime int64 `json:"ikelifetime,omitempty"` - Ikepolicy string `json:"ikepolicy,omitempty"` - Ipaddress string `json:"ipaddress,omitempty"` - Ipsecpsk string `json:"ipsecpsk,omitempty"` - Name string `json:"name,omitempty"` - Project string `json:"project,omitempty"` - Projectid string `json:"projectid,omitempty"` - Removed string `json:"removed,omitempty"` + JobID string `json:"jobid"` + Account string `json:"account"` + Cidrlist string `json:"cidrlist"` + Domain string `json:"domain"` + Domainid string `json:"domainid"` + Dpd bool `json:"dpd"` + Esplifetime int64 `json:"esplifetime"` + Esppolicy string `json:"esppolicy"` + Forceencap bool `json:"forceencap"` + Gateway string `json:"gateway"` + Id string `json:"id"` + Ikelifetime int64 `json:"ikelifetime"` + Ikepolicy string `json:"ikepolicy"` + Ipaddress string `json:"ipaddress"` + Ipsecpsk string `json:"ipsecpsk"` + Name string `json:"name"` + Project string `json:"project"` + Projectid string `json:"projectid"` + Removed string `json:"removed"` } type CreateVpnGatewayParams struct { @@ -1282,192 +722,64 @@ func (s *VPNService) CreateVpnGateway(p *CreateVpnGatewayParams) (*CreateVpnGate return nil, err } } + return &r, nil } type CreateVpnGatewayResponse struct { - JobID string `json:"jobid,omitempty"` - Account string `json:"account,omitempty"` - Domain string `json:"domain,omitempty"` - Domainid string `json:"domainid,omitempty"` - Fordisplay bool `json:"fordisplay,omitempty"` - Id string `json:"id,omitempty"` - Project string `json:"project,omitempty"` - Projectid string `json:"projectid,omitempty"` - Publicip string `json:"publicip,omitempty"` - Removed string `json:"removed,omitempty"` - Vpcid string `json:"vpcid,omitempty"` + JobID string `json:"jobid"` + Account string `json:"account"` + Domain string `json:"domain"` + Domainid string `json:"domainid"` + Fordisplay bool `json:"fordisplay"` + Id string `json:"id"` + Project string `json:"project"` + Projectid string `json:"projectid"` + Publicip string `json:"publicip"` + Removed string `json:"removed"` + Vpcid string `json:"vpcid"` } -type CreateVpnConnectionParams struct { +type DeleteRemoteAccessVpnParams struct { p map[string]interface{} } -func (p *CreateVpnConnectionParams) toURLValues() url.Values { +func (p *DeleteRemoteAccessVpnParams) toURLValues() url.Values { u := url.Values{} if p.p == nil { return u } - if v, found := p.p["fordisplay"]; found { - vv := strconv.FormatBool(v.(bool)) - u.Set("fordisplay", vv) - } - if v, found := p.p["passive"]; found { - vv := strconv.FormatBool(v.(bool)) - u.Set("passive", vv) - } - if v, found := p.p["s2scustomergatewayid"]; found { - u.Set("s2scustomergatewayid", v.(string)) - } - if v, found := p.p["s2svpngatewayid"]; found { - u.Set("s2svpngatewayid", v.(string)) + if v, found := p.p["publicipid"]; found { + u.Set("publicipid", v.(string)) } return u } -func (p *CreateVpnConnectionParams) SetFordisplay(v bool) { +func (p *DeleteRemoteAccessVpnParams) SetPublicipid(v string) { if p.p == nil { p.p = make(map[string]interface{}) } - p.p["fordisplay"] = v + p.p["publicipid"] = v return } -func (p *CreateVpnConnectionParams) SetPassive(v bool) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["passive"] = v - return -} - -func (p *CreateVpnConnectionParams) SetS2scustomergatewayid(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["s2scustomergatewayid"] = v - return -} - -func (p *CreateVpnConnectionParams) SetS2svpngatewayid(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["s2svpngatewayid"] = v - return -} - -// You should always use this function to get a new CreateVpnConnectionParams instance, +// You should always use this function to get a new DeleteRemoteAccessVpnParams instance, // as then you are sure you have configured all required params -func (s *VPNService) NewCreateVpnConnectionParams(s2scustomergatewayid string, s2svpngatewayid string) *CreateVpnConnectionParams { - p := &CreateVpnConnectionParams{} +func (s *VPNService) NewDeleteRemoteAccessVpnParams(publicipid string) *DeleteRemoteAccessVpnParams { + p := &DeleteRemoteAccessVpnParams{} p.p = make(map[string]interface{}) - p.p["s2scustomergatewayid"] = s2scustomergatewayid - p.p["s2svpngatewayid"] = s2svpngatewayid + p.p["publicipid"] = publicipid return p } -// Create site to site vpn connection -func (s *VPNService) CreateVpnConnection(p *CreateVpnConnectionParams) (*CreateVpnConnectionResponse, error) { - resp, err := s.cs.newRequest("createVpnConnection", p.toURLValues()) +// Destroys a l2tp/ipsec remote access vpn +func (s *VPNService) DeleteRemoteAccessVpn(p *DeleteRemoteAccessVpnParams) (*DeleteRemoteAccessVpnResponse, error) { + resp, err := s.cs.newRequest("deleteRemoteAccessVpn", p.toURLValues()) if err != nil { return nil, err } - var r CreateVpnConnectionResponse - if err := json.Unmarshal(resp, &r); err != nil { - return nil, err - } - - // If we have a async client, we need to wait for the async result - if s.cs.async { - b, err := s.cs.GetAsyncJobResult(r.JobID, s.cs.timeout) - if err != nil { - if err == AsyncTimeoutErr { - return &r, err - } - return nil, err - } - - b, err = getRawValue(b) - if err != nil { - return nil, err - } - - if err := json.Unmarshal(b, &r); err != nil { - return nil, err - } - } - return &r, nil -} - -type CreateVpnConnectionResponse struct { - JobID string `json:"jobid,omitempty"` - Account string `json:"account,omitempty"` - Cidrlist string `json:"cidrlist,omitempty"` - Created string `json:"created,omitempty"` - Domain string `json:"domain,omitempty"` - Domainid string `json:"domainid,omitempty"` - Dpd bool `json:"dpd,omitempty"` - Esplifetime int64 `json:"esplifetime,omitempty"` - Esppolicy string `json:"esppolicy,omitempty"` - Forceencap bool `json:"forceencap,omitempty"` - Fordisplay bool `json:"fordisplay,omitempty"` - Gateway string `json:"gateway,omitempty"` - Id string `json:"id,omitempty"` - Ikelifetime int64 `json:"ikelifetime,omitempty"` - Ikepolicy string `json:"ikepolicy,omitempty"` - Ipsecpsk string `json:"ipsecpsk,omitempty"` - Passive bool `json:"passive,omitempty"` - Project string `json:"project,omitempty"` - Projectid string `json:"projectid,omitempty"` - Publicip string `json:"publicip,omitempty"` - Removed string `json:"removed,omitempty"` - S2scustomergatewayid string `json:"s2scustomergatewayid,omitempty"` - S2svpngatewayid string `json:"s2svpngatewayid,omitempty"` - State string `json:"state,omitempty"` -} - -type DeleteVpnCustomerGatewayParams struct { - p map[string]interface{} -} - -func (p *DeleteVpnCustomerGatewayParams) toURLValues() url.Values { - u := url.Values{} - if p.p == nil { - return u - } - if v, found := p.p["id"]; found { - u.Set("id", v.(string)) - } - return u -} - -func (p *DeleteVpnCustomerGatewayParams) SetId(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["id"] = v - return -} - -// You should always use this function to get a new DeleteVpnCustomerGatewayParams instance, -// as then you are sure you have configured all required params -func (s *VPNService) NewDeleteVpnCustomerGatewayParams(id string) *DeleteVpnCustomerGatewayParams { - p := &DeleteVpnCustomerGatewayParams{} - p.p = make(map[string]interface{}) - p.p["id"] = id - return p -} - -// Delete site to site vpn customer gateway -func (s *VPNService) DeleteVpnCustomerGateway(p *DeleteVpnCustomerGatewayParams) (*DeleteVpnCustomerGatewayResponse, error) { - resp, err := s.cs.newRequest("deleteVpnCustomerGateway", p.toURLValues()) - if err != nil { - return nil, err - } - - var r DeleteVpnCustomerGatewayResponse + var r DeleteRemoteAccessVpnResponse if err := json.Unmarshal(resp, &r); err != nil { return nil, err } @@ -1486,80 +798,14 @@ func (s *VPNService) DeleteVpnCustomerGateway(p *DeleteVpnCustomerGatewayParams) return nil, err } } + return &r, nil } -type DeleteVpnCustomerGatewayResponse struct { - JobID string `json:"jobid,omitempty"` - Displaytext string `json:"displaytext,omitempty"` - Success bool `json:"success,omitempty"` -} - -type DeleteVpnGatewayParams struct { - p map[string]interface{} -} - -func (p *DeleteVpnGatewayParams) toURLValues() url.Values { - u := url.Values{} - if p.p == nil { - return u - } - if v, found := p.p["id"]; found { - u.Set("id", v.(string)) - } - return u -} - -func (p *DeleteVpnGatewayParams) SetId(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["id"] = v - return -} - -// You should always use this function to get a new DeleteVpnGatewayParams instance, -// as then you are sure you have configured all required params -func (s *VPNService) NewDeleteVpnGatewayParams(id string) *DeleteVpnGatewayParams { - p := &DeleteVpnGatewayParams{} - p.p = make(map[string]interface{}) - p.p["id"] = id - return p -} - -// Delete site to site vpn gateway -func (s *VPNService) DeleteVpnGateway(p *DeleteVpnGatewayParams) (*DeleteVpnGatewayResponse, error) { - resp, err := s.cs.newRequest("deleteVpnGateway", p.toURLValues()) - if err != nil { - return nil, err - } - - var r DeleteVpnGatewayResponse - if err := json.Unmarshal(resp, &r); err != nil { - return nil, err - } - - // If we have a async client, we need to wait for the async result - if s.cs.async { - b, err := s.cs.GetAsyncJobResult(r.JobID, s.cs.timeout) - if err != nil { - if err == AsyncTimeoutErr { - return &r, err - } - return nil, err - } - - if err := json.Unmarshal(b, &r); err != nil { - return nil, err - } - } - return &r, nil -} - -type DeleteVpnGatewayResponse struct { - JobID string `json:"jobid,omitempty"` - Displaytext string `json:"displaytext,omitempty"` - Success bool `json:"success,omitempty"` +type DeleteRemoteAccessVpnResponse struct { + JobID string `json:"jobid"` + Displaytext string `json:"displaytext"` + Success bool `json:"success"` } type DeleteVpnConnectionParams struct { @@ -1620,13 +866,1697 @@ func (s *VPNService) DeleteVpnConnection(p *DeleteVpnConnectionParams) (*DeleteV return nil, err } } + return &r, nil } type DeleteVpnConnectionResponse struct { - JobID string `json:"jobid,omitempty"` - Displaytext string `json:"displaytext,omitempty"` - Success bool `json:"success,omitempty"` + JobID string `json:"jobid"` + Displaytext string `json:"displaytext"` + Success bool `json:"success"` +} + +type DeleteVpnCustomerGatewayParams struct { + p map[string]interface{} +} + +func (p *DeleteVpnCustomerGatewayParams) toURLValues() url.Values { + u := url.Values{} + if p.p == nil { + return u + } + if v, found := p.p["id"]; found { + u.Set("id", v.(string)) + } + return u +} + +func (p *DeleteVpnCustomerGatewayParams) SetId(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["id"] = v + return +} + +// You should always use this function to get a new DeleteVpnCustomerGatewayParams instance, +// as then you are sure you have configured all required params +func (s *VPNService) NewDeleteVpnCustomerGatewayParams(id string) *DeleteVpnCustomerGatewayParams { + p := &DeleteVpnCustomerGatewayParams{} + p.p = make(map[string]interface{}) + p.p["id"] = id + return p +} + +// Delete site to site vpn customer gateway +func (s *VPNService) DeleteVpnCustomerGateway(p *DeleteVpnCustomerGatewayParams) (*DeleteVpnCustomerGatewayResponse, error) { + resp, err := s.cs.newRequest("deleteVpnCustomerGateway", p.toURLValues()) + if err != nil { + return nil, err + } + + var r DeleteVpnCustomerGatewayResponse + if err := json.Unmarshal(resp, &r); err != nil { + return nil, err + } + + // If we have a async client, we need to wait for the async result + if s.cs.async { + b, err := s.cs.GetAsyncJobResult(r.JobID, s.cs.timeout) + if err != nil { + if err == AsyncTimeoutErr { + return &r, err + } + return nil, err + } + + if err := json.Unmarshal(b, &r); err != nil { + return nil, err + } + } + + return &r, nil +} + +type DeleteVpnCustomerGatewayResponse struct { + JobID string `json:"jobid"` + Displaytext string `json:"displaytext"` + Success bool `json:"success"` +} + +type DeleteVpnGatewayParams struct { + p map[string]interface{} +} + +func (p *DeleteVpnGatewayParams) toURLValues() url.Values { + u := url.Values{} + if p.p == nil { + return u + } + if v, found := p.p["id"]; found { + u.Set("id", v.(string)) + } + return u +} + +func (p *DeleteVpnGatewayParams) SetId(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["id"] = v + return +} + +// You should always use this function to get a new DeleteVpnGatewayParams instance, +// as then you are sure you have configured all required params +func (s *VPNService) NewDeleteVpnGatewayParams(id string) *DeleteVpnGatewayParams { + p := &DeleteVpnGatewayParams{} + p.p = make(map[string]interface{}) + p.p["id"] = id + return p +} + +// Delete site to site vpn gateway +func (s *VPNService) DeleteVpnGateway(p *DeleteVpnGatewayParams) (*DeleteVpnGatewayResponse, error) { + resp, err := s.cs.newRequest("deleteVpnGateway", p.toURLValues()) + if err != nil { + return nil, err + } + + var r DeleteVpnGatewayResponse + if err := json.Unmarshal(resp, &r); err != nil { + return nil, err + } + + // If we have a async client, we need to wait for the async result + if s.cs.async { + b, err := s.cs.GetAsyncJobResult(r.JobID, s.cs.timeout) + if err != nil { + if err == AsyncTimeoutErr { + return &r, err + } + return nil, err + } + + if err := json.Unmarshal(b, &r); err != nil { + return nil, err + } + } + + return &r, nil +} + +type DeleteVpnGatewayResponse struct { + JobID string `json:"jobid"` + Displaytext string `json:"displaytext"` + Success bool `json:"success"` +} + +type ListRemoteAccessVpnsParams struct { + p map[string]interface{} +} + +func (p *ListRemoteAccessVpnsParams) toURLValues() url.Values { + u := url.Values{} + if p.p == nil { + return u + } + if v, found := p.p["account"]; found { + u.Set("account", v.(string)) + } + if v, found := p.p["domainid"]; found { + u.Set("domainid", v.(string)) + } + if v, found := p.p["fordisplay"]; found { + vv := strconv.FormatBool(v.(bool)) + u.Set("fordisplay", vv) + } + if v, found := p.p["id"]; found { + u.Set("id", v.(string)) + } + if v, found := p.p["isrecursive"]; found { + vv := strconv.FormatBool(v.(bool)) + u.Set("isrecursive", vv) + } + if v, found := p.p["keyword"]; found { + u.Set("keyword", v.(string)) + } + if v, found := p.p["listall"]; found { + vv := strconv.FormatBool(v.(bool)) + u.Set("listall", vv) + } + if v, found := p.p["networkid"]; found { + u.Set("networkid", v.(string)) + } + if v, found := p.p["page"]; found { + vv := strconv.Itoa(v.(int)) + u.Set("page", vv) + } + if v, found := p.p["pagesize"]; found { + vv := strconv.Itoa(v.(int)) + u.Set("pagesize", vv) + } + if v, found := p.p["projectid"]; found { + u.Set("projectid", v.(string)) + } + if v, found := p.p["publicipid"]; found { + u.Set("publicipid", v.(string)) + } + return u +} + +func (p *ListRemoteAccessVpnsParams) SetAccount(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["account"] = v + return +} + +func (p *ListRemoteAccessVpnsParams) SetDomainid(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["domainid"] = v + return +} + +func (p *ListRemoteAccessVpnsParams) SetFordisplay(v bool) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["fordisplay"] = v + return +} + +func (p *ListRemoteAccessVpnsParams) SetId(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["id"] = v + return +} + +func (p *ListRemoteAccessVpnsParams) SetIsrecursive(v bool) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["isrecursive"] = v + return +} + +func (p *ListRemoteAccessVpnsParams) SetKeyword(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["keyword"] = v + return +} + +func (p *ListRemoteAccessVpnsParams) SetListall(v bool) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["listall"] = v + return +} + +func (p *ListRemoteAccessVpnsParams) SetNetworkid(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["networkid"] = v + return +} + +func (p *ListRemoteAccessVpnsParams) SetPage(v int) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["page"] = v + return +} + +func (p *ListRemoteAccessVpnsParams) SetPagesize(v int) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["pagesize"] = v + return +} + +func (p *ListRemoteAccessVpnsParams) SetProjectid(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["projectid"] = v + return +} + +func (p *ListRemoteAccessVpnsParams) SetPublicipid(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["publicipid"] = v + return +} + +// You should always use this function to get a new ListRemoteAccessVpnsParams instance, +// as then you are sure you have configured all required params +func (s *VPNService) NewListRemoteAccessVpnsParams() *ListRemoteAccessVpnsParams { + p := &ListRemoteAccessVpnsParams{} + p.p = make(map[string]interface{}) + return p +} + +// This is a courtesy helper function, which in some cases may not work as expected! +func (s *VPNService) GetRemoteAccessVpnByID(id string, opts ...OptionFunc) (*RemoteAccessVpn, int, error) { + p := &ListRemoteAccessVpnsParams{} + p.p = make(map[string]interface{}) + + p.p["id"] = id + + for _, fn := range append(s.cs.options, opts...) { + if err := fn(s.cs, p); err != nil { + return nil, -1, err + } + } + + l, err := s.ListRemoteAccessVpns(p) + if err != nil { + if strings.Contains(err.Error(), fmt.Sprintf( + "Invalid parameter id value=%s due to incorrect long value format, "+ + "or entity does not exist", id)) { + return nil, 0, fmt.Errorf("No match found for %s: %+v", id, l) + } + return nil, -1, err + } + + if l.Count == 0 { + return nil, l.Count, fmt.Errorf("No match found for %s: %+v", id, l) + } + + if l.Count == 1 { + return l.RemoteAccessVpns[0], l.Count, nil + } + return nil, l.Count, fmt.Errorf("There is more then one result for RemoteAccessVpn UUID: %s!", id) +} + +// Lists remote access vpns +func (s *VPNService) ListRemoteAccessVpns(p *ListRemoteAccessVpnsParams) (*ListRemoteAccessVpnsResponse, error) { + resp, err := s.cs.newRequest("listRemoteAccessVpns", p.toURLValues()) + if err != nil { + return nil, err + } + + var r ListRemoteAccessVpnsResponse + if err := json.Unmarshal(resp, &r); err != nil { + return nil, err + } + + return &r, nil +} + +type ListRemoteAccessVpnsResponse struct { + Count int `json:"count"` + RemoteAccessVpns []*RemoteAccessVpn `json:"remoteaccessvpn"` +} + +type RemoteAccessVpn struct { + Account string `json:"account"` + Domain string `json:"domain"` + Domainid string `json:"domainid"` + Fordisplay bool `json:"fordisplay"` + Id string `json:"id"` + Iprange string `json:"iprange"` + Presharedkey string `json:"presharedkey"` + Project string `json:"project"` + Projectid string `json:"projectid"` + Publicip string `json:"publicip"` + Publicipid string `json:"publicipid"` + State string `json:"state"` +} + +type ListVpnConnectionsParams struct { + p map[string]interface{} +} + +func (p *ListVpnConnectionsParams) toURLValues() url.Values { + u := url.Values{} + if p.p == nil { + return u + } + if v, found := p.p["account"]; found { + u.Set("account", v.(string)) + } + if v, found := p.p["domainid"]; found { + u.Set("domainid", v.(string)) + } + if v, found := p.p["fordisplay"]; found { + vv := strconv.FormatBool(v.(bool)) + u.Set("fordisplay", vv) + } + if v, found := p.p["id"]; found { + u.Set("id", v.(string)) + } + if v, found := p.p["isrecursive"]; found { + vv := strconv.FormatBool(v.(bool)) + u.Set("isrecursive", vv) + } + if v, found := p.p["keyword"]; found { + u.Set("keyword", v.(string)) + } + if v, found := p.p["listall"]; found { + vv := strconv.FormatBool(v.(bool)) + u.Set("listall", vv) + } + if v, found := p.p["page"]; found { + vv := strconv.Itoa(v.(int)) + u.Set("page", vv) + } + if v, found := p.p["pagesize"]; found { + vv := strconv.Itoa(v.(int)) + u.Set("pagesize", vv) + } + if v, found := p.p["projectid"]; found { + u.Set("projectid", v.(string)) + } + if v, found := p.p["vpcid"]; found { + u.Set("vpcid", v.(string)) + } + return u +} + +func (p *ListVpnConnectionsParams) SetAccount(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["account"] = v + return +} + +func (p *ListVpnConnectionsParams) SetDomainid(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["domainid"] = v + return +} + +func (p *ListVpnConnectionsParams) SetFordisplay(v bool) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["fordisplay"] = v + return +} + +func (p *ListVpnConnectionsParams) SetId(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["id"] = v + return +} + +func (p *ListVpnConnectionsParams) SetIsrecursive(v bool) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["isrecursive"] = v + return +} + +func (p *ListVpnConnectionsParams) SetKeyword(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["keyword"] = v + return +} + +func (p *ListVpnConnectionsParams) SetListall(v bool) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["listall"] = v + return +} + +func (p *ListVpnConnectionsParams) SetPage(v int) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["page"] = v + return +} + +func (p *ListVpnConnectionsParams) SetPagesize(v int) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["pagesize"] = v + return +} + +func (p *ListVpnConnectionsParams) SetProjectid(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["projectid"] = v + return +} + +func (p *ListVpnConnectionsParams) SetVpcid(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["vpcid"] = v + return +} + +// You should always use this function to get a new ListVpnConnectionsParams instance, +// as then you are sure you have configured all required params +func (s *VPNService) NewListVpnConnectionsParams() *ListVpnConnectionsParams { + p := &ListVpnConnectionsParams{} + p.p = make(map[string]interface{}) + return p +} + +// This is a courtesy helper function, which in some cases may not work as expected! +func (s *VPNService) GetVpnConnectionByID(id string, opts ...OptionFunc) (*VpnConnection, int, error) { + p := &ListVpnConnectionsParams{} + p.p = make(map[string]interface{}) + + p.p["id"] = id + + for _, fn := range append(s.cs.options, opts...) { + if err := fn(s.cs, p); err != nil { + return nil, -1, err + } + } + + l, err := s.ListVpnConnections(p) + if err != nil { + if strings.Contains(err.Error(), fmt.Sprintf( + "Invalid parameter id value=%s due to incorrect long value format, "+ + "or entity does not exist", id)) { + return nil, 0, fmt.Errorf("No match found for %s: %+v", id, l) + } + return nil, -1, err + } + + if l.Count == 0 { + return nil, l.Count, fmt.Errorf("No match found for %s: %+v", id, l) + } + + if l.Count == 1 { + return l.VpnConnections[0], l.Count, nil + } + return nil, l.Count, fmt.Errorf("There is more then one result for VpnConnection UUID: %s!", id) +} + +// Lists site to site vpn connection gateways +func (s *VPNService) ListVpnConnections(p *ListVpnConnectionsParams) (*ListVpnConnectionsResponse, error) { + resp, err := s.cs.newRequest("listVpnConnections", p.toURLValues()) + if err != nil { + return nil, err + } + + var r ListVpnConnectionsResponse + if err := json.Unmarshal(resp, &r); err != nil { + return nil, err + } + + return &r, nil +} + +type ListVpnConnectionsResponse struct { + Count int `json:"count"` + VpnConnections []*VpnConnection `json:"vpnconnection"` +} + +type VpnConnection struct { + Account string `json:"account"` + Cidrlist string `json:"cidrlist"` + Created string `json:"created"` + Domain string `json:"domain"` + Domainid string `json:"domainid"` + Dpd bool `json:"dpd"` + Esplifetime int64 `json:"esplifetime"` + Esppolicy string `json:"esppolicy"` + Forceencap bool `json:"forceencap"` + Fordisplay bool `json:"fordisplay"` + Gateway string `json:"gateway"` + Id string `json:"id"` + Ikelifetime int64 `json:"ikelifetime"` + Ikepolicy string `json:"ikepolicy"` + Ipsecpsk string `json:"ipsecpsk"` + Passive bool `json:"passive"` + Project string `json:"project"` + Projectid string `json:"projectid"` + Publicip string `json:"publicip"` + Removed string `json:"removed"` + S2scustomergatewayid string `json:"s2scustomergatewayid"` + S2svpngatewayid string `json:"s2svpngatewayid"` + State string `json:"state"` +} + +type ListVpnCustomerGatewaysParams struct { + p map[string]interface{} +} + +func (p *ListVpnCustomerGatewaysParams) toURLValues() url.Values { + u := url.Values{} + if p.p == nil { + return u + } + if v, found := p.p["account"]; found { + u.Set("account", v.(string)) + } + if v, found := p.p["domainid"]; found { + u.Set("domainid", v.(string)) + } + if v, found := p.p["id"]; found { + u.Set("id", v.(string)) + } + if v, found := p.p["isrecursive"]; found { + vv := strconv.FormatBool(v.(bool)) + u.Set("isrecursive", vv) + } + if v, found := p.p["keyword"]; found { + u.Set("keyword", v.(string)) + } + if v, found := p.p["listall"]; found { + vv := strconv.FormatBool(v.(bool)) + u.Set("listall", vv) + } + if v, found := p.p["page"]; found { + vv := strconv.Itoa(v.(int)) + u.Set("page", vv) + } + if v, found := p.p["pagesize"]; found { + vv := strconv.Itoa(v.(int)) + u.Set("pagesize", vv) + } + if v, found := p.p["projectid"]; found { + u.Set("projectid", v.(string)) + } + return u +} + +func (p *ListVpnCustomerGatewaysParams) SetAccount(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["account"] = v + return +} + +func (p *ListVpnCustomerGatewaysParams) SetDomainid(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["domainid"] = v + return +} + +func (p *ListVpnCustomerGatewaysParams) SetId(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["id"] = v + return +} + +func (p *ListVpnCustomerGatewaysParams) SetIsrecursive(v bool) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["isrecursive"] = v + return +} + +func (p *ListVpnCustomerGatewaysParams) SetKeyword(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["keyword"] = v + return +} + +func (p *ListVpnCustomerGatewaysParams) SetListall(v bool) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["listall"] = v + return +} + +func (p *ListVpnCustomerGatewaysParams) SetPage(v int) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["page"] = v + return +} + +func (p *ListVpnCustomerGatewaysParams) SetPagesize(v int) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["pagesize"] = v + return +} + +func (p *ListVpnCustomerGatewaysParams) SetProjectid(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["projectid"] = v + return +} + +// You should always use this function to get a new ListVpnCustomerGatewaysParams instance, +// as then you are sure you have configured all required params +func (s *VPNService) NewListVpnCustomerGatewaysParams() *ListVpnCustomerGatewaysParams { + p := &ListVpnCustomerGatewaysParams{} + p.p = make(map[string]interface{}) + return p +} + +// This is a courtesy helper function, which in some cases may not work as expected! +func (s *VPNService) GetVpnCustomerGatewayID(keyword string, opts ...OptionFunc) (string, int, error) { + p := &ListVpnCustomerGatewaysParams{} + p.p = make(map[string]interface{}) + + p.p["keyword"] = keyword + + for _, fn := range append(s.cs.options, opts...) { + if err := fn(s.cs, p); err != nil { + return "", -1, err + } + } + + l, err := s.ListVpnCustomerGateways(p) + if err != nil { + return "", -1, err + } + + if l.Count == 0 { + return "", l.Count, fmt.Errorf("No match found for %s: %+v", keyword, l) + } + + if l.Count == 1 { + return l.VpnCustomerGateways[0].Id, l.Count, nil + } + + if l.Count > 1 { + for _, v := range l.VpnCustomerGateways { + if v.Name == keyword { + return v.Id, l.Count, nil + } + } + } + return "", l.Count, fmt.Errorf("Could not find an exact match for %s: %+v", keyword, l) +} + +// This is a courtesy helper function, which in some cases may not work as expected! +func (s *VPNService) GetVpnCustomerGatewayByName(name string, opts ...OptionFunc) (*VpnCustomerGateway, int, error) { + id, count, err := s.GetVpnCustomerGatewayID(name, opts...) + if err != nil { + return nil, count, err + } + + r, count, err := s.GetVpnCustomerGatewayByID(id, opts...) + if err != nil { + return nil, count, err + } + return r, count, nil +} + +// This is a courtesy helper function, which in some cases may not work as expected! +func (s *VPNService) GetVpnCustomerGatewayByID(id string, opts ...OptionFunc) (*VpnCustomerGateway, int, error) { + p := &ListVpnCustomerGatewaysParams{} + p.p = make(map[string]interface{}) + + p.p["id"] = id + + for _, fn := range append(s.cs.options, opts...) { + if err := fn(s.cs, p); err != nil { + return nil, -1, err + } + } + + l, err := s.ListVpnCustomerGateways(p) + if err != nil { + if strings.Contains(err.Error(), fmt.Sprintf( + "Invalid parameter id value=%s due to incorrect long value format, "+ + "or entity does not exist", id)) { + return nil, 0, fmt.Errorf("No match found for %s: %+v", id, l) + } + return nil, -1, err + } + + if l.Count == 0 { + return nil, l.Count, fmt.Errorf("No match found for %s: %+v", id, l) + } + + if l.Count == 1 { + return l.VpnCustomerGateways[0], l.Count, nil + } + return nil, l.Count, fmt.Errorf("There is more then one result for VpnCustomerGateway UUID: %s!", id) +} + +// Lists site to site vpn customer gateways +func (s *VPNService) ListVpnCustomerGateways(p *ListVpnCustomerGatewaysParams) (*ListVpnCustomerGatewaysResponse, error) { + resp, err := s.cs.newRequest("listVpnCustomerGateways", p.toURLValues()) + if err != nil { + return nil, err + } + + var r ListVpnCustomerGatewaysResponse + if err := json.Unmarshal(resp, &r); err != nil { + return nil, err + } + + return &r, nil +} + +type ListVpnCustomerGatewaysResponse struct { + Count int `json:"count"` + VpnCustomerGateways []*VpnCustomerGateway `json:"vpncustomergateway"` +} + +type VpnCustomerGateway struct { + Account string `json:"account"` + Cidrlist string `json:"cidrlist"` + Domain string `json:"domain"` + Domainid string `json:"domainid"` + Dpd bool `json:"dpd"` + Esplifetime int64 `json:"esplifetime"` + Esppolicy string `json:"esppolicy"` + Forceencap bool `json:"forceencap"` + Gateway string `json:"gateway"` + Id string `json:"id"` + Ikelifetime int64 `json:"ikelifetime"` + Ikepolicy string `json:"ikepolicy"` + Ipaddress string `json:"ipaddress"` + Ipsecpsk string `json:"ipsecpsk"` + Name string `json:"name"` + Project string `json:"project"` + Projectid string `json:"projectid"` + Removed string `json:"removed"` +} + +type ListVpnGatewaysParams struct { + p map[string]interface{} +} + +func (p *ListVpnGatewaysParams) toURLValues() url.Values { + u := url.Values{} + if p.p == nil { + return u + } + if v, found := p.p["account"]; found { + u.Set("account", v.(string)) + } + if v, found := p.p["domainid"]; found { + u.Set("domainid", v.(string)) + } + if v, found := p.p["fordisplay"]; found { + vv := strconv.FormatBool(v.(bool)) + u.Set("fordisplay", vv) + } + if v, found := p.p["id"]; found { + u.Set("id", v.(string)) + } + if v, found := p.p["isrecursive"]; found { + vv := strconv.FormatBool(v.(bool)) + u.Set("isrecursive", vv) + } + if v, found := p.p["keyword"]; found { + u.Set("keyword", v.(string)) + } + if v, found := p.p["listall"]; found { + vv := strconv.FormatBool(v.(bool)) + u.Set("listall", vv) + } + if v, found := p.p["page"]; found { + vv := strconv.Itoa(v.(int)) + u.Set("page", vv) + } + if v, found := p.p["pagesize"]; found { + vv := strconv.Itoa(v.(int)) + u.Set("pagesize", vv) + } + if v, found := p.p["projectid"]; found { + u.Set("projectid", v.(string)) + } + if v, found := p.p["vpcid"]; found { + u.Set("vpcid", v.(string)) + } + return u +} + +func (p *ListVpnGatewaysParams) SetAccount(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["account"] = v + return +} + +func (p *ListVpnGatewaysParams) SetDomainid(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["domainid"] = v + return +} + +func (p *ListVpnGatewaysParams) SetFordisplay(v bool) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["fordisplay"] = v + return +} + +func (p *ListVpnGatewaysParams) SetId(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["id"] = v + return +} + +func (p *ListVpnGatewaysParams) SetIsrecursive(v bool) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["isrecursive"] = v + return +} + +func (p *ListVpnGatewaysParams) SetKeyword(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["keyword"] = v + return +} + +func (p *ListVpnGatewaysParams) SetListall(v bool) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["listall"] = v + return +} + +func (p *ListVpnGatewaysParams) SetPage(v int) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["page"] = v + return +} + +func (p *ListVpnGatewaysParams) SetPagesize(v int) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["pagesize"] = v + return +} + +func (p *ListVpnGatewaysParams) SetProjectid(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["projectid"] = v + return +} + +func (p *ListVpnGatewaysParams) SetVpcid(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["vpcid"] = v + return +} + +// You should always use this function to get a new ListVpnGatewaysParams instance, +// as then you are sure you have configured all required params +func (s *VPNService) NewListVpnGatewaysParams() *ListVpnGatewaysParams { + p := &ListVpnGatewaysParams{} + p.p = make(map[string]interface{}) + return p +} + +// This is a courtesy helper function, which in some cases may not work as expected! +func (s *VPNService) GetVpnGatewayByID(id string, opts ...OptionFunc) (*VpnGateway, int, error) { + p := &ListVpnGatewaysParams{} + p.p = make(map[string]interface{}) + + p.p["id"] = id + + for _, fn := range append(s.cs.options, opts...) { + if err := fn(s.cs, p); err != nil { + return nil, -1, err + } + } + + l, err := s.ListVpnGateways(p) + if err != nil { + if strings.Contains(err.Error(), fmt.Sprintf( + "Invalid parameter id value=%s due to incorrect long value format, "+ + "or entity does not exist", id)) { + return nil, 0, fmt.Errorf("No match found for %s: %+v", id, l) + } + return nil, -1, err + } + + if l.Count == 0 { + return nil, l.Count, fmt.Errorf("No match found for %s: %+v", id, l) + } + + if l.Count == 1 { + return l.VpnGateways[0], l.Count, nil + } + return nil, l.Count, fmt.Errorf("There is more then one result for VpnGateway UUID: %s!", id) +} + +// Lists site 2 site vpn gateways +func (s *VPNService) ListVpnGateways(p *ListVpnGatewaysParams) (*ListVpnGatewaysResponse, error) { + resp, err := s.cs.newRequest("listVpnGateways", p.toURLValues()) + if err != nil { + return nil, err + } + + var r ListVpnGatewaysResponse + if err := json.Unmarshal(resp, &r); err != nil { + return nil, err + } + + return &r, nil +} + +type ListVpnGatewaysResponse struct { + Count int `json:"count"` + VpnGateways []*VpnGateway `json:"vpngateway"` +} + +type VpnGateway struct { + Account string `json:"account"` + Domain string `json:"domain"` + Domainid string `json:"domainid"` + Fordisplay bool `json:"fordisplay"` + Id string `json:"id"` + Project string `json:"project"` + Projectid string `json:"projectid"` + Publicip string `json:"publicip"` + Removed string `json:"removed"` + Vpcid string `json:"vpcid"` +} + +type ListVpnUsersParams struct { + p map[string]interface{} +} + +func (p *ListVpnUsersParams) toURLValues() url.Values { + u := url.Values{} + if p.p == nil { + return u + } + if v, found := p.p["account"]; found { + u.Set("account", v.(string)) + } + if v, found := p.p["domainid"]; found { + u.Set("domainid", v.(string)) + } + if v, found := p.p["id"]; found { + u.Set("id", v.(string)) + } + if v, found := p.p["isrecursive"]; found { + vv := strconv.FormatBool(v.(bool)) + u.Set("isrecursive", vv) + } + if v, found := p.p["keyword"]; found { + u.Set("keyword", v.(string)) + } + if v, found := p.p["listall"]; found { + vv := strconv.FormatBool(v.(bool)) + u.Set("listall", vv) + } + if v, found := p.p["page"]; found { + vv := strconv.Itoa(v.(int)) + u.Set("page", vv) + } + if v, found := p.p["pagesize"]; found { + vv := strconv.Itoa(v.(int)) + u.Set("pagesize", vv) + } + if v, found := p.p["projectid"]; found { + u.Set("projectid", v.(string)) + } + if v, found := p.p["username"]; found { + u.Set("username", v.(string)) + } + return u +} + +func (p *ListVpnUsersParams) SetAccount(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["account"] = v + return +} + +func (p *ListVpnUsersParams) SetDomainid(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["domainid"] = v + return +} + +func (p *ListVpnUsersParams) SetId(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["id"] = v + return +} + +func (p *ListVpnUsersParams) SetIsrecursive(v bool) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["isrecursive"] = v + return +} + +func (p *ListVpnUsersParams) SetKeyword(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["keyword"] = v + return +} + +func (p *ListVpnUsersParams) SetListall(v bool) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["listall"] = v + return +} + +func (p *ListVpnUsersParams) SetPage(v int) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["page"] = v + return +} + +func (p *ListVpnUsersParams) SetPagesize(v int) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["pagesize"] = v + return +} + +func (p *ListVpnUsersParams) SetProjectid(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["projectid"] = v + return +} + +func (p *ListVpnUsersParams) SetUsername(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["username"] = v + return +} + +// You should always use this function to get a new ListVpnUsersParams instance, +// as then you are sure you have configured all required params +func (s *VPNService) NewListVpnUsersParams() *ListVpnUsersParams { + p := &ListVpnUsersParams{} + p.p = make(map[string]interface{}) + return p +} + +// This is a courtesy helper function, which in some cases may not work as expected! +func (s *VPNService) GetVpnUserByID(id string, opts ...OptionFunc) (*VpnUser, int, error) { + p := &ListVpnUsersParams{} + p.p = make(map[string]interface{}) + + p.p["id"] = id + + for _, fn := range append(s.cs.options, opts...) { + if err := fn(s.cs, p); err != nil { + return nil, -1, err + } + } + + l, err := s.ListVpnUsers(p) + if err != nil { + if strings.Contains(err.Error(), fmt.Sprintf( + "Invalid parameter id value=%s due to incorrect long value format, "+ + "or entity does not exist", id)) { + return nil, 0, fmt.Errorf("No match found for %s: %+v", id, l) + } + return nil, -1, err + } + + if l.Count == 0 { + return nil, l.Count, fmt.Errorf("No match found for %s: %+v", id, l) + } + + if l.Count == 1 { + return l.VpnUsers[0], l.Count, nil + } + return nil, l.Count, fmt.Errorf("There is more then one result for VpnUser UUID: %s!", id) +} + +// Lists vpn users +func (s *VPNService) ListVpnUsers(p *ListVpnUsersParams) (*ListVpnUsersResponse, error) { + resp, err := s.cs.newRequest("listVpnUsers", p.toURLValues()) + if err != nil { + return nil, err + } + + var r ListVpnUsersResponse + if err := json.Unmarshal(resp, &r); err != nil { + return nil, err + } + + return &r, nil +} + +type ListVpnUsersResponse struct { + Count int `json:"count"` + VpnUsers []*VpnUser `json:"vpnuser"` +} + +type VpnUser struct { + Account string `json:"account"` + Domain string `json:"domain"` + Domainid string `json:"domainid"` + Id string `json:"id"` + Project string `json:"project"` + Projectid string `json:"projectid"` + State string `json:"state"` + Username string `json:"username"` +} + +type RemoveVpnUserParams struct { + p map[string]interface{} +} + +func (p *RemoveVpnUserParams) toURLValues() url.Values { + u := url.Values{} + if p.p == nil { + return u + } + if v, found := p.p["account"]; found { + u.Set("account", v.(string)) + } + if v, found := p.p["domainid"]; found { + u.Set("domainid", v.(string)) + } + if v, found := p.p["projectid"]; found { + u.Set("projectid", v.(string)) + } + if v, found := p.p["username"]; found { + u.Set("username", v.(string)) + } + return u +} + +func (p *RemoveVpnUserParams) SetAccount(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["account"] = v + return +} + +func (p *RemoveVpnUserParams) SetDomainid(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["domainid"] = v + return +} + +func (p *RemoveVpnUserParams) SetProjectid(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["projectid"] = v + return +} + +func (p *RemoveVpnUserParams) SetUsername(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["username"] = v + return +} + +// You should always use this function to get a new RemoveVpnUserParams instance, +// as then you are sure you have configured all required params +func (s *VPNService) NewRemoveVpnUserParams(username string) *RemoveVpnUserParams { + p := &RemoveVpnUserParams{} + p.p = make(map[string]interface{}) + p.p["username"] = username + return p +} + +// Removes vpn user +func (s *VPNService) RemoveVpnUser(p *RemoveVpnUserParams) (*RemoveVpnUserResponse, error) { + resp, err := s.cs.newRequest("removeVpnUser", p.toURLValues()) + if err != nil { + return nil, err + } + + var r RemoveVpnUserResponse + if err := json.Unmarshal(resp, &r); err != nil { + return nil, err + } + + // If we have a async client, we need to wait for the async result + if s.cs.async { + b, err := s.cs.GetAsyncJobResult(r.JobID, s.cs.timeout) + if err != nil { + if err == AsyncTimeoutErr { + return &r, err + } + return nil, err + } + + if err := json.Unmarshal(b, &r); err != nil { + return nil, err + } + } + + return &r, nil +} + +type RemoveVpnUserResponse struct { + JobID string `json:"jobid"` + Displaytext string `json:"displaytext"` + Success bool `json:"success"` +} + +type ResetVpnConnectionParams struct { + p map[string]interface{} +} + +func (p *ResetVpnConnectionParams) toURLValues() url.Values { + u := url.Values{} + if p.p == nil { + return u + } + if v, found := p.p["account"]; found { + u.Set("account", v.(string)) + } + if v, found := p.p["domainid"]; found { + u.Set("domainid", v.(string)) + } + if v, found := p.p["id"]; found { + u.Set("id", v.(string)) + } + return u +} + +func (p *ResetVpnConnectionParams) SetAccount(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["account"] = v + return +} + +func (p *ResetVpnConnectionParams) SetDomainid(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["domainid"] = v + return +} + +func (p *ResetVpnConnectionParams) SetId(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["id"] = v + return +} + +// You should always use this function to get a new ResetVpnConnectionParams instance, +// as then you are sure you have configured all required params +func (s *VPNService) NewResetVpnConnectionParams(id string) *ResetVpnConnectionParams { + p := &ResetVpnConnectionParams{} + p.p = make(map[string]interface{}) + p.p["id"] = id + return p +} + +// Reset site to site vpn connection +func (s *VPNService) ResetVpnConnection(p *ResetVpnConnectionParams) (*ResetVpnConnectionResponse, error) { + resp, err := s.cs.newRequest("resetVpnConnection", p.toURLValues()) + if err != nil { + return nil, err + } + + var r ResetVpnConnectionResponse + if err := json.Unmarshal(resp, &r); err != nil { + return nil, err + } + + // If we have a async client, we need to wait for the async result + if s.cs.async { + b, err := s.cs.GetAsyncJobResult(r.JobID, s.cs.timeout) + if err != nil { + if err == AsyncTimeoutErr { + return &r, err + } + return nil, err + } + + b, err = getRawValue(b) + if err != nil { + return nil, err + } + + if err := json.Unmarshal(b, &r); err != nil { + return nil, err + } + } + + return &r, nil +} + +type ResetVpnConnectionResponse struct { + JobID string `json:"jobid"` + Account string `json:"account"` + Cidrlist string `json:"cidrlist"` + Created string `json:"created"` + Domain string `json:"domain"` + Domainid string `json:"domainid"` + Dpd bool `json:"dpd"` + Esplifetime int64 `json:"esplifetime"` + Esppolicy string `json:"esppolicy"` + Forceencap bool `json:"forceencap"` + Fordisplay bool `json:"fordisplay"` + Gateway string `json:"gateway"` + Id string `json:"id"` + Ikelifetime int64 `json:"ikelifetime"` + Ikepolicy string `json:"ikepolicy"` + Ipsecpsk string `json:"ipsecpsk"` + Passive bool `json:"passive"` + Project string `json:"project"` + Projectid string `json:"projectid"` + Publicip string `json:"publicip"` + Removed string `json:"removed"` + S2scustomergatewayid string `json:"s2scustomergatewayid"` + S2svpngatewayid string `json:"s2svpngatewayid"` + State string `json:"state"` +} + +type UpdateRemoteAccessVpnParams struct { + p map[string]interface{} +} + +func (p *UpdateRemoteAccessVpnParams) toURLValues() url.Values { + u := url.Values{} + if p.p == nil { + return u + } + if v, found := p.p["customid"]; found { + u.Set("customid", v.(string)) + } + if v, found := p.p["fordisplay"]; found { + vv := strconv.FormatBool(v.(bool)) + u.Set("fordisplay", vv) + } + if v, found := p.p["id"]; found { + u.Set("id", v.(string)) + } + return u +} + +func (p *UpdateRemoteAccessVpnParams) SetCustomid(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["customid"] = v + return +} + +func (p *UpdateRemoteAccessVpnParams) SetFordisplay(v bool) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["fordisplay"] = v + return +} + +func (p *UpdateRemoteAccessVpnParams) SetId(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["id"] = v + return +} + +// You should always use this function to get a new UpdateRemoteAccessVpnParams instance, +// as then you are sure you have configured all required params +func (s *VPNService) NewUpdateRemoteAccessVpnParams(id string) *UpdateRemoteAccessVpnParams { + p := &UpdateRemoteAccessVpnParams{} + p.p = make(map[string]interface{}) + p.p["id"] = id + return p +} + +// Updates remote access vpn +func (s *VPNService) UpdateRemoteAccessVpn(p *UpdateRemoteAccessVpnParams) (*UpdateRemoteAccessVpnResponse, error) { + resp, err := s.cs.newRequest("updateRemoteAccessVpn", p.toURLValues()) + if err != nil { + return nil, err + } + + var r UpdateRemoteAccessVpnResponse + if err := json.Unmarshal(resp, &r); err != nil { + return nil, err + } + + // If we have a async client, we need to wait for the async result + if s.cs.async { + b, err := s.cs.GetAsyncJobResult(r.JobID, s.cs.timeout) + if err != nil { + if err == AsyncTimeoutErr { + return &r, err + } + return nil, err + } + + b, err = getRawValue(b) + if err != nil { + return nil, err + } + + if err := json.Unmarshal(b, &r); err != nil { + return nil, err + } + } + + return &r, nil +} + +type UpdateRemoteAccessVpnResponse struct { + JobID string `json:"jobid"` + Account string `json:"account"` + Domain string `json:"domain"` + Domainid string `json:"domainid"` + Fordisplay bool `json:"fordisplay"` + Id string `json:"id"` + Iprange string `json:"iprange"` + Presharedkey string `json:"presharedkey"` + Project string `json:"project"` + Projectid string `json:"projectid"` + Publicip string `json:"publicip"` + Publicipid string `json:"publicipid"` + State string `json:"state"` +} + +type UpdateVpnConnectionParams struct { + p map[string]interface{} +} + +func (p *UpdateVpnConnectionParams) toURLValues() url.Values { + u := url.Values{} + if p.p == nil { + return u + } + if v, found := p.p["customid"]; found { + u.Set("customid", v.(string)) + } + if v, found := p.p["fordisplay"]; found { + vv := strconv.FormatBool(v.(bool)) + u.Set("fordisplay", vv) + } + if v, found := p.p["id"]; found { + u.Set("id", v.(string)) + } + return u +} + +func (p *UpdateVpnConnectionParams) SetCustomid(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["customid"] = v + return +} + +func (p *UpdateVpnConnectionParams) SetFordisplay(v bool) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["fordisplay"] = v + return +} + +func (p *UpdateVpnConnectionParams) SetId(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["id"] = v + return +} + +// You should always use this function to get a new UpdateVpnConnectionParams instance, +// as then you are sure you have configured all required params +func (s *VPNService) NewUpdateVpnConnectionParams(id string) *UpdateVpnConnectionParams { + p := &UpdateVpnConnectionParams{} + p.p = make(map[string]interface{}) + p.p["id"] = id + return p +} + +// Updates site to site vpn connection +func (s *VPNService) UpdateVpnConnection(p *UpdateVpnConnectionParams) (*UpdateVpnConnectionResponse, error) { + resp, err := s.cs.newRequest("updateVpnConnection", p.toURLValues()) + if err != nil { + return nil, err + } + + var r UpdateVpnConnectionResponse + if err := json.Unmarshal(resp, &r); err != nil { + return nil, err + } + + // If we have a async client, we need to wait for the async result + if s.cs.async { + b, err := s.cs.GetAsyncJobResult(r.JobID, s.cs.timeout) + if err != nil { + if err == AsyncTimeoutErr { + return &r, err + } + return nil, err + } + + b, err = getRawValue(b) + if err != nil { + return nil, err + } + + if err := json.Unmarshal(b, &r); err != nil { + return nil, err + } + } + + return &r, nil +} + +type UpdateVpnConnectionResponse struct { + JobID string `json:"jobid"` + Account string `json:"account"` + Cidrlist string `json:"cidrlist"` + Created string `json:"created"` + Domain string `json:"domain"` + Domainid string `json:"domainid"` + Dpd bool `json:"dpd"` + Esplifetime int64 `json:"esplifetime"` + Esppolicy string `json:"esppolicy"` + Forceencap bool `json:"forceencap"` + Fordisplay bool `json:"fordisplay"` + Gateway string `json:"gateway"` + Id string `json:"id"` + Ikelifetime int64 `json:"ikelifetime"` + Ikepolicy string `json:"ikepolicy"` + Ipsecpsk string `json:"ipsecpsk"` + Passive bool `json:"passive"` + Project string `json:"project"` + Projectid string `json:"projectid"` + Publicip string `json:"publicip"` + Removed string `json:"removed"` + S2scustomergatewayid string `json:"s2scustomergatewayid"` + S2svpngatewayid string `json:"s2svpngatewayid"` + State string `json:"state"` } type UpdateVpnCustomerGatewayParams struct { @@ -1833,941 +2763,30 @@ func (s *VPNService) UpdateVpnCustomerGateway(p *UpdateVpnCustomerGatewayParams) return nil, err } } + return &r, nil } type UpdateVpnCustomerGatewayResponse struct { - JobID string `json:"jobid,omitempty"` - Account string `json:"account,omitempty"` - Cidrlist string `json:"cidrlist,omitempty"` - Domain string `json:"domain,omitempty"` - Domainid string `json:"domainid,omitempty"` - Dpd bool `json:"dpd,omitempty"` - Esplifetime int64 `json:"esplifetime,omitempty"` - Esppolicy string `json:"esppolicy,omitempty"` - Forceencap bool `json:"forceencap,omitempty"` - Gateway string `json:"gateway,omitempty"` - Id string `json:"id,omitempty"` - Ikelifetime int64 `json:"ikelifetime,omitempty"` - Ikepolicy string `json:"ikepolicy,omitempty"` - Ipaddress string `json:"ipaddress,omitempty"` - Ipsecpsk string `json:"ipsecpsk,omitempty"` - Name string `json:"name,omitempty"` - Project string `json:"project,omitempty"` - Projectid string `json:"projectid,omitempty"` - Removed string `json:"removed,omitempty"` -} - -type ResetVpnConnectionParams struct { - p map[string]interface{} -} - -func (p *ResetVpnConnectionParams) toURLValues() url.Values { - u := url.Values{} - if p.p == nil { - return u - } - if v, found := p.p["account"]; found { - u.Set("account", v.(string)) - } - if v, found := p.p["domainid"]; found { - u.Set("domainid", v.(string)) - } - if v, found := p.p["id"]; found { - u.Set("id", v.(string)) - } - return u -} - -func (p *ResetVpnConnectionParams) SetAccount(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["account"] = v - return -} - -func (p *ResetVpnConnectionParams) SetDomainid(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["domainid"] = v - return -} - -func (p *ResetVpnConnectionParams) SetId(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["id"] = v - return -} - -// You should always use this function to get a new ResetVpnConnectionParams instance, -// as then you are sure you have configured all required params -func (s *VPNService) NewResetVpnConnectionParams(id string) *ResetVpnConnectionParams { - p := &ResetVpnConnectionParams{} - p.p = make(map[string]interface{}) - p.p["id"] = id - return p -} - -// Reset site to site vpn connection -func (s *VPNService) ResetVpnConnection(p *ResetVpnConnectionParams) (*ResetVpnConnectionResponse, error) { - resp, err := s.cs.newRequest("resetVpnConnection", p.toURLValues()) - if err != nil { - return nil, err - } - - var r ResetVpnConnectionResponse - if err := json.Unmarshal(resp, &r); err != nil { - return nil, err - } - - // If we have a async client, we need to wait for the async result - if s.cs.async { - b, err := s.cs.GetAsyncJobResult(r.JobID, s.cs.timeout) - if err != nil { - if err == AsyncTimeoutErr { - return &r, err - } - return nil, err - } - - b, err = getRawValue(b) - if err != nil { - return nil, err - } - - if err := json.Unmarshal(b, &r); err != nil { - return nil, err - } - } - return &r, nil -} - -type ResetVpnConnectionResponse struct { - JobID string `json:"jobid,omitempty"` - Account string `json:"account,omitempty"` - Cidrlist string `json:"cidrlist,omitempty"` - Created string `json:"created,omitempty"` - Domain string `json:"domain,omitempty"` - Domainid string `json:"domainid,omitempty"` - Dpd bool `json:"dpd,omitempty"` - Esplifetime int64 `json:"esplifetime,omitempty"` - Esppolicy string `json:"esppolicy,omitempty"` - Forceencap bool `json:"forceencap,omitempty"` - Fordisplay bool `json:"fordisplay,omitempty"` - Gateway string `json:"gateway,omitempty"` - Id string `json:"id,omitempty"` - Ikelifetime int64 `json:"ikelifetime,omitempty"` - Ikepolicy string `json:"ikepolicy,omitempty"` - Ipsecpsk string `json:"ipsecpsk,omitempty"` - Passive bool `json:"passive,omitempty"` - Project string `json:"project,omitempty"` - Projectid string `json:"projectid,omitempty"` - Publicip string `json:"publicip,omitempty"` - Removed string `json:"removed,omitempty"` - S2scustomergatewayid string `json:"s2scustomergatewayid,omitempty"` - S2svpngatewayid string `json:"s2svpngatewayid,omitempty"` - State string `json:"state,omitempty"` -} - -type ListVpnCustomerGatewaysParams struct { - p map[string]interface{} -} - -func (p *ListVpnCustomerGatewaysParams) toURLValues() url.Values { - u := url.Values{} - if p.p == nil { - return u - } - if v, found := p.p["account"]; found { - u.Set("account", v.(string)) - } - if v, found := p.p["domainid"]; found { - u.Set("domainid", v.(string)) - } - if v, found := p.p["id"]; found { - u.Set("id", v.(string)) - } - if v, found := p.p["isrecursive"]; found { - vv := strconv.FormatBool(v.(bool)) - u.Set("isrecursive", vv) - } - if v, found := p.p["keyword"]; found { - u.Set("keyword", v.(string)) - } - if v, found := p.p["listall"]; found { - vv := strconv.FormatBool(v.(bool)) - u.Set("listall", vv) - } - if v, found := p.p["page"]; found { - vv := strconv.Itoa(v.(int)) - u.Set("page", vv) - } - if v, found := p.p["pagesize"]; found { - vv := strconv.Itoa(v.(int)) - u.Set("pagesize", vv) - } - if v, found := p.p["projectid"]; found { - u.Set("projectid", v.(string)) - } - return u -} - -func (p *ListVpnCustomerGatewaysParams) SetAccount(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["account"] = v - return -} - -func (p *ListVpnCustomerGatewaysParams) SetDomainid(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["domainid"] = v - return -} - -func (p *ListVpnCustomerGatewaysParams) SetId(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["id"] = v - return -} - -func (p *ListVpnCustomerGatewaysParams) SetIsrecursive(v bool) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["isrecursive"] = v - return -} - -func (p *ListVpnCustomerGatewaysParams) SetKeyword(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["keyword"] = v - return -} - -func (p *ListVpnCustomerGatewaysParams) SetListall(v bool) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["listall"] = v - return -} - -func (p *ListVpnCustomerGatewaysParams) SetPage(v int) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["page"] = v - return -} - -func (p *ListVpnCustomerGatewaysParams) SetPagesize(v int) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["pagesize"] = v - return -} - -func (p *ListVpnCustomerGatewaysParams) SetProjectid(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["projectid"] = v - return -} - -// You should always use this function to get a new ListVpnCustomerGatewaysParams instance, -// as then you are sure you have configured all required params -func (s *VPNService) NewListVpnCustomerGatewaysParams() *ListVpnCustomerGatewaysParams { - p := &ListVpnCustomerGatewaysParams{} - p.p = make(map[string]interface{}) - return p -} - -// This is a courtesy helper function, which in some cases may not work as expected! -func (s *VPNService) GetVpnCustomerGatewayID(keyword string, opts ...OptionFunc) (string, int, error) { - p := &ListVpnCustomerGatewaysParams{} - p.p = make(map[string]interface{}) - - p.p["keyword"] = keyword - - for _, fn := range opts { - if err := fn(s.cs, p); err != nil { - return "", -1, err - } - } - - l, err := s.ListVpnCustomerGateways(p) - if err != nil { - return "", -1, err - } - - if l.Count == 0 { - return "", l.Count, fmt.Errorf("No match found for %s: %+v", keyword, l) - } - - if l.Count == 1 { - return l.VpnCustomerGateways[0].Id, l.Count, nil - } - - if l.Count > 1 { - for _, v := range l.VpnCustomerGateways { - if v.Name == keyword { - return v.Id, l.Count, nil - } - } - } - return "", l.Count, fmt.Errorf("Could not find an exact match for %s: %+v", keyword, l) -} - -// This is a courtesy helper function, which in some cases may not work as expected! -func (s *VPNService) GetVpnCustomerGatewayByName(name string, opts ...OptionFunc) (*VpnCustomerGateway, int, error) { - id, count, err := s.GetVpnCustomerGatewayID(name, opts...) - if err != nil { - return nil, count, err - } - - r, count, err := s.GetVpnCustomerGatewayByID(id, opts...) - if err != nil { - return nil, count, err - } - return r, count, nil -} - -// This is a courtesy helper function, which in some cases may not work as expected! -func (s *VPNService) GetVpnCustomerGatewayByID(id string, opts ...OptionFunc) (*VpnCustomerGateway, int, error) { - p := &ListVpnCustomerGatewaysParams{} - p.p = make(map[string]interface{}) - - p.p["id"] = id - - for _, fn := range opts { - if err := fn(s.cs, p); err != nil { - return nil, -1, err - } - } - - l, err := s.ListVpnCustomerGateways(p) - if err != nil { - if strings.Contains(err.Error(), fmt.Sprintf( - "Invalid parameter id value=%s due to incorrect long value format, "+ - "or entity does not exist", id)) { - return nil, 0, fmt.Errorf("No match found for %s: %+v", id, l) - } - return nil, -1, err - } - - if l.Count == 0 { - return nil, l.Count, fmt.Errorf("No match found for %s: %+v", id, l) - } - - if l.Count == 1 { - return l.VpnCustomerGateways[0], l.Count, nil - } - return nil, l.Count, fmt.Errorf("There is more then one result for VpnCustomerGateway UUID: %s!", id) -} - -// Lists site to site vpn customer gateways -func (s *VPNService) ListVpnCustomerGateways(p *ListVpnCustomerGatewaysParams) (*ListVpnCustomerGatewaysResponse, error) { - resp, err := s.cs.newRequest("listVpnCustomerGateways", p.toURLValues()) - if err != nil { - return nil, err - } - - var r ListVpnCustomerGatewaysResponse - if err := json.Unmarshal(resp, &r); err != nil { - return nil, err - } - return &r, nil -} - -type ListVpnCustomerGatewaysResponse struct { - Count int `json:"count"` - VpnCustomerGateways []*VpnCustomerGateway `json:"vpncustomergateway"` -} - -type VpnCustomerGateway struct { - Account string `json:"account,omitempty"` - Cidrlist string `json:"cidrlist,omitempty"` - Domain string `json:"domain,omitempty"` - Domainid string `json:"domainid,omitempty"` - Dpd bool `json:"dpd,omitempty"` - Esplifetime int64 `json:"esplifetime,omitempty"` - Esppolicy string `json:"esppolicy,omitempty"` - Forceencap bool `json:"forceencap,omitempty"` - Gateway string `json:"gateway,omitempty"` - Id string `json:"id,omitempty"` - Ikelifetime int64 `json:"ikelifetime,omitempty"` - Ikepolicy string `json:"ikepolicy,omitempty"` - Ipaddress string `json:"ipaddress,omitempty"` - Ipsecpsk string `json:"ipsecpsk,omitempty"` - Name string `json:"name,omitempty"` - Project string `json:"project,omitempty"` - Projectid string `json:"projectid,omitempty"` - Removed string `json:"removed,omitempty"` -} - -type ListVpnGatewaysParams struct { - p map[string]interface{} -} - -func (p *ListVpnGatewaysParams) toURLValues() url.Values { - u := url.Values{} - if p.p == nil { - return u - } - if v, found := p.p["account"]; found { - u.Set("account", v.(string)) - } - if v, found := p.p["domainid"]; found { - u.Set("domainid", v.(string)) - } - if v, found := p.p["fordisplay"]; found { - vv := strconv.FormatBool(v.(bool)) - u.Set("fordisplay", vv) - } - if v, found := p.p["id"]; found { - u.Set("id", v.(string)) - } - if v, found := p.p["isrecursive"]; found { - vv := strconv.FormatBool(v.(bool)) - u.Set("isrecursive", vv) - } - if v, found := p.p["keyword"]; found { - u.Set("keyword", v.(string)) - } - if v, found := p.p["listall"]; found { - vv := strconv.FormatBool(v.(bool)) - u.Set("listall", vv) - } - if v, found := p.p["page"]; found { - vv := strconv.Itoa(v.(int)) - u.Set("page", vv) - } - if v, found := p.p["pagesize"]; found { - vv := strconv.Itoa(v.(int)) - u.Set("pagesize", vv) - } - if v, found := p.p["projectid"]; found { - u.Set("projectid", v.(string)) - } - if v, found := p.p["vpcid"]; found { - u.Set("vpcid", v.(string)) - } - return u -} - -func (p *ListVpnGatewaysParams) SetAccount(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["account"] = v - return -} - -func (p *ListVpnGatewaysParams) SetDomainid(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["domainid"] = v - return -} - -func (p *ListVpnGatewaysParams) SetFordisplay(v bool) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["fordisplay"] = v - return -} - -func (p *ListVpnGatewaysParams) SetId(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["id"] = v - return -} - -func (p *ListVpnGatewaysParams) SetIsrecursive(v bool) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["isrecursive"] = v - return -} - -func (p *ListVpnGatewaysParams) SetKeyword(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["keyword"] = v - return -} - -func (p *ListVpnGatewaysParams) SetListall(v bool) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["listall"] = v - return -} - -func (p *ListVpnGatewaysParams) SetPage(v int) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["page"] = v - return -} - -func (p *ListVpnGatewaysParams) SetPagesize(v int) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["pagesize"] = v - return -} - -func (p *ListVpnGatewaysParams) SetProjectid(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["projectid"] = v - return -} - -func (p *ListVpnGatewaysParams) SetVpcid(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["vpcid"] = v - return -} - -// You should always use this function to get a new ListVpnGatewaysParams instance, -// as then you are sure you have configured all required params -func (s *VPNService) NewListVpnGatewaysParams() *ListVpnGatewaysParams { - p := &ListVpnGatewaysParams{} - p.p = make(map[string]interface{}) - return p -} - -// This is a courtesy helper function, which in some cases may not work as expected! -func (s *VPNService) GetVpnGatewayByID(id string, opts ...OptionFunc) (*VpnGateway, int, error) { - p := &ListVpnGatewaysParams{} - p.p = make(map[string]interface{}) - - p.p["id"] = id - - for _, fn := range opts { - if err := fn(s.cs, p); err != nil { - return nil, -1, err - } - } - - l, err := s.ListVpnGateways(p) - if err != nil { - if strings.Contains(err.Error(), fmt.Sprintf( - "Invalid parameter id value=%s due to incorrect long value format, "+ - "or entity does not exist", id)) { - return nil, 0, fmt.Errorf("No match found for %s: %+v", id, l) - } - return nil, -1, err - } - - if l.Count == 0 { - return nil, l.Count, fmt.Errorf("No match found for %s: %+v", id, l) - } - - if l.Count == 1 { - return l.VpnGateways[0], l.Count, nil - } - return nil, l.Count, fmt.Errorf("There is more then one result for VpnGateway UUID: %s!", id) -} - -// Lists site 2 site vpn gateways -func (s *VPNService) ListVpnGateways(p *ListVpnGatewaysParams) (*ListVpnGatewaysResponse, error) { - resp, err := s.cs.newRequest("listVpnGateways", p.toURLValues()) - if err != nil { - return nil, err - } - - var r ListVpnGatewaysResponse - if err := json.Unmarshal(resp, &r); err != nil { - return nil, err - } - return &r, nil -} - -type ListVpnGatewaysResponse struct { - Count int `json:"count"` - VpnGateways []*VpnGateway `json:"vpngateway"` -} - -type VpnGateway struct { - Account string `json:"account,omitempty"` - Domain string `json:"domain,omitempty"` - Domainid string `json:"domainid,omitempty"` - Fordisplay bool `json:"fordisplay,omitempty"` - Id string `json:"id,omitempty"` - Project string `json:"project,omitempty"` - Projectid string `json:"projectid,omitempty"` - Publicip string `json:"publicip,omitempty"` - Removed string `json:"removed,omitempty"` - Vpcid string `json:"vpcid,omitempty"` -} - -type ListVpnConnectionsParams struct { - p map[string]interface{} -} - -func (p *ListVpnConnectionsParams) toURLValues() url.Values { - u := url.Values{} - if p.p == nil { - return u - } - if v, found := p.p["account"]; found { - u.Set("account", v.(string)) - } - if v, found := p.p["domainid"]; found { - u.Set("domainid", v.(string)) - } - if v, found := p.p["fordisplay"]; found { - vv := strconv.FormatBool(v.(bool)) - u.Set("fordisplay", vv) - } - if v, found := p.p["id"]; found { - u.Set("id", v.(string)) - } - if v, found := p.p["isrecursive"]; found { - vv := strconv.FormatBool(v.(bool)) - u.Set("isrecursive", vv) - } - if v, found := p.p["keyword"]; found { - u.Set("keyword", v.(string)) - } - if v, found := p.p["listall"]; found { - vv := strconv.FormatBool(v.(bool)) - u.Set("listall", vv) - } - if v, found := p.p["page"]; found { - vv := strconv.Itoa(v.(int)) - u.Set("page", vv) - } - if v, found := p.p["pagesize"]; found { - vv := strconv.Itoa(v.(int)) - u.Set("pagesize", vv) - } - if v, found := p.p["projectid"]; found { - u.Set("projectid", v.(string)) - } - if v, found := p.p["vpcid"]; found { - u.Set("vpcid", v.(string)) - } - return u -} - -func (p *ListVpnConnectionsParams) SetAccount(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["account"] = v - return -} - -func (p *ListVpnConnectionsParams) SetDomainid(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["domainid"] = v - return -} - -func (p *ListVpnConnectionsParams) SetFordisplay(v bool) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["fordisplay"] = v - return -} - -func (p *ListVpnConnectionsParams) SetId(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["id"] = v - return -} - -func (p *ListVpnConnectionsParams) SetIsrecursive(v bool) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["isrecursive"] = v - return -} - -func (p *ListVpnConnectionsParams) SetKeyword(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["keyword"] = v - return -} - -func (p *ListVpnConnectionsParams) SetListall(v bool) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["listall"] = v - return -} - -func (p *ListVpnConnectionsParams) SetPage(v int) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["page"] = v - return -} - -func (p *ListVpnConnectionsParams) SetPagesize(v int) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["pagesize"] = v - return -} - -func (p *ListVpnConnectionsParams) SetProjectid(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["projectid"] = v - return -} - -func (p *ListVpnConnectionsParams) SetVpcid(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["vpcid"] = v - return -} - -// You should always use this function to get a new ListVpnConnectionsParams instance, -// as then you are sure you have configured all required params -func (s *VPNService) NewListVpnConnectionsParams() *ListVpnConnectionsParams { - p := &ListVpnConnectionsParams{} - p.p = make(map[string]interface{}) - return p -} - -// This is a courtesy helper function, which in some cases may not work as expected! -func (s *VPNService) GetVpnConnectionByID(id string, opts ...OptionFunc) (*VpnConnection, int, error) { - p := &ListVpnConnectionsParams{} - p.p = make(map[string]interface{}) - - p.p["id"] = id - - for _, fn := range opts { - if err := fn(s.cs, p); err != nil { - return nil, -1, err - } - } - - l, err := s.ListVpnConnections(p) - if err != nil { - if strings.Contains(err.Error(), fmt.Sprintf( - "Invalid parameter id value=%s due to incorrect long value format, "+ - "or entity does not exist", id)) { - return nil, 0, fmt.Errorf("No match found for %s: %+v", id, l) - } - return nil, -1, err - } - - if l.Count == 0 { - return nil, l.Count, fmt.Errorf("No match found for %s: %+v", id, l) - } - - if l.Count == 1 { - return l.VpnConnections[0], l.Count, nil - } - return nil, l.Count, fmt.Errorf("There is more then one result for VpnConnection UUID: %s!", id) -} - -// Lists site to site vpn connection gateways -func (s *VPNService) ListVpnConnections(p *ListVpnConnectionsParams) (*ListVpnConnectionsResponse, error) { - resp, err := s.cs.newRequest("listVpnConnections", p.toURLValues()) - if err != nil { - return nil, err - } - - var r ListVpnConnectionsResponse - if err := json.Unmarshal(resp, &r); err != nil { - return nil, err - } - return &r, nil -} - -type ListVpnConnectionsResponse struct { - Count int `json:"count"` - VpnConnections []*VpnConnection `json:"vpnconnection"` -} - -type VpnConnection struct { - Account string `json:"account,omitempty"` - Cidrlist string `json:"cidrlist,omitempty"` - Created string `json:"created,omitempty"` - Domain string `json:"domain,omitempty"` - Domainid string `json:"domainid,omitempty"` - Dpd bool `json:"dpd,omitempty"` - Esplifetime int64 `json:"esplifetime,omitempty"` - Esppolicy string `json:"esppolicy,omitempty"` - Forceencap bool `json:"forceencap,omitempty"` - Fordisplay bool `json:"fordisplay,omitempty"` - Gateway string `json:"gateway,omitempty"` - Id string `json:"id,omitempty"` - Ikelifetime int64 `json:"ikelifetime,omitempty"` - Ikepolicy string `json:"ikepolicy,omitempty"` - Ipsecpsk string `json:"ipsecpsk,omitempty"` - Passive bool `json:"passive,omitempty"` - Project string `json:"project,omitempty"` - Projectid string `json:"projectid,omitempty"` - Publicip string `json:"publicip,omitempty"` - Removed string `json:"removed,omitempty"` - S2scustomergatewayid string `json:"s2scustomergatewayid,omitempty"` - S2svpngatewayid string `json:"s2svpngatewayid,omitempty"` - State string `json:"state,omitempty"` -} - -type UpdateVpnConnectionParams struct { - p map[string]interface{} -} - -func (p *UpdateVpnConnectionParams) toURLValues() url.Values { - u := url.Values{} - if p.p == nil { - return u - } - if v, found := p.p["customid"]; found { - u.Set("customid", v.(string)) - } - if v, found := p.p["fordisplay"]; found { - vv := strconv.FormatBool(v.(bool)) - u.Set("fordisplay", vv) - } - if v, found := p.p["id"]; found { - u.Set("id", v.(string)) - } - return u -} - -func (p *UpdateVpnConnectionParams) SetCustomid(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["customid"] = v - return -} - -func (p *UpdateVpnConnectionParams) SetFordisplay(v bool) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["fordisplay"] = v - return -} - -func (p *UpdateVpnConnectionParams) SetId(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["id"] = v - return -} - -// You should always use this function to get a new UpdateVpnConnectionParams instance, -// as then you are sure you have configured all required params -func (s *VPNService) NewUpdateVpnConnectionParams(id string) *UpdateVpnConnectionParams { - p := &UpdateVpnConnectionParams{} - p.p = make(map[string]interface{}) - p.p["id"] = id - return p -} - -// Updates site to site vpn connection -func (s *VPNService) UpdateVpnConnection(p *UpdateVpnConnectionParams) (*UpdateVpnConnectionResponse, error) { - resp, err := s.cs.newRequest("updateVpnConnection", p.toURLValues()) - if err != nil { - return nil, err - } - - var r UpdateVpnConnectionResponse - if err := json.Unmarshal(resp, &r); err != nil { - return nil, err - } - - // If we have a async client, we need to wait for the async result - if s.cs.async { - b, err := s.cs.GetAsyncJobResult(r.JobID, s.cs.timeout) - if err != nil { - if err == AsyncTimeoutErr { - return &r, err - } - return nil, err - } - - b, err = getRawValue(b) - if err != nil { - return nil, err - } - - if err := json.Unmarshal(b, &r); err != nil { - return nil, err - } - } - return &r, nil -} - -type UpdateVpnConnectionResponse struct { - JobID string `json:"jobid,omitempty"` - Account string `json:"account,omitempty"` - Cidrlist string `json:"cidrlist,omitempty"` - Created string `json:"created,omitempty"` - Domain string `json:"domain,omitempty"` - Domainid string `json:"domainid,omitempty"` - Dpd bool `json:"dpd,omitempty"` - Esplifetime int64 `json:"esplifetime,omitempty"` - Esppolicy string `json:"esppolicy,omitempty"` - Forceencap bool `json:"forceencap,omitempty"` - Fordisplay bool `json:"fordisplay,omitempty"` - Gateway string `json:"gateway,omitempty"` - Id string `json:"id,omitempty"` - Ikelifetime int64 `json:"ikelifetime,omitempty"` - Ikepolicy string `json:"ikepolicy,omitempty"` - Ipsecpsk string `json:"ipsecpsk,omitempty"` - Passive bool `json:"passive,omitempty"` - Project string `json:"project,omitempty"` - Projectid string `json:"projectid,omitempty"` - Publicip string `json:"publicip,omitempty"` - Removed string `json:"removed,omitempty"` - S2scustomergatewayid string `json:"s2scustomergatewayid,omitempty"` - S2svpngatewayid string `json:"s2svpngatewayid,omitempty"` - State string `json:"state,omitempty"` + JobID string `json:"jobid"` + Account string `json:"account"` + Cidrlist string `json:"cidrlist"` + Domain string `json:"domain"` + Domainid string `json:"domainid"` + Dpd bool `json:"dpd"` + Esplifetime int64 `json:"esplifetime"` + Esppolicy string `json:"esppolicy"` + Forceencap bool `json:"forceencap"` + Gateway string `json:"gateway"` + Id string `json:"id"` + Ikelifetime int64 `json:"ikelifetime"` + Ikepolicy string `json:"ikepolicy"` + Ipaddress string `json:"ipaddress"` + Ipsecpsk string `json:"ipsecpsk"` + Name string `json:"name"` + Project string `json:"project"` + Projectid string `json:"projectid"` + Removed string `json:"removed"` } type UpdateVpnGatewayParams struct { @@ -2856,19 +2875,20 @@ func (s *VPNService) UpdateVpnGateway(p *UpdateVpnGatewayParams) (*UpdateVpnGate return nil, err } } + return &r, nil } type UpdateVpnGatewayResponse struct { - JobID string `json:"jobid,omitempty"` - Account string `json:"account,omitempty"` - Domain string `json:"domain,omitempty"` - Domainid string `json:"domainid,omitempty"` - Fordisplay bool `json:"fordisplay,omitempty"` - Id string `json:"id,omitempty"` - Project string `json:"project,omitempty"` - Projectid string `json:"projectid,omitempty"` - Publicip string `json:"publicip,omitempty"` - Removed string `json:"removed,omitempty"` - Vpcid string `json:"vpcid,omitempty"` + JobID string `json:"jobid"` + Account string `json:"account"` + Domain string `json:"domain"` + Domainid string `json:"domainid"` + Fordisplay bool `json:"fordisplay"` + Id string `json:"id"` + Project string `json:"project"` + Projectid string `json:"projectid"` + Publicip string `json:"publicip"` + Removed string `json:"removed"` + Vpcid string `json:"vpcid"` } diff --git a/vendor/github.com/xanzy/go-cloudstack/cloudstack/VirtualMachineService.go b/vendor/github.com/xanzy/go-cloudstack/cloudstack/VirtualMachineService.go index 8be3066f4..638d81482 100644 --- a/vendor/github.com/xanzy/go-cloudstack/cloudstack/VirtualMachineService.go +++ b/vendor/github.com/xanzy/go-cloudstack/cloudstack/VirtualMachineService.go @@ -1,5 +1,5 @@ // -// Copyright 2016, Sander van Harmelen +// Copyright 2018, Sander van Harmelen // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -24,6 +24,679 @@ import ( "strings" ) +type AddNicToVirtualMachineParams struct { + p map[string]interface{} +} + +func (p *AddNicToVirtualMachineParams) toURLValues() url.Values { + u := url.Values{} + if p.p == nil { + return u + } + if v, found := p.p["dhcpoptions"]; found { + i := 0 + for k, vv := range v.(map[string]string) { + u.Set(fmt.Sprintf("dhcpoptions[%d].key", i), k) + u.Set(fmt.Sprintf("dhcpoptions[%d].value", i), vv) + i++ + } + } + if v, found := p.p["ipaddress"]; found { + u.Set("ipaddress", v.(string)) + } + if v, found := p.p["macaddress"]; found { + u.Set("macaddress", v.(string)) + } + if v, found := p.p["networkid"]; found { + u.Set("networkid", v.(string)) + } + if v, found := p.p["virtualmachineid"]; found { + u.Set("virtualmachineid", v.(string)) + } + return u +} + +func (p *AddNicToVirtualMachineParams) SetDhcpoptions(v map[string]string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["dhcpoptions"] = v + return +} + +func (p *AddNicToVirtualMachineParams) SetIpaddress(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["ipaddress"] = v + return +} + +func (p *AddNicToVirtualMachineParams) SetMacaddress(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["macaddress"] = v + return +} + +func (p *AddNicToVirtualMachineParams) SetNetworkid(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["networkid"] = v + return +} + +func (p *AddNicToVirtualMachineParams) SetVirtualmachineid(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["virtualmachineid"] = v + return +} + +// You should always use this function to get a new AddNicToVirtualMachineParams instance, +// as then you are sure you have configured all required params +func (s *VirtualMachineService) NewAddNicToVirtualMachineParams(networkid string, virtualmachineid string) *AddNicToVirtualMachineParams { + p := &AddNicToVirtualMachineParams{} + p.p = make(map[string]interface{}) + p.p["networkid"] = networkid + p.p["virtualmachineid"] = virtualmachineid + return p +} + +// Adds VM to specified network by creating a NIC +func (s *VirtualMachineService) AddNicToVirtualMachine(p *AddNicToVirtualMachineParams) (*AddNicToVirtualMachineResponse, error) { + resp, err := s.cs.newRequest("addNicToVirtualMachine", p.toURLValues()) + if err != nil { + return nil, err + } + + var r AddNicToVirtualMachineResponse + if err := json.Unmarshal(resp, &r); err != nil { + return nil, err + } + + // If we have a async client, we need to wait for the async result + if s.cs.async { + b, err := s.cs.GetAsyncJobResult(r.JobID, s.cs.timeout) + if err != nil { + if err == AsyncTimeoutErr { + return &r, err + } + return nil, err + } + + b, err = getRawValue(b) + if err != nil { + return nil, err + } + + if err := json.Unmarshal(b, &r); err != nil { + return nil, err + } + } + + return &r, nil +} + +type AddNicToVirtualMachineResponse struct { + JobID string `json:"jobid"` + Account string `json:"account"` + Affinitygroup []AddNicToVirtualMachineResponseAffinitygroup `json:"affinitygroup"` + Cpunumber int `json:"cpunumber"` + Cpuspeed int `json:"cpuspeed"` + Cpuused string `json:"cpuused"` + Created string `json:"created"` + Details map[string]string `json:"details"` + Diskioread int64 `json:"diskioread"` + Diskiowrite int64 `json:"diskiowrite"` + Diskkbsread int64 `json:"diskkbsread"` + Diskkbswrite int64 `json:"diskkbswrite"` + Diskofferingid string `json:"diskofferingid"` + Diskofferingname string `json:"diskofferingname"` + Displayname string `json:"displayname"` + Displayvm bool `json:"displayvm"` + Domain string `json:"domain"` + Domainid string `json:"domainid"` + Forvirtualnetwork bool `json:"forvirtualnetwork"` + Group string `json:"group"` + Groupid string `json:"groupid"` + Guestosid string `json:"guestosid"` + Haenable bool `json:"haenable"` + Hostid string `json:"hostid"` + Hostname string `json:"hostname"` + Hypervisor string `json:"hypervisor"` + Id string `json:"id"` + Instancename string `json:"instancename"` + Isdynamicallyscalable bool `json:"isdynamicallyscalable"` + Isodisplaytext string `json:"isodisplaytext"` + Isoid string `json:"isoid"` + Isoname string `json:"isoname"` + Keypair string `json:"keypair"` + Memory int `json:"memory"` + Memoryintfreekbs int64 `json:"memoryintfreekbs"` + Memorykbs int64 `json:"memorykbs"` + Memorytargetkbs int64 `json:"memorytargetkbs"` + Name string `json:"name"` + Networkkbsread int64 `json:"networkkbsread"` + Networkkbswrite int64 `json:"networkkbswrite"` + Nic []Nic `json:"nic"` + Ostypeid int64 `json:"ostypeid"` + Password string `json:"password"` + Passwordenabled bool `json:"passwordenabled"` + Project string `json:"project"` + Projectid string `json:"projectid"` + Publicip string `json:"publicip"` + Publicipid string `json:"publicipid"` + Rootdeviceid int64 `json:"rootdeviceid"` + Rootdevicetype string `json:"rootdevicetype"` + Securitygroup []AddNicToVirtualMachineResponseSecuritygroup `json:"securitygroup"` + Serviceofferingid string `json:"serviceofferingid"` + Serviceofferingname string `json:"serviceofferingname"` + Servicestate string `json:"servicestate"` + State string `json:"state"` + Templatedisplaytext string `json:"templatedisplaytext"` + Templateid string `json:"templateid"` + Templatename string `json:"templatename"` + Userid string `json:"userid"` + Username string `json:"username"` + Vgpu string `json:"vgpu"` + Zoneid string `json:"zoneid"` + Zonename string `json:"zonename"` +} + +type AddNicToVirtualMachineResponseSecuritygroup struct { + Account string `json:"account"` + Description string `json:"description"` + Domain string `json:"domain"` + Domainid string `json:"domainid"` + Egressrule []AddNicToVirtualMachineResponseSecuritygroupRule `json:"egressrule"` + Id string `json:"id"` + Ingressrule []AddNicToVirtualMachineResponseSecuritygroupRule `json:"ingressrule"` + Name string `json:"name"` + Project string `json:"project"` + Projectid string `json:"projectid"` + Tags []Tags `json:"tags"` + Virtualmachinecount int `json:"virtualmachinecount"` + Virtualmachineids []interface{} `json:"virtualmachineids"` +} + +type AddNicToVirtualMachineResponseSecuritygroupRule struct { + Account string `json:"account"` + Cidr string `json:"cidr"` + Endport int `json:"endport"` + Icmpcode int `json:"icmpcode"` + Icmptype int `json:"icmptype"` + Protocol string `json:"protocol"` + Ruleid string `json:"ruleid"` + Securitygroupname string `json:"securitygroupname"` + Startport int `json:"startport"` + Tags []Tags `json:"tags"` +} + +type AddNicToVirtualMachineResponseAffinitygroup struct { + Account string `json:"account"` + Description string `json:"description"` + Domain string `json:"domain"` + Domainid string `json:"domainid"` + Id string `json:"id"` + Name string `json:"name"` + Project string `json:"project"` + Projectid string `json:"projectid"` + Type string `json:"type"` + VirtualmachineIds []string `json:"virtualmachineIds"` +} + +type AssignVirtualMachineParams struct { + p map[string]interface{} +} + +func (p *AssignVirtualMachineParams) toURLValues() url.Values { + u := url.Values{} + if p.p == nil { + return u + } + if v, found := p.p["account"]; found { + u.Set("account", v.(string)) + } + if v, found := p.p["domainid"]; found { + u.Set("domainid", v.(string)) + } + if v, found := p.p["networkids"]; found { + vv := strings.Join(v.([]string), ",") + u.Set("networkids", vv) + } + if v, found := p.p["projectid"]; found { + u.Set("projectid", v.(string)) + } + if v, found := p.p["securitygroupids"]; found { + vv := strings.Join(v.([]string), ",") + u.Set("securitygroupids", vv) + } + if v, found := p.p["virtualmachineid"]; found { + u.Set("virtualmachineid", v.(string)) + } + return u +} + +func (p *AssignVirtualMachineParams) SetAccount(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["account"] = v + return +} + +func (p *AssignVirtualMachineParams) SetDomainid(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["domainid"] = v + return +} + +func (p *AssignVirtualMachineParams) SetNetworkids(v []string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["networkids"] = v + return +} + +func (p *AssignVirtualMachineParams) SetProjectid(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["projectid"] = v + return +} + +func (p *AssignVirtualMachineParams) SetSecuritygroupids(v []string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["securitygroupids"] = v + return +} + +func (p *AssignVirtualMachineParams) SetVirtualmachineid(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["virtualmachineid"] = v + return +} + +// You should always use this function to get a new AssignVirtualMachineParams instance, +// as then you are sure you have configured all required params +func (s *VirtualMachineService) NewAssignVirtualMachineParams(virtualmachineid string) *AssignVirtualMachineParams { + p := &AssignVirtualMachineParams{} + p.p = make(map[string]interface{}) + p.p["virtualmachineid"] = virtualmachineid + return p +} + +// Change ownership of a VM from one account to another. This API is available for Basic zones with security groups and Advanced zones with guest networks. A root administrator can reassign a VM from any account to any other account in any domain. A domain administrator can reassign a VM to any account in the same domain. +func (s *VirtualMachineService) AssignVirtualMachine(p *AssignVirtualMachineParams) (*AssignVirtualMachineResponse, error) { + resp, err := s.cs.newRequest("assignVirtualMachine", p.toURLValues()) + if err != nil { + return nil, err + } + + var r AssignVirtualMachineResponse + if err := json.Unmarshal(resp, &r); err != nil { + return nil, err + } + + return &r, nil +} + +type AssignVirtualMachineResponse struct { + Account string `json:"account"` + Affinitygroup []AssignVirtualMachineResponseAffinitygroup `json:"affinitygroup"` + Cpunumber int `json:"cpunumber"` + Cpuspeed int `json:"cpuspeed"` + Cpuused string `json:"cpuused"` + Created string `json:"created"` + Details map[string]string `json:"details"` + Diskioread int64 `json:"diskioread"` + Diskiowrite int64 `json:"diskiowrite"` + Diskkbsread int64 `json:"diskkbsread"` + Diskkbswrite int64 `json:"diskkbswrite"` + Diskofferingid string `json:"diskofferingid"` + Diskofferingname string `json:"diskofferingname"` + Displayname string `json:"displayname"` + Displayvm bool `json:"displayvm"` + Domain string `json:"domain"` + Domainid string `json:"domainid"` + Forvirtualnetwork bool `json:"forvirtualnetwork"` + Group string `json:"group"` + Groupid string `json:"groupid"` + Guestosid string `json:"guestosid"` + Haenable bool `json:"haenable"` + Hostid string `json:"hostid"` + Hostname string `json:"hostname"` + Hypervisor string `json:"hypervisor"` + Id string `json:"id"` + Instancename string `json:"instancename"` + Isdynamicallyscalable bool `json:"isdynamicallyscalable"` + Isodisplaytext string `json:"isodisplaytext"` + Isoid string `json:"isoid"` + Isoname string `json:"isoname"` + Keypair string `json:"keypair"` + Memory int `json:"memory"` + Memoryintfreekbs int64 `json:"memoryintfreekbs"` + Memorykbs int64 `json:"memorykbs"` + Memorytargetkbs int64 `json:"memorytargetkbs"` + Name string `json:"name"` + Networkkbsread int64 `json:"networkkbsread"` + Networkkbswrite int64 `json:"networkkbswrite"` + Nic []Nic `json:"nic"` + Ostypeid int64 `json:"ostypeid"` + Password string `json:"password"` + Passwordenabled bool `json:"passwordenabled"` + Project string `json:"project"` + Projectid string `json:"projectid"` + Publicip string `json:"publicip"` + Publicipid string `json:"publicipid"` + Rootdeviceid int64 `json:"rootdeviceid"` + Rootdevicetype string `json:"rootdevicetype"` + Securitygroup []AssignVirtualMachineResponseSecuritygroup `json:"securitygroup"` + Serviceofferingid string `json:"serviceofferingid"` + Serviceofferingname string `json:"serviceofferingname"` + Servicestate string `json:"servicestate"` + State string `json:"state"` + Templatedisplaytext string `json:"templatedisplaytext"` + Templateid string `json:"templateid"` + Templatename string `json:"templatename"` + Userid string `json:"userid"` + Username string `json:"username"` + Vgpu string `json:"vgpu"` + Zoneid string `json:"zoneid"` + Zonename string `json:"zonename"` +} + +type AssignVirtualMachineResponseSecuritygroup struct { + Account string `json:"account"` + Description string `json:"description"` + Domain string `json:"domain"` + Domainid string `json:"domainid"` + Egressrule []AssignVirtualMachineResponseSecuritygroupRule `json:"egressrule"` + Id string `json:"id"` + Ingressrule []AssignVirtualMachineResponseSecuritygroupRule `json:"ingressrule"` + Name string `json:"name"` + Project string `json:"project"` + Projectid string `json:"projectid"` + Tags []Tags `json:"tags"` + Virtualmachinecount int `json:"virtualmachinecount"` + Virtualmachineids []interface{} `json:"virtualmachineids"` +} + +type AssignVirtualMachineResponseSecuritygroupRule struct { + Account string `json:"account"` + Cidr string `json:"cidr"` + Endport int `json:"endport"` + Icmpcode int `json:"icmpcode"` + Icmptype int `json:"icmptype"` + Protocol string `json:"protocol"` + Ruleid string `json:"ruleid"` + Securitygroupname string `json:"securitygroupname"` + Startport int `json:"startport"` + Tags []Tags `json:"tags"` +} + +type AssignVirtualMachineResponseAffinitygroup struct { + Account string `json:"account"` + Description string `json:"description"` + Domain string `json:"domain"` + Domainid string `json:"domainid"` + Id string `json:"id"` + Name string `json:"name"` + Project string `json:"project"` + Projectid string `json:"projectid"` + Type string `json:"type"` + VirtualmachineIds []string `json:"virtualmachineIds"` +} + +type ChangeServiceForVirtualMachineParams struct { + p map[string]interface{} +} + +func (p *ChangeServiceForVirtualMachineParams) toURLValues() url.Values { + u := url.Values{} + if p.p == nil { + return u + } + if v, found := p.p["details"]; found { + i := 0 + for k, vv := range v.(map[string]string) { + u.Set(fmt.Sprintf("details[%d].%s", i, k), vv) + i++ + } + } + if v, found := p.p["id"]; found { + u.Set("id", v.(string)) + } + if v, found := p.p["serviceofferingid"]; found { + u.Set("serviceofferingid", v.(string)) + } + return u +} + +func (p *ChangeServiceForVirtualMachineParams) SetDetails(v map[string]string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["details"] = v + return +} + +func (p *ChangeServiceForVirtualMachineParams) SetId(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["id"] = v + return +} + +func (p *ChangeServiceForVirtualMachineParams) SetServiceofferingid(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["serviceofferingid"] = v + return +} + +// You should always use this function to get a new ChangeServiceForVirtualMachineParams instance, +// as then you are sure you have configured all required params +func (s *VirtualMachineService) NewChangeServiceForVirtualMachineParams(id string, serviceofferingid string) *ChangeServiceForVirtualMachineParams { + p := &ChangeServiceForVirtualMachineParams{} + p.p = make(map[string]interface{}) + p.p["id"] = id + p.p["serviceofferingid"] = serviceofferingid + return p +} + +// Changes the service offering for a virtual machine. The virtual machine must be in a "Stopped" state for this command to take effect. +func (s *VirtualMachineService) ChangeServiceForVirtualMachine(p *ChangeServiceForVirtualMachineParams) (*ChangeServiceForVirtualMachineResponse, error) { + resp, err := s.cs.newRequest("changeServiceForVirtualMachine", p.toURLValues()) + if err != nil { + return nil, err + } + + var r ChangeServiceForVirtualMachineResponse + if err := json.Unmarshal(resp, &r); err != nil { + return nil, err + } + + return &r, nil +} + +type ChangeServiceForVirtualMachineResponse struct { + Account string `json:"account"` + Affinitygroup []ChangeServiceForVirtualMachineResponseAffinitygroup `json:"affinitygroup"` + Cpunumber int `json:"cpunumber"` + Cpuspeed int `json:"cpuspeed"` + Cpuused string `json:"cpuused"` + Created string `json:"created"` + Details map[string]string `json:"details"` + Diskioread int64 `json:"diskioread"` + Diskiowrite int64 `json:"diskiowrite"` + Diskkbsread int64 `json:"diskkbsread"` + Diskkbswrite int64 `json:"diskkbswrite"` + Diskofferingid string `json:"diskofferingid"` + Diskofferingname string `json:"diskofferingname"` + Displayname string `json:"displayname"` + Displayvm bool `json:"displayvm"` + Domain string `json:"domain"` + Domainid string `json:"domainid"` + Forvirtualnetwork bool `json:"forvirtualnetwork"` + Group string `json:"group"` + Groupid string `json:"groupid"` + Guestosid string `json:"guestosid"` + Haenable bool `json:"haenable"` + Hostid string `json:"hostid"` + Hostname string `json:"hostname"` + Hypervisor string `json:"hypervisor"` + Id string `json:"id"` + Instancename string `json:"instancename"` + Isdynamicallyscalable bool `json:"isdynamicallyscalable"` + Isodisplaytext string `json:"isodisplaytext"` + Isoid string `json:"isoid"` + Isoname string `json:"isoname"` + Keypair string `json:"keypair"` + Memory int `json:"memory"` + Memoryintfreekbs int64 `json:"memoryintfreekbs"` + Memorykbs int64 `json:"memorykbs"` + Memorytargetkbs int64 `json:"memorytargetkbs"` + Name string `json:"name"` + Networkkbsread int64 `json:"networkkbsread"` + Networkkbswrite int64 `json:"networkkbswrite"` + Nic []Nic `json:"nic"` + Ostypeid int64 `json:"ostypeid"` + Password string `json:"password"` + Passwordenabled bool `json:"passwordenabled"` + Project string `json:"project"` + Projectid string `json:"projectid"` + Publicip string `json:"publicip"` + Publicipid string `json:"publicipid"` + Rootdeviceid int64 `json:"rootdeviceid"` + Rootdevicetype string `json:"rootdevicetype"` + Securitygroup []ChangeServiceForVirtualMachineResponseSecuritygroup `json:"securitygroup"` + Serviceofferingid string `json:"serviceofferingid"` + Serviceofferingname string `json:"serviceofferingname"` + Servicestate string `json:"servicestate"` + State string `json:"state"` + Templatedisplaytext string `json:"templatedisplaytext"` + Templateid string `json:"templateid"` + Templatename string `json:"templatename"` + Userid string `json:"userid"` + Username string `json:"username"` + Vgpu string `json:"vgpu"` + Zoneid string `json:"zoneid"` + Zonename string `json:"zonename"` +} + +type ChangeServiceForVirtualMachineResponseSecuritygroup struct { + Account string `json:"account"` + Description string `json:"description"` + Domain string `json:"domain"` + Domainid string `json:"domainid"` + Egressrule []ChangeServiceForVirtualMachineResponseSecuritygroupRule `json:"egressrule"` + Id string `json:"id"` + Ingressrule []ChangeServiceForVirtualMachineResponseSecuritygroupRule `json:"ingressrule"` + Name string `json:"name"` + Project string `json:"project"` + Projectid string `json:"projectid"` + Tags []Tags `json:"tags"` + Virtualmachinecount int `json:"virtualmachinecount"` + Virtualmachineids []interface{} `json:"virtualmachineids"` +} + +type ChangeServiceForVirtualMachineResponseSecuritygroupRule struct { + Account string `json:"account"` + Cidr string `json:"cidr"` + Endport int `json:"endport"` + Icmpcode int `json:"icmpcode"` + Icmptype int `json:"icmptype"` + Protocol string `json:"protocol"` + Ruleid string `json:"ruleid"` + Securitygroupname string `json:"securitygroupname"` + Startport int `json:"startport"` + Tags []Tags `json:"tags"` +} + +type ChangeServiceForVirtualMachineResponseAffinitygroup struct { + Account string `json:"account"` + Description string `json:"description"` + Domain string `json:"domain"` + Domainid string `json:"domainid"` + Id string `json:"id"` + Name string `json:"name"` + Project string `json:"project"` + Projectid string `json:"projectid"` + Type string `json:"type"` + VirtualmachineIds []string `json:"virtualmachineIds"` +} + +type CleanVMReservationsParams struct { + p map[string]interface{} +} + +func (p *CleanVMReservationsParams) toURLValues() url.Values { + u := url.Values{} + if p.p == nil { + return u + } + return u +} + +// You should always use this function to get a new CleanVMReservationsParams instance, +// as then you are sure you have configured all required params +func (s *VirtualMachineService) NewCleanVMReservationsParams() *CleanVMReservationsParams { + p := &CleanVMReservationsParams{} + p.p = make(map[string]interface{}) + return p +} + +// Cleanups VM reservations in the database. +func (s *VirtualMachineService) CleanVMReservations(p *CleanVMReservationsParams) (*CleanVMReservationsResponse, error) { + resp, err := s.cs.newRequest("cleanVMReservations", p.toURLValues()) + if err != nil { + return nil, err + } + + var r CleanVMReservationsResponse + if err := json.Unmarshal(resp, &r); err != nil { + return nil, err + } + + // If we have a async client, we need to wait for the async result + if s.cs.async { + b, err := s.cs.GetAsyncJobResult(r.JobID, s.cs.timeout) + if err != nil { + if err == AsyncTimeoutErr { + return &r, err + } + return nil, err + } + + if err := json.Unmarshal(b, &r); err != nil { + return nil, err + } + } + + return &r, nil +} + +type CleanVMReservationsResponse struct { + JobID string `json:"jobid"` + Displaytext string `json:"displaytext"` + Success bool `json:"success"` +} + type DeployVirtualMachineParams struct { p map[string]interface{} } @@ -47,14 +720,29 @@ func (p *DeployVirtualMachineParams) toURLValues() url.Values { if v, found := p.p["customid"]; found { u.Set("customid", v.(string)) } + if v, found := p.p["datadiskofferinglist"]; found { + i := 0 + for k, vv := range v.(map[string]string) { + u.Set(fmt.Sprintf("datadiskofferinglist[%d].key", i), k) + u.Set(fmt.Sprintf("datadiskofferinglist[%d].value", i), vv) + i++ + } + } if v, found := p.p["deploymentplanner"]; found { u.Set("deploymentplanner", v.(string)) } if v, found := p.p["details"]; found { i := 0 for k, vv := range v.(map[string]string) { - u.Set(fmt.Sprintf("details[%d].key", i), k) - u.Set(fmt.Sprintf("details[%d].value", i), vv) + u.Set(fmt.Sprintf("details[%d].%s", i, k), vv) + i++ + } + } + if v, found := p.p["dhcpoptionsnetworklist"]; found { + i := 0 + for k, vv := range v.(map[string]string) { + u.Set(fmt.Sprintf("dhcpoptionsnetworklist[%d].key", i), k) + u.Set(fmt.Sprintf("dhcpoptionsnetworklist[%d].value", i), vv) i++ } } @@ -100,6 +788,9 @@ func (p *DeployVirtualMachineParams) toURLValues() url.Values { if v, found := p.p["keypair"]; found { u.Set("keypair", v.(string)) } + if v, found := p.p["macaddress"]; found { + u.Set("macaddress", v.(string)) + } if v, found := p.p["name"]; found { u.Set("name", v.(string)) } @@ -177,6 +868,14 @@ func (p *DeployVirtualMachineParams) SetCustomid(v string) { return } +func (p *DeployVirtualMachineParams) SetDatadiskofferinglist(v map[string]string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["datadiskofferinglist"] = v + return +} + func (p *DeployVirtualMachineParams) SetDeploymentplanner(v string) { if p.p == nil { p.p = make(map[string]interface{}) @@ -193,6 +892,14 @@ func (p *DeployVirtualMachineParams) SetDetails(v map[string]string) { return } +func (p *DeployVirtualMachineParams) SetDhcpoptionsnetworklist(v map[string]string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["dhcpoptionsnetworklist"] = v + return +} + func (p *DeployVirtualMachineParams) SetDiskofferingid(v string) { if p.p == nil { p.p = make(map[string]interface{}) @@ -289,6 +996,14 @@ func (p *DeployVirtualMachineParams) SetKeypair(v string) { return } +func (p *DeployVirtualMachineParams) SetMacaddress(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["macaddress"] = v + return +} + func (p *DeployVirtualMachineParams) SetName(v string) { if p.p == nil { p.p = make(map[string]interface{}) @@ -427,184 +1142,116 @@ func (s *VirtualMachineService) DeployVirtualMachine(p *DeployVirtualMachinePara return nil, err } } + return &r, nil } type DeployVirtualMachineResponse struct { - JobID string `json:"jobid,omitempty"` - Account string `json:"account,omitempty"` - Affinitygroup []struct { - Account string `json:"account,omitempty"` - Description string `json:"description,omitempty"` - Domain string `json:"domain,omitempty"` - Domainid string `json:"domainid,omitempty"` - Id string `json:"id,omitempty"` - Name string `json:"name,omitempty"` - Project string `json:"project,omitempty"` - Projectid string `json:"projectid,omitempty"` - Type string `json:"type,omitempty"` - VirtualmachineIds []string `json:"virtualmachineIds,omitempty"` - } `json:"affinitygroup,omitempty"` - Cpunumber int `json:"cpunumber,omitempty"` - Cpuspeed int `json:"cpuspeed,omitempty"` - Cpuused string `json:"cpuused,omitempty"` - Created string `json:"created,omitempty"` - Details map[string]string `json:"details,omitempty"` - Diskioread int64 `json:"diskioread,omitempty"` - Diskiowrite int64 `json:"diskiowrite,omitempty"` - Diskkbsread int64 `json:"diskkbsread,omitempty"` - Diskkbswrite int64 `json:"diskkbswrite,omitempty"` - Diskofferingid string `json:"diskofferingid,omitempty"` - Diskofferingname string `json:"diskofferingname,omitempty"` - Displayname string `json:"displayname,omitempty"` - Displayvm bool `json:"displayvm,omitempty"` - Domain string `json:"domain,omitempty"` - Domainid string `json:"domainid,omitempty"` - Forvirtualnetwork bool `json:"forvirtualnetwork,omitempty"` - Group string `json:"group,omitempty"` - Groupid string `json:"groupid,omitempty"` - Guestosid string `json:"guestosid,omitempty"` - Haenable bool `json:"haenable,omitempty"` - Hostid string `json:"hostid,omitempty"` - Hostname string `json:"hostname,omitempty"` - Hypervisor string `json:"hypervisor,omitempty"` - Id string `json:"id,omitempty"` - Instancename string `json:"instancename,omitempty"` - Isdynamicallyscalable bool `json:"isdynamicallyscalable,omitempty"` - Isodisplaytext string `json:"isodisplaytext,omitempty"` - Isoid string `json:"isoid,omitempty"` - Isoname string `json:"isoname,omitempty"` - Keypair string `json:"keypair,omitempty"` - Memory int `json:"memory,omitempty"` - Name string `json:"name,omitempty"` - Networkkbsread int64 `json:"networkkbsread,omitempty"` - Networkkbswrite int64 `json:"networkkbswrite,omitempty"` - Nic []struct { - Broadcasturi string `json:"broadcasturi,omitempty"` - Deviceid string `json:"deviceid,omitempty"` - Gateway string `json:"gateway,omitempty"` - Id string `json:"id,omitempty"` - Ip6address string `json:"ip6address,omitempty"` - Ip6cidr string `json:"ip6cidr,omitempty"` - Ip6gateway string `json:"ip6gateway,omitempty"` - Ipaddress string `json:"ipaddress,omitempty"` - Isdefault bool `json:"isdefault,omitempty"` - Isolationuri string `json:"isolationuri,omitempty"` - Macaddress string `json:"macaddress,omitempty"` - Netmask string `json:"netmask,omitempty"` - Networkid string `json:"networkid,omitempty"` - Networkname string `json:"networkname,omitempty"` - Secondaryip []struct { - Id string `json:"id,omitempty"` - Ipaddress string `json:"ipaddress,omitempty"` - } `json:"secondaryip,omitempty"` - Traffictype string `json:"traffictype,omitempty"` - Type string `json:"type,omitempty"` - Virtualmachineid string `json:"virtualmachineid,omitempty"` - } `json:"nic,omitempty"` - Ostypeid int64 `json:"ostypeid,omitempty"` - Password string `json:"password,omitempty"` - Passwordenabled bool `json:"passwordenabled,omitempty"` - Project string `json:"project,omitempty"` - Projectid string `json:"projectid,omitempty"` - Publicip string `json:"publicip,omitempty"` - Publicipid string `json:"publicipid,omitempty"` - Rootdeviceid int64 `json:"rootdeviceid,omitempty"` - Rootdevicetype string `json:"rootdevicetype,omitempty"` - Securitygroup []struct { - Account string `json:"account,omitempty"` - Description string `json:"description,omitempty"` - Domain string `json:"domain,omitempty"` - Domainid string `json:"domainid,omitempty"` - Egressrule []struct { - Account string `json:"account,omitempty"` - Cidr string `json:"cidr,omitempty"` - Endport int `json:"endport,omitempty"` - Icmpcode int `json:"icmpcode,omitempty"` - Icmptype int `json:"icmptype,omitempty"` - Protocol string `json:"protocol,omitempty"` - Ruleid string `json:"ruleid,omitempty"` - Securitygroupname string `json:"securitygroupname,omitempty"` - Startport int `json:"startport,omitempty"` - Tags []struct { - Account string `json:"account,omitempty"` - Customer string `json:"customer,omitempty"` - Domain string `json:"domain,omitempty"` - Domainid string `json:"domainid,omitempty"` - Key string `json:"key,omitempty"` - Project string `json:"project,omitempty"` - Projectid string `json:"projectid,omitempty"` - Resourceid string `json:"resourceid,omitempty"` - Resourcetype string `json:"resourcetype,omitempty"` - Value string `json:"value,omitempty"` - } `json:"tags,omitempty"` - } `json:"egressrule,omitempty"` - Id string `json:"id,omitempty"` - Ingressrule []struct { - Account string `json:"account,omitempty"` - Cidr string `json:"cidr,omitempty"` - Endport int `json:"endport,omitempty"` - Icmpcode int `json:"icmpcode,omitempty"` - Icmptype int `json:"icmptype,omitempty"` - Protocol string `json:"protocol,omitempty"` - Ruleid string `json:"ruleid,omitempty"` - Securitygroupname string `json:"securitygroupname,omitempty"` - Startport int `json:"startport,omitempty"` - Tags []struct { - Account string `json:"account,omitempty"` - Customer string `json:"customer,omitempty"` - Domain string `json:"domain,omitempty"` - Domainid string `json:"domainid,omitempty"` - Key string `json:"key,omitempty"` - Project string `json:"project,omitempty"` - Projectid string `json:"projectid,omitempty"` - Resourceid string `json:"resourceid,omitempty"` - Resourcetype string `json:"resourcetype,omitempty"` - Value string `json:"value,omitempty"` - } `json:"tags,omitempty"` - } `json:"ingressrule,omitempty"` - Name string `json:"name,omitempty"` - Project string `json:"project,omitempty"` - Projectid string `json:"projectid,omitempty"` - Tags []struct { - Account string `json:"account,omitempty"` - Customer string `json:"customer,omitempty"` - Domain string `json:"domain,omitempty"` - Domainid string `json:"domainid,omitempty"` - Key string `json:"key,omitempty"` - Project string `json:"project,omitempty"` - Projectid string `json:"projectid,omitempty"` - Resourceid string `json:"resourceid,omitempty"` - Resourcetype string `json:"resourcetype,omitempty"` - Value string `json:"value,omitempty"` - } `json:"tags,omitempty"` - Virtualmachinecount int `json:"virtualmachinecount,omitempty"` - Virtualmachineids []string `json:"virtualmachineids,omitempty"` - } `json:"securitygroup,omitempty"` - Serviceofferingid string `json:"serviceofferingid,omitempty"` - Serviceofferingname string `json:"serviceofferingname,omitempty"` - Servicestate string `json:"servicestate,omitempty"` - State string `json:"state,omitempty"` - Tags []struct { - Account string `json:"account,omitempty"` - Customer string `json:"customer,omitempty"` - Domain string `json:"domain,omitempty"` - Domainid string `json:"domainid,omitempty"` - Key string `json:"key,omitempty"` - Project string `json:"project,omitempty"` - Projectid string `json:"projectid,omitempty"` - Resourceid string `json:"resourceid,omitempty"` - Resourcetype string `json:"resourcetype,omitempty"` - Value string `json:"value,omitempty"` - } `json:"tags,omitempty"` - Templatedisplaytext string `json:"templatedisplaytext,omitempty"` - Templateid string `json:"templateid,omitempty"` - Templatename string `json:"templatename,omitempty"` - Userid string `json:"userid,omitempty"` - Username string `json:"username,omitempty"` - Vgpu string `json:"vgpu,omitempty"` - Zoneid string `json:"zoneid,omitempty"` - Zonename string `json:"zonename,omitempty"` + JobID string `json:"jobid"` + Account string `json:"account"` + Affinitygroup []DeployVirtualMachineResponseAffinitygroup `json:"affinitygroup"` + Cpunumber int `json:"cpunumber"` + Cpuspeed int `json:"cpuspeed"` + Cpuused string `json:"cpuused"` + Created string `json:"created"` + Details map[string]string `json:"details"` + Diskioread int64 `json:"diskioread"` + Diskiowrite int64 `json:"diskiowrite"` + Diskkbsread int64 `json:"diskkbsread"` + Diskkbswrite int64 `json:"diskkbswrite"` + Diskofferingid string `json:"diskofferingid"` + Diskofferingname string `json:"diskofferingname"` + Displayname string `json:"displayname"` + Displayvm bool `json:"displayvm"` + Domain string `json:"domain"` + Domainid string `json:"domainid"` + Forvirtualnetwork bool `json:"forvirtualnetwork"` + Group string `json:"group"` + Groupid string `json:"groupid"` + Guestosid string `json:"guestosid"` + Haenable bool `json:"haenable"` + Hostid string `json:"hostid"` + Hostname string `json:"hostname"` + Hypervisor string `json:"hypervisor"` + Id string `json:"id"` + Instancename string `json:"instancename"` + Isdynamicallyscalable bool `json:"isdynamicallyscalable"` + Isodisplaytext string `json:"isodisplaytext"` + Isoid string `json:"isoid"` + Isoname string `json:"isoname"` + Keypair string `json:"keypair"` + Memory int `json:"memory"` + Memoryintfreekbs int64 `json:"memoryintfreekbs"` + Memorykbs int64 `json:"memorykbs"` + Memorytargetkbs int64 `json:"memorytargetkbs"` + Name string `json:"name"` + Networkkbsread int64 `json:"networkkbsread"` + Networkkbswrite int64 `json:"networkkbswrite"` + Nic []Nic `json:"nic"` + Ostypeid int64 `json:"ostypeid"` + Password string `json:"password"` + Passwordenabled bool `json:"passwordenabled"` + Project string `json:"project"` + Projectid string `json:"projectid"` + Publicip string `json:"publicip"` + Publicipid string `json:"publicipid"` + Rootdeviceid int64 `json:"rootdeviceid"` + Rootdevicetype string `json:"rootdevicetype"` + Securitygroup []DeployVirtualMachineResponseSecuritygroup `json:"securitygroup"` + Serviceofferingid string `json:"serviceofferingid"` + Serviceofferingname string `json:"serviceofferingname"` + Servicestate string `json:"servicestate"` + State string `json:"state"` + Templatedisplaytext string `json:"templatedisplaytext"` + Templateid string `json:"templateid"` + Templatename string `json:"templatename"` + Userid string `json:"userid"` + Username string `json:"username"` + Vgpu string `json:"vgpu"` + Zoneid string `json:"zoneid"` + Zonename string `json:"zonename"` +} + +type DeployVirtualMachineResponseSecuritygroup struct { + Account string `json:"account"` + Description string `json:"description"` + Domain string `json:"domain"` + Domainid string `json:"domainid"` + Egressrule []DeployVirtualMachineResponseSecuritygroupRule `json:"egressrule"` + Id string `json:"id"` + Ingressrule []DeployVirtualMachineResponseSecuritygroupRule `json:"ingressrule"` + Name string `json:"name"` + Project string `json:"project"` + Projectid string `json:"projectid"` + Tags []Tags `json:"tags"` + Virtualmachinecount int `json:"virtualmachinecount"` + Virtualmachineids []interface{} `json:"virtualmachineids"` +} + +type DeployVirtualMachineResponseSecuritygroupRule struct { + Account string `json:"account"` + Cidr string `json:"cidr"` + Endport int `json:"endport"` + Icmpcode int `json:"icmpcode"` + Icmptype int `json:"icmptype"` + Protocol string `json:"protocol"` + Ruleid string `json:"ruleid"` + Securitygroupname string `json:"securitygroupname"` + Startport int `json:"startport"` + Tags []Tags `json:"tags"` +} + +type DeployVirtualMachineResponseAffinitygroup struct { + Account string `json:"account"` + Description string `json:"description"` + Domain string `json:"domain"` + Domainid string `json:"domainid"` + Id string `json:"id"` + Name string `json:"name"` + Project string `json:"project"` + Projectid string `json:"projectid"` + Type string `json:"type"` + VirtualmachineIds []string `json:"virtualmachineIds"` } type DestroyVirtualMachineParams struct { @@ -682,191 +1329,123 @@ func (s *VirtualMachineService) DestroyVirtualMachine(p *DestroyVirtualMachinePa return nil, err } } + return &r, nil } type DestroyVirtualMachineResponse struct { - JobID string `json:"jobid,omitempty"` - Account string `json:"account,omitempty"` - Affinitygroup []struct { - Account string `json:"account,omitempty"` - Description string `json:"description,omitempty"` - Domain string `json:"domain,omitempty"` - Domainid string `json:"domainid,omitempty"` - Id string `json:"id,omitempty"` - Name string `json:"name,omitempty"` - Project string `json:"project,omitempty"` - Projectid string `json:"projectid,omitempty"` - Type string `json:"type,omitempty"` - VirtualmachineIds []string `json:"virtualmachineIds,omitempty"` - } `json:"affinitygroup,omitempty"` - Cpunumber int `json:"cpunumber,omitempty"` - Cpuspeed int `json:"cpuspeed,omitempty"` - Cpuused string `json:"cpuused,omitempty"` - Created string `json:"created,omitempty"` - Details map[string]string `json:"details,omitempty"` - Diskioread int64 `json:"diskioread,omitempty"` - Diskiowrite int64 `json:"diskiowrite,omitempty"` - Diskkbsread int64 `json:"diskkbsread,omitempty"` - Diskkbswrite int64 `json:"diskkbswrite,omitempty"` - Diskofferingid string `json:"diskofferingid,omitempty"` - Diskofferingname string `json:"diskofferingname,omitempty"` - Displayname string `json:"displayname,omitempty"` - Displayvm bool `json:"displayvm,omitempty"` - Domain string `json:"domain,omitempty"` - Domainid string `json:"domainid,omitempty"` - Forvirtualnetwork bool `json:"forvirtualnetwork,omitempty"` - Group string `json:"group,omitempty"` - Groupid string `json:"groupid,omitempty"` - Guestosid string `json:"guestosid,omitempty"` - Haenable bool `json:"haenable,omitempty"` - Hostid string `json:"hostid,omitempty"` - Hostname string `json:"hostname,omitempty"` - Hypervisor string `json:"hypervisor,omitempty"` - Id string `json:"id,omitempty"` - Instancename string `json:"instancename,omitempty"` - Isdynamicallyscalable bool `json:"isdynamicallyscalable,omitempty"` - Isodisplaytext string `json:"isodisplaytext,omitempty"` - Isoid string `json:"isoid,omitempty"` - Isoname string `json:"isoname,omitempty"` - Keypair string `json:"keypair,omitempty"` - Memory int `json:"memory,omitempty"` - Name string `json:"name,omitempty"` - Networkkbsread int64 `json:"networkkbsread,omitempty"` - Networkkbswrite int64 `json:"networkkbswrite,omitempty"` - Nic []struct { - Broadcasturi string `json:"broadcasturi,omitempty"` - Deviceid string `json:"deviceid,omitempty"` - Gateway string `json:"gateway,omitempty"` - Id string `json:"id,omitempty"` - Ip6address string `json:"ip6address,omitempty"` - Ip6cidr string `json:"ip6cidr,omitempty"` - Ip6gateway string `json:"ip6gateway,omitempty"` - Ipaddress string `json:"ipaddress,omitempty"` - Isdefault bool `json:"isdefault,omitempty"` - Isolationuri string `json:"isolationuri,omitempty"` - Macaddress string `json:"macaddress,omitempty"` - Netmask string `json:"netmask,omitempty"` - Networkid string `json:"networkid,omitempty"` - Networkname string `json:"networkname,omitempty"` - Secondaryip []struct { - Id string `json:"id,omitempty"` - Ipaddress string `json:"ipaddress,omitempty"` - } `json:"secondaryip,omitempty"` - Traffictype string `json:"traffictype,omitempty"` - Type string `json:"type,omitempty"` - Virtualmachineid string `json:"virtualmachineid,omitempty"` - } `json:"nic,omitempty"` - Ostypeid int64 `json:"ostypeid,omitempty"` - Password string `json:"password,omitempty"` - Passwordenabled bool `json:"passwordenabled,omitempty"` - Project string `json:"project,omitempty"` - Projectid string `json:"projectid,omitempty"` - Publicip string `json:"publicip,omitempty"` - Publicipid string `json:"publicipid,omitempty"` - Rootdeviceid int64 `json:"rootdeviceid,omitempty"` - Rootdevicetype string `json:"rootdevicetype,omitempty"` - Securitygroup []struct { - Account string `json:"account,omitempty"` - Description string `json:"description,omitempty"` - Domain string `json:"domain,omitempty"` - Domainid string `json:"domainid,omitempty"` - Egressrule []struct { - Account string `json:"account,omitempty"` - Cidr string `json:"cidr,omitempty"` - Endport int `json:"endport,omitempty"` - Icmpcode int `json:"icmpcode,omitempty"` - Icmptype int `json:"icmptype,omitempty"` - Protocol string `json:"protocol,omitempty"` - Ruleid string `json:"ruleid,omitempty"` - Securitygroupname string `json:"securitygroupname,omitempty"` - Startport int `json:"startport,omitempty"` - Tags []struct { - Account string `json:"account,omitempty"` - Customer string `json:"customer,omitempty"` - Domain string `json:"domain,omitempty"` - Domainid string `json:"domainid,omitempty"` - Key string `json:"key,omitempty"` - Project string `json:"project,omitempty"` - Projectid string `json:"projectid,omitempty"` - Resourceid string `json:"resourceid,omitempty"` - Resourcetype string `json:"resourcetype,omitempty"` - Value string `json:"value,omitempty"` - } `json:"tags,omitempty"` - } `json:"egressrule,omitempty"` - Id string `json:"id,omitempty"` - Ingressrule []struct { - Account string `json:"account,omitempty"` - Cidr string `json:"cidr,omitempty"` - Endport int `json:"endport,omitempty"` - Icmpcode int `json:"icmpcode,omitempty"` - Icmptype int `json:"icmptype,omitempty"` - Protocol string `json:"protocol,omitempty"` - Ruleid string `json:"ruleid,omitempty"` - Securitygroupname string `json:"securitygroupname,omitempty"` - Startport int `json:"startport,omitempty"` - Tags []struct { - Account string `json:"account,omitempty"` - Customer string `json:"customer,omitempty"` - Domain string `json:"domain,omitempty"` - Domainid string `json:"domainid,omitempty"` - Key string `json:"key,omitempty"` - Project string `json:"project,omitempty"` - Projectid string `json:"projectid,omitempty"` - Resourceid string `json:"resourceid,omitempty"` - Resourcetype string `json:"resourcetype,omitempty"` - Value string `json:"value,omitempty"` - } `json:"tags,omitempty"` - } `json:"ingressrule,omitempty"` - Name string `json:"name,omitempty"` - Project string `json:"project,omitempty"` - Projectid string `json:"projectid,omitempty"` - Tags []struct { - Account string `json:"account,omitempty"` - Customer string `json:"customer,omitempty"` - Domain string `json:"domain,omitempty"` - Domainid string `json:"domainid,omitempty"` - Key string `json:"key,omitempty"` - Project string `json:"project,omitempty"` - Projectid string `json:"projectid,omitempty"` - Resourceid string `json:"resourceid,omitempty"` - Resourcetype string `json:"resourcetype,omitempty"` - Value string `json:"value,omitempty"` - } `json:"tags,omitempty"` - Virtualmachinecount int `json:"virtualmachinecount,omitempty"` - Virtualmachineids []string `json:"virtualmachineids,omitempty"` - } `json:"securitygroup,omitempty"` - Serviceofferingid string `json:"serviceofferingid,omitempty"` - Serviceofferingname string `json:"serviceofferingname,omitempty"` - Servicestate string `json:"servicestate,omitempty"` - State string `json:"state,omitempty"` - Tags []struct { - Account string `json:"account,omitempty"` - Customer string `json:"customer,omitempty"` - Domain string `json:"domain,omitempty"` - Domainid string `json:"domainid,omitempty"` - Key string `json:"key,omitempty"` - Project string `json:"project,omitempty"` - Projectid string `json:"projectid,omitempty"` - Resourceid string `json:"resourceid,omitempty"` - Resourcetype string `json:"resourcetype,omitempty"` - Value string `json:"value,omitempty"` - } `json:"tags,omitempty"` - Templatedisplaytext string `json:"templatedisplaytext,omitempty"` - Templateid string `json:"templateid,omitempty"` - Templatename string `json:"templatename,omitempty"` - Userid string `json:"userid,omitempty"` - Username string `json:"username,omitempty"` - Vgpu string `json:"vgpu,omitempty"` - Zoneid string `json:"zoneid,omitempty"` - Zonename string `json:"zonename,omitempty"` + JobID string `json:"jobid"` + Account string `json:"account"` + Affinitygroup []DestroyVirtualMachineResponseAffinitygroup `json:"affinitygroup"` + Cpunumber int `json:"cpunumber"` + Cpuspeed int `json:"cpuspeed"` + Cpuused string `json:"cpuused"` + Created string `json:"created"` + Details map[string]string `json:"details"` + Diskioread int64 `json:"diskioread"` + Diskiowrite int64 `json:"diskiowrite"` + Diskkbsread int64 `json:"diskkbsread"` + Diskkbswrite int64 `json:"diskkbswrite"` + Diskofferingid string `json:"diskofferingid"` + Diskofferingname string `json:"diskofferingname"` + Displayname string `json:"displayname"` + Displayvm bool `json:"displayvm"` + Domain string `json:"domain"` + Domainid string `json:"domainid"` + Forvirtualnetwork bool `json:"forvirtualnetwork"` + Group string `json:"group"` + Groupid string `json:"groupid"` + Guestosid string `json:"guestosid"` + Haenable bool `json:"haenable"` + Hostid string `json:"hostid"` + Hostname string `json:"hostname"` + Hypervisor string `json:"hypervisor"` + Id string `json:"id"` + Instancename string `json:"instancename"` + Isdynamicallyscalable bool `json:"isdynamicallyscalable"` + Isodisplaytext string `json:"isodisplaytext"` + Isoid string `json:"isoid"` + Isoname string `json:"isoname"` + Keypair string `json:"keypair"` + Memory int `json:"memory"` + Memoryintfreekbs int64 `json:"memoryintfreekbs"` + Memorykbs int64 `json:"memorykbs"` + Memorytargetkbs int64 `json:"memorytargetkbs"` + Name string `json:"name"` + Networkkbsread int64 `json:"networkkbsread"` + Networkkbswrite int64 `json:"networkkbswrite"` + Nic []Nic `json:"nic"` + Ostypeid int64 `json:"ostypeid"` + Password string `json:"password"` + Passwordenabled bool `json:"passwordenabled"` + Project string `json:"project"` + Projectid string `json:"projectid"` + Publicip string `json:"publicip"` + Publicipid string `json:"publicipid"` + Rootdeviceid int64 `json:"rootdeviceid"` + Rootdevicetype string `json:"rootdevicetype"` + Securitygroup []DestroyVirtualMachineResponseSecuritygroup `json:"securitygroup"` + Serviceofferingid string `json:"serviceofferingid"` + Serviceofferingname string `json:"serviceofferingname"` + Servicestate string `json:"servicestate"` + State string `json:"state"` + Templatedisplaytext string `json:"templatedisplaytext"` + Templateid string `json:"templateid"` + Templatename string `json:"templatename"` + Userid string `json:"userid"` + Username string `json:"username"` + Vgpu string `json:"vgpu"` + Zoneid string `json:"zoneid"` + Zonename string `json:"zonename"` } -type RebootVirtualMachineParams struct { +type DestroyVirtualMachineResponseSecuritygroup struct { + Account string `json:"account"` + Description string `json:"description"` + Domain string `json:"domain"` + Domainid string `json:"domainid"` + Egressrule []DestroyVirtualMachineResponseSecuritygroupRule `json:"egressrule"` + Id string `json:"id"` + Ingressrule []DestroyVirtualMachineResponseSecuritygroupRule `json:"ingressrule"` + Name string `json:"name"` + Project string `json:"project"` + Projectid string `json:"projectid"` + Tags []Tags `json:"tags"` + Virtualmachinecount int `json:"virtualmachinecount"` + Virtualmachineids []interface{} `json:"virtualmachineids"` +} + +type DestroyVirtualMachineResponseSecuritygroupRule struct { + Account string `json:"account"` + Cidr string `json:"cidr"` + Endport int `json:"endport"` + Icmpcode int `json:"icmpcode"` + Icmptype int `json:"icmptype"` + Protocol string `json:"protocol"` + Ruleid string `json:"ruleid"` + Securitygroupname string `json:"securitygroupname"` + Startport int `json:"startport"` + Tags []Tags `json:"tags"` +} + +type DestroyVirtualMachineResponseAffinitygroup struct { + Account string `json:"account"` + Description string `json:"description"` + Domain string `json:"domain"` + Domainid string `json:"domainid"` + Id string `json:"id"` + Name string `json:"name"` + Project string `json:"project"` + Projectid string `json:"projectid"` + Type string `json:"type"` + VirtualmachineIds []string `json:"virtualmachineIds"` +} + +type ExpungeVirtualMachineParams struct { p map[string]interface{} } -func (p *RebootVirtualMachineParams) toURLValues() url.Values { +func (p *ExpungeVirtualMachineParams) toURLValues() url.Values { u := url.Values{} if p.p == nil { return u @@ -877,7 +1456,7 @@ func (p *RebootVirtualMachineParams) toURLValues() url.Values { return u } -func (p *RebootVirtualMachineParams) SetId(v string) { +func (p *ExpungeVirtualMachineParams) SetId(v string) { if p.p == nil { p.p = make(map[string]interface{}) } @@ -885,23 +1464,23 @@ func (p *RebootVirtualMachineParams) SetId(v string) { return } -// You should always use this function to get a new RebootVirtualMachineParams instance, +// You should always use this function to get a new ExpungeVirtualMachineParams instance, // as then you are sure you have configured all required params -func (s *VirtualMachineService) NewRebootVirtualMachineParams(id string) *RebootVirtualMachineParams { - p := &RebootVirtualMachineParams{} +func (s *VirtualMachineService) NewExpungeVirtualMachineParams(id string) *ExpungeVirtualMachineParams { + p := &ExpungeVirtualMachineParams{} p.p = make(map[string]interface{}) p.p["id"] = id return p } -// Reboots a virtual machine. -func (s *VirtualMachineService) RebootVirtualMachine(p *RebootVirtualMachineParams) (*RebootVirtualMachineResponse, error) { - resp, err := s.cs.newRequest("rebootVirtualMachine", p.toURLValues()) +// Expunge a virtual machine. Once expunged, it cannot be recoverd. +func (s *VirtualMachineService) ExpungeVirtualMachine(p *ExpungeVirtualMachineParams) (*ExpungeVirtualMachineResponse, error) { + resp, err := s.cs.newRequest("expungeVirtualMachine", p.toURLValues()) if err != nil { return nil, err } - var r RebootVirtualMachineResponse + var r ExpungeVirtualMachineResponse if err := json.Unmarshal(resp, &r); err != nil { return nil, err } @@ -916,720 +1495,25 @@ func (s *VirtualMachineService) RebootVirtualMachine(p *RebootVirtualMachinePara return nil, err } - b, err = getRawValue(b) - if err != nil { - return nil, err - } - if err := json.Unmarshal(b, &r); err != nil { return nil, err } } + return &r, nil } -type RebootVirtualMachineResponse struct { - JobID string `json:"jobid,omitempty"` - Account string `json:"account,omitempty"` - Affinitygroup []struct { - Account string `json:"account,omitempty"` - Description string `json:"description,omitempty"` - Domain string `json:"domain,omitempty"` - Domainid string `json:"domainid,omitempty"` - Id string `json:"id,omitempty"` - Name string `json:"name,omitempty"` - Project string `json:"project,omitempty"` - Projectid string `json:"projectid,omitempty"` - Type string `json:"type,omitempty"` - VirtualmachineIds []string `json:"virtualmachineIds,omitempty"` - } `json:"affinitygroup,omitempty"` - Cpunumber int `json:"cpunumber,omitempty"` - Cpuspeed int `json:"cpuspeed,omitempty"` - Cpuused string `json:"cpuused,omitempty"` - Created string `json:"created,omitempty"` - Details map[string]string `json:"details,omitempty"` - Diskioread int64 `json:"diskioread,omitempty"` - Diskiowrite int64 `json:"diskiowrite,omitempty"` - Diskkbsread int64 `json:"diskkbsread,omitempty"` - Diskkbswrite int64 `json:"diskkbswrite,omitempty"` - Diskofferingid string `json:"diskofferingid,omitempty"` - Diskofferingname string `json:"diskofferingname,omitempty"` - Displayname string `json:"displayname,omitempty"` - Displayvm bool `json:"displayvm,omitempty"` - Domain string `json:"domain,omitempty"` - Domainid string `json:"domainid,omitempty"` - Forvirtualnetwork bool `json:"forvirtualnetwork,omitempty"` - Group string `json:"group,omitempty"` - Groupid string `json:"groupid,omitempty"` - Guestosid string `json:"guestosid,omitempty"` - Haenable bool `json:"haenable,omitempty"` - Hostid string `json:"hostid,omitempty"` - Hostname string `json:"hostname,omitempty"` - Hypervisor string `json:"hypervisor,omitempty"` - Id string `json:"id,omitempty"` - Instancename string `json:"instancename,omitempty"` - Isdynamicallyscalable bool `json:"isdynamicallyscalable,omitempty"` - Isodisplaytext string `json:"isodisplaytext,omitempty"` - Isoid string `json:"isoid,omitempty"` - Isoname string `json:"isoname,omitempty"` - Keypair string `json:"keypair,omitempty"` - Memory int `json:"memory,omitempty"` - Name string `json:"name,omitempty"` - Networkkbsread int64 `json:"networkkbsread,omitempty"` - Networkkbswrite int64 `json:"networkkbswrite,omitempty"` - Nic []struct { - Broadcasturi string `json:"broadcasturi,omitempty"` - Deviceid string `json:"deviceid,omitempty"` - Gateway string `json:"gateway,omitempty"` - Id string `json:"id,omitempty"` - Ip6address string `json:"ip6address,omitempty"` - Ip6cidr string `json:"ip6cidr,omitempty"` - Ip6gateway string `json:"ip6gateway,omitempty"` - Ipaddress string `json:"ipaddress,omitempty"` - Isdefault bool `json:"isdefault,omitempty"` - Isolationuri string `json:"isolationuri,omitempty"` - Macaddress string `json:"macaddress,omitempty"` - Netmask string `json:"netmask,omitempty"` - Networkid string `json:"networkid,omitempty"` - Networkname string `json:"networkname,omitempty"` - Secondaryip []struct { - Id string `json:"id,omitempty"` - Ipaddress string `json:"ipaddress,omitempty"` - } `json:"secondaryip,omitempty"` - Traffictype string `json:"traffictype,omitempty"` - Type string `json:"type,omitempty"` - Virtualmachineid string `json:"virtualmachineid,omitempty"` - } `json:"nic,omitempty"` - Ostypeid int64 `json:"ostypeid,omitempty"` - Password string `json:"password,omitempty"` - Passwordenabled bool `json:"passwordenabled,omitempty"` - Project string `json:"project,omitempty"` - Projectid string `json:"projectid,omitempty"` - Publicip string `json:"publicip,omitempty"` - Publicipid string `json:"publicipid,omitempty"` - Rootdeviceid int64 `json:"rootdeviceid,omitempty"` - Rootdevicetype string `json:"rootdevicetype,omitempty"` - Securitygroup []struct { - Account string `json:"account,omitempty"` - Description string `json:"description,omitempty"` - Domain string `json:"domain,omitempty"` - Domainid string `json:"domainid,omitempty"` - Egressrule []struct { - Account string `json:"account,omitempty"` - Cidr string `json:"cidr,omitempty"` - Endport int `json:"endport,omitempty"` - Icmpcode int `json:"icmpcode,omitempty"` - Icmptype int `json:"icmptype,omitempty"` - Protocol string `json:"protocol,omitempty"` - Ruleid string `json:"ruleid,omitempty"` - Securitygroupname string `json:"securitygroupname,omitempty"` - Startport int `json:"startport,omitempty"` - Tags []struct { - Account string `json:"account,omitempty"` - Customer string `json:"customer,omitempty"` - Domain string `json:"domain,omitempty"` - Domainid string `json:"domainid,omitempty"` - Key string `json:"key,omitempty"` - Project string `json:"project,omitempty"` - Projectid string `json:"projectid,omitempty"` - Resourceid string `json:"resourceid,omitempty"` - Resourcetype string `json:"resourcetype,omitempty"` - Value string `json:"value,omitempty"` - } `json:"tags,omitempty"` - } `json:"egressrule,omitempty"` - Id string `json:"id,omitempty"` - Ingressrule []struct { - Account string `json:"account,omitempty"` - Cidr string `json:"cidr,omitempty"` - Endport int `json:"endport,omitempty"` - Icmpcode int `json:"icmpcode,omitempty"` - Icmptype int `json:"icmptype,omitempty"` - Protocol string `json:"protocol,omitempty"` - Ruleid string `json:"ruleid,omitempty"` - Securitygroupname string `json:"securitygroupname,omitempty"` - Startport int `json:"startport,omitempty"` - Tags []struct { - Account string `json:"account,omitempty"` - Customer string `json:"customer,omitempty"` - Domain string `json:"domain,omitempty"` - Domainid string `json:"domainid,omitempty"` - Key string `json:"key,omitempty"` - Project string `json:"project,omitempty"` - Projectid string `json:"projectid,omitempty"` - Resourceid string `json:"resourceid,omitempty"` - Resourcetype string `json:"resourcetype,omitempty"` - Value string `json:"value,omitempty"` - } `json:"tags,omitempty"` - } `json:"ingressrule,omitempty"` - Name string `json:"name,omitempty"` - Project string `json:"project,omitempty"` - Projectid string `json:"projectid,omitempty"` - Tags []struct { - Account string `json:"account,omitempty"` - Customer string `json:"customer,omitempty"` - Domain string `json:"domain,omitempty"` - Domainid string `json:"domainid,omitempty"` - Key string `json:"key,omitempty"` - Project string `json:"project,omitempty"` - Projectid string `json:"projectid,omitempty"` - Resourceid string `json:"resourceid,omitempty"` - Resourcetype string `json:"resourcetype,omitempty"` - Value string `json:"value,omitempty"` - } `json:"tags,omitempty"` - Virtualmachinecount int `json:"virtualmachinecount,omitempty"` - Virtualmachineids []string `json:"virtualmachineids,omitempty"` - } `json:"securitygroup,omitempty"` - Serviceofferingid string `json:"serviceofferingid,omitempty"` - Serviceofferingname string `json:"serviceofferingname,omitempty"` - Servicestate string `json:"servicestate,omitempty"` - State string `json:"state,omitempty"` - Tags []struct { - Account string `json:"account,omitempty"` - Customer string `json:"customer,omitempty"` - Domain string `json:"domain,omitempty"` - Domainid string `json:"domainid,omitempty"` - Key string `json:"key,omitempty"` - Project string `json:"project,omitempty"` - Projectid string `json:"projectid,omitempty"` - Resourceid string `json:"resourceid,omitempty"` - Resourcetype string `json:"resourcetype,omitempty"` - Value string `json:"value,omitempty"` - } `json:"tags,omitempty"` - Templatedisplaytext string `json:"templatedisplaytext,omitempty"` - Templateid string `json:"templateid,omitempty"` - Templatename string `json:"templatename,omitempty"` - Userid string `json:"userid,omitempty"` - Username string `json:"username,omitempty"` - Vgpu string `json:"vgpu,omitempty"` - Zoneid string `json:"zoneid,omitempty"` - Zonename string `json:"zonename,omitempty"` +type ExpungeVirtualMachineResponse struct { + JobID string `json:"jobid"` + Displaytext string `json:"displaytext"` + Success bool `json:"success"` } -type StartVirtualMachineParams struct { +type GetVMPasswordParams struct { p map[string]interface{} } -func (p *StartVirtualMachineParams) toURLValues() url.Values { - u := url.Values{} - if p.p == nil { - return u - } - if v, found := p.p["deploymentplanner"]; found { - u.Set("deploymentplanner", v.(string)) - } - if v, found := p.p["hostid"]; found { - u.Set("hostid", v.(string)) - } - if v, found := p.p["id"]; found { - u.Set("id", v.(string)) - } - return u -} - -func (p *StartVirtualMachineParams) SetDeploymentplanner(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["deploymentplanner"] = v - return -} - -func (p *StartVirtualMachineParams) SetHostid(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["hostid"] = v - return -} - -func (p *StartVirtualMachineParams) SetId(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["id"] = v - return -} - -// You should always use this function to get a new StartVirtualMachineParams instance, -// as then you are sure you have configured all required params -func (s *VirtualMachineService) NewStartVirtualMachineParams(id string) *StartVirtualMachineParams { - p := &StartVirtualMachineParams{} - p.p = make(map[string]interface{}) - p.p["id"] = id - return p -} - -// Starts a virtual machine. -func (s *VirtualMachineService) StartVirtualMachine(p *StartVirtualMachineParams) (*StartVirtualMachineResponse, error) { - resp, err := s.cs.newRequest("startVirtualMachine", p.toURLValues()) - if err != nil { - return nil, err - } - - var r StartVirtualMachineResponse - if err := json.Unmarshal(resp, &r); err != nil { - return nil, err - } - - // If we have a async client, we need to wait for the async result - if s.cs.async { - b, err := s.cs.GetAsyncJobResult(r.JobID, s.cs.timeout) - if err != nil { - if err == AsyncTimeoutErr { - return &r, err - } - return nil, err - } - - b, err = getRawValue(b) - if err != nil { - return nil, err - } - - if err := json.Unmarshal(b, &r); err != nil { - return nil, err - } - } - return &r, nil -} - -type StartVirtualMachineResponse struct { - JobID string `json:"jobid,omitempty"` - Account string `json:"account,omitempty"` - Affinitygroup []struct { - Account string `json:"account,omitempty"` - Description string `json:"description,omitempty"` - Domain string `json:"domain,omitempty"` - Domainid string `json:"domainid,omitempty"` - Id string `json:"id,omitempty"` - Name string `json:"name,omitempty"` - Project string `json:"project,omitempty"` - Projectid string `json:"projectid,omitempty"` - Type string `json:"type,omitempty"` - VirtualmachineIds []string `json:"virtualmachineIds,omitempty"` - } `json:"affinitygroup,omitempty"` - Cpunumber int `json:"cpunumber,omitempty"` - Cpuspeed int `json:"cpuspeed,omitempty"` - Cpuused string `json:"cpuused,omitempty"` - Created string `json:"created,omitempty"` - Details map[string]string `json:"details,omitempty"` - Diskioread int64 `json:"diskioread,omitempty"` - Diskiowrite int64 `json:"diskiowrite,omitempty"` - Diskkbsread int64 `json:"diskkbsread,omitempty"` - Diskkbswrite int64 `json:"diskkbswrite,omitempty"` - Diskofferingid string `json:"diskofferingid,omitempty"` - Diskofferingname string `json:"diskofferingname,omitempty"` - Displayname string `json:"displayname,omitempty"` - Displayvm bool `json:"displayvm,omitempty"` - Domain string `json:"domain,omitempty"` - Domainid string `json:"domainid,omitempty"` - Forvirtualnetwork bool `json:"forvirtualnetwork,omitempty"` - Group string `json:"group,omitempty"` - Groupid string `json:"groupid,omitempty"` - Guestosid string `json:"guestosid,omitempty"` - Haenable bool `json:"haenable,omitempty"` - Hostid string `json:"hostid,omitempty"` - Hostname string `json:"hostname,omitempty"` - Hypervisor string `json:"hypervisor,omitempty"` - Id string `json:"id,omitempty"` - Instancename string `json:"instancename,omitempty"` - Isdynamicallyscalable bool `json:"isdynamicallyscalable,omitempty"` - Isodisplaytext string `json:"isodisplaytext,omitempty"` - Isoid string `json:"isoid,omitempty"` - Isoname string `json:"isoname,omitempty"` - Keypair string `json:"keypair,omitempty"` - Memory int `json:"memory,omitempty"` - Name string `json:"name,omitempty"` - Networkkbsread int64 `json:"networkkbsread,omitempty"` - Networkkbswrite int64 `json:"networkkbswrite,omitempty"` - Nic []struct { - Broadcasturi string `json:"broadcasturi,omitempty"` - Deviceid string `json:"deviceid,omitempty"` - Gateway string `json:"gateway,omitempty"` - Id string `json:"id,omitempty"` - Ip6address string `json:"ip6address,omitempty"` - Ip6cidr string `json:"ip6cidr,omitempty"` - Ip6gateway string `json:"ip6gateway,omitempty"` - Ipaddress string `json:"ipaddress,omitempty"` - Isdefault bool `json:"isdefault,omitempty"` - Isolationuri string `json:"isolationuri,omitempty"` - Macaddress string `json:"macaddress,omitempty"` - Netmask string `json:"netmask,omitempty"` - Networkid string `json:"networkid,omitempty"` - Networkname string `json:"networkname,omitempty"` - Secondaryip []struct { - Id string `json:"id,omitempty"` - Ipaddress string `json:"ipaddress,omitempty"` - } `json:"secondaryip,omitempty"` - Traffictype string `json:"traffictype,omitempty"` - Type string `json:"type,omitempty"` - Virtualmachineid string `json:"virtualmachineid,omitempty"` - } `json:"nic,omitempty"` - Ostypeid int64 `json:"ostypeid,omitempty"` - Password string `json:"password,omitempty"` - Passwordenabled bool `json:"passwordenabled,omitempty"` - Project string `json:"project,omitempty"` - Projectid string `json:"projectid,omitempty"` - Publicip string `json:"publicip,omitempty"` - Publicipid string `json:"publicipid,omitempty"` - Rootdeviceid int64 `json:"rootdeviceid,omitempty"` - Rootdevicetype string `json:"rootdevicetype,omitempty"` - Securitygroup []struct { - Account string `json:"account,omitempty"` - Description string `json:"description,omitempty"` - Domain string `json:"domain,omitempty"` - Domainid string `json:"domainid,omitempty"` - Egressrule []struct { - Account string `json:"account,omitempty"` - Cidr string `json:"cidr,omitempty"` - Endport int `json:"endport,omitempty"` - Icmpcode int `json:"icmpcode,omitempty"` - Icmptype int `json:"icmptype,omitempty"` - Protocol string `json:"protocol,omitempty"` - Ruleid string `json:"ruleid,omitempty"` - Securitygroupname string `json:"securitygroupname,omitempty"` - Startport int `json:"startport,omitempty"` - Tags []struct { - Account string `json:"account,omitempty"` - Customer string `json:"customer,omitempty"` - Domain string `json:"domain,omitempty"` - Domainid string `json:"domainid,omitempty"` - Key string `json:"key,omitempty"` - Project string `json:"project,omitempty"` - Projectid string `json:"projectid,omitempty"` - Resourceid string `json:"resourceid,omitempty"` - Resourcetype string `json:"resourcetype,omitempty"` - Value string `json:"value,omitempty"` - } `json:"tags,omitempty"` - } `json:"egressrule,omitempty"` - Id string `json:"id,omitempty"` - Ingressrule []struct { - Account string `json:"account,omitempty"` - Cidr string `json:"cidr,omitempty"` - Endport int `json:"endport,omitempty"` - Icmpcode int `json:"icmpcode,omitempty"` - Icmptype int `json:"icmptype,omitempty"` - Protocol string `json:"protocol,omitempty"` - Ruleid string `json:"ruleid,omitempty"` - Securitygroupname string `json:"securitygroupname,omitempty"` - Startport int `json:"startport,omitempty"` - Tags []struct { - Account string `json:"account,omitempty"` - Customer string `json:"customer,omitempty"` - Domain string `json:"domain,omitempty"` - Domainid string `json:"domainid,omitempty"` - Key string `json:"key,omitempty"` - Project string `json:"project,omitempty"` - Projectid string `json:"projectid,omitempty"` - Resourceid string `json:"resourceid,omitempty"` - Resourcetype string `json:"resourcetype,omitempty"` - Value string `json:"value,omitempty"` - } `json:"tags,omitempty"` - } `json:"ingressrule,omitempty"` - Name string `json:"name,omitempty"` - Project string `json:"project,omitempty"` - Projectid string `json:"projectid,omitempty"` - Tags []struct { - Account string `json:"account,omitempty"` - Customer string `json:"customer,omitempty"` - Domain string `json:"domain,omitempty"` - Domainid string `json:"domainid,omitempty"` - Key string `json:"key,omitempty"` - Project string `json:"project,omitempty"` - Projectid string `json:"projectid,omitempty"` - Resourceid string `json:"resourceid,omitempty"` - Resourcetype string `json:"resourcetype,omitempty"` - Value string `json:"value,omitempty"` - } `json:"tags,omitempty"` - Virtualmachinecount int `json:"virtualmachinecount,omitempty"` - Virtualmachineids []string `json:"virtualmachineids,omitempty"` - } `json:"securitygroup,omitempty"` - Serviceofferingid string `json:"serviceofferingid,omitempty"` - Serviceofferingname string `json:"serviceofferingname,omitempty"` - Servicestate string `json:"servicestate,omitempty"` - State string `json:"state,omitempty"` - Tags []struct { - Account string `json:"account,omitempty"` - Customer string `json:"customer,omitempty"` - Domain string `json:"domain,omitempty"` - Domainid string `json:"domainid,omitempty"` - Key string `json:"key,omitempty"` - Project string `json:"project,omitempty"` - Projectid string `json:"projectid,omitempty"` - Resourceid string `json:"resourceid,omitempty"` - Resourcetype string `json:"resourcetype,omitempty"` - Value string `json:"value,omitempty"` - } `json:"tags,omitempty"` - Templatedisplaytext string `json:"templatedisplaytext,omitempty"` - Templateid string `json:"templateid,omitempty"` - Templatename string `json:"templatename,omitempty"` - Userid string `json:"userid,omitempty"` - Username string `json:"username,omitempty"` - Vgpu string `json:"vgpu,omitempty"` - Zoneid string `json:"zoneid,omitempty"` - Zonename string `json:"zonename,omitempty"` -} - -type StopVirtualMachineParams struct { - p map[string]interface{} -} - -func (p *StopVirtualMachineParams) toURLValues() url.Values { - u := url.Values{} - if p.p == nil { - return u - } - if v, found := p.p["forced"]; found { - vv := strconv.FormatBool(v.(bool)) - u.Set("forced", vv) - } - if v, found := p.p["id"]; found { - u.Set("id", v.(string)) - } - return u -} - -func (p *StopVirtualMachineParams) SetForced(v bool) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["forced"] = v - return -} - -func (p *StopVirtualMachineParams) SetId(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["id"] = v - return -} - -// You should always use this function to get a new StopVirtualMachineParams instance, -// as then you are sure you have configured all required params -func (s *VirtualMachineService) NewStopVirtualMachineParams(id string) *StopVirtualMachineParams { - p := &StopVirtualMachineParams{} - p.p = make(map[string]interface{}) - p.p["id"] = id - return p -} - -// Stops a virtual machine. -func (s *VirtualMachineService) StopVirtualMachine(p *StopVirtualMachineParams) (*StopVirtualMachineResponse, error) { - resp, err := s.cs.newRequest("stopVirtualMachine", p.toURLValues()) - if err != nil { - return nil, err - } - - var r StopVirtualMachineResponse - if err := json.Unmarshal(resp, &r); err != nil { - return nil, err - } - - // If we have a async client, we need to wait for the async result - if s.cs.async { - b, err := s.cs.GetAsyncJobResult(r.JobID, s.cs.timeout) - if err != nil { - if err == AsyncTimeoutErr { - return &r, err - } - return nil, err - } - - b, err = getRawValue(b) - if err != nil { - return nil, err - } - - if err := json.Unmarshal(b, &r); err != nil { - return nil, err - } - } - return &r, nil -} - -type StopVirtualMachineResponse struct { - JobID string `json:"jobid,omitempty"` - Account string `json:"account,omitempty"` - Affinitygroup []struct { - Account string `json:"account,omitempty"` - Description string `json:"description,omitempty"` - Domain string `json:"domain,omitempty"` - Domainid string `json:"domainid,omitempty"` - Id string `json:"id,omitempty"` - Name string `json:"name,omitempty"` - Project string `json:"project,omitempty"` - Projectid string `json:"projectid,omitempty"` - Type string `json:"type,omitempty"` - VirtualmachineIds []string `json:"virtualmachineIds,omitempty"` - } `json:"affinitygroup,omitempty"` - Cpunumber int `json:"cpunumber,omitempty"` - Cpuspeed int `json:"cpuspeed,omitempty"` - Cpuused string `json:"cpuused,omitempty"` - Created string `json:"created,omitempty"` - Details map[string]string `json:"details,omitempty"` - Diskioread int64 `json:"diskioread,omitempty"` - Diskiowrite int64 `json:"diskiowrite,omitempty"` - Diskkbsread int64 `json:"diskkbsread,omitempty"` - Diskkbswrite int64 `json:"diskkbswrite,omitempty"` - Diskofferingid string `json:"diskofferingid,omitempty"` - Diskofferingname string `json:"diskofferingname,omitempty"` - Displayname string `json:"displayname,omitempty"` - Displayvm bool `json:"displayvm,omitempty"` - Domain string `json:"domain,omitempty"` - Domainid string `json:"domainid,omitempty"` - Forvirtualnetwork bool `json:"forvirtualnetwork,omitempty"` - Group string `json:"group,omitempty"` - Groupid string `json:"groupid,omitempty"` - Guestosid string `json:"guestosid,omitempty"` - Haenable bool `json:"haenable,omitempty"` - Hostid string `json:"hostid,omitempty"` - Hostname string `json:"hostname,omitempty"` - Hypervisor string `json:"hypervisor,omitempty"` - Id string `json:"id,omitempty"` - Instancename string `json:"instancename,omitempty"` - Isdynamicallyscalable bool `json:"isdynamicallyscalable,omitempty"` - Isodisplaytext string `json:"isodisplaytext,omitempty"` - Isoid string `json:"isoid,omitempty"` - Isoname string `json:"isoname,omitempty"` - Keypair string `json:"keypair,omitempty"` - Memory int `json:"memory,omitempty"` - Name string `json:"name,omitempty"` - Networkkbsread int64 `json:"networkkbsread,omitempty"` - Networkkbswrite int64 `json:"networkkbswrite,omitempty"` - Nic []struct { - Broadcasturi string `json:"broadcasturi,omitempty"` - Deviceid string `json:"deviceid,omitempty"` - Gateway string `json:"gateway,omitempty"` - Id string `json:"id,omitempty"` - Ip6address string `json:"ip6address,omitempty"` - Ip6cidr string `json:"ip6cidr,omitempty"` - Ip6gateway string `json:"ip6gateway,omitempty"` - Ipaddress string `json:"ipaddress,omitempty"` - Isdefault bool `json:"isdefault,omitempty"` - Isolationuri string `json:"isolationuri,omitempty"` - Macaddress string `json:"macaddress,omitempty"` - Netmask string `json:"netmask,omitempty"` - Networkid string `json:"networkid,omitempty"` - Networkname string `json:"networkname,omitempty"` - Secondaryip []struct { - Id string `json:"id,omitempty"` - Ipaddress string `json:"ipaddress,omitempty"` - } `json:"secondaryip,omitempty"` - Traffictype string `json:"traffictype,omitempty"` - Type string `json:"type,omitempty"` - Virtualmachineid string `json:"virtualmachineid,omitempty"` - } `json:"nic,omitempty"` - Ostypeid int64 `json:"ostypeid,omitempty"` - Password string `json:"password,omitempty"` - Passwordenabled bool `json:"passwordenabled,omitempty"` - Project string `json:"project,omitempty"` - Projectid string `json:"projectid,omitempty"` - Publicip string `json:"publicip,omitempty"` - Publicipid string `json:"publicipid,omitempty"` - Rootdeviceid int64 `json:"rootdeviceid,omitempty"` - Rootdevicetype string `json:"rootdevicetype,omitempty"` - Securitygroup []struct { - Account string `json:"account,omitempty"` - Description string `json:"description,omitempty"` - Domain string `json:"domain,omitempty"` - Domainid string `json:"domainid,omitempty"` - Egressrule []struct { - Account string `json:"account,omitempty"` - Cidr string `json:"cidr,omitempty"` - Endport int `json:"endport,omitempty"` - Icmpcode int `json:"icmpcode,omitempty"` - Icmptype int `json:"icmptype,omitempty"` - Protocol string `json:"protocol,omitempty"` - Ruleid string `json:"ruleid,omitempty"` - Securitygroupname string `json:"securitygroupname,omitempty"` - Startport int `json:"startport,omitempty"` - Tags []struct { - Account string `json:"account,omitempty"` - Customer string `json:"customer,omitempty"` - Domain string `json:"domain,omitempty"` - Domainid string `json:"domainid,omitempty"` - Key string `json:"key,omitempty"` - Project string `json:"project,omitempty"` - Projectid string `json:"projectid,omitempty"` - Resourceid string `json:"resourceid,omitempty"` - Resourcetype string `json:"resourcetype,omitempty"` - Value string `json:"value,omitempty"` - } `json:"tags,omitempty"` - } `json:"egressrule,omitempty"` - Id string `json:"id,omitempty"` - Ingressrule []struct { - Account string `json:"account,omitempty"` - Cidr string `json:"cidr,omitempty"` - Endport int `json:"endport,omitempty"` - Icmpcode int `json:"icmpcode,omitempty"` - Icmptype int `json:"icmptype,omitempty"` - Protocol string `json:"protocol,omitempty"` - Ruleid string `json:"ruleid,omitempty"` - Securitygroupname string `json:"securitygroupname,omitempty"` - Startport int `json:"startport,omitempty"` - Tags []struct { - Account string `json:"account,omitempty"` - Customer string `json:"customer,omitempty"` - Domain string `json:"domain,omitempty"` - Domainid string `json:"domainid,omitempty"` - Key string `json:"key,omitempty"` - Project string `json:"project,omitempty"` - Projectid string `json:"projectid,omitempty"` - Resourceid string `json:"resourceid,omitempty"` - Resourcetype string `json:"resourcetype,omitempty"` - Value string `json:"value,omitempty"` - } `json:"tags,omitempty"` - } `json:"ingressrule,omitempty"` - Name string `json:"name,omitempty"` - Project string `json:"project,omitempty"` - Projectid string `json:"projectid,omitempty"` - Tags []struct { - Account string `json:"account,omitempty"` - Customer string `json:"customer,omitempty"` - Domain string `json:"domain,omitempty"` - Domainid string `json:"domainid,omitempty"` - Key string `json:"key,omitempty"` - Project string `json:"project,omitempty"` - Projectid string `json:"projectid,omitempty"` - Resourceid string `json:"resourceid,omitempty"` - Resourcetype string `json:"resourcetype,omitempty"` - Value string `json:"value,omitempty"` - } `json:"tags,omitempty"` - Virtualmachinecount int `json:"virtualmachinecount,omitempty"` - Virtualmachineids []string `json:"virtualmachineids,omitempty"` - } `json:"securitygroup,omitempty"` - Serviceofferingid string `json:"serviceofferingid,omitempty"` - Serviceofferingname string `json:"serviceofferingname,omitempty"` - Servicestate string `json:"servicestate,omitempty"` - State string `json:"state,omitempty"` - Tags []struct { - Account string `json:"account,omitempty"` - Customer string `json:"customer,omitempty"` - Domain string `json:"domain,omitempty"` - Domainid string `json:"domainid,omitempty"` - Key string `json:"key,omitempty"` - Project string `json:"project,omitempty"` - Projectid string `json:"projectid,omitempty"` - Resourceid string `json:"resourceid,omitempty"` - Resourcetype string `json:"resourcetype,omitempty"` - Value string `json:"value,omitempty"` - } `json:"tags,omitempty"` - Templatedisplaytext string `json:"templatedisplaytext,omitempty"` - Templateid string `json:"templateid,omitempty"` - Templatename string `json:"templatename,omitempty"` - Userid string `json:"userid,omitempty"` - Username string `json:"username,omitempty"` - Vgpu string `json:"vgpu,omitempty"` - Zoneid string `json:"zoneid,omitempty"` - Zonename string `json:"zonename,omitempty"` -} - -type ResetPasswordForVirtualMachineParams struct { - p map[string]interface{} -} - -func (p *ResetPasswordForVirtualMachineParams) toURLValues() url.Values { +func (p *GetVMPasswordParams) toURLValues() url.Values { u := url.Values{} if p.p == nil { return u @@ -1640,7 +1524,7 @@ func (p *ResetPasswordForVirtualMachineParams) toURLValues() url.Values { return u } -func (p *ResetPasswordForVirtualMachineParams) SetId(v string) { +func (p *GetVMPasswordParams) SetId(v string) { if p.p == nil { p.p = make(map[string]interface{}) } @@ -1648,575 +1532,32 @@ func (p *ResetPasswordForVirtualMachineParams) SetId(v string) { return } -// You should always use this function to get a new ResetPasswordForVirtualMachineParams instance, +// You should always use this function to get a new GetVMPasswordParams instance, // as then you are sure you have configured all required params -func (s *VirtualMachineService) NewResetPasswordForVirtualMachineParams(id string) *ResetPasswordForVirtualMachineParams { - p := &ResetPasswordForVirtualMachineParams{} +func (s *VirtualMachineService) NewGetVMPasswordParams(id string) *GetVMPasswordParams { + p := &GetVMPasswordParams{} p.p = make(map[string]interface{}) p.p["id"] = id return p } -// Resets the password for virtual machine. The virtual machine must be in a "Stopped" state and the template must already support this feature for this command to take effect. [async] -func (s *VirtualMachineService) ResetPasswordForVirtualMachine(p *ResetPasswordForVirtualMachineParams) (*ResetPasswordForVirtualMachineResponse, error) { - resp, err := s.cs.newRequest("resetPasswordForVirtualMachine", p.toURLValues()) +// Returns an encrypted password for the VM +func (s *VirtualMachineService) GetVMPassword(p *GetVMPasswordParams) (*GetVMPasswordResponse, error) { + resp, err := s.cs.newRequest("getVMPassword", p.toURLValues()) if err != nil { return nil, err } - var r ResetPasswordForVirtualMachineResponse + var r GetVMPasswordResponse if err := json.Unmarshal(resp, &r); err != nil { return nil, err } - // If we have a async client, we need to wait for the async result - if s.cs.async { - b, err := s.cs.GetAsyncJobResult(r.JobID, s.cs.timeout) - if err != nil { - if err == AsyncTimeoutErr { - return &r, err - } - return nil, err - } - - b, err = getRawValue(b) - if err != nil { - return nil, err - } - - if err := json.Unmarshal(b, &r); err != nil { - return nil, err - } - } return &r, nil } -type ResetPasswordForVirtualMachineResponse struct { - JobID string `json:"jobid,omitempty"` - Account string `json:"account,omitempty"` - Affinitygroup []struct { - Account string `json:"account,omitempty"` - Description string `json:"description,omitempty"` - Domain string `json:"domain,omitempty"` - Domainid string `json:"domainid,omitempty"` - Id string `json:"id,omitempty"` - Name string `json:"name,omitempty"` - Project string `json:"project,omitempty"` - Projectid string `json:"projectid,omitempty"` - Type string `json:"type,omitempty"` - VirtualmachineIds []string `json:"virtualmachineIds,omitempty"` - } `json:"affinitygroup,omitempty"` - Cpunumber int `json:"cpunumber,omitempty"` - Cpuspeed int `json:"cpuspeed,omitempty"` - Cpuused string `json:"cpuused,omitempty"` - Created string `json:"created,omitempty"` - Details map[string]string `json:"details,omitempty"` - Diskioread int64 `json:"diskioread,omitempty"` - Diskiowrite int64 `json:"diskiowrite,omitempty"` - Diskkbsread int64 `json:"diskkbsread,omitempty"` - Diskkbswrite int64 `json:"diskkbswrite,omitempty"` - Diskofferingid string `json:"diskofferingid,omitempty"` - Diskofferingname string `json:"diskofferingname,omitempty"` - Displayname string `json:"displayname,omitempty"` - Displayvm bool `json:"displayvm,omitempty"` - Domain string `json:"domain,omitempty"` - Domainid string `json:"domainid,omitempty"` - Forvirtualnetwork bool `json:"forvirtualnetwork,omitempty"` - Group string `json:"group,omitempty"` - Groupid string `json:"groupid,omitempty"` - Guestosid string `json:"guestosid,omitempty"` - Haenable bool `json:"haenable,omitempty"` - Hostid string `json:"hostid,omitempty"` - Hostname string `json:"hostname,omitempty"` - Hypervisor string `json:"hypervisor,omitempty"` - Id string `json:"id,omitempty"` - Instancename string `json:"instancename,omitempty"` - Isdynamicallyscalable bool `json:"isdynamicallyscalable,omitempty"` - Isodisplaytext string `json:"isodisplaytext,omitempty"` - Isoid string `json:"isoid,omitempty"` - Isoname string `json:"isoname,omitempty"` - Keypair string `json:"keypair,omitempty"` - Memory int `json:"memory,omitempty"` - Name string `json:"name,omitempty"` - Networkkbsread int64 `json:"networkkbsread,omitempty"` - Networkkbswrite int64 `json:"networkkbswrite,omitempty"` - Nic []struct { - Broadcasturi string `json:"broadcasturi,omitempty"` - Deviceid string `json:"deviceid,omitempty"` - Gateway string `json:"gateway,omitempty"` - Id string `json:"id,omitempty"` - Ip6address string `json:"ip6address,omitempty"` - Ip6cidr string `json:"ip6cidr,omitempty"` - Ip6gateway string `json:"ip6gateway,omitempty"` - Ipaddress string `json:"ipaddress,omitempty"` - Isdefault bool `json:"isdefault,omitempty"` - Isolationuri string `json:"isolationuri,omitempty"` - Macaddress string `json:"macaddress,omitempty"` - Netmask string `json:"netmask,omitempty"` - Networkid string `json:"networkid,omitempty"` - Networkname string `json:"networkname,omitempty"` - Secondaryip []struct { - Id string `json:"id,omitempty"` - Ipaddress string `json:"ipaddress,omitempty"` - } `json:"secondaryip,omitempty"` - Traffictype string `json:"traffictype,omitempty"` - Type string `json:"type,omitempty"` - Virtualmachineid string `json:"virtualmachineid,omitempty"` - } `json:"nic,omitempty"` - Ostypeid int64 `json:"ostypeid,omitempty"` - Password string `json:"password,omitempty"` - Passwordenabled bool `json:"passwordenabled,omitempty"` - Project string `json:"project,omitempty"` - Projectid string `json:"projectid,omitempty"` - Publicip string `json:"publicip,omitempty"` - Publicipid string `json:"publicipid,omitempty"` - Rootdeviceid int64 `json:"rootdeviceid,omitempty"` - Rootdevicetype string `json:"rootdevicetype,omitempty"` - Securitygroup []struct { - Account string `json:"account,omitempty"` - Description string `json:"description,omitempty"` - Domain string `json:"domain,omitempty"` - Domainid string `json:"domainid,omitempty"` - Egressrule []struct { - Account string `json:"account,omitempty"` - Cidr string `json:"cidr,omitempty"` - Endport int `json:"endport,omitempty"` - Icmpcode int `json:"icmpcode,omitempty"` - Icmptype int `json:"icmptype,omitempty"` - Protocol string `json:"protocol,omitempty"` - Ruleid string `json:"ruleid,omitempty"` - Securitygroupname string `json:"securitygroupname,omitempty"` - Startport int `json:"startport,omitempty"` - Tags []struct { - Account string `json:"account,omitempty"` - Customer string `json:"customer,omitempty"` - Domain string `json:"domain,omitempty"` - Domainid string `json:"domainid,omitempty"` - Key string `json:"key,omitempty"` - Project string `json:"project,omitempty"` - Projectid string `json:"projectid,omitempty"` - Resourceid string `json:"resourceid,omitempty"` - Resourcetype string `json:"resourcetype,omitempty"` - Value string `json:"value,omitempty"` - } `json:"tags,omitempty"` - } `json:"egressrule,omitempty"` - Id string `json:"id,omitempty"` - Ingressrule []struct { - Account string `json:"account,omitempty"` - Cidr string `json:"cidr,omitempty"` - Endport int `json:"endport,omitempty"` - Icmpcode int `json:"icmpcode,omitempty"` - Icmptype int `json:"icmptype,omitempty"` - Protocol string `json:"protocol,omitempty"` - Ruleid string `json:"ruleid,omitempty"` - Securitygroupname string `json:"securitygroupname,omitempty"` - Startport int `json:"startport,omitempty"` - Tags []struct { - Account string `json:"account,omitempty"` - Customer string `json:"customer,omitempty"` - Domain string `json:"domain,omitempty"` - Domainid string `json:"domainid,omitempty"` - Key string `json:"key,omitempty"` - Project string `json:"project,omitempty"` - Projectid string `json:"projectid,omitempty"` - Resourceid string `json:"resourceid,omitempty"` - Resourcetype string `json:"resourcetype,omitempty"` - Value string `json:"value,omitempty"` - } `json:"tags,omitempty"` - } `json:"ingressrule,omitempty"` - Name string `json:"name,omitempty"` - Project string `json:"project,omitempty"` - Projectid string `json:"projectid,omitempty"` - Tags []struct { - Account string `json:"account,omitempty"` - Customer string `json:"customer,omitempty"` - Domain string `json:"domain,omitempty"` - Domainid string `json:"domainid,omitempty"` - Key string `json:"key,omitempty"` - Project string `json:"project,omitempty"` - Projectid string `json:"projectid,omitempty"` - Resourceid string `json:"resourceid,omitempty"` - Resourcetype string `json:"resourcetype,omitempty"` - Value string `json:"value,omitempty"` - } `json:"tags,omitempty"` - Virtualmachinecount int `json:"virtualmachinecount,omitempty"` - Virtualmachineids []string `json:"virtualmachineids,omitempty"` - } `json:"securitygroup,omitempty"` - Serviceofferingid string `json:"serviceofferingid,omitempty"` - Serviceofferingname string `json:"serviceofferingname,omitempty"` - Servicestate string `json:"servicestate,omitempty"` - State string `json:"state,omitempty"` - Tags []struct { - Account string `json:"account,omitempty"` - Customer string `json:"customer,omitempty"` - Domain string `json:"domain,omitempty"` - Domainid string `json:"domainid,omitempty"` - Key string `json:"key,omitempty"` - Project string `json:"project,omitempty"` - Projectid string `json:"projectid,omitempty"` - Resourceid string `json:"resourceid,omitempty"` - Resourcetype string `json:"resourcetype,omitempty"` - Value string `json:"value,omitempty"` - } `json:"tags,omitempty"` - Templatedisplaytext string `json:"templatedisplaytext,omitempty"` - Templateid string `json:"templateid,omitempty"` - Templatename string `json:"templatename,omitempty"` - Userid string `json:"userid,omitempty"` - Username string `json:"username,omitempty"` - Vgpu string `json:"vgpu,omitempty"` - Zoneid string `json:"zoneid,omitempty"` - Zonename string `json:"zonename,omitempty"` -} - -type UpdateVirtualMachineParams struct { - p map[string]interface{} -} - -func (p *UpdateVirtualMachineParams) toURLValues() url.Values { - u := url.Values{} - if p.p == nil { - return u - } - if v, found := p.p["customid"]; found { - u.Set("customid", v.(string)) - } - if v, found := p.p["details"]; found { - i := 0 - for k, vv := range v.(map[string]string) { - u.Set(fmt.Sprintf("details[%d].key", i), k) - u.Set(fmt.Sprintf("details[%d].value", i), vv) - i++ - } - } - if v, found := p.p["displayname"]; found { - u.Set("displayname", v.(string)) - } - if v, found := p.p["displayvm"]; found { - vv := strconv.FormatBool(v.(bool)) - u.Set("displayvm", vv) - } - if v, found := p.p["group"]; found { - u.Set("group", v.(string)) - } - if v, found := p.p["haenable"]; found { - vv := strconv.FormatBool(v.(bool)) - u.Set("haenable", vv) - } - if v, found := p.p["id"]; found { - u.Set("id", v.(string)) - } - if v, found := p.p["instancename"]; found { - u.Set("instancename", v.(string)) - } - if v, found := p.p["isdynamicallyscalable"]; found { - vv := strconv.FormatBool(v.(bool)) - u.Set("isdynamicallyscalable", vv) - } - if v, found := p.p["name"]; found { - u.Set("name", v.(string)) - } - if v, found := p.p["ostypeid"]; found { - u.Set("ostypeid", v.(string)) - } - if v, found := p.p["userdata"]; found { - u.Set("userdata", v.(string)) - } - return u -} - -func (p *UpdateVirtualMachineParams) SetCustomid(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["customid"] = v - return -} - -func (p *UpdateVirtualMachineParams) SetDetails(v map[string]string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["details"] = v - return -} - -func (p *UpdateVirtualMachineParams) SetDisplayname(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["displayname"] = v - return -} - -func (p *UpdateVirtualMachineParams) SetDisplayvm(v bool) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["displayvm"] = v - return -} - -func (p *UpdateVirtualMachineParams) SetGroup(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["group"] = v - return -} - -func (p *UpdateVirtualMachineParams) SetHaenable(v bool) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["haenable"] = v - return -} - -func (p *UpdateVirtualMachineParams) SetId(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["id"] = v - return -} - -func (p *UpdateVirtualMachineParams) SetInstancename(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["instancename"] = v - return -} - -func (p *UpdateVirtualMachineParams) SetIsdynamicallyscalable(v bool) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["isdynamicallyscalable"] = v - return -} - -func (p *UpdateVirtualMachineParams) SetName(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["name"] = v - return -} - -func (p *UpdateVirtualMachineParams) SetOstypeid(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["ostypeid"] = v - return -} - -func (p *UpdateVirtualMachineParams) SetUserdata(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["userdata"] = v - return -} - -// You should always use this function to get a new UpdateVirtualMachineParams instance, -// as then you are sure you have configured all required params -func (s *VirtualMachineService) NewUpdateVirtualMachineParams(id string) *UpdateVirtualMachineParams { - p := &UpdateVirtualMachineParams{} - p.p = make(map[string]interface{}) - p.p["id"] = id - return p -} - -// Updates properties of a virtual machine. The VM has to be stopped and restarted for the new properties to take effect. UpdateVirtualMachine does not first check whether the VM is stopped. Therefore, stop the VM manually before issuing this call. -func (s *VirtualMachineService) UpdateVirtualMachine(p *UpdateVirtualMachineParams) (*UpdateVirtualMachineResponse, error) { - resp, err := s.cs.newRequest("updateVirtualMachine", p.toURLValues()) - if err != nil { - return nil, err - } - - var r UpdateVirtualMachineResponse - if err := json.Unmarshal(resp, &r); err != nil { - return nil, err - } - return &r, nil -} - -type UpdateVirtualMachineResponse struct { - Account string `json:"account,omitempty"` - Affinitygroup []struct { - Account string `json:"account,omitempty"` - Description string `json:"description,omitempty"` - Domain string `json:"domain,omitempty"` - Domainid string `json:"domainid,omitempty"` - Id string `json:"id,omitempty"` - Name string `json:"name,omitempty"` - Project string `json:"project,omitempty"` - Projectid string `json:"projectid,omitempty"` - Type string `json:"type,omitempty"` - VirtualmachineIds []string `json:"virtualmachineIds,omitempty"` - } `json:"affinitygroup,omitempty"` - Cpunumber int `json:"cpunumber,omitempty"` - Cpuspeed int `json:"cpuspeed,omitempty"` - Cpuused string `json:"cpuused,omitempty"` - Created string `json:"created,omitempty"` - Details map[string]string `json:"details,omitempty"` - Diskioread int64 `json:"diskioread,omitempty"` - Diskiowrite int64 `json:"diskiowrite,omitempty"` - Diskkbsread int64 `json:"diskkbsread,omitempty"` - Diskkbswrite int64 `json:"diskkbswrite,omitempty"` - Diskofferingid string `json:"diskofferingid,omitempty"` - Diskofferingname string `json:"diskofferingname,omitempty"` - Displayname string `json:"displayname,omitempty"` - Displayvm bool `json:"displayvm,omitempty"` - Domain string `json:"domain,omitempty"` - Domainid string `json:"domainid,omitempty"` - Forvirtualnetwork bool `json:"forvirtualnetwork,omitempty"` - Group string `json:"group,omitempty"` - Groupid string `json:"groupid,omitempty"` - Guestosid string `json:"guestosid,omitempty"` - Haenable bool `json:"haenable,omitempty"` - Hostid string `json:"hostid,omitempty"` - Hostname string `json:"hostname,omitempty"` - Hypervisor string `json:"hypervisor,omitempty"` - Id string `json:"id,omitempty"` - Instancename string `json:"instancename,omitempty"` - Isdynamicallyscalable bool `json:"isdynamicallyscalable,omitempty"` - Isodisplaytext string `json:"isodisplaytext,omitempty"` - Isoid string `json:"isoid,omitempty"` - Isoname string `json:"isoname,omitempty"` - Keypair string `json:"keypair,omitempty"` - Memory int `json:"memory,omitempty"` - Name string `json:"name,omitempty"` - Networkkbsread int64 `json:"networkkbsread,omitempty"` - Networkkbswrite int64 `json:"networkkbswrite,omitempty"` - Nic []struct { - Broadcasturi string `json:"broadcasturi,omitempty"` - Deviceid string `json:"deviceid,omitempty"` - Gateway string `json:"gateway,omitempty"` - Id string `json:"id,omitempty"` - Ip6address string `json:"ip6address,omitempty"` - Ip6cidr string `json:"ip6cidr,omitempty"` - Ip6gateway string `json:"ip6gateway,omitempty"` - Ipaddress string `json:"ipaddress,omitempty"` - Isdefault bool `json:"isdefault,omitempty"` - Isolationuri string `json:"isolationuri,omitempty"` - Macaddress string `json:"macaddress,omitempty"` - Netmask string `json:"netmask,omitempty"` - Networkid string `json:"networkid,omitempty"` - Networkname string `json:"networkname,omitempty"` - Secondaryip []struct { - Id string `json:"id,omitempty"` - Ipaddress string `json:"ipaddress,omitempty"` - } `json:"secondaryip,omitempty"` - Traffictype string `json:"traffictype,omitempty"` - Type string `json:"type,omitempty"` - Virtualmachineid string `json:"virtualmachineid,omitempty"` - } `json:"nic,omitempty"` - Ostypeid int64 `json:"ostypeid,omitempty"` - Password string `json:"password,omitempty"` - Passwordenabled bool `json:"passwordenabled,omitempty"` - Project string `json:"project,omitempty"` - Projectid string `json:"projectid,omitempty"` - Publicip string `json:"publicip,omitempty"` - Publicipid string `json:"publicipid,omitempty"` - Rootdeviceid int64 `json:"rootdeviceid,omitempty"` - Rootdevicetype string `json:"rootdevicetype,omitempty"` - Securitygroup []struct { - Account string `json:"account,omitempty"` - Description string `json:"description,omitempty"` - Domain string `json:"domain,omitempty"` - Domainid string `json:"domainid,omitempty"` - Egressrule []struct { - Account string `json:"account,omitempty"` - Cidr string `json:"cidr,omitempty"` - Endport int `json:"endport,omitempty"` - Icmpcode int `json:"icmpcode,omitempty"` - Icmptype int `json:"icmptype,omitempty"` - Protocol string `json:"protocol,omitempty"` - Ruleid string `json:"ruleid,omitempty"` - Securitygroupname string `json:"securitygroupname,omitempty"` - Startport int `json:"startport,omitempty"` - Tags []struct { - Account string `json:"account,omitempty"` - Customer string `json:"customer,omitempty"` - Domain string `json:"domain,omitempty"` - Domainid string `json:"domainid,omitempty"` - Key string `json:"key,omitempty"` - Project string `json:"project,omitempty"` - Projectid string `json:"projectid,omitempty"` - Resourceid string `json:"resourceid,omitempty"` - Resourcetype string `json:"resourcetype,omitempty"` - Value string `json:"value,omitempty"` - } `json:"tags,omitempty"` - } `json:"egressrule,omitempty"` - Id string `json:"id,omitempty"` - Ingressrule []struct { - Account string `json:"account,omitempty"` - Cidr string `json:"cidr,omitempty"` - Endport int `json:"endport,omitempty"` - Icmpcode int `json:"icmpcode,omitempty"` - Icmptype int `json:"icmptype,omitempty"` - Protocol string `json:"protocol,omitempty"` - Ruleid string `json:"ruleid,omitempty"` - Securitygroupname string `json:"securitygroupname,omitempty"` - Startport int `json:"startport,omitempty"` - Tags []struct { - Account string `json:"account,omitempty"` - Customer string `json:"customer,omitempty"` - Domain string `json:"domain,omitempty"` - Domainid string `json:"domainid,omitempty"` - Key string `json:"key,omitempty"` - Project string `json:"project,omitempty"` - Projectid string `json:"projectid,omitempty"` - Resourceid string `json:"resourceid,omitempty"` - Resourcetype string `json:"resourcetype,omitempty"` - Value string `json:"value,omitempty"` - } `json:"tags,omitempty"` - } `json:"ingressrule,omitempty"` - Name string `json:"name,omitempty"` - Project string `json:"project,omitempty"` - Projectid string `json:"projectid,omitempty"` - Tags []struct { - Account string `json:"account,omitempty"` - Customer string `json:"customer,omitempty"` - Domain string `json:"domain,omitempty"` - Domainid string `json:"domainid,omitempty"` - Key string `json:"key,omitempty"` - Project string `json:"project,omitempty"` - Projectid string `json:"projectid,omitempty"` - Resourceid string `json:"resourceid,omitempty"` - Resourcetype string `json:"resourcetype,omitempty"` - Value string `json:"value,omitempty"` - } `json:"tags,omitempty"` - Virtualmachinecount int `json:"virtualmachinecount,omitempty"` - Virtualmachineids []string `json:"virtualmachineids,omitempty"` - } `json:"securitygroup,omitempty"` - Serviceofferingid string `json:"serviceofferingid,omitempty"` - Serviceofferingname string `json:"serviceofferingname,omitempty"` - Servicestate string `json:"servicestate,omitempty"` - State string `json:"state,omitempty"` - Tags []struct { - Account string `json:"account,omitempty"` - Customer string `json:"customer,omitempty"` - Domain string `json:"domain,omitempty"` - Domainid string `json:"domainid,omitempty"` - Key string `json:"key,omitempty"` - Project string `json:"project,omitempty"` - Projectid string `json:"projectid,omitempty"` - Resourceid string `json:"resourceid,omitempty"` - Resourcetype string `json:"resourcetype,omitempty"` - Value string `json:"value,omitempty"` - } `json:"tags,omitempty"` - Templatedisplaytext string `json:"templatedisplaytext,omitempty"` - Templateid string `json:"templateid,omitempty"` - Templatename string `json:"templatename,omitempty"` - Userid string `json:"userid,omitempty"` - Username string `json:"username,omitempty"` - Vgpu string `json:"vgpu,omitempty"` - Zoneid string `json:"zoneid,omitempty"` - Zonename string `json:"zonename,omitempty"` +type GetVMPasswordResponse struct { + Encryptedpassword string `json:"encryptedpassword"` } type ListVirtualMachinesParams struct { @@ -2255,9 +1596,6 @@ func (p *ListVirtualMachinesParams) toURLValues() url.Values { if v, found := p.p["hostid"]; found { u.Set("hostid", v.(string)) } - if v, found := p.p["hostid"]; found { - u.Set("hostid", v.(string)) - } if v, found := p.p["hypervisor"]; found { u.Set("hypervisor", v.(string)) } @@ -2302,9 +1640,6 @@ func (p *ListVirtualMachinesParams) toURLValues() url.Values { if v, found := p.p["podid"]; found { u.Set("podid", v.(string)) } - if v, found := p.p["podid"]; found { - u.Set("podid", v.(string)) - } if v, found := p.p["projectid"]; found { u.Set("projectid", v.(string)) } @@ -2317,9 +1652,6 @@ func (p *ListVirtualMachinesParams) toURLValues() url.Values { if v, found := p.p["storageid"]; found { u.Set("storageid", v.(string)) } - if v, found := p.p["storageid"]; found { - u.Set("storageid", v.(string)) - } if v, found := p.p["tags"]; found { i := 0 for k, vv := range v.(map[string]string) { @@ -2598,7 +1930,7 @@ func (s *VirtualMachineService) GetVirtualMachineID(name string, opts ...OptionF p.p["name"] = name - for _, fn := range opts { + for _, fn := range append(s.cs.options, opts...) { if err := fn(s.cs, p); err != nil { return "", -1, err } @@ -2648,7 +1980,7 @@ func (s *VirtualMachineService) GetVirtualMachineByID(id string, opts ...OptionF p.p["id"] = id - for _, fn := range opts { + for _, fn := range append(s.cs.options, opts...) { if err := fn(s.cs, p); err != nil { return nil, -1, err } @@ -2685,6 +2017,7 @@ func (s *VirtualMachineService) ListVirtualMachines(p *ListVirtualMachinesParams if err := json.Unmarshal(resp, &r); err != nil { return nil, err } + return &r, nil } @@ -2694,1098 +2027,110 @@ type ListVirtualMachinesResponse struct { } type VirtualMachine struct { - Account string `json:"account,omitempty"` - Affinitygroup []struct { - Account string `json:"account,omitempty"` - Description string `json:"description,omitempty"` - Domain string `json:"domain,omitempty"` - Domainid string `json:"domainid,omitempty"` - Id string `json:"id,omitempty"` - Name string `json:"name,omitempty"` - Project string `json:"project,omitempty"` - Projectid string `json:"projectid,omitempty"` - Type string `json:"type,omitempty"` - VirtualmachineIds []string `json:"virtualmachineIds,omitempty"` - } `json:"affinitygroup,omitempty"` - Cpunumber int `json:"cpunumber,omitempty"` - Cpuspeed int `json:"cpuspeed,omitempty"` - Cpuused string `json:"cpuused,omitempty"` - Created string `json:"created,omitempty"` - Details map[string]string `json:"details,omitempty"` - Diskioread int64 `json:"diskioread,omitempty"` - Diskiowrite int64 `json:"diskiowrite,omitempty"` - Diskkbsread int64 `json:"diskkbsread,omitempty"` - Diskkbswrite int64 `json:"diskkbswrite,omitempty"` - Diskofferingid string `json:"diskofferingid,omitempty"` - Diskofferingname string `json:"diskofferingname,omitempty"` - Displayname string `json:"displayname,omitempty"` - Displayvm bool `json:"displayvm,omitempty"` - Domain string `json:"domain,omitempty"` - Domainid string `json:"domainid,omitempty"` - Forvirtualnetwork bool `json:"forvirtualnetwork,omitempty"` - Group string `json:"group,omitempty"` - Groupid string `json:"groupid,omitempty"` - Guestosid string `json:"guestosid,omitempty"` - Haenable bool `json:"haenable,omitempty"` - Hostid string `json:"hostid,omitempty"` - Hostname string `json:"hostname,omitempty"` - Hypervisor string `json:"hypervisor,omitempty"` - Id string `json:"id,omitempty"` - Instancename string `json:"instancename,omitempty"` - Isdynamicallyscalable bool `json:"isdynamicallyscalable,omitempty"` - Isodisplaytext string `json:"isodisplaytext,omitempty"` - Isoid string `json:"isoid,omitempty"` - Isoname string `json:"isoname,omitempty"` - Keypair string `json:"keypair,omitempty"` - Memory int `json:"memory,omitempty"` - Name string `json:"name,omitempty"` - Networkkbsread int64 `json:"networkkbsread,omitempty"` - Networkkbswrite int64 `json:"networkkbswrite,omitempty"` - Nic []struct { - Broadcasturi string `json:"broadcasturi,omitempty"` - Deviceid string `json:"deviceid,omitempty"` - Gateway string `json:"gateway,omitempty"` - Id string `json:"id,omitempty"` - Ip6address string `json:"ip6address,omitempty"` - Ip6cidr string `json:"ip6cidr,omitempty"` - Ip6gateway string `json:"ip6gateway,omitempty"` - Ipaddress string `json:"ipaddress,omitempty"` - Isdefault bool `json:"isdefault,omitempty"` - Isolationuri string `json:"isolationuri,omitempty"` - Macaddress string `json:"macaddress,omitempty"` - Netmask string `json:"netmask,omitempty"` - Networkid string `json:"networkid,omitempty"` - Networkname string `json:"networkname,omitempty"` - Secondaryip []struct { - Id string `json:"id,omitempty"` - Ipaddress string `json:"ipaddress,omitempty"` - } `json:"secondaryip,omitempty"` - Traffictype string `json:"traffictype,omitempty"` - Type string `json:"type,omitempty"` - Virtualmachineid string `json:"virtualmachineid,omitempty"` - } `json:"nic,omitempty"` - Ostypeid int64 `json:"ostypeid,omitempty"` - Password string `json:"password,omitempty"` - Passwordenabled bool `json:"passwordenabled,omitempty"` - Project string `json:"project,omitempty"` - Projectid string `json:"projectid,omitempty"` - Publicip string `json:"publicip,omitempty"` - Publicipid string `json:"publicipid,omitempty"` - Rootdeviceid int64 `json:"rootdeviceid,omitempty"` - Rootdevicetype string `json:"rootdevicetype,omitempty"` - Securitygroup []struct { - Account string `json:"account,omitempty"` - Description string `json:"description,omitempty"` - Domain string `json:"domain,omitempty"` - Domainid string `json:"domainid,omitempty"` - Egressrule []struct { - Account string `json:"account,omitempty"` - Cidr string `json:"cidr,omitempty"` - Endport int `json:"endport,omitempty"` - Icmpcode int `json:"icmpcode,omitempty"` - Icmptype int `json:"icmptype,omitempty"` - Protocol string `json:"protocol,omitempty"` - Ruleid string `json:"ruleid,omitempty"` - Securitygroupname string `json:"securitygroupname,omitempty"` - Startport int `json:"startport,omitempty"` - Tags []struct { - Account string `json:"account,omitempty"` - Customer string `json:"customer,omitempty"` - Domain string `json:"domain,omitempty"` - Domainid string `json:"domainid,omitempty"` - Key string `json:"key,omitempty"` - Project string `json:"project,omitempty"` - Projectid string `json:"projectid,omitempty"` - Resourceid string `json:"resourceid,omitempty"` - Resourcetype string `json:"resourcetype,omitempty"` - Value string `json:"value,omitempty"` - } `json:"tags,omitempty"` - } `json:"egressrule,omitempty"` - Id string `json:"id,omitempty"` - Ingressrule []struct { - Account string `json:"account,omitempty"` - Cidr string `json:"cidr,omitempty"` - Endport int `json:"endport,omitempty"` - Icmpcode int `json:"icmpcode,omitempty"` - Icmptype int `json:"icmptype,omitempty"` - Protocol string `json:"protocol,omitempty"` - Ruleid string `json:"ruleid,omitempty"` - Securitygroupname string `json:"securitygroupname,omitempty"` - Startport int `json:"startport,omitempty"` - Tags []struct { - Account string `json:"account,omitempty"` - Customer string `json:"customer,omitempty"` - Domain string `json:"domain,omitempty"` - Domainid string `json:"domainid,omitempty"` - Key string `json:"key,omitempty"` - Project string `json:"project,omitempty"` - Projectid string `json:"projectid,omitempty"` - Resourceid string `json:"resourceid,omitempty"` - Resourcetype string `json:"resourcetype,omitempty"` - Value string `json:"value,omitempty"` - } `json:"tags,omitempty"` - } `json:"ingressrule,omitempty"` - Name string `json:"name,omitempty"` - Project string `json:"project,omitempty"` - Projectid string `json:"projectid,omitempty"` - Tags []struct { - Account string `json:"account,omitempty"` - Customer string `json:"customer,omitempty"` - Domain string `json:"domain,omitempty"` - Domainid string `json:"domainid,omitempty"` - Key string `json:"key,omitempty"` - Project string `json:"project,omitempty"` - Projectid string `json:"projectid,omitempty"` - Resourceid string `json:"resourceid,omitempty"` - Resourcetype string `json:"resourcetype,omitempty"` - Value string `json:"value,omitempty"` - } `json:"tags,omitempty"` - Virtualmachinecount int `json:"virtualmachinecount,omitempty"` - Virtualmachineids []string `json:"virtualmachineids,omitempty"` - } `json:"securitygroup,omitempty"` - Serviceofferingid string `json:"serviceofferingid,omitempty"` - Serviceofferingname string `json:"serviceofferingname,omitempty"` - Servicestate string `json:"servicestate,omitempty"` - State string `json:"state,omitempty"` - Tags []struct { - Account string `json:"account,omitempty"` - Customer string `json:"customer,omitempty"` - Domain string `json:"domain,omitempty"` - Domainid string `json:"domainid,omitempty"` - Key string `json:"key,omitempty"` - Project string `json:"project,omitempty"` - Projectid string `json:"projectid,omitempty"` - Resourceid string `json:"resourceid,omitempty"` - Resourcetype string `json:"resourcetype,omitempty"` - Value string `json:"value,omitempty"` - } `json:"tags,omitempty"` - Templatedisplaytext string `json:"templatedisplaytext,omitempty"` - Templateid string `json:"templateid,omitempty"` - Templatename string `json:"templatename,omitempty"` - Userid string `json:"userid,omitempty"` - Username string `json:"username,omitempty"` - Vgpu string `json:"vgpu,omitempty"` - Zoneid string `json:"zoneid,omitempty"` - Zonename string `json:"zonename,omitempty"` + Account string `json:"account"` + Affinitygroup []VirtualMachineAffinitygroup `json:"affinitygroup"` + Cpunumber int `json:"cpunumber"` + Cpuspeed int `json:"cpuspeed"` + Cpuused string `json:"cpuused"` + Created string `json:"created"` + Details map[string]string `json:"details"` + Diskioread int64 `json:"diskioread"` + Diskiowrite int64 `json:"diskiowrite"` + Diskkbsread int64 `json:"diskkbsread"` + Diskkbswrite int64 `json:"diskkbswrite"` + Diskofferingid string `json:"diskofferingid"` + Diskofferingname string `json:"diskofferingname"` + Displayname string `json:"displayname"` + Displayvm bool `json:"displayvm"` + Domain string `json:"domain"` + Domainid string `json:"domainid"` + Forvirtualnetwork bool `json:"forvirtualnetwork"` + Group string `json:"group"` + Groupid string `json:"groupid"` + Guestosid string `json:"guestosid"` + Haenable bool `json:"haenable"` + Hostid string `json:"hostid"` + Hostname string `json:"hostname"` + Hypervisor string `json:"hypervisor"` + Id string `json:"id"` + Instancename string `json:"instancename"` + Isdynamicallyscalable bool `json:"isdynamicallyscalable"` + Isodisplaytext string `json:"isodisplaytext"` + Isoid string `json:"isoid"` + Isoname string `json:"isoname"` + Keypair string `json:"keypair"` + Memory int `json:"memory"` + Memoryintfreekbs int64 `json:"memoryintfreekbs"` + Memorykbs int64 `json:"memorykbs"` + Memorytargetkbs int64 `json:"memorytargetkbs"` + Name string `json:"name"` + Networkkbsread int64 `json:"networkkbsread"` + Networkkbswrite int64 `json:"networkkbswrite"` + Nic []Nic `json:"nic"` + Ostypeid int64 `json:"ostypeid"` + Password string `json:"password"` + Passwordenabled bool `json:"passwordenabled"` + Project string `json:"project"` + Projectid string `json:"projectid"` + Publicip string `json:"publicip"` + Publicipid string `json:"publicipid"` + Rootdeviceid int64 `json:"rootdeviceid"` + Rootdevicetype string `json:"rootdevicetype"` + Securitygroup []VirtualMachineSecuritygroup `json:"securitygroup"` + Serviceofferingid string `json:"serviceofferingid"` + Serviceofferingname string `json:"serviceofferingname"` + Servicestate string `json:"servicestate"` + State string `json:"state"` + Templatedisplaytext string `json:"templatedisplaytext"` + Templateid string `json:"templateid"` + Templatename string `json:"templatename"` + Userid string `json:"userid"` + Username string `json:"username"` + Vgpu string `json:"vgpu"` + Zoneid string `json:"zoneid"` + Zonename string `json:"zonename"` } -type GetVMPasswordParams struct { - p map[string]interface{} +type VirtualMachineSecuritygroup struct { + Account string `json:"account"` + Description string `json:"description"` + Domain string `json:"domain"` + Domainid string `json:"domainid"` + Egressrule []VirtualMachineSecuritygroupRule `json:"egressrule"` + Id string `json:"id"` + Ingressrule []VirtualMachineSecuritygroupRule `json:"ingressrule"` + Name string `json:"name"` + Project string `json:"project"` + Projectid string `json:"projectid"` + Tags []Tags `json:"tags"` + Virtualmachinecount int `json:"virtualmachinecount"` + Virtualmachineids []interface{} `json:"virtualmachineids"` } -func (p *GetVMPasswordParams) toURLValues() url.Values { - u := url.Values{} - if p.p == nil { - return u - } - if v, found := p.p["id"]; found { - u.Set("id", v.(string)) - } - return u +type VirtualMachineSecuritygroupRule struct { + Account string `json:"account"` + Cidr string `json:"cidr"` + Endport int `json:"endport"` + Icmpcode int `json:"icmpcode"` + Icmptype int `json:"icmptype"` + Protocol string `json:"protocol"` + Ruleid string `json:"ruleid"` + Securitygroupname string `json:"securitygroupname"` + Startport int `json:"startport"` + Tags []Tags `json:"tags"` } -func (p *GetVMPasswordParams) SetId(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["id"] = v - return -} - -// You should always use this function to get a new GetVMPasswordParams instance, -// as then you are sure you have configured all required params -func (s *VirtualMachineService) NewGetVMPasswordParams(id string) *GetVMPasswordParams { - p := &GetVMPasswordParams{} - p.p = make(map[string]interface{}) - p.p["id"] = id - return p -} - -// Returns an encrypted password for the VM -func (s *VirtualMachineService) GetVMPassword(p *GetVMPasswordParams) (*GetVMPasswordResponse, error) { - resp, err := s.cs.newRequest("getVMPassword", p.toURLValues()) - if err != nil { - return nil, err - } - - var r GetVMPasswordResponse - if err := json.Unmarshal(resp, &r); err != nil { - return nil, err - } - return &r, nil -} - -type GetVMPasswordResponse struct { - Encryptedpassword string `json:"encryptedpassword,omitempty"` -} - -type RestoreVirtualMachineParams struct { - p map[string]interface{} -} - -func (p *RestoreVirtualMachineParams) toURLValues() url.Values { - u := url.Values{} - if p.p == nil { - return u - } - if v, found := p.p["templateid"]; found { - u.Set("templateid", v.(string)) - } - if v, found := p.p["virtualmachineid"]; found { - u.Set("virtualmachineid", v.(string)) - } - return u -} - -func (p *RestoreVirtualMachineParams) SetTemplateid(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["templateid"] = v - return -} - -func (p *RestoreVirtualMachineParams) SetVirtualmachineid(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["virtualmachineid"] = v - return -} - -// You should always use this function to get a new RestoreVirtualMachineParams instance, -// as then you are sure you have configured all required params -func (s *VirtualMachineService) NewRestoreVirtualMachineParams(virtualmachineid string) *RestoreVirtualMachineParams { - p := &RestoreVirtualMachineParams{} - p.p = make(map[string]interface{}) - p.p["virtualmachineid"] = virtualmachineid - return p -} - -// Restore a VM to original template/ISO or new template/ISO -func (s *VirtualMachineService) RestoreVirtualMachine(p *RestoreVirtualMachineParams) (*RestoreVirtualMachineResponse, error) { - resp, err := s.cs.newRequest("restoreVirtualMachine", p.toURLValues()) - if err != nil { - return nil, err - } - - var r RestoreVirtualMachineResponse - if err := json.Unmarshal(resp, &r); err != nil { - return nil, err - } - - // If we have a async client, we need to wait for the async result - if s.cs.async { - b, err := s.cs.GetAsyncJobResult(r.JobID, s.cs.timeout) - if err != nil { - if err == AsyncTimeoutErr { - return &r, err - } - return nil, err - } - - b, err = getRawValue(b) - if err != nil { - return nil, err - } - - if err := json.Unmarshal(b, &r); err != nil { - return nil, err - } - } - return &r, nil -} - -type RestoreVirtualMachineResponse struct { - JobID string `json:"jobid,omitempty"` - Account string `json:"account,omitempty"` - Affinitygroup []struct { - Account string `json:"account,omitempty"` - Description string `json:"description,omitempty"` - Domain string `json:"domain,omitempty"` - Domainid string `json:"domainid,omitempty"` - Id string `json:"id,omitempty"` - Name string `json:"name,omitempty"` - Project string `json:"project,omitempty"` - Projectid string `json:"projectid,omitempty"` - Type string `json:"type,omitempty"` - VirtualmachineIds []string `json:"virtualmachineIds,omitempty"` - } `json:"affinitygroup,omitempty"` - Cpunumber int `json:"cpunumber,omitempty"` - Cpuspeed int `json:"cpuspeed,omitempty"` - Cpuused string `json:"cpuused,omitempty"` - Created string `json:"created,omitempty"` - Details map[string]string `json:"details,omitempty"` - Diskioread int64 `json:"diskioread,omitempty"` - Diskiowrite int64 `json:"diskiowrite,omitempty"` - Diskkbsread int64 `json:"diskkbsread,omitempty"` - Diskkbswrite int64 `json:"diskkbswrite,omitempty"` - Diskofferingid string `json:"diskofferingid,omitempty"` - Diskofferingname string `json:"diskofferingname,omitempty"` - Displayname string `json:"displayname,omitempty"` - Displayvm bool `json:"displayvm,omitempty"` - Domain string `json:"domain,omitempty"` - Domainid string `json:"domainid,omitempty"` - Forvirtualnetwork bool `json:"forvirtualnetwork,omitempty"` - Group string `json:"group,omitempty"` - Groupid string `json:"groupid,omitempty"` - Guestosid string `json:"guestosid,omitempty"` - Haenable bool `json:"haenable,omitempty"` - Hostid string `json:"hostid,omitempty"` - Hostname string `json:"hostname,omitempty"` - Hypervisor string `json:"hypervisor,omitempty"` - Id string `json:"id,omitempty"` - Instancename string `json:"instancename,omitempty"` - Isdynamicallyscalable bool `json:"isdynamicallyscalable,omitempty"` - Isodisplaytext string `json:"isodisplaytext,omitempty"` - Isoid string `json:"isoid,omitempty"` - Isoname string `json:"isoname,omitempty"` - Keypair string `json:"keypair,omitempty"` - Memory int `json:"memory,omitempty"` - Name string `json:"name,omitempty"` - Networkkbsread int64 `json:"networkkbsread,omitempty"` - Networkkbswrite int64 `json:"networkkbswrite,omitempty"` - Nic []struct { - Broadcasturi string `json:"broadcasturi,omitempty"` - Deviceid string `json:"deviceid,omitempty"` - Gateway string `json:"gateway,omitempty"` - Id string `json:"id,omitempty"` - Ip6address string `json:"ip6address,omitempty"` - Ip6cidr string `json:"ip6cidr,omitempty"` - Ip6gateway string `json:"ip6gateway,omitempty"` - Ipaddress string `json:"ipaddress,omitempty"` - Isdefault bool `json:"isdefault,omitempty"` - Isolationuri string `json:"isolationuri,omitempty"` - Macaddress string `json:"macaddress,omitempty"` - Netmask string `json:"netmask,omitempty"` - Networkid string `json:"networkid,omitempty"` - Networkname string `json:"networkname,omitempty"` - Secondaryip []struct { - Id string `json:"id,omitempty"` - Ipaddress string `json:"ipaddress,omitempty"` - } `json:"secondaryip,omitempty"` - Traffictype string `json:"traffictype,omitempty"` - Type string `json:"type,omitempty"` - Virtualmachineid string `json:"virtualmachineid,omitempty"` - } `json:"nic,omitempty"` - Ostypeid int64 `json:"ostypeid,omitempty"` - Password string `json:"password,omitempty"` - Passwordenabled bool `json:"passwordenabled,omitempty"` - Project string `json:"project,omitempty"` - Projectid string `json:"projectid,omitempty"` - Publicip string `json:"publicip,omitempty"` - Publicipid string `json:"publicipid,omitempty"` - Rootdeviceid int64 `json:"rootdeviceid,omitempty"` - Rootdevicetype string `json:"rootdevicetype,omitempty"` - Securitygroup []struct { - Account string `json:"account,omitempty"` - Description string `json:"description,omitempty"` - Domain string `json:"domain,omitempty"` - Domainid string `json:"domainid,omitempty"` - Egressrule []struct { - Account string `json:"account,omitempty"` - Cidr string `json:"cidr,omitempty"` - Endport int `json:"endport,omitempty"` - Icmpcode int `json:"icmpcode,omitempty"` - Icmptype int `json:"icmptype,omitempty"` - Protocol string `json:"protocol,omitempty"` - Ruleid string `json:"ruleid,omitempty"` - Securitygroupname string `json:"securitygroupname,omitempty"` - Startport int `json:"startport,omitempty"` - Tags []struct { - Account string `json:"account,omitempty"` - Customer string `json:"customer,omitempty"` - Domain string `json:"domain,omitempty"` - Domainid string `json:"domainid,omitempty"` - Key string `json:"key,omitempty"` - Project string `json:"project,omitempty"` - Projectid string `json:"projectid,omitempty"` - Resourceid string `json:"resourceid,omitempty"` - Resourcetype string `json:"resourcetype,omitempty"` - Value string `json:"value,omitempty"` - } `json:"tags,omitempty"` - } `json:"egressrule,omitempty"` - Id string `json:"id,omitempty"` - Ingressrule []struct { - Account string `json:"account,omitempty"` - Cidr string `json:"cidr,omitempty"` - Endport int `json:"endport,omitempty"` - Icmpcode int `json:"icmpcode,omitempty"` - Icmptype int `json:"icmptype,omitempty"` - Protocol string `json:"protocol,omitempty"` - Ruleid string `json:"ruleid,omitempty"` - Securitygroupname string `json:"securitygroupname,omitempty"` - Startport int `json:"startport,omitempty"` - Tags []struct { - Account string `json:"account,omitempty"` - Customer string `json:"customer,omitempty"` - Domain string `json:"domain,omitempty"` - Domainid string `json:"domainid,omitempty"` - Key string `json:"key,omitempty"` - Project string `json:"project,omitempty"` - Projectid string `json:"projectid,omitempty"` - Resourceid string `json:"resourceid,omitempty"` - Resourcetype string `json:"resourcetype,omitempty"` - Value string `json:"value,omitempty"` - } `json:"tags,omitempty"` - } `json:"ingressrule,omitempty"` - Name string `json:"name,omitempty"` - Project string `json:"project,omitempty"` - Projectid string `json:"projectid,omitempty"` - Tags []struct { - Account string `json:"account,omitempty"` - Customer string `json:"customer,omitempty"` - Domain string `json:"domain,omitempty"` - Domainid string `json:"domainid,omitempty"` - Key string `json:"key,omitempty"` - Project string `json:"project,omitempty"` - Projectid string `json:"projectid,omitempty"` - Resourceid string `json:"resourceid,omitempty"` - Resourcetype string `json:"resourcetype,omitempty"` - Value string `json:"value,omitempty"` - } `json:"tags,omitempty"` - Virtualmachinecount int `json:"virtualmachinecount,omitempty"` - Virtualmachineids []string `json:"virtualmachineids,omitempty"` - } `json:"securitygroup,omitempty"` - Serviceofferingid string `json:"serviceofferingid,omitempty"` - Serviceofferingname string `json:"serviceofferingname,omitempty"` - Servicestate string `json:"servicestate,omitempty"` - State string `json:"state,omitempty"` - Tags []struct { - Account string `json:"account,omitempty"` - Customer string `json:"customer,omitempty"` - Domain string `json:"domain,omitempty"` - Domainid string `json:"domainid,omitempty"` - Key string `json:"key,omitempty"` - Project string `json:"project,omitempty"` - Projectid string `json:"projectid,omitempty"` - Resourceid string `json:"resourceid,omitempty"` - Resourcetype string `json:"resourcetype,omitempty"` - Value string `json:"value,omitempty"` - } `json:"tags,omitempty"` - Templatedisplaytext string `json:"templatedisplaytext,omitempty"` - Templateid string `json:"templateid,omitempty"` - Templatename string `json:"templatename,omitempty"` - Userid string `json:"userid,omitempty"` - Username string `json:"username,omitempty"` - Vgpu string `json:"vgpu,omitempty"` - Zoneid string `json:"zoneid,omitempty"` - Zonename string `json:"zonename,omitempty"` -} - -type ChangeServiceForVirtualMachineParams struct { - p map[string]interface{} -} - -func (p *ChangeServiceForVirtualMachineParams) toURLValues() url.Values { - u := url.Values{} - if p.p == nil { - return u - } - if v, found := p.p["details"]; found { - i := 0 - for k, vv := range v.(map[string]string) { - u.Set(fmt.Sprintf("details[%d].key", i), k) - u.Set(fmt.Sprintf("details[%d].value", i), vv) - i++ - } - } - if v, found := p.p["id"]; found { - u.Set("id", v.(string)) - } - if v, found := p.p["serviceofferingid"]; found { - u.Set("serviceofferingid", v.(string)) - } - return u -} - -func (p *ChangeServiceForVirtualMachineParams) SetDetails(v map[string]string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["details"] = v - return -} - -func (p *ChangeServiceForVirtualMachineParams) SetId(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["id"] = v - return -} - -func (p *ChangeServiceForVirtualMachineParams) SetServiceofferingid(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["serviceofferingid"] = v - return -} - -// You should always use this function to get a new ChangeServiceForVirtualMachineParams instance, -// as then you are sure you have configured all required params -func (s *VirtualMachineService) NewChangeServiceForVirtualMachineParams(id string, serviceofferingid string) *ChangeServiceForVirtualMachineParams { - p := &ChangeServiceForVirtualMachineParams{} - p.p = make(map[string]interface{}) - p.p["id"] = id - p.p["serviceofferingid"] = serviceofferingid - return p -} - -// Changes the service offering for a virtual machine. The virtual machine must be in a "Stopped" state for this command to take effect. -func (s *VirtualMachineService) ChangeServiceForVirtualMachine(p *ChangeServiceForVirtualMachineParams) (*ChangeServiceForVirtualMachineResponse, error) { - resp, err := s.cs.newRequest("changeServiceForVirtualMachine", p.toURLValues()) - if err != nil { - return nil, err - } - - var r ChangeServiceForVirtualMachineResponse - if err := json.Unmarshal(resp, &r); err != nil { - return nil, err - } - return &r, nil -} - -type ChangeServiceForVirtualMachineResponse struct { - Account string `json:"account,omitempty"` - Affinitygroup []struct { - Account string `json:"account,omitempty"` - Description string `json:"description,omitempty"` - Domain string `json:"domain,omitempty"` - Domainid string `json:"domainid,omitempty"` - Id string `json:"id,omitempty"` - Name string `json:"name,omitempty"` - Project string `json:"project,omitempty"` - Projectid string `json:"projectid,omitempty"` - Type string `json:"type,omitempty"` - VirtualmachineIds []string `json:"virtualmachineIds,omitempty"` - } `json:"affinitygroup,omitempty"` - Cpunumber int `json:"cpunumber,omitempty"` - Cpuspeed int `json:"cpuspeed,omitempty"` - Cpuused string `json:"cpuused,omitempty"` - Created string `json:"created,omitempty"` - Details map[string]string `json:"details,omitempty"` - Diskioread int64 `json:"diskioread,omitempty"` - Diskiowrite int64 `json:"diskiowrite,omitempty"` - Diskkbsread int64 `json:"diskkbsread,omitempty"` - Diskkbswrite int64 `json:"diskkbswrite,omitempty"` - Diskofferingid string `json:"diskofferingid,omitempty"` - Diskofferingname string `json:"diskofferingname,omitempty"` - Displayname string `json:"displayname,omitempty"` - Displayvm bool `json:"displayvm,omitempty"` - Domain string `json:"domain,omitempty"` - Domainid string `json:"domainid,omitempty"` - Forvirtualnetwork bool `json:"forvirtualnetwork,omitempty"` - Group string `json:"group,omitempty"` - Groupid string `json:"groupid,omitempty"` - Guestosid string `json:"guestosid,omitempty"` - Haenable bool `json:"haenable,omitempty"` - Hostid string `json:"hostid,omitempty"` - Hostname string `json:"hostname,omitempty"` - Hypervisor string `json:"hypervisor,omitempty"` - Id string `json:"id,omitempty"` - Instancename string `json:"instancename,omitempty"` - Isdynamicallyscalable bool `json:"isdynamicallyscalable,omitempty"` - Isodisplaytext string `json:"isodisplaytext,omitempty"` - Isoid string `json:"isoid,omitempty"` - Isoname string `json:"isoname,omitempty"` - Keypair string `json:"keypair,omitempty"` - Memory int `json:"memory,omitempty"` - Name string `json:"name,omitempty"` - Networkkbsread int64 `json:"networkkbsread,omitempty"` - Networkkbswrite int64 `json:"networkkbswrite,omitempty"` - Nic []struct { - Broadcasturi string `json:"broadcasturi,omitempty"` - Deviceid string `json:"deviceid,omitempty"` - Gateway string `json:"gateway,omitempty"` - Id string `json:"id,omitempty"` - Ip6address string `json:"ip6address,omitempty"` - Ip6cidr string `json:"ip6cidr,omitempty"` - Ip6gateway string `json:"ip6gateway,omitempty"` - Ipaddress string `json:"ipaddress,omitempty"` - Isdefault bool `json:"isdefault,omitempty"` - Isolationuri string `json:"isolationuri,omitempty"` - Macaddress string `json:"macaddress,omitempty"` - Netmask string `json:"netmask,omitempty"` - Networkid string `json:"networkid,omitempty"` - Networkname string `json:"networkname,omitempty"` - Secondaryip []struct { - Id string `json:"id,omitempty"` - Ipaddress string `json:"ipaddress,omitempty"` - } `json:"secondaryip,omitempty"` - Traffictype string `json:"traffictype,omitempty"` - Type string `json:"type,omitempty"` - Virtualmachineid string `json:"virtualmachineid,omitempty"` - } `json:"nic,omitempty"` - Ostypeid int64 `json:"ostypeid,omitempty"` - Password string `json:"password,omitempty"` - Passwordenabled bool `json:"passwordenabled,omitempty"` - Project string `json:"project,omitempty"` - Projectid string `json:"projectid,omitempty"` - Publicip string `json:"publicip,omitempty"` - Publicipid string `json:"publicipid,omitempty"` - Rootdeviceid int64 `json:"rootdeviceid,omitempty"` - Rootdevicetype string `json:"rootdevicetype,omitempty"` - Securitygroup []struct { - Account string `json:"account,omitempty"` - Description string `json:"description,omitempty"` - Domain string `json:"domain,omitempty"` - Domainid string `json:"domainid,omitempty"` - Egressrule []struct { - Account string `json:"account,omitempty"` - Cidr string `json:"cidr,omitempty"` - Endport int `json:"endport,omitempty"` - Icmpcode int `json:"icmpcode,omitempty"` - Icmptype int `json:"icmptype,omitempty"` - Protocol string `json:"protocol,omitempty"` - Ruleid string `json:"ruleid,omitempty"` - Securitygroupname string `json:"securitygroupname,omitempty"` - Startport int `json:"startport,omitempty"` - Tags []struct { - Account string `json:"account,omitempty"` - Customer string `json:"customer,omitempty"` - Domain string `json:"domain,omitempty"` - Domainid string `json:"domainid,omitempty"` - Key string `json:"key,omitempty"` - Project string `json:"project,omitempty"` - Projectid string `json:"projectid,omitempty"` - Resourceid string `json:"resourceid,omitempty"` - Resourcetype string `json:"resourcetype,omitempty"` - Value string `json:"value,omitempty"` - } `json:"tags,omitempty"` - } `json:"egressrule,omitempty"` - Id string `json:"id,omitempty"` - Ingressrule []struct { - Account string `json:"account,omitempty"` - Cidr string `json:"cidr,omitempty"` - Endport int `json:"endport,omitempty"` - Icmpcode int `json:"icmpcode,omitempty"` - Icmptype int `json:"icmptype,omitempty"` - Protocol string `json:"protocol,omitempty"` - Ruleid string `json:"ruleid,omitempty"` - Securitygroupname string `json:"securitygroupname,omitempty"` - Startport int `json:"startport,omitempty"` - Tags []struct { - Account string `json:"account,omitempty"` - Customer string `json:"customer,omitempty"` - Domain string `json:"domain,omitempty"` - Domainid string `json:"domainid,omitempty"` - Key string `json:"key,omitempty"` - Project string `json:"project,omitempty"` - Projectid string `json:"projectid,omitempty"` - Resourceid string `json:"resourceid,omitempty"` - Resourcetype string `json:"resourcetype,omitempty"` - Value string `json:"value,omitempty"` - } `json:"tags,omitempty"` - } `json:"ingressrule,omitempty"` - Name string `json:"name,omitempty"` - Project string `json:"project,omitempty"` - Projectid string `json:"projectid,omitempty"` - Tags []struct { - Account string `json:"account,omitempty"` - Customer string `json:"customer,omitempty"` - Domain string `json:"domain,omitempty"` - Domainid string `json:"domainid,omitempty"` - Key string `json:"key,omitempty"` - Project string `json:"project,omitempty"` - Projectid string `json:"projectid,omitempty"` - Resourceid string `json:"resourceid,omitempty"` - Resourcetype string `json:"resourcetype,omitempty"` - Value string `json:"value,omitempty"` - } `json:"tags,omitempty"` - Virtualmachinecount int `json:"virtualmachinecount,omitempty"` - Virtualmachineids []string `json:"virtualmachineids,omitempty"` - } `json:"securitygroup,omitempty"` - Serviceofferingid string `json:"serviceofferingid,omitempty"` - Serviceofferingname string `json:"serviceofferingname,omitempty"` - Servicestate string `json:"servicestate,omitempty"` - State string `json:"state,omitempty"` - Tags []struct { - Account string `json:"account,omitempty"` - Customer string `json:"customer,omitempty"` - Domain string `json:"domain,omitempty"` - Domainid string `json:"domainid,omitempty"` - Key string `json:"key,omitempty"` - Project string `json:"project,omitempty"` - Projectid string `json:"projectid,omitempty"` - Resourceid string `json:"resourceid,omitempty"` - Resourcetype string `json:"resourcetype,omitempty"` - Value string `json:"value,omitempty"` - } `json:"tags,omitempty"` - Templatedisplaytext string `json:"templatedisplaytext,omitempty"` - Templateid string `json:"templateid,omitempty"` - Templatename string `json:"templatename,omitempty"` - Userid string `json:"userid,omitempty"` - Username string `json:"username,omitempty"` - Vgpu string `json:"vgpu,omitempty"` - Zoneid string `json:"zoneid,omitempty"` - Zonename string `json:"zonename,omitempty"` -} - -type ScaleVirtualMachineParams struct { - p map[string]interface{} -} - -func (p *ScaleVirtualMachineParams) toURLValues() url.Values { - u := url.Values{} - if p.p == nil { - return u - } - if v, found := p.p["details"]; found { - i := 0 - for k, vv := range v.(map[string]string) { - u.Set(fmt.Sprintf("details[%d].key", i), k) - u.Set(fmt.Sprintf("details[%d].value", i), vv) - i++ - } - } - if v, found := p.p["id"]; found { - u.Set("id", v.(string)) - } - if v, found := p.p["serviceofferingid"]; found { - u.Set("serviceofferingid", v.(string)) - } - return u -} - -func (p *ScaleVirtualMachineParams) SetDetails(v map[string]string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["details"] = v - return -} - -func (p *ScaleVirtualMachineParams) SetId(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["id"] = v - return -} - -func (p *ScaleVirtualMachineParams) SetServiceofferingid(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["serviceofferingid"] = v - return -} - -// You should always use this function to get a new ScaleVirtualMachineParams instance, -// as then you are sure you have configured all required params -func (s *VirtualMachineService) NewScaleVirtualMachineParams(id string, serviceofferingid string) *ScaleVirtualMachineParams { - p := &ScaleVirtualMachineParams{} - p.p = make(map[string]interface{}) - p.p["id"] = id - p.p["serviceofferingid"] = serviceofferingid - return p -} - -// Scales the virtual machine to a new service offering. -func (s *VirtualMachineService) ScaleVirtualMachine(p *ScaleVirtualMachineParams) (*ScaleVirtualMachineResponse, error) { - resp, err := s.cs.newRequest("scaleVirtualMachine", p.toURLValues()) - if err != nil { - return nil, err - } - - var r ScaleVirtualMachineResponse - if err := json.Unmarshal(resp, &r); err != nil { - return nil, err - } - - // If we have a async client, we need to wait for the async result - if s.cs.async { - b, err := s.cs.GetAsyncJobResult(r.JobID, s.cs.timeout) - if err != nil { - if err == AsyncTimeoutErr { - return &r, err - } - return nil, err - } - - if err := json.Unmarshal(b, &r); err != nil { - return nil, err - } - } - return &r, nil -} - -type ScaleVirtualMachineResponse struct { - JobID string `json:"jobid,omitempty"` - Displaytext string `json:"displaytext,omitempty"` - Success bool `json:"success,omitempty"` -} - -type AssignVirtualMachineParams struct { - p map[string]interface{} -} - -func (p *AssignVirtualMachineParams) toURLValues() url.Values { - u := url.Values{} - if p.p == nil { - return u - } - if v, found := p.p["account"]; found { - u.Set("account", v.(string)) - } - if v, found := p.p["domainid"]; found { - u.Set("domainid", v.(string)) - } - if v, found := p.p["networkids"]; found { - vv := strings.Join(v.([]string), ",") - u.Set("networkids", vv) - } - if v, found := p.p["securitygroupids"]; found { - vv := strings.Join(v.([]string), ",") - u.Set("securitygroupids", vv) - } - if v, found := p.p["virtualmachineid"]; found { - u.Set("virtualmachineid", v.(string)) - } - return u -} - -func (p *AssignVirtualMachineParams) SetAccount(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["account"] = v - return -} - -func (p *AssignVirtualMachineParams) SetDomainid(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["domainid"] = v - return -} - -func (p *AssignVirtualMachineParams) SetNetworkids(v []string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["networkids"] = v - return -} - -func (p *AssignVirtualMachineParams) SetSecuritygroupids(v []string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["securitygroupids"] = v - return -} - -func (p *AssignVirtualMachineParams) SetVirtualmachineid(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["virtualmachineid"] = v - return -} - -// You should always use this function to get a new AssignVirtualMachineParams instance, -// as then you are sure you have configured all required params -func (s *VirtualMachineService) NewAssignVirtualMachineParams(account string, domainid string, virtualmachineid string) *AssignVirtualMachineParams { - p := &AssignVirtualMachineParams{} - p.p = make(map[string]interface{}) - p.p["account"] = account - p.p["domainid"] = domainid - p.p["virtualmachineid"] = virtualmachineid - return p -} - -// Change ownership of a VM from one account to another. This API is available for Basic zones with security groups and Advanced zones with guest networks. A root administrator can reassign a VM from any account to any other account in any domain. A domain administrator can reassign a VM to any account in the same domain. -func (s *VirtualMachineService) AssignVirtualMachine(p *AssignVirtualMachineParams) (*AssignVirtualMachineResponse, error) { - resp, err := s.cs.newRequest("assignVirtualMachine", p.toURLValues()) - if err != nil { - return nil, err - } - - var r AssignVirtualMachineResponse - if err := json.Unmarshal(resp, &r); err != nil { - return nil, err - } - return &r, nil -} - -type AssignVirtualMachineResponse struct { - Account string `json:"account,omitempty"` - Affinitygroup []struct { - Account string `json:"account,omitempty"` - Description string `json:"description,omitempty"` - Domain string `json:"domain,omitempty"` - Domainid string `json:"domainid,omitempty"` - Id string `json:"id,omitempty"` - Name string `json:"name,omitempty"` - Project string `json:"project,omitempty"` - Projectid string `json:"projectid,omitempty"` - Type string `json:"type,omitempty"` - VirtualmachineIds []string `json:"virtualmachineIds,omitempty"` - } `json:"affinitygroup,omitempty"` - Cpunumber int `json:"cpunumber,omitempty"` - Cpuspeed int `json:"cpuspeed,omitempty"` - Cpuused string `json:"cpuused,omitempty"` - Created string `json:"created,omitempty"` - Details map[string]string `json:"details,omitempty"` - Diskioread int64 `json:"diskioread,omitempty"` - Diskiowrite int64 `json:"diskiowrite,omitempty"` - Diskkbsread int64 `json:"diskkbsread,omitempty"` - Diskkbswrite int64 `json:"diskkbswrite,omitempty"` - Diskofferingid string `json:"diskofferingid,omitempty"` - Diskofferingname string `json:"diskofferingname,omitempty"` - Displayname string `json:"displayname,omitempty"` - Displayvm bool `json:"displayvm,omitempty"` - Domain string `json:"domain,omitempty"` - Domainid string `json:"domainid,omitempty"` - Forvirtualnetwork bool `json:"forvirtualnetwork,omitempty"` - Group string `json:"group,omitempty"` - Groupid string `json:"groupid,omitempty"` - Guestosid string `json:"guestosid,omitempty"` - Haenable bool `json:"haenable,omitempty"` - Hostid string `json:"hostid,omitempty"` - Hostname string `json:"hostname,omitempty"` - Hypervisor string `json:"hypervisor,omitempty"` - Id string `json:"id,omitempty"` - Instancename string `json:"instancename,omitempty"` - Isdynamicallyscalable bool `json:"isdynamicallyscalable,omitempty"` - Isodisplaytext string `json:"isodisplaytext,omitempty"` - Isoid string `json:"isoid,omitempty"` - Isoname string `json:"isoname,omitempty"` - Keypair string `json:"keypair,omitempty"` - Memory int `json:"memory,omitempty"` - Name string `json:"name,omitempty"` - Networkkbsread int64 `json:"networkkbsread,omitempty"` - Networkkbswrite int64 `json:"networkkbswrite,omitempty"` - Nic []struct { - Broadcasturi string `json:"broadcasturi,omitempty"` - Deviceid string `json:"deviceid,omitempty"` - Gateway string `json:"gateway,omitempty"` - Id string `json:"id,omitempty"` - Ip6address string `json:"ip6address,omitempty"` - Ip6cidr string `json:"ip6cidr,omitempty"` - Ip6gateway string `json:"ip6gateway,omitempty"` - Ipaddress string `json:"ipaddress,omitempty"` - Isdefault bool `json:"isdefault,omitempty"` - Isolationuri string `json:"isolationuri,omitempty"` - Macaddress string `json:"macaddress,omitempty"` - Netmask string `json:"netmask,omitempty"` - Networkid string `json:"networkid,omitempty"` - Networkname string `json:"networkname,omitempty"` - Secondaryip []struct { - Id string `json:"id,omitempty"` - Ipaddress string `json:"ipaddress,omitempty"` - } `json:"secondaryip,omitempty"` - Traffictype string `json:"traffictype,omitempty"` - Type string `json:"type,omitempty"` - Virtualmachineid string `json:"virtualmachineid,omitempty"` - } `json:"nic,omitempty"` - Ostypeid int64 `json:"ostypeid,omitempty"` - Password string `json:"password,omitempty"` - Passwordenabled bool `json:"passwordenabled,omitempty"` - Project string `json:"project,omitempty"` - Projectid string `json:"projectid,omitempty"` - Publicip string `json:"publicip,omitempty"` - Publicipid string `json:"publicipid,omitempty"` - Rootdeviceid int64 `json:"rootdeviceid,omitempty"` - Rootdevicetype string `json:"rootdevicetype,omitempty"` - Securitygroup []struct { - Account string `json:"account,omitempty"` - Description string `json:"description,omitempty"` - Domain string `json:"domain,omitempty"` - Domainid string `json:"domainid,omitempty"` - Egressrule []struct { - Account string `json:"account,omitempty"` - Cidr string `json:"cidr,omitempty"` - Endport int `json:"endport,omitempty"` - Icmpcode int `json:"icmpcode,omitempty"` - Icmptype int `json:"icmptype,omitempty"` - Protocol string `json:"protocol,omitempty"` - Ruleid string `json:"ruleid,omitempty"` - Securitygroupname string `json:"securitygroupname,omitempty"` - Startport int `json:"startport,omitempty"` - Tags []struct { - Account string `json:"account,omitempty"` - Customer string `json:"customer,omitempty"` - Domain string `json:"domain,omitempty"` - Domainid string `json:"domainid,omitempty"` - Key string `json:"key,omitempty"` - Project string `json:"project,omitempty"` - Projectid string `json:"projectid,omitempty"` - Resourceid string `json:"resourceid,omitempty"` - Resourcetype string `json:"resourcetype,omitempty"` - Value string `json:"value,omitempty"` - } `json:"tags,omitempty"` - } `json:"egressrule,omitempty"` - Id string `json:"id,omitempty"` - Ingressrule []struct { - Account string `json:"account,omitempty"` - Cidr string `json:"cidr,omitempty"` - Endport int `json:"endport,omitempty"` - Icmpcode int `json:"icmpcode,omitempty"` - Icmptype int `json:"icmptype,omitempty"` - Protocol string `json:"protocol,omitempty"` - Ruleid string `json:"ruleid,omitempty"` - Securitygroupname string `json:"securitygroupname,omitempty"` - Startport int `json:"startport,omitempty"` - Tags []struct { - Account string `json:"account,omitempty"` - Customer string `json:"customer,omitempty"` - Domain string `json:"domain,omitempty"` - Domainid string `json:"domainid,omitempty"` - Key string `json:"key,omitempty"` - Project string `json:"project,omitempty"` - Projectid string `json:"projectid,omitempty"` - Resourceid string `json:"resourceid,omitempty"` - Resourcetype string `json:"resourcetype,omitempty"` - Value string `json:"value,omitempty"` - } `json:"tags,omitempty"` - } `json:"ingressrule,omitempty"` - Name string `json:"name,omitempty"` - Project string `json:"project,omitempty"` - Projectid string `json:"projectid,omitempty"` - Tags []struct { - Account string `json:"account,omitempty"` - Customer string `json:"customer,omitempty"` - Domain string `json:"domain,omitempty"` - Domainid string `json:"domainid,omitempty"` - Key string `json:"key,omitempty"` - Project string `json:"project,omitempty"` - Projectid string `json:"projectid,omitempty"` - Resourceid string `json:"resourceid,omitempty"` - Resourcetype string `json:"resourcetype,omitempty"` - Value string `json:"value,omitempty"` - } `json:"tags,omitempty"` - Virtualmachinecount int `json:"virtualmachinecount,omitempty"` - Virtualmachineids []string `json:"virtualmachineids,omitempty"` - } `json:"securitygroup,omitempty"` - Serviceofferingid string `json:"serviceofferingid,omitempty"` - Serviceofferingname string `json:"serviceofferingname,omitempty"` - Servicestate string `json:"servicestate,omitempty"` - State string `json:"state,omitempty"` - Tags []struct { - Account string `json:"account,omitempty"` - Customer string `json:"customer,omitempty"` - Domain string `json:"domain,omitempty"` - Domainid string `json:"domainid,omitempty"` - Key string `json:"key,omitempty"` - Project string `json:"project,omitempty"` - Projectid string `json:"projectid,omitempty"` - Resourceid string `json:"resourceid,omitempty"` - Resourcetype string `json:"resourcetype,omitempty"` - Value string `json:"value,omitempty"` - } `json:"tags,omitempty"` - Templatedisplaytext string `json:"templatedisplaytext,omitempty"` - Templateid string `json:"templateid,omitempty"` - Templatename string `json:"templatename,omitempty"` - Userid string `json:"userid,omitempty"` - Username string `json:"username,omitempty"` - Vgpu string `json:"vgpu,omitempty"` - Zoneid string `json:"zoneid,omitempty"` - Zonename string `json:"zonename,omitempty"` +type VirtualMachineAffinitygroup struct { + Account string `json:"account"` + Description string `json:"description"` + Domain string `json:"domain"` + Domainid string `json:"domainid"` + Id string `json:"id"` + Name string `json:"name"` + Project string `json:"project"` + Projectid string `json:"projectid"` + Type string `json:"type"` + VirtualmachineIds []string `json:"virtualmachineIds"` } type MigrateVirtualMachineParams struct { @@ -3873,184 +2218,116 @@ func (s *VirtualMachineService) MigrateVirtualMachine(p *MigrateVirtualMachinePa return nil, err } } + return &r, nil } type MigrateVirtualMachineResponse struct { - JobID string `json:"jobid,omitempty"` - Account string `json:"account,omitempty"` - Affinitygroup []struct { - Account string `json:"account,omitempty"` - Description string `json:"description,omitempty"` - Domain string `json:"domain,omitempty"` - Domainid string `json:"domainid,omitempty"` - Id string `json:"id,omitempty"` - Name string `json:"name,omitempty"` - Project string `json:"project,omitempty"` - Projectid string `json:"projectid,omitempty"` - Type string `json:"type,omitempty"` - VirtualmachineIds []string `json:"virtualmachineIds,omitempty"` - } `json:"affinitygroup,omitempty"` - Cpunumber int `json:"cpunumber,omitempty"` - Cpuspeed int `json:"cpuspeed,omitempty"` - Cpuused string `json:"cpuused,omitempty"` - Created string `json:"created,omitempty"` - Details map[string]string `json:"details,omitempty"` - Diskioread int64 `json:"diskioread,omitempty"` - Diskiowrite int64 `json:"diskiowrite,omitempty"` - Diskkbsread int64 `json:"diskkbsread,omitempty"` - Diskkbswrite int64 `json:"diskkbswrite,omitempty"` - Diskofferingid string `json:"diskofferingid,omitempty"` - Diskofferingname string `json:"diskofferingname,omitempty"` - Displayname string `json:"displayname,omitempty"` - Displayvm bool `json:"displayvm,omitempty"` - Domain string `json:"domain,omitempty"` - Domainid string `json:"domainid,omitempty"` - Forvirtualnetwork bool `json:"forvirtualnetwork,omitempty"` - Group string `json:"group,omitempty"` - Groupid string `json:"groupid,omitempty"` - Guestosid string `json:"guestosid,omitempty"` - Haenable bool `json:"haenable,omitempty"` - Hostid string `json:"hostid,omitempty"` - Hostname string `json:"hostname,omitempty"` - Hypervisor string `json:"hypervisor,omitempty"` - Id string `json:"id,omitempty"` - Instancename string `json:"instancename,omitempty"` - Isdynamicallyscalable bool `json:"isdynamicallyscalable,omitempty"` - Isodisplaytext string `json:"isodisplaytext,omitempty"` - Isoid string `json:"isoid,omitempty"` - Isoname string `json:"isoname,omitempty"` - Keypair string `json:"keypair,omitempty"` - Memory int `json:"memory,omitempty"` - Name string `json:"name,omitempty"` - Networkkbsread int64 `json:"networkkbsread,omitempty"` - Networkkbswrite int64 `json:"networkkbswrite,omitempty"` - Nic []struct { - Broadcasturi string `json:"broadcasturi,omitempty"` - Deviceid string `json:"deviceid,omitempty"` - Gateway string `json:"gateway,omitempty"` - Id string `json:"id,omitempty"` - Ip6address string `json:"ip6address,omitempty"` - Ip6cidr string `json:"ip6cidr,omitempty"` - Ip6gateway string `json:"ip6gateway,omitempty"` - Ipaddress string `json:"ipaddress,omitempty"` - Isdefault bool `json:"isdefault,omitempty"` - Isolationuri string `json:"isolationuri,omitempty"` - Macaddress string `json:"macaddress,omitempty"` - Netmask string `json:"netmask,omitempty"` - Networkid string `json:"networkid,omitempty"` - Networkname string `json:"networkname,omitempty"` - Secondaryip []struct { - Id string `json:"id,omitempty"` - Ipaddress string `json:"ipaddress,omitempty"` - } `json:"secondaryip,omitempty"` - Traffictype string `json:"traffictype,omitempty"` - Type string `json:"type,omitempty"` - Virtualmachineid string `json:"virtualmachineid,omitempty"` - } `json:"nic,omitempty"` - Ostypeid int64 `json:"ostypeid,omitempty"` - Password string `json:"password,omitempty"` - Passwordenabled bool `json:"passwordenabled,omitempty"` - Project string `json:"project,omitempty"` - Projectid string `json:"projectid,omitempty"` - Publicip string `json:"publicip,omitempty"` - Publicipid string `json:"publicipid,omitempty"` - Rootdeviceid int64 `json:"rootdeviceid,omitempty"` - Rootdevicetype string `json:"rootdevicetype,omitempty"` - Securitygroup []struct { - Account string `json:"account,omitempty"` - Description string `json:"description,omitempty"` - Domain string `json:"domain,omitempty"` - Domainid string `json:"domainid,omitempty"` - Egressrule []struct { - Account string `json:"account,omitempty"` - Cidr string `json:"cidr,omitempty"` - Endport int `json:"endport,omitempty"` - Icmpcode int `json:"icmpcode,omitempty"` - Icmptype int `json:"icmptype,omitempty"` - Protocol string `json:"protocol,omitempty"` - Ruleid string `json:"ruleid,omitempty"` - Securitygroupname string `json:"securitygroupname,omitempty"` - Startport int `json:"startport,omitempty"` - Tags []struct { - Account string `json:"account,omitempty"` - Customer string `json:"customer,omitempty"` - Domain string `json:"domain,omitempty"` - Domainid string `json:"domainid,omitempty"` - Key string `json:"key,omitempty"` - Project string `json:"project,omitempty"` - Projectid string `json:"projectid,omitempty"` - Resourceid string `json:"resourceid,omitempty"` - Resourcetype string `json:"resourcetype,omitempty"` - Value string `json:"value,omitempty"` - } `json:"tags,omitempty"` - } `json:"egressrule,omitempty"` - Id string `json:"id,omitempty"` - Ingressrule []struct { - Account string `json:"account,omitempty"` - Cidr string `json:"cidr,omitempty"` - Endport int `json:"endport,omitempty"` - Icmpcode int `json:"icmpcode,omitempty"` - Icmptype int `json:"icmptype,omitempty"` - Protocol string `json:"protocol,omitempty"` - Ruleid string `json:"ruleid,omitempty"` - Securitygroupname string `json:"securitygroupname,omitempty"` - Startport int `json:"startport,omitempty"` - Tags []struct { - Account string `json:"account,omitempty"` - Customer string `json:"customer,omitempty"` - Domain string `json:"domain,omitempty"` - Domainid string `json:"domainid,omitempty"` - Key string `json:"key,omitempty"` - Project string `json:"project,omitempty"` - Projectid string `json:"projectid,omitempty"` - Resourceid string `json:"resourceid,omitempty"` - Resourcetype string `json:"resourcetype,omitempty"` - Value string `json:"value,omitempty"` - } `json:"tags,omitempty"` - } `json:"ingressrule,omitempty"` - Name string `json:"name,omitempty"` - Project string `json:"project,omitempty"` - Projectid string `json:"projectid,omitempty"` - Tags []struct { - Account string `json:"account,omitempty"` - Customer string `json:"customer,omitempty"` - Domain string `json:"domain,omitempty"` - Domainid string `json:"domainid,omitempty"` - Key string `json:"key,omitempty"` - Project string `json:"project,omitempty"` - Projectid string `json:"projectid,omitempty"` - Resourceid string `json:"resourceid,omitempty"` - Resourcetype string `json:"resourcetype,omitempty"` - Value string `json:"value,omitempty"` - } `json:"tags,omitempty"` - Virtualmachinecount int `json:"virtualmachinecount,omitempty"` - Virtualmachineids []string `json:"virtualmachineids,omitempty"` - } `json:"securitygroup,omitempty"` - Serviceofferingid string `json:"serviceofferingid,omitempty"` - Serviceofferingname string `json:"serviceofferingname,omitempty"` - Servicestate string `json:"servicestate,omitempty"` - State string `json:"state,omitempty"` - Tags []struct { - Account string `json:"account,omitempty"` - Customer string `json:"customer,omitempty"` - Domain string `json:"domain,omitempty"` - Domainid string `json:"domainid,omitempty"` - Key string `json:"key,omitempty"` - Project string `json:"project,omitempty"` - Projectid string `json:"projectid,omitempty"` - Resourceid string `json:"resourceid,omitempty"` - Resourcetype string `json:"resourcetype,omitempty"` - Value string `json:"value,omitempty"` - } `json:"tags,omitempty"` - Templatedisplaytext string `json:"templatedisplaytext,omitempty"` - Templateid string `json:"templateid,omitempty"` - Templatename string `json:"templatename,omitempty"` - Userid string `json:"userid,omitempty"` - Username string `json:"username,omitempty"` - Vgpu string `json:"vgpu,omitempty"` - Zoneid string `json:"zoneid,omitempty"` - Zonename string `json:"zonename,omitempty"` + JobID string `json:"jobid"` + Account string `json:"account"` + Affinitygroup []MigrateVirtualMachineResponseAffinitygroup `json:"affinitygroup"` + Cpunumber int `json:"cpunumber"` + Cpuspeed int `json:"cpuspeed"` + Cpuused string `json:"cpuused"` + Created string `json:"created"` + Details map[string]string `json:"details"` + Diskioread int64 `json:"diskioread"` + Diskiowrite int64 `json:"diskiowrite"` + Diskkbsread int64 `json:"diskkbsread"` + Diskkbswrite int64 `json:"diskkbswrite"` + Diskofferingid string `json:"diskofferingid"` + Diskofferingname string `json:"diskofferingname"` + Displayname string `json:"displayname"` + Displayvm bool `json:"displayvm"` + Domain string `json:"domain"` + Domainid string `json:"domainid"` + Forvirtualnetwork bool `json:"forvirtualnetwork"` + Group string `json:"group"` + Groupid string `json:"groupid"` + Guestosid string `json:"guestosid"` + Haenable bool `json:"haenable"` + Hostid string `json:"hostid"` + Hostname string `json:"hostname"` + Hypervisor string `json:"hypervisor"` + Id string `json:"id"` + Instancename string `json:"instancename"` + Isdynamicallyscalable bool `json:"isdynamicallyscalable"` + Isodisplaytext string `json:"isodisplaytext"` + Isoid string `json:"isoid"` + Isoname string `json:"isoname"` + Keypair string `json:"keypair"` + Memory int `json:"memory"` + Memoryintfreekbs int64 `json:"memoryintfreekbs"` + Memorykbs int64 `json:"memorykbs"` + Memorytargetkbs int64 `json:"memorytargetkbs"` + Name string `json:"name"` + Networkkbsread int64 `json:"networkkbsread"` + Networkkbswrite int64 `json:"networkkbswrite"` + Nic []Nic `json:"nic"` + Ostypeid int64 `json:"ostypeid"` + Password string `json:"password"` + Passwordenabled bool `json:"passwordenabled"` + Project string `json:"project"` + Projectid string `json:"projectid"` + Publicip string `json:"publicip"` + Publicipid string `json:"publicipid"` + Rootdeviceid int64 `json:"rootdeviceid"` + Rootdevicetype string `json:"rootdevicetype"` + Securitygroup []MigrateVirtualMachineResponseSecuritygroup `json:"securitygroup"` + Serviceofferingid string `json:"serviceofferingid"` + Serviceofferingname string `json:"serviceofferingname"` + Servicestate string `json:"servicestate"` + State string `json:"state"` + Templatedisplaytext string `json:"templatedisplaytext"` + Templateid string `json:"templateid"` + Templatename string `json:"templatename"` + Userid string `json:"userid"` + Username string `json:"username"` + Vgpu string `json:"vgpu"` + Zoneid string `json:"zoneid"` + Zonename string `json:"zonename"` +} + +type MigrateVirtualMachineResponseSecuritygroup struct { + Account string `json:"account"` + Description string `json:"description"` + Domain string `json:"domain"` + Domainid string `json:"domainid"` + Egressrule []MigrateVirtualMachineResponseSecuritygroupRule `json:"egressrule"` + Id string `json:"id"` + Ingressrule []MigrateVirtualMachineResponseSecuritygroupRule `json:"ingressrule"` + Name string `json:"name"` + Project string `json:"project"` + Projectid string `json:"projectid"` + Tags []Tags `json:"tags"` + Virtualmachinecount int `json:"virtualmachinecount"` + Virtualmachineids []interface{} `json:"virtualmachineids"` +} + +type MigrateVirtualMachineResponseSecuritygroupRule struct { + Account string `json:"account"` + Cidr string `json:"cidr"` + Endport int `json:"endport"` + Icmpcode int `json:"icmpcode"` + Icmptype int `json:"icmptype"` + Protocol string `json:"protocol"` + Ruleid string `json:"ruleid"` + Securitygroupname string `json:"securitygroupname"` + Startport int `json:"startport"` + Tags []Tags `json:"tags"` +} + +type MigrateVirtualMachineResponseAffinitygroup struct { + Account string `json:"account"` + Description string `json:"description"` + Domain string `json:"domain"` + Domainid string `json:"domainid"` + Id string `json:"id"` + Name string `json:"name"` + Project string `json:"project"` + Projectid string `json:"projectid"` + Type string `json:"type"` + VirtualmachineIds []string `json:"virtualmachineIds"` } type MigrateVirtualMachineWithVolumeParams struct { @@ -4144,184 +2421,291 @@ func (s *VirtualMachineService) MigrateVirtualMachineWithVolume(p *MigrateVirtua return nil, err } } + return &r, nil } type MigrateVirtualMachineWithVolumeResponse struct { - JobID string `json:"jobid,omitempty"` - Account string `json:"account,omitempty"` - Affinitygroup []struct { - Account string `json:"account,omitempty"` - Description string `json:"description,omitempty"` - Domain string `json:"domain,omitempty"` - Domainid string `json:"domainid,omitempty"` - Id string `json:"id,omitempty"` - Name string `json:"name,omitempty"` - Project string `json:"project,omitempty"` - Projectid string `json:"projectid,omitempty"` - Type string `json:"type,omitempty"` - VirtualmachineIds []string `json:"virtualmachineIds,omitempty"` - } `json:"affinitygroup,omitempty"` - Cpunumber int `json:"cpunumber,omitempty"` - Cpuspeed int `json:"cpuspeed,omitempty"` - Cpuused string `json:"cpuused,omitempty"` - Created string `json:"created,omitempty"` - Details map[string]string `json:"details,omitempty"` - Diskioread int64 `json:"diskioread,omitempty"` - Diskiowrite int64 `json:"diskiowrite,omitempty"` - Diskkbsread int64 `json:"diskkbsread,omitempty"` - Diskkbswrite int64 `json:"diskkbswrite,omitempty"` - Diskofferingid string `json:"diskofferingid,omitempty"` - Diskofferingname string `json:"diskofferingname,omitempty"` - Displayname string `json:"displayname,omitempty"` - Displayvm bool `json:"displayvm,omitempty"` - Domain string `json:"domain,omitempty"` - Domainid string `json:"domainid,omitempty"` - Forvirtualnetwork bool `json:"forvirtualnetwork,omitempty"` - Group string `json:"group,omitempty"` - Groupid string `json:"groupid,omitempty"` - Guestosid string `json:"guestosid,omitempty"` - Haenable bool `json:"haenable,omitempty"` - Hostid string `json:"hostid,omitempty"` - Hostname string `json:"hostname,omitempty"` - Hypervisor string `json:"hypervisor,omitempty"` - Id string `json:"id,omitempty"` - Instancename string `json:"instancename,omitempty"` - Isdynamicallyscalable bool `json:"isdynamicallyscalable,omitempty"` - Isodisplaytext string `json:"isodisplaytext,omitempty"` - Isoid string `json:"isoid,omitempty"` - Isoname string `json:"isoname,omitempty"` - Keypair string `json:"keypair,omitempty"` - Memory int `json:"memory,omitempty"` - Name string `json:"name,omitempty"` - Networkkbsread int64 `json:"networkkbsread,omitempty"` - Networkkbswrite int64 `json:"networkkbswrite,omitempty"` - Nic []struct { - Broadcasturi string `json:"broadcasturi,omitempty"` - Deviceid string `json:"deviceid,omitempty"` - Gateway string `json:"gateway,omitempty"` - Id string `json:"id,omitempty"` - Ip6address string `json:"ip6address,omitempty"` - Ip6cidr string `json:"ip6cidr,omitempty"` - Ip6gateway string `json:"ip6gateway,omitempty"` - Ipaddress string `json:"ipaddress,omitempty"` - Isdefault bool `json:"isdefault,omitempty"` - Isolationuri string `json:"isolationuri,omitempty"` - Macaddress string `json:"macaddress,omitempty"` - Netmask string `json:"netmask,omitempty"` - Networkid string `json:"networkid,omitempty"` - Networkname string `json:"networkname,omitempty"` - Secondaryip []struct { - Id string `json:"id,omitempty"` - Ipaddress string `json:"ipaddress,omitempty"` - } `json:"secondaryip,omitempty"` - Traffictype string `json:"traffictype,omitempty"` - Type string `json:"type,omitempty"` - Virtualmachineid string `json:"virtualmachineid,omitempty"` - } `json:"nic,omitempty"` - Ostypeid int64 `json:"ostypeid,omitempty"` - Password string `json:"password,omitempty"` - Passwordenabled bool `json:"passwordenabled,omitempty"` - Project string `json:"project,omitempty"` - Projectid string `json:"projectid,omitempty"` - Publicip string `json:"publicip,omitempty"` - Publicipid string `json:"publicipid,omitempty"` - Rootdeviceid int64 `json:"rootdeviceid,omitempty"` - Rootdevicetype string `json:"rootdevicetype,omitempty"` - Securitygroup []struct { - Account string `json:"account,omitempty"` - Description string `json:"description,omitempty"` - Domain string `json:"domain,omitempty"` - Domainid string `json:"domainid,omitempty"` - Egressrule []struct { - Account string `json:"account,omitempty"` - Cidr string `json:"cidr,omitempty"` - Endport int `json:"endport,omitempty"` - Icmpcode int `json:"icmpcode,omitempty"` - Icmptype int `json:"icmptype,omitempty"` - Protocol string `json:"protocol,omitempty"` - Ruleid string `json:"ruleid,omitempty"` - Securitygroupname string `json:"securitygroupname,omitempty"` - Startport int `json:"startport,omitempty"` - Tags []struct { - Account string `json:"account,omitempty"` - Customer string `json:"customer,omitempty"` - Domain string `json:"domain,omitempty"` - Domainid string `json:"domainid,omitempty"` - Key string `json:"key,omitempty"` - Project string `json:"project,omitempty"` - Projectid string `json:"projectid,omitempty"` - Resourceid string `json:"resourceid,omitempty"` - Resourcetype string `json:"resourcetype,omitempty"` - Value string `json:"value,omitempty"` - } `json:"tags,omitempty"` - } `json:"egressrule,omitempty"` - Id string `json:"id,omitempty"` - Ingressrule []struct { - Account string `json:"account,omitempty"` - Cidr string `json:"cidr,omitempty"` - Endport int `json:"endport,omitempty"` - Icmpcode int `json:"icmpcode,omitempty"` - Icmptype int `json:"icmptype,omitempty"` - Protocol string `json:"protocol,omitempty"` - Ruleid string `json:"ruleid,omitempty"` - Securitygroupname string `json:"securitygroupname,omitempty"` - Startport int `json:"startport,omitempty"` - Tags []struct { - Account string `json:"account,omitempty"` - Customer string `json:"customer,omitempty"` - Domain string `json:"domain,omitempty"` - Domainid string `json:"domainid,omitempty"` - Key string `json:"key,omitempty"` - Project string `json:"project,omitempty"` - Projectid string `json:"projectid,omitempty"` - Resourceid string `json:"resourceid,omitempty"` - Resourcetype string `json:"resourcetype,omitempty"` - Value string `json:"value,omitempty"` - } `json:"tags,omitempty"` - } `json:"ingressrule,omitempty"` - Name string `json:"name,omitempty"` - Project string `json:"project,omitempty"` - Projectid string `json:"projectid,omitempty"` - Tags []struct { - Account string `json:"account,omitempty"` - Customer string `json:"customer,omitempty"` - Domain string `json:"domain,omitempty"` - Domainid string `json:"domainid,omitempty"` - Key string `json:"key,omitempty"` - Project string `json:"project,omitempty"` - Projectid string `json:"projectid,omitempty"` - Resourceid string `json:"resourceid,omitempty"` - Resourcetype string `json:"resourcetype,omitempty"` - Value string `json:"value,omitempty"` - } `json:"tags,omitempty"` - Virtualmachinecount int `json:"virtualmachinecount,omitempty"` - Virtualmachineids []string `json:"virtualmachineids,omitempty"` - } `json:"securitygroup,omitempty"` - Serviceofferingid string `json:"serviceofferingid,omitempty"` - Serviceofferingname string `json:"serviceofferingname,omitempty"` - Servicestate string `json:"servicestate,omitempty"` - State string `json:"state,omitempty"` - Tags []struct { - Account string `json:"account,omitempty"` - Customer string `json:"customer,omitempty"` - Domain string `json:"domain,omitempty"` - Domainid string `json:"domainid,omitempty"` - Key string `json:"key,omitempty"` - Project string `json:"project,omitempty"` - Projectid string `json:"projectid,omitempty"` - Resourceid string `json:"resourceid,omitempty"` - Resourcetype string `json:"resourcetype,omitempty"` - Value string `json:"value,omitempty"` - } `json:"tags,omitempty"` - Templatedisplaytext string `json:"templatedisplaytext,omitempty"` - Templateid string `json:"templateid,omitempty"` - Templatename string `json:"templatename,omitempty"` - Userid string `json:"userid,omitempty"` - Username string `json:"username,omitempty"` - Vgpu string `json:"vgpu,omitempty"` - Zoneid string `json:"zoneid,omitempty"` - Zonename string `json:"zonename,omitempty"` + JobID string `json:"jobid"` + Account string `json:"account"` + Affinitygroup []MigrateVirtualMachineWithVolumeResponseAffinitygroup `json:"affinitygroup"` + Cpunumber int `json:"cpunumber"` + Cpuspeed int `json:"cpuspeed"` + Cpuused string `json:"cpuused"` + Created string `json:"created"` + Details map[string]string `json:"details"` + Diskioread int64 `json:"diskioread"` + Diskiowrite int64 `json:"diskiowrite"` + Diskkbsread int64 `json:"diskkbsread"` + Diskkbswrite int64 `json:"diskkbswrite"` + Diskofferingid string `json:"diskofferingid"` + Diskofferingname string `json:"diskofferingname"` + Displayname string `json:"displayname"` + Displayvm bool `json:"displayvm"` + Domain string `json:"domain"` + Domainid string `json:"domainid"` + Forvirtualnetwork bool `json:"forvirtualnetwork"` + Group string `json:"group"` + Groupid string `json:"groupid"` + Guestosid string `json:"guestosid"` + Haenable bool `json:"haenable"` + Hostid string `json:"hostid"` + Hostname string `json:"hostname"` + Hypervisor string `json:"hypervisor"` + Id string `json:"id"` + Instancename string `json:"instancename"` + Isdynamicallyscalable bool `json:"isdynamicallyscalable"` + Isodisplaytext string `json:"isodisplaytext"` + Isoid string `json:"isoid"` + Isoname string `json:"isoname"` + Keypair string `json:"keypair"` + Memory int `json:"memory"` + Memoryintfreekbs int64 `json:"memoryintfreekbs"` + Memorykbs int64 `json:"memorykbs"` + Memorytargetkbs int64 `json:"memorytargetkbs"` + Name string `json:"name"` + Networkkbsread int64 `json:"networkkbsread"` + Networkkbswrite int64 `json:"networkkbswrite"` + Nic []Nic `json:"nic"` + Ostypeid int64 `json:"ostypeid"` + Password string `json:"password"` + Passwordenabled bool `json:"passwordenabled"` + Project string `json:"project"` + Projectid string `json:"projectid"` + Publicip string `json:"publicip"` + Publicipid string `json:"publicipid"` + Rootdeviceid int64 `json:"rootdeviceid"` + Rootdevicetype string `json:"rootdevicetype"` + Securitygroup []MigrateVirtualMachineWithVolumeResponseSecuritygroup `json:"securitygroup"` + Serviceofferingid string `json:"serviceofferingid"` + Serviceofferingname string `json:"serviceofferingname"` + Servicestate string `json:"servicestate"` + State string `json:"state"` + Templatedisplaytext string `json:"templatedisplaytext"` + Templateid string `json:"templateid"` + Templatename string `json:"templatename"` + Userid string `json:"userid"` + Username string `json:"username"` + Vgpu string `json:"vgpu"` + Zoneid string `json:"zoneid"` + Zonename string `json:"zonename"` +} + +type MigrateVirtualMachineWithVolumeResponseSecuritygroup struct { + Account string `json:"account"` + Description string `json:"description"` + Domain string `json:"domain"` + Domainid string `json:"domainid"` + Egressrule []MigrateVirtualMachineWithVolumeResponseSecuritygroupRule `json:"egressrule"` + Id string `json:"id"` + Ingressrule []MigrateVirtualMachineWithVolumeResponseSecuritygroupRule `json:"ingressrule"` + Name string `json:"name"` + Project string `json:"project"` + Projectid string `json:"projectid"` + Tags []Tags `json:"tags"` + Virtualmachinecount int `json:"virtualmachinecount"` + Virtualmachineids []interface{} `json:"virtualmachineids"` +} + +type MigrateVirtualMachineWithVolumeResponseSecuritygroupRule struct { + Account string `json:"account"` + Cidr string `json:"cidr"` + Endport int `json:"endport"` + Icmpcode int `json:"icmpcode"` + Icmptype int `json:"icmptype"` + Protocol string `json:"protocol"` + Ruleid string `json:"ruleid"` + Securitygroupname string `json:"securitygroupname"` + Startport int `json:"startport"` + Tags []Tags `json:"tags"` +} + +type MigrateVirtualMachineWithVolumeResponseAffinitygroup struct { + Account string `json:"account"` + Description string `json:"description"` + Domain string `json:"domain"` + Domainid string `json:"domainid"` + Id string `json:"id"` + Name string `json:"name"` + Project string `json:"project"` + Projectid string `json:"projectid"` + Type string `json:"type"` + VirtualmachineIds []string `json:"virtualmachineIds"` +} + +type RebootVirtualMachineParams struct { + p map[string]interface{} +} + +func (p *RebootVirtualMachineParams) toURLValues() url.Values { + u := url.Values{} + if p.p == nil { + return u + } + if v, found := p.p["id"]; found { + u.Set("id", v.(string)) + } + return u +} + +func (p *RebootVirtualMachineParams) SetId(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["id"] = v + return +} + +// You should always use this function to get a new RebootVirtualMachineParams instance, +// as then you are sure you have configured all required params +func (s *VirtualMachineService) NewRebootVirtualMachineParams(id string) *RebootVirtualMachineParams { + p := &RebootVirtualMachineParams{} + p.p = make(map[string]interface{}) + p.p["id"] = id + return p +} + +// Reboots a virtual machine. +func (s *VirtualMachineService) RebootVirtualMachine(p *RebootVirtualMachineParams) (*RebootVirtualMachineResponse, error) { + resp, err := s.cs.newRequest("rebootVirtualMachine", p.toURLValues()) + if err != nil { + return nil, err + } + + var r RebootVirtualMachineResponse + if err := json.Unmarshal(resp, &r); err != nil { + return nil, err + } + + // If we have a async client, we need to wait for the async result + if s.cs.async { + b, err := s.cs.GetAsyncJobResult(r.JobID, s.cs.timeout) + if err != nil { + if err == AsyncTimeoutErr { + return &r, err + } + return nil, err + } + + b, err = getRawValue(b) + if err != nil { + return nil, err + } + + if err := json.Unmarshal(b, &r); err != nil { + return nil, err + } + } + + return &r, nil +} + +type RebootVirtualMachineResponse struct { + JobID string `json:"jobid"` + Account string `json:"account"` + Affinitygroup []RebootVirtualMachineResponseAffinitygroup `json:"affinitygroup"` + Cpunumber int `json:"cpunumber"` + Cpuspeed int `json:"cpuspeed"` + Cpuused string `json:"cpuused"` + Created string `json:"created"` + Details map[string]string `json:"details"` + Diskioread int64 `json:"diskioread"` + Diskiowrite int64 `json:"diskiowrite"` + Diskkbsread int64 `json:"diskkbsread"` + Diskkbswrite int64 `json:"diskkbswrite"` + Diskofferingid string `json:"diskofferingid"` + Diskofferingname string `json:"diskofferingname"` + Displayname string `json:"displayname"` + Displayvm bool `json:"displayvm"` + Domain string `json:"domain"` + Domainid string `json:"domainid"` + Forvirtualnetwork bool `json:"forvirtualnetwork"` + Group string `json:"group"` + Groupid string `json:"groupid"` + Guestosid string `json:"guestosid"` + Haenable bool `json:"haenable"` + Hostid string `json:"hostid"` + Hostname string `json:"hostname"` + Hypervisor string `json:"hypervisor"` + Id string `json:"id"` + Instancename string `json:"instancename"` + Isdynamicallyscalable bool `json:"isdynamicallyscalable"` + Isodisplaytext string `json:"isodisplaytext"` + Isoid string `json:"isoid"` + Isoname string `json:"isoname"` + Keypair string `json:"keypair"` + Memory int `json:"memory"` + Memoryintfreekbs int64 `json:"memoryintfreekbs"` + Memorykbs int64 `json:"memorykbs"` + Memorytargetkbs int64 `json:"memorytargetkbs"` + Name string `json:"name"` + Networkkbsread int64 `json:"networkkbsread"` + Networkkbswrite int64 `json:"networkkbswrite"` + Nic []Nic `json:"nic"` + Ostypeid int64 `json:"ostypeid"` + Password string `json:"password"` + Passwordenabled bool `json:"passwordenabled"` + Project string `json:"project"` + Projectid string `json:"projectid"` + Publicip string `json:"publicip"` + Publicipid string `json:"publicipid"` + Rootdeviceid int64 `json:"rootdeviceid"` + Rootdevicetype string `json:"rootdevicetype"` + Securitygroup []RebootVirtualMachineResponseSecuritygroup `json:"securitygroup"` + Serviceofferingid string `json:"serviceofferingid"` + Serviceofferingname string `json:"serviceofferingname"` + Servicestate string `json:"servicestate"` + State string `json:"state"` + Templatedisplaytext string `json:"templatedisplaytext"` + Templateid string `json:"templateid"` + Templatename string `json:"templatename"` + Userid string `json:"userid"` + Username string `json:"username"` + Vgpu string `json:"vgpu"` + Zoneid string `json:"zoneid"` + Zonename string `json:"zonename"` +} + +type RebootVirtualMachineResponseSecuritygroup struct { + Account string `json:"account"` + Description string `json:"description"` + Domain string `json:"domain"` + Domainid string `json:"domainid"` + Egressrule []RebootVirtualMachineResponseSecuritygroupRule `json:"egressrule"` + Id string `json:"id"` + Ingressrule []RebootVirtualMachineResponseSecuritygroupRule `json:"ingressrule"` + Name string `json:"name"` + Project string `json:"project"` + Projectid string `json:"projectid"` + Tags []Tags `json:"tags"` + Virtualmachinecount int `json:"virtualmachinecount"` + Virtualmachineids []interface{} `json:"virtualmachineids"` +} + +type RebootVirtualMachineResponseSecuritygroupRule struct { + Account string `json:"account"` + Cidr string `json:"cidr"` + Endport int `json:"endport"` + Icmpcode int `json:"icmpcode"` + Icmptype int `json:"icmptype"` + Protocol string `json:"protocol"` + Ruleid string `json:"ruleid"` + Securitygroupname string `json:"securitygroupname"` + Startport int `json:"startport"` + Tags []Tags `json:"tags"` +} + +type RebootVirtualMachineResponseAffinitygroup struct { + Account string `json:"account"` + Description string `json:"description"` + Domain string `json:"domain"` + Domainid string `json:"domainid"` + Id string `json:"id"` + Name string `json:"name"` + Project string `json:"project"` + Projectid string `json:"projectid"` + Type string `json:"type"` + VirtualmachineIds []string `json:"virtualmachineIds"` } type RecoverVirtualMachineParams struct { @@ -4367,571 +2751,115 @@ func (s *VirtualMachineService) RecoverVirtualMachine(p *RecoverVirtualMachinePa if err := json.Unmarshal(resp, &r); err != nil { return nil, err } + return &r, nil } type RecoverVirtualMachineResponse struct { - Account string `json:"account,omitempty"` - Affinitygroup []struct { - Account string `json:"account,omitempty"` - Description string `json:"description,omitempty"` - Domain string `json:"domain,omitempty"` - Domainid string `json:"domainid,omitempty"` - Id string `json:"id,omitempty"` - Name string `json:"name,omitempty"` - Project string `json:"project,omitempty"` - Projectid string `json:"projectid,omitempty"` - Type string `json:"type,omitempty"` - VirtualmachineIds []string `json:"virtualmachineIds,omitempty"` - } `json:"affinitygroup,omitempty"` - Cpunumber int `json:"cpunumber,omitempty"` - Cpuspeed int `json:"cpuspeed,omitempty"` - Cpuused string `json:"cpuused,omitempty"` - Created string `json:"created,omitempty"` - Details map[string]string `json:"details,omitempty"` - Diskioread int64 `json:"diskioread,omitempty"` - Diskiowrite int64 `json:"diskiowrite,omitempty"` - Diskkbsread int64 `json:"diskkbsread,omitempty"` - Diskkbswrite int64 `json:"diskkbswrite,omitempty"` - Diskofferingid string `json:"diskofferingid,omitempty"` - Diskofferingname string `json:"diskofferingname,omitempty"` - Displayname string `json:"displayname,omitempty"` - Displayvm bool `json:"displayvm,omitempty"` - Domain string `json:"domain,omitempty"` - Domainid string `json:"domainid,omitempty"` - Forvirtualnetwork bool `json:"forvirtualnetwork,omitempty"` - Group string `json:"group,omitempty"` - Groupid string `json:"groupid,omitempty"` - Guestosid string `json:"guestosid,omitempty"` - Haenable bool `json:"haenable,omitempty"` - Hostid string `json:"hostid,omitempty"` - Hostname string `json:"hostname,omitempty"` - Hypervisor string `json:"hypervisor,omitempty"` - Id string `json:"id,omitempty"` - Instancename string `json:"instancename,omitempty"` - Isdynamicallyscalable bool `json:"isdynamicallyscalable,omitempty"` - Isodisplaytext string `json:"isodisplaytext,omitempty"` - Isoid string `json:"isoid,omitempty"` - Isoname string `json:"isoname,omitempty"` - Keypair string `json:"keypair,omitempty"` - Memory int `json:"memory,omitempty"` - Name string `json:"name,omitempty"` - Networkkbsread int64 `json:"networkkbsread,omitempty"` - Networkkbswrite int64 `json:"networkkbswrite,omitempty"` - Nic []struct { - Broadcasturi string `json:"broadcasturi,omitempty"` - Deviceid string `json:"deviceid,omitempty"` - Gateway string `json:"gateway,omitempty"` - Id string `json:"id,omitempty"` - Ip6address string `json:"ip6address,omitempty"` - Ip6cidr string `json:"ip6cidr,omitempty"` - Ip6gateway string `json:"ip6gateway,omitempty"` - Ipaddress string `json:"ipaddress,omitempty"` - Isdefault bool `json:"isdefault,omitempty"` - Isolationuri string `json:"isolationuri,omitempty"` - Macaddress string `json:"macaddress,omitempty"` - Netmask string `json:"netmask,omitempty"` - Networkid string `json:"networkid,omitempty"` - Networkname string `json:"networkname,omitempty"` - Secondaryip []struct { - Id string `json:"id,omitempty"` - Ipaddress string `json:"ipaddress,omitempty"` - } `json:"secondaryip,omitempty"` - Traffictype string `json:"traffictype,omitempty"` - Type string `json:"type,omitempty"` - Virtualmachineid string `json:"virtualmachineid,omitempty"` - } `json:"nic,omitempty"` - Ostypeid int64 `json:"ostypeid,omitempty"` - Password string `json:"password,omitempty"` - Passwordenabled bool `json:"passwordenabled,omitempty"` - Project string `json:"project,omitempty"` - Projectid string `json:"projectid,omitempty"` - Publicip string `json:"publicip,omitempty"` - Publicipid string `json:"publicipid,omitempty"` - Rootdeviceid int64 `json:"rootdeviceid,omitempty"` - Rootdevicetype string `json:"rootdevicetype,omitempty"` - Securitygroup []struct { - Account string `json:"account,omitempty"` - Description string `json:"description,omitempty"` - Domain string `json:"domain,omitempty"` - Domainid string `json:"domainid,omitempty"` - Egressrule []struct { - Account string `json:"account,omitempty"` - Cidr string `json:"cidr,omitempty"` - Endport int `json:"endport,omitempty"` - Icmpcode int `json:"icmpcode,omitempty"` - Icmptype int `json:"icmptype,omitempty"` - Protocol string `json:"protocol,omitempty"` - Ruleid string `json:"ruleid,omitempty"` - Securitygroupname string `json:"securitygroupname,omitempty"` - Startport int `json:"startport,omitempty"` - Tags []struct { - Account string `json:"account,omitempty"` - Customer string `json:"customer,omitempty"` - Domain string `json:"domain,omitempty"` - Domainid string `json:"domainid,omitempty"` - Key string `json:"key,omitempty"` - Project string `json:"project,omitempty"` - Projectid string `json:"projectid,omitempty"` - Resourceid string `json:"resourceid,omitempty"` - Resourcetype string `json:"resourcetype,omitempty"` - Value string `json:"value,omitempty"` - } `json:"tags,omitempty"` - } `json:"egressrule,omitempty"` - Id string `json:"id,omitempty"` - Ingressrule []struct { - Account string `json:"account,omitempty"` - Cidr string `json:"cidr,omitempty"` - Endport int `json:"endport,omitempty"` - Icmpcode int `json:"icmpcode,omitempty"` - Icmptype int `json:"icmptype,omitempty"` - Protocol string `json:"protocol,omitempty"` - Ruleid string `json:"ruleid,omitempty"` - Securitygroupname string `json:"securitygroupname,omitempty"` - Startport int `json:"startport,omitempty"` - Tags []struct { - Account string `json:"account,omitempty"` - Customer string `json:"customer,omitempty"` - Domain string `json:"domain,omitempty"` - Domainid string `json:"domainid,omitempty"` - Key string `json:"key,omitempty"` - Project string `json:"project,omitempty"` - Projectid string `json:"projectid,omitempty"` - Resourceid string `json:"resourceid,omitempty"` - Resourcetype string `json:"resourcetype,omitempty"` - Value string `json:"value,omitempty"` - } `json:"tags,omitempty"` - } `json:"ingressrule,omitempty"` - Name string `json:"name,omitempty"` - Project string `json:"project,omitempty"` - Projectid string `json:"projectid,omitempty"` - Tags []struct { - Account string `json:"account,omitempty"` - Customer string `json:"customer,omitempty"` - Domain string `json:"domain,omitempty"` - Domainid string `json:"domainid,omitempty"` - Key string `json:"key,omitempty"` - Project string `json:"project,omitempty"` - Projectid string `json:"projectid,omitempty"` - Resourceid string `json:"resourceid,omitempty"` - Resourcetype string `json:"resourcetype,omitempty"` - Value string `json:"value,omitempty"` - } `json:"tags,omitempty"` - Virtualmachinecount int `json:"virtualmachinecount,omitempty"` - Virtualmachineids []string `json:"virtualmachineids,omitempty"` - } `json:"securitygroup,omitempty"` - Serviceofferingid string `json:"serviceofferingid,omitempty"` - Serviceofferingname string `json:"serviceofferingname,omitempty"` - Servicestate string `json:"servicestate,omitempty"` - State string `json:"state,omitempty"` - Tags []struct { - Account string `json:"account,omitempty"` - Customer string `json:"customer,omitempty"` - Domain string `json:"domain,omitempty"` - Domainid string `json:"domainid,omitempty"` - Key string `json:"key,omitempty"` - Project string `json:"project,omitempty"` - Projectid string `json:"projectid,omitempty"` - Resourceid string `json:"resourceid,omitempty"` - Resourcetype string `json:"resourcetype,omitempty"` - Value string `json:"value,omitempty"` - } `json:"tags,omitempty"` - Templatedisplaytext string `json:"templatedisplaytext,omitempty"` - Templateid string `json:"templateid,omitempty"` - Templatename string `json:"templatename,omitempty"` - Userid string `json:"userid,omitempty"` - Username string `json:"username,omitempty"` - Vgpu string `json:"vgpu,omitempty"` - Zoneid string `json:"zoneid,omitempty"` - Zonename string `json:"zonename,omitempty"` + Account string `json:"account"` + Affinitygroup []RecoverVirtualMachineResponseAffinitygroup `json:"affinitygroup"` + Cpunumber int `json:"cpunumber"` + Cpuspeed int `json:"cpuspeed"` + Cpuused string `json:"cpuused"` + Created string `json:"created"` + Details map[string]string `json:"details"` + Diskioread int64 `json:"diskioread"` + Diskiowrite int64 `json:"diskiowrite"` + Diskkbsread int64 `json:"diskkbsread"` + Diskkbswrite int64 `json:"diskkbswrite"` + Diskofferingid string `json:"diskofferingid"` + Diskofferingname string `json:"diskofferingname"` + Displayname string `json:"displayname"` + Displayvm bool `json:"displayvm"` + Domain string `json:"domain"` + Domainid string `json:"domainid"` + Forvirtualnetwork bool `json:"forvirtualnetwork"` + Group string `json:"group"` + Groupid string `json:"groupid"` + Guestosid string `json:"guestosid"` + Haenable bool `json:"haenable"` + Hostid string `json:"hostid"` + Hostname string `json:"hostname"` + Hypervisor string `json:"hypervisor"` + Id string `json:"id"` + Instancename string `json:"instancename"` + Isdynamicallyscalable bool `json:"isdynamicallyscalable"` + Isodisplaytext string `json:"isodisplaytext"` + Isoid string `json:"isoid"` + Isoname string `json:"isoname"` + Keypair string `json:"keypair"` + Memory int `json:"memory"` + Memoryintfreekbs int64 `json:"memoryintfreekbs"` + Memorykbs int64 `json:"memorykbs"` + Memorytargetkbs int64 `json:"memorytargetkbs"` + Name string `json:"name"` + Networkkbsread int64 `json:"networkkbsread"` + Networkkbswrite int64 `json:"networkkbswrite"` + Nic []Nic `json:"nic"` + Ostypeid int64 `json:"ostypeid"` + Password string `json:"password"` + Passwordenabled bool `json:"passwordenabled"` + Project string `json:"project"` + Projectid string `json:"projectid"` + Publicip string `json:"publicip"` + Publicipid string `json:"publicipid"` + Rootdeviceid int64 `json:"rootdeviceid"` + Rootdevicetype string `json:"rootdevicetype"` + Securitygroup []RecoverVirtualMachineResponseSecuritygroup `json:"securitygroup"` + Serviceofferingid string `json:"serviceofferingid"` + Serviceofferingname string `json:"serviceofferingname"` + Servicestate string `json:"servicestate"` + State string `json:"state"` + Templatedisplaytext string `json:"templatedisplaytext"` + Templateid string `json:"templateid"` + Templatename string `json:"templatename"` + Userid string `json:"userid"` + Username string `json:"username"` + Vgpu string `json:"vgpu"` + Zoneid string `json:"zoneid"` + Zonename string `json:"zonename"` } -type ExpungeVirtualMachineParams struct { - p map[string]interface{} +type RecoverVirtualMachineResponseSecuritygroup struct { + Account string `json:"account"` + Description string `json:"description"` + Domain string `json:"domain"` + Domainid string `json:"domainid"` + Egressrule []RecoverVirtualMachineResponseSecuritygroupRule `json:"egressrule"` + Id string `json:"id"` + Ingressrule []RecoverVirtualMachineResponseSecuritygroupRule `json:"ingressrule"` + Name string `json:"name"` + Project string `json:"project"` + Projectid string `json:"projectid"` + Tags []Tags `json:"tags"` + Virtualmachinecount int `json:"virtualmachinecount"` + Virtualmachineids []interface{} `json:"virtualmachineids"` } -func (p *ExpungeVirtualMachineParams) toURLValues() url.Values { - u := url.Values{} - if p.p == nil { - return u - } - if v, found := p.p["id"]; found { - u.Set("id", v.(string)) - } - return u +type RecoverVirtualMachineResponseSecuritygroupRule struct { + Account string `json:"account"` + Cidr string `json:"cidr"` + Endport int `json:"endport"` + Icmpcode int `json:"icmpcode"` + Icmptype int `json:"icmptype"` + Protocol string `json:"protocol"` + Ruleid string `json:"ruleid"` + Securitygroupname string `json:"securitygroupname"` + Startport int `json:"startport"` + Tags []Tags `json:"tags"` } -func (p *ExpungeVirtualMachineParams) SetId(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["id"] = v - return -} - -// You should always use this function to get a new ExpungeVirtualMachineParams instance, -// as then you are sure you have configured all required params -func (s *VirtualMachineService) NewExpungeVirtualMachineParams(id string) *ExpungeVirtualMachineParams { - p := &ExpungeVirtualMachineParams{} - p.p = make(map[string]interface{}) - p.p["id"] = id - return p -} - -// Expunge a virtual machine. Once expunged, it cannot be recoverd. -func (s *VirtualMachineService) ExpungeVirtualMachine(p *ExpungeVirtualMachineParams) (*ExpungeVirtualMachineResponse, error) { - resp, err := s.cs.newRequest("expungeVirtualMachine", p.toURLValues()) - if err != nil { - return nil, err - } - - var r ExpungeVirtualMachineResponse - if err := json.Unmarshal(resp, &r); err != nil { - return nil, err - } - - // If we have a async client, we need to wait for the async result - if s.cs.async { - b, err := s.cs.GetAsyncJobResult(r.JobID, s.cs.timeout) - if err != nil { - if err == AsyncTimeoutErr { - return &r, err - } - return nil, err - } - - if err := json.Unmarshal(b, &r); err != nil { - return nil, err - } - } - return &r, nil -} - -type ExpungeVirtualMachineResponse struct { - JobID string `json:"jobid,omitempty"` - Displaytext string `json:"displaytext,omitempty"` - Success bool `json:"success,omitempty"` -} - -type CleanVMReservationsParams struct { - p map[string]interface{} -} - -func (p *CleanVMReservationsParams) toURLValues() url.Values { - u := url.Values{} - if p.p == nil { - return u - } - return u -} - -// You should always use this function to get a new CleanVMReservationsParams instance, -// as then you are sure you have configured all required params -func (s *VirtualMachineService) NewCleanVMReservationsParams() *CleanVMReservationsParams { - p := &CleanVMReservationsParams{} - p.p = make(map[string]interface{}) - return p -} - -// Cleanups VM reservations in the database. -func (s *VirtualMachineService) CleanVMReservations(p *CleanVMReservationsParams) (*CleanVMReservationsResponse, error) { - resp, err := s.cs.newRequest("cleanVMReservations", p.toURLValues()) - if err != nil { - return nil, err - } - - var r CleanVMReservationsResponse - if err := json.Unmarshal(resp, &r); err != nil { - return nil, err - } - - // If we have a async client, we need to wait for the async result - if s.cs.async { - b, err := s.cs.GetAsyncJobResult(r.JobID, s.cs.timeout) - if err != nil { - if err == AsyncTimeoutErr { - return &r, err - } - return nil, err - } - - if err := json.Unmarshal(b, &r); err != nil { - return nil, err - } - } - return &r, nil -} - -type CleanVMReservationsResponse struct { - JobID string `json:"jobid,omitempty"` - Displaytext string `json:"displaytext,omitempty"` - Success bool `json:"success,omitempty"` -} - -type AddNicToVirtualMachineParams struct { - p map[string]interface{} -} - -func (p *AddNicToVirtualMachineParams) toURLValues() url.Values { - u := url.Values{} - if p.p == nil { - return u - } - if v, found := p.p["ipaddress"]; found { - u.Set("ipaddress", v.(string)) - } - if v, found := p.p["networkid"]; found { - u.Set("networkid", v.(string)) - } - if v, found := p.p["virtualmachineid"]; found { - u.Set("virtualmachineid", v.(string)) - } - return u -} - -func (p *AddNicToVirtualMachineParams) SetIpaddress(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["ipaddress"] = v - return -} - -func (p *AddNicToVirtualMachineParams) SetNetworkid(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["networkid"] = v - return -} - -func (p *AddNicToVirtualMachineParams) SetVirtualmachineid(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["virtualmachineid"] = v - return -} - -// You should always use this function to get a new AddNicToVirtualMachineParams instance, -// as then you are sure you have configured all required params -func (s *VirtualMachineService) NewAddNicToVirtualMachineParams(networkid string, virtualmachineid string) *AddNicToVirtualMachineParams { - p := &AddNicToVirtualMachineParams{} - p.p = make(map[string]interface{}) - p.p["networkid"] = networkid - p.p["virtualmachineid"] = virtualmachineid - return p -} - -// Adds VM to specified network by creating a NIC -func (s *VirtualMachineService) AddNicToVirtualMachine(p *AddNicToVirtualMachineParams) (*AddNicToVirtualMachineResponse, error) { - resp, err := s.cs.newRequest("addNicToVirtualMachine", p.toURLValues()) - if err != nil { - return nil, err - } - - var r AddNicToVirtualMachineResponse - if err := json.Unmarshal(resp, &r); err != nil { - return nil, err - } - - // If we have a async client, we need to wait for the async result - if s.cs.async { - b, err := s.cs.GetAsyncJobResult(r.JobID, s.cs.timeout) - if err != nil { - if err == AsyncTimeoutErr { - return &r, err - } - return nil, err - } - - b, err = getRawValue(b) - if err != nil { - return nil, err - } - - if err := json.Unmarshal(b, &r); err != nil { - return nil, err - } - } - return &r, nil -} - -type AddNicToVirtualMachineResponse struct { - JobID string `json:"jobid,omitempty"` - Account string `json:"account,omitempty"` - Affinitygroup []struct { - Account string `json:"account,omitempty"` - Description string `json:"description,omitempty"` - Domain string `json:"domain,omitempty"` - Domainid string `json:"domainid,omitempty"` - Id string `json:"id,omitempty"` - Name string `json:"name,omitempty"` - Project string `json:"project,omitempty"` - Projectid string `json:"projectid,omitempty"` - Type string `json:"type,omitempty"` - VirtualmachineIds []string `json:"virtualmachineIds,omitempty"` - } `json:"affinitygroup,omitempty"` - Cpunumber int `json:"cpunumber,omitempty"` - Cpuspeed int `json:"cpuspeed,omitempty"` - Cpuused string `json:"cpuused,omitempty"` - Created string `json:"created,omitempty"` - Details map[string]string `json:"details,omitempty"` - Diskioread int64 `json:"diskioread,omitempty"` - Diskiowrite int64 `json:"diskiowrite,omitempty"` - Diskkbsread int64 `json:"diskkbsread,omitempty"` - Diskkbswrite int64 `json:"diskkbswrite,omitempty"` - Diskofferingid string `json:"diskofferingid,omitempty"` - Diskofferingname string `json:"diskofferingname,omitempty"` - Displayname string `json:"displayname,omitempty"` - Displayvm bool `json:"displayvm,omitempty"` - Domain string `json:"domain,omitempty"` - Domainid string `json:"domainid,omitempty"` - Forvirtualnetwork bool `json:"forvirtualnetwork,omitempty"` - Group string `json:"group,omitempty"` - Groupid string `json:"groupid,omitempty"` - Guestosid string `json:"guestosid,omitempty"` - Haenable bool `json:"haenable,omitempty"` - Hostid string `json:"hostid,omitempty"` - Hostname string `json:"hostname,omitempty"` - Hypervisor string `json:"hypervisor,omitempty"` - Id string `json:"id,omitempty"` - Instancename string `json:"instancename,omitempty"` - Isdynamicallyscalable bool `json:"isdynamicallyscalable,omitempty"` - Isodisplaytext string `json:"isodisplaytext,omitempty"` - Isoid string `json:"isoid,omitempty"` - Isoname string `json:"isoname,omitempty"` - Keypair string `json:"keypair,omitempty"` - Memory int `json:"memory,omitempty"` - Name string `json:"name,omitempty"` - Networkkbsread int64 `json:"networkkbsread,omitempty"` - Networkkbswrite int64 `json:"networkkbswrite,omitempty"` - Nic []struct { - Broadcasturi string `json:"broadcasturi,omitempty"` - Deviceid string `json:"deviceid,omitempty"` - Gateway string `json:"gateway,omitempty"` - Id string `json:"id,omitempty"` - Ip6address string `json:"ip6address,omitempty"` - Ip6cidr string `json:"ip6cidr,omitempty"` - Ip6gateway string `json:"ip6gateway,omitempty"` - Ipaddress string `json:"ipaddress,omitempty"` - Isdefault bool `json:"isdefault,omitempty"` - Isolationuri string `json:"isolationuri,omitempty"` - Macaddress string `json:"macaddress,omitempty"` - Netmask string `json:"netmask,omitempty"` - Networkid string `json:"networkid,omitempty"` - Networkname string `json:"networkname,omitempty"` - Secondaryip []struct { - Id string `json:"id,omitempty"` - Ipaddress string `json:"ipaddress,omitempty"` - } `json:"secondaryip,omitempty"` - Traffictype string `json:"traffictype,omitempty"` - Type string `json:"type,omitempty"` - Virtualmachineid string `json:"virtualmachineid,omitempty"` - } `json:"nic,omitempty"` - Ostypeid int64 `json:"ostypeid,omitempty"` - Password string `json:"password,omitempty"` - Passwordenabled bool `json:"passwordenabled,omitempty"` - Project string `json:"project,omitempty"` - Projectid string `json:"projectid,omitempty"` - Publicip string `json:"publicip,omitempty"` - Publicipid string `json:"publicipid,omitempty"` - Rootdeviceid int64 `json:"rootdeviceid,omitempty"` - Rootdevicetype string `json:"rootdevicetype,omitempty"` - Securitygroup []struct { - Account string `json:"account,omitempty"` - Description string `json:"description,omitempty"` - Domain string `json:"domain,omitempty"` - Domainid string `json:"domainid,omitempty"` - Egressrule []struct { - Account string `json:"account,omitempty"` - Cidr string `json:"cidr,omitempty"` - Endport int `json:"endport,omitempty"` - Icmpcode int `json:"icmpcode,omitempty"` - Icmptype int `json:"icmptype,omitempty"` - Protocol string `json:"protocol,omitempty"` - Ruleid string `json:"ruleid,omitempty"` - Securitygroupname string `json:"securitygroupname,omitempty"` - Startport int `json:"startport,omitempty"` - Tags []struct { - Account string `json:"account,omitempty"` - Customer string `json:"customer,omitempty"` - Domain string `json:"domain,omitempty"` - Domainid string `json:"domainid,omitempty"` - Key string `json:"key,omitempty"` - Project string `json:"project,omitempty"` - Projectid string `json:"projectid,omitempty"` - Resourceid string `json:"resourceid,omitempty"` - Resourcetype string `json:"resourcetype,omitempty"` - Value string `json:"value,omitempty"` - } `json:"tags,omitempty"` - } `json:"egressrule,omitempty"` - Id string `json:"id,omitempty"` - Ingressrule []struct { - Account string `json:"account,omitempty"` - Cidr string `json:"cidr,omitempty"` - Endport int `json:"endport,omitempty"` - Icmpcode int `json:"icmpcode,omitempty"` - Icmptype int `json:"icmptype,omitempty"` - Protocol string `json:"protocol,omitempty"` - Ruleid string `json:"ruleid,omitempty"` - Securitygroupname string `json:"securitygroupname,omitempty"` - Startport int `json:"startport,omitempty"` - Tags []struct { - Account string `json:"account,omitempty"` - Customer string `json:"customer,omitempty"` - Domain string `json:"domain,omitempty"` - Domainid string `json:"domainid,omitempty"` - Key string `json:"key,omitempty"` - Project string `json:"project,omitempty"` - Projectid string `json:"projectid,omitempty"` - Resourceid string `json:"resourceid,omitempty"` - Resourcetype string `json:"resourcetype,omitempty"` - Value string `json:"value,omitempty"` - } `json:"tags,omitempty"` - } `json:"ingressrule,omitempty"` - Name string `json:"name,omitempty"` - Project string `json:"project,omitempty"` - Projectid string `json:"projectid,omitempty"` - Tags []struct { - Account string `json:"account,omitempty"` - Customer string `json:"customer,omitempty"` - Domain string `json:"domain,omitempty"` - Domainid string `json:"domainid,omitempty"` - Key string `json:"key,omitempty"` - Project string `json:"project,omitempty"` - Projectid string `json:"projectid,omitempty"` - Resourceid string `json:"resourceid,omitempty"` - Resourcetype string `json:"resourcetype,omitempty"` - Value string `json:"value,omitempty"` - } `json:"tags,omitempty"` - Virtualmachinecount int `json:"virtualmachinecount,omitempty"` - Virtualmachineids []string `json:"virtualmachineids,omitempty"` - } `json:"securitygroup,omitempty"` - Serviceofferingid string `json:"serviceofferingid,omitempty"` - Serviceofferingname string `json:"serviceofferingname,omitempty"` - Servicestate string `json:"servicestate,omitempty"` - State string `json:"state,omitempty"` - Tags []struct { - Account string `json:"account,omitempty"` - Customer string `json:"customer,omitempty"` - Domain string `json:"domain,omitempty"` - Domainid string `json:"domainid,omitempty"` - Key string `json:"key,omitempty"` - Project string `json:"project,omitempty"` - Projectid string `json:"projectid,omitempty"` - Resourceid string `json:"resourceid,omitempty"` - Resourcetype string `json:"resourcetype,omitempty"` - Value string `json:"value,omitempty"` - } `json:"tags,omitempty"` - Templatedisplaytext string `json:"templatedisplaytext,omitempty"` - Templateid string `json:"templateid,omitempty"` - Templatename string `json:"templatename,omitempty"` - Userid string `json:"userid,omitempty"` - Username string `json:"username,omitempty"` - Vgpu string `json:"vgpu,omitempty"` - Zoneid string `json:"zoneid,omitempty"` - Zonename string `json:"zonename,omitempty"` +type RecoverVirtualMachineResponseAffinitygroup struct { + Account string `json:"account"` + Description string `json:"description"` + Domain string `json:"domain"` + Domainid string `json:"domainid"` + Id string `json:"id"` + Name string `json:"name"` + Project string `json:"project"` + Projectid string `json:"projectid"` + Type string `json:"type"` + VirtualmachineIds []string `json:"virtualmachineIds"` } type RemoveNicFromVirtualMachineParams struct { @@ -5009,184 +2937,956 @@ func (s *VirtualMachineService) RemoveNicFromVirtualMachine(p *RemoveNicFromVirt return nil, err } } + return &r, nil } type RemoveNicFromVirtualMachineResponse struct { - JobID string `json:"jobid,omitempty"` - Account string `json:"account,omitempty"` - Affinitygroup []struct { - Account string `json:"account,omitempty"` - Description string `json:"description,omitempty"` - Domain string `json:"domain,omitempty"` - Domainid string `json:"domainid,omitempty"` - Id string `json:"id,omitempty"` - Name string `json:"name,omitempty"` - Project string `json:"project,omitempty"` - Projectid string `json:"projectid,omitempty"` - Type string `json:"type,omitempty"` - VirtualmachineIds []string `json:"virtualmachineIds,omitempty"` - } `json:"affinitygroup,omitempty"` - Cpunumber int `json:"cpunumber,omitempty"` - Cpuspeed int `json:"cpuspeed,omitempty"` - Cpuused string `json:"cpuused,omitempty"` - Created string `json:"created,omitempty"` - Details map[string]string `json:"details,omitempty"` - Diskioread int64 `json:"diskioread,omitempty"` - Diskiowrite int64 `json:"diskiowrite,omitempty"` - Diskkbsread int64 `json:"diskkbsread,omitempty"` - Diskkbswrite int64 `json:"diskkbswrite,omitempty"` - Diskofferingid string `json:"diskofferingid,omitempty"` - Diskofferingname string `json:"diskofferingname,omitempty"` - Displayname string `json:"displayname,omitempty"` - Displayvm bool `json:"displayvm,omitempty"` - Domain string `json:"domain,omitempty"` - Domainid string `json:"domainid,omitempty"` - Forvirtualnetwork bool `json:"forvirtualnetwork,omitempty"` - Group string `json:"group,omitempty"` - Groupid string `json:"groupid,omitempty"` - Guestosid string `json:"guestosid,omitempty"` - Haenable bool `json:"haenable,omitempty"` - Hostid string `json:"hostid,omitempty"` - Hostname string `json:"hostname,omitempty"` - Hypervisor string `json:"hypervisor,omitempty"` - Id string `json:"id,omitempty"` - Instancename string `json:"instancename,omitempty"` - Isdynamicallyscalable bool `json:"isdynamicallyscalable,omitempty"` - Isodisplaytext string `json:"isodisplaytext,omitempty"` - Isoid string `json:"isoid,omitempty"` - Isoname string `json:"isoname,omitempty"` - Keypair string `json:"keypair,omitempty"` - Memory int `json:"memory,omitempty"` - Name string `json:"name,omitempty"` - Networkkbsread int64 `json:"networkkbsread,omitempty"` - Networkkbswrite int64 `json:"networkkbswrite,omitempty"` - Nic []struct { - Broadcasturi string `json:"broadcasturi,omitempty"` - Deviceid string `json:"deviceid,omitempty"` - Gateway string `json:"gateway,omitempty"` - Id string `json:"id,omitempty"` - Ip6address string `json:"ip6address,omitempty"` - Ip6cidr string `json:"ip6cidr,omitempty"` - Ip6gateway string `json:"ip6gateway,omitempty"` - Ipaddress string `json:"ipaddress,omitempty"` - Isdefault bool `json:"isdefault,omitempty"` - Isolationuri string `json:"isolationuri,omitempty"` - Macaddress string `json:"macaddress,omitempty"` - Netmask string `json:"netmask,omitempty"` - Networkid string `json:"networkid,omitempty"` - Networkname string `json:"networkname,omitempty"` - Secondaryip []struct { - Id string `json:"id,omitempty"` - Ipaddress string `json:"ipaddress,omitempty"` - } `json:"secondaryip,omitempty"` - Traffictype string `json:"traffictype,omitempty"` - Type string `json:"type,omitempty"` - Virtualmachineid string `json:"virtualmachineid,omitempty"` - } `json:"nic,omitempty"` - Ostypeid int64 `json:"ostypeid,omitempty"` - Password string `json:"password,omitempty"` - Passwordenabled bool `json:"passwordenabled,omitempty"` - Project string `json:"project,omitempty"` - Projectid string `json:"projectid,omitempty"` - Publicip string `json:"publicip,omitempty"` - Publicipid string `json:"publicipid,omitempty"` - Rootdeviceid int64 `json:"rootdeviceid,omitempty"` - Rootdevicetype string `json:"rootdevicetype,omitempty"` - Securitygroup []struct { - Account string `json:"account,omitempty"` - Description string `json:"description,omitempty"` - Domain string `json:"domain,omitempty"` - Domainid string `json:"domainid,omitempty"` - Egressrule []struct { - Account string `json:"account,omitempty"` - Cidr string `json:"cidr,omitempty"` - Endport int `json:"endport,omitempty"` - Icmpcode int `json:"icmpcode,omitempty"` - Icmptype int `json:"icmptype,omitempty"` - Protocol string `json:"protocol,omitempty"` - Ruleid string `json:"ruleid,omitempty"` - Securitygroupname string `json:"securitygroupname,omitempty"` - Startport int `json:"startport,omitempty"` - Tags []struct { - Account string `json:"account,omitempty"` - Customer string `json:"customer,omitempty"` - Domain string `json:"domain,omitempty"` - Domainid string `json:"domainid,omitempty"` - Key string `json:"key,omitempty"` - Project string `json:"project,omitempty"` - Projectid string `json:"projectid,omitempty"` - Resourceid string `json:"resourceid,omitempty"` - Resourcetype string `json:"resourcetype,omitempty"` - Value string `json:"value,omitempty"` - } `json:"tags,omitempty"` - } `json:"egressrule,omitempty"` - Id string `json:"id,omitempty"` - Ingressrule []struct { - Account string `json:"account,omitempty"` - Cidr string `json:"cidr,omitempty"` - Endport int `json:"endport,omitempty"` - Icmpcode int `json:"icmpcode,omitempty"` - Icmptype int `json:"icmptype,omitempty"` - Protocol string `json:"protocol,omitempty"` - Ruleid string `json:"ruleid,omitempty"` - Securitygroupname string `json:"securitygroupname,omitempty"` - Startport int `json:"startport,omitempty"` - Tags []struct { - Account string `json:"account,omitempty"` - Customer string `json:"customer,omitempty"` - Domain string `json:"domain,omitempty"` - Domainid string `json:"domainid,omitempty"` - Key string `json:"key,omitempty"` - Project string `json:"project,omitempty"` - Projectid string `json:"projectid,omitempty"` - Resourceid string `json:"resourceid,omitempty"` - Resourcetype string `json:"resourcetype,omitempty"` - Value string `json:"value,omitempty"` - } `json:"tags,omitempty"` - } `json:"ingressrule,omitempty"` - Name string `json:"name,omitempty"` - Project string `json:"project,omitempty"` - Projectid string `json:"projectid,omitempty"` - Tags []struct { - Account string `json:"account,omitempty"` - Customer string `json:"customer,omitempty"` - Domain string `json:"domain,omitempty"` - Domainid string `json:"domainid,omitempty"` - Key string `json:"key,omitempty"` - Project string `json:"project,omitempty"` - Projectid string `json:"projectid,omitempty"` - Resourceid string `json:"resourceid,omitempty"` - Resourcetype string `json:"resourcetype,omitempty"` - Value string `json:"value,omitempty"` - } `json:"tags,omitempty"` - Virtualmachinecount int `json:"virtualmachinecount,omitempty"` - Virtualmachineids []string `json:"virtualmachineids,omitempty"` - } `json:"securitygroup,omitempty"` - Serviceofferingid string `json:"serviceofferingid,omitempty"` - Serviceofferingname string `json:"serviceofferingname,omitempty"` - Servicestate string `json:"servicestate,omitempty"` - State string `json:"state,omitempty"` - Tags []struct { - Account string `json:"account,omitempty"` - Customer string `json:"customer,omitempty"` - Domain string `json:"domain,omitempty"` - Domainid string `json:"domainid,omitempty"` - Key string `json:"key,omitempty"` - Project string `json:"project,omitempty"` - Projectid string `json:"projectid,omitempty"` - Resourceid string `json:"resourceid,omitempty"` - Resourcetype string `json:"resourcetype,omitempty"` - Value string `json:"value,omitempty"` - } `json:"tags,omitempty"` - Templatedisplaytext string `json:"templatedisplaytext,omitempty"` - Templateid string `json:"templateid,omitempty"` - Templatename string `json:"templatename,omitempty"` - Userid string `json:"userid,omitempty"` - Username string `json:"username,omitempty"` - Vgpu string `json:"vgpu,omitempty"` - Zoneid string `json:"zoneid,omitempty"` - Zonename string `json:"zonename,omitempty"` + JobID string `json:"jobid"` + Account string `json:"account"` + Affinitygroup []RemoveNicFromVirtualMachineResponseAffinitygroup `json:"affinitygroup"` + Cpunumber int `json:"cpunumber"` + Cpuspeed int `json:"cpuspeed"` + Cpuused string `json:"cpuused"` + Created string `json:"created"` + Details map[string]string `json:"details"` + Diskioread int64 `json:"diskioread"` + Diskiowrite int64 `json:"diskiowrite"` + Diskkbsread int64 `json:"diskkbsread"` + Diskkbswrite int64 `json:"diskkbswrite"` + Diskofferingid string `json:"diskofferingid"` + Diskofferingname string `json:"diskofferingname"` + Displayname string `json:"displayname"` + Displayvm bool `json:"displayvm"` + Domain string `json:"domain"` + Domainid string `json:"domainid"` + Forvirtualnetwork bool `json:"forvirtualnetwork"` + Group string `json:"group"` + Groupid string `json:"groupid"` + Guestosid string `json:"guestosid"` + Haenable bool `json:"haenable"` + Hostid string `json:"hostid"` + Hostname string `json:"hostname"` + Hypervisor string `json:"hypervisor"` + Id string `json:"id"` + Instancename string `json:"instancename"` + Isdynamicallyscalable bool `json:"isdynamicallyscalable"` + Isodisplaytext string `json:"isodisplaytext"` + Isoid string `json:"isoid"` + Isoname string `json:"isoname"` + Keypair string `json:"keypair"` + Memory int `json:"memory"` + Memoryintfreekbs int64 `json:"memoryintfreekbs"` + Memorykbs int64 `json:"memorykbs"` + Memorytargetkbs int64 `json:"memorytargetkbs"` + Name string `json:"name"` + Networkkbsread int64 `json:"networkkbsread"` + Networkkbswrite int64 `json:"networkkbswrite"` + Nic []Nic `json:"nic"` + Ostypeid int64 `json:"ostypeid"` + Password string `json:"password"` + Passwordenabled bool `json:"passwordenabled"` + Project string `json:"project"` + Projectid string `json:"projectid"` + Publicip string `json:"publicip"` + Publicipid string `json:"publicipid"` + Rootdeviceid int64 `json:"rootdeviceid"` + Rootdevicetype string `json:"rootdevicetype"` + Securitygroup []RemoveNicFromVirtualMachineResponseSecuritygroup `json:"securitygroup"` + Serviceofferingid string `json:"serviceofferingid"` + Serviceofferingname string `json:"serviceofferingname"` + Servicestate string `json:"servicestate"` + State string `json:"state"` + Templatedisplaytext string `json:"templatedisplaytext"` + Templateid string `json:"templateid"` + Templatename string `json:"templatename"` + Userid string `json:"userid"` + Username string `json:"username"` + Vgpu string `json:"vgpu"` + Zoneid string `json:"zoneid"` + Zonename string `json:"zonename"` +} + +type RemoveNicFromVirtualMachineResponseSecuritygroup struct { + Account string `json:"account"` + Description string `json:"description"` + Domain string `json:"domain"` + Domainid string `json:"domainid"` + Egressrule []RemoveNicFromVirtualMachineResponseSecuritygroupRule `json:"egressrule"` + Id string `json:"id"` + Ingressrule []RemoveNicFromVirtualMachineResponseSecuritygroupRule `json:"ingressrule"` + Name string `json:"name"` + Project string `json:"project"` + Projectid string `json:"projectid"` + Tags []Tags `json:"tags"` + Virtualmachinecount int `json:"virtualmachinecount"` + Virtualmachineids []interface{} `json:"virtualmachineids"` +} + +type RemoveNicFromVirtualMachineResponseSecuritygroupRule struct { + Account string `json:"account"` + Cidr string `json:"cidr"` + Endport int `json:"endport"` + Icmpcode int `json:"icmpcode"` + Icmptype int `json:"icmptype"` + Protocol string `json:"protocol"` + Ruleid string `json:"ruleid"` + Securitygroupname string `json:"securitygroupname"` + Startport int `json:"startport"` + Tags []Tags `json:"tags"` +} + +type RemoveNicFromVirtualMachineResponseAffinitygroup struct { + Account string `json:"account"` + Description string `json:"description"` + Domain string `json:"domain"` + Domainid string `json:"domainid"` + Id string `json:"id"` + Name string `json:"name"` + Project string `json:"project"` + Projectid string `json:"projectid"` + Type string `json:"type"` + VirtualmachineIds []string `json:"virtualmachineIds"` +} + +type ResetPasswordForVirtualMachineParams struct { + p map[string]interface{} +} + +func (p *ResetPasswordForVirtualMachineParams) toURLValues() url.Values { + u := url.Values{} + if p.p == nil { + return u + } + if v, found := p.p["id"]; found { + u.Set("id", v.(string)) + } + return u +} + +func (p *ResetPasswordForVirtualMachineParams) SetId(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["id"] = v + return +} + +// You should always use this function to get a new ResetPasswordForVirtualMachineParams instance, +// as then you are sure you have configured all required params +func (s *VirtualMachineService) NewResetPasswordForVirtualMachineParams(id string) *ResetPasswordForVirtualMachineParams { + p := &ResetPasswordForVirtualMachineParams{} + p.p = make(map[string]interface{}) + p.p["id"] = id + return p +} + +// Resets the password for virtual machine. The virtual machine must be in a "Stopped" state and the template must already support this feature for this command to take effect. [async] +func (s *VirtualMachineService) ResetPasswordForVirtualMachine(p *ResetPasswordForVirtualMachineParams) (*ResetPasswordForVirtualMachineResponse, error) { + resp, err := s.cs.newRequest("resetPasswordForVirtualMachine", p.toURLValues()) + if err != nil { + return nil, err + } + + var r ResetPasswordForVirtualMachineResponse + if err := json.Unmarshal(resp, &r); err != nil { + return nil, err + } + + // If we have a async client, we need to wait for the async result + if s.cs.async { + b, err := s.cs.GetAsyncJobResult(r.JobID, s.cs.timeout) + if err != nil { + if err == AsyncTimeoutErr { + return &r, err + } + return nil, err + } + + b, err = getRawValue(b) + if err != nil { + return nil, err + } + + if err := json.Unmarshal(b, &r); err != nil { + return nil, err + } + } + + return &r, nil +} + +type ResetPasswordForVirtualMachineResponse struct { + JobID string `json:"jobid"` + Account string `json:"account"` + Affinitygroup []ResetPasswordForVirtualMachineResponseAffinitygroup `json:"affinitygroup"` + Cpunumber int `json:"cpunumber"` + Cpuspeed int `json:"cpuspeed"` + Cpuused string `json:"cpuused"` + Created string `json:"created"` + Details map[string]string `json:"details"` + Diskioread int64 `json:"diskioread"` + Diskiowrite int64 `json:"diskiowrite"` + Diskkbsread int64 `json:"diskkbsread"` + Diskkbswrite int64 `json:"diskkbswrite"` + Diskofferingid string `json:"diskofferingid"` + Diskofferingname string `json:"diskofferingname"` + Displayname string `json:"displayname"` + Displayvm bool `json:"displayvm"` + Domain string `json:"domain"` + Domainid string `json:"domainid"` + Forvirtualnetwork bool `json:"forvirtualnetwork"` + Group string `json:"group"` + Groupid string `json:"groupid"` + Guestosid string `json:"guestosid"` + Haenable bool `json:"haenable"` + Hostid string `json:"hostid"` + Hostname string `json:"hostname"` + Hypervisor string `json:"hypervisor"` + Id string `json:"id"` + Instancename string `json:"instancename"` + Isdynamicallyscalable bool `json:"isdynamicallyscalable"` + Isodisplaytext string `json:"isodisplaytext"` + Isoid string `json:"isoid"` + Isoname string `json:"isoname"` + Keypair string `json:"keypair"` + Memory int `json:"memory"` + Memoryintfreekbs int64 `json:"memoryintfreekbs"` + Memorykbs int64 `json:"memorykbs"` + Memorytargetkbs int64 `json:"memorytargetkbs"` + Name string `json:"name"` + Networkkbsread int64 `json:"networkkbsread"` + Networkkbswrite int64 `json:"networkkbswrite"` + Nic []Nic `json:"nic"` + Ostypeid int64 `json:"ostypeid"` + Password string `json:"password"` + Passwordenabled bool `json:"passwordenabled"` + Project string `json:"project"` + Projectid string `json:"projectid"` + Publicip string `json:"publicip"` + Publicipid string `json:"publicipid"` + Rootdeviceid int64 `json:"rootdeviceid"` + Rootdevicetype string `json:"rootdevicetype"` + Securitygroup []ResetPasswordForVirtualMachineResponseSecuritygroup `json:"securitygroup"` + Serviceofferingid string `json:"serviceofferingid"` + Serviceofferingname string `json:"serviceofferingname"` + Servicestate string `json:"servicestate"` + State string `json:"state"` + Templatedisplaytext string `json:"templatedisplaytext"` + Templateid string `json:"templateid"` + Templatename string `json:"templatename"` + Userid string `json:"userid"` + Username string `json:"username"` + Vgpu string `json:"vgpu"` + Zoneid string `json:"zoneid"` + Zonename string `json:"zonename"` +} + +type ResetPasswordForVirtualMachineResponseSecuritygroup struct { + Account string `json:"account"` + Description string `json:"description"` + Domain string `json:"domain"` + Domainid string `json:"domainid"` + Egressrule []ResetPasswordForVirtualMachineResponseSecuritygroupRule `json:"egressrule"` + Id string `json:"id"` + Ingressrule []ResetPasswordForVirtualMachineResponseSecuritygroupRule `json:"ingressrule"` + Name string `json:"name"` + Project string `json:"project"` + Projectid string `json:"projectid"` + Tags []Tags `json:"tags"` + Virtualmachinecount int `json:"virtualmachinecount"` + Virtualmachineids []interface{} `json:"virtualmachineids"` +} + +type ResetPasswordForVirtualMachineResponseSecuritygroupRule struct { + Account string `json:"account"` + Cidr string `json:"cidr"` + Endport int `json:"endport"` + Icmpcode int `json:"icmpcode"` + Icmptype int `json:"icmptype"` + Protocol string `json:"protocol"` + Ruleid string `json:"ruleid"` + Securitygroupname string `json:"securitygroupname"` + Startport int `json:"startport"` + Tags []Tags `json:"tags"` +} + +type ResetPasswordForVirtualMachineResponseAffinitygroup struct { + Account string `json:"account"` + Description string `json:"description"` + Domain string `json:"domain"` + Domainid string `json:"domainid"` + Id string `json:"id"` + Name string `json:"name"` + Project string `json:"project"` + Projectid string `json:"projectid"` + Type string `json:"type"` + VirtualmachineIds []string `json:"virtualmachineIds"` +} + +type RestoreVirtualMachineParams struct { + p map[string]interface{} +} + +func (p *RestoreVirtualMachineParams) toURLValues() url.Values { + u := url.Values{} + if p.p == nil { + return u + } + if v, found := p.p["templateid"]; found { + u.Set("templateid", v.(string)) + } + if v, found := p.p["virtualmachineid"]; found { + u.Set("virtualmachineid", v.(string)) + } + return u +} + +func (p *RestoreVirtualMachineParams) SetTemplateid(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["templateid"] = v + return +} + +func (p *RestoreVirtualMachineParams) SetVirtualmachineid(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["virtualmachineid"] = v + return +} + +// You should always use this function to get a new RestoreVirtualMachineParams instance, +// as then you are sure you have configured all required params +func (s *VirtualMachineService) NewRestoreVirtualMachineParams(virtualmachineid string) *RestoreVirtualMachineParams { + p := &RestoreVirtualMachineParams{} + p.p = make(map[string]interface{}) + p.p["virtualmachineid"] = virtualmachineid + return p +} + +// Restore a VM to original template/ISO or new template/ISO +func (s *VirtualMachineService) RestoreVirtualMachine(p *RestoreVirtualMachineParams) (*RestoreVirtualMachineResponse, error) { + resp, err := s.cs.newRequest("restoreVirtualMachine", p.toURLValues()) + if err != nil { + return nil, err + } + + var r RestoreVirtualMachineResponse + if err := json.Unmarshal(resp, &r); err != nil { + return nil, err + } + + // If we have a async client, we need to wait for the async result + if s.cs.async { + b, err := s.cs.GetAsyncJobResult(r.JobID, s.cs.timeout) + if err != nil { + if err == AsyncTimeoutErr { + return &r, err + } + return nil, err + } + + b, err = getRawValue(b) + if err != nil { + return nil, err + } + + if err := json.Unmarshal(b, &r); err != nil { + return nil, err + } + } + + return &r, nil +} + +type RestoreVirtualMachineResponse struct { + JobID string `json:"jobid"` + Account string `json:"account"` + Affinitygroup []RestoreVirtualMachineResponseAffinitygroup `json:"affinitygroup"` + Cpunumber int `json:"cpunumber"` + Cpuspeed int `json:"cpuspeed"` + Cpuused string `json:"cpuused"` + Created string `json:"created"` + Details map[string]string `json:"details"` + Diskioread int64 `json:"diskioread"` + Diskiowrite int64 `json:"diskiowrite"` + Diskkbsread int64 `json:"diskkbsread"` + Diskkbswrite int64 `json:"diskkbswrite"` + Diskofferingid string `json:"diskofferingid"` + Diskofferingname string `json:"diskofferingname"` + Displayname string `json:"displayname"` + Displayvm bool `json:"displayvm"` + Domain string `json:"domain"` + Domainid string `json:"domainid"` + Forvirtualnetwork bool `json:"forvirtualnetwork"` + Group string `json:"group"` + Groupid string `json:"groupid"` + Guestosid string `json:"guestosid"` + Haenable bool `json:"haenable"` + Hostid string `json:"hostid"` + Hostname string `json:"hostname"` + Hypervisor string `json:"hypervisor"` + Id string `json:"id"` + Instancename string `json:"instancename"` + Isdynamicallyscalable bool `json:"isdynamicallyscalable"` + Isodisplaytext string `json:"isodisplaytext"` + Isoid string `json:"isoid"` + Isoname string `json:"isoname"` + Keypair string `json:"keypair"` + Memory int `json:"memory"` + Memoryintfreekbs int64 `json:"memoryintfreekbs"` + Memorykbs int64 `json:"memorykbs"` + Memorytargetkbs int64 `json:"memorytargetkbs"` + Name string `json:"name"` + Networkkbsread int64 `json:"networkkbsread"` + Networkkbswrite int64 `json:"networkkbswrite"` + Nic []Nic `json:"nic"` + Ostypeid int64 `json:"ostypeid"` + Password string `json:"password"` + Passwordenabled bool `json:"passwordenabled"` + Project string `json:"project"` + Projectid string `json:"projectid"` + Publicip string `json:"publicip"` + Publicipid string `json:"publicipid"` + Rootdeviceid int64 `json:"rootdeviceid"` + Rootdevicetype string `json:"rootdevicetype"` + Securitygroup []RestoreVirtualMachineResponseSecuritygroup `json:"securitygroup"` + Serviceofferingid string `json:"serviceofferingid"` + Serviceofferingname string `json:"serviceofferingname"` + Servicestate string `json:"servicestate"` + State string `json:"state"` + Templatedisplaytext string `json:"templatedisplaytext"` + Templateid string `json:"templateid"` + Templatename string `json:"templatename"` + Userid string `json:"userid"` + Username string `json:"username"` + Vgpu string `json:"vgpu"` + Zoneid string `json:"zoneid"` + Zonename string `json:"zonename"` +} + +type RestoreVirtualMachineResponseSecuritygroup struct { + Account string `json:"account"` + Description string `json:"description"` + Domain string `json:"domain"` + Domainid string `json:"domainid"` + Egressrule []RestoreVirtualMachineResponseSecuritygroupRule `json:"egressrule"` + Id string `json:"id"` + Ingressrule []RestoreVirtualMachineResponseSecuritygroupRule `json:"ingressrule"` + Name string `json:"name"` + Project string `json:"project"` + Projectid string `json:"projectid"` + Tags []Tags `json:"tags"` + Virtualmachinecount int `json:"virtualmachinecount"` + Virtualmachineids []interface{} `json:"virtualmachineids"` +} + +type RestoreVirtualMachineResponseSecuritygroupRule struct { + Account string `json:"account"` + Cidr string `json:"cidr"` + Endport int `json:"endport"` + Icmpcode int `json:"icmpcode"` + Icmptype int `json:"icmptype"` + Protocol string `json:"protocol"` + Ruleid string `json:"ruleid"` + Securitygroupname string `json:"securitygroupname"` + Startport int `json:"startport"` + Tags []Tags `json:"tags"` +} + +type RestoreVirtualMachineResponseAffinitygroup struct { + Account string `json:"account"` + Description string `json:"description"` + Domain string `json:"domain"` + Domainid string `json:"domainid"` + Id string `json:"id"` + Name string `json:"name"` + Project string `json:"project"` + Projectid string `json:"projectid"` + Type string `json:"type"` + VirtualmachineIds []string `json:"virtualmachineIds"` +} + +type ScaleVirtualMachineParams struct { + p map[string]interface{} +} + +func (p *ScaleVirtualMachineParams) toURLValues() url.Values { + u := url.Values{} + if p.p == nil { + return u + } + if v, found := p.p["details"]; found { + i := 0 + for k, vv := range v.(map[string]string) { + u.Set(fmt.Sprintf("details[%d].%s", i, k), vv) + i++ + } + } + if v, found := p.p["id"]; found { + u.Set("id", v.(string)) + } + if v, found := p.p["serviceofferingid"]; found { + u.Set("serviceofferingid", v.(string)) + } + return u +} + +func (p *ScaleVirtualMachineParams) SetDetails(v map[string]string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["details"] = v + return +} + +func (p *ScaleVirtualMachineParams) SetId(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["id"] = v + return +} + +func (p *ScaleVirtualMachineParams) SetServiceofferingid(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["serviceofferingid"] = v + return +} + +// You should always use this function to get a new ScaleVirtualMachineParams instance, +// as then you are sure you have configured all required params +func (s *VirtualMachineService) NewScaleVirtualMachineParams(id string, serviceofferingid string) *ScaleVirtualMachineParams { + p := &ScaleVirtualMachineParams{} + p.p = make(map[string]interface{}) + p.p["id"] = id + p.p["serviceofferingid"] = serviceofferingid + return p +} + +// Scales the virtual machine to a new service offering. +func (s *VirtualMachineService) ScaleVirtualMachine(p *ScaleVirtualMachineParams) (*ScaleVirtualMachineResponse, error) { + resp, err := s.cs.newRequest("scaleVirtualMachine", p.toURLValues()) + if err != nil { + return nil, err + } + + var r ScaleVirtualMachineResponse + if err := json.Unmarshal(resp, &r); err != nil { + return nil, err + } + + // If we have a async client, we need to wait for the async result + if s.cs.async { + b, err := s.cs.GetAsyncJobResult(r.JobID, s.cs.timeout) + if err != nil { + if err == AsyncTimeoutErr { + return &r, err + } + return nil, err + } + + if err := json.Unmarshal(b, &r); err != nil { + return nil, err + } + } + + return &r, nil +} + +type ScaleVirtualMachineResponse struct { + JobID string `json:"jobid"` + Displaytext string `json:"displaytext"` + Success bool `json:"success"` +} + +type StartVirtualMachineParams struct { + p map[string]interface{} +} + +func (p *StartVirtualMachineParams) toURLValues() url.Values { + u := url.Values{} + if p.p == nil { + return u + } + if v, found := p.p["deploymentplanner"]; found { + u.Set("deploymentplanner", v.(string)) + } + if v, found := p.p["hostid"]; found { + u.Set("hostid", v.(string)) + } + if v, found := p.p["id"]; found { + u.Set("id", v.(string)) + } + return u +} + +func (p *StartVirtualMachineParams) SetDeploymentplanner(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["deploymentplanner"] = v + return +} + +func (p *StartVirtualMachineParams) SetHostid(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["hostid"] = v + return +} + +func (p *StartVirtualMachineParams) SetId(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["id"] = v + return +} + +// You should always use this function to get a new StartVirtualMachineParams instance, +// as then you are sure you have configured all required params +func (s *VirtualMachineService) NewStartVirtualMachineParams(id string) *StartVirtualMachineParams { + p := &StartVirtualMachineParams{} + p.p = make(map[string]interface{}) + p.p["id"] = id + return p +} + +// Starts a virtual machine. +func (s *VirtualMachineService) StartVirtualMachine(p *StartVirtualMachineParams) (*StartVirtualMachineResponse, error) { + resp, err := s.cs.newRequest("startVirtualMachine", p.toURLValues()) + if err != nil { + return nil, err + } + + var r StartVirtualMachineResponse + if err := json.Unmarshal(resp, &r); err != nil { + return nil, err + } + + // If we have a async client, we need to wait for the async result + if s.cs.async { + b, err := s.cs.GetAsyncJobResult(r.JobID, s.cs.timeout) + if err != nil { + if err == AsyncTimeoutErr { + return &r, err + } + return nil, err + } + + b, err = getRawValue(b) + if err != nil { + return nil, err + } + + if err := json.Unmarshal(b, &r); err != nil { + return nil, err + } + } + + return &r, nil +} + +type StartVirtualMachineResponse struct { + JobID string `json:"jobid"` + Account string `json:"account"` + Affinitygroup []StartVirtualMachineResponseAffinitygroup `json:"affinitygroup"` + Cpunumber int `json:"cpunumber"` + Cpuspeed int `json:"cpuspeed"` + Cpuused string `json:"cpuused"` + Created string `json:"created"` + Details map[string]string `json:"details"` + Diskioread int64 `json:"diskioread"` + Diskiowrite int64 `json:"diskiowrite"` + Diskkbsread int64 `json:"diskkbsread"` + Diskkbswrite int64 `json:"diskkbswrite"` + Diskofferingid string `json:"diskofferingid"` + Diskofferingname string `json:"diskofferingname"` + Displayname string `json:"displayname"` + Displayvm bool `json:"displayvm"` + Domain string `json:"domain"` + Domainid string `json:"domainid"` + Forvirtualnetwork bool `json:"forvirtualnetwork"` + Group string `json:"group"` + Groupid string `json:"groupid"` + Guestosid string `json:"guestosid"` + Haenable bool `json:"haenable"` + Hostid string `json:"hostid"` + Hostname string `json:"hostname"` + Hypervisor string `json:"hypervisor"` + Id string `json:"id"` + Instancename string `json:"instancename"` + Isdynamicallyscalable bool `json:"isdynamicallyscalable"` + Isodisplaytext string `json:"isodisplaytext"` + Isoid string `json:"isoid"` + Isoname string `json:"isoname"` + Keypair string `json:"keypair"` + Memory int `json:"memory"` + Memoryintfreekbs int64 `json:"memoryintfreekbs"` + Memorykbs int64 `json:"memorykbs"` + Memorytargetkbs int64 `json:"memorytargetkbs"` + Name string `json:"name"` + Networkkbsread int64 `json:"networkkbsread"` + Networkkbswrite int64 `json:"networkkbswrite"` + Nic []Nic `json:"nic"` + Ostypeid int64 `json:"ostypeid"` + Password string `json:"password"` + Passwordenabled bool `json:"passwordenabled"` + Project string `json:"project"` + Projectid string `json:"projectid"` + Publicip string `json:"publicip"` + Publicipid string `json:"publicipid"` + Rootdeviceid int64 `json:"rootdeviceid"` + Rootdevicetype string `json:"rootdevicetype"` + Securitygroup []StartVirtualMachineResponseSecuritygroup `json:"securitygroup"` + Serviceofferingid string `json:"serviceofferingid"` + Serviceofferingname string `json:"serviceofferingname"` + Servicestate string `json:"servicestate"` + State string `json:"state"` + Templatedisplaytext string `json:"templatedisplaytext"` + Templateid string `json:"templateid"` + Templatename string `json:"templatename"` + Userid string `json:"userid"` + Username string `json:"username"` + Vgpu string `json:"vgpu"` + Zoneid string `json:"zoneid"` + Zonename string `json:"zonename"` +} + +type StartVirtualMachineResponseSecuritygroup struct { + Account string `json:"account"` + Description string `json:"description"` + Domain string `json:"domain"` + Domainid string `json:"domainid"` + Egressrule []StartVirtualMachineResponseSecuritygroupRule `json:"egressrule"` + Id string `json:"id"` + Ingressrule []StartVirtualMachineResponseSecuritygroupRule `json:"ingressrule"` + Name string `json:"name"` + Project string `json:"project"` + Projectid string `json:"projectid"` + Tags []Tags `json:"tags"` + Virtualmachinecount int `json:"virtualmachinecount"` + Virtualmachineids []interface{} `json:"virtualmachineids"` +} + +type StartVirtualMachineResponseSecuritygroupRule struct { + Account string `json:"account"` + Cidr string `json:"cidr"` + Endport int `json:"endport"` + Icmpcode int `json:"icmpcode"` + Icmptype int `json:"icmptype"` + Protocol string `json:"protocol"` + Ruleid string `json:"ruleid"` + Securitygroupname string `json:"securitygroupname"` + Startport int `json:"startport"` + Tags []Tags `json:"tags"` +} + +type StartVirtualMachineResponseAffinitygroup struct { + Account string `json:"account"` + Description string `json:"description"` + Domain string `json:"domain"` + Domainid string `json:"domainid"` + Id string `json:"id"` + Name string `json:"name"` + Project string `json:"project"` + Projectid string `json:"projectid"` + Type string `json:"type"` + VirtualmachineIds []string `json:"virtualmachineIds"` +} + +type StopVirtualMachineParams struct { + p map[string]interface{} +} + +func (p *StopVirtualMachineParams) toURLValues() url.Values { + u := url.Values{} + if p.p == nil { + return u + } + if v, found := p.p["forced"]; found { + vv := strconv.FormatBool(v.(bool)) + u.Set("forced", vv) + } + if v, found := p.p["id"]; found { + u.Set("id", v.(string)) + } + return u +} + +func (p *StopVirtualMachineParams) SetForced(v bool) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["forced"] = v + return +} + +func (p *StopVirtualMachineParams) SetId(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["id"] = v + return +} + +// You should always use this function to get a new StopVirtualMachineParams instance, +// as then you are sure you have configured all required params +func (s *VirtualMachineService) NewStopVirtualMachineParams(id string) *StopVirtualMachineParams { + p := &StopVirtualMachineParams{} + p.p = make(map[string]interface{}) + p.p["id"] = id + return p +} + +// Stops a virtual machine. +func (s *VirtualMachineService) StopVirtualMachine(p *StopVirtualMachineParams) (*StopVirtualMachineResponse, error) { + resp, err := s.cs.newRequest("stopVirtualMachine", p.toURLValues()) + if err != nil { + return nil, err + } + + var r StopVirtualMachineResponse + if err := json.Unmarshal(resp, &r); err != nil { + return nil, err + } + + // If we have a async client, we need to wait for the async result + if s.cs.async { + b, err := s.cs.GetAsyncJobResult(r.JobID, s.cs.timeout) + if err != nil { + if err == AsyncTimeoutErr { + return &r, err + } + return nil, err + } + + b, err = getRawValue(b) + if err != nil { + return nil, err + } + + if err := json.Unmarshal(b, &r); err != nil { + return nil, err + } + } + + return &r, nil +} + +type StopVirtualMachineResponse struct { + JobID string `json:"jobid"` + Account string `json:"account"` + Affinitygroup []StopVirtualMachineResponseAffinitygroup `json:"affinitygroup"` + Cpunumber int `json:"cpunumber"` + Cpuspeed int `json:"cpuspeed"` + Cpuused string `json:"cpuused"` + Created string `json:"created"` + Details map[string]string `json:"details"` + Diskioread int64 `json:"diskioread"` + Diskiowrite int64 `json:"diskiowrite"` + Diskkbsread int64 `json:"diskkbsread"` + Diskkbswrite int64 `json:"diskkbswrite"` + Diskofferingid string `json:"diskofferingid"` + Diskofferingname string `json:"diskofferingname"` + Displayname string `json:"displayname"` + Displayvm bool `json:"displayvm"` + Domain string `json:"domain"` + Domainid string `json:"domainid"` + Forvirtualnetwork bool `json:"forvirtualnetwork"` + Group string `json:"group"` + Groupid string `json:"groupid"` + Guestosid string `json:"guestosid"` + Haenable bool `json:"haenable"` + Hostid string `json:"hostid"` + Hostname string `json:"hostname"` + Hypervisor string `json:"hypervisor"` + Id string `json:"id"` + Instancename string `json:"instancename"` + Isdynamicallyscalable bool `json:"isdynamicallyscalable"` + Isodisplaytext string `json:"isodisplaytext"` + Isoid string `json:"isoid"` + Isoname string `json:"isoname"` + Keypair string `json:"keypair"` + Memory int `json:"memory"` + Memoryintfreekbs int64 `json:"memoryintfreekbs"` + Memorykbs int64 `json:"memorykbs"` + Memorytargetkbs int64 `json:"memorytargetkbs"` + Name string `json:"name"` + Networkkbsread int64 `json:"networkkbsread"` + Networkkbswrite int64 `json:"networkkbswrite"` + Nic []Nic `json:"nic"` + Ostypeid int64 `json:"ostypeid"` + Password string `json:"password"` + Passwordenabled bool `json:"passwordenabled"` + Project string `json:"project"` + Projectid string `json:"projectid"` + Publicip string `json:"publicip"` + Publicipid string `json:"publicipid"` + Rootdeviceid int64 `json:"rootdeviceid"` + Rootdevicetype string `json:"rootdevicetype"` + Securitygroup []StopVirtualMachineResponseSecuritygroup `json:"securitygroup"` + Serviceofferingid string `json:"serviceofferingid"` + Serviceofferingname string `json:"serviceofferingname"` + Servicestate string `json:"servicestate"` + State string `json:"state"` + Templatedisplaytext string `json:"templatedisplaytext"` + Templateid string `json:"templateid"` + Templatename string `json:"templatename"` + Userid string `json:"userid"` + Username string `json:"username"` + Vgpu string `json:"vgpu"` + Zoneid string `json:"zoneid"` + Zonename string `json:"zonename"` +} + +type StopVirtualMachineResponseSecuritygroup struct { + Account string `json:"account"` + Description string `json:"description"` + Domain string `json:"domain"` + Domainid string `json:"domainid"` + Egressrule []StopVirtualMachineResponseSecuritygroupRule `json:"egressrule"` + Id string `json:"id"` + Ingressrule []StopVirtualMachineResponseSecuritygroupRule `json:"ingressrule"` + Name string `json:"name"` + Project string `json:"project"` + Projectid string `json:"projectid"` + Tags []Tags `json:"tags"` + Virtualmachinecount int `json:"virtualmachinecount"` + Virtualmachineids []interface{} `json:"virtualmachineids"` +} + +type StopVirtualMachineResponseSecuritygroupRule struct { + Account string `json:"account"` + Cidr string `json:"cidr"` + Endport int `json:"endport"` + Icmpcode int `json:"icmpcode"` + Icmptype int `json:"icmptype"` + Protocol string `json:"protocol"` + Ruleid string `json:"ruleid"` + Securitygroupname string `json:"securitygroupname"` + Startport int `json:"startport"` + Tags []Tags `json:"tags"` +} + +type StopVirtualMachineResponseAffinitygroup struct { + Account string `json:"account"` + Description string `json:"description"` + Domain string `json:"domain"` + Domainid string `json:"domainid"` + Id string `json:"id"` + Name string `json:"name"` + Project string `json:"project"` + Projectid string `json:"projectid"` + Type string `json:"type"` + VirtualmachineIds []string `json:"virtualmachineIds"` } type UpdateDefaultNicForVirtualMachineParams struct { @@ -5264,182 +3964,448 @@ func (s *VirtualMachineService) UpdateDefaultNicForVirtualMachine(p *UpdateDefau return nil, err } } + return &r, nil } type UpdateDefaultNicForVirtualMachineResponse struct { - JobID string `json:"jobid,omitempty"` - Account string `json:"account,omitempty"` - Affinitygroup []struct { - Account string `json:"account,omitempty"` - Description string `json:"description,omitempty"` - Domain string `json:"domain,omitempty"` - Domainid string `json:"domainid,omitempty"` - Id string `json:"id,omitempty"` - Name string `json:"name,omitempty"` - Project string `json:"project,omitempty"` - Projectid string `json:"projectid,omitempty"` - Type string `json:"type,omitempty"` - VirtualmachineIds []string `json:"virtualmachineIds,omitempty"` - } `json:"affinitygroup,omitempty"` - Cpunumber int `json:"cpunumber,omitempty"` - Cpuspeed int `json:"cpuspeed,omitempty"` - Cpuused string `json:"cpuused,omitempty"` - Created string `json:"created,omitempty"` - Details map[string]string `json:"details,omitempty"` - Diskioread int64 `json:"diskioread,omitempty"` - Diskiowrite int64 `json:"diskiowrite,omitempty"` - Diskkbsread int64 `json:"diskkbsread,omitempty"` - Diskkbswrite int64 `json:"diskkbswrite,omitempty"` - Diskofferingid string `json:"diskofferingid,omitempty"` - Diskofferingname string `json:"diskofferingname,omitempty"` - Displayname string `json:"displayname,omitempty"` - Displayvm bool `json:"displayvm,omitempty"` - Domain string `json:"domain,omitempty"` - Domainid string `json:"domainid,omitempty"` - Forvirtualnetwork bool `json:"forvirtualnetwork,omitempty"` - Group string `json:"group,omitempty"` - Groupid string `json:"groupid,omitempty"` - Guestosid string `json:"guestosid,omitempty"` - Haenable bool `json:"haenable,omitempty"` - Hostid string `json:"hostid,omitempty"` - Hostname string `json:"hostname,omitempty"` - Hypervisor string `json:"hypervisor,omitempty"` - Id string `json:"id,omitempty"` - Instancename string `json:"instancename,omitempty"` - Isdynamicallyscalable bool `json:"isdynamicallyscalable,omitempty"` - Isodisplaytext string `json:"isodisplaytext,omitempty"` - Isoid string `json:"isoid,omitempty"` - Isoname string `json:"isoname,omitempty"` - Keypair string `json:"keypair,omitempty"` - Memory int `json:"memory,omitempty"` - Name string `json:"name,omitempty"` - Networkkbsread int64 `json:"networkkbsread,omitempty"` - Networkkbswrite int64 `json:"networkkbswrite,omitempty"` - Nic []struct { - Broadcasturi string `json:"broadcasturi,omitempty"` - Deviceid string `json:"deviceid,omitempty"` - Gateway string `json:"gateway,omitempty"` - Id string `json:"id,omitempty"` - Ip6address string `json:"ip6address,omitempty"` - Ip6cidr string `json:"ip6cidr,omitempty"` - Ip6gateway string `json:"ip6gateway,omitempty"` - Ipaddress string `json:"ipaddress,omitempty"` - Isdefault bool `json:"isdefault,omitempty"` - Isolationuri string `json:"isolationuri,omitempty"` - Macaddress string `json:"macaddress,omitempty"` - Netmask string `json:"netmask,omitempty"` - Networkid string `json:"networkid,omitempty"` - Networkname string `json:"networkname,omitempty"` - Secondaryip []struct { - Id string `json:"id,omitempty"` - Ipaddress string `json:"ipaddress,omitempty"` - } `json:"secondaryip,omitempty"` - Traffictype string `json:"traffictype,omitempty"` - Type string `json:"type,omitempty"` - Virtualmachineid string `json:"virtualmachineid,omitempty"` - } `json:"nic,omitempty"` - Ostypeid int64 `json:"ostypeid,omitempty"` - Password string `json:"password,omitempty"` - Passwordenabled bool `json:"passwordenabled,omitempty"` - Project string `json:"project,omitempty"` - Projectid string `json:"projectid,omitempty"` - Publicip string `json:"publicip,omitempty"` - Publicipid string `json:"publicipid,omitempty"` - Rootdeviceid int64 `json:"rootdeviceid,omitempty"` - Rootdevicetype string `json:"rootdevicetype,omitempty"` - Securitygroup []struct { - Account string `json:"account,omitempty"` - Description string `json:"description,omitempty"` - Domain string `json:"domain,omitempty"` - Domainid string `json:"domainid,omitempty"` - Egressrule []struct { - Account string `json:"account,omitempty"` - Cidr string `json:"cidr,omitempty"` - Endport int `json:"endport,omitempty"` - Icmpcode int `json:"icmpcode,omitempty"` - Icmptype int `json:"icmptype,omitempty"` - Protocol string `json:"protocol,omitempty"` - Ruleid string `json:"ruleid,omitempty"` - Securitygroupname string `json:"securitygroupname,omitempty"` - Startport int `json:"startport,omitempty"` - Tags []struct { - Account string `json:"account,omitempty"` - Customer string `json:"customer,omitempty"` - Domain string `json:"domain,omitempty"` - Domainid string `json:"domainid,omitempty"` - Key string `json:"key,omitempty"` - Project string `json:"project,omitempty"` - Projectid string `json:"projectid,omitempty"` - Resourceid string `json:"resourceid,omitempty"` - Resourcetype string `json:"resourcetype,omitempty"` - Value string `json:"value,omitempty"` - } `json:"tags,omitempty"` - } `json:"egressrule,omitempty"` - Id string `json:"id,omitempty"` - Ingressrule []struct { - Account string `json:"account,omitempty"` - Cidr string `json:"cidr,omitempty"` - Endport int `json:"endport,omitempty"` - Icmpcode int `json:"icmpcode,omitempty"` - Icmptype int `json:"icmptype,omitempty"` - Protocol string `json:"protocol,omitempty"` - Ruleid string `json:"ruleid,omitempty"` - Securitygroupname string `json:"securitygroupname,omitempty"` - Startport int `json:"startport,omitempty"` - Tags []struct { - Account string `json:"account,omitempty"` - Customer string `json:"customer,omitempty"` - Domain string `json:"domain,omitempty"` - Domainid string `json:"domainid,omitempty"` - Key string `json:"key,omitempty"` - Project string `json:"project,omitempty"` - Projectid string `json:"projectid,omitempty"` - Resourceid string `json:"resourceid,omitempty"` - Resourcetype string `json:"resourcetype,omitempty"` - Value string `json:"value,omitempty"` - } `json:"tags,omitempty"` - } `json:"ingressrule,omitempty"` - Name string `json:"name,omitempty"` - Project string `json:"project,omitempty"` - Projectid string `json:"projectid,omitempty"` - Tags []struct { - Account string `json:"account,omitempty"` - Customer string `json:"customer,omitempty"` - Domain string `json:"domain,omitempty"` - Domainid string `json:"domainid,omitempty"` - Key string `json:"key,omitempty"` - Project string `json:"project,omitempty"` - Projectid string `json:"projectid,omitempty"` - Resourceid string `json:"resourceid,omitempty"` - Resourcetype string `json:"resourcetype,omitempty"` - Value string `json:"value,omitempty"` - } `json:"tags,omitempty"` - Virtualmachinecount int `json:"virtualmachinecount,omitempty"` - Virtualmachineids []string `json:"virtualmachineids,omitempty"` - } `json:"securitygroup,omitempty"` - Serviceofferingid string `json:"serviceofferingid,omitempty"` - Serviceofferingname string `json:"serviceofferingname,omitempty"` - Servicestate string `json:"servicestate,omitempty"` - State string `json:"state,omitempty"` - Tags []struct { - Account string `json:"account,omitempty"` - Customer string `json:"customer,omitempty"` - Domain string `json:"domain,omitempty"` - Domainid string `json:"domainid,omitempty"` - Key string `json:"key,omitempty"` - Project string `json:"project,omitempty"` - Projectid string `json:"projectid,omitempty"` - Resourceid string `json:"resourceid,omitempty"` - Resourcetype string `json:"resourcetype,omitempty"` - Value string `json:"value,omitempty"` - } `json:"tags,omitempty"` - Templatedisplaytext string `json:"templatedisplaytext,omitempty"` - Templateid string `json:"templateid,omitempty"` - Templatename string `json:"templatename,omitempty"` - Userid string `json:"userid,omitempty"` - Username string `json:"username,omitempty"` - Vgpu string `json:"vgpu,omitempty"` - Zoneid string `json:"zoneid,omitempty"` - Zonename string `json:"zonename,omitempty"` + JobID string `json:"jobid"` + Account string `json:"account"` + Affinitygroup []UpdateDefaultNicForVirtualMachineResponseAffinitygroup `json:"affinitygroup"` + Cpunumber int `json:"cpunumber"` + Cpuspeed int `json:"cpuspeed"` + Cpuused string `json:"cpuused"` + Created string `json:"created"` + Details map[string]string `json:"details"` + Diskioread int64 `json:"diskioread"` + Diskiowrite int64 `json:"diskiowrite"` + Diskkbsread int64 `json:"diskkbsread"` + Diskkbswrite int64 `json:"diskkbswrite"` + Diskofferingid string `json:"diskofferingid"` + Diskofferingname string `json:"diskofferingname"` + Displayname string `json:"displayname"` + Displayvm bool `json:"displayvm"` + Domain string `json:"domain"` + Domainid string `json:"domainid"` + Forvirtualnetwork bool `json:"forvirtualnetwork"` + Group string `json:"group"` + Groupid string `json:"groupid"` + Guestosid string `json:"guestosid"` + Haenable bool `json:"haenable"` + Hostid string `json:"hostid"` + Hostname string `json:"hostname"` + Hypervisor string `json:"hypervisor"` + Id string `json:"id"` + Instancename string `json:"instancename"` + Isdynamicallyscalable bool `json:"isdynamicallyscalable"` + Isodisplaytext string `json:"isodisplaytext"` + Isoid string `json:"isoid"` + Isoname string `json:"isoname"` + Keypair string `json:"keypair"` + Memory int `json:"memory"` + Memoryintfreekbs int64 `json:"memoryintfreekbs"` + Memorykbs int64 `json:"memorykbs"` + Memorytargetkbs int64 `json:"memorytargetkbs"` + Name string `json:"name"` + Networkkbsread int64 `json:"networkkbsread"` + Networkkbswrite int64 `json:"networkkbswrite"` + Nic []Nic `json:"nic"` + Ostypeid int64 `json:"ostypeid"` + Password string `json:"password"` + Passwordenabled bool `json:"passwordenabled"` + Project string `json:"project"` + Projectid string `json:"projectid"` + Publicip string `json:"publicip"` + Publicipid string `json:"publicipid"` + Rootdeviceid int64 `json:"rootdeviceid"` + Rootdevicetype string `json:"rootdevicetype"` + Securitygroup []UpdateDefaultNicForVirtualMachineResponseSecuritygroup `json:"securitygroup"` + Serviceofferingid string `json:"serviceofferingid"` + Serviceofferingname string `json:"serviceofferingname"` + Servicestate string `json:"servicestate"` + State string `json:"state"` + Templatedisplaytext string `json:"templatedisplaytext"` + Templateid string `json:"templateid"` + Templatename string `json:"templatename"` + Userid string `json:"userid"` + Username string `json:"username"` + Vgpu string `json:"vgpu"` + Zoneid string `json:"zoneid"` + Zonename string `json:"zonename"` +} + +type UpdateDefaultNicForVirtualMachineResponseSecuritygroup struct { + Account string `json:"account"` + Description string `json:"description"` + Domain string `json:"domain"` + Domainid string `json:"domainid"` + Egressrule []UpdateDefaultNicForVirtualMachineResponseSecuritygroupRule `json:"egressrule"` + Id string `json:"id"` + Ingressrule []UpdateDefaultNicForVirtualMachineResponseSecuritygroupRule `json:"ingressrule"` + Name string `json:"name"` + Project string `json:"project"` + Projectid string `json:"projectid"` + Tags []Tags `json:"tags"` + Virtualmachinecount int `json:"virtualmachinecount"` + Virtualmachineids []interface{} `json:"virtualmachineids"` +} + +type UpdateDefaultNicForVirtualMachineResponseSecuritygroupRule struct { + Account string `json:"account"` + Cidr string `json:"cidr"` + Endport int `json:"endport"` + Icmpcode int `json:"icmpcode"` + Icmptype int `json:"icmptype"` + Protocol string `json:"protocol"` + Ruleid string `json:"ruleid"` + Securitygroupname string `json:"securitygroupname"` + Startport int `json:"startport"` + Tags []Tags `json:"tags"` +} + +type UpdateDefaultNicForVirtualMachineResponseAffinitygroup struct { + Account string `json:"account"` + Description string `json:"description"` + Domain string `json:"domain"` + Domainid string `json:"domainid"` + Id string `json:"id"` + Name string `json:"name"` + Project string `json:"project"` + Projectid string `json:"projectid"` + Type string `json:"type"` + VirtualmachineIds []string `json:"virtualmachineIds"` +} + +type UpdateVirtualMachineParams struct { + p map[string]interface{} +} + +func (p *UpdateVirtualMachineParams) toURLValues() url.Values { + u := url.Values{} + if p.p == nil { + return u + } + if v, found := p.p["cleanupdetails"]; found { + vv := strconv.FormatBool(v.(bool)) + u.Set("cleanupdetails", vv) + } + if v, found := p.p["customid"]; found { + u.Set("customid", v.(string)) + } + if v, found := p.p["details"]; found { + i := 0 + for k, vv := range v.(map[string]string) { + u.Set(fmt.Sprintf("details[%d].%s", i, k), vv) + i++ + } + } + if v, found := p.p["dhcpoptionsnetworklist"]; found { + i := 0 + for k, vv := range v.(map[string]string) { + u.Set(fmt.Sprintf("dhcpoptionsnetworklist[%d].key", i), k) + u.Set(fmt.Sprintf("dhcpoptionsnetworklist[%d].value", i), vv) + i++ + } + } + if v, found := p.p["displayname"]; found { + u.Set("displayname", v.(string)) + } + if v, found := p.p["displayvm"]; found { + vv := strconv.FormatBool(v.(bool)) + u.Set("displayvm", vv) + } + if v, found := p.p["group"]; found { + u.Set("group", v.(string)) + } + if v, found := p.p["haenable"]; found { + vv := strconv.FormatBool(v.(bool)) + u.Set("haenable", vv) + } + if v, found := p.p["id"]; found { + u.Set("id", v.(string)) + } + if v, found := p.p["instancename"]; found { + u.Set("instancename", v.(string)) + } + if v, found := p.p["isdynamicallyscalable"]; found { + vv := strconv.FormatBool(v.(bool)) + u.Set("isdynamicallyscalable", vv) + } + if v, found := p.p["name"]; found { + u.Set("name", v.(string)) + } + if v, found := p.p["ostypeid"]; found { + u.Set("ostypeid", v.(string)) + } + if v, found := p.p["securitygroupids"]; found { + vv := strings.Join(v.([]string), ",") + u.Set("securitygroupids", vv) + } + if v, found := p.p["securitygroupnames"]; found { + vv := strings.Join(v.([]string), ",") + u.Set("securitygroupnames", vv) + } + if v, found := p.p["userdata"]; found { + u.Set("userdata", v.(string)) + } + return u +} + +func (p *UpdateVirtualMachineParams) SetCleanupdetails(v bool) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["cleanupdetails"] = v + return +} + +func (p *UpdateVirtualMachineParams) SetCustomid(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["customid"] = v + return +} + +func (p *UpdateVirtualMachineParams) SetDetails(v map[string]string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["details"] = v + return +} + +func (p *UpdateVirtualMachineParams) SetDhcpoptionsnetworklist(v map[string]string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["dhcpoptionsnetworklist"] = v + return +} + +func (p *UpdateVirtualMachineParams) SetDisplayname(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["displayname"] = v + return +} + +func (p *UpdateVirtualMachineParams) SetDisplayvm(v bool) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["displayvm"] = v + return +} + +func (p *UpdateVirtualMachineParams) SetGroup(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["group"] = v + return +} + +func (p *UpdateVirtualMachineParams) SetHaenable(v bool) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["haenable"] = v + return +} + +func (p *UpdateVirtualMachineParams) SetId(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["id"] = v + return +} + +func (p *UpdateVirtualMachineParams) SetInstancename(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["instancename"] = v + return +} + +func (p *UpdateVirtualMachineParams) SetIsdynamicallyscalable(v bool) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["isdynamicallyscalable"] = v + return +} + +func (p *UpdateVirtualMachineParams) SetName(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["name"] = v + return +} + +func (p *UpdateVirtualMachineParams) SetOstypeid(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["ostypeid"] = v + return +} + +func (p *UpdateVirtualMachineParams) SetSecuritygroupids(v []string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["securitygroupids"] = v + return +} + +func (p *UpdateVirtualMachineParams) SetSecuritygroupnames(v []string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["securitygroupnames"] = v + return +} + +func (p *UpdateVirtualMachineParams) SetUserdata(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["userdata"] = v + return +} + +// You should always use this function to get a new UpdateVirtualMachineParams instance, +// as then you are sure you have configured all required params +func (s *VirtualMachineService) NewUpdateVirtualMachineParams(id string) *UpdateVirtualMachineParams { + p := &UpdateVirtualMachineParams{} + p.p = make(map[string]interface{}) + p.p["id"] = id + return p +} + +// Updates properties of a virtual machine. The VM has to be stopped and restarted for the new properties to take effect. UpdateVirtualMachine does not first check whether the VM is stopped. Therefore, stop the VM manually before issuing this call. +func (s *VirtualMachineService) UpdateVirtualMachine(p *UpdateVirtualMachineParams) (*UpdateVirtualMachineResponse, error) { + resp, err := s.cs.newRequest("updateVirtualMachine", p.toURLValues()) + if err != nil { + return nil, err + } + + var r UpdateVirtualMachineResponse + if err := json.Unmarshal(resp, &r); err != nil { + return nil, err + } + + return &r, nil +} + +type UpdateVirtualMachineResponse struct { + Account string `json:"account"` + Affinitygroup []UpdateVirtualMachineResponseAffinitygroup `json:"affinitygroup"` + Cpunumber int `json:"cpunumber"` + Cpuspeed int `json:"cpuspeed"` + Cpuused string `json:"cpuused"` + Created string `json:"created"` + Details map[string]string `json:"details"` + Diskioread int64 `json:"diskioread"` + Diskiowrite int64 `json:"diskiowrite"` + Diskkbsread int64 `json:"diskkbsread"` + Diskkbswrite int64 `json:"diskkbswrite"` + Diskofferingid string `json:"diskofferingid"` + Diskofferingname string `json:"diskofferingname"` + Displayname string `json:"displayname"` + Displayvm bool `json:"displayvm"` + Domain string `json:"domain"` + Domainid string `json:"domainid"` + Forvirtualnetwork bool `json:"forvirtualnetwork"` + Group string `json:"group"` + Groupid string `json:"groupid"` + Guestosid string `json:"guestosid"` + Haenable bool `json:"haenable"` + Hostid string `json:"hostid"` + Hostname string `json:"hostname"` + Hypervisor string `json:"hypervisor"` + Id string `json:"id"` + Instancename string `json:"instancename"` + Isdynamicallyscalable bool `json:"isdynamicallyscalable"` + Isodisplaytext string `json:"isodisplaytext"` + Isoid string `json:"isoid"` + Isoname string `json:"isoname"` + Keypair string `json:"keypair"` + Memory int `json:"memory"` + Memoryintfreekbs int64 `json:"memoryintfreekbs"` + Memorykbs int64 `json:"memorykbs"` + Memorytargetkbs int64 `json:"memorytargetkbs"` + Name string `json:"name"` + Networkkbsread int64 `json:"networkkbsread"` + Networkkbswrite int64 `json:"networkkbswrite"` + Nic []Nic `json:"nic"` + Ostypeid int64 `json:"ostypeid"` + Password string `json:"password"` + Passwordenabled bool `json:"passwordenabled"` + Project string `json:"project"` + Projectid string `json:"projectid"` + Publicip string `json:"publicip"` + Publicipid string `json:"publicipid"` + Rootdeviceid int64 `json:"rootdeviceid"` + Rootdevicetype string `json:"rootdevicetype"` + Securitygroup []UpdateVirtualMachineResponseSecuritygroup `json:"securitygroup"` + Serviceofferingid string `json:"serviceofferingid"` + Serviceofferingname string `json:"serviceofferingname"` + Servicestate string `json:"servicestate"` + State string `json:"state"` + Templatedisplaytext string `json:"templatedisplaytext"` + Templateid string `json:"templateid"` + Templatename string `json:"templatename"` + Userid string `json:"userid"` + Username string `json:"username"` + Vgpu string `json:"vgpu"` + Zoneid string `json:"zoneid"` + Zonename string `json:"zonename"` +} + +type UpdateVirtualMachineResponseSecuritygroup struct { + Account string `json:"account"` + Description string `json:"description"` + Domain string `json:"domain"` + Domainid string `json:"domainid"` + Egressrule []UpdateVirtualMachineResponseSecuritygroupRule `json:"egressrule"` + Id string `json:"id"` + Ingressrule []UpdateVirtualMachineResponseSecuritygroupRule `json:"ingressrule"` + Name string `json:"name"` + Project string `json:"project"` + Projectid string `json:"projectid"` + Tags []Tags `json:"tags"` + Virtualmachinecount int `json:"virtualmachinecount"` + Virtualmachineids []interface{} `json:"virtualmachineids"` +} + +type UpdateVirtualMachineResponseSecuritygroupRule struct { + Account string `json:"account"` + Cidr string `json:"cidr"` + Endport int `json:"endport"` + Icmpcode int `json:"icmpcode"` + Icmptype int `json:"icmptype"` + Protocol string `json:"protocol"` + Ruleid string `json:"ruleid"` + Securitygroupname string `json:"securitygroupname"` + Startport int `json:"startport"` + Tags []Tags `json:"tags"` +} + +type UpdateVirtualMachineResponseAffinitygroup struct { + Account string `json:"account"` + Description string `json:"description"` + Domain string `json:"domain"` + Domainid string `json:"domainid"` + Id string `json:"id"` + Name string `json:"name"` + Project string `json:"project"` + Projectid string `json:"projectid"` + Type string `json:"type"` + VirtualmachineIds []string `json:"virtualmachineIds"` } diff --git a/vendor/github.com/xanzy/go-cloudstack/cloudstack/VolumeService.go b/vendor/github.com/xanzy/go-cloudstack/cloudstack/VolumeService.go index 5b18eb4a5..e7cf73f7c 100644 --- a/vendor/github.com/xanzy/go-cloudstack/cloudstack/VolumeService.go +++ b/vendor/github.com/xanzy/go-cloudstack/cloudstack/VolumeService.go @@ -1,5 +1,5 @@ // -// Copyright 2016, Sander van Harmelen +// Copyright 2018, Sander van Harmelen // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -111,461 +111,69 @@ func (s *VolumeService) AttachVolume(p *AttachVolumeParams) (*AttachVolumeRespon return nil, err } } + return &r, nil } type AttachVolumeResponse struct { - JobID string `json:"jobid,omitempty"` - Account string `json:"account,omitempty"` - Attached string `json:"attached,omitempty"` - Chaininfo string `json:"chaininfo,omitempty"` - Created string `json:"created,omitempty"` - Destroyed bool `json:"destroyed,omitempty"` - Deviceid int64 `json:"deviceid,omitempty"` - DiskBytesReadRate int64 `json:"diskBytesReadRate,omitempty"` - DiskBytesWriteRate int64 `json:"diskBytesWriteRate,omitempty"` - DiskIopsReadRate int64 `json:"diskIopsReadRate,omitempty"` - DiskIopsWriteRate int64 `json:"diskIopsWriteRate,omitempty"` - Diskofferingdisplaytext string `json:"diskofferingdisplaytext,omitempty"` - Diskofferingid string `json:"diskofferingid,omitempty"` - Diskofferingname string `json:"diskofferingname,omitempty"` - Displayvolume bool `json:"displayvolume,omitempty"` - Domain string `json:"domain,omitempty"` - Domainid string `json:"domainid,omitempty"` - Hypervisor string `json:"hypervisor,omitempty"` - Id string `json:"id,omitempty"` - Isextractable bool `json:"isextractable,omitempty"` - Isodisplaytext string `json:"isodisplaytext,omitempty"` - Isoid string `json:"isoid,omitempty"` - Isoname string `json:"isoname,omitempty"` - Maxiops int64 `json:"maxiops,omitempty"` - Miniops int64 `json:"miniops,omitempty"` - Name string `json:"name,omitempty"` - Path string `json:"path,omitempty"` - Project string `json:"project,omitempty"` - Projectid string `json:"projectid,omitempty"` - Provisioningtype string `json:"provisioningtype,omitempty"` - Quiescevm bool `json:"quiescevm,omitempty"` - Serviceofferingdisplaytext string `json:"serviceofferingdisplaytext,omitempty"` - Serviceofferingid string `json:"serviceofferingid,omitempty"` - Serviceofferingname string `json:"serviceofferingname,omitempty"` - Size int64 `json:"size,omitempty"` - Snapshotid string `json:"snapshotid,omitempty"` - State string `json:"state,omitempty"` - Status string `json:"status,omitempty"` - Storage string `json:"storage,omitempty"` - Storageid string `json:"storageid,omitempty"` - Storagetype string `json:"storagetype,omitempty"` - Tags []struct { - Account string `json:"account,omitempty"` - Customer string `json:"customer,omitempty"` - Domain string `json:"domain,omitempty"` - Domainid string `json:"domainid,omitempty"` - Key string `json:"key,omitempty"` - Project string `json:"project,omitempty"` - Projectid string `json:"projectid,omitempty"` - Resourceid string `json:"resourceid,omitempty"` - Resourcetype string `json:"resourcetype,omitempty"` - Value string `json:"value,omitempty"` - } `json:"tags,omitempty"` - Templatedisplaytext string `json:"templatedisplaytext,omitempty"` - Templateid string `json:"templateid,omitempty"` - Templatename string `json:"templatename,omitempty"` - Type string `json:"type,omitempty"` - Virtualmachineid string `json:"virtualmachineid,omitempty"` - Vmdisplayname string `json:"vmdisplayname,omitempty"` - Vmname string `json:"vmname,omitempty"` - Vmstate string `json:"vmstate,omitempty"` - Zoneid string `json:"zoneid,omitempty"` - Zonename string `json:"zonename,omitempty"` -} - -type UploadVolumeParams struct { - p map[string]interface{} -} - -func (p *UploadVolumeParams) toURLValues() url.Values { - u := url.Values{} - if p.p == nil { - return u - } - if v, found := p.p["account"]; found { - u.Set("account", v.(string)) - } - if v, found := p.p["checksum"]; found { - u.Set("checksum", v.(string)) - } - if v, found := p.p["diskofferingid"]; found { - u.Set("diskofferingid", v.(string)) - } - if v, found := p.p["domainid"]; found { - u.Set("domainid", v.(string)) - } - if v, found := p.p["format"]; found { - u.Set("format", v.(string)) - } - if v, found := p.p["imagestoreuuid"]; found { - u.Set("imagestoreuuid", v.(string)) - } - if v, found := p.p["name"]; found { - u.Set("name", v.(string)) - } - if v, found := p.p["projectid"]; found { - u.Set("projectid", v.(string)) - } - if v, found := p.p["url"]; found { - u.Set("url", v.(string)) - } - if v, found := p.p["zoneid"]; found { - u.Set("zoneid", v.(string)) - } - return u -} - -func (p *UploadVolumeParams) SetAccount(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["account"] = v - return -} - -func (p *UploadVolumeParams) SetChecksum(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["checksum"] = v - return -} - -func (p *UploadVolumeParams) SetDiskofferingid(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["diskofferingid"] = v - return -} - -func (p *UploadVolumeParams) SetDomainid(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["domainid"] = v - return -} - -func (p *UploadVolumeParams) SetFormat(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["format"] = v - return -} - -func (p *UploadVolumeParams) SetImagestoreuuid(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["imagestoreuuid"] = v - return -} - -func (p *UploadVolumeParams) SetName(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["name"] = v - return -} - -func (p *UploadVolumeParams) SetProjectid(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["projectid"] = v - return -} - -func (p *UploadVolumeParams) SetUrl(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["url"] = v - return -} - -func (p *UploadVolumeParams) SetZoneid(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["zoneid"] = v - return -} - -// You should always use this function to get a new UploadVolumeParams instance, -// as then you are sure you have configured all required params -func (s *VolumeService) NewUploadVolumeParams(format string, name string, url string, zoneid string) *UploadVolumeParams { - p := &UploadVolumeParams{} - p.p = make(map[string]interface{}) - p.p["format"] = format - p.p["name"] = name - p.p["url"] = url - p.p["zoneid"] = zoneid - return p -} - -// Uploads a data disk. -func (s *VolumeService) UploadVolume(p *UploadVolumeParams) (*UploadVolumeResponse, error) { - resp, err := s.cs.newRequest("uploadVolume", p.toURLValues()) - if err != nil { - return nil, err - } - - var r UploadVolumeResponse - if err := json.Unmarshal(resp, &r); err != nil { - return nil, err - } - - // If we have a async client, we need to wait for the async result - if s.cs.async { - b, err := s.cs.GetAsyncJobResult(r.JobID, s.cs.timeout) - if err != nil { - if err == AsyncTimeoutErr { - return &r, err - } - return nil, err - } - - b, err = getRawValue(b) - if err != nil { - return nil, err - } - - if err := json.Unmarshal(b, &r); err != nil { - return nil, err - } - } - return &r, nil -} - -type UploadVolumeResponse struct { - JobID string `json:"jobid,omitempty"` - Account string `json:"account,omitempty"` - Attached string `json:"attached,omitempty"` - Chaininfo string `json:"chaininfo,omitempty"` - Created string `json:"created,omitempty"` - Destroyed bool `json:"destroyed,omitempty"` - Deviceid int64 `json:"deviceid,omitempty"` - DiskBytesReadRate int64 `json:"diskBytesReadRate,omitempty"` - DiskBytesWriteRate int64 `json:"diskBytesWriteRate,omitempty"` - DiskIopsReadRate int64 `json:"diskIopsReadRate,omitempty"` - DiskIopsWriteRate int64 `json:"diskIopsWriteRate,omitempty"` - Diskofferingdisplaytext string `json:"diskofferingdisplaytext,omitempty"` - Diskofferingid string `json:"diskofferingid,omitempty"` - Diskofferingname string `json:"diskofferingname,omitempty"` - Displayvolume bool `json:"displayvolume,omitempty"` - Domain string `json:"domain,omitempty"` - Domainid string `json:"domainid,omitempty"` - Hypervisor string `json:"hypervisor,omitempty"` - Id string `json:"id,omitempty"` - Isextractable bool `json:"isextractable,omitempty"` - Isodisplaytext string `json:"isodisplaytext,omitempty"` - Isoid string `json:"isoid,omitempty"` - Isoname string `json:"isoname,omitempty"` - Maxiops int64 `json:"maxiops,omitempty"` - Miniops int64 `json:"miniops,omitempty"` - Name string `json:"name,omitempty"` - Path string `json:"path,omitempty"` - Project string `json:"project,omitempty"` - Projectid string `json:"projectid,omitempty"` - Provisioningtype string `json:"provisioningtype,omitempty"` - Quiescevm bool `json:"quiescevm,omitempty"` - Serviceofferingdisplaytext string `json:"serviceofferingdisplaytext,omitempty"` - Serviceofferingid string `json:"serviceofferingid,omitempty"` - Serviceofferingname string `json:"serviceofferingname,omitempty"` - Size int64 `json:"size,omitempty"` - Snapshotid string `json:"snapshotid,omitempty"` - State string `json:"state,omitempty"` - Status string `json:"status,omitempty"` - Storage string `json:"storage,omitempty"` - Storageid string `json:"storageid,omitempty"` - Storagetype string `json:"storagetype,omitempty"` - Tags []struct { - Account string `json:"account,omitempty"` - Customer string `json:"customer,omitempty"` - Domain string `json:"domain,omitempty"` - Domainid string `json:"domainid,omitempty"` - Key string `json:"key,omitempty"` - Project string `json:"project,omitempty"` - Projectid string `json:"projectid,omitempty"` - Resourceid string `json:"resourceid,omitempty"` - Resourcetype string `json:"resourcetype,omitempty"` - Value string `json:"value,omitempty"` - } `json:"tags,omitempty"` - Templatedisplaytext string `json:"templatedisplaytext,omitempty"` - Templateid string `json:"templateid,omitempty"` - Templatename string `json:"templatename,omitempty"` - Type string `json:"type,omitempty"` - Virtualmachineid string `json:"virtualmachineid,omitempty"` - Vmdisplayname string `json:"vmdisplayname,omitempty"` - Vmname string `json:"vmname,omitempty"` - Vmstate string `json:"vmstate,omitempty"` - Zoneid string `json:"zoneid,omitempty"` - Zonename string `json:"zonename,omitempty"` -} - -type DetachVolumeParams struct { - p map[string]interface{} -} - -func (p *DetachVolumeParams) toURLValues() url.Values { - u := url.Values{} - if p.p == nil { - return u - } - if v, found := p.p["deviceid"]; found { - vv := strconv.FormatInt(v.(int64), 10) - u.Set("deviceid", vv) - } - if v, found := p.p["id"]; found { - u.Set("id", v.(string)) - } - if v, found := p.p["virtualmachineid"]; found { - u.Set("virtualmachineid", v.(string)) - } - return u -} - -func (p *DetachVolumeParams) SetDeviceid(v int64) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["deviceid"] = v - return -} - -func (p *DetachVolumeParams) SetId(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["id"] = v - return -} - -func (p *DetachVolumeParams) SetVirtualmachineid(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["virtualmachineid"] = v - return -} - -// You should always use this function to get a new DetachVolumeParams instance, -// as then you are sure you have configured all required params -func (s *VolumeService) NewDetachVolumeParams() *DetachVolumeParams { - p := &DetachVolumeParams{} - p.p = make(map[string]interface{}) - return p -} - -// Detaches a disk volume from a virtual machine. -func (s *VolumeService) DetachVolume(p *DetachVolumeParams) (*DetachVolumeResponse, error) { - resp, err := s.cs.newRequest("detachVolume", p.toURLValues()) - if err != nil { - return nil, err - } - - var r DetachVolumeResponse - if err := json.Unmarshal(resp, &r); err != nil { - return nil, err - } - - // If we have a async client, we need to wait for the async result - if s.cs.async { - b, err := s.cs.GetAsyncJobResult(r.JobID, s.cs.timeout) - if err != nil { - if err == AsyncTimeoutErr { - return &r, err - } - return nil, err - } - - b, err = getRawValue(b) - if err != nil { - return nil, err - } - - if err := json.Unmarshal(b, &r); err != nil { - return nil, err - } - } - return &r, nil -} - -type DetachVolumeResponse struct { - JobID string `json:"jobid,omitempty"` - Account string `json:"account,omitempty"` - Attached string `json:"attached,omitempty"` - Chaininfo string `json:"chaininfo,omitempty"` - Created string `json:"created,omitempty"` - Destroyed bool `json:"destroyed,omitempty"` - Deviceid int64 `json:"deviceid,omitempty"` - DiskBytesReadRate int64 `json:"diskBytesReadRate,omitempty"` - DiskBytesWriteRate int64 `json:"diskBytesWriteRate,omitempty"` - DiskIopsReadRate int64 `json:"diskIopsReadRate,omitempty"` - DiskIopsWriteRate int64 `json:"diskIopsWriteRate,omitempty"` - Diskofferingdisplaytext string `json:"diskofferingdisplaytext,omitempty"` - Diskofferingid string `json:"diskofferingid,omitempty"` - Diskofferingname string `json:"diskofferingname,omitempty"` - Displayvolume bool `json:"displayvolume,omitempty"` - Domain string `json:"domain,omitempty"` - Domainid string `json:"domainid,omitempty"` - Hypervisor string `json:"hypervisor,omitempty"` - Id string `json:"id,omitempty"` - Isextractable bool `json:"isextractable,omitempty"` - Isodisplaytext string `json:"isodisplaytext,omitempty"` - Isoid string `json:"isoid,omitempty"` - Isoname string `json:"isoname,omitempty"` - Maxiops int64 `json:"maxiops,omitempty"` - Miniops int64 `json:"miniops,omitempty"` - Name string `json:"name,omitempty"` - Path string `json:"path,omitempty"` - Project string `json:"project,omitempty"` - Projectid string `json:"projectid,omitempty"` - Provisioningtype string `json:"provisioningtype,omitempty"` - Quiescevm bool `json:"quiescevm,omitempty"` - Serviceofferingdisplaytext string `json:"serviceofferingdisplaytext,omitempty"` - Serviceofferingid string `json:"serviceofferingid,omitempty"` - Serviceofferingname string `json:"serviceofferingname,omitempty"` - Size int64 `json:"size,omitempty"` - Snapshotid string `json:"snapshotid,omitempty"` - State string `json:"state,omitempty"` - Status string `json:"status,omitempty"` - Storage string `json:"storage,omitempty"` - Storageid string `json:"storageid,omitempty"` - Storagetype string `json:"storagetype,omitempty"` - Tags []struct { - Account string `json:"account,omitempty"` - Customer string `json:"customer,omitempty"` - Domain string `json:"domain,omitempty"` - Domainid string `json:"domainid,omitempty"` - Key string `json:"key,omitempty"` - Project string `json:"project,omitempty"` - Projectid string `json:"projectid,omitempty"` - Resourceid string `json:"resourceid,omitempty"` - Resourcetype string `json:"resourcetype,omitempty"` - Value string `json:"value,omitempty"` - } `json:"tags,omitempty"` - Templatedisplaytext string `json:"templatedisplaytext,omitempty"` - Templateid string `json:"templateid,omitempty"` - Templatename string `json:"templatename,omitempty"` - Type string `json:"type,omitempty"` - Virtualmachineid string `json:"virtualmachineid,omitempty"` - Vmdisplayname string `json:"vmdisplayname,omitempty"` - Vmname string `json:"vmname,omitempty"` - Vmstate string `json:"vmstate,omitempty"` - Zoneid string `json:"zoneid,omitempty"` - Zonename string `json:"zonename,omitempty"` + JobID string `json:"jobid"` + Account string `json:"account"` + Attached string `json:"attached"` + Chaininfo string `json:"chaininfo"` + Clusterid string `json:"clusterid"` + Clustername string `json:"clustername"` + Created string `json:"created"` + Destroyed bool `json:"destroyed"` + Deviceid int64 `json:"deviceid"` + DiskBytesReadRate int64 `json:"diskBytesReadRate"` + DiskBytesWriteRate int64 `json:"diskBytesWriteRate"` + DiskIopsReadRate int64 `json:"diskIopsReadRate"` + DiskIopsWriteRate int64 `json:"diskIopsWriteRate"` + Diskofferingdisplaytext string `json:"diskofferingdisplaytext"` + Diskofferingid string `json:"diskofferingid"` + Diskofferingname string `json:"diskofferingname"` + Displayvolume bool `json:"displayvolume"` + Domain string `json:"domain"` + Domainid string `json:"domainid"` + Hypervisor string `json:"hypervisor"` + Id string `json:"id"` + Isextractable bool `json:"isextractable"` + Isodisplaytext string `json:"isodisplaytext"` + Isoid string `json:"isoid"` + Isoname string `json:"isoname"` + Maxiops int64 `json:"maxiops"` + Miniops int64 `json:"miniops"` + Name string `json:"name"` + Path string `json:"path"` + Physicalsize int64 `json:"physicalsize"` + Podid string `json:"podid"` + Podname string `json:"podname"` + Project string `json:"project"` + Projectid string `json:"projectid"` + Provisioningtype string `json:"provisioningtype"` + Quiescevm bool `json:"quiescevm"` + Serviceofferingdisplaytext string `json:"serviceofferingdisplaytext"` + Serviceofferingid string `json:"serviceofferingid"` + Serviceofferingname string `json:"serviceofferingname"` + Size int64 `json:"size"` + Snapshotid string `json:"snapshotid"` + State string `json:"state"` + Status string `json:"status"` + Storage string `json:"storage"` + Storageid string `json:"storageid"` + Storagetype string `json:"storagetype"` + Templatedisplaytext string `json:"templatedisplaytext"` + Templateid string `json:"templateid"` + Templatename string `json:"templatename"` + Type string `json:"type"` + Utilization string `json:"utilization"` + Virtualmachineid string `json:"virtualmachineid"` + Virtualsize int64 `json:"virtualsize"` + Vmdisplayname string `json:"vmdisplayname"` + Vmname string `json:"vmname"` + Vmstate string `json:"vmstate"` + Zoneid string `json:"zoneid"` + Zonename string `json:"zonename"` } type CreateVolumeParams struct { @@ -766,73 +374,69 @@ func (s *VolumeService) CreateVolume(p *CreateVolumeParams) (*CreateVolumeRespon return nil, err } } + return &r, nil } type CreateVolumeResponse struct { - JobID string `json:"jobid,omitempty"` - Account string `json:"account,omitempty"` - Attached string `json:"attached,omitempty"` - Chaininfo string `json:"chaininfo,omitempty"` - Created string `json:"created,omitempty"` - Destroyed bool `json:"destroyed,omitempty"` - Deviceid int64 `json:"deviceid,omitempty"` - DiskBytesReadRate int64 `json:"diskBytesReadRate,omitempty"` - DiskBytesWriteRate int64 `json:"diskBytesWriteRate,omitempty"` - DiskIopsReadRate int64 `json:"diskIopsReadRate,omitempty"` - DiskIopsWriteRate int64 `json:"diskIopsWriteRate,omitempty"` - Diskofferingdisplaytext string `json:"diskofferingdisplaytext,omitempty"` - Diskofferingid string `json:"diskofferingid,omitempty"` - Diskofferingname string `json:"diskofferingname,omitempty"` - Displayvolume bool `json:"displayvolume,omitempty"` - Domain string `json:"domain,omitempty"` - Domainid string `json:"domainid,omitempty"` - Hypervisor string `json:"hypervisor,omitempty"` - Id string `json:"id,omitempty"` - Isextractable bool `json:"isextractable,omitempty"` - Isodisplaytext string `json:"isodisplaytext,omitempty"` - Isoid string `json:"isoid,omitempty"` - Isoname string `json:"isoname,omitempty"` - Maxiops int64 `json:"maxiops,omitempty"` - Miniops int64 `json:"miniops,omitempty"` - Name string `json:"name,omitempty"` - Path string `json:"path,omitempty"` - Project string `json:"project,omitempty"` - Projectid string `json:"projectid,omitempty"` - Provisioningtype string `json:"provisioningtype,omitempty"` - Quiescevm bool `json:"quiescevm,omitempty"` - Serviceofferingdisplaytext string `json:"serviceofferingdisplaytext,omitempty"` - Serviceofferingid string `json:"serviceofferingid,omitempty"` - Serviceofferingname string `json:"serviceofferingname,omitempty"` - Size int64 `json:"size,omitempty"` - Snapshotid string `json:"snapshotid,omitempty"` - State string `json:"state,omitempty"` - Status string `json:"status,omitempty"` - Storage string `json:"storage,omitempty"` - Storageid string `json:"storageid,omitempty"` - Storagetype string `json:"storagetype,omitempty"` - Tags []struct { - Account string `json:"account,omitempty"` - Customer string `json:"customer,omitempty"` - Domain string `json:"domain,omitempty"` - Domainid string `json:"domainid,omitempty"` - Key string `json:"key,omitempty"` - Project string `json:"project,omitempty"` - Projectid string `json:"projectid,omitempty"` - Resourceid string `json:"resourceid,omitempty"` - Resourcetype string `json:"resourcetype,omitempty"` - Value string `json:"value,omitempty"` - } `json:"tags,omitempty"` - Templatedisplaytext string `json:"templatedisplaytext,omitempty"` - Templateid string `json:"templateid,omitempty"` - Templatename string `json:"templatename,omitempty"` - Type string `json:"type,omitempty"` - Virtualmachineid string `json:"virtualmachineid,omitempty"` - Vmdisplayname string `json:"vmdisplayname,omitempty"` - Vmname string `json:"vmname,omitempty"` - Vmstate string `json:"vmstate,omitempty"` - Zoneid string `json:"zoneid,omitempty"` - Zonename string `json:"zonename,omitempty"` + JobID string `json:"jobid"` + Account string `json:"account"` + Attached string `json:"attached"` + Chaininfo string `json:"chaininfo"` + Clusterid string `json:"clusterid"` + Clustername string `json:"clustername"` + Created string `json:"created"` + Destroyed bool `json:"destroyed"` + Deviceid int64 `json:"deviceid"` + DiskBytesReadRate int64 `json:"diskBytesReadRate"` + DiskBytesWriteRate int64 `json:"diskBytesWriteRate"` + DiskIopsReadRate int64 `json:"diskIopsReadRate"` + DiskIopsWriteRate int64 `json:"diskIopsWriteRate"` + Diskofferingdisplaytext string `json:"diskofferingdisplaytext"` + Diskofferingid string `json:"diskofferingid"` + Diskofferingname string `json:"diskofferingname"` + Displayvolume bool `json:"displayvolume"` + Domain string `json:"domain"` + Domainid string `json:"domainid"` + Hypervisor string `json:"hypervisor"` + Id string `json:"id"` + Isextractable bool `json:"isextractable"` + Isodisplaytext string `json:"isodisplaytext"` + Isoid string `json:"isoid"` + Isoname string `json:"isoname"` + Maxiops int64 `json:"maxiops"` + Miniops int64 `json:"miniops"` + Name string `json:"name"` + Path string `json:"path"` + Physicalsize int64 `json:"physicalsize"` + Podid string `json:"podid"` + Podname string `json:"podname"` + Project string `json:"project"` + Projectid string `json:"projectid"` + Provisioningtype string `json:"provisioningtype"` + Quiescevm bool `json:"quiescevm"` + Serviceofferingdisplaytext string `json:"serviceofferingdisplaytext"` + Serviceofferingid string `json:"serviceofferingid"` + Serviceofferingname string `json:"serviceofferingname"` + Size int64 `json:"size"` + Snapshotid string `json:"snapshotid"` + State string `json:"state"` + Status string `json:"status"` + Storage string `json:"storage"` + Storageid string `json:"storageid"` + Storagetype string `json:"storagetype"` + Templatedisplaytext string `json:"templatedisplaytext"` + Templateid string `json:"templateid"` + Templatename string `json:"templatename"` + Type string `json:"type"` + Utilization string `json:"utilization"` + Virtualmachineid string `json:"virtualmachineid"` + Virtualsize int64 `json:"virtualsize"` + Vmdisplayname string `json:"vmdisplayname"` + Vmname string `json:"vmname"` + Vmstate string `json:"vmstate"` + Zoneid string `json:"zoneid"` + Zonename string `json:"zonename"` } type DeleteVolumeParams struct { @@ -878,134 +482,65 @@ func (s *VolumeService) DeleteVolume(p *DeleteVolumeParams) (*DeleteVolumeRespon if err := json.Unmarshal(resp, &r); err != nil { return nil, err } + return &r, nil } type DeleteVolumeResponse struct { - Displaytext string `json:"displaytext,omitempty"` - Success string `json:"success,omitempty"` + Displaytext string `json:"displaytext"` + Success bool `json:"success"` } -type ListVolumesParams struct { +func (r *DeleteVolumeResponse) UnmarshalJSON(b []byte) error { + var m map[string]interface{} + err := json.Unmarshal(b, &m) + if err != nil { + return err + } + + if success, ok := m["success"].(string); ok { + m["success"] = success == "true" + b, err = json.Marshal(m) + if err != nil { + return err + } + } + + type alias DeleteVolumeResponse + return json.Unmarshal(b, (*alias)(r)) +} + +type DetachVolumeParams struct { p map[string]interface{} } -func (p *ListVolumesParams) toURLValues() url.Values { +func (p *DetachVolumeParams) toURLValues() url.Values { u := url.Values{} if p.p == nil { return u } - if v, found := p.p["account"]; found { - u.Set("account", v.(string)) - } - if v, found := p.p["diskofferingid"]; found { - u.Set("diskofferingid", v.(string)) - } - if v, found := p.p["displayvolume"]; found { - vv := strconv.FormatBool(v.(bool)) - u.Set("displayvolume", vv) - } - if v, found := p.p["domainid"]; found { - u.Set("domainid", v.(string)) - } - if v, found := p.p["hostid"]; found { - u.Set("hostid", v.(string)) + if v, found := p.p["deviceid"]; found { + vv := strconv.FormatInt(v.(int64), 10) + u.Set("deviceid", vv) } if v, found := p.p["id"]; found { u.Set("id", v.(string)) } - if v, found := p.p["isrecursive"]; found { - vv := strconv.FormatBool(v.(bool)) - u.Set("isrecursive", vv) - } - if v, found := p.p["keyword"]; found { - u.Set("keyword", v.(string)) - } - if v, found := p.p["listall"]; found { - vv := strconv.FormatBool(v.(bool)) - u.Set("listall", vv) - } - if v, found := p.p["name"]; found { - u.Set("name", v.(string)) - } - if v, found := p.p["page"]; found { - vv := strconv.Itoa(v.(int)) - u.Set("page", vv) - } - if v, found := p.p["pagesize"]; found { - vv := strconv.Itoa(v.(int)) - u.Set("pagesize", vv) - } - if v, found := p.p["podid"]; found { - u.Set("podid", v.(string)) - } - if v, found := p.p["projectid"]; found { - u.Set("projectid", v.(string)) - } - if v, found := p.p["storageid"]; found { - u.Set("storageid", v.(string)) - } - if v, found := p.p["tags"]; found { - i := 0 - for k, vv := range v.(map[string]string) { - u.Set(fmt.Sprintf("tags[%d].key", i), k) - u.Set(fmt.Sprintf("tags[%d].value", i), vv) - i++ - } - } - if v, found := p.p["type"]; found { - u.Set("type", v.(string)) - } if v, found := p.p["virtualmachineid"]; found { u.Set("virtualmachineid", v.(string)) } - if v, found := p.p["zoneid"]; found { - u.Set("zoneid", v.(string)) - } return u } -func (p *ListVolumesParams) SetAccount(v string) { +func (p *DetachVolumeParams) SetDeviceid(v int64) { if p.p == nil { p.p = make(map[string]interface{}) } - p.p["account"] = v + p.p["deviceid"] = v return } -func (p *ListVolumesParams) SetDiskofferingid(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["diskofferingid"] = v - return -} - -func (p *ListVolumesParams) SetDisplayvolume(v bool) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["displayvolume"] = v - return -} - -func (p *ListVolumesParams) SetDomainid(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["domainid"] = v - return -} - -func (p *ListVolumesParams) SetHostid(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["hostid"] = v - return -} - -func (p *ListVolumesParams) SetId(v string) { +func (p *DetachVolumeParams) SetId(v string) { if p.p == nil { p.p = make(map[string]interface{}) } @@ -1013,95 +548,7 @@ func (p *ListVolumesParams) SetId(v string) { return } -func (p *ListVolumesParams) SetIsrecursive(v bool) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["isrecursive"] = v - return -} - -func (p *ListVolumesParams) SetKeyword(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["keyword"] = v - return -} - -func (p *ListVolumesParams) SetListall(v bool) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["listall"] = v - return -} - -func (p *ListVolumesParams) SetName(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["name"] = v - return -} - -func (p *ListVolumesParams) SetPage(v int) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["page"] = v - return -} - -func (p *ListVolumesParams) SetPagesize(v int) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["pagesize"] = v - return -} - -func (p *ListVolumesParams) SetPodid(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["podid"] = v - return -} - -func (p *ListVolumesParams) SetProjectid(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["projectid"] = v - return -} - -func (p *ListVolumesParams) SetStorageid(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["storageid"] = v - return -} - -func (p *ListVolumesParams) SetTags(v map[string]string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["tags"] = v - return -} - -func (p *ListVolumesParams) SetType(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["type"] = v - return -} - -func (p *ListVolumesParams) SetVirtualmachineid(v string) { +func (p *DetachVolumeParams) SetVirtualmachineid(v string) { if p.p == nil { p.p = make(map[string]interface{}) } @@ -1109,187 +556,108 @@ func (p *ListVolumesParams) SetVirtualmachineid(v string) { return } -func (p *ListVolumesParams) SetZoneid(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["zoneid"] = v - return -} - -// You should always use this function to get a new ListVolumesParams instance, +// You should always use this function to get a new DetachVolumeParams instance, // as then you are sure you have configured all required params -func (s *VolumeService) NewListVolumesParams() *ListVolumesParams { - p := &ListVolumesParams{} +func (s *VolumeService) NewDetachVolumeParams() *DetachVolumeParams { + p := &DetachVolumeParams{} p.p = make(map[string]interface{}) return p } -// This is a courtesy helper function, which in some cases may not work as expected! -func (s *VolumeService) GetVolumeID(name string, opts ...OptionFunc) (string, int, error) { - p := &ListVolumesParams{} - p.p = make(map[string]interface{}) - - p.p["name"] = name - - for _, fn := range opts { - if err := fn(s.cs, p); err != nil { - return "", -1, err - } - } - - l, err := s.ListVolumes(p) - if err != nil { - return "", -1, err - } - - if l.Count == 0 { - return "", l.Count, fmt.Errorf("No match found for %s: %+v", name, l) - } - - if l.Count == 1 { - return l.Volumes[0].Id, l.Count, nil - } - - if l.Count > 1 { - for _, v := range l.Volumes { - if v.Name == name { - return v.Id, l.Count, nil - } - } - } - return "", l.Count, fmt.Errorf("Could not find an exact match for %s: %+v", name, l) -} - -// This is a courtesy helper function, which in some cases may not work as expected! -func (s *VolumeService) GetVolumeByName(name string, opts ...OptionFunc) (*Volume, int, error) { - id, count, err := s.GetVolumeID(name, opts...) - if err != nil { - return nil, count, err - } - - r, count, err := s.GetVolumeByID(id, opts...) - if err != nil { - return nil, count, err - } - return r, count, nil -} - -// This is a courtesy helper function, which in some cases may not work as expected! -func (s *VolumeService) GetVolumeByID(id string, opts ...OptionFunc) (*Volume, int, error) { - p := &ListVolumesParams{} - p.p = make(map[string]interface{}) - - p.p["id"] = id - - for _, fn := range opts { - if err := fn(s.cs, p); err != nil { - return nil, -1, err - } - } - - l, err := s.ListVolumes(p) - if err != nil { - if strings.Contains(err.Error(), fmt.Sprintf( - "Invalid parameter id value=%s due to incorrect long value format, "+ - "or entity does not exist", id)) { - return nil, 0, fmt.Errorf("No match found for %s: %+v", id, l) - } - return nil, -1, err - } - - if l.Count == 0 { - return nil, l.Count, fmt.Errorf("No match found for %s: %+v", id, l) - } - - if l.Count == 1 { - return l.Volumes[0], l.Count, nil - } - return nil, l.Count, fmt.Errorf("There is more then one result for Volume UUID: %s!", id) -} - -// Lists all volumes. -func (s *VolumeService) ListVolumes(p *ListVolumesParams) (*ListVolumesResponse, error) { - resp, err := s.cs.newRequest("listVolumes", p.toURLValues()) +// Detaches a disk volume from a virtual machine. +func (s *VolumeService) DetachVolume(p *DetachVolumeParams) (*DetachVolumeResponse, error) { + resp, err := s.cs.newRequest("detachVolume", p.toURLValues()) if err != nil { return nil, err } - var r ListVolumesResponse + var r DetachVolumeResponse if err := json.Unmarshal(resp, &r); err != nil { return nil, err } + + // If we have a async client, we need to wait for the async result + if s.cs.async { + b, err := s.cs.GetAsyncJobResult(r.JobID, s.cs.timeout) + if err != nil { + if err == AsyncTimeoutErr { + return &r, err + } + return nil, err + } + + b, err = getRawValue(b) + if err != nil { + return nil, err + } + + if err := json.Unmarshal(b, &r); err != nil { + return nil, err + } + } + return &r, nil } -type ListVolumesResponse struct { - Count int `json:"count"` - Volumes []*Volume `json:"volume"` -} - -type Volume struct { - Account string `json:"account,omitempty"` - Attached string `json:"attached,omitempty"` - Chaininfo string `json:"chaininfo,omitempty"` - Created string `json:"created,omitempty"` - Destroyed bool `json:"destroyed,omitempty"` - Deviceid int64 `json:"deviceid,omitempty"` - DiskBytesReadRate int64 `json:"diskBytesReadRate,omitempty"` - DiskBytesWriteRate int64 `json:"diskBytesWriteRate,omitempty"` - DiskIopsReadRate int64 `json:"diskIopsReadRate,omitempty"` - DiskIopsWriteRate int64 `json:"diskIopsWriteRate,omitempty"` - Diskofferingdisplaytext string `json:"diskofferingdisplaytext,omitempty"` - Diskofferingid string `json:"diskofferingid,omitempty"` - Diskofferingname string `json:"diskofferingname,omitempty"` - Displayvolume bool `json:"displayvolume,omitempty"` - Domain string `json:"domain,omitempty"` - Domainid string `json:"domainid,omitempty"` - Hypervisor string `json:"hypervisor,omitempty"` - Id string `json:"id,omitempty"` - Isextractable bool `json:"isextractable,omitempty"` - Isodisplaytext string `json:"isodisplaytext,omitempty"` - Isoid string `json:"isoid,omitempty"` - Isoname string `json:"isoname,omitempty"` - Maxiops int64 `json:"maxiops,omitempty"` - Miniops int64 `json:"miniops,omitempty"` - Name string `json:"name,omitempty"` - Path string `json:"path,omitempty"` - Project string `json:"project,omitempty"` - Projectid string `json:"projectid,omitempty"` - Provisioningtype string `json:"provisioningtype,omitempty"` - Quiescevm bool `json:"quiescevm,omitempty"` - Serviceofferingdisplaytext string `json:"serviceofferingdisplaytext,omitempty"` - Serviceofferingid string `json:"serviceofferingid,omitempty"` - Serviceofferingname string `json:"serviceofferingname,omitempty"` - Size int64 `json:"size,omitempty"` - Snapshotid string `json:"snapshotid,omitempty"` - State string `json:"state,omitempty"` - Status string `json:"status,omitempty"` - Storage string `json:"storage,omitempty"` - Storageid string `json:"storageid,omitempty"` - Storagetype string `json:"storagetype,omitempty"` - Tags []struct { - Account string `json:"account,omitempty"` - Customer string `json:"customer,omitempty"` - Domain string `json:"domain,omitempty"` - Domainid string `json:"domainid,omitempty"` - Key string `json:"key,omitempty"` - Project string `json:"project,omitempty"` - Projectid string `json:"projectid,omitempty"` - Resourceid string `json:"resourceid,omitempty"` - Resourcetype string `json:"resourcetype,omitempty"` - Value string `json:"value,omitempty"` - } `json:"tags,omitempty"` - Templatedisplaytext string `json:"templatedisplaytext,omitempty"` - Templateid string `json:"templateid,omitempty"` - Templatename string `json:"templatename,omitempty"` - Type string `json:"type,omitempty"` - Virtualmachineid string `json:"virtualmachineid,omitempty"` - Vmdisplayname string `json:"vmdisplayname,omitempty"` - Vmname string `json:"vmname,omitempty"` - Vmstate string `json:"vmstate,omitempty"` - Zoneid string `json:"zoneid,omitempty"` - Zonename string `json:"zonename,omitempty"` +type DetachVolumeResponse struct { + JobID string `json:"jobid"` + Account string `json:"account"` + Attached string `json:"attached"` + Chaininfo string `json:"chaininfo"` + Clusterid string `json:"clusterid"` + Clustername string `json:"clustername"` + Created string `json:"created"` + Destroyed bool `json:"destroyed"` + Deviceid int64 `json:"deviceid"` + DiskBytesReadRate int64 `json:"diskBytesReadRate"` + DiskBytesWriteRate int64 `json:"diskBytesWriteRate"` + DiskIopsReadRate int64 `json:"diskIopsReadRate"` + DiskIopsWriteRate int64 `json:"diskIopsWriteRate"` + Diskofferingdisplaytext string `json:"diskofferingdisplaytext"` + Diskofferingid string `json:"diskofferingid"` + Diskofferingname string `json:"diskofferingname"` + Displayvolume bool `json:"displayvolume"` + Domain string `json:"domain"` + Domainid string `json:"domainid"` + Hypervisor string `json:"hypervisor"` + Id string `json:"id"` + Isextractable bool `json:"isextractable"` + Isodisplaytext string `json:"isodisplaytext"` + Isoid string `json:"isoid"` + Isoname string `json:"isoname"` + Maxiops int64 `json:"maxiops"` + Miniops int64 `json:"miniops"` + Name string `json:"name"` + Path string `json:"path"` + Physicalsize int64 `json:"physicalsize"` + Podid string `json:"podid"` + Podname string `json:"podname"` + Project string `json:"project"` + Projectid string `json:"projectid"` + Provisioningtype string `json:"provisioningtype"` + Quiescevm bool `json:"quiescevm"` + Serviceofferingdisplaytext string `json:"serviceofferingdisplaytext"` + Serviceofferingid string `json:"serviceofferingid"` + Serviceofferingname string `json:"serviceofferingname"` + Size int64 `json:"size"` + Snapshotid string `json:"snapshotid"` + State string `json:"state"` + Status string `json:"status"` + Storage string `json:"storage"` + Storageid string `json:"storageid"` + Storagetype string `json:"storagetype"` + Templatedisplaytext string `json:"templatedisplaytext"` + Templateid string `json:"templateid"` + Templatename string `json:"templatename"` + Type string `json:"type"` + Utilization string `json:"utilization"` + Virtualmachineid string `json:"virtualmachineid"` + Virtualsize int64 `json:"virtualsize"` + Vmdisplayname string `json:"vmdisplayname"` + Vmname string `json:"vmname"` + Vmstate string `json:"vmstate"` + Zoneid string `json:"zoneid"` + Zonename string `json:"zonename"` } type ExtractVolumeParams struct { @@ -1390,66 +758,44 @@ func (s *VolumeService) ExtractVolume(p *ExtractVolumeParams) (*ExtractVolumeRes return nil, err } } + return &r, nil } type ExtractVolumeResponse struct { - JobID string `json:"jobid,omitempty"` - Accountid string `json:"accountid,omitempty"` - Created string `json:"created,omitempty"` - ExtractId string `json:"extractId,omitempty"` - ExtractMode string `json:"extractMode,omitempty"` - Id string `json:"id,omitempty"` - Name string `json:"name,omitempty"` - Resultstring string `json:"resultstring,omitempty"` - State string `json:"state,omitempty"` - Status string `json:"status,omitempty"` - Storagetype string `json:"storagetype,omitempty"` - Uploadpercentage int `json:"uploadpercentage,omitempty"` - Url string `json:"url,omitempty"` - Zoneid string `json:"zoneid,omitempty"` - Zonename string `json:"zonename,omitempty"` + JobID string `json:"jobid"` + Accountid string `json:"accountid"` + Created string `json:"created"` + ExtractId string `json:"extractId"` + ExtractMode string `json:"extractMode"` + Id string `json:"id"` + Name string `json:"name"` + Resultstring string `json:"resultstring"` + State string `json:"state"` + Status string `json:"status"` + Storagetype string `json:"storagetype"` + Uploadpercentage int `json:"uploadpercentage"` + Url string `json:"url"` + Zoneid string `json:"zoneid"` + Zonename string `json:"zonename"` } -type MigrateVolumeParams struct { +type GetPathForVolumeParams struct { p map[string]interface{} } -func (p *MigrateVolumeParams) toURLValues() url.Values { +func (p *GetPathForVolumeParams) toURLValues() url.Values { u := url.Values{} if p.p == nil { return u } - if v, found := p.p["livemigrate"]; found { - vv := strconv.FormatBool(v.(bool)) - u.Set("livemigrate", vv) - } - if v, found := p.p["storageid"]; found { - u.Set("storageid", v.(string)) - } if v, found := p.p["volumeid"]; found { u.Set("volumeid", v.(string)) } return u } -func (p *MigrateVolumeParams) SetLivemigrate(v bool) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["livemigrate"] = v - return -} - -func (p *MigrateVolumeParams) SetStorageid(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["storageid"] = v - return -} - -func (p *MigrateVolumeParams) SetVolumeid(v string) { +func (p *GetPathForVolumeParams) SetVolumeid(v string) { if p.p == nil { p.p = make(map[string]interface{}) } @@ -1457,503 +803,32 @@ func (p *MigrateVolumeParams) SetVolumeid(v string) { return } -// You should always use this function to get a new MigrateVolumeParams instance, +// You should always use this function to get a new GetPathForVolumeParams instance, // as then you are sure you have configured all required params -func (s *VolumeService) NewMigrateVolumeParams(storageid string, volumeid string) *MigrateVolumeParams { - p := &MigrateVolumeParams{} +func (s *VolumeService) NewGetPathForVolumeParams(volumeid string) *GetPathForVolumeParams { + p := &GetPathForVolumeParams{} p.p = make(map[string]interface{}) - p.p["storageid"] = storageid p.p["volumeid"] = volumeid return p } -// Migrate volume -func (s *VolumeService) MigrateVolume(p *MigrateVolumeParams) (*MigrateVolumeResponse, error) { - resp, err := s.cs.newRequest("migrateVolume", p.toURLValues()) +// Get the path associated with the provided volume UUID +func (s *VolumeService) GetPathForVolume(p *GetPathForVolumeParams) (*GetPathForVolumeResponse, error) { + resp, err := s.cs.newRequest("getPathForVolume", p.toURLValues()) if err != nil { return nil, err } - var r MigrateVolumeResponse + var r GetPathForVolumeResponse if err := json.Unmarshal(resp, &r); err != nil { return nil, err } - // If we have a async client, we need to wait for the async result - if s.cs.async { - b, err := s.cs.GetAsyncJobResult(r.JobID, s.cs.timeout) - if err != nil { - if err == AsyncTimeoutErr { - return &r, err - } - return nil, err - } - - b, err = getRawValue(b) - if err != nil { - return nil, err - } - - if err := json.Unmarshal(b, &r); err != nil { - return nil, err - } - } return &r, nil } -type MigrateVolumeResponse struct { - JobID string `json:"jobid,omitempty"` - Account string `json:"account,omitempty"` - Attached string `json:"attached,omitempty"` - Chaininfo string `json:"chaininfo,omitempty"` - Created string `json:"created,omitempty"` - Destroyed bool `json:"destroyed,omitempty"` - Deviceid int64 `json:"deviceid,omitempty"` - DiskBytesReadRate int64 `json:"diskBytesReadRate,omitempty"` - DiskBytesWriteRate int64 `json:"diskBytesWriteRate,omitempty"` - DiskIopsReadRate int64 `json:"diskIopsReadRate,omitempty"` - DiskIopsWriteRate int64 `json:"diskIopsWriteRate,omitempty"` - Diskofferingdisplaytext string `json:"diskofferingdisplaytext,omitempty"` - Diskofferingid string `json:"diskofferingid,omitempty"` - Diskofferingname string `json:"diskofferingname,omitempty"` - Displayvolume bool `json:"displayvolume,omitempty"` - Domain string `json:"domain,omitempty"` - Domainid string `json:"domainid,omitempty"` - Hypervisor string `json:"hypervisor,omitempty"` - Id string `json:"id,omitempty"` - Isextractable bool `json:"isextractable,omitempty"` - Isodisplaytext string `json:"isodisplaytext,omitempty"` - Isoid string `json:"isoid,omitempty"` - Isoname string `json:"isoname,omitempty"` - Maxiops int64 `json:"maxiops,omitempty"` - Miniops int64 `json:"miniops,omitempty"` - Name string `json:"name,omitempty"` - Path string `json:"path,omitempty"` - Project string `json:"project,omitempty"` - Projectid string `json:"projectid,omitempty"` - Provisioningtype string `json:"provisioningtype,omitempty"` - Quiescevm bool `json:"quiescevm,omitempty"` - Serviceofferingdisplaytext string `json:"serviceofferingdisplaytext,omitempty"` - Serviceofferingid string `json:"serviceofferingid,omitempty"` - Serviceofferingname string `json:"serviceofferingname,omitempty"` - Size int64 `json:"size,omitempty"` - Snapshotid string `json:"snapshotid,omitempty"` - State string `json:"state,omitempty"` - Status string `json:"status,omitempty"` - Storage string `json:"storage,omitempty"` - Storageid string `json:"storageid,omitempty"` - Storagetype string `json:"storagetype,omitempty"` - Tags []struct { - Account string `json:"account,omitempty"` - Customer string `json:"customer,omitempty"` - Domain string `json:"domain,omitempty"` - Domainid string `json:"domainid,omitempty"` - Key string `json:"key,omitempty"` - Project string `json:"project,omitempty"` - Projectid string `json:"projectid,omitempty"` - Resourceid string `json:"resourceid,omitempty"` - Resourcetype string `json:"resourcetype,omitempty"` - Value string `json:"value,omitempty"` - } `json:"tags,omitempty"` - Templatedisplaytext string `json:"templatedisplaytext,omitempty"` - Templateid string `json:"templateid,omitempty"` - Templatename string `json:"templatename,omitempty"` - Type string `json:"type,omitempty"` - Virtualmachineid string `json:"virtualmachineid,omitempty"` - Vmdisplayname string `json:"vmdisplayname,omitempty"` - Vmname string `json:"vmname,omitempty"` - Vmstate string `json:"vmstate,omitempty"` - Zoneid string `json:"zoneid,omitempty"` - Zonename string `json:"zonename,omitempty"` -} - -type ResizeVolumeParams struct { - p map[string]interface{} -} - -func (p *ResizeVolumeParams) toURLValues() url.Values { - u := url.Values{} - if p.p == nil { - return u - } - if v, found := p.p["diskofferingid"]; found { - u.Set("diskofferingid", v.(string)) - } - if v, found := p.p["id"]; found { - u.Set("id", v.(string)) - } - if v, found := p.p["maxiops"]; found { - vv := strconv.FormatInt(v.(int64), 10) - u.Set("maxiops", vv) - } - if v, found := p.p["miniops"]; found { - vv := strconv.FormatInt(v.(int64), 10) - u.Set("miniops", vv) - } - if v, found := p.p["shrinkok"]; found { - vv := strconv.FormatBool(v.(bool)) - u.Set("shrinkok", vv) - } - if v, found := p.p["size"]; found { - vv := strconv.FormatInt(v.(int64), 10) - u.Set("size", vv) - } - return u -} - -func (p *ResizeVolumeParams) SetDiskofferingid(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["diskofferingid"] = v - return -} - -func (p *ResizeVolumeParams) SetId(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["id"] = v - return -} - -func (p *ResizeVolumeParams) SetMaxiops(v int64) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["maxiops"] = v - return -} - -func (p *ResizeVolumeParams) SetMiniops(v int64) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["miniops"] = v - return -} - -func (p *ResizeVolumeParams) SetShrinkok(v bool) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["shrinkok"] = v - return -} - -func (p *ResizeVolumeParams) SetSize(v int64) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["size"] = v - return -} - -// You should always use this function to get a new ResizeVolumeParams instance, -// as then you are sure you have configured all required params -func (s *VolumeService) NewResizeVolumeParams(id string) *ResizeVolumeParams { - p := &ResizeVolumeParams{} - p.p = make(map[string]interface{}) - p.p["id"] = id - return p -} - -// Resizes a volume -func (s *VolumeService) ResizeVolume(p *ResizeVolumeParams) (*ResizeVolumeResponse, error) { - resp, err := s.cs.newRequest("resizeVolume", p.toURLValues()) - if err != nil { - return nil, err - } - - var r ResizeVolumeResponse - if err := json.Unmarshal(resp, &r); err != nil { - return nil, err - } - - // If we have a async client, we need to wait for the async result - if s.cs.async { - b, err := s.cs.GetAsyncJobResult(r.JobID, s.cs.timeout) - if err != nil { - if err == AsyncTimeoutErr { - return &r, err - } - return nil, err - } - - b, err = getRawValue(b) - if err != nil { - return nil, err - } - - if err := json.Unmarshal(b, &r); err != nil { - return nil, err - } - } - return &r, nil -} - -type ResizeVolumeResponse struct { - JobID string `json:"jobid,omitempty"` - Account string `json:"account,omitempty"` - Attached string `json:"attached,omitempty"` - Chaininfo string `json:"chaininfo,omitempty"` - Created string `json:"created,omitempty"` - Destroyed bool `json:"destroyed,omitempty"` - Deviceid int64 `json:"deviceid,omitempty"` - DiskBytesReadRate int64 `json:"diskBytesReadRate,omitempty"` - DiskBytesWriteRate int64 `json:"diskBytesWriteRate,omitempty"` - DiskIopsReadRate int64 `json:"diskIopsReadRate,omitempty"` - DiskIopsWriteRate int64 `json:"diskIopsWriteRate,omitempty"` - Diskofferingdisplaytext string `json:"diskofferingdisplaytext,omitempty"` - Diskofferingid string `json:"diskofferingid,omitempty"` - Diskofferingname string `json:"diskofferingname,omitempty"` - Displayvolume bool `json:"displayvolume,omitempty"` - Domain string `json:"domain,omitempty"` - Domainid string `json:"domainid,omitempty"` - Hypervisor string `json:"hypervisor,omitempty"` - Id string `json:"id,omitempty"` - Isextractable bool `json:"isextractable,omitempty"` - Isodisplaytext string `json:"isodisplaytext,omitempty"` - Isoid string `json:"isoid,omitempty"` - Isoname string `json:"isoname,omitempty"` - Maxiops int64 `json:"maxiops,omitempty"` - Miniops int64 `json:"miniops,omitempty"` - Name string `json:"name,omitempty"` - Path string `json:"path,omitempty"` - Project string `json:"project,omitempty"` - Projectid string `json:"projectid,omitempty"` - Provisioningtype string `json:"provisioningtype,omitempty"` - Quiescevm bool `json:"quiescevm,omitempty"` - Serviceofferingdisplaytext string `json:"serviceofferingdisplaytext,omitempty"` - Serviceofferingid string `json:"serviceofferingid,omitempty"` - Serviceofferingname string `json:"serviceofferingname,omitempty"` - Size int64 `json:"size,omitempty"` - Snapshotid string `json:"snapshotid,omitempty"` - State string `json:"state,omitempty"` - Status string `json:"status,omitempty"` - Storage string `json:"storage,omitempty"` - Storageid string `json:"storageid,omitempty"` - Storagetype string `json:"storagetype,omitempty"` - Tags []struct { - Account string `json:"account,omitempty"` - Customer string `json:"customer,omitempty"` - Domain string `json:"domain,omitempty"` - Domainid string `json:"domainid,omitempty"` - Key string `json:"key,omitempty"` - Project string `json:"project,omitempty"` - Projectid string `json:"projectid,omitempty"` - Resourceid string `json:"resourceid,omitempty"` - Resourcetype string `json:"resourcetype,omitempty"` - Value string `json:"value,omitempty"` - } `json:"tags,omitempty"` - Templatedisplaytext string `json:"templatedisplaytext,omitempty"` - Templateid string `json:"templateid,omitempty"` - Templatename string `json:"templatename,omitempty"` - Type string `json:"type,omitempty"` - Virtualmachineid string `json:"virtualmachineid,omitempty"` - Vmdisplayname string `json:"vmdisplayname,omitempty"` - Vmname string `json:"vmname,omitempty"` - Vmstate string `json:"vmstate,omitempty"` - Zoneid string `json:"zoneid,omitempty"` - Zonename string `json:"zonename,omitempty"` -} - -type UpdateVolumeParams struct { - p map[string]interface{} -} - -func (p *UpdateVolumeParams) toURLValues() url.Values { - u := url.Values{} - if p.p == nil { - return u - } - if v, found := p.p["chaininfo"]; found { - u.Set("chaininfo", v.(string)) - } - if v, found := p.p["customid"]; found { - u.Set("customid", v.(string)) - } - if v, found := p.p["displayvolume"]; found { - vv := strconv.FormatBool(v.(bool)) - u.Set("displayvolume", vv) - } - if v, found := p.p["id"]; found { - u.Set("id", v.(string)) - } - if v, found := p.p["path"]; found { - u.Set("path", v.(string)) - } - if v, found := p.p["state"]; found { - u.Set("state", v.(string)) - } - if v, found := p.p["storageid"]; found { - u.Set("storageid", v.(string)) - } - return u -} - -func (p *UpdateVolumeParams) SetChaininfo(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["chaininfo"] = v - return -} - -func (p *UpdateVolumeParams) SetCustomid(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["customid"] = v - return -} - -func (p *UpdateVolumeParams) SetDisplayvolume(v bool) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["displayvolume"] = v - return -} - -func (p *UpdateVolumeParams) SetId(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["id"] = v - return -} - -func (p *UpdateVolumeParams) SetPath(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["path"] = v - return -} - -func (p *UpdateVolumeParams) SetState(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["state"] = v - return -} - -func (p *UpdateVolumeParams) SetStorageid(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["storageid"] = v - return -} - -// You should always use this function to get a new UpdateVolumeParams instance, -// as then you are sure you have configured all required params -func (s *VolumeService) NewUpdateVolumeParams() *UpdateVolumeParams { - p := &UpdateVolumeParams{} - p.p = make(map[string]interface{}) - return p -} - -// Updates the volume. -func (s *VolumeService) UpdateVolume(p *UpdateVolumeParams) (*UpdateVolumeResponse, error) { - resp, err := s.cs.newRequest("updateVolume", p.toURLValues()) - if err != nil { - return nil, err - } - - var r UpdateVolumeResponse - if err := json.Unmarshal(resp, &r); err != nil { - return nil, err - } - - // If we have a async client, we need to wait for the async result - if s.cs.async { - b, err := s.cs.GetAsyncJobResult(r.JobID, s.cs.timeout) - if err != nil { - if err == AsyncTimeoutErr { - return &r, err - } - return nil, err - } - - b, err = getRawValue(b) - if err != nil { - return nil, err - } - - if err := json.Unmarshal(b, &r); err != nil { - return nil, err - } - } - return &r, nil -} - -type UpdateVolumeResponse struct { - JobID string `json:"jobid,omitempty"` - Account string `json:"account,omitempty"` - Attached string `json:"attached,omitempty"` - Chaininfo string `json:"chaininfo,omitempty"` - Created string `json:"created,omitempty"` - Destroyed bool `json:"destroyed,omitempty"` - Deviceid int64 `json:"deviceid,omitempty"` - DiskBytesReadRate int64 `json:"diskBytesReadRate,omitempty"` - DiskBytesWriteRate int64 `json:"diskBytesWriteRate,omitempty"` - DiskIopsReadRate int64 `json:"diskIopsReadRate,omitempty"` - DiskIopsWriteRate int64 `json:"diskIopsWriteRate,omitempty"` - Diskofferingdisplaytext string `json:"diskofferingdisplaytext,omitempty"` - Diskofferingid string `json:"diskofferingid,omitempty"` - Diskofferingname string `json:"diskofferingname,omitempty"` - Displayvolume bool `json:"displayvolume,omitempty"` - Domain string `json:"domain,omitempty"` - Domainid string `json:"domainid,omitempty"` - Hypervisor string `json:"hypervisor,omitempty"` - Id string `json:"id,omitempty"` - Isextractable bool `json:"isextractable,omitempty"` - Isodisplaytext string `json:"isodisplaytext,omitempty"` - Isoid string `json:"isoid,omitempty"` - Isoname string `json:"isoname,omitempty"` - Maxiops int64 `json:"maxiops,omitempty"` - Miniops int64 `json:"miniops,omitempty"` - Name string `json:"name,omitempty"` - Path string `json:"path,omitempty"` - Project string `json:"project,omitempty"` - Projectid string `json:"projectid,omitempty"` - Provisioningtype string `json:"provisioningtype,omitempty"` - Quiescevm bool `json:"quiescevm,omitempty"` - Serviceofferingdisplaytext string `json:"serviceofferingdisplaytext,omitempty"` - Serviceofferingid string `json:"serviceofferingid,omitempty"` - Serviceofferingname string `json:"serviceofferingname,omitempty"` - Size int64 `json:"size,omitempty"` - Snapshotid string `json:"snapshotid,omitempty"` - State string `json:"state,omitempty"` - Status string `json:"status,omitempty"` - Storage string `json:"storage,omitempty"` - Storageid string `json:"storageid,omitempty"` - Storagetype string `json:"storagetype,omitempty"` - Tags []struct { - Account string `json:"account,omitempty"` - Customer string `json:"customer,omitempty"` - Domain string `json:"domain,omitempty"` - Domainid string `json:"domainid,omitempty"` - Key string `json:"key,omitempty"` - Project string `json:"project,omitempty"` - Projectid string `json:"projectid,omitempty"` - Resourceid string `json:"resourceid,omitempty"` - Resourcetype string `json:"resourcetype,omitempty"` - Value string `json:"value,omitempty"` - } `json:"tags,omitempty"` - Templatedisplaytext string `json:"templatedisplaytext,omitempty"` - Templateid string `json:"templateid,omitempty"` - Templatename string `json:"templatename,omitempty"` - Type string `json:"type,omitempty"` - Virtualmachineid string `json:"virtualmachineid,omitempty"` - Vmdisplayname string `json:"vmdisplayname,omitempty"` - Vmname string `json:"vmname,omitempty"` - Vmstate string `json:"vmstate,omitempty"` - Zoneid string `json:"zoneid,omitempty"` - Zonename string `json:"zonename,omitempty"` +type GetPathForVolumeResponse struct { + Path string `json:"path"` } type GetSolidFireVolumeSizeParams struct { @@ -1965,23 +840,12 @@ func (p *GetSolidFireVolumeSizeParams) toURLValues() url.Values { if p.p == nil { return u } - if v, found := p.p["storageid"]; found { - u.Set("storageid", v.(string)) - } if v, found := p.p["volumeid"]; found { u.Set("volumeid", v.(string)) } return u } -func (p *GetSolidFireVolumeSizeParams) SetStorageid(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["storageid"] = v - return -} - func (p *GetSolidFireVolumeSizeParams) SetVolumeid(v string) { if p.p == nil { p.p = make(map[string]interface{}) @@ -1992,10 +856,9 @@ func (p *GetSolidFireVolumeSizeParams) SetVolumeid(v string) { // You should always use this function to get a new GetSolidFireVolumeSizeParams instance, // as then you are sure you have configured all required params -func (s *VolumeService) NewGetSolidFireVolumeSizeParams(storageid string, volumeid string) *GetSolidFireVolumeSizeParams { +func (s *VolumeService) NewGetSolidFireVolumeSizeParams(volumeid string) *GetSolidFireVolumeSizeParams { p := &GetSolidFireVolumeSizeParams{} p.p = make(map[string]interface{}) - p.p["storageid"] = storageid p.p["volumeid"] = volumeid return p } @@ -2011,123 +874,12 @@ func (s *VolumeService) GetSolidFireVolumeSize(p *GetSolidFireVolumeSizeParams) if err := json.Unmarshal(resp, &r); err != nil { return nil, err } + return &r, nil } type GetSolidFireVolumeSizeResponse struct { - SolidFireVolumeSize int64 `json:"solidFireVolumeSize,omitempty"` -} - -type GetSolidFireVolumeAccessGroupIdParams struct { - p map[string]interface{} -} - -func (p *GetSolidFireVolumeAccessGroupIdParams) toURLValues() url.Values { - u := url.Values{} - if p.p == nil { - return u - } - if v, found := p.p["clusterid"]; found { - u.Set("clusterid", v.(string)) - } - if v, found := p.p["storageid"]; found { - u.Set("storageid", v.(string)) - } - return u -} - -func (p *GetSolidFireVolumeAccessGroupIdParams) SetClusterid(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["clusterid"] = v - return -} - -func (p *GetSolidFireVolumeAccessGroupIdParams) SetStorageid(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["storageid"] = v - return -} - -// You should always use this function to get a new GetSolidFireVolumeAccessGroupIdParams instance, -// as then you are sure you have configured all required params -func (s *VolumeService) NewGetSolidFireVolumeAccessGroupIdParams(clusterid string, storageid string) *GetSolidFireVolumeAccessGroupIdParams { - p := &GetSolidFireVolumeAccessGroupIdParams{} - p.p = make(map[string]interface{}) - p.p["clusterid"] = clusterid - p.p["storageid"] = storageid - return p -} - -// Get the SF Volume Access Group ID -func (s *VolumeService) GetSolidFireVolumeAccessGroupId(p *GetSolidFireVolumeAccessGroupIdParams) (*GetSolidFireVolumeAccessGroupIdResponse, error) { - resp, err := s.cs.newRequest("getSolidFireVolumeAccessGroupId", p.toURLValues()) - if err != nil { - return nil, err - } - - var r GetSolidFireVolumeAccessGroupIdResponse - if err := json.Unmarshal(resp, &r); err != nil { - return nil, err - } - return &r, nil -} - -type GetSolidFireVolumeAccessGroupIdResponse struct { - SolidFireVolumeAccessGroupId int64 `json:"solidFireVolumeAccessGroupId,omitempty"` -} - -type GetSolidFireVolumeIscsiNameParams struct { - p map[string]interface{} -} - -func (p *GetSolidFireVolumeIscsiNameParams) toURLValues() url.Values { - u := url.Values{} - if p.p == nil { - return u - } - if v, found := p.p["volumeid"]; found { - u.Set("volumeid", v.(string)) - } - return u -} - -func (p *GetSolidFireVolumeIscsiNameParams) SetVolumeid(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["volumeid"] = v - return -} - -// You should always use this function to get a new GetSolidFireVolumeIscsiNameParams instance, -// as then you are sure you have configured all required params -func (s *VolumeService) NewGetSolidFireVolumeIscsiNameParams(volumeid string) *GetSolidFireVolumeIscsiNameParams { - p := &GetSolidFireVolumeIscsiNameParams{} - p.p = make(map[string]interface{}) - p.p["volumeid"] = volumeid - return p -} - -// Get SolidFire Volume's Iscsi Name -func (s *VolumeService) GetSolidFireVolumeIscsiName(p *GetSolidFireVolumeIscsiNameParams) (*GetSolidFireVolumeIscsiNameResponse, error) { - resp, err := s.cs.newRequest("getSolidFireVolumeIscsiName", p.toURLValues()) - if err != nil { - return nil, err - } - - var r GetSolidFireVolumeIscsiNameResponse - if err := json.Unmarshal(resp, &r); err != nil { - return nil, err - } - return &r, nil -} - -type GetSolidFireVolumeIscsiNameResponse struct { - SolidFireVolumeIscsiName string `json:"solidFireVolumeIscsiName,omitempty"` + SolidFireVolumeSize int64 `json:"solidFireVolumeSize"` } type GetUploadParamsForVolumeParams struct { @@ -2263,13 +1015,1253 @@ func (s *VolumeService) GetUploadParamsForVolume(p *GetUploadParamsForVolumePara if err := json.Unmarshal(resp, &r); err != nil { return nil, err } + return &r, nil } type GetUploadParamsForVolumeResponse struct { - Expires string `json:"expires,omitempty"` - Id string `json:"id,omitempty"` - Metadata string `json:"metadata,omitempty"` - PostURL string `json:"postURL,omitempty"` - Signature string `json:"signature,omitempty"` + Expires string `json:"expires"` + Id string `json:"id"` + Metadata string `json:"metadata"` + PostURL string `json:"postURL"` + Signature string `json:"signature"` +} + +type GetVolumeiScsiNameParams struct { + p map[string]interface{} +} + +func (p *GetVolumeiScsiNameParams) toURLValues() url.Values { + u := url.Values{} + if p.p == nil { + return u + } + if v, found := p.p["volumeid"]; found { + u.Set("volumeid", v.(string)) + } + return u +} + +func (p *GetVolumeiScsiNameParams) SetVolumeid(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["volumeid"] = v + return +} + +// You should always use this function to get a new GetVolumeiScsiNameParams instance, +// as then you are sure you have configured all required params +func (s *VolumeService) NewGetVolumeiScsiNameParams(volumeid string) *GetVolumeiScsiNameParams { + p := &GetVolumeiScsiNameParams{} + p.p = make(map[string]interface{}) + p.p["volumeid"] = volumeid + return p +} + +// Get Volume's iSCSI Name +func (s *VolumeService) GetVolumeiScsiName(p *GetVolumeiScsiNameParams) (*GetVolumeiScsiNameResponse, error) { + resp, err := s.cs.newRequest("getVolumeiScsiName", p.toURLValues()) + if err != nil { + return nil, err + } + + var r GetVolumeiScsiNameResponse + if err := json.Unmarshal(resp, &r); err != nil { + return nil, err + } + + return &r, nil +} + +type GetVolumeiScsiNameResponse struct { + VolumeiScsiName string `json:"volumeiScsiName"` +} + +type ListVolumesParams struct { + p map[string]interface{} +} + +func (p *ListVolumesParams) toURLValues() url.Values { + u := url.Values{} + if p.p == nil { + return u + } + if v, found := p.p["account"]; found { + u.Set("account", v.(string)) + } + if v, found := p.p["clusterid"]; found { + u.Set("clusterid", v.(string)) + } + if v, found := p.p["diskofferingid"]; found { + u.Set("diskofferingid", v.(string)) + } + if v, found := p.p["displayvolume"]; found { + vv := strconv.FormatBool(v.(bool)) + u.Set("displayvolume", vv) + } + if v, found := p.p["domainid"]; found { + u.Set("domainid", v.(string)) + } + if v, found := p.p["hostid"]; found { + u.Set("hostid", v.(string)) + } + if v, found := p.p["id"]; found { + u.Set("id", v.(string)) + } + if v, found := p.p["ids"]; found { + vv := strings.Join(v.([]string), ",") + u.Set("ids", vv) + } + if v, found := p.p["isrecursive"]; found { + vv := strconv.FormatBool(v.(bool)) + u.Set("isrecursive", vv) + } + if v, found := p.p["keyword"]; found { + u.Set("keyword", v.(string)) + } + if v, found := p.p["listall"]; found { + vv := strconv.FormatBool(v.(bool)) + u.Set("listall", vv) + } + if v, found := p.p["name"]; found { + u.Set("name", v.(string)) + } + if v, found := p.p["page"]; found { + vv := strconv.Itoa(v.(int)) + u.Set("page", vv) + } + if v, found := p.p["pagesize"]; found { + vv := strconv.Itoa(v.(int)) + u.Set("pagesize", vv) + } + if v, found := p.p["podid"]; found { + u.Set("podid", v.(string)) + } + if v, found := p.p["projectid"]; found { + u.Set("projectid", v.(string)) + } + if v, found := p.p["storageid"]; found { + u.Set("storageid", v.(string)) + } + if v, found := p.p["tags"]; found { + i := 0 + for k, vv := range v.(map[string]string) { + u.Set(fmt.Sprintf("tags[%d].key", i), k) + u.Set(fmt.Sprintf("tags[%d].value", i), vv) + i++ + } + } + if v, found := p.p["type"]; found { + u.Set("type", v.(string)) + } + if v, found := p.p["virtualmachineid"]; found { + u.Set("virtualmachineid", v.(string)) + } + if v, found := p.p["zoneid"]; found { + u.Set("zoneid", v.(string)) + } + return u +} + +func (p *ListVolumesParams) SetAccount(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["account"] = v + return +} + +func (p *ListVolumesParams) SetClusterid(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["clusterid"] = v + return +} + +func (p *ListVolumesParams) SetDiskofferingid(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["diskofferingid"] = v + return +} + +func (p *ListVolumesParams) SetDisplayvolume(v bool) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["displayvolume"] = v + return +} + +func (p *ListVolumesParams) SetDomainid(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["domainid"] = v + return +} + +func (p *ListVolumesParams) SetHostid(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["hostid"] = v + return +} + +func (p *ListVolumesParams) SetId(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["id"] = v + return +} + +func (p *ListVolumesParams) SetIds(v []string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["ids"] = v + return +} + +func (p *ListVolumesParams) SetIsrecursive(v bool) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["isrecursive"] = v + return +} + +func (p *ListVolumesParams) SetKeyword(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["keyword"] = v + return +} + +func (p *ListVolumesParams) SetListall(v bool) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["listall"] = v + return +} + +func (p *ListVolumesParams) SetName(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["name"] = v + return +} + +func (p *ListVolumesParams) SetPage(v int) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["page"] = v + return +} + +func (p *ListVolumesParams) SetPagesize(v int) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["pagesize"] = v + return +} + +func (p *ListVolumesParams) SetPodid(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["podid"] = v + return +} + +func (p *ListVolumesParams) SetProjectid(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["projectid"] = v + return +} + +func (p *ListVolumesParams) SetStorageid(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["storageid"] = v + return +} + +func (p *ListVolumesParams) SetTags(v map[string]string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["tags"] = v + return +} + +func (p *ListVolumesParams) SetType(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["type"] = v + return +} + +func (p *ListVolumesParams) SetVirtualmachineid(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["virtualmachineid"] = v + return +} + +func (p *ListVolumesParams) SetZoneid(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["zoneid"] = v + return +} + +// You should always use this function to get a new ListVolumesParams instance, +// as then you are sure you have configured all required params +func (s *VolumeService) NewListVolumesParams() *ListVolumesParams { + p := &ListVolumesParams{} + p.p = make(map[string]interface{}) + return p +} + +// This is a courtesy helper function, which in some cases may not work as expected! +func (s *VolumeService) GetVolumeID(name string, opts ...OptionFunc) (string, int, error) { + p := &ListVolumesParams{} + p.p = make(map[string]interface{}) + + p.p["name"] = name + + for _, fn := range append(s.cs.options, opts...) { + if err := fn(s.cs, p); err != nil { + return "", -1, err + } + } + + l, err := s.ListVolumes(p) + if err != nil { + return "", -1, err + } + + if l.Count == 0 { + return "", l.Count, fmt.Errorf("No match found for %s: %+v", name, l) + } + + if l.Count == 1 { + return l.Volumes[0].Id, l.Count, nil + } + + if l.Count > 1 { + for _, v := range l.Volumes { + if v.Name == name { + return v.Id, l.Count, nil + } + } + } + return "", l.Count, fmt.Errorf("Could not find an exact match for %s: %+v", name, l) +} + +// This is a courtesy helper function, which in some cases may not work as expected! +func (s *VolumeService) GetVolumeByName(name string, opts ...OptionFunc) (*Volume, int, error) { + id, count, err := s.GetVolumeID(name, opts...) + if err != nil { + return nil, count, err + } + + r, count, err := s.GetVolumeByID(id, opts...) + if err != nil { + return nil, count, err + } + return r, count, nil +} + +// This is a courtesy helper function, which in some cases may not work as expected! +func (s *VolumeService) GetVolumeByID(id string, opts ...OptionFunc) (*Volume, int, error) { + p := &ListVolumesParams{} + p.p = make(map[string]interface{}) + + p.p["id"] = id + + for _, fn := range append(s.cs.options, opts...) { + if err := fn(s.cs, p); err != nil { + return nil, -1, err + } + } + + l, err := s.ListVolumes(p) + if err != nil { + if strings.Contains(err.Error(), fmt.Sprintf( + "Invalid parameter id value=%s due to incorrect long value format, "+ + "or entity does not exist", id)) { + return nil, 0, fmt.Errorf("No match found for %s: %+v", id, l) + } + return nil, -1, err + } + + if l.Count == 0 { + return nil, l.Count, fmt.Errorf("No match found for %s: %+v", id, l) + } + + if l.Count == 1 { + return l.Volumes[0], l.Count, nil + } + return nil, l.Count, fmt.Errorf("There is more then one result for Volume UUID: %s!", id) +} + +// Lists all volumes. +func (s *VolumeService) ListVolumes(p *ListVolumesParams) (*ListVolumesResponse, error) { + resp, err := s.cs.newRequest("listVolumes", p.toURLValues()) + if err != nil { + return nil, err + } + + var r ListVolumesResponse + if err := json.Unmarshal(resp, &r); err != nil { + return nil, err + } + + return &r, nil +} + +type ListVolumesResponse struct { + Count int `json:"count"` + Volumes []*Volume `json:"volume"` +} + +type Volume struct { + Account string `json:"account"` + Attached string `json:"attached"` + Chaininfo string `json:"chaininfo"` + Clusterid string `json:"clusterid"` + Clustername string `json:"clustername"` + Created string `json:"created"` + Destroyed bool `json:"destroyed"` + Deviceid int64 `json:"deviceid"` + DiskBytesReadRate int64 `json:"diskBytesReadRate"` + DiskBytesWriteRate int64 `json:"diskBytesWriteRate"` + DiskIopsReadRate int64 `json:"diskIopsReadRate"` + DiskIopsWriteRate int64 `json:"diskIopsWriteRate"` + Diskofferingdisplaytext string `json:"diskofferingdisplaytext"` + Diskofferingid string `json:"diskofferingid"` + Diskofferingname string `json:"diskofferingname"` + Displayvolume bool `json:"displayvolume"` + Domain string `json:"domain"` + Domainid string `json:"domainid"` + Hypervisor string `json:"hypervisor"` + Id string `json:"id"` + Isextractable bool `json:"isextractable"` + Isodisplaytext string `json:"isodisplaytext"` + Isoid string `json:"isoid"` + Isoname string `json:"isoname"` + Maxiops int64 `json:"maxiops"` + Miniops int64 `json:"miniops"` + Name string `json:"name"` + Path string `json:"path"` + Physicalsize int64 `json:"physicalsize"` + Podid string `json:"podid"` + Podname string `json:"podname"` + Project string `json:"project"` + Projectid string `json:"projectid"` + Provisioningtype string `json:"provisioningtype"` + Quiescevm bool `json:"quiescevm"` + Serviceofferingdisplaytext string `json:"serviceofferingdisplaytext"` + Serviceofferingid string `json:"serviceofferingid"` + Serviceofferingname string `json:"serviceofferingname"` + Size int64 `json:"size"` + Snapshotid string `json:"snapshotid"` + State string `json:"state"` + Status string `json:"status"` + Storage string `json:"storage"` + Storageid string `json:"storageid"` + Storagetype string `json:"storagetype"` + Templatedisplaytext string `json:"templatedisplaytext"` + Templateid string `json:"templateid"` + Templatename string `json:"templatename"` + Type string `json:"type"` + Utilization string `json:"utilization"` + Virtualmachineid string `json:"virtualmachineid"` + Virtualsize int64 `json:"virtualsize"` + Vmdisplayname string `json:"vmdisplayname"` + Vmname string `json:"vmname"` + Vmstate string `json:"vmstate"` + Zoneid string `json:"zoneid"` + Zonename string `json:"zonename"` +} + +type MigrateVolumeParams struct { + p map[string]interface{} +} + +func (p *MigrateVolumeParams) toURLValues() url.Values { + u := url.Values{} + if p.p == nil { + return u + } + if v, found := p.p["livemigrate"]; found { + vv := strconv.FormatBool(v.(bool)) + u.Set("livemigrate", vv) + } + if v, found := p.p["storageid"]; found { + u.Set("storageid", v.(string)) + } + if v, found := p.p["volumeid"]; found { + u.Set("volumeid", v.(string)) + } + return u +} + +func (p *MigrateVolumeParams) SetLivemigrate(v bool) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["livemigrate"] = v + return +} + +func (p *MigrateVolumeParams) SetStorageid(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["storageid"] = v + return +} + +func (p *MigrateVolumeParams) SetVolumeid(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["volumeid"] = v + return +} + +// You should always use this function to get a new MigrateVolumeParams instance, +// as then you are sure you have configured all required params +func (s *VolumeService) NewMigrateVolumeParams(storageid string, volumeid string) *MigrateVolumeParams { + p := &MigrateVolumeParams{} + p.p = make(map[string]interface{}) + p.p["storageid"] = storageid + p.p["volumeid"] = volumeid + return p +} + +// Migrate volume +func (s *VolumeService) MigrateVolume(p *MigrateVolumeParams) (*MigrateVolumeResponse, error) { + resp, err := s.cs.newRequest("migrateVolume", p.toURLValues()) + if err != nil { + return nil, err + } + + var r MigrateVolumeResponse + if err := json.Unmarshal(resp, &r); err != nil { + return nil, err + } + + // If we have a async client, we need to wait for the async result + if s.cs.async { + b, err := s.cs.GetAsyncJobResult(r.JobID, s.cs.timeout) + if err != nil { + if err == AsyncTimeoutErr { + return &r, err + } + return nil, err + } + + b, err = getRawValue(b) + if err != nil { + return nil, err + } + + if err := json.Unmarshal(b, &r); err != nil { + return nil, err + } + } + + return &r, nil +} + +type MigrateVolumeResponse struct { + JobID string `json:"jobid"` + Account string `json:"account"` + Attached string `json:"attached"` + Chaininfo string `json:"chaininfo"` + Clusterid string `json:"clusterid"` + Clustername string `json:"clustername"` + Created string `json:"created"` + Destroyed bool `json:"destroyed"` + Deviceid int64 `json:"deviceid"` + DiskBytesReadRate int64 `json:"diskBytesReadRate"` + DiskBytesWriteRate int64 `json:"diskBytesWriteRate"` + DiskIopsReadRate int64 `json:"diskIopsReadRate"` + DiskIopsWriteRate int64 `json:"diskIopsWriteRate"` + Diskofferingdisplaytext string `json:"diskofferingdisplaytext"` + Diskofferingid string `json:"diskofferingid"` + Diskofferingname string `json:"diskofferingname"` + Displayvolume bool `json:"displayvolume"` + Domain string `json:"domain"` + Domainid string `json:"domainid"` + Hypervisor string `json:"hypervisor"` + Id string `json:"id"` + Isextractable bool `json:"isextractable"` + Isodisplaytext string `json:"isodisplaytext"` + Isoid string `json:"isoid"` + Isoname string `json:"isoname"` + Maxiops int64 `json:"maxiops"` + Miniops int64 `json:"miniops"` + Name string `json:"name"` + Path string `json:"path"` + Physicalsize int64 `json:"physicalsize"` + Podid string `json:"podid"` + Podname string `json:"podname"` + Project string `json:"project"` + Projectid string `json:"projectid"` + Provisioningtype string `json:"provisioningtype"` + Quiescevm bool `json:"quiescevm"` + Serviceofferingdisplaytext string `json:"serviceofferingdisplaytext"` + Serviceofferingid string `json:"serviceofferingid"` + Serviceofferingname string `json:"serviceofferingname"` + Size int64 `json:"size"` + Snapshotid string `json:"snapshotid"` + State string `json:"state"` + Status string `json:"status"` + Storage string `json:"storage"` + Storageid string `json:"storageid"` + Storagetype string `json:"storagetype"` + Templatedisplaytext string `json:"templatedisplaytext"` + Templateid string `json:"templateid"` + Templatename string `json:"templatename"` + Type string `json:"type"` + Utilization string `json:"utilization"` + Virtualmachineid string `json:"virtualmachineid"` + Virtualsize int64 `json:"virtualsize"` + Vmdisplayname string `json:"vmdisplayname"` + Vmname string `json:"vmname"` + Vmstate string `json:"vmstate"` + Zoneid string `json:"zoneid"` + Zonename string `json:"zonename"` +} + +type ResizeVolumeParams struct { + p map[string]interface{} +} + +func (p *ResizeVolumeParams) toURLValues() url.Values { + u := url.Values{} + if p.p == nil { + return u + } + if v, found := p.p["diskofferingid"]; found { + u.Set("diskofferingid", v.(string)) + } + if v, found := p.p["id"]; found { + u.Set("id", v.(string)) + } + if v, found := p.p["maxiops"]; found { + vv := strconv.FormatInt(v.(int64), 10) + u.Set("maxiops", vv) + } + if v, found := p.p["miniops"]; found { + vv := strconv.FormatInt(v.(int64), 10) + u.Set("miniops", vv) + } + if v, found := p.p["shrinkok"]; found { + vv := strconv.FormatBool(v.(bool)) + u.Set("shrinkok", vv) + } + if v, found := p.p["size"]; found { + vv := strconv.FormatInt(v.(int64), 10) + u.Set("size", vv) + } + return u +} + +func (p *ResizeVolumeParams) SetDiskofferingid(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["diskofferingid"] = v + return +} + +func (p *ResizeVolumeParams) SetId(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["id"] = v + return +} + +func (p *ResizeVolumeParams) SetMaxiops(v int64) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["maxiops"] = v + return +} + +func (p *ResizeVolumeParams) SetMiniops(v int64) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["miniops"] = v + return +} + +func (p *ResizeVolumeParams) SetShrinkok(v bool) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["shrinkok"] = v + return +} + +func (p *ResizeVolumeParams) SetSize(v int64) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["size"] = v + return +} + +// You should always use this function to get a new ResizeVolumeParams instance, +// as then you are sure you have configured all required params +func (s *VolumeService) NewResizeVolumeParams(id string) *ResizeVolumeParams { + p := &ResizeVolumeParams{} + p.p = make(map[string]interface{}) + p.p["id"] = id + return p +} + +// Resizes a volume +func (s *VolumeService) ResizeVolume(p *ResizeVolumeParams) (*ResizeVolumeResponse, error) { + resp, err := s.cs.newRequest("resizeVolume", p.toURLValues()) + if err != nil { + return nil, err + } + + var r ResizeVolumeResponse + if err := json.Unmarshal(resp, &r); err != nil { + return nil, err + } + + // If we have a async client, we need to wait for the async result + if s.cs.async { + b, err := s.cs.GetAsyncJobResult(r.JobID, s.cs.timeout) + if err != nil { + if err == AsyncTimeoutErr { + return &r, err + } + return nil, err + } + + b, err = getRawValue(b) + if err != nil { + return nil, err + } + + if err := json.Unmarshal(b, &r); err != nil { + return nil, err + } + } + + return &r, nil +} + +type ResizeVolumeResponse struct { + JobID string `json:"jobid"` + Account string `json:"account"` + Attached string `json:"attached"` + Chaininfo string `json:"chaininfo"` + Clusterid string `json:"clusterid"` + Clustername string `json:"clustername"` + Created string `json:"created"` + Destroyed bool `json:"destroyed"` + Deviceid int64 `json:"deviceid"` + DiskBytesReadRate int64 `json:"diskBytesReadRate"` + DiskBytesWriteRate int64 `json:"diskBytesWriteRate"` + DiskIopsReadRate int64 `json:"diskIopsReadRate"` + DiskIopsWriteRate int64 `json:"diskIopsWriteRate"` + Diskofferingdisplaytext string `json:"diskofferingdisplaytext"` + Diskofferingid string `json:"diskofferingid"` + Diskofferingname string `json:"diskofferingname"` + Displayvolume bool `json:"displayvolume"` + Domain string `json:"domain"` + Domainid string `json:"domainid"` + Hypervisor string `json:"hypervisor"` + Id string `json:"id"` + Isextractable bool `json:"isextractable"` + Isodisplaytext string `json:"isodisplaytext"` + Isoid string `json:"isoid"` + Isoname string `json:"isoname"` + Maxiops int64 `json:"maxiops"` + Miniops int64 `json:"miniops"` + Name string `json:"name"` + Path string `json:"path"` + Physicalsize int64 `json:"physicalsize"` + Podid string `json:"podid"` + Podname string `json:"podname"` + Project string `json:"project"` + Projectid string `json:"projectid"` + Provisioningtype string `json:"provisioningtype"` + Quiescevm bool `json:"quiescevm"` + Serviceofferingdisplaytext string `json:"serviceofferingdisplaytext"` + Serviceofferingid string `json:"serviceofferingid"` + Serviceofferingname string `json:"serviceofferingname"` + Size int64 `json:"size"` + Snapshotid string `json:"snapshotid"` + State string `json:"state"` + Status string `json:"status"` + Storage string `json:"storage"` + Storageid string `json:"storageid"` + Storagetype string `json:"storagetype"` + Templatedisplaytext string `json:"templatedisplaytext"` + Templateid string `json:"templateid"` + Templatename string `json:"templatename"` + Type string `json:"type"` + Utilization string `json:"utilization"` + Virtualmachineid string `json:"virtualmachineid"` + Virtualsize int64 `json:"virtualsize"` + Vmdisplayname string `json:"vmdisplayname"` + Vmname string `json:"vmname"` + Vmstate string `json:"vmstate"` + Zoneid string `json:"zoneid"` + Zonename string `json:"zonename"` +} + +type UpdateVolumeParams struct { + p map[string]interface{} +} + +func (p *UpdateVolumeParams) toURLValues() url.Values { + u := url.Values{} + if p.p == nil { + return u + } + if v, found := p.p["chaininfo"]; found { + u.Set("chaininfo", v.(string)) + } + if v, found := p.p["customid"]; found { + u.Set("customid", v.(string)) + } + if v, found := p.p["displayvolume"]; found { + vv := strconv.FormatBool(v.(bool)) + u.Set("displayvolume", vv) + } + if v, found := p.p["id"]; found { + u.Set("id", v.(string)) + } + if v, found := p.p["path"]; found { + u.Set("path", v.(string)) + } + if v, found := p.p["state"]; found { + u.Set("state", v.(string)) + } + if v, found := p.p["storageid"]; found { + u.Set("storageid", v.(string)) + } + return u +} + +func (p *UpdateVolumeParams) SetChaininfo(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["chaininfo"] = v + return +} + +func (p *UpdateVolumeParams) SetCustomid(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["customid"] = v + return +} + +func (p *UpdateVolumeParams) SetDisplayvolume(v bool) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["displayvolume"] = v + return +} + +func (p *UpdateVolumeParams) SetId(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["id"] = v + return +} + +func (p *UpdateVolumeParams) SetPath(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["path"] = v + return +} + +func (p *UpdateVolumeParams) SetState(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["state"] = v + return +} + +func (p *UpdateVolumeParams) SetStorageid(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["storageid"] = v + return +} + +// You should always use this function to get a new UpdateVolumeParams instance, +// as then you are sure you have configured all required params +func (s *VolumeService) NewUpdateVolumeParams() *UpdateVolumeParams { + p := &UpdateVolumeParams{} + p.p = make(map[string]interface{}) + return p +} + +// Updates the volume. +func (s *VolumeService) UpdateVolume(p *UpdateVolumeParams) (*UpdateVolumeResponse, error) { + resp, err := s.cs.newRequest("updateVolume", p.toURLValues()) + if err != nil { + return nil, err + } + + var r UpdateVolumeResponse + if err := json.Unmarshal(resp, &r); err != nil { + return nil, err + } + + // If we have a async client, we need to wait for the async result + if s.cs.async { + b, err := s.cs.GetAsyncJobResult(r.JobID, s.cs.timeout) + if err != nil { + if err == AsyncTimeoutErr { + return &r, err + } + return nil, err + } + + b, err = getRawValue(b) + if err != nil { + return nil, err + } + + if err := json.Unmarshal(b, &r); err != nil { + return nil, err + } + } + + return &r, nil +} + +type UpdateVolumeResponse struct { + JobID string `json:"jobid"` + Account string `json:"account"` + Attached string `json:"attached"` + Chaininfo string `json:"chaininfo"` + Clusterid string `json:"clusterid"` + Clustername string `json:"clustername"` + Created string `json:"created"` + Destroyed bool `json:"destroyed"` + Deviceid int64 `json:"deviceid"` + DiskBytesReadRate int64 `json:"diskBytesReadRate"` + DiskBytesWriteRate int64 `json:"diskBytesWriteRate"` + DiskIopsReadRate int64 `json:"diskIopsReadRate"` + DiskIopsWriteRate int64 `json:"diskIopsWriteRate"` + Diskofferingdisplaytext string `json:"diskofferingdisplaytext"` + Diskofferingid string `json:"diskofferingid"` + Diskofferingname string `json:"diskofferingname"` + Displayvolume bool `json:"displayvolume"` + Domain string `json:"domain"` + Domainid string `json:"domainid"` + Hypervisor string `json:"hypervisor"` + Id string `json:"id"` + Isextractable bool `json:"isextractable"` + Isodisplaytext string `json:"isodisplaytext"` + Isoid string `json:"isoid"` + Isoname string `json:"isoname"` + Maxiops int64 `json:"maxiops"` + Miniops int64 `json:"miniops"` + Name string `json:"name"` + Path string `json:"path"` + Physicalsize int64 `json:"physicalsize"` + Podid string `json:"podid"` + Podname string `json:"podname"` + Project string `json:"project"` + Projectid string `json:"projectid"` + Provisioningtype string `json:"provisioningtype"` + Quiescevm bool `json:"quiescevm"` + Serviceofferingdisplaytext string `json:"serviceofferingdisplaytext"` + Serviceofferingid string `json:"serviceofferingid"` + Serviceofferingname string `json:"serviceofferingname"` + Size int64 `json:"size"` + Snapshotid string `json:"snapshotid"` + State string `json:"state"` + Status string `json:"status"` + Storage string `json:"storage"` + Storageid string `json:"storageid"` + Storagetype string `json:"storagetype"` + Templatedisplaytext string `json:"templatedisplaytext"` + Templateid string `json:"templateid"` + Templatename string `json:"templatename"` + Type string `json:"type"` + Utilization string `json:"utilization"` + Virtualmachineid string `json:"virtualmachineid"` + Virtualsize int64 `json:"virtualsize"` + Vmdisplayname string `json:"vmdisplayname"` + Vmname string `json:"vmname"` + Vmstate string `json:"vmstate"` + Zoneid string `json:"zoneid"` + Zonename string `json:"zonename"` +} + +type UploadVolumeParams struct { + p map[string]interface{} +} + +func (p *UploadVolumeParams) toURLValues() url.Values { + u := url.Values{} + if p.p == nil { + return u + } + if v, found := p.p["account"]; found { + u.Set("account", v.(string)) + } + if v, found := p.p["checksum"]; found { + u.Set("checksum", v.(string)) + } + if v, found := p.p["diskofferingid"]; found { + u.Set("diskofferingid", v.(string)) + } + if v, found := p.p["domainid"]; found { + u.Set("domainid", v.(string)) + } + if v, found := p.p["format"]; found { + u.Set("format", v.(string)) + } + if v, found := p.p["imagestoreuuid"]; found { + u.Set("imagestoreuuid", v.(string)) + } + if v, found := p.p["name"]; found { + u.Set("name", v.(string)) + } + if v, found := p.p["projectid"]; found { + u.Set("projectid", v.(string)) + } + if v, found := p.p["url"]; found { + u.Set("url", v.(string)) + } + if v, found := p.p["zoneid"]; found { + u.Set("zoneid", v.(string)) + } + return u +} + +func (p *UploadVolumeParams) SetAccount(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["account"] = v + return +} + +func (p *UploadVolumeParams) SetChecksum(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["checksum"] = v + return +} + +func (p *UploadVolumeParams) SetDiskofferingid(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["diskofferingid"] = v + return +} + +func (p *UploadVolumeParams) SetDomainid(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["domainid"] = v + return +} + +func (p *UploadVolumeParams) SetFormat(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["format"] = v + return +} + +func (p *UploadVolumeParams) SetImagestoreuuid(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["imagestoreuuid"] = v + return +} + +func (p *UploadVolumeParams) SetName(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["name"] = v + return +} + +func (p *UploadVolumeParams) SetProjectid(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["projectid"] = v + return +} + +func (p *UploadVolumeParams) SetUrl(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["url"] = v + return +} + +func (p *UploadVolumeParams) SetZoneid(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["zoneid"] = v + return +} + +// You should always use this function to get a new UploadVolumeParams instance, +// as then you are sure you have configured all required params +func (s *VolumeService) NewUploadVolumeParams(format string, name string, url string, zoneid string) *UploadVolumeParams { + p := &UploadVolumeParams{} + p.p = make(map[string]interface{}) + p.p["format"] = format + p.p["name"] = name + p.p["url"] = url + p.p["zoneid"] = zoneid + return p +} + +// Uploads a data disk. +func (s *VolumeService) UploadVolume(p *UploadVolumeParams) (*UploadVolumeResponse, error) { + resp, err := s.cs.newRequest("uploadVolume", p.toURLValues()) + if err != nil { + return nil, err + } + + var r UploadVolumeResponse + if err := json.Unmarshal(resp, &r); err != nil { + return nil, err + } + + // If we have a async client, we need to wait for the async result + if s.cs.async { + b, err := s.cs.GetAsyncJobResult(r.JobID, s.cs.timeout) + if err != nil { + if err == AsyncTimeoutErr { + return &r, err + } + return nil, err + } + + b, err = getRawValue(b) + if err != nil { + return nil, err + } + + if err := json.Unmarshal(b, &r); err != nil { + return nil, err + } + } + + return &r, nil +} + +type UploadVolumeResponse struct { + JobID string `json:"jobid"` + Account string `json:"account"` + Attached string `json:"attached"` + Chaininfo string `json:"chaininfo"` + Clusterid string `json:"clusterid"` + Clustername string `json:"clustername"` + Created string `json:"created"` + Destroyed bool `json:"destroyed"` + Deviceid int64 `json:"deviceid"` + DiskBytesReadRate int64 `json:"diskBytesReadRate"` + DiskBytesWriteRate int64 `json:"diskBytesWriteRate"` + DiskIopsReadRate int64 `json:"diskIopsReadRate"` + DiskIopsWriteRate int64 `json:"diskIopsWriteRate"` + Diskofferingdisplaytext string `json:"diskofferingdisplaytext"` + Diskofferingid string `json:"diskofferingid"` + Diskofferingname string `json:"diskofferingname"` + Displayvolume bool `json:"displayvolume"` + Domain string `json:"domain"` + Domainid string `json:"domainid"` + Hypervisor string `json:"hypervisor"` + Id string `json:"id"` + Isextractable bool `json:"isextractable"` + Isodisplaytext string `json:"isodisplaytext"` + Isoid string `json:"isoid"` + Isoname string `json:"isoname"` + Maxiops int64 `json:"maxiops"` + Miniops int64 `json:"miniops"` + Name string `json:"name"` + Path string `json:"path"` + Physicalsize int64 `json:"physicalsize"` + Podid string `json:"podid"` + Podname string `json:"podname"` + Project string `json:"project"` + Projectid string `json:"projectid"` + Provisioningtype string `json:"provisioningtype"` + Quiescevm bool `json:"quiescevm"` + Serviceofferingdisplaytext string `json:"serviceofferingdisplaytext"` + Serviceofferingid string `json:"serviceofferingid"` + Serviceofferingname string `json:"serviceofferingname"` + Size int64 `json:"size"` + Snapshotid string `json:"snapshotid"` + State string `json:"state"` + Status string `json:"status"` + Storage string `json:"storage"` + Storageid string `json:"storageid"` + Storagetype string `json:"storagetype"` + Templatedisplaytext string `json:"templatedisplaytext"` + Templateid string `json:"templateid"` + Templatename string `json:"templatename"` + Type string `json:"type"` + Utilization string `json:"utilization"` + Virtualmachineid string `json:"virtualmachineid"` + Virtualsize int64 `json:"virtualsize"` + Vmdisplayname string `json:"vmdisplayname"` + Vmname string `json:"vmname"` + Vmstate string `json:"vmstate"` + Zoneid string `json:"zoneid"` + Zonename string `json:"zonename"` } diff --git a/vendor/github.com/xanzy/go-cloudstack/cloudstack/ZoneService.go b/vendor/github.com/xanzy/go-cloudstack/cloudstack/ZoneService.go index d02e4dcd7..1d8029d41 100644 --- a/vendor/github.com/xanzy/go-cloudstack/cloudstack/ZoneService.go +++ b/vendor/github.com/xanzy/go-cloudstack/cloudstack/ZoneService.go @@ -1,5 +1,5 @@ // -// Copyright 2016, Sander van Harmelen +// Copyright 2018, Sander van Harmelen // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -215,55 +215,863 @@ func (s *ZoneService) CreateZone(p *CreateZoneParams) (*CreateZoneResponse, erro if err := json.Unmarshal(resp, &r); err != nil { return nil, err } + return &r, nil } type CreateZoneResponse struct { - Allocationstate string `json:"allocationstate,omitempty"` - Capacity []struct { - Capacitytotal int64 `json:"capacitytotal,omitempty"` - Capacityused int64 `json:"capacityused,omitempty"` - Clusterid string `json:"clusterid,omitempty"` - Clustername string `json:"clustername,omitempty"` - Percentused string `json:"percentused,omitempty"` - Podid string `json:"podid,omitempty"` - Podname string `json:"podname,omitempty"` - Type int `json:"type,omitempty"` - Zoneid string `json:"zoneid,omitempty"` - Zonename string `json:"zonename,omitempty"` - } `json:"capacity,omitempty"` - Description string `json:"description,omitempty"` - Dhcpprovider string `json:"dhcpprovider,omitempty"` - Displaytext string `json:"displaytext,omitempty"` - Dns1 string `json:"dns1,omitempty"` - Dns2 string `json:"dns2,omitempty"` - Domain string `json:"domain,omitempty"` - Domainid string `json:"domainid,omitempty"` - Domainname string `json:"domainname,omitempty"` - Guestcidraddress string `json:"guestcidraddress,omitempty"` - Id string `json:"id,omitempty"` - Internaldns1 string `json:"internaldns1,omitempty"` - Internaldns2 string `json:"internaldns2,omitempty"` - Ip6dns1 string `json:"ip6dns1,omitempty"` - Ip6dns2 string `json:"ip6dns2,omitempty"` - Localstorageenabled bool `json:"localstorageenabled,omitempty"` - Name string `json:"name,omitempty"` - Networktype string `json:"networktype,omitempty"` - Resourcedetails map[string]string `json:"resourcedetails,omitempty"` - Securitygroupsenabled bool `json:"securitygroupsenabled,omitempty"` - Tags []struct { - Account string `json:"account,omitempty"` - Customer string `json:"customer,omitempty"` - Domain string `json:"domain,omitempty"` - Domainid string `json:"domainid,omitempty"` - Key string `json:"key,omitempty"` - Project string `json:"project,omitempty"` - Projectid string `json:"projectid,omitempty"` - Resourceid string `json:"resourceid,omitempty"` - Resourcetype string `json:"resourcetype,omitempty"` - Value string `json:"value,omitempty"` - } `json:"tags,omitempty"` - Zonetoken string `json:"zonetoken,omitempty"` + Allocationstate string `json:"allocationstate"` + Capacity []CreateZoneResponseCapacity `json:"capacity"` + Description string `json:"description"` + Dhcpprovider string `json:"dhcpprovider"` + Displaytext string `json:"displaytext"` + Dns1 string `json:"dns1"` + Dns2 string `json:"dns2"` + Domain string `json:"domain"` + Domainid string `json:"domainid"` + Domainname string `json:"domainname"` + Guestcidraddress string `json:"guestcidraddress"` + Id string `json:"id"` + Internaldns1 string `json:"internaldns1"` + Internaldns2 string `json:"internaldns2"` + Ip6dns1 string `json:"ip6dns1"` + Ip6dns2 string `json:"ip6dns2"` + Localstorageenabled bool `json:"localstorageenabled"` + Name string `json:"name"` + Networktype string `json:"networktype"` + Resourcedetails map[string]string `json:"resourcedetails"` + Securitygroupsenabled bool `json:"securitygroupsenabled"` + Tags []Tags `json:"tags"` + Zonetoken string `json:"zonetoken"` +} + +type CreateZoneResponseCapacity struct { + Capacityallocated int64 `json:"capacityallocated"` + Capacitytotal int64 `json:"capacitytotal"` + Capacityused int64 `json:"capacityused"` + Clusterid string `json:"clusterid"` + Clustername string `json:"clustername"` + Name string `json:"name"` + Percentused string `json:"percentused"` + Podid string `json:"podid"` + Podname string `json:"podname"` + Type int `json:"type"` + Zoneid string `json:"zoneid"` + Zonename string `json:"zonename"` +} + +type DedicateZoneParams struct { + p map[string]interface{} +} + +func (p *DedicateZoneParams) toURLValues() url.Values { + u := url.Values{} + if p.p == nil { + return u + } + if v, found := p.p["account"]; found { + u.Set("account", v.(string)) + } + if v, found := p.p["domainid"]; found { + u.Set("domainid", v.(string)) + } + if v, found := p.p["zoneid"]; found { + u.Set("zoneid", v.(string)) + } + return u +} + +func (p *DedicateZoneParams) SetAccount(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["account"] = v + return +} + +func (p *DedicateZoneParams) SetDomainid(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["domainid"] = v + return +} + +func (p *DedicateZoneParams) SetZoneid(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["zoneid"] = v + return +} + +// You should always use this function to get a new DedicateZoneParams instance, +// as then you are sure you have configured all required params +func (s *ZoneService) NewDedicateZoneParams(domainid string, zoneid string) *DedicateZoneParams { + p := &DedicateZoneParams{} + p.p = make(map[string]interface{}) + p.p["domainid"] = domainid + p.p["zoneid"] = zoneid + return p +} + +// Dedicates a zones. +func (s *ZoneService) DedicateZone(p *DedicateZoneParams) (*DedicateZoneResponse, error) { + resp, err := s.cs.newRequest("dedicateZone", p.toURLValues()) + if err != nil { + return nil, err + } + + var r DedicateZoneResponse + if err := json.Unmarshal(resp, &r); err != nil { + return nil, err + } + + // If we have a async client, we need to wait for the async result + if s.cs.async { + b, err := s.cs.GetAsyncJobResult(r.JobID, s.cs.timeout) + if err != nil { + if err == AsyncTimeoutErr { + return &r, err + } + return nil, err + } + + b, err = getRawValue(b) + if err != nil { + return nil, err + } + + if err := json.Unmarshal(b, &r); err != nil { + return nil, err + } + } + + return &r, nil +} + +type DedicateZoneResponse struct { + JobID string `json:"jobid"` + Accountid string `json:"accountid"` + Affinitygroupid string `json:"affinitygroupid"` + Domainid string `json:"domainid"` + Id string `json:"id"` + Zoneid string `json:"zoneid"` + Zonename string `json:"zonename"` +} + +type DeleteZoneParams struct { + p map[string]interface{} +} + +func (p *DeleteZoneParams) toURLValues() url.Values { + u := url.Values{} + if p.p == nil { + return u + } + if v, found := p.p["id"]; found { + u.Set("id", v.(string)) + } + return u +} + +func (p *DeleteZoneParams) SetId(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["id"] = v + return +} + +// You should always use this function to get a new DeleteZoneParams instance, +// as then you are sure you have configured all required params +func (s *ZoneService) NewDeleteZoneParams(id string) *DeleteZoneParams { + p := &DeleteZoneParams{} + p.p = make(map[string]interface{}) + p.p["id"] = id + return p +} + +// Deletes a Zone. +func (s *ZoneService) DeleteZone(p *DeleteZoneParams) (*DeleteZoneResponse, error) { + resp, err := s.cs.newRequest("deleteZone", p.toURLValues()) + if err != nil { + return nil, err + } + + var r DeleteZoneResponse + if err := json.Unmarshal(resp, &r); err != nil { + return nil, err + } + + return &r, nil +} + +type DeleteZoneResponse struct { + Displaytext string `json:"displaytext"` + Success bool `json:"success"` +} + +func (r *DeleteZoneResponse) UnmarshalJSON(b []byte) error { + var m map[string]interface{} + err := json.Unmarshal(b, &m) + if err != nil { + return err + } + + if success, ok := m["success"].(string); ok { + m["success"] = success == "true" + b, err = json.Marshal(m) + if err != nil { + return err + } + } + + type alias DeleteZoneResponse + return json.Unmarshal(b, (*alias)(r)) +} + +type DisableOutOfBandManagementForZoneParams struct { + p map[string]interface{} +} + +func (p *DisableOutOfBandManagementForZoneParams) toURLValues() url.Values { + u := url.Values{} + if p.p == nil { + return u + } + if v, found := p.p["zoneid"]; found { + u.Set("zoneid", v.(string)) + } + return u +} + +func (p *DisableOutOfBandManagementForZoneParams) SetZoneid(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["zoneid"] = v + return +} + +// You should always use this function to get a new DisableOutOfBandManagementForZoneParams instance, +// as then you are sure you have configured all required params +func (s *ZoneService) NewDisableOutOfBandManagementForZoneParams(zoneid string) *DisableOutOfBandManagementForZoneParams { + p := &DisableOutOfBandManagementForZoneParams{} + p.p = make(map[string]interface{}) + p.p["zoneid"] = zoneid + return p +} + +// Disables out-of-band management for a zone +func (s *ZoneService) DisableOutOfBandManagementForZone(p *DisableOutOfBandManagementForZoneParams) (*DisableOutOfBandManagementForZoneResponse, error) { + resp, err := s.cs.newRequest("disableOutOfBandManagementForZone", p.toURLValues()) + if err != nil { + return nil, err + } + + var r DisableOutOfBandManagementForZoneResponse + if err := json.Unmarshal(resp, &r); err != nil { + return nil, err + } + + // If we have a async client, we need to wait for the async result + if s.cs.async { + b, err := s.cs.GetAsyncJobResult(r.JobID, s.cs.timeout) + if err != nil { + if err == AsyncTimeoutErr { + return &r, err + } + return nil, err + } + + b, err = getRawValue(b) + if err != nil { + return nil, err + } + + if err := json.Unmarshal(b, &r); err != nil { + return nil, err + } + } + + return &r, nil +} + +type DisableOutOfBandManagementForZoneResponse struct { + JobID string `json:"jobid"` + Action string `json:"action"` + Address string `json:"address"` + Description string `json:"description"` + Driver string `json:"driver"` + Enabled bool `json:"enabled"` + Hostid string `json:"hostid"` + Password string `json:"password"` + Port string `json:"port"` + Powerstate string `json:"powerstate"` + Status bool `json:"status"` + Username string `json:"username"` +} + +type EnableOutOfBandManagementForZoneParams struct { + p map[string]interface{} +} + +func (p *EnableOutOfBandManagementForZoneParams) toURLValues() url.Values { + u := url.Values{} + if p.p == nil { + return u + } + if v, found := p.p["zoneid"]; found { + u.Set("zoneid", v.(string)) + } + return u +} + +func (p *EnableOutOfBandManagementForZoneParams) SetZoneid(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["zoneid"] = v + return +} + +// You should always use this function to get a new EnableOutOfBandManagementForZoneParams instance, +// as then you are sure you have configured all required params +func (s *ZoneService) NewEnableOutOfBandManagementForZoneParams(zoneid string) *EnableOutOfBandManagementForZoneParams { + p := &EnableOutOfBandManagementForZoneParams{} + p.p = make(map[string]interface{}) + p.p["zoneid"] = zoneid + return p +} + +// Enables out-of-band management for a zone +func (s *ZoneService) EnableOutOfBandManagementForZone(p *EnableOutOfBandManagementForZoneParams) (*EnableOutOfBandManagementForZoneResponse, error) { + resp, err := s.cs.newRequest("enableOutOfBandManagementForZone", p.toURLValues()) + if err != nil { + return nil, err + } + + var r EnableOutOfBandManagementForZoneResponse + if err := json.Unmarshal(resp, &r); err != nil { + return nil, err + } + + // If we have a async client, we need to wait for the async result + if s.cs.async { + b, err := s.cs.GetAsyncJobResult(r.JobID, s.cs.timeout) + if err != nil { + if err == AsyncTimeoutErr { + return &r, err + } + return nil, err + } + + b, err = getRawValue(b) + if err != nil { + return nil, err + } + + if err := json.Unmarshal(b, &r); err != nil { + return nil, err + } + } + + return &r, nil +} + +type EnableOutOfBandManagementForZoneResponse struct { + JobID string `json:"jobid"` + Action string `json:"action"` + Address string `json:"address"` + Description string `json:"description"` + Driver string `json:"driver"` + Enabled bool `json:"enabled"` + Hostid string `json:"hostid"` + Password string `json:"password"` + Port string `json:"port"` + Powerstate string `json:"powerstate"` + Status bool `json:"status"` + Username string `json:"username"` +} + +type ListDedicatedZonesParams struct { + p map[string]interface{} +} + +func (p *ListDedicatedZonesParams) toURLValues() url.Values { + u := url.Values{} + if p.p == nil { + return u + } + if v, found := p.p["account"]; found { + u.Set("account", v.(string)) + } + if v, found := p.p["affinitygroupid"]; found { + u.Set("affinitygroupid", v.(string)) + } + if v, found := p.p["domainid"]; found { + u.Set("domainid", v.(string)) + } + if v, found := p.p["keyword"]; found { + u.Set("keyword", v.(string)) + } + if v, found := p.p["page"]; found { + vv := strconv.Itoa(v.(int)) + u.Set("page", vv) + } + if v, found := p.p["pagesize"]; found { + vv := strconv.Itoa(v.(int)) + u.Set("pagesize", vv) + } + if v, found := p.p["zoneid"]; found { + u.Set("zoneid", v.(string)) + } + return u +} + +func (p *ListDedicatedZonesParams) SetAccount(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["account"] = v + return +} + +func (p *ListDedicatedZonesParams) SetAffinitygroupid(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["affinitygroupid"] = v + return +} + +func (p *ListDedicatedZonesParams) SetDomainid(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["domainid"] = v + return +} + +func (p *ListDedicatedZonesParams) SetKeyword(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["keyword"] = v + return +} + +func (p *ListDedicatedZonesParams) SetPage(v int) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["page"] = v + return +} + +func (p *ListDedicatedZonesParams) SetPagesize(v int) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["pagesize"] = v + return +} + +func (p *ListDedicatedZonesParams) SetZoneid(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["zoneid"] = v + return +} + +// You should always use this function to get a new ListDedicatedZonesParams instance, +// as then you are sure you have configured all required params +func (s *ZoneService) NewListDedicatedZonesParams() *ListDedicatedZonesParams { + p := &ListDedicatedZonesParams{} + p.p = make(map[string]interface{}) + return p +} + +// List dedicated zones. +func (s *ZoneService) ListDedicatedZones(p *ListDedicatedZonesParams) (*ListDedicatedZonesResponse, error) { + resp, err := s.cs.newRequest("listDedicatedZones", p.toURLValues()) + if err != nil { + return nil, err + } + + var r ListDedicatedZonesResponse + if err := json.Unmarshal(resp, &r); err != nil { + return nil, err + } + + return &r, nil +} + +type ListDedicatedZonesResponse struct { + Count int `json:"count"` + DedicatedZones []*DedicatedZone `json:"dedicatedzone"` +} + +type DedicatedZone struct { + Accountid string `json:"accountid"` + Affinitygroupid string `json:"affinitygroupid"` + Domainid string `json:"domainid"` + Id string `json:"id"` + Zoneid string `json:"zoneid"` + Zonename string `json:"zonename"` +} + +type ListZonesParams struct { + p map[string]interface{} +} + +func (p *ListZonesParams) toURLValues() url.Values { + u := url.Values{} + if p.p == nil { + return u + } + if v, found := p.p["available"]; found { + vv := strconv.FormatBool(v.(bool)) + u.Set("available", vv) + } + if v, found := p.p["domainid"]; found { + u.Set("domainid", v.(string)) + } + if v, found := p.p["id"]; found { + u.Set("id", v.(string)) + } + if v, found := p.p["keyword"]; found { + u.Set("keyword", v.(string)) + } + if v, found := p.p["name"]; found { + u.Set("name", v.(string)) + } + if v, found := p.p["networktype"]; found { + u.Set("networktype", v.(string)) + } + if v, found := p.p["page"]; found { + vv := strconv.Itoa(v.(int)) + u.Set("page", vv) + } + if v, found := p.p["pagesize"]; found { + vv := strconv.Itoa(v.(int)) + u.Set("pagesize", vv) + } + if v, found := p.p["showcapacities"]; found { + vv := strconv.FormatBool(v.(bool)) + u.Set("showcapacities", vv) + } + if v, found := p.p["tags"]; found { + i := 0 + for k, vv := range v.(map[string]string) { + u.Set(fmt.Sprintf("tags[%d].key", i), k) + u.Set(fmt.Sprintf("tags[%d].value", i), vv) + i++ + } + } + return u +} + +func (p *ListZonesParams) SetAvailable(v bool) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["available"] = v + return +} + +func (p *ListZonesParams) SetDomainid(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["domainid"] = v + return +} + +func (p *ListZonesParams) SetId(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["id"] = v + return +} + +func (p *ListZonesParams) SetKeyword(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["keyword"] = v + return +} + +func (p *ListZonesParams) SetName(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["name"] = v + return +} + +func (p *ListZonesParams) SetNetworktype(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["networktype"] = v + return +} + +func (p *ListZonesParams) SetPage(v int) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["page"] = v + return +} + +func (p *ListZonesParams) SetPagesize(v int) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["pagesize"] = v + return +} + +func (p *ListZonesParams) SetShowcapacities(v bool) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["showcapacities"] = v + return +} + +func (p *ListZonesParams) SetTags(v map[string]string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["tags"] = v + return +} + +// You should always use this function to get a new ListZonesParams instance, +// as then you are sure you have configured all required params +func (s *ZoneService) NewListZonesParams() *ListZonesParams { + p := &ListZonesParams{} + p.p = make(map[string]interface{}) + return p +} + +// This is a courtesy helper function, which in some cases may not work as expected! +func (s *ZoneService) GetZoneID(name string, opts ...OptionFunc) (string, int, error) { + p := &ListZonesParams{} + p.p = make(map[string]interface{}) + + p.p["name"] = name + + for _, fn := range append(s.cs.options, opts...) { + if err := fn(s.cs, p); err != nil { + return "", -1, err + } + } + + l, err := s.ListZones(p) + if err != nil { + return "", -1, err + } + + if l.Count == 0 { + return "", l.Count, fmt.Errorf("No match found for %s: %+v", name, l) + } + + if l.Count == 1 { + return l.Zones[0].Id, l.Count, nil + } + + if l.Count > 1 { + for _, v := range l.Zones { + if v.Name == name { + return v.Id, l.Count, nil + } + } + } + return "", l.Count, fmt.Errorf("Could not find an exact match for %s: %+v", name, l) +} + +// This is a courtesy helper function, which in some cases may not work as expected! +func (s *ZoneService) GetZoneByName(name string, opts ...OptionFunc) (*Zone, int, error) { + id, count, err := s.GetZoneID(name, opts...) + if err != nil { + return nil, count, err + } + + r, count, err := s.GetZoneByID(id, opts...) + if err != nil { + return nil, count, err + } + return r, count, nil +} + +// This is a courtesy helper function, which in some cases may not work as expected! +func (s *ZoneService) GetZoneByID(id string, opts ...OptionFunc) (*Zone, int, error) { + p := &ListZonesParams{} + p.p = make(map[string]interface{}) + + p.p["id"] = id + + for _, fn := range append(s.cs.options, opts...) { + if err := fn(s.cs, p); err != nil { + return nil, -1, err + } + } + + l, err := s.ListZones(p) + if err != nil { + if strings.Contains(err.Error(), fmt.Sprintf( + "Invalid parameter id value=%s due to incorrect long value format, "+ + "or entity does not exist", id)) { + return nil, 0, fmt.Errorf("No match found for %s: %+v", id, l) + } + return nil, -1, err + } + + if l.Count == 0 { + return nil, l.Count, fmt.Errorf("No match found for %s: %+v", id, l) + } + + if l.Count == 1 { + return l.Zones[0], l.Count, nil + } + return nil, l.Count, fmt.Errorf("There is more then one result for Zone UUID: %s!", id) +} + +// Lists zones +func (s *ZoneService) ListZones(p *ListZonesParams) (*ListZonesResponse, error) { + resp, err := s.cs.newRequest("listZones", p.toURLValues()) + if err != nil { + return nil, err + } + + var r ListZonesResponse + if err := json.Unmarshal(resp, &r); err != nil { + return nil, err + } + + return &r, nil +} + +type ListZonesResponse struct { + Count int `json:"count"` + Zones []*Zone `json:"zone"` +} + +type Zone struct { + Allocationstate string `json:"allocationstate"` + Capacity []ZoneCapacity `json:"capacity"` + Description string `json:"description"` + Dhcpprovider string `json:"dhcpprovider"` + Displaytext string `json:"displaytext"` + Dns1 string `json:"dns1"` + Dns2 string `json:"dns2"` + Domain string `json:"domain"` + Domainid string `json:"domainid"` + Domainname string `json:"domainname"` + Guestcidraddress string `json:"guestcidraddress"` + Id string `json:"id"` + Internaldns1 string `json:"internaldns1"` + Internaldns2 string `json:"internaldns2"` + Ip6dns1 string `json:"ip6dns1"` + Ip6dns2 string `json:"ip6dns2"` + Localstorageenabled bool `json:"localstorageenabled"` + Name string `json:"name"` + Networktype string `json:"networktype"` + Resourcedetails map[string]string `json:"resourcedetails"` + Securitygroupsenabled bool `json:"securitygroupsenabled"` + Tags []Tags `json:"tags"` + Zonetoken string `json:"zonetoken"` +} + +type ZoneCapacity struct { + Capacityallocated int64 `json:"capacityallocated"` + Capacitytotal int64 `json:"capacitytotal"` + Capacityused int64 `json:"capacityused"` + Clusterid string `json:"clusterid"` + Clustername string `json:"clustername"` + Name string `json:"name"` + Percentused string `json:"percentused"` + Podid string `json:"podid"` + Podname string `json:"podname"` + Type int `json:"type"` + Zoneid string `json:"zoneid"` + Zonename string `json:"zonename"` +} + +type ReleaseDedicatedZoneParams struct { + p map[string]interface{} +} + +func (p *ReleaseDedicatedZoneParams) toURLValues() url.Values { + u := url.Values{} + if p.p == nil { + return u + } + if v, found := p.p["zoneid"]; found { + u.Set("zoneid", v.(string)) + } + return u +} + +func (p *ReleaseDedicatedZoneParams) SetZoneid(v string) { + if p.p == nil { + p.p = make(map[string]interface{}) + } + p.p["zoneid"] = v + return +} + +// You should always use this function to get a new ReleaseDedicatedZoneParams instance, +// as then you are sure you have configured all required params +func (s *ZoneService) NewReleaseDedicatedZoneParams(zoneid string) *ReleaseDedicatedZoneParams { + p := &ReleaseDedicatedZoneParams{} + p.p = make(map[string]interface{}) + p.p["zoneid"] = zoneid + return p +} + +// Release dedication of zone +func (s *ZoneService) ReleaseDedicatedZone(p *ReleaseDedicatedZoneParams) (*ReleaseDedicatedZoneResponse, error) { + resp, err := s.cs.newRequest("releaseDedicatedZone", p.toURLValues()) + if err != nil { + return nil, err + } + + var r ReleaseDedicatedZoneResponse + if err := json.Unmarshal(resp, &r); err != nil { + return nil, err + } + + // If we have a async client, we need to wait for the async result + if s.cs.async { + b, err := s.cs.GetAsyncJobResult(r.JobID, s.cs.timeout) + if err != nil { + if err == AsyncTimeoutErr { + return &r, err + } + return nil, err + } + + if err := json.Unmarshal(b, &r); err != nil { + return nil, err + } + } + + return &r, nil +} + +type ReleaseDedicatedZoneResponse struct { + JobID string `json:"jobid"` + Displaytext string `json:"displaytext"` + Success bool `json:"success"` } type UpdateZoneParams struct { @@ -281,8 +1089,7 @@ func (p *UpdateZoneParams) toURLValues() url.Values { if v, found := p.p["details"]; found { i := 0 for k, vv := range v.(map[string]string) { - u.Set(fmt.Sprintf("details[%d].key", i), k) - u.Set(fmt.Sprintf("details[%d].value", i), vv) + u.Set(fmt.Sprintf("details[%d].%s", i, k), vv) i++ } } @@ -482,686 +1289,47 @@ func (s *ZoneService) UpdateZone(p *UpdateZoneParams) (*UpdateZoneResponse, erro if err := json.Unmarshal(resp, &r); err != nil { return nil, err } + return &r, nil } type UpdateZoneResponse struct { - Allocationstate string `json:"allocationstate,omitempty"` - Capacity []struct { - Capacitytotal int64 `json:"capacitytotal,omitempty"` - Capacityused int64 `json:"capacityused,omitempty"` - Clusterid string `json:"clusterid,omitempty"` - Clustername string `json:"clustername,omitempty"` - Percentused string `json:"percentused,omitempty"` - Podid string `json:"podid,omitempty"` - Podname string `json:"podname,omitempty"` - Type int `json:"type,omitempty"` - Zoneid string `json:"zoneid,omitempty"` - Zonename string `json:"zonename,omitempty"` - } `json:"capacity,omitempty"` - Description string `json:"description,omitempty"` - Dhcpprovider string `json:"dhcpprovider,omitempty"` - Displaytext string `json:"displaytext,omitempty"` - Dns1 string `json:"dns1,omitempty"` - Dns2 string `json:"dns2,omitempty"` - Domain string `json:"domain,omitempty"` - Domainid string `json:"domainid,omitempty"` - Domainname string `json:"domainname,omitempty"` - Guestcidraddress string `json:"guestcidraddress,omitempty"` - Id string `json:"id,omitempty"` - Internaldns1 string `json:"internaldns1,omitempty"` - Internaldns2 string `json:"internaldns2,omitempty"` - Ip6dns1 string `json:"ip6dns1,omitempty"` - Ip6dns2 string `json:"ip6dns2,omitempty"` - Localstorageenabled bool `json:"localstorageenabled,omitempty"` - Name string `json:"name,omitempty"` - Networktype string `json:"networktype,omitempty"` - Resourcedetails map[string]string `json:"resourcedetails,omitempty"` - Securitygroupsenabled bool `json:"securitygroupsenabled,omitempty"` - Tags []struct { - Account string `json:"account,omitempty"` - Customer string `json:"customer,omitempty"` - Domain string `json:"domain,omitempty"` - Domainid string `json:"domainid,omitempty"` - Key string `json:"key,omitempty"` - Project string `json:"project,omitempty"` - Projectid string `json:"projectid,omitempty"` - Resourceid string `json:"resourceid,omitempty"` - Resourcetype string `json:"resourcetype,omitempty"` - Value string `json:"value,omitempty"` - } `json:"tags,omitempty"` - Zonetoken string `json:"zonetoken,omitempty"` + Allocationstate string `json:"allocationstate"` + Capacity []UpdateZoneResponseCapacity `json:"capacity"` + Description string `json:"description"` + Dhcpprovider string `json:"dhcpprovider"` + Displaytext string `json:"displaytext"` + Dns1 string `json:"dns1"` + Dns2 string `json:"dns2"` + Domain string `json:"domain"` + Domainid string `json:"domainid"` + Domainname string `json:"domainname"` + Guestcidraddress string `json:"guestcidraddress"` + Id string `json:"id"` + Internaldns1 string `json:"internaldns1"` + Internaldns2 string `json:"internaldns2"` + Ip6dns1 string `json:"ip6dns1"` + Ip6dns2 string `json:"ip6dns2"` + Localstorageenabled bool `json:"localstorageenabled"` + Name string `json:"name"` + Networktype string `json:"networktype"` + Resourcedetails map[string]string `json:"resourcedetails"` + Securitygroupsenabled bool `json:"securitygroupsenabled"` + Tags []Tags `json:"tags"` + Zonetoken string `json:"zonetoken"` } -type DeleteZoneParams struct { - p map[string]interface{} -} - -func (p *DeleteZoneParams) toURLValues() url.Values { - u := url.Values{} - if p.p == nil { - return u - } - if v, found := p.p["id"]; found { - u.Set("id", v.(string)) - } - return u -} - -func (p *DeleteZoneParams) SetId(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["id"] = v - return -} - -// You should always use this function to get a new DeleteZoneParams instance, -// as then you are sure you have configured all required params -func (s *ZoneService) NewDeleteZoneParams(id string) *DeleteZoneParams { - p := &DeleteZoneParams{} - p.p = make(map[string]interface{}) - p.p["id"] = id - return p -} - -// Deletes a Zone. -func (s *ZoneService) DeleteZone(p *DeleteZoneParams) (*DeleteZoneResponse, error) { - resp, err := s.cs.newRequest("deleteZone", p.toURLValues()) - if err != nil { - return nil, err - } - - var r DeleteZoneResponse - if err := json.Unmarshal(resp, &r); err != nil { - return nil, err - } - return &r, nil -} - -type DeleteZoneResponse struct { - Displaytext string `json:"displaytext,omitempty"` - Success string `json:"success,omitempty"` -} - -type ListZonesParams struct { - p map[string]interface{} -} - -func (p *ListZonesParams) toURLValues() url.Values { - u := url.Values{} - if p.p == nil { - return u - } - if v, found := p.p["available"]; found { - vv := strconv.FormatBool(v.(bool)) - u.Set("available", vv) - } - if v, found := p.p["domainid"]; found { - u.Set("domainid", v.(string)) - } - if v, found := p.p["id"]; found { - u.Set("id", v.(string)) - } - if v, found := p.p["keyword"]; found { - u.Set("keyword", v.(string)) - } - if v, found := p.p["name"]; found { - u.Set("name", v.(string)) - } - if v, found := p.p["networktype"]; found { - u.Set("networktype", v.(string)) - } - if v, found := p.p["page"]; found { - vv := strconv.Itoa(v.(int)) - u.Set("page", vv) - } - if v, found := p.p["pagesize"]; found { - vv := strconv.Itoa(v.(int)) - u.Set("pagesize", vv) - } - if v, found := p.p["showcapacities"]; found { - vv := strconv.FormatBool(v.(bool)) - u.Set("showcapacities", vv) - } - if v, found := p.p["tags"]; found { - i := 0 - for k, vv := range v.(map[string]string) { - u.Set(fmt.Sprintf("tags[%d].key", i), k) - u.Set(fmt.Sprintf("tags[%d].value", i), vv) - i++ - } - } - return u -} - -func (p *ListZonesParams) SetAvailable(v bool) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["available"] = v - return -} - -func (p *ListZonesParams) SetDomainid(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["domainid"] = v - return -} - -func (p *ListZonesParams) SetId(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["id"] = v - return -} - -func (p *ListZonesParams) SetKeyword(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["keyword"] = v - return -} - -func (p *ListZonesParams) SetName(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["name"] = v - return -} - -func (p *ListZonesParams) SetNetworktype(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["networktype"] = v - return -} - -func (p *ListZonesParams) SetPage(v int) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["page"] = v - return -} - -func (p *ListZonesParams) SetPagesize(v int) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["pagesize"] = v - return -} - -func (p *ListZonesParams) SetShowcapacities(v bool) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["showcapacities"] = v - return -} - -func (p *ListZonesParams) SetTags(v map[string]string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["tags"] = v - return -} - -// You should always use this function to get a new ListZonesParams instance, -// as then you are sure you have configured all required params -func (s *ZoneService) NewListZonesParams() *ListZonesParams { - p := &ListZonesParams{} - p.p = make(map[string]interface{}) - return p -} - -// This is a courtesy helper function, which in some cases may not work as expected! -func (s *ZoneService) GetZoneID(name string, opts ...OptionFunc) (string, int, error) { - p := &ListZonesParams{} - p.p = make(map[string]interface{}) - - p.p["name"] = name - - for _, fn := range opts { - if err := fn(s.cs, p); err != nil { - return "", -1, err - } - } - - l, err := s.ListZones(p) - if err != nil { - return "", -1, err - } - - if l.Count == 0 { - return "", l.Count, fmt.Errorf("No match found for %s: %+v", name, l) - } - - if l.Count == 1 { - return l.Zones[0].Id, l.Count, nil - } - - if l.Count > 1 { - for _, v := range l.Zones { - if v.Name == name { - return v.Id, l.Count, nil - } - } - } - return "", l.Count, fmt.Errorf("Could not find an exact match for %s: %+v", name, l) -} - -// This is a courtesy helper function, which in some cases may not work as expected! -func (s *ZoneService) GetZoneByName(name string, opts ...OptionFunc) (*Zone, int, error) { - id, count, err := s.GetZoneID(name, opts...) - if err != nil { - return nil, count, err - } - - r, count, err := s.GetZoneByID(id, opts...) - if err != nil { - return nil, count, err - } - return r, count, nil -} - -// This is a courtesy helper function, which in some cases may not work as expected! -func (s *ZoneService) GetZoneByID(id string, opts ...OptionFunc) (*Zone, int, error) { - p := &ListZonesParams{} - p.p = make(map[string]interface{}) - - p.p["id"] = id - - for _, fn := range opts { - if err := fn(s.cs, p); err != nil { - return nil, -1, err - } - } - - l, err := s.ListZones(p) - if err != nil { - if strings.Contains(err.Error(), fmt.Sprintf( - "Invalid parameter id value=%s due to incorrect long value format, "+ - "or entity does not exist", id)) { - return nil, 0, fmt.Errorf("No match found for %s: %+v", id, l) - } - return nil, -1, err - } - - if l.Count == 0 { - return nil, l.Count, fmt.Errorf("No match found for %s: %+v", id, l) - } - - if l.Count == 1 { - return l.Zones[0], l.Count, nil - } - return nil, l.Count, fmt.Errorf("There is more then one result for Zone UUID: %s!", id) -} - -// Lists zones -func (s *ZoneService) ListZones(p *ListZonesParams) (*ListZonesResponse, error) { - resp, err := s.cs.newRequest("listZones", p.toURLValues()) - if err != nil { - return nil, err - } - - var r ListZonesResponse - if err := json.Unmarshal(resp, &r); err != nil { - return nil, err - } - return &r, nil -} - -type ListZonesResponse struct { - Count int `json:"count"` - Zones []*Zone `json:"zone"` -} - -type Zone struct { - Allocationstate string `json:"allocationstate,omitempty"` - Capacity []struct { - Capacitytotal int64 `json:"capacitytotal,omitempty"` - Capacityused int64 `json:"capacityused,omitempty"` - Clusterid string `json:"clusterid,omitempty"` - Clustername string `json:"clustername,omitempty"` - Percentused string `json:"percentused,omitempty"` - Podid string `json:"podid,omitempty"` - Podname string `json:"podname,omitempty"` - Type int `json:"type,omitempty"` - Zoneid string `json:"zoneid,omitempty"` - Zonename string `json:"zonename,omitempty"` - } `json:"capacity,omitempty"` - Description string `json:"description,omitempty"` - Dhcpprovider string `json:"dhcpprovider,omitempty"` - Displaytext string `json:"displaytext,omitempty"` - Dns1 string `json:"dns1,omitempty"` - Dns2 string `json:"dns2,omitempty"` - Domain string `json:"domain,omitempty"` - Domainid string `json:"domainid,omitempty"` - Domainname string `json:"domainname,omitempty"` - Guestcidraddress string `json:"guestcidraddress,omitempty"` - Id string `json:"id,omitempty"` - Internaldns1 string `json:"internaldns1,omitempty"` - Internaldns2 string `json:"internaldns2,omitempty"` - Ip6dns1 string `json:"ip6dns1,omitempty"` - Ip6dns2 string `json:"ip6dns2,omitempty"` - Localstorageenabled bool `json:"localstorageenabled,omitempty"` - Name string `json:"name,omitempty"` - Networktype string `json:"networktype,omitempty"` - Resourcedetails map[string]string `json:"resourcedetails,omitempty"` - Securitygroupsenabled bool `json:"securitygroupsenabled,omitempty"` - Tags []struct { - Account string `json:"account,omitempty"` - Customer string `json:"customer,omitempty"` - Domain string `json:"domain,omitempty"` - Domainid string `json:"domainid,omitempty"` - Key string `json:"key,omitempty"` - Project string `json:"project,omitempty"` - Projectid string `json:"projectid,omitempty"` - Resourceid string `json:"resourceid,omitempty"` - Resourcetype string `json:"resourcetype,omitempty"` - Value string `json:"value,omitempty"` - } `json:"tags,omitempty"` - Zonetoken string `json:"zonetoken,omitempty"` -} - -type DedicateZoneParams struct { - p map[string]interface{} -} - -func (p *DedicateZoneParams) toURLValues() url.Values { - u := url.Values{} - if p.p == nil { - return u - } - if v, found := p.p["account"]; found { - u.Set("account", v.(string)) - } - if v, found := p.p["domainid"]; found { - u.Set("domainid", v.(string)) - } - if v, found := p.p["zoneid"]; found { - u.Set("zoneid", v.(string)) - } - return u -} - -func (p *DedicateZoneParams) SetAccount(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["account"] = v - return -} - -func (p *DedicateZoneParams) SetDomainid(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["domainid"] = v - return -} - -func (p *DedicateZoneParams) SetZoneid(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["zoneid"] = v - return -} - -// You should always use this function to get a new DedicateZoneParams instance, -// as then you are sure you have configured all required params -func (s *ZoneService) NewDedicateZoneParams(domainid string, zoneid string) *DedicateZoneParams { - p := &DedicateZoneParams{} - p.p = make(map[string]interface{}) - p.p["domainid"] = domainid - p.p["zoneid"] = zoneid - return p -} - -// Dedicates a zones. -func (s *ZoneService) DedicateZone(p *DedicateZoneParams) (*DedicateZoneResponse, error) { - resp, err := s.cs.newRequest("dedicateZone", p.toURLValues()) - if err != nil { - return nil, err - } - - var r DedicateZoneResponse - if err := json.Unmarshal(resp, &r); err != nil { - return nil, err - } - - // If we have a async client, we need to wait for the async result - if s.cs.async { - b, err := s.cs.GetAsyncJobResult(r.JobID, s.cs.timeout) - if err != nil { - if err == AsyncTimeoutErr { - return &r, err - } - return nil, err - } - - b, err = getRawValue(b) - if err != nil { - return nil, err - } - - if err := json.Unmarshal(b, &r); err != nil { - return nil, err - } - } - return &r, nil -} - -type DedicateZoneResponse struct { - JobID string `json:"jobid,omitempty"` - Accountid string `json:"accountid,omitempty"` - Affinitygroupid string `json:"affinitygroupid,omitempty"` - Domainid string `json:"domainid,omitempty"` - Id string `json:"id,omitempty"` - Zoneid string `json:"zoneid,omitempty"` - Zonename string `json:"zonename,omitempty"` -} - -type ReleaseDedicatedZoneParams struct { - p map[string]interface{} -} - -func (p *ReleaseDedicatedZoneParams) toURLValues() url.Values { - u := url.Values{} - if p.p == nil { - return u - } - if v, found := p.p["zoneid"]; found { - u.Set("zoneid", v.(string)) - } - return u -} - -func (p *ReleaseDedicatedZoneParams) SetZoneid(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["zoneid"] = v - return -} - -// You should always use this function to get a new ReleaseDedicatedZoneParams instance, -// as then you are sure you have configured all required params -func (s *ZoneService) NewReleaseDedicatedZoneParams(zoneid string) *ReleaseDedicatedZoneParams { - p := &ReleaseDedicatedZoneParams{} - p.p = make(map[string]interface{}) - p.p["zoneid"] = zoneid - return p -} - -// Release dedication of zone -func (s *ZoneService) ReleaseDedicatedZone(p *ReleaseDedicatedZoneParams) (*ReleaseDedicatedZoneResponse, error) { - resp, err := s.cs.newRequest("releaseDedicatedZone", p.toURLValues()) - if err != nil { - return nil, err - } - - var r ReleaseDedicatedZoneResponse - if err := json.Unmarshal(resp, &r); err != nil { - return nil, err - } - - // If we have a async client, we need to wait for the async result - if s.cs.async { - b, err := s.cs.GetAsyncJobResult(r.JobID, s.cs.timeout) - if err != nil { - if err == AsyncTimeoutErr { - return &r, err - } - return nil, err - } - - if err := json.Unmarshal(b, &r); err != nil { - return nil, err - } - } - return &r, nil -} - -type ReleaseDedicatedZoneResponse struct { - JobID string `json:"jobid,omitempty"` - Displaytext string `json:"displaytext,omitempty"` - Success bool `json:"success,omitempty"` -} - -type ListDedicatedZonesParams struct { - p map[string]interface{} -} - -func (p *ListDedicatedZonesParams) toURLValues() url.Values { - u := url.Values{} - if p.p == nil { - return u - } - if v, found := p.p["account"]; found { - u.Set("account", v.(string)) - } - if v, found := p.p["affinitygroupid"]; found { - u.Set("affinitygroupid", v.(string)) - } - if v, found := p.p["domainid"]; found { - u.Set("domainid", v.(string)) - } - if v, found := p.p["keyword"]; found { - u.Set("keyword", v.(string)) - } - if v, found := p.p["page"]; found { - vv := strconv.Itoa(v.(int)) - u.Set("page", vv) - } - if v, found := p.p["pagesize"]; found { - vv := strconv.Itoa(v.(int)) - u.Set("pagesize", vv) - } - if v, found := p.p["zoneid"]; found { - u.Set("zoneid", v.(string)) - } - return u -} - -func (p *ListDedicatedZonesParams) SetAccount(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["account"] = v - return -} - -func (p *ListDedicatedZonesParams) SetAffinitygroupid(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["affinitygroupid"] = v - return -} - -func (p *ListDedicatedZonesParams) SetDomainid(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["domainid"] = v - return -} - -func (p *ListDedicatedZonesParams) SetKeyword(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["keyword"] = v - return -} - -func (p *ListDedicatedZonesParams) SetPage(v int) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["page"] = v - return -} - -func (p *ListDedicatedZonesParams) SetPagesize(v int) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["pagesize"] = v - return -} - -func (p *ListDedicatedZonesParams) SetZoneid(v string) { - if p.p == nil { - p.p = make(map[string]interface{}) - } - p.p["zoneid"] = v - return -} - -// You should always use this function to get a new ListDedicatedZonesParams instance, -// as then you are sure you have configured all required params -func (s *ZoneService) NewListDedicatedZonesParams() *ListDedicatedZonesParams { - p := &ListDedicatedZonesParams{} - p.p = make(map[string]interface{}) - return p -} - -// List dedicated zones. -func (s *ZoneService) ListDedicatedZones(p *ListDedicatedZonesParams) (*ListDedicatedZonesResponse, error) { - resp, err := s.cs.newRequest("listDedicatedZones", p.toURLValues()) - if err != nil { - return nil, err - } - - var r ListDedicatedZonesResponse - if err := json.Unmarshal(resp, &r); err != nil { - return nil, err - } - return &r, nil -} - -type ListDedicatedZonesResponse struct { - Count int `json:"count"` - DedicatedZones []*DedicatedZone `json:"dedicatedzone"` -} - -type DedicatedZone struct { - Accountid string `json:"accountid,omitempty"` - Affinitygroupid string `json:"affinitygroupid,omitempty"` - Domainid string `json:"domainid,omitempty"` - Id string `json:"id,omitempty"` - Zoneid string `json:"zoneid,omitempty"` - Zonename string `json:"zonename,omitempty"` +type UpdateZoneResponseCapacity struct { + Capacityallocated int64 `json:"capacityallocated"` + Capacitytotal int64 `json:"capacitytotal"` + Capacityused int64 `json:"capacityused"` + Clusterid string `json:"clusterid"` + Clustername string `json:"clustername"` + Name string `json:"name"` + Percentused string `json:"percentused"` + Podid string `json:"podid"` + Podname string `json:"podname"` + Type int `json:"type"` + Zoneid string `json:"zoneid"` + Zonename string `json:"zonename"` } diff --git a/vendor/github.com/xanzy/go-cloudstack/cloudstack/cloudstack.go b/vendor/github.com/xanzy/go-cloudstack/cloudstack/cloudstack.go index fd1b8d71e..04bbac3a8 100644 --- a/vendor/github.com/xanzy/go-cloudstack/cloudstack/cloudstack.go +++ b/vendor/github.com/xanzy/go-cloudstack/cloudstack/cloudstack.go @@ -1,5 +1,5 @@ // -// Copyright 2016, Sander van Harmelen +// Copyright 2018, Sander van Harmelen // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -26,7 +26,9 @@ import ( "errors" "fmt" "io/ioutil" + "net" "net/http" + "net/http/cookiejar" "net/url" "regexp" "sort" @@ -65,80 +67,98 @@ type CloudStackClient struct { apiKey string // Api key secret string // Secret key async bool // Wait for async calls to finish + options []OptionFunc // A list of option functions to apply to all API calls timeout int64 // Max waiting timeout in seconds for async jobs to finish; defaults to 300 seconds - APIDiscovery *APIDiscoveryService - Account *AccountService - Address *AddressService - AffinityGroup *AffinityGroupService - Alert *AlertService - Asyncjob *AsyncjobService - Authentication *AuthenticationService - AutoScale *AutoScaleService - Baremetal *BaremetalService - Certificate *CertificateService - CloudIdentifier *CloudIdentifierService - Cluster *ClusterService - Configuration *ConfigurationService - DiskOffering *DiskOfferingService - Domain *DomainService - Event *EventService - Firewall *FirewallService - GuestOS *GuestOSService - Host *HostService - Hypervisor *HypervisorService - ISO *ISOService - ImageStore *ImageStoreService - InternalLB *InternalLBService - LDAP *LDAPService - Limit *LimitService - LoadBalancer *LoadBalancerService - NAT *NATService - NetworkACL *NetworkACLService - NetworkDevice *NetworkDeviceService - NetworkOffering *NetworkOfferingService - Network *NetworkService - Nic *NicService - NiciraNVP *NiciraNVPService - OvsElement *OvsElementService - Pod *PodService - Pool *PoolService - PortableIP *PortableIPService - Project *ProjectService - Quota *QuotaService - Region *RegionService - Resourcemetadata *ResourcemetadataService - Resourcetags *ResourcetagsService - Router *RouterService - SSH *SSHService - SecurityGroup *SecurityGroupService - ServiceOffering *ServiceOfferingService - Snapshot *SnapshotService - StoragePool *StoragePoolService - StratosphereSSP *StratosphereSSPService - Swift *SwiftService - SystemCapacity *SystemCapacityService - SystemVM *SystemVMService - Template *TemplateService - UCS *UCSService - Usage *UsageService - User *UserService - VLAN *VLANService - VMGroup *VMGroupService - VPC *VPCService - VPN *VPNService - VirtualMachine *VirtualMachineService - Volume *VolumeService - Zone *ZoneService + APIDiscovery *APIDiscoveryService + Account *AccountService + Address *AddressService + AffinityGroup *AffinityGroupService + Alert *AlertService + Asyncjob *AsyncjobService + Authentication *AuthenticationService + AutoScale *AutoScaleService + Baremetal *BaremetalService + BigSwitchBCF *BigSwitchBCFService + BrocadeVCS *BrocadeVCSService + Certificate *CertificateService + CloudIdentifier *CloudIdentifierService + Cluster *ClusterService + Configuration *ConfigurationService + Custom *CustomService + DiskOffering *DiskOfferingService + Domain *DomainService + Event *EventService + Firewall *FirewallService + GuestOS *GuestOSService + Host *HostService + Hypervisor *HypervisorService + ISO *ISOService + ImageStore *ImageStoreService + InternalLB *InternalLBService + LDAP *LDAPService + Limit *LimitService + LoadBalancer *LoadBalancerService + NAT *NATService + NetworkACL *NetworkACLService + NetworkDevice *NetworkDeviceService + NetworkOffering *NetworkOfferingService + Network *NetworkService + Nic *NicService + NiciraNVP *NiciraNVPService + NuageVSP *NuageVSPService + OutofbandManagement *OutofbandManagementService + OvsElement *OvsElementService + Pod *PodService + Pool *PoolService + PortableIP *PortableIPService + Project *ProjectService + Quota *QuotaService + Region *RegionService + Resourcemetadata *ResourcemetadataService + Resourcetags *ResourcetagsService + Role *RoleService + Router *RouterService + SSH *SSHService + SecurityGroup *SecurityGroupService + ServiceOffering *ServiceOfferingService + Snapshot *SnapshotService + StoragePool *StoragePoolService + StratosphereSSP *StratosphereSSPService + Swift *SwiftService + SystemCapacity *SystemCapacityService + SystemVM *SystemVMService + Template *TemplateService + UCS *UCSService + Usage *UsageService + User *UserService + VLAN *VLANService + VMGroup *VMGroupService + VPC *VPCService + VPN *VPNService + VirtualMachine *VirtualMachineService + Volume *VolumeService + Zone *ZoneService } // Creates a new client for communicating with CloudStack func newClient(apiurl string, apikey string, secret string, async bool, verifyssl bool) *CloudStackClient { + jar, _ := cookiejar.New(nil) cs := &CloudStackClient{ client: &http.Client{ + Jar: jar, Transport: &http.Transport{ - Proxy: http.ProxyFromEnvironment, - TLSClientConfig: &tls.Config{InsecureSkipVerify: !verifyssl}, // If verifyssl is true, skipping the verify should be false and vice versa + Proxy: http.ProxyFromEnvironment, + DialContext: (&net.Dialer{ + Timeout: 30 * time.Second, + KeepAlive: 30 * time.Second, + DualStack: true, + }).DialContext, + MaxIdleConns: 100, + IdleConnTimeout: 90 * time.Second, + TLSClientConfig: &tls.Config{InsecureSkipVerify: !verifyssl}, // If verifyssl is true, skipping the verify should be false and vice versa + TLSHandshakeTimeout: 10 * time.Second, + ExpectContinueTimeout: 1 * time.Second, }, Timeout: time.Duration(60 * time.Second), }, @@ -146,6 +166,7 @@ func newClient(apiurl string, apikey string, secret string, async bool, verifyss apiKey: apikey, secret: secret, async: async, + options: []OptionFunc{}, timeout: 300, } cs.APIDiscovery = NewAPIDiscoveryService(cs) @@ -157,10 +178,13 @@ func newClient(apiurl string, apikey string, secret string, async bool, verifyss cs.Authentication = NewAuthenticationService(cs) cs.AutoScale = NewAutoScaleService(cs) cs.Baremetal = NewBaremetalService(cs) + cs.BigSwitchBCF = NewBigSwitchBCFService(cs) + cs.BrocadeVCS = NewBrocadeVCSService(cs) cs.Certificate = NewCertificateService(cs) cs.CloudIdentifier = NewCloudIdentifierService(cs) cs.Cluster = NewClusterService(cs) cs.Configuration = NewConfigurationService(cs) + cs.Custom = NewCustomService(cs) cs.DiskOffering = NewDiskOfferingService(cs) cs.Domain = NewDomainService(cs) cs.Event = NewEventService(cs) @@ -181,6 +205,8 @@ func newClient(apiurl string, apikey string, secret string, async bool, verifyss cs.Network = NewNetworkService(cs) cs.Nic = NewNicService(cs) cs.NiciraNVP = NewNiciraNVPService(cs) + cs.NuageVSP = NewNuageVSPService(cs) + cs.OutofbandManagement = NewOutofbandManagementService(cs) cs.OvsElement = NewOvsElementService(cs) cs.Pod = NewPodService(cs) cs.Pool = NewPoolService(cs) @@ -190,6 +216,7 @@ func newClient(apiurl string, apikey string, secret string, async bool, verifyss cs.Region = NewRegionService(cs) cs.Resourcemetadata = NewResourcemetadataService(cs) cs.Resourcetags = NewResourcetagsService(cs) + cs.Role = NewRoleService(cs) cs.Router = NewRouterService(cs) cs.SSH = NewSSHService(cs) cs.SecurityGroup = NewSecurityGroupService(cs) @@ -237,6 +264,15 @@ func (cs *CloudStackClient) AsyncTimeout(timeoutInSeconds int64) { cs.timeout = timeoutInSeconds } +// Set any default options that would be added to all API calls that support it. +func (cs *CloudStackClient) DefaultOptions(options ...OptionFunc) { + if options != nil { + cs.options = options + } else { + cs.options = []OptionFunc{} + } +} + var AsyncTimeoutErr = errors.New("Timeout while waiting for async job to finish") // A helper function that you can use to get the result of a running async job. If the job is not finished within the configured @@ -303,7 +339,7 @@ func (cs *CloudStackClient) newRequest(api string, params url.Values) (json.RawM var err error var resp *http.Response - if !cs.HTTPGETOnly && (api == "deployVirtualMachine" || api == "updateVirtualMachine") { + if !cs.HTTPGETOnly && (api == "deployVirtualMachine" || api == "login" || api == "updateVirtualMachine") { // The deployVirtualMachine API should be called using a POST call // so we don't have to worry about the userdata size @@ -503,6 +539,22 @@ func NewBaremetalService(cs *CloudStackClient) *BaremetalService { return &BaremetalService{cs: cs} } +type BigSwitchBCFService struct { + cs *CloudStackClient +} + +func NewBigSwitchBCFService(cs *CloudStackClient) *BigSwitchBCFService { + return &BigSwitchBCFService{cs: cs} +} + +type BrocadeVCSService struct { + cs *CloudStackClient +} + +func NewBrocadeVCSService(cs *CloudStackClient) *BrocadeVCSService { + return &BrocadeVCSService{cs: cs} +} + type CertificateService struct { cs *CloudStackClient } @@ -535,6 +587,14 @@ func NewConfigurationService(cs *CloudStackClient) *ConfigurationService { return &ConfigurationService{cs: cs} } +type CustomService struct { + cs *CloudStackClient +} + +func NewCustomService(cs *CloudStackClient) *CustomService { + return &CustomService{cs: cs} +} + type DiskOfferingService struct { cs *CloudStackClient } @@ -695,6 +755,22 @@ func NewNiciraNVPService(cs *CloudStackClient) *NiciraNVPService { return &NiciraNVPService{cs: cs} } +type NuageVSPService struct { + cs *CloudStackClient +} + +func NewNuageVSPService(cs *CloudStackClient) *NuageVSPService { + return &NuageVSPService{cs: cs} +} + +type OutofbandManagementService struct { + cs *CloudStackClient +} + +func NewOutofbandManagementService(cs *CloudStackClient) *OutofbandManagementService { + return &OutofbandManagementService{cs: cs} +} + type OvsElementService struct { cs *CloudStackClient } @@ -767,6 +843,14 @@ func NewResourcetagsService(cs *CloudStackClient) *ResourcetagsService { return &ResourcetagsService{cs: cs} } +type RoleService struct { + cs *CloudStackClient +} + +func NewRoleService(cs *CloudStackClient) *RoleService { + return &RoleService{cs: cs} +} + type RouterService struct { cs *CloudStackClient } diff --git a/website/source/docs/provisioners/ansible.html.md b/website/source/docs/provisioners/ansible.html.md index 440215b8a..7ec4941c9 100644 --- a/website/source/docs/provisioners/ansible.html.md +++ b/website/source/docs/provisioners/ansible.html.md @@ -49,7 +49,7 @@ DigitalOcean. Replace the mock `api_token` value with your own. Required Parameters: -- `playbook_file` - The playbook to be run by Ansible. +- `playbook_file` (string) - The playbook to be run by Ansible. Optional Parameters: @@ -57,9 +57,7 @@ Optional Parameters: running Ansible. Usage example: ``` json - { "ansible_env_vars": [ "ANSIBLE_HOST_KEY_CHECKING=False", "ANSIBLE_SSH_ARGS='-o ForwardAgent=yes -o ControlMaster=auto -o ControlPersist=60s'", "ANSIBLE_NOCOLOR=True" ] - } ``` If you are running a Windows build on AWS, Azure or Google Compute and @@ -82,9 +80,7 @@ Optional Parameters: not be quoted. Usage example: ``` json - { "extra_arguments": [ "--extra-vars", "Region={{user `Region`}} Stage={{user `Stage`}}" ] - } ``` If you are running a Windows build on AWS, Azure or Google Compute and @@ -117,7 +113,7 @@ Optional Parameters: inventory directory with `host_vars` `group_vars` that you would like to use in the playbook that this provisioner will run. -- `local_port` (string) - The port on which to attempt to listen for SSH +- `local_port` (uint) - The port on which to attempt to listen for SSH connections. This value is a starting point. The provisioner will attempt listen for SSH connections on the first available of ten ports, starting at `local_port`. A system-chosen port is used when `local_port` is missing or @@ -175,9 +171,7 @@ To debug underlying issues with Ansible, add `"-vvvv"` to `"extra_arguments"` to enable verbose logging. ``` json -{ "extra_arguments": [ "-vvvv" ] -} ``` ## Limitations diff --git a/website/source/layouts/docs.erb b/website/source/layouts/docs.erb index e0cf12c86..63f65f109 100644 --- a/website/source/layouts/docs.erb +++ b/website/source/layouts/docs.erb @@ -202,7 +202,7 @@ Ansible Local > - Ansible Remote + Ansible (Remote) > Breakpoint