Browse Source

Revert "Rackspace/Openstack - Add/enhance --*-net-* create switches."

This reverts commit 07cadc68a5.

Signed-off-by: Nathan LeClaire <nathan.leclaire@gmail.com>
Nathan LeClaire 3 years ago
parent
commit
1ffea5ceed
2 changed files with 52 additions and 65 deletions
  1. 16
    25
      drivers/openstack/client.go
  2. 36
    40
      drivers/openstack/openstack.go

+ 16
- 25
drivers/openstack/client.go View File

@@ -41,8 +41,7 @@ type Client interface {
41 41
 	GetPublicKey(keyPairName string) ([]byte, error)
42 42
 	CreateKeyPair(d *Driver, name string, publicKey string) error
43 43
 	DeleteKeyPair(d *Driver, name string) error
44
-	GetNetworkIDs(d *Driver) ([]string, error)
45
-	GetNetworkID(d *Driver, networkName string) (string, error)
44
+	GetNetworkID(d *Driver) (string, error)
46 45
 	GetFlavorID(d *Driver) (string, error)
47 46
 	GetImageID(d *Driver) (string, error)
48 47
 	AssignFloatingIP(d *Driver, floatingIP *FloatingIP) error
@@ -67,12 +66,12 @@ func (c *GenericClient) CreateInstance(d *Driver) (string, error) {
67 66
 		SecurityGroups:   d.SecurityGroups,
68 67
 		AvailabilityZone: d.AvailabilityZone,
69 68
 	}
70
-	if len(d.NetworkIds) > 0 {
71
-		networks := make([]servers.Network, len(d.NetworkIds))
72
-		for i, networkId := range d.NetworkIds {
73
-			networks[i] = servers.Network{UUID: networkId}
69
+	if d.NetworkId != "" {
70
+		serverOpts.Networks = []servers.Network{
71
+			{
72
+				UUID: d.NetworkId,
73
+			},
74 74
 		}
75
-		serverOpts.Networks = networks
76 75
 	}
77 76
 
78 77
 	log.Info("Creating machine...")
@@ -200,23 +199,15 @@ func (c *GenericClient) GetInstanceIPAddresses(d *Driver) ([]IPAddress, error) {
200 199
 	return addresses, nil
201 200
 }
202 201
 
203
-func (c *GenericClient) GetNetworkIDs(d *Driver) ([]string, error) {
204
-	networkIDs := make([]string, len(d.NetworkNames))
205
-	for i, networkName := range d.NetworkNames {
206
-		id, err := c.GetNetworkID(d, networkName)
207
-		if err != nil {
208
-			return nil, err
209
-		}
210
-		networkIDs[i] = id
211
-	}
212
-	return networkIDs, nil
202
+func (c *GenericClient) GetNetworkID(d *Driver) (string, error) {
203
+	return c.getNetworkID(d, d.NetworkName)
213 204
 }
214 205
 
215 206
 func (c *GenericClient) GetFloatingIPPoolID(d *Driver) (string, error) {
216
-	return c.GetNetworkID(d, d.FloatingIPPool)
207
+	return c.getNetworkID(d, d.FloatingIpPool)
217 208
 }
218 209
 
219
-func (c *GenericClient) GetNetworkID(d *Driver, networkName string) (string, error) {
210
+func (c *GenericClient) getNetworkID(d *Driver, networkName string) (string, error) {
220 211
 	opts := networks.ListOpts{Name: networkName}
221 212
 	pager := networks.List(c.Network, opts)
222 213
 	networkID := ""
@@ -354,7 +345,7 @@ func (c *GenericClient) AssignFloatingIP(d *Driver, floatingIP *FloatingIP) erro
354 345
 func (c *GenericClient) assignNovaFloatingIP(d *Driver, floatingIP *FloatingIP) error {
355 346
 	if floatingIP.Ip == "" {
356 347
 		f, err := compute_ips.Create(c.Compute, compute_ips.CreateOpts{
357
-			Pool: d.FloatingIPPool,
348
+			Pool: d.FloatingIpPool,
358 349
 		}).Extract()
359 350
 		if err != nil {
360 351
 			return err
@@ -372,7 +363,7 @@ func (c *GenericClient) assignNeutronFloatingIP(d *Driver, floatingIP *FloatingI
372 363
 	}
373 364
 	if floatingIP.Id == "" {
374 365
 		f, err := floatingips.Create(c.Network, floatingips.CreateOpts{
375
-			FloatingNetworkID: d.FloatingIPPoolId,
366
+			FloatingNetworkID: d.FloatingIpPoolId,
376 367
 			PortID:            portID,
377 368
 		}).Extract()
378 369
 		if err != nil {
@@ -409,7 +400,7 @@ func (c *GenericClient) getNovaNetworkFloatingIPs(d *Driver) ([]FloatingIP, erro
409 400
 		ipListing, err := compute_ips.ExtractFloatingIPs(page)
410 401
 
411 402
 		for _, ip := range ipListing {
412
-			if ip.InstanceID == "" && ip.Pool == d.FloatingIPPool {
403
+			if ip.InstanceID == "" && ip.Pool == d.FloatingIpPool {
413 404
 				ips = append(ips, FloatingIP{
414 405
 					Id:   ip.ID,
415 406
 					Ip:   ip.IP,
@@ -424,11 +415,11 @@ func (c *GenericClient) getNovaNetworkFloatingIPs(d *Driver) ([]FloatingIP, erro
424 415
 
425 416
 func (c *GenericClient) getNeutronNetworkFloatingIPs(d *Driver) ([]FloatingIP, error) {
426 417
 	log.Debug("Listing floating IPs", map[string]string{
427
-		"FloatingNetworkId": d.FloatingIPPoolId,
418
+		"FloatingNetworkId": d.FloatingIpPoolId,
428 419
 		"TenantID":          d.TenantId,
429 420
 	})
430 421
 	pager := floatingips.List(c.Network, floatingips.ListOpts{
431
-		FloatingNetworkID: d.FloatingIPPoolId,
422
+		FloatingNetworkID: d.FloatingIpPoolId,
432 423
 		TenantID:          d.TenantId,
433 424
 	})
434 425
 
@@ -458,7 +449,7 @@ func (c *GenericClient) getNeutronNetworkFloatingIPs(d *Driver) ([]FloatingIP, e
458 449
 func (c *GenericClient) GetInstancePortID(d *Driver) (string, error) {
459 450
 	pager := ports.List(c.Network, ports.ListOpts{
460 451
 		DeviceID:  d.MachineId,
461
-		NetworkID: d.NetworkIds[0],
452
+		NetworkID: d.NetworkId,
462 453
 	})
463 454
 
464 455
 	var portID string

+ 36
- 40
drivers/openstack/openstack.go View File

@@ -35,13 +35,13 @@ type Driver struct {
35 35
 	ImageName        string
36 36
 	ImageId          string
37 37
 	KeyPairName      string
38
-	NetworkNames     []string
39
-	NetworkIds       []string
38
+	NetworkName      string
39
+	NetworkId        string
40 40
 	PrivateKeyFile   string
41 41
 	SecurityGroups   []string
42
-	FloatingIPPool   string
42
+	FloatingIpPool   string
43 43
 	ComputeNetwork   bool
44
-	FloatingIPPoolId string
44
+	FloatingIpPoolId string
45 45
 	IpVersion        int
46 46
 	client           Client
47 47
 }
@@ -150,21 +150,21 @@ func (d *Driver) GetCreateFlags() []mcnflag.Flag {
150 150
 			Value:  "",
151 151
 		},
152 152
 		mcnflag.StringFlag{
153
-			EnvVar: "OS_PRIVATE_KEY_FILE",
154
-			Name:   "openstack-private-key-file",
155
-			Usage:  "Private keyfile to use for SSH (absolute path)",
153
+			EnvVar: "OS_NETWORK_ID",
154
+			Name:   "openstack-net-id",
155
+			Usage:  "OpenStack network id the machine will be connected on",
156 156
 			Value:  "",
157 157
 		},
158 158
 		mcnflag.StringFlag{
159
-			EnvVar: "OS_NETWORK_ID",
160
-			Name:   "openstack-net-id",
161
-			Usage:  "OpenStack comma separated networks id the machine will be connected on",
159
+			EnvVar: "OS_PRIVATE_KEY_FILE",
160
+			Name:   "openstack-private-key-file",
161
+			Usage:  "Private keyfile to use for SSH (absolute path)",
162 162
 			Value:  "",
163 163
 		},
164 164
 		mcnflag.StringFlag{
165 165
 			EnvVar: "OS_NETWORK_NAME",
166 166
 			Name:   "openstack-net-name",
167
-			Usage:  "OpenStack comma separated network names the machine will be connected on",
167
+			Usage:  "OpenStack network name the machine will be connected on",
168 168
 			Value:  "",
169 169
 		},
170 170
 		mcnflag.StringFlag{
@@ -181,7 +181,7 @@ func (d *Driver) GetCreateFlags() []mcnflag.Flag {
181 181
 		mcnflag.StringFlag{
182 182
 			EnvVar: "OS_FLOATINGIP_POOL",
183 183
 			Name:   "openstack-floatingip-pool",
184
-			Usage:  "OpenStack floating IP pool to get an IP from to assign to the instance (first network only)",
184
+			Usage:  "OpenStack floating IP pool to get an IP from to assign to the instance",
185 185
 			Value:  "",
186 186
 		},
187 187
 		mcnflag.IntFlag{
@@ -258,16 +258,12 @@ func (d *Driver) SetConfigFromFlags(flags drivers.DriverOptions) error {
258 258
 	d.FlavorName = flags.String("openstack-flavor-name")
259 259
 	d.ImageId = flags.String("openstack-image-id")
260 260
 	d.ImageName = flags.String("openstack-image-name")
261
-	if flags.String("openstack-net-id") != "" {
262
-		d.NetworkIds = strings.Split(flags.String("openstack-net-id"), ",")
263
-	}
264
-	if flags.String("openstack-net-name") != "" {
265
-		d.NetworkNames = strings.Split(flags.String("openstack-net-name"), ",")
266
-	}
261
+	d.NetworkId = flags.String("openstack-net-id")
262
+	d.NetworkName = flags.String("openstack-net-name")
267 263
 	if flags.String("openstack-sec-groups") != "" {
268 264
 		d.SecurityGroups = strings.Split(flags.String("openstack-sec-groups"), ",")
269 265
 	}
270
-	d.FloatingIPPool = flags.String("openstack-floatingip-pool")
266
+	d.FloatingIpPool = flags.String("openstack-floatingip-pool")
271 267
 	d.IpVersion = flags.Int("openstack-ip-version")
272 268
 	d.ComputeNetwork = flags.Bool("openstack-nova-network")
273 269
 	d.SSHUser = flags.String("openstack-ssh-user")
@@ -307,7 +303,7 @@ func (d *Driver) GetIP() (string, error) {
307 303
 	}
308 304
 
309 305
 	addressType := Fixed
310
-	if d.FloatingIPPool != "" {
306
+	if d.FloatingIpPool != "" {
311 307
 		addressType = Floating
312 308
 	}
313 309
 
@@ -380,7 +376,7 @@ func (d *Driver) Create() error {
380 376
 	if err := d.waitForInstanceActive(); err != nil {
381 377
 		return err
382 378
 	}
383
-	if d.FloatingIPPool != "" {
379
+	if d.FloatingIpPool != "" {
384 380
 		if err := d.assignFloatingIP(); err != nil {
385 381
 			return err
386 382
 		}
@@ -477,8 +473,8 @@ func (d *Driver) checkConfig() error {
477 473
 		return fmt.Errorf(errorExclusiveOptions, "Image name", "Image id")
478 474
 	}
479 475
 
480
-	if len(d.NetworkNames) > 0 && len(d.NetworkIds) > 0 {
481
-		return fmt.Errorf(errorExclusiveOptions, "Network names", "Network ids")
476
+	if d.NetworkName != "" && d.NetworkId != "" {
477
+		return fmt.Errorf(errorExclusiveOptions, "Network name", "Network id")
482 478
 	}
483 479
 	if d.EndpointType != "" && (d.EndpointType != "publicURL" && d.EndpointType != "adminURL" && d.EndpointType != "internalURL") {
484 480
 		return fmt.Errorf(errorWrongEndpointType)
@@ -490,26 +486,26 @@ func (d *Driver) checkConfig() error {
490 486
 }
491 487
 
492 488
 func (d *Driver) resolveIds() error {
493
-	if len(d.NetworkNames) > 0 && !d.ComputeNetwork {
489
+	if d.NetworkName != "" && !d.ComputeNetwork {
494 490
 		if err := d.initNetwork(); err != nil {
495 491
 			return err
496 492
 		}
497
-		networkIds, err := d.client.GetNetworkIDs(d)
493
+
494
+		networkID, err := d.client.GetNetworkID(d)
495
+
498 496
 		if err != nil {
499 497
 			return err
500 498
 		}
501 499
 
502
-		if len(networkIds) == 0 {
503
-			return fmt.Errorf(errorUnknownNetworkName, strings.Join(d.NetworkNames, ",")) // TODO specific name
500
+		if networkID == "" {
501
+			return fmt.Errorf(errorUnknownNetworkName, d.NetworkName)
504 502
 		}
505 503
 
506
-		d.NetworkIds = networkIds
507
-		for i, networkName := range d.NetworkNames {
508
-			log.Debug("Found network id using its name", map[string]string{
509
-				"Name": networkName,
510
-				"ID":   d.NetworkIds[i],
511
-			})
512
-		}
504
+		d.NetworkId = networkID
505
+		log.Debug("Found network id using its name", map[string]string{
506
+			"Name": d.NetworkName,
507
+			"ID":   d.NetworkId,
508
+		})
513 509
 	}
514 510
 
515 511
 	if d.FlavorName != "" {
@@ -554,7 +550,7 @@ func (d *Driver) resolveIds() error {
554 550
 		})
555 551
 	}
556 552
 
557
-	if d.FloatingIPPool != "" && !d.ComputeNetwork {
553
+	if d.FloatingIpPool != "" && !d.ComputeNetwork {
558 554
 		if err := d.initNetwork(); err != nil {
559 555
 			return err
560 556
 		}
@@ -565,13 +561,13 @@ func (d *Driver) resolveIds() error {
565 561
 		}
566 562
 
567 563
 		if f == "" {
568
-			return fmt.Errorf(errorUnknownNetworkName, d.FloatingIPPool)
564
+			return fmt.Errorf(errorUnknownNetworkName, d.FloatingIpPool)
569 565
 		}
570 566
 
571
-		d.FloatingIPPoolId = f
567
+		d.FloatingIpPoolId = f
572 568
 		log.Debug("Found floating IP pool id using its name", map[string]string{
573
-			"Name": d.FloatingIPPool,
574
-			"ID":   d.FloatingIPPoolId,
569
+			"Name": d.FloatingIpPool,
570
+			"ID":   d.FloatingIpPoolId,
575 571
 		})
576 572
 	}
577 573
 
@@ -712,7 +708,7 @@ func (d *Driver) assignFloatingIP() error {
712 708
 
713 709
 	log.Debugf("Looking for an available floating IP", map[string]string{
714 710
 		"MachineId": d.MachineId,
715
-		"Pool":      d.FloatingIPPool,
711
+		"Pool":      d.FloatingIpPool,
716 712
 	})
717 713
 
718 714
 	for _, ip := range ips {

Loading…
Cancel
Save