github.com/niedbalski/juju@v0.0.0-20190215020005-8ff100488e47/provider/gce/google/export_test.go (about)

     1  // Copyright 2014 Canonical Ltd.
     2  // Licensed under the AGPLv3, see LICENCE file for details.
     3  
     4  package google
     5  
     6  import (
     7  	"github.com/juju/collections/set"
     8  	"google.golang.org/api/compute/v1"
     9  )
    10  
    11  var (
    12  	NewRawConnection = &newRawConnection
    13  
    14  	NewInstanceRaw      = newInstance
    15  	PackMetadata        = packMetadata
    16  	UnpackMetadata      = unpackMetadata
    17  	FormatMachineType   = formatMachineType
    18  	FirewallSpec        = firewallSpec
    19  	ExtractAddresses    = extractAddresses
    20  	NewRuleSetFromRules = newRuleSetFromRules
    21  )
    22  
    23  func SetRawConn(conn *Connection, raw rawConnectionWrapper) {
    24  	conn.raw = raw
    25  }
    26  
    27  func ExposeRawService(conn *Connection) *compute.Service {
    28  	return conn.raw.(*rawConn).Service
    29  }
    30  
    31  func NewAttached(spec DiskSpec) *compute.AttachedDisk {
    32  	return spec.newAttached()
    33  }
    34  
    35  func NewDetached(spec DiskSpec) (*compute.Disk, error) {
    36  	return spec.newDetached()
    37  }
    38  
    39  func NewAvailabilityZone(zone *compute.Zone) AvailabilityZone {
    40  	return AvailabilityZone{zone: zone}
    41  }
    42  
    43  func GetInstanceSpec(inst *Instance) *InstanceSpec {
    44  	return inst.spec
    45  }
    46  
    47  // TODO(ericsnow) Elimiinate this.
    48  func SetInstanceSpec(inst *Instance, spec *InstanceSpec) {
    49  	inst.spec = spec
    50  }
    51  
    52  func NewNetInterface(spec NetworkSpec, name string) *compute.NetworkInterface {
    53  	return spec.newInterface(name)
    54  }
    55  
    56  func ConnAddInstance(conn *Connection, inst *compute.Instance, mtype string, zone string) error {
    57  	return conn.addInstance(inst, mtype, zone)
    58  }
    59  
    60  func ConnRemoveInstance(conn *Connection, id, zone string) error {
    61  	return conn.removeInstance(id, zone)
    62  }
    63  
    64  func HashSuffixNamer(fw *firewall, prefix string, _ set.Strings) (string, error) {
    65  	if len(fw.SourceCIDRs) == 0 || len(fw.SourceCIDRs) == 1 && fw.SourceCIDRs[0] == "0.0.0.0/0" {
    66  		return prefix, nil
    67  	}
    68  	return prefix + "-" + sourcecidrs(fw.SourceCIDRs).key(), nil
    69  }