github.com/niedbalski/juju@v0.0.0-20190215020005-8ff100488e47/provider/rackspace/provider_configurator.go (about) 1 // Copyright 2015 Canonical Ltd. 2 // Licensed under the AGPLv3, see LICENCE file for details. 3 4 package rackspace 5 6 import ( 7 "github.com/juju/errors" 8 jujuos "github.com/juju/os" 9 jujuseries "github.com/juju/os/series" 10 "github.com/juju/schema" 11 "gopkg.in/goose.v2/nova" 12 13 "github.com/juju/juju/cloudconfig/cloudinit" 14 "github.com/juju/juju/environs" 15 ) 16 17 type rackspaceConfigurator struct { 18 } 19 20 // ModifyRunServerOptions implements ProviderConfigurator interface. 21 func (c *rackspaceConfigurator) ModifyRunServerOptions(options *nova.RunServerOpts) { 22 // More on how ConfigDrive option is used on rackspace: 23 // http://docs.rackspace.com/servers/api/v2/cs-devguide/content/config_drive_ext.html 24 options.ConfigDrive = true 25 } 26 27 // GetCloudConfig implements ProviderConfigurator interface. 28 func (c *rackspaceConfigurator) GetCloudConfig(args environs.StartInstanceParams) (cloudinit.CloudConfig, error) { 29 series := args.Tools.OneSeries() 30 cloudcfg, err := cloudinit.New(series) 31 if err != nil { 32 return nil, errors.Trace(err) 33 } 34 // Additional package required for sshInstanceConfigurator, to save 35 // iptables state between restarts. 36 cloudcfg.AddPackage("iptables-persistent") 37 38 if args.InstanceConfig.EnableOSRefreshUpdate { 39 // cloud-init often fails to update APT caches 40 // during instance startup on RackSpace. Add an 41 // extra call to "apt-get update" with a sleep 42 // on failure to attempt to alleviate this. 43 // See lp:1677425. 44 os, err := jujuseries.GetOSFromSeries(series) 45 if err == nil && os == jujuos.Ubuntu { 46 cloudcfg.AddBootCmd("apt-get update || (sleep 30s; apt-get update)") 47 } 48 } 49 50 return cloudcfg, nil 51 } 52 53 // GetConfigDefaults implements ProviderConfigurator interface. 54 func (c *rackspaceConfigurator) GetConfigDefaults() schema.Defaults { 55 return schema.Defaults{ 56 "use-floating-ip": false, 57 "use-default-secgroup": false, 58 "network": "", 59 "external-network": "", 60 "use-openstack-gbp": false, 61 "policy-target-group": "", 62 } 63 }