github.com/juju/juju@v0.0.0-20240430160146-1752b71fcf00/provider/openstack/provider_configurator.go (about)

     1  // Copyright 2015 Canonical Ltd.
     2  // Licensed under the AGPLv3, see LICENCE file for details.
     3  
     4  package openstack
     5  
     6  import (
     7  	"github.com/go-goose/goose/v5/nova"
     8  	"github.com/juju/errors"
     9  	"github.com/juju/schema"
    10  
    11  	"github.com/juju/juju/cloudconfig/cloudinit"
    12  	"github.com/juju/juju/environs"
    13  )
    14  
    15  // This interface is added to allow to customize OpenStack provider behaviour.
    16  // This is used in other providers, that embeds OpenStack provider.
    17  type ProviderConfigurator interface {
    18  	// GetConfigDefaults sets some configuration default values, if any
    19  	GetConfigDefaults() schema.Defaults
    20  
    21  	// This method allows to adjust default RunServerOptions,
    22  	// before new server is actually created.
    23  	ModifyRunServerOptions(options *nova.RunServerOpts)
    24  
    25  	// This method provides default cloud config.
    26  	// This config can be different for different providers.
    27  	GetCloudConfig(args environs.StartInstanceParams) (cloudinit.CloudConfig, error)
    28  }
    29  
    30  type defaultConfigurator struct{}
    31  
    32  // ModifyRunServerOptions implements ProviderConfigurator interface.
    33  func (c *defaultConfigurator) ModifyRunServerOptions(_ *nova.RunServerOpts) {
    34  }
    35  
    36  // GetCloudConfig implements ProviderConfigurator interface.
    37  func (c *defaultConfigurator) GetCloudConfig(args environs.StartInstanceParams) (cloudinit.CloudConfig, error) {
    38  	cloudCfg, err := cloudinit.New(args.InstanceConfig.Base.OS)
    39  	return cloudCfg, errors.Trace(err)
    40  }
    41  
    42  // GetConfigDefaults implements ProviderConfigurator interface.
    43  func (c *defaultConfigurator) GetConfigDefaults() schema.Defaults {
    44  	return schema.Defaults{
    45  		"use-default-secgroup": false,
    46  		"network":              "",
    47  		"external-network":     "",
    48  		"use-openstack-gbp":    false,
    49  		"policy-target-group":  "",
    50  	}
    51  }