From cbea101ecf189b2d46403864d6c8f3e0d391aa8c Mon Sep 17 00:00:00 2001 From: Sander van Harmelen Date: Thu, 21 Apr 2016 16:57:02 +0200 Subject: [PATCH 1/2] Update `go-cloudstack` dependency --- Godeps/Godeps.json | 4 +- .../cloudstack/APIDiscoveryService.go | 2 +- .../cloudstack/AccountService.go | 42 +++-- .../cloudstack/AddressService.go | 25 +-- .../cloudstack/AffinityGroupService.go | 49 ++--- .../go-cloudstack/cloudstack/AlertService.go | 24 ++- .../cloudstack/AsyncjobService.go | 2 +- .../cloudstack/AuthenticationService.go | 2 +- .../cloudstack/AutoScaleService.go | 86 ++++----- .../cloudstack/BaremetalService.go | 2 +- .../cloudstack/CertificateService.go | 2 +- .../cloudstack/CloudIdentifierService.go | 2 +- .../cloudstack/ClusterService.go | 24 ++- .../cloudstack/ConfigurationService.go | 2 +- .../cloudstack/DiskOfferingService.go | 24 ++- .../go-cloudstack/cloudstack/DomainService.go | 46 +++-- .../go-cloudstack/cloudstack/EventService.go | 25 +-- .../cloudstack/FirewallService.go | 71 +++----- .../cloudstack/GuestOSService.go | 40 ++++- .../go-cloudstack/cloudstack/HostService.go | 32 +++- .../cloudstack/HypervisorService.go | 10 +- .../go-cloudstack/cloudstack/ISOService.go | 57 +++--- .../cloudstack/ImageStoreService.go | 46 +++-- .../cloudstack/InternalLBService.go | 57 +++--- .../go-cloudstack/cloudstack/LDAPService.go | 2 +- .../go-cloudstack/cloudstack/LimitService.go | 2 +- .../cloudstack/LoadBalancerService.go | 167 ++++++++---------- .../go-cloudstack/cloudstack/NATService.go | 25 +-- .../cloudstack/NetworkACLService.go | 72 +++----- .../cloudstack/NetworkDeviceService.go | 2 +- .../cloudstack/NetworkOfferingService.go | 24 ++- .../cloudstack/NetworkService.go | 119 ++++++++----- .../go-cloudstack/cloudstack/NicService.go | 2 +- .../cloudstack/NiciraNVPService.go | 2 +- .../cloudstack/OvsElementService.go | 10 +- .../go-cloudstack/cloudstack/PodService.go | 24 ++- .../go-cloudstack/cloudstack/PoolService.go | 24 ++- .../cloudstack/PortableIPService.go | 10 +- .../cloudstack/ProjectService.go | 47 ++--- .../go-cloudstack/cloudstack/QuotaService.go | 2 +- .../go-cloudstack/cloudstack/RegionService.go | 2 +- .../cloudstack/ResourcemetadataService.go | 2 +- .../cloudstack/ResourcetagsService.go | 10 +- .../go-cloudstack/cloudstack/RouterService.go | 57 +++--- .../go-cloudstack/cloudstack/SSHService.go | 2 +- .../cloudstack/SecurityGroupService.go | 49 ++--- .../cloudstack/ServiceOfferingService.go | 24 ++- .../cloudstack/SnapshotService.go | 75 ++++---- .../cloudstack/StoragePoolService.go | 2 +- .../cloudstack/StratosphereSSPService.go | 2 +- .../go-cloudstack/cloudstack/SwiftService.go | 10 +- .../cloudstack/SystemCapacityService.go | 2 +- .../cloudstack/SystemVMService.go | 24 ++- .../cloudstack/TemplateService.go | 57 +++--- .../go-cloudstack/cloudstack/UCSService.go | 24 ++- .../go-cloudstack/cloudstack/UsageService.go | 10 +- .../go-cloudstack/cloudstack/UserService.go | 10 +- .../go-cloudstack/cloudstack/VLANService.go | 48 ++--- .../cloudstack/VMGroupService.go | 49 ++--- .../go-cloudstack/cloudstack/VPCService.go | 117 +++++------- .../go-cloudstack/cloudstack/VPNService.go | 141 +++++---------- .../cloudstack/VirtualMachineService.go | 49 ++--- .../go-cloudstack/cloudstack/VolumeService.go | 49 ++--- .../go-cloudstack/cloudstack/ZoneService.go | 24 ++- .../go-cloudstack/cloudstack/cloudstack.go | 44 ++++- 65 files changed, 1076 insertions(+), 1017 deletions(-) diff --git a/Godeps/Godeps.json b/Godeps/Godeps.json index 4e6e519c05..b3537a277b 100644 --- a/Godeps/Godeps.json +++ b/Godeps/Godeps.json @@ -1265,8 +1265,8 @@ }, { "ImportPath": "github.com/xanzy/go-cloudstack/cloudstack", - "Comment": "2.0.0", - "Rev": "6e28220a0503ff25e2c1480791e23d12872140ac" + "Comment": "2.0.0-2-gcfbfb48", + "Rev": "cfbfb481e04c131cb89df1c6141b082f2714bc29" }, { "ImportPath": "github.com/xanzy/ssh-agent", diff --git a/vendor/github.com/xanzy/go-cloudstack/cloudstack/APIDiscoveryService.go b/vendor/github.com/xanzy/go-cloudstack/cloudstack/APIDiscoveryService.go index 0802f3351d..490d36d650 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 2014, Sander van Harmelen +// Copyright 2016, 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. diff --git a/vendor/github.com/xanzy/go-cloudstack/cloudstack/AccountService.go b/vendor/github.com/xanzy/go-cloudstack/cloudstack/AccountService.go index 98b49df34f..35ef09546e 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 2014, Sander van Harmelen +// Copyright 2016, 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. @@ -1130,12 +1130,18 @@ func (s *AccountService) NewListAccountsParams() *ListAccountsParams { } // This is a courtesy helper function, which in some cases may not work as expected! -func (s *AccountService) GetAccountID(name string) (string, error) { +func (s *AccountService) GetAccountID(name string, opts ...OptionFunc) (string, error) { p := &ListAccountsParams{} p.p = make(map[string]interface{}) p.p["name"] = name + for _, fn := range opts { + if err := fn(s.cs, p); err != nil { + return "", err + } + } + l, err := s.ListAccounts(p) if err != nil { return "", err @@ -1160,13 +1166,13 @@ func (s *AccountService) GetAccountID(name string) (string, error) { } // This is a courtesy helper function, which in some cases may not work as expected! -func (s *AccountService) GetAccountByName(name string) (*Account, int, error) { - id, err := s.GetAccountID(name) +func (s *AccountService) GetAccountByName(name string, opts ...OptionFunc) (*Account, int, error) { + id, err := s.GetAccountID(name, opts...) if err != nil { return nil, -1, err } - r, count, err := s.GetAccountByID(id) + r, count, err := s.GetAccountByID(id, opts...) if err != nil { return nil, count, err } @@ -1174,12 +1180,18 @@ func (s *AccountService) GetAccountByName(name string) (*Account, int, error) { } // This is a courtesy helper function, which in some cases may not work as expected! -func (s *AccountService) GetAccountByID(id string) (*Account, int, error) { +func (s *AccountService) GetAccountByID(id string, opts ...OptionFunc) (*Account, int, error) { p := &ListAccountsParams{} 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.ListAccounts(p) if err != nil { if strings.Contains(err.Error(), fmt.Sprintf( @@ -1716,28 +1728,24 @@ func (s *AccountService) NewListProjectAccountsParams(projectid string) *ListPro } // This is a courtesy helper function, which in some cases may not work as expected! -func (s *AccountService) GetProjectAccountID(keyword string, projectid string) (string, error) { +func (s *AccountService) GetProjectAccountID(keyword string, projectid string, opts ...OptionFunc) (string, error) { p := &ListProjectAccountsParams{} p.p = make(map[string]interface{}) p.p["keyword"] = keyword p.p["projectid"] = projectid + for _, fn := range opts { + if err := fn(s.cs, p); err != nil { + return "", err + } + } + l, err := s.ListProjectAccounts(p) if err != nil { return "", err } - if l.Count == 0 { - // If no matches, search all projects - p.p["projectid"] = "-1" - - l, err = s.ListProjectAccounts(p) - if err != nil { - return "", err - } - } - if l.Count == 0 { return "", fmt.Errorf("No match found for %s: %+v", keyword, l) } diff --git a/vendor/github.com/xanzy/go-cloudstack/cloudstack/AddressService.go b/vendor/github.com/xanzy/go-cloudstack/cloudstack/AddressService.go index fad3476096..9ffc6d9b81 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 2014, Sander van Harmelen +// Copyright 2016, 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. @@ -581,12 +581,18 @@ func (s *AddressService) NewListPublicIpAddressesParams() *ListPublicIpAddresses } // This is a courtesy helper function, which in some cases may not work as expected! -func (s *AddressService) GetPublicIpAddressByID(id string) (*PublicIpAddress, int, error) { +func (s *AddressService) GetPublicIpAddressByID(id string, opts ...OptionFunc) (*PublicIpAddress, int, error) { p := &ListPublicIpAddressesParams{} 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.ListPublicIpAddresses(p) if err != nil { if strings.Contains(err.Error(), fmt.Sprintf( @@ -597,21 +603,6 @@ func (s *AddressService) GetPublicIpAddressByID(id string) (*PublicIpAddress, in return nil, -1, err } - if l.Count == 0 { - // If no matches, search all projects - p.p["projectid"] = "-1" - - l, err = s.ListPublicIpAddresses(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) } diff --git a/vendor/github.com/xanzy/go-cloudstack/cloudstack/AffinityGroupService.go b/vendor/github.com/xanzy/go-cloudstack/cloudstack/AffinityGroupService.go index 92fd5dcdb7..5511cbcad6 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 2014, Sander van Harmelen +// Copyright 2016, 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. @@ -427,27 +427,23 @@ func (s *AffinityGroupService) NewListAffinityGroupsParams() *ListAffinityGroups } // This is a courtesy helper function, which in some cases may not work as expected! -func (s *AffinityGroupService) GetAffinityGroupID(name string) (string, error) { +func (s *AffinityGroupService) GetAffinityGroupID(name string, opts ...OptionFunc) (string, error) { p := &ListAffinityGroupsParams{} p.p = make(map[string]interface{}) p.p["name"] = name + for _, fn := range opts { + if err := fn(s.cs, p); err != nil { + return "", err + } + } + l, err := s.ListAffinityGroups(p) if err != nil { return "", err } - if l.Count == 0 { - // If no matches, search all projects - p.p["projectid"] = "-1" - - l, err = s.ListAffinityGroups(p) - if err != nil { - return "", err - } - } - if l.Count == 0 { return "", fmt.Errorf("No match found for %s: %+v", name, l) } @@ -467,13 +463,13 @@ func (s *AffinityGroupService) GetAffinityGroupID(name string) (string, error) { } // This is a courtesy helper function, which in some cases may not work as expected! -func (s *AffinityGroupService) GetAffinityGroupByName(name string) (*AffinityGroup, int, error) { - id, err := s.GetAffinityGroupID(name) +func (s *AffinityGroupService) GetAffinityGroupByName(name string, opts ...OptionFunc) (*AffinityGroup, int, error) { + id, err := s.GetAffinityGroupID(name, opts...) if err != nil { return nil, -1, err } - r, count, err := s.GetAffinityGroupByID(id) + r, count, err := s.GetAffinityGroupByID(id, opts...) if err != nil { return nil, count, err } @@ -481,12 +477,18 @@ func (s *AffinityGroupService) GetAffinityGroupByName(name string) (*AffinityGro } // This is a courtesy helper function, which in some cases may not work as expected! -func (s *AffinityGroupService) GetAffinityGroupByID(id string) (*AffinityGroup, int, error) { +func (s *AffinityGroupService) GetAffinityGroupByID(id string, opts ...OptionFunc) (*AffinityGroup, int, error) { p := &ListAffinityGroupsParams{} 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.ListAffinityGroups(p) if err != nil { if strings.Contains(err.Error(), fmt.Sprintf( @@ -497,21 +499,6 @@ func (s *AffinityGroupService) GetAffinityGroupByID(id string) (*AffinityGroup, return nil, -1, err } - if l.Count == 0 { - // If no matches, search all projects - p.p["projectid"] = "-1" - - l, err = s.ListAffinityGroups(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) } diff --git a/vendor/github.com/xanzy/go-cloudstack/cloudstack/AlertService.go b/vendor/github.com/xanzy/go-cloudstack/cloudstack/AlertService.go index 2cfd4b291e..a91f17cdf5 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 2014, Sander van Harmelen +// Copyright 2016, 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. @@ -113,12 +113,18 @@ func (s *AlertService) NewListAlertsParams() *ListAlertsParams { } // This is a courtesy helper function, which in some cases may not work as expected! -func (s *AlertService) GetAlertID(name string) (string, error) { +func (s *AlertService) GetAlertID(name string, opts ...OptionFunc) (string, 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 "", err + } + } + l, err := s.ListAlerts(p) if err != nil { return "", err @@ -143,13 +149,13 @@ func (s *AlertService) GetAlertID(name string) (string, error) { } // This is a courtesy helper function, which in some cases may not work as expected! -func (s *AlertService) GetAlertByName(name string) (*Alert, int, error) { - id, err := s.GetAlertID(name) +func (s *AlertService) GetAlertByName(name string, opts ...OptionFunc) (*Alert, int, error) { + id, err := s.GetAlertID(name, opts...) if err != nil { return nil, -1, err } - r, count, err := s.GetAlertByID(id) + r, count, err := s.GetAlertByID(id, opts...) if err != nil { return nil, count, err } @@ -157,12 +163,18 @@ func (s *AlertService) GetAlertByName(name string) (*Alert, int, error) { } // This is a courtesy helper function, which in some cases may not work as expected! -func (s *AlertService) GetAlertByID(id string) (*Alert, int, error) { +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( diff --git a/vendor/github.com/xanzy/go-cloudstack/cloudstack/AsyncjobService.go b/vendor/github.com/xanzy/go-cloudstack/cloudstack/AsyncjobService.go index ca21e7f043..b3e1fd89a9 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 2014, Sander van Harmelen +// Copyright 2016, 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. diff --git a/vendor/github.com/xanzy/go-cloudstack/cloudstack/AuthenticationService.go b/vendor/github.com/xanzy/go-cloudstack/cloudstack/AuthenticationService.go index 6839870f76..b97e70cfac 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 2014, Sander van Harmelen +// Copyright 2016, 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. diff --git a/vendor/github.com/xanzy/go-cloudstack/cloudstack/AutoScaleService.go b/vendor/github.com/xanzy/go-cloudstack/cloudstack/AutoScaleService.go index 65a1d2e05b..eaec8dd038 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 2014, Sander van Harmelen +// Copyright 2016, 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. @@ -1134,12 +1134,18 @@ func (s *AutoScaleService) NewListCountersParams() *ListCountersParams { } // This is a courtesy helper function, which in some cases may not work as expected! -func (s *AutoScaleService) GetCounterID(name string) (string, error) { +func (s *AutoScaleService) GetCounterID(name string, opts ...OptionFunc) (string, 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 "", err + } + } + l, err := s.ListCounters(p) if err != nil { return "", err @@ -1164,13 +1170,13 @@ func (s *AutoScaleService) GetCounterID(name string) (string, error) { } // This is a courtesy helper function, which in some cases may not work as expected! -func (s *AutoScaleService) GetCounterByName(name string) (*Counter, int, error) { - id, err := s.GetCounterID(name) +func (s *AutoScaleService) GetCounterByName(name string, opts ...OptionFunc) (*Counter, int, error) { + id, err := s.GetCounterID(name, opts...) if err != nil { return nil, -1, err } - r, count, err := s.GetCounterByID(id) + r, count, err := s.GetCounterByID(id, opts...) if err != nil { return nil, count, err } @@ -1178,12 +1184,18 @@ func (s *AutoScaleService) GetCounterByName(name string) (*Counter, int, error) } // This is a courtesy helper function, which in some cases may not work as expected! -func (s *AutoScaleService) GetCounterByID(id string) (*Counter, int, error) { +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 + } + } + l, err := s.ListCounters(p) if err != nil { if strings.Contains(err.Error(), fmt.Sprintf( @@ -1366,12 +1378,18 @@ func (s *AutoScaleService) NewListConditionsParams() *ListConditionsParams { } // This is a courtesy helper function, which in some cases may not work as expected! -func (s *AutoScaleService) GetConditionByID(id string) (*Condition, int, error) { +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( @@ -1570,12 +1588,18 @@ func (s *AutoScaleService) NewListAutoScalePoliciesParams() *ListAutoScalePolici } // This is a courtesy helper function, which in some cases may not work as expected! -func (s *AutoScaleService) GetAutoScalePolicyByID(id string) (*AutoScalePolicy, int, error) { +func (s *AutoScaleService) GetAutoScalePolicyByID(id string, opts ...OptionFunc) (*AutoScalePolicy, int, error) { p := &ListAutoScalePoliciesParams{} 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.ListAutoScalePolicies(p) if err != nil { if strings.Contains(err.Error(), fmt.Sprintf( @@ -1808,12 +1832,18 @@ func (s *AutoScaleService) NewListAutoScaleVmProfilesParams() *ListAutoScaleVmPr } // This is a courtesy helper function, which in some cases may not work as expected! -func (s *AutoScaleService) GetAutoScaleVmProfileByID(id string) (*AutoScaleVmProfile, int, error) { +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( @@ -1824,21 +1854,6 @@ func (s *AutoScaleService) GetAutoScaleVmProfileByID(id string) (*AutoScaleVmPro return nil, -1, err } - if l.Count == 0 { - // If no matches, search all projects - p.p["projectid"] = "-1" - - 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) } @@ -2064,12 +2079,18 @@ func (s *AutoScaleService) NewListAutoScaleVmGroupsParams() *ListAutoScaleVmGrou } // This is a courtesy helper function, which in some cases may not work as expected! -func (s *AutoScaleService) GetAutoScaleVmGroupByID(id string) (*AutoScaleVmGroup, int, error) { +func (s *AutoScaleService) GetAutoScaleVmGroupByID(id string, opts ...OptionFunc) (*AutoScaleVmGroup, int, error) { p := &ListAutoScaleVmGroupsParams{} 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.ListAutoScaleVmGroups(p) if err != nil { if strings.Contains(err.Error(), fmt.Sprintf( @@ -2080,21 +2101,6 @@ func (s *AutoScaleService) GetAutoScaleVmGroupByID(id string) (*AutoScaleVmGroup return nil, -1, err } - if l.Count == 0 { - // If no matches, search all projects - p.p["projectid"] = "-1" - - l, err = s.ListAutoScaleVmGroups(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) } diff --git a/vendor/github.com/xanzy/go-cloudstack/cloudstack/BaremetalService.go b/vendor/github.com/xanzy/go-cloudstack/cloudstack/BaremetalService.go index 5d3f8976e6..c1b7eaaba8 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 2014, Sander van Harmelen +// Copyright 2016, 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. diff --git a/vendor/github.com/xanzy/go-cloudstack/cloudstack/CertificateService.go b/vendor/github.com/xanzy/go-cloudstack/cloudstack/CertificateService.go index dc125a02f2..a13fcdfc21 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 2014, Sander van Harmelen +// Copyright 2016, 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. diff --git a/vendor/github.com/xanzy/go-cloudstack/cloudstack/CloudIdentifierService.go b/vendor/github.com/xanzy/go-cloudstack/cloudstack/CloudIdentifierService.go index 0572bcdee1..99eeba2c8e 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 2014, Sander van Harmelen +// Copyright 2016, 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. diff --git a/vendor/github.com/xanzy/go-cloudstack/cloudstack/ClusterService.go b/vendor/github.com/xanzy/go-cloudstack/cloudstack/ClusterService.go index c9c346e8a5..a4fe1fe9c2 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 2014, Sander van Harmelen +// Copyright 2016, 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. @@ -636,12 +636,18 @@ func (s *ClusterService) NewListClustersParams() *ListClustersParams { } // This is a courtesy helper function, which in some cases may not work as expected! -func (s *ClusterService) GetClusterID(name string) (string, error) { +func (s *ClusterService) GetClusterID(name string, opts ...OptionFunc) (string, error) { p := &ListClustersParams{} p.p = make(map[string]interface{}) p.p["name"] = name + for _, fn := range opts { + if err := fn(s.cs, p); err != nil { + return "", err + } + } + l, err := s.ListClusters(p) if err != nil { return "", err @@ -666,13 +672,13 @@ func (s *ClusterService) GetClusterID(name string) (string, error) { } // This is a courtesy helper function, which in some cases may not work as expected! -func (s *ClusterService) GetClusterByName(name string) (*Cluster, int, error) { - id, err := s.GetClusterID(name) +func (s *ClusterService) GetClusterByName(name string, opts ...OptionFunc) (*Cluster, int, error) { + id, err := s.GetClusterID(name, opts...) if err != nil { return nil, -1, err } - r, count, err := s.GetClusterByID(id) + r, count, err := s.GetClusterByID(id, opts...) if err != nil { return nil, count, err } @@ -680,12 +686,18 @@ func (s *ClusterService) GetClusterByName(name string) (*Cluster, int, error) { } // This is a courtesy helper function, which in some cases may not work as expected! -func (s *ClusterService) GetClusterByID(id string) (*Cluster, int, error) { +func (s *ClusterService) GetClusterByID(id string, opts ...OptionFunc) (*Cluster, int, error) { p := &ListClustersParams{} 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.ListClusters(p) if err != nil { if strings.Contains(err.Error(), fmt.Sprintf( diff --git a/vendor/github.com/xanzy/go-cloudstack/cloudstack/ConfigurationService.go b/vendor/github.com/xanzy/go-cloudstack/cloudstack/ConfigurationService.go index af9f46a341..b4a6a7b1bf 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 2014, Sander van Harmelen +// Copyright 2016, 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. diff --git a/vendor/github.com/xanzy/go-cloudstack/cloudstack/DiskOfferingService.go b/vendor/github.com/xanzy/go-cloudstack/cloudstack/DiskOfferingService.go index 72f781afe1..6511df393f 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 2014, Sander van Harmelen +// Copyright 2016, 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. @@ -562,12 +562,18 @@ func (s *DiskOfferingService) NewListDiskOfferingsParams() *ListDiskOfferingsPar } // This is a courtesy helper function, which in some cases may not work as expected! -func (s *DiskOfferingService) GetDiskOfferingID(name string) (string, error) { +func (s *DiskOfferingService) GetDiskOfferingID(name string, opts ...OptionFunc) (string, error) { p := &ListDiskOfferingsParams{} p.p = make(map[string]interface{}) p.p["name"] = name + for _, fn := range opts { + if err := fn(s.cs, p); err != nil { + return "", err + } + } + l, err := s.ListDiskOfferings(p) if err != nil { return "", err @@ -592,13 +598,13 @@ func (s *DiskOfferingService) GetDiskOfferingID(name string) (string, error) { } // This is a courtesy helper function, which in some cases may not work as expected! -func (s *DiskOfferingService) GetDiskOfferingByName(name string) (*DiskOffering, int, error) { - id, err := s.GetDiskOfferingID(name) +func (s *DiskOfferingService) GetDiskOfferingByName(name string, opts ...OptionFunc) (*DiskOffering, int, error) { + id, err := s.GetDiskOfferingID(name, opts...) if err != nil { return nil, -1, err } - r, count, err := s.GetDiskOfferingByID(id) + r, count, err := s.GetDiskOfferingByID(id, opts...) if err != nil { return nil, count, err } @@ -606,12 +612,18 @@ func (s *DiskOfferingService) GetDiskOfferingByName(name string) (*DiskOffering, } // This is a courtesy helper function, which in some cases may not work as expected! -func (s *DiskOfferingService) GetDiskOfferingByID(id string) (*DiskOffering, int, error) { +func (s *DiskOfferingService) GetDiskOfferingByID(id string, opts ...OptionFunc) (*DiskOffering, int, error) { p := &ListDiskOfferingsParams{} 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.ListDiskOfferings(p) if err != nil { if strings.Contains(err.Error(), fmt.Sprintf( diff --git a/vendor/github.com/xanzy/go-cloudstack/cloudstack/DomainService.go b/vendor/github.com/xanzy/go-cloudstack/cloudstack/DomainService.go index 21595ed4cc..01107241b6 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 2014, Sander van Harmelen +// Copyright 2016, 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. @@ -448,12 +448,18 @@ func (s *DomainService) NewListDomainsParams() *ListDomainsParams { } // This is a courtesy helper function, which in some cases may not work as expected! -func (s *DomainService) GetDomainID(name string) (string, error) { +func (s *DomainService) GetDomainID(name string, opts ...OptionFunc) (string, 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 "", err + } + } + l, err := s.ListDomains(p) if err != nil { return "", err @@ -478,13 +484,13 @@ func (s *DomainService) GetDomainID(name string) (string, error) { } // This is a courtesy helper function, which in some cases may not work as expected! -func (s *DomainService) GetDomainByName(name string) (*Domain, int, error) { - id, err := s.GetDomainID(name) +func (s *DomainService) GetDomainByName(name string, opts ...OptionFunc) (*Domain, int, error) { + id, err := s.GetDomainID(name, opts...) if err != nil { return nil, -1, err } - r, count, err := s.GetDomainByID(id) + r, count, err := s.GetDomainByID(id, opts...) if err != nil { return nil, count, err } @@ -492,12 +498,18 @@ func (s *DomainService) GetDomainByName(name string) (*Domain, int, error) { } // This is a courtesy helper function, which in some cases may not work as expected! -func (s *DomainService) GetDomainByID(id string) (*Domain, int, error) { +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( @@ -687,12 +699,18 @@ func (s *DomainService) NewListDomainChildrenParams() *ListDomainChildrenParams } // This is a courtesy helper function, which in some cases may not work as expected! -func (s *DomainService) GetDomainChildrenID(name string) (string, error) { +func (s *DomainService) GetDomainChildrenID(name string, opts ...OptionFunc) (string, error) { p := &ListDomainChildrenParams{} p.p = make(map[string]interface{}) p.p["name"] = name + for _, fn := range opts { + if err := fn(s.cs, p); err != nil { + return "", err + } + } + l, err := s.ListDomainChildren(p) if err != nil { return "", err @@ -717,13 +735,13 @@ func (s *DomainService) GetDomainChildrenID(name string) (string, error) { } // This is a courtesy helper function, which in some cases may not work as expected! -func (s *DomainService) GetDomainChildrenByName(name string) (*DomainChildren, int, error) { - id, err := s.GetDomainChildrenID(name) +func (s *DomainService) GetDomainChildrenByName(name string, opts ...OptionFunc) (*DomainChildren, int, error) { + id, err := s.GetDomainChildrenID(name, opts...) if err != nil { return nil, -1, err } - r, count, err := s.GetDomainChildrenByID(id) + r, count, err := s.GetDomainChildrenByID(id, opts...) if err != nil { return nil, count, err } @@ -731,12 +749,18 @@ func (s *DomainService) GetDomainChildrenByName(name string) (*DomainChildren, i } // This is a courtesy helper function, which in some cases may not work as expected! -func (s *DomainService) GetDomainChildrenByID(id string) (*DomainChildren, int, error) { +func (s *DomainService) GetDomainChildrenByID(id string, opts ...OptionFunc) (*DomainChildren, int, error) { p := &ListDomainChildrenParams{} 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.ListDomainChildren(p) if err != nil { if strings.Contains(err.Error(), fmt.Sprintf( diff --git a/vendor/github.com/xanzy/go-cloudstack/cloudstack/EventService.go b/vendor/github.com/xanzy/go-cloudstack/cloudstack/EventService.go index 23e53bb548..dee8297133 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 2014, Sander van Harmelen +// Copyright 2016, 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. @@ -216,12 +216,18 @@ func (s *EventService) NewListEventsParams() *ListEventsParams { } // This is a courtesy helper function, which in some cases may not work as expected! -func (s *EventService) GetEventByID(id string) (*Event, int, error) { +func (s *EventService) GetEventByID(id string, opts ...OptionFunc) (*Event, int, error) { p := &ListEventsParams{} 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.ListEvents(p) if err != nil { if strings.Contains(err.Error(), fmt.Sprintf( @@ -232,21 +238,6 @@ func (s *EventService) GetEventByID(id string) (*Event, int, error) { return nil, -1, err } - if l.Count == 0 { - // If no matches, search all projects - p.p["projectid"] = "-1" - - l, err = s.ListEvents(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) } diff --git a/vendor/github.com/xanzy/go-cloudstack/cloudstack/FirewallService.go b/vendor/github.com/xanzy/go-cloudstack/cloudstack/FirewallService.go index a544a99f7b..3c7c17ddb2 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 2014, Sander van Harmelen +// Copyright 2016, 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. @@ -248,12 +248,18 @@ func (s *FirewallService) NewListPortForwardingRulesParams() *ListPortForwarding } // This is a courtesy helper function, which in some cases may not work as expected! -func (s *FirewallService) GetPortForwardingRuleByID(id string) (*PortForwardingRule, int, error) { +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( @@ -264,21 +270,6 @@ func (s *FirewallService) GetPortForwardingRuleByID(id string) (*PortForwardingR return nil, -1, err } - if l.Count == 0 { - // If no matches, search all projects - p.p["projectid"] = "-1" - - 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) } @@ -1276,12 +1267,18 @@ func (s *FirewallService) NewListFirewallRulesParams() *ListFirewallRulesParams } // This is a courtesy helper function, which in some cases may not work as expected! -func (s *FirewallService) GetFirewallRuleByID(id string) (*FirewallRule, int, error) { +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( @@ -1292,21 +1289,6 @@ func (s *FirewallService) GetFirewallRuleByID(id string) (*FirewallRule, int, er return nil, -1, err } - if l.Count == 0 { - // If no matches, search all projects - p.p["projectid"] = "-1" - - 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) } @@ -1945,12 +1927,18 @@ func (s *FirewallService) NewListEgressFirewallRulesParams() *ListEgressFirewall } // This is a courtesy helper function, which in some cases may not work as expected! -func (s *FirewallService) GetEgressFirewallRuleByID(id string) (*EgressFirewallRule, int, error) { +func (s *FirewallService) GetEgressFirewallRuleByID(id string, opts ...OptionFunc) (*EgressFirewallRule, int, error) { p := &ListEgressFirewallRulesParams{} 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.ListEgressFirewallRules(p) if err != nil { if strings.Contains(err.Error(), fmt.Sprintf( @@ -1961,21 +1949,6 @@ func (s *FirewallService) GetEgressFirewallRuleByID(id string) (*EgressFirewallR return nil, -1, err } - if l.Count == 0 { - // If no matches, search all projects - p.p["projectid"] = "-1" - - l, err = s.ListEgressFirewallRules(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) } diff --git a/vendor/github.com/xanzy/go-cloudstack/cloudstack/GuestOSService.go b/vendor/github.com/xanzy/go-cloudstack/cloudstack/GuestOSService.go index 1cbff4db0e..0a8ce305da 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 2014, Sander van Harmelen +// Copyright 2016, 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. @@ -113,12 +113,18 @@ func (s *GuestOSService) NewListOsTypesParams() *ListOsTypesParams { } // This is a courtesy helper function, which in some cases may not work as expected! -func (s *GuestOSService) GetOsTypeByID(id string) (*OsType, int, error) { +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( @@ -243,12 +249,18 @@ func (s *GuestOSService) NewListOsCategoriesParams() *ListOsCategoriesParams { } // This is a courtesy helper function, which in some cases may not work as expected! -func (s *GuestOSService) GetOsCategoryID(name string) (string, error) { +func (s *GuestOSService) GetOsCategoryID(name string, opts ...OptionFunc) (string, 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 "", err + } + } + l, err := s.ListOsCategories(p) if err != nil { return "", err @@ -273,13 +285,13 @@ func (s *GuestOSService) GetOsCategoryID(name string) (string, error) { } // This is a courtesy helper function, which in some cases may not work as expected! -func (s *GuestOSService) GetOsCategoryByName(name string) (*OsCategory, int, error) { - id, err := s.GetOsCategoryID(name) +func (s *GuestOSService) GetOsCategoryByName(name string, opts ...OptionFunc) (*OsCategory, int, error) { + id, err := s.GetOsCategoryID(name, opts...) if err != nil { return nil, -1, err } - r, count, err := s.GetOsCategoryByID(id) + r, count, err := s.GetOsCategoryByID(id, opts...) if err != nil { return nil, count, err } @@ -287,12 +299,18 @@ func (s *GuestOSService) GetOsCategoryByName(name string) (*OsCategory, int, err } // This is a courtesy helper function, which in some cases may not work as expected! -func (s *GuestOSService) GetOsCategoryByID(id string) (*OsCategory, int, error) { +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( @@ -687,12 +705,18 @@ func (s *GuestOSService) NewListGuestOsMappingParams() *ListGuestOsMappingParams } // This is a courtesy helper function, which in some cases may not work as expected! -func (s *GuestOSService) GetGuestOsMappingByID(id string) (*GuestOsMapping, int, error) { +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( diff --git a/vendor/github.com/xanzy/go-cloudstack/cloudstack/HostService.go b/vendor/github.com/xanzy/go-cloudstack/cloudstack/HostService.go index ebe619f706..6d0836696b 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 2014, Sander van Harmelen +// Copyright 2016, 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. @@ -1037,12 +1037,18 @@ func (s *HostService) NewListHostsParams() *ListHostsParams { } // This is a courtesy helper function, which in some cases may not work as expected! -func (s *HostService) GetHostID(name string) (string, error) { +func (s *HostService) GetHostID(name string, opts ...OptionFunc) (string, 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 "", err + } + } + l, err := s.ListHosts(p) if err != nil { return "", err @@ -1067,13 +1073,13 @@ func (s *HostService) GetHostID(name string) (string, error) { } // This is a courtesy helper function, which in some cases may not work as expected! -func (s *HostService) GetHostByName(name string) (*Host, int, error) { - id, err := s.GetHostID(name) +func (s *HostService) GetHostByName(name string, opts ...OptionFunc) (*Host, int, error) { + id, err := s.GetHostID(name, opts...) if err != nil { return nil, -1, err } - r, count, err := s.GetHostByID(id) + r, count, err := s.GetHostByID(id, opts...) if err != nil { return nil, count, err } @@ -1081,12 +1087,18 @@ func (s *HostService) GetHostByName(name string) (*Host, int, error) { } // This is a courtesy helper function, which in some cases may not work as expected! -func (s *HostService) GetHostByID(id string) (*Host, int, error) { +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( @@ -1243,12 +1255,18 @@ func (s *HostService) NewListHostTagsParams() *ListHostTagsParams { } // This is a courtesy helper function, which in some cases may not work as expected! -func (s *HostService) GetHostTagID(keyword string) (string, error) { +func (s *HostService) GetHostTagID(keyword string, opts ...OptionFunc) (string, 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 "", err + } + } + l, err := s.ListHostTags(p) if err != nil { return "", err diff --git a/vendor/github.com/xanzy/go-cloudstack/cloudstack/HypervisorService.go b/vendor/github.com/xanzy/go-cloudstack/cloudstack/HypervisorService.go index aaabfadaab..c172615c98 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 2014, Sander van Harmelen +// Copyright 2016, 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. @@ -236,12 +236,18 @@ func (s *HypervisorService) NewListHypervisorCapabilitiesParams() *ListHyperviso } // This is a courtesy helper function, which in some cases may not work as expected! -func (s *HypervisorService) GetHypervisorCapabilityByID(id string) (*HypervisorCapability, int, error) { +func (s *HypervisorService) GetHypervisorCapabilityByID(id string, opts ...OptionFunc) (*HypervisorCapability, int, error) { p := &ListHypervisorCapabilitiesParams{} 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.ListHypervisorCapabilities(p) if err != nil { if strings.Contains(err.Error(), fmt.Sprintf( diff --git a/vendor/github.com/xanzy/go-cloudstack/cloudstack/ISOService.go b/vendor/github.com/xanzy/go-cloudstack/cloudstack/ISOService.go index f8efcaedd8..7cf1c92ec5 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 2014, Sander van Harmelen +// Copyright 2016, 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. @@ -754,7 +754,7 @@ func (s *ISOService) NewListIsosParams() *ListIsosParams { } // This is a courtesy helper function, which in some cases may not work as expected! -func (s *ISOService) GetIsoID(name string, isofilter string, zoneid string) (string, error) { +func (s *ISOService) GetIsoID(name string, isofilter string, zoneid string, opts ...OptionFunc) (string, error) { p := &ListIsosParams{} p.p = make(map[string]interface{}) @@ -762,21 +762,17 @@ func (s *ISOService) GetIsoID(name string, isofilter string, zoneid string) (str p.p["isofilter"] = isofilter p.p["zoneid"] = zoneid + for _, fn := range opts { + if err := fn(s.cs, p); err != nil { + return "", err + } + } + l, err := s.ListIsos(p) if err != nil { return "", err } - if l.Count == 0 { - // If no matches, search all projects - p.p["projectid"] = "-1" - - l, err = s.ListIsos(p) - if err != nil { - return "", err - } - } - if l.Count == 0 { return "", fmt.Errorf("No match found for %s: %+v", name, l) } @@ -796,13 +792,13 @@ func (s *ISOService) GetIsoID(name string, isofilter string, zoneid string) (str } // This is a courtesy helper function, which in some cases may not work as expected! -func (s *ISOService) GetIsoByName(name string, isofilter string, zoneid string) (*Iso, int, error) { - id, err := s.GetIsoID(name, isofilter, zoneid) +func (s *ISOService) GetIsoByName(name string, isofilter string, zoneid string, opts ...OptionFunc) (*Iso, int, error) { + id, err := s.GetIsoID(name, isofilter, zoneid, opts...) if err != nil { return nil, -1, err } - r, count, err := s.GetIsoByID(id) + r, count, err := s.GetIsoByID(id, opts...) if err != nil { return nil, count, err } @@ -810,12 +806,18 @@ func (s *ISOService) GetIsoByName(name string, isofilter string, zoneid string) } // This is a courtesy helper function, which in some cases may not work as expected! -func (s *ISOService) GetIsoByID(id string) (*Iso, int, error) { +func (s *ISOService) GetIsoByID(id string, opts ...OptionFunc) (*Iso, int, error) { p := &ListIsosParams{} 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.ListIsos(p) if err != nil { if strings.Contains(err.Error(), fmt.Sprintf( @@ -826,21 +828,6 @@ func (s *ISOService) GetIsoByID(id string) (*Iso, int, error) { return nil, -1, err } - if l.Count == 0 { - // If no matches, search all projects - p.p["projectid"] = "-1" - - l, err = s.ListIsos(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) } @@ -1779,13 +1766,19 @@ func (s *ISOService) NewListIsoPermissionsParams(id string) *ListIsoPermissionsP } // This is a courtesy helper function, which in some cases may not work as expected! -func (s *ISOService) GetIsoPermissionByID(id string) (*IsoPermission, int, error) { +func (s *ISOService) GetIsoPermissionByID(id string, opts ...OptionFunc) (*IsoPermission, int, error) { p := &ListIsoPermissionsParams{} p.p = make(map[string]interface{}) p.p["id"] = id 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) if err != nil { if strings.Contains(err.Error(), fmt.Sprintf( diff --git a/vendor/github.com/xanzy/go-cloudstack/cloudstack/ImageStoreService.go b/vendor/github.com/xanzy/go-cloudstack/cloudstack/ImageStoreService.go index accae7deb4..1795e4c9ba 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 2014, Sander van Harmelen +// Copyright 2016, 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. @@ -419,12 +419,18 @@ func (s *ImageStoreService) NewListImageStoresParams() *ListImageStoresParams { } // This is a courtesy helper function, which in some cases may not work as expected! -func (s *ImageStoreService) GetImageStoreID(name string) (string, error) { +func (s *ImageStoreService) GetImageStoreID(name string, opts ...OptionFunc) (string, error) { p := &ListImageStoresParams{} p.p = make(map[string]interface{}) p.p["name"] = name + for _, fn := range opts { + if err := fn(s.cs, p); err != nil { + return "", err + } + } + l, err := s.ListImageStores(p) if err != nil { return "", err @@ -449,13 +455,13 @@ func (s *ImageStoreService) GetImageStoreID(name string) (string, error) { } // This is a courtesy helper function, which in some cases may not work as expected! -func (s *ImageStoreService) GetImageStoreByName(name string) (*ImageStore, int, error) { - id, err := s.GetImageStoreID(name) +func (s *ImageStoreService) GetImageStoreByName(name string, opts ...OptionFunc) (*ImageStore, int, error) { + id, err := s.GetImageStoreID(name, opts...) if err != nil { return nil, -1, err } - r, count, err := s.GetImageStoreByID(id) + r, count, err := s.GetImageStoreByID(id, opts...) if err != nil { return nil, count, err } @@ -463,12 +469,18 @@ func (s *ImageStoreService) GetImageStoreByName(name string) (*ImageStore, int, } // This is a courtesy helper function, which in some cases may not work as expected! -func (s *ImageStoreService) GetImageStoreByID(id string) (*ImageStore, int, error) { +func (s *ImageStoreService) GetImageStoreByID(id string, opts ...OptionFunc) (*ImageStore, int, error) { p := &ListImageStoresParams{} 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.ListImageStores(p) if err != nil { if strings.Contains(err.Error(), fmt.Sprintf( @@ -789,12 +801,18 @@ func (s *ImageStoreService) NewListSecondaryStagingStoresParams() *ListSecondary } // This is a courtesy helper function, which in some cases may not work as expected! -func (s *ImageStoreService) GetSecondaryStagingStoreID(name string) (string, error) { +func (s *ImageStoreService) GetSecondaryStagingStoreID(name string, opts ...OptionFunc) (string, error) { p := &ListSecondaryStagingStoresParams{} p.p = make(map[string]interface{}) p.p["name"] = name + for _, fn := range opts { + if err := fn(s.cs, p); err != nil { + return "", err + } + } + l, err := s.ListSecondaryStagingStores(p) if err != nil { return "", err @@ -819,13 +837,13 @@ func (s *ImageStoreService) GetSecondaryStagingStoreID(name string) (string, err } // This is a courtesy helper function, which in some cases may not work as expected! -func (s *ImageStoreService) GetSecondaryStagingStoreByName(name string) (*SecondaryStagingStore, int, error) { - id, err := s.GetSecondaryStagingStoreID(name) +func (s *ImageStoreService) GetSecondaryStagingStoreByName(name string, opts ...OptionFunc) (*SecondaryStagingStore, int, error) { + id, err := s.GetSecondaryStagingStoreID(name, opts...) if err != nil { return nil, -1, err } - r, count, err := s.GetSecondaryStagingStoreByID(id) + r, count, err := s.GetSecondaryStagingStoreByID(id, opts...) if err != nil { return nil, count, err } @@ -833,12 +851,18 @@ func (s *ImageStoreService) GetSecondaryStagingStoreByName(name string) (*Second } // This is a courtesy helper function, which in some cases may not work as expected! -func (s *ImageStoreService) GetSecondaryStagingStoreByID(id string) (*SecondaryStagingStore, int, error) { +func (s *ImageStoreService) GetSecondaryStagingStoreByID(id string, opts ...OptionFunc) (*SecondaryStagingStore, int, error) { p := &ListSecondaryStagingStoresParams{} 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.ListSecondaryStagingStores(p) if err != nil { if strings.Contains(err.Error(), fmt.Sprintf( diff --git a/vendor/github.com/xanzy/go-cloudstack/cloudstack/InternalLBService.go b/vendor/github.com/xanzy/go-cloudstack/cloudstack/InternalLBService.go index 71eab8f57f..bc0505c41b 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 2014, Sander van Harmelen +// Copyright 2016, 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. @@ -273,12 +273,18 @@ func (s *InternalLBService) NewListInternalLoadBalancerElementsParams() *ListInt } // This is a courtesy helper function, which in some cases may not work as expected! -func (s *InternalLBService) GetInternalLoadBalancerElementByID(id string) (*InternalLoadBalancerElement, int, error) { +func (s *InternalLBService) GetInternalLoadBalancerElementByID(id string, opts ...OptionFunc) (*InternalLoadBalancerElement, int, error) { p := &ListInternalLoadBalancerElementsParams{} 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.ListInternalLoadBalancerElements(p) if err != nil { if strings.Contains(err.Error(), fmt.Sprintf( @@ -825,27 +831,23 @@ func (s *InternalLBService) NewListInternalLoadBalancerVMsParams() *ListInternal } // This is a courtesy helper function, which in some cases may not work as expected! -func (s *InternalLBService) GetInternalLoadBalancerVMID(name string) (string, error) { +func (s *InternalLBService) GetInternalLoadBalancerVMID(name string, opts ...OptionFunc) (string, error) { p := &ListInternalLoadBalancerVMsParams{} p.p = make(map[string]interface{}) p.p["name"] = name + for _, fn := range opts { + if err := fn(s.cs, p); err != nil { + return "", err + } + } + l, err := s.ListInternalLoadBalancerVMs(p) if err != nil { return "", err } - if l.Count == 0 { - // If no matches, search all projects - p.p["projectid"] = "-1" - - l, err = s.ListInternalLoadBalancerVMs(p) - if err != nil { - return "", err - } - } - if l.Count == 0 { return "", fmt.Errorf("No match found for %s: %+v", name, l) } @@ -865,13 +867,13 @@ func (s *InternalLBService) GetInternalLoadBalancerVMID(name string) (string, er } // This is a courtesy helper function, which in some cases may not work as expected! -func (s *InternalLBService) GetInternalLoadBalancerVMByName(name string) (*InternalLoadBalancerVM, int, error) { - id, err := s.GetInternalLoadBalancerVMID(name) +func (s *InternalLBService) GetInternalLoadBalancerVMByName(name string, opts ...OptionFunc) (*InternalLoadBalancerVM, int, error) { + id, err := s.GetInternalLoadBalancerVMID(name, opts...) if err != nil { return nil, -1, err } - r, count, err := s.GetInternalLoadBalancerVMByID(id) + r, count, err := s.GetInternalLoadBalancerVMByID(id, opts...) if err != nil { return nil, count, err } @@ -879,12 +881,18 @@ func (s *InternalLBService) GetInternalLoadBalancerVMByName(name string) (*Inter } // This is a courtesy helper function, which in some cases may not work as expected! -func (s *InternalLBService) GetInternalLoadBalancerVMByID(id string) (*InternalLoadBalancerVM, int, error) { +func (s *InternalLBService) GetInternalLoadBalancerVMByID(id string, opts ...OptionFunc) (*InternalLoadBalancerVM, int, error) { p := &ListInternalLoadBalancerVMsParams{} 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.ListInternalLoadBalancerVMs(p) if err != nil { if strings.Contains(err.Error(), fmt.Sprintf( @@ -895,21 +903,6 @@ func (s *InternalLBService) GetInternalLoadBalancerVMByID(id string) (*InternalL return nil, -1, err } - if l.Count == 0 { - // If no matches, search all projects - p.p["projectid"] = "-1" - - l, err = s.ListInternalLoadBalancerVMs(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) } diff --git a/vendor/github.com/xanzy/go-cloudstack/cloudstack/LDAPService.go b/vendor/github.com/xanzy/go-cloudstack/cloudstack/LDAPService.go index f7890854a2..18935c294a 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 2014, Sander van Harmelen +// Copyright 2016, 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. diff --git a/vendor/github.com/xanzy/go-cloudstack/cloudstack/LimitService.go b/vendor/github.com/xanzy/go-cloudstack/cloudstack/LimitService.go index 6aa7e7292f..276abecf8a 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 2014, Sander van Harmelen +// Copyright 2016, 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. diff --git a/vendor/github.com/xanzy/go-cloudstack/cloudstack/LoadBalancerService.go b/vendor/github.com/xanzy/go-cloudstack/cloudstack/LoadBalancerService.go index 0d2bfd4706..c70cf5fb52 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 2014, Sander van Harmelen +// Copyright 2016, 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. @@ -1067,27 +1067,23 @@ func (s *LoadBalancerService) NewListLoadBalancerRulesParams() *ListLoadBalancer } // This is a courtesy helper function, which in some cases may not work as expected! -func (s *LoadBalancerService) GetLoadBalancerRuleID(name string) (string, error) { +func (s *LoadBalancerService) GetLoadBalancerRuleID(name string, opts ...OptionFunc) (string, error) { p := &ListLoadBalancerRulesParams{} p.p = make(map[string]interface{}) p.p["name"] = name + for _, fn := range opts { + if err := fn(s.cs, p); err != nil { + return "", err + } + } + l, err := s.ListLoadBalancerRules(p) if err != nil { return "", err } - if l.Count == 0 { - // If no matches, search all projects - p.p["projectid"] = "-1" - - l, err = s.ListLoadBalancerRules(p) - if err != nil { - return "", err - } - } - if l.Count == 0 { return "", fmt.Errorf("No match found for %s: %+v", name, l) } @@ -1107,13 +1103,13 @@ func (s *LoadBalancerService) GetLoadBalancerRuleID(name string) (string, error) } // This is a courtesy helper function, which in some cases may not work as expected! -func (s *LoadBalancerService) GetLoadBalancerRuleByName(name string) (*LoadBalancerRule, int, error) { - id, err := s.GetLoadBalancerRuleID(name) +func (s *LoadBalancerService) GetLoadBalancerRuleByName(name string, opts ...OptionFunc) (*LoadBalancerRule, int, error) { + id, err := s.GetLoadBalancerRuleID(name, opts...) if err != nil { return nil, -1, err } - r, count, err := s.GetLoadBalancerRuleByID(id) + r, count, err := s.GetLoadBalancerRuleByID(id, opts...) if err != nil { return nil, count, err } @@ -1121,12 +1117,18 @@ func (s *LoadBalancerService) GetLoadBalancerRuleByName(name string) (*LoadBalan } // This is a courtesy helper function, which in some cases may not work as expected! -func (s *LoadBalancerService) GetLoadBalancerRuleByID(id string) (*LoadBalancerRule, int, error) { +func (s *LoadBalancerService) GetLoadBalancerRuleByID(id string, opts ...OptionFunc) (*LoadBalancerRule, int, error) { p := &ListLoadBalancerRulesParams{} 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.ListLoadBalancerRules(p) if err != nil { if strings.Contains(err.Error(), fmt.Sprintf( @@ -1137,21 +1139,6 @@ func (s *LoadBalancerService) GetLoadBalancerRuleByID(id string) (*LoadBalancerR return nil, -1, err } - if l.Count == 0 { - // If no matches, search all projects - p.p["projectid"] = "-1" - - l, err = s.ListLoadBalancerRules(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) } @@ -1305,12 +1292,18 @@ func (s *LoadBalancerService) NewListLBStickinessPoliciesParams() *ListLBStickin } // This is a courtesy helper function, which in some cases may not work as expected! -func (s *LoadBalancerService) GetLBStickinessPolicyByID(id string) (*LBStickinessPolicy, int, error) { +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( @@ -1460,12 +1453,18 @@ func (s *LoadBalancerService) NewListLBHealthCheckPoliciesParams() *ListLBHealth } // This is a courtesy helper function, which in some cases may not work as expected! -func (s *LoadBalancerService) GetLBHealthCheckPolicyByID(id string) (*LBHealthCheckPolicy, int, error) { +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( @@ -1960,13 +1959,19 @@ func (s *LoadBalancerService) NewListLoadBalancerRuleInstancesParams(id string) } // This is a courtesy helper function, which in some cases may not work as expected! -func (s *LoadBalancerService) GetLoadBalancerRuleInstanceByID(id string) (*LoadBalancerRuleInstance, int, error) { +func (s *LoadBalancerService) GetLoadBalancerRuleInstanceByID(id string, opts ...OptionFunc) (*LoadBalancerRuleInstance, int, error) { p := &ListLoadBalancerRuleInstancesParams{} p.p = make(map[string]interface{}) p.p["id"] = id 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( @@ -3656,27 +3661,23 @@ func (s *LoadBalancerService) NewListGlobalLoadBalancerRulesParams() *ListGlobal } // This is a courtesy helper function, which in some cases may not work as expected! -func (s *LoadBalancerService) GetGlobalLoadBalancerRuleID(keyword string) (string, error) { +func (s *LoadBalancerService) GetGlobalLoadBalancerRuleID(keyword string, opts ...OptionFunc) (string, 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 "", err + } + } + l, err := s.ListGlobalLoadBalancerRules(p) if err != nil { return "", err } - if l.Count == 0 { - // If no matches, search all projects - p.p["projectid"] = "-1" - - l, err = s.ListGlobalLoadBalancerRules(p) - if err != nil { - return "", err - } - } - if l.Count == 0 { return "", fmt.Errorf("No match found for %s: %+v", keyword, l) } @@ -3696,13 +3697,13 @@ func (s *LoadBalancerService) GetGlobalLoadBalancerRuleID(keyword string) (strin } // This is a courtesy helper function, which in some cases may not work as expected! -func (s *LoadBalancerService) GetGlobalLoadBalancerRuleByName(name string) (*GlobalLoadBalancerRule, int, error) { - id, err := s.GetGlobalLoadBalancerRuleID(name) +func (s *LoadBalancerService) GetGlobalLoadBalancerRuleByName(name string, opts ...OptionFunc) (*GlobalLoadBalancerRule, int, error) { + id, err := s.GetGlobalLoadBalancerRuleID(name, opts...) if err != nil { return nil, -1, err } - r, count, err := s.GetGlobalLoadBalancerRuleByID(id) + r, count, err := s.GetGlobalLoadBalancerRuleByID(id, opts...) if err != nil { return nil, count, err } @@ -3710,12 +3711,18 @@ func (s *LoadBalancerService) GetGlobalLoadBalancerRuleByName(name string) (*Glo } // This is a courtesy helper function, which in some cases may not work as expected! -func (s *LoadBalancerService) GetGlobalLoadBalancerRuleByID(id string) (*GlobalLoadBalancerRule, int, error) { +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( @@ -3726,21 +3733,6 @@ func (s *LoadBalancerService) GetGlobalLoadBalancerRuleByID(id string) (*GlobalL return nil, -1, err } - if l.Count == 0 { - // If no matches, search all projects - p.p["projectid"] = "-1" - - 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) } @@ -4416,27 +4408,23 @@ func (s *LoadBalancerService) NewListLoadBalancersParams() *ListLoadBalancersPar } // This is a courtesy helper function, which in some cases may not work as expected! -func (s *LoadBalancerService) GetLoadBalancerID(name string) (string, error) { +func (s *LoadBalancerService) GetLoadBalancerID(name string, opts ...OptionFunc) (string, error) { p := &ListLoadBalancersParams{} p.p = make(map[string]interface{}) p.p["name"] = name + for _, fn := range opts { + if err := fn(s.cs, p); err != nil { + return "", err + } + } + l, err := s.ListLoadBalancers(p) if err != nil { return "", err } - if l.Count == 0 { - // If no matches, search all projects - p.p["projectid"] = "-1" - - l, err = s.ListLoadBalancers(p) - if err != nil { - return "", err - } - } - if l.Count == 0 { return "", fmt.Errorf("No match found for %s: %+v", name, l) } @@ -4456,13 +4444,13 @@ func (s *LoadBalancerService) GetLoadBalancerID(name string) (string, error) { } // This is a courtesy helper function, which in some cases may not work as expected! -func (s *LoadBalancerService) GetLoadBalancerByName(name string) (*LoadBalancer, int, error) { - id, err := s.GetLoadBalancerID(name) +func (s *LoadBalancerService) GetLoadBalancerByName(name string, opts ...OptionFunc) (*LoadBalancer, int, error) { + id, err := s.GetLoadBalancerID(name, opts...) if err != nil { return nil, -1, err } - r, count, err := s.GetLoadBalancerByID(id) + r, count, err := s.GetLoadBalancerByID(id, opts...) if err != nil { return nil, count, err } @@ -4470,12 +4458,18 @@ func (s *LoadBalancerService) GetLoadBalancerByName(name string) (*LoadBalancer, } // This is a courtesy helper function, which in some cases may not work as expected! -func (s *LoadBalancerService) GetLoadBalancerByID(id string) (*LoadBalancer, int, error) { +func (s *LoadBalancerService) GetLoadBalancerByID(id string, opts ...OptionFunc) (*LoadBalancer, int, error) { p := &ListLoadBalancersParams{} 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.ListLoadBalancers(p) if err != nil { if strings.Contains(err.Error(), fmt.Sprintf( @@ -4486,21 +4480,6 @@ func (s *LoadBalancerService) GetLoadBalancerByID(id string) (*LoadBalancer, int return nil, -1, err } - if l.Count == 0 { - // If no matches, search all projects - p.p["projectid"] = "-1" - - l, err = s.ListLoadBalancers(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) } diff --git a/vendor/github.com/xanzy/go-cloudstack/cloudstack/NATService.go b/vendor/github.com/xanzy/go-cloudstack/cloudstack/NATService.go index be3b4df0af..daaf10edeb 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 2014, Sander van Harmelen +// Copyright 2016, 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. @@ -481,12 +481,18 @@ func (s *NATService) NewListIpForwardingRulesParams() *ListIpForwardingRulesPara } // This is a courtesy helper function, which in some cases may not work as expected! -func (s *NATService) GetIpForwardingRuleByID(id string) (*IpForwardingRule, int, error) { +func (s *NATService) GetIpForwardingRuleByID(id string, opts ...OptionFunc) (*IpForwardingRule, int, error) { p := &ListIpForwardingRulesParams{} 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.ListIpForwardingRules(p) if err != nil { if strings.Contains(err.Error(), fmt.Sprintf( @@ -497,21 +503,6 @@ func (s *NATService) GetIpForwardingRuleByID(id string) (*IpForwardingRule, int, return nil, -1, err } - if l.Count == 0 { - // If no matches, search all projects - p.p["projectid"] = "-1" - - l, err = s.ListIpForwardingRules(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) } diff --git a/vendor/github.com/xanzy/go-cloudstack/cloudstack/NetworkACLService.go b/vendor/github.com/xanzy/go-cloudstack/cloudstack/NetworkACLService.go index b0ecfe1e04..d195d443b3 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 2014, Sander van Harmelen +// Copyright 2016, 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. @@ -744,12 +744,18 @@ func (s *NetworkACLService) NewListNetworkACLsParams() *ListNetworkACLsParams { } // This is a courtesy helper function, which in some cases may not work as expected! -func (s *NetworkACLService) GetNetworkACLByID(id string) (*NetworkACL, int, error) { +func (s *NetworkACLService) GetNetworkACLByID(id string, opts ...OptionFunc) (*NetworkACL, int, error) { p := &ListNetworkACLsParams{} 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.ListNetworkACLs(p) if err != nil { if strings.Contains(err.Error(), fmt.Sprintf( @@ -760,21 +766,6 @@ func (s *NetworkACLService) GetNetworkACLByID(id string) (*NetworkACL, int, erro return nil, -1, err } - if l.Count == 0 { - // If no matches, search all projects - p.p["projectid"] = "-1" - - l, err = s.ListNetworkACLs(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) } @@ -1267,27 +1258,23 @@ func (s *NetworkACLService) NewListNetworkACLListsParams() *ListNetworkACLListsP } // This is a courtesy helper function, which in some cases may not work as expected! -func (s *NetworkACLService) GetNetworkACLListID(name string) (string, error) { +func (s *NetworkACLService) GetNetworkACLListID(name string, opts ...OptionFunc) (string, 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 "", err + } + } + l, err := s.ListNetworkACLLists(p) if err != nil { return "", err } - if l.Count == 0 { - // If no matches, search all projects - p.p["projectid"] = "-1" - - l, err = s.ListNetworkACLLists(p) - if err != nil { - return "", err - } - } - if l.Count == 0 { return "", fmt.Errorf("No match found for %s: %+v", name, l) } @@ -1307,13 +1294,13 @@ func (s *NetworkACLService) GetNetworkACLListID(name string) (string, error) { } // This is a courtesy helper function, which in some cases may not work as expected! -func (s *NetworkACLService) GetNetworkACLListByName(name string) (*NetworkACLList, int, error) { - id, err := s.GetNetworkACLListID(name) +func (s *NetworkACLService) GetNetworkACLListByName(name string, opts ...OptionFunc) (*NetworkACLList, int, error) { + id, err := s.GetNetworkACLListID(name, opts...) if err != nil { return nil, -1, err } - r, count, err := s.GetNetworkACLListByID(id) + r, count, err := s.GetNetworkACLListByID(id, opts...) if err != nil { return nil, count, err } @@ -1321,12 +1308,18 @@ func (s *NetworkACLService) GetNetworkACLListByName(name string) (*NetworkACLLis } // This is a courtesy helper function, which in some cases may not work as expected! -func (s *NetworkACLService) GetNetworkACLListByID(id string) (*NetworkACLList, int, error) { +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( @@ -1337,21 +1330,6 @@ func (s *NetworkACLService) GetNetworkACLListByID(id string) (*NetworkACLList, i return nil, -1, err } - if l.Count == 0 { - // If no matches, search all projects - p.p["projectid"] = "-1" - - 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) } diff --git a/vendor/github.com/xanzy/go-cloudstack/cloudstack/NetworkDeviceService.go b/vendor/github.com/xanzy/go-cloudstack/cloudstack/NetworkDeviceService.go index 7b8e64bcc4..878d5286ef 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 2014, Sander van Harmelen +// Copyright 2016, 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. diff --git a/vendor/github.com/xanzy/go-cloudstack/cloudstack/NetworkOfferingService.go b/vendor/github.com/xanzy/go-cloudstack/cloudstack/NetworkOfferingService.go index 0e57e8a7d1..43b03c1c83 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 2014, Sander van Harmelen +// Copyright 2016, 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. @@ -808,12 +808,18 @@ func (s *NetworkOfferingService) NewListNetworkOfferingsParams() *ListNetworkOff } // This is a courtesy helper function, which in some cases may not work as expected! -func (s *NetworkOfferingService) GetNetworkOfferingID(name string) (string, error) { +func (s *NetworkOfferingService) GetNetworkOfferingID(name string, opts ...OptionFunc) (string, error) { p := &ListNetworkOfferingsParams{} p.p = make(map[string]interface{}) p.p["name"] = name + for _, fn := range opts { + if err := fn(s.cs, p); err != nil { + return "", err + } + } + l, err := s.ListNetworkOfferings(p) if err != nil { return "", err @@ -838,13 +844,13 @@ func (s *NetworkOfferingService) GetNetworkOfferingID(name string) (string, erro } // This is a courtesy helper function, which in some cases may not work as expected! -func (s *NetworkOfferingService) GetNetworkOfferingByName(name string) (*NetworkOffering, int, error) { - id, err := s.GetNetworkOfferingID(name) +func (s *NetworkOfferingService) GetNetworkOfferingByName(name string, opts ...OptionFunc) (*NetworkOffering, int, error) { + id, err := s.GetNetworkOfferingID(name, opts...) if err != nil { return nil, -1, err } - r, count, err := s.GetNetworkOfferingByID(id) + r, count, err := s.GetNetworkOfferingByID(id, opts...) if err != nil { return nil, count, err } @@ -852,12 +858,18 @@ func (s *NetworkOfferingService) GetNetworkOfferingByName(name string) (*Network } // This is a courtesy helper function, which in some cases may not work as expected! -func (s *NetworkOfferingService) GetNetworkOfferingByID(id string) (*NetworkOffering, int, error) { +func (s *NetworkOfferingService) GetNetworkOfferingByID(id string, opts ...OptionFunc) (*NetworkOffering, int, error) { p := &ListNetworkOfferingsParams{} 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.ListNetworkOfferings(p) if err != nil { if strings.Contains(err.Error(), fmt.Sprintf( diff --git a/vendor/github.com/xanzy/go-cloudstack/cloudstack/NetworkService.go b/vendor/github.com/xanzy/go-cloudstack/cloudstack/NetworkService.go index 027bb9a974..43acd05aa3 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 2014, Sander van Harmelen +// Copyright 2016, 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. @@ -935,27 +935,23 @@ func (s *NetworkService) NewListNetworksParams() *ListNetworksParams { } // This is a courtesy helper function, which in some cases may not work as expected! -func (s *NetworkService) GetNetworkID(keyword string) (string, error) { +func (s *NetworkService) GetNetworkID(keyword string, opts ...OptionFunc) (string, error) { p := &ListNetworksParams{} p.p = make(map[string]interface{}) p.p["keyword"] = keyword + for _, fn := range opts { + if err := fn(s.cs, p); err != nil { + return "", err + } + } + l, err := s.ListNetworks(p) if err != nil { return "", err } - if l.Count == 0 { - // If no matches, search all projects - p.p["projectid"] = "-1" - - l, err = s.ListNetworks(p) - if err != nil { - return "", err - } - } - if l.Count == 0 { return "", fmt.Errorf("No match found for %s: %+v", keyword, l) } @@ -975,13 +971,13 @@ func (s *NetworkService) GetNetworkID(keyword string) (string, error) { } // This is a courtesy helper function, which in some cases may not work as expected! -func (s *NetworkService) GetNetworkByName(name string) (*Network, int, error) { - id, err := s.GetNetworkID(name) +func (s *NetworkService) GetNetworkByName(name string, opts ...OptionFunc) (*Network, int, error) { + id, err := s.GetNetworkID(name, opts...) if err != nil { return nil, -1, err } - r, count, err := s.GetNetworkByID(id) + r, count, err := s.GetNetworkByID(id, opts...) if err != nil { return nil, count, err } @@ -989,12 +985,18 @@ func (s *NetworkService) GetNetworkByName(name string) (*Network, int, error) { } // This is a courtesy helper function, which in some cases may not work as expected! -func (s *NetworkService) GetNetworkByID(id string) (*Network, int, error) { +func (s *NetworkService) GetNetworkByID(id string, opts ...OptionFunc) (*Network, int, error) { p := &ListNetworksParams{} 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.ListNetworks(p) if err != nil { if strings.Contains(err.Error(), fmt.Sprintf( @@ -1005,21 +1007,6 @@ func (s *NetworkService) GetNetworkByID(id string) (*Network, int, error) { return nil, -1, err } - if l.Count == 0 { - // If no matches, search all projects - p.p["projectid"] = "-1" - - l, err = s.ListNetworks(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) } @@ -1801,12 +1788,18 @@ func (s *NetworkService) NewListPhysicalNetworksParams() *ListPhysicalNetworksPa } // This is a courtesy helper function, which in some cases may not work as expected! -func (s *NetworkService) GetPhysicalNetworkID(name string) (string, error) { +func (s *NetworkService) GetPhysicalNetworkID(name string, opts ...OptionFunc) (string, error) { p := &ListPhysicalNetworksParams{} p.p = make(map[string]interface{}) p.p["name"] = name + for _, fn := range opts { + if err := fn(s.cs, p); err != nil { + return "", err + } + } + l, err := s.ListPhysicalNetworks(p) if err != nil { return "", err @@ -1831,13 +1824,13 @@ func (s *NetworkService) GetPhysicalNetworkID(name string) (string, error) { } // This is a courtesy helper function, which in some cases may not work as expected! -func (s *NetworkService) GetPhysicalNetworkByName(name string) (*PhysicalNetwork, int, error) { - id, err := s.GetPhysicalNetworkID(name) +func (s *NetworkService) GetPhysicalNetworkByName(name string, opts ...OptionFunc) (*PhysicalNetwork, int, error) { + id, err := s.GetPhysicalNetworkID(name, opts...) if err != nil { return nil, -1, err } - r, count, err := s.GetPhysicalNetworkByID(id) + r, count, err := s.GetPhysicalNetworkByID(id, opts...) if err != nil { return nil, count, err } @@ -1845,12 +1838,18 @@ func (s *NetworkService) GetPhysicalNetworkByName(name string) (*PhysicalNetwork } // This is a courtesy helper function, which in some cases may not work as expected! -func (s *NetworkService) GetPhysicalNetworkByID(id string) (*PhysicalNetwork, int, error) { +func (s *NetworkService) GetPhysicalNetworkByID(id string, opts ...OptionFunc) (*PhysicalNetwork, int, error) { p := &ListPhysicalNetworksParams{} 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.ListPhysicalNetworks(p) if err != nil { if strings.Contains(err.Error(), fmt.Sprintf( @@ -2410,12 +2409,18 @@ func (s *NetworkService) NewListNetworkServiceProvidersParams() *ListNetworkServ } // This is a courtesy helper function, which in some cases may not work as expected! -func (s *NetworkService) GetNetworkServiceProviderID(name string) (string, error) { +func (s *NetworkService) GetNetworkServiceProviderID(name string, opts ...OptionFunc) (string, 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 "", err + } + } + l, err := s.ListNetworkServiceProviders(p) if err != nil { return "", err @@ -2862,12 +2867,18 @@ func (s *NetworkService) NewListStorageNetworkIpRangeParams() *ListStorageNetwor } // This is a courtesy helper function, which in some cases may not work as expected! -func (s *NetworkService) GetStorageNetworkIpRangeByID(id string) (*StorageNetworkIpRange, int, error) { +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( @@ -3111,13 +3122,19 @@ func (s *NetworkService) NewListPaloAltoFirewallNetworksParams(lbdeviceid string } // This is a courtesy helper function, which in some cases may not work as expected! -func (s *NetworkService) GetPaloAltoFirewallNetworkID(keyword string, lbdeviceid string) (string, error) { +func (s *NetworkService) GetPaloAltoFirewallNetworkID(keyword string, lbdeviceid string, opts ...OptionFunc) (string, 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 "", err + } + } + l, err := s.ListPaloAltoFirewallNetworks(p) if err != nil { return "", err @@ -3306,13 +3323,19 @@ func (s *NetworkService) NewListNetscalerLoadBalancerNetworksParams(lbdeviceid s } // This is a courtesy helper function, which in some cases may not work as expected! -func (s *NetworkService) GetNetscalerLoadBalancerNetworkID(keyword string, lbdeviceid string) (string, error) { +func (s *NetworkService) GetNetscalerLoadBalancerNetworkID(keyword string, lbdeviceid string, opts ...OptionFunc) (string, 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 "", err + } + } + l, err := s.ListNetscalerLoadBalancerNetworks(p) if err != nil { return "", err @@ -3501,13 +3524,19 @@ func (s *NetworkService) NewListNiciraNvpDeviceNetworksParams(nvpdeviceid string } // This is a courtesy helper function, which in some cases may not work as expected! -func (s *NetworkService) GetNiciraNvpDeviceNetworkID(keyword string, nvpdeviceid string) (string, error) { +func (s *NetworkService) GetNiciraNvpDeviceNetworkID(keyword string, nvpdeviceid string, opts ...OptionFunc) (string, 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 "", err + } + } + l, err := s.ListNiciraNvpDeviceNetworks(p) if err != nil { return "", err @@ -3935,12 +3964,18 @@ func (s *NetworkService) NewListOpenDaylightControllersParams() *ListOpenDayligh } // This is a courtesy helper function, which in some cases may not work as expected! -func (s *NetworkService) GetOpenDaylightControllerByID(id string) (*OpenDaylightController, int, error) { +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( diff --git a/vendor/github.com/xanzy/go-cloudstack/cloudstack/NicService.go b/vendor/github.com/xanzy/go-cloudstack/cloudstack/NicService.go index b4575bd084..d83e07567e 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 2014, Sander van Harmelen +// Copyright 2016, 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. diff --git a/vendor/github.com/xanzy/go-cloudstack/cloudstack/NiciraNVPService.go b/vendor/github.com/xanzy/go-cloudstack/cloudstack/NiciraNVPService.go index a4cb2050b7..2efcd1587f 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 2014, Sander van Harmelen +// Copyright 2016, 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. diff --git a/vendor/github.com/xanzy/go-cloudstack/cloudstack/OvsElementService.go b/vendor/github.com/xanzy/go-cloudstack/cloudstack/OvsElementService.go index 3c81420b7e..a86d61f281 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 2014, Sander van Harmelen +// Copyright 2016, 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. @@ -205,12 +205,18 @@ func (s *OvsElementService) NewListOvsElementsParams() *ListOvsElementsParams { } // This is a courtesy helper function, which in some cases may not work as expected! -func (s *OvsElementService) GetOvsElementByID(id string) (*OvsElement, int, error) { +func (s *OvsElementService) GetOvsElementByID(id string, opts ...OptionFunc) (*OvsElement, int, error) { p := &ListOvsElementsParams{} 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.ListOvsElements(p) if err != nil { if strings.Contains(err.Error(), fmt.Sprintf( diff --git a/vendor/github.com/xanzy/go-cloudstack/cloudstack/PodService.go b/vendor/github.com/xanzy/go-cloudstack/cloudstack/PodService.go index f52919095b..ce7b94a3ba 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 2014, Sander van Harmelen +// Copyright 2016, 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. @@ -463,12 +463,18 @@ func (s *PodService) NewListPodsParams() *ListPodsParams { } // This is a courtesy helper function, which in some cases may not work as expected! -func (s *PodService) GetPodID(name string) (string, error) { +func (s *PodService) GetPodID(name string, opts ...OptionFunc) (string, error) { p := &ListPodsParams{} p.p = make(map[string]interface{}) p.p["name"] = name + for _, fn := range opts { + if err := fn(s.cs, p); err != nil { + return "", err + } + } + l, err := s.ListPods(p) if err != nil { return "", err @@ -493,13 +499,13 @@ func (s *PodService) GetPodID(name string) (string, error) { } // This is a courtesy helper function, which in some cases may not work as expected! -func (s *PodService) GetPodByName(name string) (*Pod, int, error) { - id, err := s.GetPodID(name) +func (s *PodService) GetPodByName(name string, opts ...OptionFunc) (*Pod, int, error) { + id, err := s.GetPodID(name, opts...) if err != nil { return nil, -1, err } - r, count, err := s.GetPodByID(id) + r, count, err := s.GetPodByID(id, opts...) if err != nil { return nil, count, err } @@ -507,12 +513,18 @@ func (s *PodService) GetPodByName(name string) (*Pod, int, error) { } // This is a courtesy helper function, which in some cases may not work as expected! -func (s *PodService) GetPodByID(id string) (*Pod, int, error) { +func (s *PodService) GetPodByID(id string, opts ...OptionFunc) (*Pod, int, error) { p := &ListPodsParams{} 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.ListPods(p) if err != nil { if strings.Contains(err.Error(), fmt.Sprintf( diff --git a/vendor/github.com/xanzy/go-cloudstack/cloudstack/PoolService.go b/vendor/github.com/xanzy/go-cloudstack/cloudstack/PoolService.go index c8753a336a..78b643b17f 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 2014, Sander van Harmelen +// Copyright 2016, 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. @@ -168,12 +168,18 @@ func (s *PoolService) NewListStoragePoolsParams() *ListStoragePoolsParams { } // This is a courtesy helper function, which in some cases may not work as expected! -func (s *PoolService) GetStoragePoolID(name string) (string, error) { +func (s *PoolService) GetStoragePoolID(name string, opts ...OptionFunc) (string, 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 "", err + } + } + l, err := s.ListStoragePools(p) if err != nil { return "", err @@ -198,13 +204,13 @@ func (s *PoolService) GetStoragePoolID(name string) (string, error) { } // This is a courtesy helper function, which in some cases may not work as expected! -func (s *PoolService) GetStoragePoolByName(name string) (*StoragePool, int, error) { - id, err := s.GetStoragePoolID(name) +func (s *PoolService) GetStoragePoolByName(name string, opts ...OptionFunc) (*StoragePool, int, error) { + id, err := s.GetStoragePoolID(name, opts...) if err != nil { return nil, -1, err } - r, count, err := s.GetStoragePoolByID(id) + r, count, err := s.GetStoragePoolByID(id, opts...) if err != nil { return nil, count, err } @@ -212,12 +218,18 @@ func (s *PoolService) GetStoragePoolByName(name string) (*StoragePool, int, erro } // This is a courtesy helper function, which in some cases may not work as expected! -func (s *PoolService) GetStoragePoolByID(id string) (*StoragePool, int, error) { +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( diff --git a/vendor/github.com/xanzy/go-cloudstack/cloudstack/PortableIPService.go b/vendor/github.com/xanzy/go-cloudstack/cloudstack/PortableIPService.go index 3dabf38ba2..2896ae2bb3 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 2014, Sander van Harmelen +// Copyright 2016, 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. @@ -319,12 +319,18 @@ func (s *PortableIPService) NewListPortableIpRangesParams() *ListPortableIpRange } // This is a courtesy helper function, which in some cases may not work as expected! -func (s *PortableIPService) GetPortableIpRangeByID(id string) (*PortableIpRange, int, error) { +func (s *PortableIPService) GetPortableIpRangeByID(id string, opts ...OptionFunc) (*PortableIpRange, int, error) { p := &ListPortableIpRangesParams{} 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.ListPortableIpRanges(p) if err != nil { if strings.Contains(err.Error(), fmt.Sprintf( diff --git a/vendor/github.com/xanzy/go-cloudstack/cloudstack/ProjectService.go b/vendor/github.com/xanzy/go-cloudstack/cloudstack/ProjectService.go index d37b502ea4..3269b47fa8 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 2014, Sander van Harmelen +// Copyright 2016, 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. @@ -805,12 +805,18 @@ func (s *ProjectService) NewListProjectsParams() *ListProjectsParams { } // This is a courtesy helper function, which in some cases may not work as expected! -func (s *ProjectService) GetProjectID(name string) (string, error) { +func (s *ProjectService) GetProjectID(name string, opts ...OptionFunc) (string, error) { p := &ListProjectsParams{} p.p = make(map[string]interface{}) p.p["name"] = name + for _, fn := range opts { + if err := fn(s.cs, p); err != nil { + return "", err + } + } + l, err := s.ListProjects(p) if err != nil { return "", err @@ -835,13 +841,13 @@ func (s *ProjectService) GetProjectID(name string) (string, error) { } // This is a courtesy helper function, which in some cases may not work as expected! -func (s *ProjectService) GetProjectByName(name string) (*Project, int, error) { - id, err := s.GetProjectID(name) +func (s *ProjectService) GetProjectByName(name string, opts ...OptionFunc) (*Project, int, error) { + id, err := s.GetProjectID(name, opts...) if err != nil { return nil, -1, err } - r, count, err := s.GetProjectByID(id) + r, count, err := s.GetProjectByID(id, opts...) if err != nil { return nil, count, err } @@ -849,12 +855,18 @@ func (s *ProjectService) GetProjectByName(name string) (*Project, int, error) { } // This is a courtesy helper function, which in some cases may not work as expected! -func (s *ProjectService) GetProjectByID(id string) (*Project, int, error) { +func (s *ProjectService) GetProjectByID(id string, opts ...OptionFunc) (*Project, int, error) { p := &ListProjectsParams{} 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.ListProjects(p) if err != nil { if strings.Contains(err.Error(), fmt.Sprintf( @@ -1098,12 +1110,18 @@ func (s *ProjectService) NewListProjectInvitationsParams() *ListProjectInvitatio } // This is a courtesy helper function, which in some cases may not work as expected! -func (s *ProjectService) GetProjectInvitationByID(id string) (*ProjectInvitation, int, error) { +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( @@ -1114,21 +1132,6 @@ func (s *ProjectService) GetProjectInvitationByID(id string) (*ProjectInvitation return nil, -1, err } - if l.Count == 0 { - // If no matches, search all projects - p.p["projectid"] = "-1" - - 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) } diff --git a/vendor/github.com/xanzy/go-cloudstack/cloudstack/QuotaService.go b/vendor/github.com/xanzy/go-cloudstack/cloudstack/QuotaService.go index 867f740cc0..896a4d7983 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 2014, Sander van Harmelen +// Copyright 2016, 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. diff --git a/vendor/github.com/xanzy/go-cloudstack/cloudstack/RegionService.go b/vendor/github.com/xanzy/go-cloudstack/cloudstack/RegionService.go index 18cede7fdd..a434f85136 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 2014, Sander van Harmelen +// Copyright 2016, 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. diff --git a/vendor/github.com/xanzy/go-cloudstack/cloudstack/ResourcemetadataService.go b/vendor/github.com/xanzy/go-cloudstack/cloudstack/ResourcemetadataService.go index e61b0ecc00..136b9d3b17 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 2014, Sander van Harmelen +// Copyright 2016, 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. diff --git a/vendor/github.com/xanzy/go-cloudstack/cloudstack/ResourcetagsService.go b/vendor/github.com/xanzy/go-cloudstack/cloudstack/ResourcetagsService.go index a3b18bfa51..c9cf1c0f78 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 2014, Sander van Harmelen +// Copyright 2016, 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. @@ -80,12 +80,18 @@ func (s *ResourcetagsService) NewListStorageTagsParams() *ListStorageTagsParams } // This is a courtesy helper function, which in some cases may not work as expected! -func (s *ResourcetagsService) GetStorageTagID(keyword string) (string, error) { +func (s *ResourcetagsService) GetStorageTagID(keyword string, opts ...OptionFunc) (string, 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 "", err + } + } + l, err := s.ListStorageTags(p) if err != nil { return "", err diff --git a/vendor/github.com/xanzy/go-cloudstack/cloudstack/RouterService.go b/vendor/github.com/xanzy/go-cloudstack/cloudstack/RouterService.go index 6e3a532a92..bbbbc4d7d4 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 2014, Sander van Harmelen +// Copyright 2016, 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. @@ -952,27 +952,23 @@ func (s *RouterService) NewListRoutersParams() *ListRoutersParams { } // This is a courtesy helper function, which in some cases may not work as expected! -func (s *RouterService) GetRouterID(name string) (string, error) { +func (s *RouterService) GetRouterID(name string, opts ...OptionFunc) (string, error) { p := &ListRoutersParams{} p.p = make(map[string]interface{}) p.p["name"] = name + for _, fn := range opts { + if err := fn(s.cs, p); err != nil { + return "", err + } + } + l, err := s.ListRouters(p) if err != nil { return "", err } - if l.Count == 0 { - // If no matches, search all projects - p.p["projectid"] = "-1" - - l, err = s.ListRouters(p) - if err != nil { - return "", err - } - } - if l.Count == 0 { return "", fmt.Errorf("No match found for %s: %+v", name, l) } @@ -992,13 +988,13 @@ func (s *RouterService) GetRouterID(name string) (string, error) { } // This is a courtesy helper function, which in some cases may not work as expected! -func (s *RouterService) GetRouterByName(name string) (*Router, int, error) { - id, err := s.GetRouterID(name) +func (s *RouterService) GetRouterByName(name string, opts ...OptionFunc) (*Router, int, error) { + id, err := s.GetRouterID(name, opts...) if err != nil { return nil, -1, err } - r, count, err := s.GetRouterByID(id) + r, count, err := s.GetRouterByID(id, opts...) if err != nil { return nil, count, err } @@ -1006,12 +1002,18 @@ func (s *RouterService) GetRouterByName(name string) (*Router, int, error) { } // This is a courtesy helper function, which in some cases may not work as expected! -func (s *RouterService) GetRouterByID(id string) (*Router, int, error) { +func (s *RouterService) GetRouterByID(id string, opts ...OptionFunc) (*Router, int, error) { p := &ListRoutersParams{} 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.ListRouters(p) if err != nil { if strings.Contains(err.Error(), fmt.Sprintf( @@ -1022,21 +1024,6 @@ func (s *RouterService) GetRouterByID(id string) (*Router, int, error) { return nil, -1, err } - if l.Count == 0 { - // If no matches, search all projects - p.p["projectid"] = "-1" - - l, err = s.ListRouters(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) } @@ -1227,12 +1214,18 @@ func (s *RouterService) NewListVirtualRouterElementsParams() *ListVirtualRouterE } // This is a courtesy helper function, which in some cases may not work as expected! -func (s *RouterService) GetVirtualRouterElementByID(id string) (*VirtualRouterElement, int, error) { +func (s *RouterService) GetVirtualRouterElementByID(id string, opts ...OptionFunc) (*VirtualRouterElement, int, error) { p := &ListVirtualRouterElementsParams{} 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.ListVirtualRouterElements(p) if err != nil { if strings.Contains(err.Error(), fmt.Sprintf( diff --git a/vendor/github.com/xanzy/go-cloudstack/cloudstack/SSHService.go b/vendor/github.com/xanzy/go-cloudstack/cloudstack/SSHService.go index 97eabc0d1d..2221a5921c 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 2014, Sander van Harmelen +// Copyright 2016, 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. diff --git a/vendor/github.com/xanzy/go-cloudstack/cloudstack/SecurityGroupService.go b/vendor/github.com/xanzy/go-cloudstack/cloudstack/SecurityGroupService.go index 73b100cbe6..8b43f4813e 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 2014, Sander van Harmelen +// Copyright 2016, 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. @@ -1017,27 +1017,23 @@ func (s *SecurityGroupService) NewListSecurityGroupsParams() *ListSecurityGroups } // This is a courtesy helper function, which in some cases may not work as expected! -func (s *SecurityGroupService) GetSecurityGroupID(keyword string) (string, error) { +func (s *SecurityGroupService) GetSecurityGroupID(keyword string, opts ...OptionFunc) (string, error) { p := &ListSecurityGroupsParams{} p.p = make(map[string]interface{}) p.p["keyword"] = keyword + for _, fn := range opts { + if err := fn(s.cs, p); err != nil { + return "", err + } + } + l, err := s.ListSecurityGroups(p) if err != nil { return "", err } - if l.Count == 0 { - // If no matches, search all projects - p.p["projectid"] = "-1" - - l, err = s.ListSecurityGroups(p) - if err != nil { - return "", err - } - } - if l.Count == 0 { return "", fmt.Errorf("No match found for %s: %+v", keyword, l) } @@ -1057,13 +1053,13 @@ func (s *SecurityGroupService) GetSecurityGroupID(keyword string) (string, error } // This is a courtesy helper function, which in some cases may not work as expected! -func (s *SecurityGroupService) GetSecurityGroupByName(name string) (*SecurityGroup, int, error) { - id, err := s.GetSecurityGroupID(name) +func (s *SecurityGroupService) GetSecurityGroupByName(name string, opts ...OptionFunc) (*SecurityGroup, int, error) { + id, err := s.GetSecurityGroupID(name, opts...) if err != nil { return nil, -1, err } - r, count, err := s.GetSecurityGroupByID(id) + r, count, err := s.GetSecurityGroupByID(id, opts...) if err != nil { return nil, count, err } @@ -1071,12 +1067,18 @@ func (s *SecurityGroupService) GetSecurityGroupByName(name string) (*SecurityGro } // This is a courtesy helper function, which in some cases may not work as expected! -func (s *SecurityGroupService) GetSecurityGroupByID(id string) (*SecurityGroup, int, error) { +func (s *SecurityGroupService) GetSecurityGroupByID(id string, opts ...OptionFunc) (*SecurityGroup, int, error) { p := &ListSecurityGroupsParams{} 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.ListSecurityGroups(p) if err != nil { if strings.Contains(err.Error(), fmt.Sprintf( @@ -1087,21 +1089,6 @@ func (s *SecurityGroupService) GetSecurityGroupByID(id string) (*SecurityGroup, return nil, -1, err } - if l.Count == 0 { - // If no matches, search all projects - p.p["projectid"] = "-1" - - l, err = s.ListSecurityGroups(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) } diff --git a/vendor/github.com/xanzy/go-cloudstack/cloudstack/ServiceOfferingService.go b/vendor/github.com/xanzy/go-cloudstack/cloudstack/ServiceOfferingService.go index ed50703eb4..b3b18548f2 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 2014, Sander van Harmelen +// Copyright 2016, 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. @@ -717,12 +717,18 @@ func (s *ServiceOfferingService) NewListServiceOfferingsParams() *ListServiceOff } // This is a courtesy helper function, which in some cases may not work as expected! -func (s *ServiceOfferingService) GetServiceOfferingID(name string) (string, error) { +func (s *ServiceOfferingService) GetServiceOfferingID(name string, opts ...OptionFunc) (string, error) { p := &ListServiceOfferingsParams{} p.p = make(map[string]interface{}) p.p["name"] = name + for _, fn := range opts { + if err := fn(s.cs, p); err != nil { + return "", err + } + } + l, err := s.ListServiceOfferings(p) if err != nil { return "", err @@ -747,13 +753,13 @@ func (s *ServiceOfferingService) GetServiceOfferingID(name string) (string, erro } // This is a courtesy helper function, which in some cases may not work as expected! -func (s *ServiceOfferingService) GetServiceOfferingByName(name string) (*ServiceOffering, int, error) { - id, err := s.GetServiceOfferingID(name) +func (s *ServiceOfferingService) GetServiceOfferingByName(name string, opts ...OptionFunc) (*ServiceOffering, int, error) { + id, err := s.GetServiceOfferingID(name, opts...) if err != nil { return nil, -1, err } - r, count, err := s.GetServiceOfferingByID(id) + r, count, err := s.GetServiceOfferingByID(id, opts...) if err != nil { return nil, count, err } @@ -761,12 +767,18 @@ func (s *ServiceOfferingService) GetServiceOfferingByName(name string) (*Service } // This is a courtesy helper function, which in some cases may not work as expected! -func (s *ServiceOfferingService) GetServiceOfferingByID(id string) (*ServiceOffering, int, error) { +func (s *ServiceOfferingService) GetServiceOfferingByID(id string, opts ...OptionFunc) (*ServiceOffering, int, error) { p := &ListServiceOfferingsParams{} 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.ListServiceOfferings(p) if err != nil { if strings.Contains(err.Error(), fmt.Sprintf( diff --git a/vendor/github.com/xanzy/go-cloudstack/cloudstack/SnapshotService.go b/vendor/github.com/xanzy/go-cloudstack/cloudstack/SnapshotService.go index dab17eeead..a92db27e5b 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 2014, Sander van Harmelen +// Copyright 2016, 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. @@ -374,27 +374,23 @@ func (s *SnapshotService) NewListSnapshotsParams() *ListSnapshotsParams { } // This is a courtesy helper function, which in some cases may not work as expected! -func (s *SnapshotService) GetSnapshotID(name string) (string, error) { +func (s *SnapshotService) GetSnapshotID(name string, opts ...OptionFunc) (string, error) { p := &ListSnapshotsParams{} p.p = make(map[string]interface{}) p.p["name"] = name + for _, fn := range opts { + if err := fn(s.cs, p); err != nil { + return "", err + } + } + l, err := s.ListSnapshots(p) if err != nil { return "", err } - if l.Count == 0 { - // If no matches, search all projects - p.p["projectid"] = "-1" - - l, err = s.ListSnapshots(p) - if err != nil { - return "", err - } - } - if l.Count == 0 { return "", fmt.Errorf("No match found for %s: %+v", name, l) } @@ -414,13 +410,13 @@ func (s *SnapshotService) GetSnapshotID(name string) (string, error) { } // This is a courtesy helper function, which in some cases may not work as expected! -func (s *SnapshotService) GetSnapshotByName(name string) (*Snapshot, int, error) { - id, err := s.GetSnapshotID(name) +func (s *SnapshotService) GetSnapshotByName(name string, opts ...OptionFunc) (*Snapshot, int, error) { + id, err := s.GetSnapshotID(name, opts...) if err != nil { return nil, -1, err } - r, count, err := s.GetSnapshotByID(id) + r, count, err := s.GetSnapshotByID(id, opts...) if err != nil { return nil, count, err } @@ -428,12 +424,18 @@ func (s *SnapshotService) GetSnapshotByName(name string) (*Snapshot, int, error) } // This is a courtesy helper function, which in some cases may not work as expected! -func (s *SnapshotService) GetSnapshotByID(id string) (*Snapshot, int, error) { +func (s *SnapshotService) GetSnapshotByID(id string, opts ...OptionFunc) (*Snapshot, int, error) { p := &ListSnapshotsParams{} 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.ListSnapshots(p) if err != nil { if strings.Contains(err.Error(), fmt.Sprintf( @@ -444,21 +446,6 @@ func (s *SnapshotService) GetSnapshotByID(id string) (*Snapshot, int, error) { return nil, -1, err } - if l.Count == 0 { - // If no matches, search all projects - p.p["projectid"] = "-1" - - l, err = s.ListSnapshots(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) } @@ -955,12 +942,18 @@ func (s *SnapshotService) NewListSnapshotPoliciesParams() *ListSnapshotPoliciesP } // This is a courtesy helper function, which in some cases may not work as expected! -func (s *SnapshotService) GetSnapshotPolicyByID(id string) (*SnapshotPolicy, int, error) { +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( @@ -1282,27 +1275,23 @@ func (s *SnapshotService) NewListVMSnapshotParams() *ListVMSnapshotParams { } // This is a courtesy helper function, which in some cases may not work as expected! -func (s *SnapshotService) GetVMSnapshotID(name string) (string, error) { +func (s *SnapshotService) GetVMSnapshotID(name string, opts ...OptionFunc) (string, error) { p := &ListVMSnapshotParams{} p.p = make(map[string]interface{}) p.p["name"] = name + for _, fn := range opts { + if err := fn(s.cs, p); err != nil { + return "", err + } + } + l, err := s.ListVMSnapshot(p) if err != nil { return "", err } - if l.Count == 0 { - // If no matches, search all projects - p.p["projectid"] = "-1" - - l, err = s.ListVMSnapshot(p) - if err != nil { - return "", err - } - } - if l.Count == 0 { return "", fmt.Errorf("No match found for %s: %+v", name, l) } diff --git a/vendor/github.com/xanzy/go-cloudstack/cloudstack/StoragePoolService.go b/vendor/github.com/xanzy/go-cloudstack/cloudstack/StoragePoolService.go index e5a0f6aba4..9b7b82c96f 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 2014, Sander van Harmelen +// Copyright 2016, 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. diff --git a/vendor/github.com/xanzy/go-cloudstack/cloudstack/StratosphereSSPService.go b/vendor/github.com/xanzy/go-cloudstack/cloudstack/StratosphereSSPService.go index 4d63b8f572..4e638f8430 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 2014, Sander van Harmelen +// Copyright 2016, 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. diff --git a/vendor/github.com/xanzy/go-cloudstack/cloudstack/SwiftService.go b/vendor/github.com/xanzy/go-cloudstack/cloudstack/SwiftService.go index f1c7433652..fe70dd4755 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 2014, Sander van Harmelen +// Copyright 2016, 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. @@ -182,12 +182,18 @@ func (s *SwiftService) NewListSwiftsParams() *ListSwiftsParams { } // This is a courtesy helper function, which in some cases may not work as expected! -func (s *SwiftService) GetSwiftID(keyword string) (string, error) { +func (s *SwiftService) GetSwiftID(keyword string, opts ...OptionFunc) (string, error) { p := &ListSwiftsParams{} p.p = make(map[string]interface{}) p.p["keyword"] = keyword + for _, fn := range opts { + if err := fn(s.cs, p); err != nil { + return "", err + } + } + l, err := s.ListSwifts(p) if err != nil { return "", err diff --git a/vendor/github.com/xanzy/go-cloudstack/cloudstack/SystemCapacityService.go b/vendor/github.com/xanzy/go-cloudstack/cloudstack/SystemCapacityService.go index fea76c8ab2..98444d6580 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 2014, Sander van Harmelen +// Copyright 2016, 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. diff --git a/vendor/github.com/xanzy/go-cloudstack/cloudstack/SystemVMService.go b/vendor/github.com/xanzy/go-cloudstack/cloudstack/SystemVMService.go index 5bea9ad189..55f81356ce 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 2014, Sander van Harmelen +// Copyright 2016, 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. @@ -572,12 +572,18 @@ func (s *SystemVMService) NewListSystemVmsParams() *ListSystemVmsParams { } // This is a courtesy helper function, which in some cases may not work as expected! -func (s *SystemVMService) GetSystemVmID(name string) (string, error) { +func (s *SystemVMService) GetSystemVmID(name string, opts ...OptionFunc) (string, error) { p := &ListSystemVmsParams{} p.p = make(map[string]interface{}) p.p["name"] = name + for _, fn := range opts { + if err := fn(s.cs, p); err != nil { + return "", err + } + } + l, err := s.ListSystemVms(p) if err != nil { return "", err @@ -602,13 +608,13 @@ func (s *SystemVMService) GetSystemVmID(name string) (string, error) { } // This is a courtesy helper function, which in some cases may not work as expected! -func (s *SystemVMService) GetSystemVmByName(name string) (*SystemVm, int, error) { - id, err := s.GetSystemVmID(name) +func (s *SystemVMService) GetSystemVmByName(name string, opts ...OptionFunc) (*SystemVm, int, error) { + id, err := s.GetSystemVmID(name, opts...) if err != nil { return nil, -1, err } - r, count, err := s.GetSystemVmByID(id) + r, count, err := s.GetSystemVmByID(id, opts...) if err != nil { return nil, count, err } @@ -616,12 +622,18 @@ func (s *SystemVMService) GetSystemVmByName(name string) (*SystemVm, int, error) } // This is a courtesy helper function, which in some cases may not work as expected! -func (s *SystemVMService) GetSystemVmByID(id string) (*SystemVm, int, error) { +func (s *SystemVMService) GetSystemVmByID(id string, opts ...OptionFunc) (*SystemVm, int, error) { p := &ListSystemVmsParams{} 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.ListSystemVms(p) if err != nil { if strings.Contains(err.Error(), fmt.Sprintf( diff --git a/vendor/github.com/xanzy/go-cloudstack/cloudstack/TemplateService.go b/vendor/github.com/xanzy/go-cloudstack/cloudstack/TemplateService.go index d07dd92060..ad915c0ddc 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 2014, Sander van Harmelen +// Copyright 2016, 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. @@ -1314,7 +1314,7 @@ func (s *TemplateService) NewListTemplatesParams(templatefilter string) *ListTem } // 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) (string, error) { +func (s *TemplateService) GetTemplateID(name string, templatefilter string, zoneid string, opts ...OptionFunc) (string, error) { p := &ListTemplatesParams{} p.p = make(map[string]interface{}) @@ -1322,21 +1322,17 @@ func (s *TemplateService) GetTemplateID(name string, templatefilter string, zone p.p["templatefilter"] = templatefilter p.p["zoneid"] = zoneid + for _, fn := range opts { + if err := fn(s.cs, p); err != nil { + return "", err + } + } + l, err := s.ListTemplates(p) if err != nil { return "", err } - if l.Count == 0 { - // If no matches, search all projects - p.p["projectid"] = "-1" - - l, err = s.ListTemplates(p) - if err != nil { - return "", err - } - } - if l.Count == 0 { return "", fmt.Errorf("No match found for %s: %+v", name, l) } @@ -1356,13 +1352,13 @@ func (s *TemplateService) GetTemplateID(name string, templatefilter string, zone } // 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) (*Template, int, error) { - id, err := s.GetTemplateID(name, templatefilter, zoneid) +func (s *TemplateService) GetTemplateByName(name string, templatefilter string, zoneid string, opts ...OptionFunc) (*Template, int, error) { + id, err := s.GetTemplateID(name, templatefilter, zoneid, opts...) if err != nil { return nil, -1, err } - r, count, err := s.GetTemplateByID(id, templatefilter) + r, count, err := s.GetTemplateByID(id, templatefilter, opts...) if err != nil { return nil, count, err } @@ -1370,13 +1366,19 @@ func (s *TemplateService) GetTemplateByName(name string, templatefilter string, } // This is a courtesy helper function, which in some cases may not work as expected! -func (s *TemplateService) GetTemplateByID(id string, templatefilter string) (*Template, int, error) { +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( @@ -1387,21 +1389,6 @@ func (s *TemplateService) GetTemplateByID(id string, templatefilter string) (*Te return nil, -1, err } - if l.Count == 0 { - // If no matches, search all projects - p.p["projectid"] = "-1" - - 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) } @@ -1636,13 +1623,19 @@ func (s *TemplateService) NewListTemplatePermissionsParams(id string) *ListTempl } // This is a courtesy helper function, which in some cases may not work as expected! -func (s *TemplateService) GetTemplatePermissionByID(id string) (*TemplatePermission, int, error) { +func (s *TemplateService) GetTemplatePermissionByID(id string, opts ...OptionFunc) (*TemplatePermission, int, error) { p := &ListTemplatePermissionsParams{} p.p = make(map[string]interface{}) p.p["id"] = id 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( diff --git a/vendor/github.com/xanzy/go-cloudstack/cloudstack/UCSService.go b/vendor/github.com/xanzy/go-cloudstack/cloudstack/UCSService.go index 5bf79c5e78..0f95779ce9 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 2014, Sander van Harmelen +// Copyright 2016, 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. @@ -202,12 +202,18 @@ func (s *UCSService) NewListUcsManagersParams() *ListUcsManagersParams { } // This is a courtesy helper function, which in some cases may not work as expected! -func (s *UCSService) GetUcsManagerID(keyword string) (string, error) { +func (s *UCSService) GetUcsManagerID(keyword string, opts ...OptionFunc) (string, 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 "", err + } + } + l, err := s.ListUcsManagers(p) if err != nil { return "", err @@ -232,13 +238,13 @@ func (s *UCSService) GetUcsManagerID(keyword string) (string, error) { } // This is a courtesy helper function, which in some cases may not work as expected! -func (s *UCSService) GetUcsManagerByName(name string) (*UcsManager, int, error) { - id, err := s.GetUcsManagerID(name) +func (s *UCSService) GetUcsManagerByName(name string, opts ...OptionFunc) (*UcsManager, int, error) { + id, err := s.GetUcsManagerID(name, opts...) if err != nil { return nil, -1, err } - r, count, err := s.GetUcsManagerByID(id) + r, count, err := s.GetUcsManagerByID(id, opts...) if err != nil { return nil, count, err } @@ -246,12 +252,18 @@ func (s *UCSService) GetUcsManagerByName(name string) (*UcsManager, int, error) } // This is a courtesy helper function, which in some cases may not work as expected! -func (s *UCSService) GetUcsManagerByID(id string) (*UcsManager, int, error) { +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( diff --git a/vendor/github.com/xanzy/go-cloudstack/cloudstack/UsageService.go b/vendor/github.com/xanzy/go-cloudstack/cloudstack/UsageService.go index a25592042a..7bae32e1d4 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 2014, Sander van Harmelen +// Copyright 2016, 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. @@ -325,13 +325,19 @@ func (s *UsageService) NewListTrafficTypesParams(physicalnetworkid string) *List } // This is a courtesy helper function, which in some cases may not work as expected! -func (s *UsageService) GetTrafficTypeID(keyword string, physicalnetworkid string) (string, error) { +func (s *UsageService) GetTrafficTypeID(keyword string, physicalnetworkid string, opts ...OptionFunc) (string, error) { p := &ListTrafficTypesParams{} p.p = make(map[string]interface{}) p.p["keyword"] = keyword p.p["physicalnetworkid"] = physicalnetworkid + for _, fn := range opts { + if err := fn(s.cs, p); err != nil { + return "", err + } + } + l, err := s.ListTrafficTypes(p) if err != nil { return "", err diff --git a/vendor/github.com/xanzy/go-cloudstack/cloudstack/UserService.go b/vendor/github.com/xanzy/go-cloudstack/cloudstack/UserService.go index e11e25f61f..cf091225d4 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 2014, Sander van Harmelen +// Copyright 2016, 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. @@ -535,12 +535,18 @@ func (s *UserService) NewListUsersParams() *ListUsersParams { } // This is a courtesy helper function, which in some cases may not work as expected! -func (s *UserService) GetUserByID(id string) (*User, int, error) { +func (s *UserService) GetUserByID(id string, opts ...OptionFunc) (*User, int, error) { p := &ListUsersParams{} 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.ListUsers(p) if err != nil { if strings.Contains(err.Error(), fmt.Sprintf( diff --git a/vendor/github.com/xanzy/go-cloudstack/cloudstack/VLANService.go b/vendor/github.com/xanzy/go-cloudstack/cloudstack/VLANService.go index 38ebb01368..0809b6dae8 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 2014, Sander van Harmelen +// Copyright 2016, 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. @@ -489,12 +489,18 @@ func (s *VLANService) NewListVlanIpRangesParams() *ListVlanIpRangesParams { } // This is a courtesy helper function, which in some cases may not work as expected! -func (s *VLANService) GetVlanIpRangeByID(id string) (*VlanIpRange, int, error) { +func (s *VLANService) GetVlanIpRangeByID(id string, opts ...OptionFunc) (*VlanIpRange, int, error) { p := &ListVlanIpRangesParams{} 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.ListVlanIpRanges(p) if err != nil { if strings.Contains(err.Error(), fmt.Sprintf( @@ -505,21 +511,6 @@ func (s *VLANService) GetVlanIpRangeByID(id string) (*VlanIpRange, int, error) { return nil, -1, err } - if l.Count == 0 { - // If no matches, search all projects - p.p["projectid"] = "-1" - - l, err = s.ListVlanIpRanges(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) } @@ -879,12 +870,18 @@ func (s *VLANService) NewListDedicatedGuestVlanRangesParams() *ListDedicatedGues } // This is a courtesy helper function, which in some cases may not work as expected! -func (s *VLANService) GetDedicatedGuestVlanRangeByID(id string) (*DedicatedGuestVlanRange, int, error) { +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( @@ -895,21 +892,6 @@ func (s *VLANService) GetDedicatedGuestVlanRangeByID(id string) (*DedicatedGuest return nil, -1, err } - if l.Count == 0 { - // If no matches, search all projects - p.p["projectid"] = "-1" - - 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) } diff --git a/vendor/github.com/xanzy/go-cloudstack/cloudstack/VMGroupService.go b/vendor/github.com/xanzy/go-cloudstack/cloudstack/VMGroupService.go index da57bef019..998e9c004e 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 2014, Sander van Harmelen +// Copyright 2016, 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,27 +368,23 @@ func (s *VMGroupService) NewListInstanceGroupsParams() *ListInstanceGroupsParams } // This is a courtesy helper function, which in some cases may not work as expected! -func (s *VMGroupService) GetInstanceGroupID(name string) (string, error) { +func (s *VMGroupService) GetInstanceGroupID(name string, opts ...OptionFunc) (string, error) { p := &ListInstanceGroupsParams{} p.p = make(map[string]interface{}) p.p["name"] = name + for _, fn := range opts { + if err := fn(s.cs, p); err != nil { + return "", err + } + } + l, err := s.ListInstanceGroups(p) if err != nil { return "", err } - if l.Count == 0 { - // If no matches, search all projects - p.p["projectid"] = "-1" - - l, err = s.ListInstanceGroups(p) - if err != nil { - return "", err - } - } - if l.Count == 0 { return "", fmt.Errorf("No match found for %s: %+v", name, l) } @@ -408,13 +404,13 @@ func (s *VMGroupService) GetInstanceGroupID(name string) (string, error) { } // This is a courtesy helper function, which in some cases may not work as expected! -func (s *VMGroupService) GetInstanceGroupByName(name string) (*InstanceGroup, int, error) { - id, err := s.GetInstanceGroupID(name) +func (s *VMGroupService) GetInstanceGroupByName(name string, opts ...OptionFunc) (*InstanceGroup, int, error) { + id, err := s.GetInstanceGroupID(name, opts...) if err != nil { return nil, -1, err } - r, count, err := s.GetInstanceGroupByID(id) + r, count, err := s.GetInstanceGroupByID(id, opts...) if err != nil { return nil, count, err } @@ -422,12 +418,18 @@ func (s *VMGroupService) GetInstanceGroupByName(name string) (*InstanceGroup, in } // This is a courtesy helper function, which in some cases may not work as expected! -func (s *VMGroupService) GetInstanceGroupByID(id string) (*InstanceGroup, int, error) { +func (s *VMGroupService) GetInstanceGroupByID(id string, opts ...OptionFunc) (*InstanceGroup, int, error) { p := &ListInstanceGroupsParams{} 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.ListInstanceGroups(p) if err != nil { if strings.Contains(err.Error(), fmt.Sprintf( @@ -438,21 +440,6 @@ func (s *VMGroupService) GetInstanceGroupByID(id string) (*InstanceGroup, int, e return nil, -1, err } - if l.Count == 0 { - // If no matches, search all projects - p.p["projectid"] = "-1" - - l, err = s.ListInstanceGroups(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) } diff --git a/vendor/github.com/xanzy/go-cloudstack/cloudstack/VPCService.go b/vendor/github.com/xanzy/go-cloudstack/cloudstack/VPCService.go index c87e16e4f6..8108300281 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 2014, Sander van Harmelen +// Copyright 2016, 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. @@ -578,27 +578,23 @@ func (s *VPCService) NewListVPCsParams() *ListVPCsParams { } // This is a courtesy helper function, which in some cases may not work as expected! -func (s *VPCService) GetVPCID(name string) (string, error) { +func (s *VPCService) GetVPCID(name string, opts ...OptionFunc) (string, error) { p := &ListVPCsParams{} p.p = make(map[string]interface{}) p.p["name"] = name + for _, fn := range opts { + if err := fn(s.cs, p); err != nil { + return "", err + } + } + l, err := s.ListVPCs(p) if err != nil { return "", err } - if l.Count == 0 { - // If no matches, search all projects - p.p["projectid"] = "-1" - - l, err = s.ListVPCs(p) - if err != nil { - return "", err - } - } - if l.Count == 0 { return "", fmt.Errorf("No match found for %s: %+v", name, l) } @@ -618,13 +614,13 @@ func (s *VPCService) GetVPCID(name string) (string, error) { } // This is a courtesy helper function, which in some cases may not work as expected! -func (s *VPCService) GetVPCByName(name string) (*VPC, int, error) { - id, err := s.GetVPCID(name) +func (s *VPCService) GetVPCByName(name string, opts ...OptionFunc) (*VPC, int, error) { + id, err := s.GetVPCID(name, opts...) if err != nil { return nil, -1, err } - r, count, err := s.GetVPCByID(id) + r, count, err := s.GetVPCByID(id, opts...) if err != nil { return nil, count, err } @@ -632,12 +628,18 @@ func (s *VPCService) GetVPCByName(name string) (*VPC, int, error) { } // This is a courtesy helper function, which in some cases may not work as expected! -func (s *VPCService) GetVPCByID(id string) (*VPC, int, error) { +func (s *VPCService) GetVPCByID(id string, opts ...OptionFunc) (*VPC, int, error) { p := &ListVPCsParams{} 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.ListVPCs(p) if err != nil { if strings.Contains(err.Error(), fmt.Sprintf( @@ -648,21 +650,6 @@ func (s *VPCService) GetVPCByID(id string) (*VPC, int, error) { return nil, -1, err } - if l.Count == 0 { - // If no matches, search all projects - p.p["projectid"] = "-1" - - l, err = s.ListVPCs(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) } @@ -1831,12 +1818,18 @@ func (s *VPCService) NewListVPCOfferingsParams() *ListVPCOfferingsParams { } // This is a courtesy helper function, which in some cases may not work as expected! -func (s *VPCService) GetVPCOfferingID(name string) (string, error) { +func (s *VPCService) GetVPCOfferingID(name string, opts ...OptionFunc) (string, 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 "", err + } + } + l, err := s.ListVPCOfferings(p) if err != nil { return "", err @@ -1861,13 +1854,13 @@ func (s *VPCService) GetVPCOfferingID(name string) (string, error) { } // This is a courtesy helper function, which in some cases may not work as expected! -func (s *VPCService) GetVPCOfferingByName(name string) (*VPCOffering, int, error) { - id, err := s.GetVPCOfferingID(name) +func (s *VPCService) GetVPCOfferingByName(name string, opts ...OptionFunc) (*VPCOffering, int, error) { + id, err := s.GetVPCOfferingID(name, opts...) if err != nil { return nil, -1, err } - r, count, err := s.GetVPCOfferingByID(id) + r, count, err := s.GetVPCOfferingByID(id, opts...) if err != nil { return nil, count, err } @@ -1875,12 +1868,18 @@ func (s *VPCService) GetVPCOfferingByName(name string) (*VPCOffering, int, error } // This is a courtesy helper function, which in some cases may not work as expected! -func (s *VPCService) GetVPCOfferingByID(id string) (*VPCOffering, int, error) { +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( @@ -2296,12 +2295,18 @@ func (s *VPCService) NewListPrivateGatewaysParams() *ListPrivateGatewaysParams { } // This is a courtesy helper function, which in some cases may not work as expected! -func (s *VPCService) GetPrivateGatewayByID(id string) (*PrivateGateway, int, error) { +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( @@ -2312,21 +2317,6 @@ func (s *VPCService) GetPrivateGatewayByID(id string) (*PrivateGateway, int, err return nil, -1, err } - if l.Count == 0 { - // If no matches, search all projects - p.p["projectid"] = "-1" - - 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) } @@ -2776,12 +2766,18 @@ func (s *VPCService) NewListStaticRoutesParams() *ListStaticRoutesParams { } // This is a courtesy helper function, which in some cases may not work as expected! -func (s *VPCService) GetStaticRouteByID(id string) (*StaticRoute, int, error) { +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( @@ -2792,21 +2788,6 @@ func (s *VPCService) GetStaticRouteByID(id string) (*StaticRoute, int, error) { return nil, -1, err } - if l.Count == 0 { - // If no matches, search all projects - p.p["projectid"] = "-1" - - 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) } diff --git a/vendor/github.com/xanzy/go-cloudstack/cloudstack/VPNService.go b/vendor/github.com/xanzy/go-cloudstack/cloudstack/VPNService.go index 26b7fdec09..b25e0a94fb 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 2014, Sander van Harmelen +// Copyright 2016, 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. @@ -388,12 +388,18 @@ func (s *VPNService) NewListRemoteAccessVpnsParams() *ListRemoteAccessVpnsParams } // This is a courtesy helper function, which in some cases may not work as expected! -func (s *VPNService) GetRemoteAccessVpnByID(id string) (*RemoteAccessVpn, int, error) { +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( @@ -404,21 +410,6 @@ func (s *VPNService) GetRemoteAccessVpnByID(id string) (*RemoteAccessVpn, int, e return nil, -1, err } - if l.Count == 0 { - // If no matches, search all projects - p.p["projectid"] = "-1" - - 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) } @@ -926,12 +917,18 @@ func (s *VPNService) NewListVpnUsersParams() *ListVpnUsersParams { } // This is a courtesy helper function, which in some cases may not work as expected! -func (s *VPNService) GetVpnUserByID(id string) (*VpnUser, int, error) { +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( @@ -942,21 +939,6 @@ func (s *VPNService) GetVpnUserByID(id string) (*VpnUser, int, error) { return nil, -1, err } - if l.Count == 0 { - // If no matches, search all projects - p.p["projectid"] = "-1" - - 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) } @@ -2115,27 +2097,23 @@ func (s *VPNService) NewListVpnCustomerGatewaysParams() *ListVpnCustomerGateways } // This is a courtesy helper function, which in some cases may not work as expected! -func (s *VPNService) GetVpnCustomerGatewayID(keyword string) (string, error) { +func (s *VPNService) GetVpnCustomerGatewayID(keyword string, opts ...OptionFunc) (string, 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 "", err + } + } + l, err := s.ListVpnCustomerGateways(p) if err != nil { return "", err } - if l.Count == 0 { - // If no matches, search all projects - p.p["projectid"] = "-1" - - l, err = s.ListVpnCustomerGateways(p) - if err != nil { - return "", err - } - } - if l.Count == 0 { return "", fmt.Errorf("No match found for %s: %+v", keyword, l) } @@ -2155,13 +2133,13 @@ func (s *VPNService) GetVpnCustomerGatewayID(keyword string) (string, error) { } // This is a courtesy helper function, which in some cases may not work as expected! -func (s *VPNService) GetVpnCustomerGatewayByName(name string) (*VpnCustomerGateway, int, error) { - id, err := s.GetVpnCustomerGatewayID(name) +func (s *VPNService) GetVpnCustomerGatewayByName(name string, opts ...OptionFunc) (*VpnCustomerGateway, int, error) { + id, err := s.GetVpnCustomerGatewayID(name, opts...) if err != nil { return nil, -1, err } - r, count, err := s.GetVpnCustomerGatewayByID(id) + r, count, err := s.GetVpnCustomerGatewayByID(id, opts...) if err != nil { return nil, count, err } @@ -2169,12 +2147,18 @@ func (s *VPNService) GetVpnCustomerGatewayByName(name string) (*VpnCustomerGatew } // This is a courtesy helper function, which in some cases may not work as expected! -func (s *VPNService) GetVpnCustomerGatewayByID(id string) (*VpnCustomerGateway, int, error) { +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( @@ -2185,21 +2169,6 @@ func (s *VPNService) GetVpnCustomerGatewayByID(id string) (*VpnCustomerGateway, return nil, -1, err } - if l.Count == 0 { - // If no matches, search all projects - p.p["projectid"] = "-1" - - 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) } @@ -2397,12 +2366,18 @@ func (s *VPNService) NewListVpnGatewaysParams() *ListVpnGatewaysParams { } // This is a courtesy helper function, which in some cases may not work as expected! -func (s *VPNService) GetVpnGatewayByID(id string) (*VpnGateway, int, error) { +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( @@ -2413,21 +2388,6 @@ func (s *VPNService) GetVpnGatewayByID(id string) (*VpnGateway, int, error) { return nil, -1, err } - if l.Count == 0 { - // If no matches, search all projects - p.p["projectid"] = "-1" - - 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) } @@ -2617,12 +2577,18 @@ func (s *VPNService) NewListVpnConnectionsParams() *ListVpnConnectionsParams { } // This is a courtesy helper function, which in some cases may not work as expected! -func (s *VPNService) GetVpnConnectionByID(id string) (*VpnConnection, int, error) { +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( @@ -2633,21 +2599,6 @@ func (s *VPNService) GetVpnConnectionByID(id string) (*VpnConnection, int, error return nil, -1, err } - if l.Count == 0 { - // If no matches, search all projects - p.p["projectid"] = "-1" - - 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) } diff --git a/vendor/github.com/xanzy/go-cloudstack/cloudstack/VirtualMachineService.go b/vendor/github.com/xanzy/go-cloudstack/cloudstack/VirtualMachineService.go index d3a43fa966..79783e2f92 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 2014, Sander van Harmelen +// Copyright 2016, 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. @@ -2592,27 +2592,23 @@ func (s *VirtualMachineService) NewListVirtualMachinesParams() *ListVirtualMachi } // This is a courtesy helper function, which in some cases may not work as expected! -func (s *VirtualMachineService) GetVirtualMachineID(name string) (string, error) { +func (s *VirtualMachineService) GetVirtualMachineID(name string, opts ...OptionFunc) (string, error) { p := &ListVirtualMachinesParams{} p.p = make(map[string]interface{}) p.p["name"] = name + for _, fn := range opts { + if err := fn(s.cs, p); err != nil { + return "", err + } + } + l, err := s.ListVirtualMachines(p) if err != nil { return "", err } - if l.Count == 0 { - // If no matches, search all projects - p.p["projectid"] = "-1" - - l, err = s.ListVirtualMachines(p) - if err != nil { - return "", err - } - } - if l.Count == 0 { return "", fmt.Errorf("No match found for %s: %+v", name, l) } @@ -2632,13 +2628,13 @@ func (s *VirtualMachineService) GetVirtualMachineID(name string) (string, error) } // This is a courtesy helper function, which in some cases may not work as expected! -func (s *VirtualMachineService) GetVirtualMachineByName(name string) (*VirtualMachine, int, error) { - id, err := s.GetVirtualMachineID(name) +func (s *VirtualMachineService) GetVirtualMachineByName(name string, opts ...OptionFunc) (*VirtualMachine, int, error) { + id, err := s.GetVirtualMachineID(name, opts...) if err != nil { return nil, -1, err } - r, count, err := s.GetVirtualMachineByID(id) + r, count, err := s.GetVirtualMachineByID(id, opts...) if err != nil { return nil, count, err } @@ -2646,12 +2642,18 @@ func (s *VirtualMachineService) GetVirtualMachineByName(name string) (*VirtualMa } // This is a courtesy helper function, which in some cases may not work as expected! -func (s *VirtualMachineService) GetVirtualMachineByID(id string) (*VirtualMachine, int, error) { +func (s *VirtualMachineService) GetVirtualMachineByID(id string, opts ...OptionFunc) (*VirtualMachine, int, error) { p := &ListVirtualMachinesParams{} 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.ListVirtualMachines(p) if err != nil { if strings.Contains(err.Error(), fmt.Sprintf( @@ -2662,21 +2664,6 @@ func (s *VirtualMachineService) GetVirtualMachineByID(id string) (*VirtualMachin return nil, -1, err } - if l.Count == 0 { - // If no matches, search all projects - p.p["projectid"] = "-1" - - l, err = s.ListVirtualMachines(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) } diff --git a/vendor/github.com/xanzy/go-cloudstack/cloudstack/VolumeService.go b/vendor/github.com/xanzy/go-cloudstack/cloudstack/VolumeService.go index 7fbf81f0c6..6ed16adb6d 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 2014, Sander van Harmelen +// Copyright 2016, 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. @@ -1126,27 +1126,23 @@ func (s *VolumeService) NewListVolumesParams() *ListVolumesParams { } // This is a courtesy helper function, which in some cases may not work as expected! -func (s *VolumeService) GetVolumeID(name string) (string, error) { +func (s *VolumeService) GetVolumeID(name string, opts ...OptionFunc) (string, 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 "", err + } + } + l, err := s.ListVolumes(p) if err != nil { return "", err } - if l.Count == 0 { - // If no matches, search all projects - p.p["projectid"] = "-1" - - l, err = s.ListVolumes(p) - if err != nil { - return "", err - } - } - if l.Count == 0 { return "", fmt.Errorf("No match found for %s: %+v", name, l) } @@ -1166,13 +1162,13 @@ func (s *VolumeService) GetVolumeID(name string) (string, error) { } // This is a courtesy helper function, which in some cases may not work as expected! -func (s *VolumeService) GetVolumeByName(name string) (*Volume, int, error) { - id, err := s.GetVolumeID(name) +func (s *VolumeService) GetVolumeByName(name string, opts ...OptionFunc) (*Volume, int, error) { + id, err := s.GetVolumeID(name, opts...) if err != nil { return nil, -1, err } - r, count, err := s.GetVolumeByID(id) + r, count, err := s.GetVolumeByID(id, opts...) if err != nil { return nil, count, err } @@ -1180,12 +1176,18 @@ func (s *VolumeService) GetVolumeByName(name string) (*Volume, int, error) { } // This is a courtesy helper function, which in some cases may not work as expected! -func (s *VolumeService) GetVolumeByID(id string) (*Volume, int, error) { +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( @@ -1196,21 +1198,6 @@ func (s *VolumeService) GetVolumeByID(id string) (*Volume, int, error) { return nil, -1, err } - if l.Count == 0 { - // If no matches, search all projects - p.p["projectid"] = "-1" - - 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) } diff --git a/vendor/github.com/xanzy/go-cloudstack/cloudstack/ZoneService.go b/vendor/github.com/xanzy/go-cloudstack/cloudstack/ZoneService.go index 68fa7b2117..e993481809 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 2014, Sander van Harmelen +// Copyright 2016, 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. @@ -724,12 +724,18 @@ func (s *ZoneService) NewListZonesParams() *ListZonesParams { } // This is a courtesy helper function, which in some cases may not work as expected! -func (s *ZoneService) GetZoneID(name string) (string, error) { +func (s *ZoneService) GetZoneID(name string, opts ...OptionFunc) (string, 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 "", err + } + } + l, err := s.ListZones(p) if err != nil { return "", err @@ -754,13 +760,13 @@ func (s *ZoneService) GetZoneID(name string) (string, error) { } // This is a courtesy helper function, which in some cases may not work as expected! -func (s *ZoneService) GetZoneByName(name string) (*Zone, int, error) { - id, err := s.GetZoneID(name) +func (s *ZoneService) GetZoneByName(name string, opts ...OptionFunc) (*Zone, int, error) { + id, err := s.GetZoneID(name, opts...) if err != nil { return nil, -1, err } - r, count, err := s.GetZoneByID(id) + r, count, err := s.GetZoneByID(id, opts...) if err != nil { return nil, count, err } @@ -768,12 +774,18 @@ func (s *ZoneService) GetZoneByName(name string) (*Zone, int, error) { } // This is a courtesy helper function, which in some cases may not work as expected! -func (s *ZoneService) GetZoneByID(id string) (*Zone, int, error) { +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( diff --git a/vendor/github.com/xanzy/go-cloudstack/cloudstack/cloudstack.go b/vendor/github.com/xanzy/go-cloudstack/cloudstack/cloudstack.go index 8c357cb495..53e38bfed2 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 2014, Sander van Harmelen +// Copyright 2016, 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. @@ -28,11 +28,25 @@ import ( "io/ioutil" "net/http" "net/url" + "regexp" "sort" "strings" "time" ) +// UnlimitedResourceID is a special ID to define an unlimited resource +const UnlimitedResourceID = "-1" + +var idRegex = regexp.MustCompile(`^([0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}|-1)$`) + +// IsID return true if the passed ID is either a UUID or a UnlimitedResourceID +func IsID(id string) bool { + return idRegex.MatchString(id) +} + +// OptionFunc can be passed to the courtesy helper functions to set additional parameters +type OptionFunc func(*CloudStackClient, interface{}) error + type CSError struct { ErrorCode int `json:"errorcode"` CSErrorCode int `json:"cserrorcode"` @@ -369,6 +383,34 @@ func getRawValue(b json.RawMessage) (json.RawMessage, error) { return nil, fmt.Errorf("Unable to extract the raw value from:\n\n%s\n\n", string(b)) } +// ProjectIDSetter is an interface that every type that can set a project ID must implement +type ProjectIDSetter interface { + SetProjectid(string) +} + +// WithProject takes either a project name or ID and sets the `projectid` parameter +func WithProject(project string) OptionFunc { + return func(cs *CloudStackClient, p interface{}) error { + ps, ok := p.(ProjectIDSetter) + + if !ok || project == "" { + return nil + } + + if !IsID(project) { + id, err := cs.Project.GetProjectID(project) + if err != nil { + return err + } + project = id + } + + ps.SetProjectid(project) + + return nil + } +} + type APIDiscoveryService struct { cs *CloudStackClient } From 5a65cc9cb6918f4bfb3964ed82104d91d619c854 Mon Sep 17 00:00:00 2001 From: Sander van Harmelen Date: Thu, 21 Apr 2016 17:31:53 +0200 Subject: [PATCH 2/2] Use the new functionality offered by the `go-cloudstack` package The updated functionality offers a new means to work with projects. This commit uses that new functionality for the `cloudstack_network` resource. --- .../cloudstack/resource_cloudstack_disk.go | 39 +++++++++++++---- .../resource_cloudstack_instance.go | 12 +++++- .../resource_cloudstack_ipaddress.go | 19 ++++++-- .../cloudstack/resource_cloudstack_network.go | 12 +++++- .../resource_cloudstack_port_forward.go | 31 +++++++++---- .../resource_cloudstack_template.go | 6 ++- .../cloudstack/resource_cloudstack_vpc.go | 5 ++- builtin/providers/cloudstack/resources.go | 43 +++++++++---------- 8 files changed, 117 insertions(+), 50 deletions(-) diff --git a/builtin/providers/cloudstack/resource_cloudstack_disk.go b/builtin/providers/cloudstack/resource_cloudstack_disk.go index de187274be..fd4807ae5a 100644 --- a/builtin/providers/cloudstack/resource_cloudstack_disk.go +++ b/builtin/providers/cloudstack/resource_cloudstack_disk.go @@ -141,7 +141,10 @@ func resourceCloudStackDiskRead(d *schema.ResourceData, meta interface{}) error cs := meta.(*cloudstack.CloudStackClient) // Get the volume details - v, count, err := cs.Volume.GetVolumeByID(d.Id()) + v, count, err := cs.Volume.GetVolumeByID( + d.Id(), + cloudstack.WithProject(d.Get("project").(string)), + ) if err != nil { if count == 0 { d.SetId("") @@ -152,7 +155,7 @@ func resourceCloudStackDiskRead(d *schema.ResourceData, meta interface{}) error } d.Set("name", v.Name) - d.Set("attach", v.Attached != "") // If attached this will contain a timestamp when attached + d.Set("attach", v.Attached != "") // If attached this contains a timestamp when attached d.Set("size", int(v.Size/(1024*1024*1024))) // Needed to get GB's again setValueOrID(d, "disk_offering", v.Diskofferingname, v.Diskofferingid) @@ -161,7 +164,10 @@ func resourceCloudStackDiskRead(d *schema.ResourceData, meta interface{}) error if v.Attached != "" { // Get the virtual machine details - vm, _, err := cs.VirtualMachine.GetVirtualMachineByID(v.Virtualmachineid) + vm, _, err := cs.VirtualMachine.GetVirtualMachineByID( + v.Virtualmachineid, + cloudstack.WithProject(d.Get("project").(string)), + ) if err != nil { return err } @@ -290,12 +296,17 @@ func resourceCloudStackDiskAttach(d *schema.ResourceData, meta interface{}) erro cs := meta.(*cloudstack.CloudStackClient) // First check if the disk isn't already attached - if attached, err := isAttached(cs, d.Id()); err != nil || attached { + if attached, err := isAttached(d, meta); err != nil || attached { return err } // Retrieve the virtual_machine ID - virtualmachineid, e := retrieveID(cs, "virtual_machine", d.Get("virtual_machine").(string)) + virtualmachineid, e := retrieveID( + cs, + "virtual_machine", + d.Get("virtual_machine").(string), + cloudstack.WithProject(d.Get("project").(string)), + ) if e != nil { return e.Error() } @@ -329,7 +340,7 @@ func resourceCloudStackDiskDetach(d *schema.ResourceData, meta interface{}) erro cs := meta.(*cloudstack.CloudStackClient) // Check if the volume is actually attached, before detaching - if attached, err := isAttached(cs, d.Id()); err != nil || !attached { + if attached, err := isAttached(d, meta); err != nil || !attached { return err } @@ -342,7 +353,12 @@ func resourceCloudStackDiskDetach(d *schema.ResourceData, meta interface{}) erro // Detach the currently attached volume if _, err := cs.Volume.DetachVolume(p); err != nil { // Retrieve the virtual_machine ID - virtualmachineid, e := retrieveID(cs, "virtual_machine", d.Get("virtual_machine").(string)) + virtualmachineid, e := retrieveID( + cs, + "virtual_machine", + d.Get("virtual_machine").(string), + cloudstack.WithProject(d.Get("project").(string)), + ) if e != nil { return e.Error() } @@ -372,9 +388,14 @@ func resourceCloudStackDiskDetach(d *schema.ResourceData, meta interface{}) erro return nil } -func isAttached(cs *cloudstack.CloudStackClient, id string) (bool, error) { +func isAttached(d *schema.ResourceData, meta interface{}) (bool, error) { + cs := meta.(*cloudstack.CloudStackClient) + // Get the volume details - v, _, err := cs.Volume.GetVolumeByID(id) + v, _, err := cs.Volume.GetVolumeByID( + d.Id(), + cloudstack.WithProject(d.Get("project").(string)), + ) if err != nil { return false, err } diff --git a/builtin/providers/cloudstack/resource_cloudstack_instance.go b/builtin/providers/cloudstack/resource_cloudstack_instance.go index 7cf6f810f6..9c787be84d 100644 --- a/builtin/providers/cloudstack/resource_cloudstack_instance.go +++ b/builtin/providers/cloudstack/resource_cloudstack_instance.go @@ -174,7 +174,12 @@ func resourceCloudStackInstanceCreate(d *schema.ResourceData, meta interface{}) } // Retrieve the network ID - networkid, e := retrieveID(cs, "network", network.(string)) + networkid, e := retrieveID( + cs, + "network", + network.(string), + cloudstack.WithProject(d.Get("project").(string)), + ) if e != nil { return e.Error() } @@ -250,7 +255,10 @@ func resourceCloudStackInstanceRead(d *schema.ResourceData, meta interface{}) er cs := meta.(*cloudstack.CloudStackClient) // Get the virtual machine details - vm, count, err := cs.VirtualMachine.GetVirtualMachineByID(d.Id()) + vm, count, err := cs.VirtualMachine.GetVirtualMachineByID( + d.Id(), + cloudstack.WithProject(d.Get("project").(string)), + ) if err != nil { if count == 0 { log.Printf("[DEBUG] Instance %s does no longer exist", d.Get("name").(string)) diff --git a/builtin/providers/cloudstack/resource_cloudstack_ipaddress.go b/builtin/providers/cloudstack/resource_cloudstack_ipaddress.go index 2c21d222e0..548d12dad8 100644 --- a/builtin/providers/cloudstack/resource_cloudstack_ipaddress.go +++ b/builtin/providers/cloudstack/resource_cloudstack_ipaddress.go @@ -74,7 +74,12 @@ func resourceCloudStackIPAddressCreate(d *schema.ResourceData, meta interface{}) } if ok { // Retrieve the network ID - networkid, e := retrieveID(cs, "network", network.(string)) + networkid, e := retrieveID( + cs, + "network", + network.(string), + cloudstack.WithProject(d.Get("project").(string)), + ) if e != nil { return e.Error() } @@ -89,7 +94,12 @@ func resourceCloudStackIPAddressCreate(d *schema.ResourceData, meta interface{}) } if ok { // Retrieve the vpc ID - vpcid, e := retrieveID(cs, "vpc", vpc.(string)) + vpcid, e := retrieveID( + cs, + "vpc", + vpc.(string), + cloudstack.WithProject(d.Get("project").(string)), + ) if e != nil { return e.Error() } @@ -118,7 +128,10 @@ func resourceCloudStackIPAddressRead(d *schema.ResourceData, meta interface{}) e cs := meta.(*cloudstack.CloudStackClient) // Get the IP address details - ip, count, err := cs.Address.GetPublicIpAddressByID(d.Id()) + ip, count, err := cs.Address.GetPublicIpAddressByID( + d.Id(), + cloudstack.WithProject(d.Get("project").(string)), + ) if err != nil { if count == 0 { log.Printf( diff --git a/builtin/providers/cloudstack/resource_cloudstack_network.go b/builtin/providers/cloudstack/resource_cloudstack_network.go index c8df5187d6..69dc27091a 100644 --- a/builtin/providers/cloudstack/resource_cloudstack_network.go +++ b/builtin/providers/cloudstack/resource_cloudstack_network.go @@ -161,7 +161,12 @@ func resourceCloudStackNetworkCreate(d *schema.ResourceData, meta interface{}) e } if ok { // Retrieve the vpc ID - vpcid, e := retrieveID(cs, "vpc", vpc.(string)) + vpcid, e := retrieveID( + cs, + "vpc", + vpc.(string), + cloudstack.WithProject(d.Get("project").(string)), + ) if e != nil { return e.Error() } @@ -205,7 +210,10 @@ func resourceCloudStackNetworkRead(d *schema.ResourceData, meta interface{}) err cs := meta.(*cloudstack.CloudStackClient) // Get the virtual machine details - n, count, err := cs.Network.GetNetworkByID(d.Id()) + n, count, err := cs.Network.GetNetworkByID( + d.Id(), + cloudstack.WithProject(d.Get("project").(string)), + ) if err != nil { if count == 0 { log.Printf( diff --git a/builtin/providers/cloudstack/resource_cloudstack_port_forward.go b/builtin/providers/cloudstack/resource_cloudstack_port_forward.go index ca84f91bab..6615b82ae7 100644 --- a/builtin/providers/cloudstack/resource_cloudstack_port_forward.go +++ b/builtin/providers/cloudstack/resource_cloudstack_port_forward.go @@ -103,7 +103,12 @@ func resourceCloudStackPortForwardCreate(d *schema.ResourceData, meta interface{ } // Retrieve the ipaddress ID - ipaddressid, e := retrieveID(cs, "ip_address", ipaddress.(string)) + ipaddressid, e := retrieveID( + cs, + "ip_address", + ipaddress.(string), + cloudstack.WithProject(d.Get("project").(string)), + ) if e != nil { return e.Error() } @@ -189,12 +194,20 @@ func createPortForward( } // Retrieve the virtual_machine ID - virtualmachineid, e := retrieveID(cs, "virtual_machine", virtualmachine.(string)) + virtualmachineid, e := retrieveID( + cs, + "virtual_machine", + virtualmachine.(string), + cloudstack.WithProject(d.Get("project").(string)), + ) if e != nil { return e.Error() } - vm, _, err := cs.VirtualMachine.GetVirtualMachineByID(virtualmachineid) + vm, _, err := cs.VirtualMachine.GetVirtualMachineByID( + virtualmachineid, + cloudstack.WithProject(d.Get("project").(string)), + ) if err != nil { return err } @@ -326,9 +339,9 @@ func resourceCloudStackPortForwardUpdate(d *schema.ResourceData, meta interface{ // set to make sure we end up in a consistent state forwards := o.(*schema.Set).Intersection(n.(*schema.Set)) - // First loop through all the new forwards and create (before destroy) them - if nrs.Len() > 0 { - err := createPortForwards(d, meta, forwards, nrs) + // First loop through all the old forwards and delete them + if ors.Len() > 0 { + err := deletePortForwards(d, meta, forwards, ors) // We need to update this first to preserve the correct state d.Set("forward", forwards) @@ -338,9 +351,9 @@ func resourceCloudStackPortForwardUpdate(d *schema.ResourceData, meta interface{ } } - // Then loop through all the old forwards and delete them - if ors.Len() > 0 { - err := deletePortForwards(d, meta, forwards, ors) + // Then loop through all the new forwards and create them + if nrs.Len() > 0 { + err := createPortForwards(d, meta, forwards, nrs) // We need to update this first to preserve the correct state d.Set("forward", forwards) diff --git a/builtin/providers/cloudstack/resource_cloudstack_template.go b/builtin/providers/cloudstack/resource_cloudstack_template.go index 10c24fdbb6..b3b3a45185 100644 --- a/builtin/providers/cloudstack/resource_cloudstack_template.go +++ b/builtin/providers/cloudstack/resource_cloudstack_template.go @@ -207,7 +207,11 @@ func resourceCloudStackTemplateRead(d *schema.ResourceData, meta interface{}) er cs := meta.(*cloudstack.CloudStackClient) // Get the template details - t, count, err := cs.Template.GetTemplateByID(d.Id(), "executable") + t, count, err := cs.Template.GetTemplateByID( + d.Id(), + "executable", + cloudstack.WithProject(d.Get("project").(string)), + ) if err != nil { if count == 0 { log.Printf( diff --git a/builtin/providers/cloudstack/resource_cloudstack_vpc.go b/builtin/providers/cloudstack/resource_cloudstack_vpc.go index a51b4dd313..16cf2ad11d 100644 --- a/builtin/providers/cloudstack/resource_cloudstack_vpc.go +++ b/builtin/providers/cloudstack/resource_cloudstack_vpc.go @@ -125,7 +125,10 @@ func resourceCloudStackVPCRead(d *schema.ResourceData, meta interface{}) error { cs := meta.(*cloudstack.CloudStackClient) // Get the VPC details - v, count, err := cs.VPC.GetVPCByID(d.Id()) + v, count, err := cs.VPC.GetVPCByID( + d.Id(), + cloudstack.WithProject(d.Get("project").(string)), + ) if err != nil { if count == 0 { log.Printf( diff --git a/builtin/providers/cloudstack/resources.go b/builtin/providers/cloudstack/resources.go index d404e38c6b..a6fbb93253 100644 --- a/builtin/providers/cloudstack/resources.go +++ b/builtin/providers/cloudstack/resources.go @@ -11,9 +11,6 @@ import ( "github.com/xanzy/go-cloudstack/cloudstack" ) -// UnlimitedResourceID is a "special" ID to define an unlimited resource -const UnlimitedResourceID = "-1" - // Define a regexp for parsing the port var splitPorts = regexp.MustCompile(`^(\d+)(?:-(\d+))?$`) @@ -28,11 +25,11 @@ func (e *retrieveError) Error() error { } func setValueOrID(d *schema.ResourceData, key string, value string, id string) { - if isID(d.Get(key).(string)) { + if cloudstack.IsID(d.Get(key).(string)) { // If the given id is an empty string, check if the configured value matches // the UnlimitedResourceID in which case we set id to UnlimitedResourceID - if id == "" && d.Get(key).(string) == UnlimitedResourceID { - id = UnlimitedResourceID + if id == "" && d.Get(key).(string) == cloudstack.UnlimitedResourceID { + id = cloudstack.UnlimitedResourceID } d.Set(key, id) @@ -41,9 +38,13 @@ func setValueOrID(d *schema.ResourceData, key string, value string, id string) { } } -func retrieveID(cs *cloudstack.CloudStackClient, name, value string) (id string, e *retrieveError) { +func retrieveID( + cs *cloudstack.CloudStackClient, + name string, + value string, + opts ...cloudstack.OptionFunc) (id string, e *retrieveError) { // If the supplied value isn't a ID, try to retrieve the ID ourselves - if isID(value) { + if cloudstack.IsID(value) { return value, nil } @@ -54,7 +55,7 @@ func retrieveID(cs *cloudstack.CloudStackClient, name, value string) (id string, case "disk_offering": id, err = cs.DiskOffering.GetDiskOfferingID(value) case "virtual_machine": - id, err = cs.VirtualMachine.GetVirtualMachineID(value) + id, err = cs.VirtualMachine.GetVirtualMachineID(value, opts...) case "service_offering": id, err = cs.ServiceOffering.GetServiceOfferingID(value) case "network_offering": @@ -64,14 +65,20 @@ func retrieveID(cs *cloudstack.CloudStackClient, name, value string) (id string, case "vpc_offering": id, err = cs.VPC.GetVPCOfferingID(value) case "vpc": - id, err = cs.VPC.GetVPCID(value) + id, err = cs.VPC.GetVPCID(value, opts...) case "network": - id, err = cs.Network.GetNetworkID(value) + id, err = cs.Network.GetNetworkID(value, opts...) case "zone": id, err = cs.Zone.GetZoneID(value) case "ip_address": p := cs.Address.NewListPublicIpAddressesParams() p.SetIpaddress(value) + for _, fn := range opts { + if e := fn(cs, p); e != nil { + err = e + break + } + } l, e := cs.Address.ListPublicIpAddresses(p) if e != nil { err = e @@ -109,7 +116,7 @@ func retrieveID(cs *cloudstack.CloudStackClient, name, value string) (id string, func retrieveTemplateID(cs *cloudstack.CloudStackClient, zoneid, value string) (id string, e *retrieveError) { // If the supplied value isn't a ID, try to retrieve the ID ourselves - if isID(value) { + if cloudstack.IsID(value) { return value, nil } @@ -123,12 +130,6 @@ func retrieveTemplateID(cs *cloudstack.CloudStackClient, zoneid, value string) ( return id, nil } -// ID can be either a UUID or a UnlimitedResourceID -func isID(id string) bool { - re := regexp.MustCompile(`^([0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}|-1)$`) - return re.MatchString(id) -} - // RetryFunc is the function retried n times type RetryFunc func() (interface{}, error) @@ -183,12 +184,8 @@ func setCidrList(rule map[string]interface{}, cidrList string) { rule["cidr_list"] = cidrs } -type projectidSetter interface { - SetProjectid(string) -} - // If there is a project supplied, we retrieve and set the project id -func setProjectid(p projectidSetter, cs *cloudstack.CloudStackClient, d *schema.ResourceData) error { +func setProjectid(p cloudstack.ProjectIDSetter, cs *cloudstack.CloudStackClient, d *schema.ResourceData) error { if project, ok := d.GetOk("project"); ok { projectid, e := retrieveID(cs, "project", project.(string)) if e != nil {