// NewClusterOperationInstance creates a new cluster operation instance with one initial task.
349627
func NewClusterOperationInstance(clusterOpID string, initialTask *automationpb.TaskContainer, taskIDGenerator *IDGenerator) ClusterOperationInstance {
	c := ClusterOperationInstance{
		automationpb.ClusterOperation{
			Id:          clusterOpID,
			SerialTasks: []*automationpb.TaskContainer{},
			State:       automationpb.ClusterOperationState_CLUSTER_OPERATION_NOT_STARTED,
		},
		taskIDGenerator,
	}
	c.InsertTaskContainers([]*automationpb.TaskContainer{initialTask}, 0)
	return c
}
931718
func newClusterPeer(srv *server, connInfo services.TunnelConnection) (*clusterPeer, error) {
	clusterPeer := &clusterPeer{
		srv:      srv,
		connInfo: connInfo,
		log: log.WithFields(log.Fields{
			trace.Component: teleport.ComponentReverseTunnelServer,
			trace.ComponentFields: map[string]string{
				"cluster": connInfo.GetClusterName(),
			},
		}),
	}

	return clusterPeer, nil
}
697135
func NewCluster() *clientv3.Client {
	t = &testing.T{}
	embeddedCluster = integration.NewClusterV3(t, &integration.ClusterConfig{Size: 1})
	return embeddedCluster.RandClient()
}
373508
func (f *clusterCacheFactoryImpl) NewClusterCache(ctx context.Context, options ...rest.HTTPClientOption) cluster.ClusterCache {
	return clusterservice.NewCache(f.config, options...)
}
549786
func NewGlusterfsProvisioner(config *rest.Config, client kubernetes.Interface) controller.Provisioner {
	klog.Infof("Creating NewGlusterfsProvisioner.")
	return newGlusterfsProvisionerInternal(config, client)
}
618121
func NewClusterService(name, namespace string) ClusterService {
	return ClusterService{
		Name:      name,
		Namespace: namespace,
		Frontends: map[string]PortConfiguration{},
		Backends:  map[string]PortConfiguration{},
		Labels:    map[string]string{},
		Selector:  map[string]string{},
	}
}
1033715
func (c *ClusterManager) initNodeInCluster(
	clusterInfo *cluster.ClusterInfo,
	self *api.Node,
	exist bool,
	nodeInitialized bool,
) ([]cluster.FinalizeInitCb, error) {
	// If I am already in the cluster map, don't add me again.
	if exist {
		return nil, nil
	}

	if nodeInitialized {
		logrus.Errorf(cluster.ErrInitNodeNotFound.Error())
		return nil, cluster.ErrInitNodeNotFound
	}

	// Alert all listeners that we are a new node and we are initializing.
	finalizeCbs := make([]cluster.FinalizeInitCb, 0)
	for e := c.listeners.Front(); e != nil; e = e.Next() {
		finalizeCb, err := e.Value.(cluster.ClusterListener).Init(self, clusterInfo)
		if err != nil {
			if self.Status != api.Status_STATUS_MAINTENANCE {
				self.Status = api.Status_STATUS_ERROR
			}
			logrus.Warnf("Failed to initialize Init %s: %v",
				e.Value.(cluster.ClusterListener).String(), err)
			c.cleanupInit(clusterInfo, self)
			return nil, err
		}
		if finalizeCb != nil {
			finalizeCbs = append(finalizeCbs, finalizeCb)
		}
	}

	return finalizeCbs, nil
}
824010
func NewClusterHealthService(client *Client) *ClusterHealthService {
	return &ClusterHealthService{
		client:  client,
		indices: make([]string, 0),
	}
}
688897
func NewClusterRoleInformer(client kubernetes.Interface, resyncPeriod time.Duration, indexers cache.Indexers) cache.SharedIndexInformer {
	return NewFilteredClusterRoleInformer(client, resyncPeriod, indexers, nil)
}
1345873
func (a *AuthWithRoles) SetClusterName(c services.ClusterName) error {
	if err := a.action(defaults.Namespace, services.KindClusterName, services.VerbCreate); err != nil {
		return trace.Wrap(err)
	}
	if err := a.action(defaults.Namespace, services.KindClusterName, services.VerbUpdate); err != nil {
		return trace.Wrap(err)
	}
	return a.authServer.SetClusterName(c)
}
326217
func (c *environClient) newInstance(
	args environs.StartInstanceParams,
	img *imagemetadata.ImageMetadata,
	userData []byte,
	authorizedKeys string,
) (srv gosigma.Server, drv gosigma.Drive, ar string, err error) {

	defer func() {
		if err == nil {
			return
		}
		if srv != nil {
			srv.Remove(gosigma.RecurseAllDrives)
		} else if drv != nil {
			drv.Remove()
		}
		srv = nil
		drv = nil
	}()

	if args.InstanceConfig == nil {
		err = errors.New("invalid configuration for new instance: InstanceConfig is nil")
		return nil, nil, "", err
	}

	logger.Debugf("Tools: %v", args.Tools.URLs())
	logger.Debugf("Juju Constraints:" + args.Constraints.String())
	logger.Debugf("InstanceConfig: %#v", args.InstanceConfig)

	constraints := newConstraints(args.InstanceConfig.Bootstrap != nil, args.Constraints, img)
	logger.Debugf("CloudSigma Constraints: %v", constraints)

	originalDrive, err := c.conn.Drive(constraints.driveTemplate, gosigma.LibraryMedia)
	if err != nil {
		err = errors.Annotatef(err, "Failed to query drive template")
		return nil, nil, "", err
	}

	baseName := "juju-" + c.uuid + "-" + args.InstanceConfig.MachineId

	cloneParams := gosigma.CloneParams{Name: baseName}
	if drv, err = originalDrive.CloneWait(cloneParams, nil); err != nil {
		err = errors.Errorf("error cloning drive: %v", err)
		return nil, nil, "", err
	}

	if drv.Size() < constraints.driveSize {
		if err = drv.ResizeWait(constraints.driveSize); err != nil {
			err = errors.Errorf("error resizing drive: %v", err)
			return nil, nil, "", err
		}
	}

	cc, err := c.generateSigmaComponents(
		baseName, constraints, args, drv, userData, authorizedKeys,
	)
	if err != nil {
		return nil, nil, "", errors.Trace(err)
	}

	if srv, err = c.conn.CreateServer(cc); err != nil {
		err = errors.Annotatef(err, "error creating new instance")
		return nil, nil, "", err
	}

	if err = srv.Start(); err != nil {
		err = errors.Annotatef(err, "error booting new instance")
		return nil, nil, "", err
	}

	// populate root drive hardware characteristics
	switch originalDrive.Arch() {
	case "64":
		ar = arch.AMD64
	case "32":
		ar = arch.I386
	default:
		err = errors.Errorf("unknown arch: %v", ar)
		return nil, nil, "", err
	}

	return srv, drv, ar, nil
}
888248
func NewClusterAdmin(addrs []string, conf *Config) (ClusterAdmin, error) {
	client, err := NewClient(addrs, conf)
	if err != nil {
		return nil, err
	}

	//make sure we can retrieve the controller
	_, err = client.Controller()
	if err != nil {
		return nil, err
	}

	ca := &clusterAdmin{
		client: client,
		conf:   client.Config(),
	}
	return ca, nil
}
325156
func NewAuthClusterClient(host, version string, authstring string, accesstoken string) (*client.Client, error) {
	if host == "" {
		host = client.GetUnixServerPath(OsdSocket, cluster.APIBase)
	}

	if version == "" {
		// Set the default version
		version = cluster.APIVersion
	}

	return client.NewAuthClient(host, version, authstring, accesstoken, "")
}
1344702
func newCluster(client *httpClient, marathonURL string, isDCOS bool) (*cluster, error) {
	// step: extract and basic validate the endpoints
	var members []*member
	var defaultProto string

	for _, endpoint := range strings.Split(marathonURL, ",") {
		// step: check for nothing
		if endpoint == "" {
			return nil, newInvalidEndpointError("endpoint is blank")
		}
		// step: prepend scheme if missing on (non-initial) endpoint.
		if !strings.HasPrefix(endpoint, "http://") && !strings.HasPrefix(endpoint, "https://") {
			if defaultProto == "" {
				return nil, newInvalidEndpointError("missing scheme on (first) endpoint")
			}

			endpoint = fmt.Sprintf("%s://%s", defaultProto, endpoint)
		}
		// step: parse the url
		u, err := url.Parse(endpoint)
		if err != nil {
			return nil, newInvalidEndpointError("invalid endpoint '%s': %s", endpoint, err)
		}
		if defaultProto == "" {
			defaultProto = u.Scheme
		}

		// step: check for empty hosts
		if u.Host == "" {
			return nil, newInvalidEndpointError("endpoint: %s must have a host", endpoint)
		}

		// step: if DCOS is set and no path is given, set the default DCOS path.
		// done in order to maintain compatibility with automatic addition of the
		// default DCOS path.
		if isDCOS && strings.TrimLeft(u.Path, "/") == "" {
			u.Path = defaultDCOSPath
		}

		// step: create a new node for this endpoint
		members = append(members, &member{endpoint: u.String()})
	}

	return &cluster{
		client:              client,
		members:             members,
		healthCheckInterval: 5 * time.Second,
	}, nil
}
1212013
func NewCluster(client ExtendedClient, applier Applier, sshKeyRing ssh.KeyRing, logger log.Logger, allowedNamespaces []string, imageExcludeList []string) *Cluster {
	c := &Cluster{
		client:            client,
		applier:           applier,
		logger:            logger,
		sshKeyRing:        sshKeyRing,
		allowedNamespaces: allowedNamespaces,
		loggedAllowedNS:   map[string]bool{},
		imageExcludeList:  imageExcludeList,
	}

	return c
}
287083
func NewMockCluster(ctrl *gomock.Controller) *MockCluster {
	mock := &MockCluster{ctrl: ctrl}
	mock.recorder = &MockClusterMockRecorder{mock}
	return mock
}
844233
func NewClusterService(context servicecontext.ServiceContext, config clusterServiceConfig) service.ClusterService {
	return &clusterService{
		BaseService: base.NewBaseService(context),
		config:      config,
	}
}