github.com/niedbalski/juju@v0.0.0-20190215020005-8ff100488e47/provider/oracle/networking.go (about)

     1  // Copyright 2017 Canonical Ltd.
     2  // Licensed under the AGPLv3, see LICENCE file for details.
     3  
     4  package oracle
     5  
     6  import (
     7  	"github.com/juju/errors"
     8  	oci "github.com/juju/go-oracle-cloud/api"
     9  	ociResponse "github.com/juju/go-oracle-cloud/response"
    10  
    11  	"github.com/juju/juju/environs"
    12  	"github.com/juju/juju/environs/context"
    13  )
    14  
    15  var _ environs.NetworkingEnviron = (*OracleEnviron)(nil)
    16  
    17  // Only Ubuntu for now. There is no CentOS image in the oracle
    18  // compute marketplace
    19  var ubuntuInterfaceTemplate = `
    20  auto %s
    21  iface %s inet dhcp
    22  `
    23  
    24  const (
    25  	// defaultNicName is the default network card name attached by default
    26  	// to every instance. This NIC is used for outbound internet access
    27  	defaultNicName = "eth0"
    28  	// nicPrefix si the default NIC prefix name for any extra NICs attached
    29  	// to instances spawned by juju
    30  	nicPrefix = "eth"
    31  	// interfacesConfigDir default path of interfaces.d directory on Ubuntu machines
    32  	// currently CentOS is not available in the oracle market, and windows needs
    33  	// no extra configuration to bring up additional NICs
    34  	interfacesConfigDir = `/etc/network/interfaces.d`
    35  )
    36  
    37  // DeleteMachineVnicSet will delete the machine vNIC set and any ACLs bound to it.
    38  func (o *OracleEnviron) DeleteMachineVnicSet(machineId string) error {
    39  	if err := o.RemoveACLAndRules(machineId); err != nil {
    40  		// A method not allowed error denotes that this feature
    41  		// is not enabled. Probably a trial account, so not really an error
    42  		if !oci.IsMethodNotAllowed(err) {
    43  			return errors.Trace(err)
    44  		}
    45  	}
    46  	name := o.client.ComposeName(o.namespace.Value(machineId))
    47  	if err := o.client.DeleteVnicSet(name); err != nil {
    48  		if !oci.IsNotFound(err) && !oci.IsMethodNotAllowed(err) {
    49  			return err
    50  		}
    51  	}
    52  	return nil
    53  }
    54  
    55  func (o *OracleEnviron) ensureVnicSet(ctx context.ProviderCallContext, machineId string, tags []string) (ociResponse.VnicSet, error) {
    56  	if access, err := o.SupportsSpaces(ctx); err != nil || access == false {
    57  		logger.Debugf("Spaces is not supported on this API endpoint.")
    58  		return ociResponse.VnicSet{}, nil
    59  	}
    60  
    61  	acl, err := o.CreateDefaultACLAndRules(machineId)
    62  	if err != nil {
    63  		return ociResponse.VnicSet{}, errors.Trace(err)
    64  	}
    65  	name := o.client.ComposeName(o.namespace.Value(machineId))
    66  	details, err := o.client.VnicSetDetails(name)
    67  	if err != nil {
    68  		if !oci.IsNotFound(err) {
    69  			return ociResponse.VnicSet{}, errors.Trace(err)
    70  		}
    71  		logger.Debugf("Creating vnic set %q", name)
    72  		vnicSetParams := oci.VnicSetParams{
    73  			AppliedAcls: []string{
    74  				acl.Name,
    75  			},
    76  			Description: "Juju created vnic set",
    77  			Name:        name,
    78  			Tags:        tags,
    79  		}
    80  		details, err := o.client.CreateVnicSet(vnicSetParams)
    81  		if err != nil {
    82  			return ociResponse.VnicSet{}, errors.Trace(err)
    83  		}
    84  		return details, nil
    85  	}
    86  	return details, nil
    87  }