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

Side by Side Diff: provider/openstack/provider.go

Issue 97400043: Change StopInstances to take []instance.Id
Patch Set: Change StopInstances to take []instance.Id Created 9 years, 10 months ago
Left:
Right:
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 unified diff | Download patch
« no previous file with comments | « provider/openstack/local_test.go ('k') | state/apiserver/client/destroy.go » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2012, 2013 Canonical Ltd. 1 // Copyright 2012, 2013 Canonical Ltd.
2 // Licensed under the AGPLv3, see LICENCE file for details. 2 // Licensed under the AGPLv3, see LICENCE file for details.
3 3
4 // Stub provider for OpenStack, using goose will be implemented here 4 // Stub provider for OpenStack, using goose will be implemented here
5 5
6 package openstack 6 package openstack
7 7
8 import ( 8 import (
9 "errors"
10 "fmt" 9 "fmt"
11 "io/ioutil" 10 "io/ioutil"
12 "net/http" 11 "net/http"
13 "regexp" 12 "regexp"
14 "strings" 13 "strings"
15 "sync" 14 "sync"
16 "time" 15 "time"
17 16
18 "github.com/juju/loggo" 17 "github.com/juju/loggo"
19 "launchpad.net/goose/client" 18 "launchpad.net/goose/client"
(...skipping 875 matching lines...) Expand 10 before | Expand all | Expand 10 after
895 // ignore the failure at this stage, just log it 894 // ignore the failure at this stage, just log it
896 logger.Debugf("failed to terminate instance %q: %v", inst.Id(), err) 895 logger.Debugf("failed to terminate instance %q: %v", inst.Id(), err)
897 } 896 }
898 return nil, nil, nil, fmt.Errorf("cannot assign public a ddress %s to instance %q: %v", publicIP.IP, inst.Id(), err) 897 return nil, nil, nil, fmt.Errorf("cannot assign public a ddress %s to instance %q: %v", publicIP.IP, inst.Id(), err)
899 } 898 }
900 logger.Infof("assigned public IP %s to %q", publicIP.IP, inst.Id ()) 899 logger.Infof("assigned public IP %s to %q", publicIP.IP, inst.Id ())
901 } 900 }
902 return inst, inst.hardwareCharacteristics(), nil, nil 901 return inst, inst.hardwareCharacteristics(), nil, nil
903 } 902 }
904 903
905 func (e *environ) StopInstances(insts []instance.Instance) error { 904 func (e *environ) StopInstances(ids ...instance.Id) error {
906 » ids := make([]instance.Id, len(insts)) 905 » // If in instance firewall mode, gather the security group names.
907 » securityGroupNames := make([]string, len(insts)) 906 » var securityGroupNames []string
908 » for i, inst := range insts { 907 » if e.Config().FirewallMode() == config.FwInstance {
909 » » instanceValue, ok := inst.(*openstackInstance) 908 » » instances, err := e.Instances(ids)
910 » » if !ok { 909 » » if err == environs.ErrNoInstances {
911 » » » return errors.New("Incompatible instance.Instance suppli ed") 910 » » » return nil
912 } 911 }
913 » » ids[i] = instanceValue.Id() 912 » » securityGroupNames = make([]string, 0, len(ids))
914 » » openstackName := instanceValue.getServerDetail().Name 913 » » for _, inst := range instances {
915 » » lastDashPos := strings.LastIndex(openstackName, "-") 914 » » » if inst == nil {
916 » » if lastDashPos == -1 { 915 » » » » continue
917 » » » return fmt.Errorf("cannot identify instance ID in openst ack server name %q", openstackName) 916 » » » }
917 » » » openstackName := inst.(*openstackInstance).getServerDeta il().Name
918 » » » lastDashPos := strings.LastIndex(openstackName, "-")
919 » » » if lastDashPos == -1 {
920 » » » » return fmt.Errorf("cannot identify machine ID in openstack server name %q", openstackName)
921 » » » }
922 » » » securityGroupName := e.machineGroupName(openstackName[la stDashPos+1:])
923 » » » securityGroupNames = append(securityGroupNames, security GroupName)
918 } 924 }
919 securityGroupNames[i] = e.machineGroupName(openstackName[lastDas hPos+1:])
920 } 925 }
921 logger.Debugf("terminating instances %v", ids) 926 logger.Debugf("terminating instances %v", ids)
922 » err := e.terminateInstances(ids) 927 » if err := e.terminateInstances(ids); err != nil {
923 » if err != nil {
924 return err 928 return err
925 } 929 }
926 » if e.Config().FirewallMode() == config.FwInstance { 930 » if securityGroupNames != nil {
927 return e.deleteSecurityGroups(securityGroupNames) 931 return e.deleteSecurityGroups(securityGroupNames)
928 } 932 }
929 return nil 933 return nil
930 } 934 }
931 935
932 // collectInstances tries to get information on each instance id in ids. 936 // collectInstances tries to get information on each instance id in ids.
933 // It fills the slots in the given map for known servers with status 937 // It fills the slots in the given map for known servers with status
934 // either ACTIVE or BUILD. Returns a list of missing ids. 938 // either ACTIVE or BUILD. Returns a list of missing ids.
935 func (e *environ) collectInstances(ids []instance.Id, out map[instance.Id]instan ce.Instance) []instance.Id { 939 func (e *environ) collectInstances(ids []instance.Id, out map[instance.Id]instan ce.Instance) []instance.Id {
936 var err error 940 var err error
(...skipping 429 matching lines...) Expand 10 before | Expand all | Expand 10 after
1366 func (e *environ) Region() (simplestreams.CloudSpec, error) { 1370 func (e *environ) Region() (simplestreams.CloudSpec, error) {
1367 return e.cloudSpec(e.ecfg().region()) 1371 return e.cloudSpec(e.ecfg().region())
1368 } 1372 }
1369 1373
1370 func (e *environ) cloudSpec(region string) (simplestreams.CloudSpec, error) { 1374 func (e *environ) cloudSpec(region string) (simplestreams.CloudSpec, error) {
1371 return simplestreams.CloudSpec{ 1375 return simplestreams.CloudSpec{
1372 Region: region, 1376 Region: region,
1373 Endpoint: e.ecfg().authURL(), 1377 Endpoint: e.ecfg().authURL(),
1374 }, nil 1378 }, nil
1375 } 1379 }
OLDNEW
« no previous file with comments | « provider/openstack/local_test.go ('k') | state/apiserver/client/destroy.go » ('j') | no next file with comments »

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