Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(138)

Unified Diff: environs/openstack/provider.go

Issue 11655043: Fix ensureGroup bug in Openstack provider (Closed)
Patch Set: Created 11 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
View side-by-side diff with in-line comments
Download patch
« environs/openstack/local_test.go ('K') | « environs/openstack/local_test.go ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: environs/openstack/provider.go
=== modified file 'environs/openstack/provider.go'
--- environs/openstack/provider.go 2013-07-19 18:26:41 +0000
+++ environs/openstack/provider.go 2013-07-22 00:37:41 +0000
@@ -1029,7 +1029,14 @@
// If it exists, its permissions are set to perms.
func (e *environ) ensureGroup(name string, rules []nova.RuleInfo) (nova.SecurityGroup, error) {
novaClient := e.nova()
- group, err := novaClient.CreateSecurityGroup(name, "juju group")
+ // First attempt to lookup an existing group by name.
rog 2013/07/22 12:48:46 s/lookup/look up/
wallyworld 2013/07/23 01:55:31 Done.
+ group, err := novaClient.SecurityGroupByName(name)
+ if err == nil {
+ // Group exists, so assume it is correctly set up and return it.
+ return *group, nil
+ }
+ // Doesn't exist, so try and create it.
+ group, err = novaClient.CreateSecurityGroup(name, "juju group")
if err != nil {
if !gooseerrors.IsDuplicateValue(err) {
return zeroGroup, err
@@ -1039,15 +1046,18 @@
if err != nil {
return zeroGroup, err
}
+ return *group, nil
}
}
- // The group is created so now add the rules.
- for _, rule := range rules {
+ // The new group is created so now add the rules.
+ group.Rules = make([]nova.SecurityGroupRule, len(rules))
+ for i, rule := range rules {
rule.ParentGroupId = group.Id
- _, err := novaClient.CreateSecurityGroupRule(rule)
+ groupRule, err := novaClient.CreateSecurityGroupRule(rule)
if err != nil && !gooseerrors.IsDuplicateValue(err) {
return zeroGroup, err
}
+ group.Rules[i] = *groupRule
}
return *group, nil
}
« environs/openstack/local_test.go ('K') | « environs/openstack/local_test.go ('k') | no next file » | no next file with comments »

Powered by Google App Engine
RSS Feeds Recent Issues | This issue
This is Rietveld f62528b