// NewCloudRegionSpec returns a CloudRegionSpec ensuring cloud arg is not empty.
778905
func NewCloudRegionSpec(cloud, region string) (*CloudRegionSpec, error) {
	if cloud == "" {
		return nil, errors.New("cloud is required to be non empty")
	}
	return &CloudRegionSpec{Cloud: cloud, Region: region}, nil
}
1122146
func (os *OpenStack) NewLoadBalancerV2() (*gophercloud.ServiceClient, error) {
	var lb *gophercloud.ServiceClient
	var err error
	if os.lbOpts.UseOctavia {
		lb, err = openstack.NewLoadBalancerV2(os.provider, gophercloud.EndpointOpts{
			Region: os.region,
		})
	} else {
		lb, err = openstack.NewNetworkV2(os.provider, gophercloud.EndpointOpts{
			Region: os.region,
		})
	}
	if err != nil {
		return nil, fmt.Errorf("failed to find load-balancer v2 endpoint for region %s: %v", os.region, err)
	}
	return lb, nil
}
1124366
func (k *kubernetesClient) SetCloudSpec(spec environs.CloudSpec) error {
	k.lock.Lock()
	defer k.lock.Unlock()

	k8sRestConfig, err := cloudSpecToK8sRestConfig(spec)
	if err != nil {
		return errors.Annotate(err, "cannot set cloud spec")
	}

	k.clientUnlocked, k.apiextensionsClientUnlocked, err = k.newClient(k8sRestConfig)
	if err != nil {
		return errors.Annotate(err, "cannot set cloud spec")
	}
	return nil
}
1328783
func GetPluralSpec(tag string) *PluralSpec {
	tag = NormalizeTag(tag)
	subtag := tag
	for {
		if spec := pluralSpecs[subtag]; spec != nil {
			return spec
		}
		end := strings.LastIndex(subtag, "-")
		if end == -1 {
			return nil
		}
		subtag = subtag[:end]
	}
}
772245
func (m *MockFactory) NewCloud(arg0 installation.Installation, arg1 string, arg2 int) (cloud.Cloud, error) {
	ret := m.ctrl.Call(m, "NewCloud", arg0, arg1, arg2)
	ret0, _ := ret[0].(cloud.Cloud)
	ret1, _ := ret[1].(error)
	return ret0, ret1
}
1141268
func DefaultSpec() *ConnectionSpec {
	return &ConnectionSpec{
		DefaultRedisHost,
		DefaultRedisPort,
		DefaultRedisPassword,
		DefaultRedisDB,
		DefaultTCPReadBuffSize,
		DefaultTCPWriteBuffSize,
		DefaultTCPReadTimeoutNSecs,
		DefaultTCPWriteTimeoutNSecs,
		DefaultTCPKeepalive,
		DefaultTCPLinger,
		DefaultReqChanSize,
		DefaultRespChanSize,
		DefaultHeartbeatSecs,
		DefaultProtocol,
	}
}
927435
func newGRPCAPIService(n *centrifuge.Node, c GRPCAPIServiceConfig) *grpcAPIService {
	return &grpcAPIService{
		config: c,
		api:    newAPIExecutor(n, "grpc"),
	}
}
918516
func queryRegion(cloud string, regions []jujucloud.Region, scanner *bufio.Scanner, w io.Writer) (string, error) {
	fmt.Fprintf(w, "Regions in %s:\n", cloud)
	names := jujucloud.RegionNames(regions)
	// add an empty string to allow for a default value. Also gives us an extra
	// line return after the list of names.
	names = append(names, "")
	if _, err := fmt.Fprintln(w, strings.Join(names, "\n")); err != nil {
		return "", errors.Trace(err)
	}
	verify := interact.MatchOptions(names, "Invalid region.")
	defaultRegion := regions[0].Name
	query := fmt.Sprintf("Select a region in %s [%s]: ", cloud, defaultRegion)
	region, err := interact.QueryVerify(query, scanner, w, w, verify)
	if err != nil {
		return "", errors.Trace(err)
	}
	if region == "" {
		return defaultRegion, nil
	}
	regionName, ok := interact.FindMatch(region, names)
	if !ok {
		// should be impossible
		return "", errors.Errorf("invalid region name chosen: %s", region)
	}

	return regionName, nil
}
947569
func NewClusterConfig(spec ClusterConfigSpecV3) (ClusterConfig, error) {
	cc := ClusterConfigV3{
		Kind:    KindClusterConfig,
		Version: V3,
		Metadata: Metadata{
			Name:      MetaNameClusterConfig,
			Namespace: defaults.Namespace,
		},
		Spec: spec,
	}
	if err := cc.CheckAndSetDefaults(); err != nil {
		return nil, trace.Wrap(err)
	}

	return &cc, nil
}
1370175
func NewRegionCache(pdClient pd.Client) *RegionCache {
	c := &RegionCache{
		pdClient: pdClient,
	}
	c.mu.regions = make(map[RegionVerID]*CachedRegion)
	c.mu.sorted = btree.New(btreeDegree)
	c.storeMu.stores = make(map[uint64]*Store)
	return c
}
445492
func RegionCreate() *Region {
	ret := wrapRegion(C.cairo_region_create())
	if err := ret.status(); err != nil {
		panic(err)
	}
	return ret
}
923299
func (env *maasEnviron) SetCloudSpec(spec environs.CloudSpec) error {
	env.ecfgMutex.Lock()
	defer env.ecfgMutex.Unlock()

	maasServer, err := parseCloudEndpoint(spec.Endpoint)
	if err != nil {
		return errors.Trace(err)
	}
	maasOAuth, err := parseOAuthToken(*spec.Credential)
	if err != nil {
		return errors.Trace(err)
	}

	// We need to know the version of the server we're on. We support 1.9
	// and 2.0. MAAS 1.9 uses the 1.0 api version and 2.0 uses the 2.0 api
	// version.
	apiVersion := apiVersion2
	controller, err := GetMAAS2Controller(maasServer, maasOAuth)
	switch {
	case gomaasapi.IsUnsupportedVersionError(err):
		apiVersion = apiVersion1
		_, _, includesVersion := gomaasapi.SplitVersionedURL(maasServer)
		versionURL := maasServer
		if !includesVersion {
			versionURL = gomaasapi.AddAPIVersionToURL(maasServer, apiVersion1)
		}
		authClient, err := gomaasapi.NewAuthenticatedClient(versionURL, maasOAuth)
		if err != nil {
			return errors.Trace(err)
		}
		env.maasClientUnlocked = gomaasapi.NewMAAS(*authClient)
		caps, err := env.GetCapabilities(env.maasClientUnlocked, maasServer)
		if err != nil {
			return errors.Trace(err)
		}
		if !caps.Contains(capNetworkDeploymentUbuntu) {
			return errors.NewNotSupported(nil, "MAAS 1.9 or more recent is required")
		}
	case err != nil:
		return errors.Trace(err)
	default:
		env.maasController = controller
	}
	env.apiVersion = apiVersion
	env.storageUnlocked = NewStorage(env)

	return nil
}
1095500
func NewWithRegion(endpoint, accessKeyID, secretAccessKey string, secure bool, region string) (*Client, error) {
	creds := credentials.NewStaticV4(accessKeyID, secretAccessKey, "")
	return privateNew(endpoint, creds, secure, region, BucketLookupAuto)
}
474207
func NewMockCloud(ctrl *gomock.Controller) *MockCloud {
	mock := &MockCloud{ctrl: ctrl}
	mock.recorder = &MockCloudMockRecorder{mock}
	return mock
}
952225
func NewProjectionFromEventSpec(eventSpec types.EventSpec) (*Projection, error) {
	// builds abi information from specification
	tables := make(types.EventTables)

	// obtain global field mappings to add to table definitions
	globalFieldMappings := getGlobalFieldMappings()

	for _, eventClass := range eventSpec {
		// validate json structure
		if err := eventClass.Validate(); err != nil {
			return nil, fmt.Errorf("validation error on %v: %v", eventClass, err)
		}

		// build columns mapping
		var columns []*types.SQLTableColumn
		channels := make(map[string][]string)

		// Add the global mappings
		eventClass.FieldMappings = append(globalFieldMappings, eventClass.FieldMappings...)

		i := 0
		for _, mapping := range eventClass.FieldMappings {
			sqlType, sqlTypeLength, err := getSQLType(mapping.Type, mapping.BytesToString)
			if err != nil {
				return nil, err
			}

			i++

			// Update channels broadcast payload subsets with this column
			for _, channel := range mapping.Notify {
				channels[channel] = append(channels[channel], mapping.ColumnName)
			}

			columns = append(columns, &types.SQLTableColumn{
				Name:    mapping.ColumnName,
				Type:    sqlType,
				Primary: mapping.Primary,
				Length:  sqlTypeLength,
			})
		}

		// Allow for compatible composition of tables
		var err error
		tables[eventClass.TableName], err = mergeTables(tables[eventClass.TableName],
			&types.SQLTable{
				Name:           eventClass.TableName,
				NotifyChannels: channels,
				Columns:        columns,
			})
		if err != nil {
			return nil, err
		}

	}

	// check if there are duplicated duplicated column names (for a given table)
	colName := make(map[string]int)

	for _, table := range tables {
		for _, column := range table.Columns {
			colName[table.Name+column.Name]++
			if colName[table.Name+column.Name] > 1 {
				return nil, fmt.Errorf("duplicated column name: '%s' in table '%s'", column.Name, table.Name)
			}
		}
	}

	return &Projection{
		Tables:    tables,
		EventSpec: eventSpec,
	}, nil
}
772636
func NewCloudinary(ctx context.Context) context.Context {
	return cloudinary.NewContext(ctx, os.Getenv("CLOUDINARY_URL"))
}
762074
func newGCECloud(config io.Reader) (*Cloud, error) {
	projectID, zone, err := getProjectAndZone()
	if err != nil {
		return nil, err
	}

	region, err := GetGCERegion(zone)
	if err != nil {
		return nil, err
	}

	networkName, err := getNetworkNameViaMetadata()
	if err != nil {
		return nil, err
	}
	networkURL := gceNetworkURL(projectID, networkName)

	// By default, Kubernetes clusters only run against one zone
	managedZones := []string{zone}

	tokenSource := google.ComputeTokenSource("")
	var nodeTags []string
	var nodeInstancePrefix string
	if config != nil {
		var cfg Config
		if err := gcfg.ReadInto(&cfg, config); err != nil {
			glog.Errorf("Couldn't read config: %v", err)
			return nil, err
		}
		glog.Infof("Using GCE provider config %+v", cfg)
		if cfg.Global.ProjectID != "" {
			projectID = cfg.Global.ProjectID
		}
		if cfg.Global.NetworkName != "" {
			if strings.Contains(cfg.Global.NetworkName, "/") {
				networkURL = cfg.Global.NetworkName
			} else {
				networkURL = gceNetworkURL(cfg.Global.ProjectID, cfg.Global.NetworkName)
			}
		}
		if cfg.Global.TokenURL != "" {
			tokenSource = NewAltTokenSource(cfg.Global.TokenURL, cfg.Global.TokenBody)
		}
		nodeTags = cfg.Global.NodeTags
		nodeInstancePrefix = cfg.Global.NodeInstancePrefix
		if cfg.Global.Multizone {
			managedZones = nil // Use all zones in region
		}
	}

	return CreateGCECloud(projectID, region, zone, managedZones, networkURL, nodeTags, nodeInstancePrefix, tokenSource, true /* useMetadataServer */)
}