Skip to content
Permalink
Browse files
Make the GetXXXID also search projects
  • Loading branch information
Sander van Harmelen committed Jun 9, 2015
1 parent 679b677 commit 9a3ffa294331f8004f9613a231fa3203eb595bd7
Show file tree
Hide file tree
Showing 31 changed files with 398 additions and 1 deletion.
@@ -1738,6 +1738,16 @@ func (s *AccountService) GetProjectAccountID(keyword string, projectid string) (
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)
}
@@ -751,6 +751,16 @@ func (s *ISOService) GetIsoID(name string) (string, error) {
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)
}
@@ -832,6 +832,16 @@ func (s *InternalLBService) GetInternalLoadBalancerVMID(name string) (string, er
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)
}
@@ -1092,6 +1092,16 @@ func (s *LoadBalancerService) GetLoadBalancerRuleID(name string) (string, error)
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)
}
@@ -3695,6 +3705,16 @@ func (s *LoadBalancerService) GetGlobalLoadBalancerRuleID(keyword string) (strin
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)
}
@@ -4451,6 +4471,16 @@ func (s *LoadBalancerService) GetLoadBalancerID(name string) (string, error) {
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)
}
@@ -1290,6 +1290,16 @@ func (s *NetworkACLService) GetNetworkACLListID(name string) (string, error) {
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)
}
@@ -258,6 +258,9 @@ func (p *CreateNetworkParams) toURLValues() url.Values {
if v, found := p.p["vlan"]; found {
u.Set("vlan", v.(string))
}
if v, found := p.p["vlan"]; found {
u.Set("vlan", v.(string))
}
if v, found := p.p["vpcid"]; found {
u.Set("vpcid", v.(string))
}
@@ -949,6 +952,16 @@ func (s *NetworkService) GetNetworkID(keyword string) (string, error) {
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)
}
@@ -941,6 +941,16 @@ func (s *RouterService) GetRouterID(name string) (string, error) {
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)
}
@@ -1034,6 +1034,16 @@ func (s *SecurityGroupService) GetSecurityGroupID(keyword string) (string, error
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)
}
@@ -375,6 +375,16 @@ func (s *SnapshotService) GetSnapshotID(name string) (string, error) {
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)
}
@@ -1277,6 +1287,16 @@ func (s *SnapshotService) GetVMSnapshotID(name string) (string, error) {
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)
}
@@ -1310,6 +1310,16 @@ func (s *TemplateService) GetTemplateID(name string, templatefilter string, zone
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)
}
@@ -379,6 +379,16 @@ func (s *VMGroupService) GetInstanceGroupID(name string) (string, error) {
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)
}
@@ -590,6 +590,16 @@ func (s *VPCService) GetVPCID(name string) (string, error) {
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)
}
@@ -2113,6 +2113,16 @@ func (s *VPNService) GetVpnCustomerGatewayID(keyword string) (string, error) {
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)
}
@@ -2193,6 +2193,9 @@ func (p *ListVirtualMachinesParams) toURLValues() url.Values {
if v, found := p.p["hostid"]; found {
u.Set("hostid", v.(string))
}
if v, found := p.p["hostid"]; found {
u.Set("hostid", v.(string))
}
if v, found := p.p["hypervisor"]; found {
u.Set("hypervisor", v.(string))
}
@@ -2234,6 +2237,9 @@ func (p *ListVirtualMachinesParams) toURLValues() url.Values {
if v, found := p.p["podid"]; found {
u.Set("podid", v.(string))
}
if v, found := p.p["podid"]; found {
u.Set("podid", v.(string))
}
if v, found := p.p["projectid"]; found {
u.Set("projectid", v.(string))
}
@@ -2246,6 +2252,9 @@ func (p *ListVirtualMachinesParams) toURLValues() url.Values {
if v, found := p.p["storageid"]; found {
u.Set("storageid", v.(string))
}
if v, found := p.p["storageid"]; found {
u.Set("storageid", v.(string))
}
if v, found := p.p["tags"]; found {
i := 0
for k, vv := range v.(map[string]string) {
@@ -2510,6 +2519,16 @@ func (s *VirtualMachineService) GetVirtualMachineID(name string) (string, error)
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)
}
@@ -944,12 +944,18 @@ func (p *ListVolumesParams) toURLValues() url.Values {
if v, found := p.p["podid"]; found {
u.Set("podid", v.(string))
}
if v, found := p.p["podid"]; found {
u.Set("podid", v.(string))
}
if v, found := p.p["projectid"]; found {
u.Set("projectid", v.(string))
}
if v, found := p.p["storageid"]; found {
u.Set("storageid", v.(string))
}
if v, found := p.p["storageid"]; found {
u.Set("storageid", v.(string))
}
if v, found := p.p["tags"]; found {
i := 0
for k, vv := range v.(map[string]string) {
@@ -1142,6 +1148,16 @@ func (s *VolumeService) GetVolumeID(name string) (string, error) {
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)
}
@@ -1738,6 +1738,16 @@ func (s *AccountService) GetProjectAccountID(keyword string, projectid string) (
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)
}
@@ -751,6 +751,16 @@ func (s *ISOService) GetIsoID(name string) (string, error) {
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)
}

0 comments on commit 9a3ffa2

Please sign in to comment.