// CreateServiceProfile creates the given service-profile.
772549
func (n *NetworkServerAPI) CreateServiceProfile(ctx context.Context, req *ns.CreateServiceProfileRequest) (*ns.CreateServiceProfileResponse, error) {
	if req.ServiceProfile == nil {
		return nil, grpc.Errorf(codes.InvalidArgument, "service_profile must not be nil")
	}

	var spID uuid.UUID
	copy(spID[:], req.ServiceProfile.Id)

	sp := storage.ServiceProfile{
		ID:                     spID,
		ULRate:                 int(req.ServiceProfile.UlRate),
		ULBucketSize:           int(req.ServiceProfile.UlBucketSize),
		DLRate:                 int(req.ServiceProfile.DlRate),
		DLBucketSize:           int(req.ServiceProfile.DlBucketSize),
		AddGWMetadata:          req.ServiceProfile.AddGwMetadata,
		DevStatusReqFreq:       int(req.ServiceProfile.DevStatusReqFreq),
		ReportDevStatusBattery: req.ServiceProfile.ReportDevStatusBattery,
		ReportDevStatusMargin:  req.ServiceProfile.ReportDevStatusMargin,
		DRMin:                  int(req.ServiceProfile.DrMin),
		DRMax:                  int(req.ServiceProfile.DrMax),
		ChannelMask:            req.ServiceProfile.ChannelMask,
		PRAllowed:              req.ServiceProfile.PrAllowed,
		HRAllowed:              req.ServiceProfile.HrAllowed,
		RAAllowed:              req.ServiceProfile.RaAllowed,
		NwkGeoLoc:              req.ServiceProfile.NwkGeoLoc,
		TargetPER:              int(req.ServiceProfile.TargetPer),
		MinGWDiversity:         int(req.ServiceProfile.MinGwDiversity),
	}

	switch req.ServiceProfile.UlRatePolicy {
	case ns.RatePolicy_MARK:
		sp.ULRatePolicy = storage.Mark
	case ns.RatePolicy_DROP:
		sp.ULRatePolicy = storage.Drop
	}

	switch req.ServiceProfile.DlRatePolicy {
	case ns.RatePolicy_MARK:
		sp.DLRatePolicy = storage.Mark
	case ns.RatePolicy_DROP:
		sp.DLRatePolicy = storage.Drop
	}

	if err := storage.CreateServiceProfile(storage.DB(), &sp); err != nil {
		return nil, errToRPCError(err)
	}

	return &ns.CreateServiceProfileResponse{
		Id: sp.ID.Bytes(),
	}, nil
}
1329227
func (m *manager) CreateService(name, exepath string, c mgr.Config, args ...string) (windowsService, error) {
	// The Create function relies on the fact that this calls Connect(which connects to localhost) and not
	// ConnectRemote. If we get to the point where we need to call ConnectRemote we need to stop using
	// series.HostSeries inside Create.
	s, err := mgr.Connect()
	if err != nil {
		return nil, err
	}
	defer s.Disconnect()
	return s.CreateService(name, exepath, c, args...)
}
422672
func (c *Client) CreateService(i *CreateServiceInput) (*Service, error) {
	resp, err := c.PostForm("/service", i, nil)
	if err != nil {
		return nil, err
	}

	var s *Service
	if err := decodeJSON(&s, resp.Body); err != nil {
		return nil, err
	}
	return s, nil
}
748585
func (c *Cluster) CreateService(s types.ServiceSpec, encodedAuth string, queryRegistry bool) (*apitypes.ServiceCreateResponse, error) {
	var resp *apitypes.ServiceCreateResponse
	err := c.lockedManagerAction(func(ctx context.Context, state nodeState) error {
		err := c.populateNetworkID(ctx, state.controlClient, &s)
		if err != nil {
			return err
		}

		serviceSpec, err := convert.ServiceSpecToGRPC(s)
		if err != nil {
			return errdefs.InvalidParameter(err)
		}

		resp = &apitypes.ServiceCreateResponse{}

		switch serviceSpec.Task.Runtime.(type) {
		case *swarmapi.TaskSpec_Attachment:
			return fmt.Errorf("invalid task spec: spec type %q not supported", types.RuntimeNetworkAttachment)
		// handle other runtimes here
		case *swarmapi.TaskSpec_Generic:
			switch serviceSpec.Task.GetGeneric().Kind {
			case string(types.RuntimePlugin):
				if !c.config.Backend.HasExperimental() {
					return fmt.Errorf("runtime type %q only supported in experimental", types.RuntimePlugin)
				}
				if s.TaskTemplate.PluginSpec == nil {
					return errors.New("plugin spec must be set")
				}

			default:
				return fmt.Errorf("unsupported runtime type: %q", serviceSpec.Task.GetGeneric().Kind)
			}

			r, err := state.controlClient.CreateService(ctx, &swarmapi.CreateServiceRequest{Spec: &serviceSpec})
			if err != nil {
				return err
			}

			resp.ID = r.Service.ID
		case *swarmapi.TaskSpec_Container:
			ctnr := serviceSpec.Task.GetContainer()
			if ctnr == nil {
				return errors.New("service does not use container tasks")
			}
			if encodedAuth != "" {
				ctnr.PullOptions = &swarmapi.ContainerSpec_PullOptions{RegistryAuth: encodedAuth}
			}

			// retrieve auth config from encoded auth
			authConfig := &apitypes.AuthConfig{}
			if encodedAuth != "" {
				authReader := strings.NewReader(encodedAuth)
				dec := json.NewDecoder(base64.NewDecoder(base64.URLEncoding, authReader))
				if err := dec.Decode(authConfig); err != nil {
					logrus.Warnf("invalid authconfig: %v", err)
				}
			}

			// pin image by digest for API versions < 1.30
			// TODO(nishanttotla): The check on "DOCKER_SERVICE_PREFER_OFFLINE_IMAGE"
			// should be removed in the future. Since integration tests only use the
			// latest API version, so this is no longer required.
			if os.Getenv("DOCKER_SERVICE_PREFER_OFFLINE_IMAGE") != "1" && queryRegistry {
				digestImage, err := c.imageWithDigestString(ctx, ctnr.Image, authConfig)
				if err != nil {
					logrus.Warnf("unable to pin image %s to digest: %s", ctnr.Image, err.Error())
					// warning in the client response should be concise
					resp.Warnings = append(resp.Warnings, digestWarning(ctnr.Image))

				} else if ctnr.Image != digestImage {
					logrus.Debugf("pinning image %s by digest: %s", ctnr.Image, digestImage)
					ctnr.Image = digestImage

				} else {
					logrus.Debugf("creating service using supplied digest reference %s", ctnr.Image)

				}

				// Replace the context with a fresh one.
				// If we timed out while communicating with the
				// registry, then "ctx" will already be expired, which
				// would cause UpdateService below to fail. Reusing
				// "ctx" could make it impossible to create a service
				// if the registry is slow or unresponsive.
				var cancel func()
				ctx, cancel = c.getRequestContext()
				defer cancel()
			}

			r, err := state.controlClient.CreateService(ctx, &swarmapi.CreateServiceRequest{Spec: &serviceSpec})
			if err != nil {
				return err
			}

			resp.ID = r.Service.ID
		}
		return nil
	})

	return resp, err
}
605989
func (b *BigIP) CreateUdpProfile(name string, parent string) error {
	config := &UdpProfile{
		Name:         name,
		DefaultsFrom: parent,
	}

	return b.post(config, uriLtm, uriProfile, uriUdp)
}
683314
func (r *REPL) cmdProfile() error {
	if r.profiler {
		r.profiler = false
	} else {
		r.profiler = true
	}
	return nil
}
46778
func CreateDeviceProfile(db sqlx.Execer, dp *DeviceProfile) error {
	now := time.Now()

	if dp.ID == uuid.Nil {
		var err error
		dp.ID, err = uuid.NewV4()
		if err != nil {
			return errors.Wrap(err, "new uuid v4 error")
		}
	}

	dp.CreatedAt = now
	dp.UpdatedAt = now

	_, err := db.Exec(`
        insert into device_profile (
            created_at,
            updated_at,

            device_profile_id,
            supports_class_b,
            class_b_timeout,
            ping_slot_period,
            ping_slot_dr,
            ping_slot_freq,
            supports_class_c,
            class_c_timeout,
            mac_version,
            reg_params_revision,
            rx_delay_1,
            rx_dr_offset_1,
            rx_data_rate_2,
            rx_freq_2,
            factory_preset_freqs,
            max_eirp,
            max_duty_cycle,
            supports_join,
            rf_region,
            supports_32bit_fcnt
        ) values ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14, $15, $16, $17, $18, $19, $20, $21, $22)`,
		dp.CreatedAt,
		dp.UpdatedAt,
		dp.ID,
		dp.SupportsClassB,
		dp.ClassBTimeout,
		dp.PingSlotPeriod,
		dp.PingSlotDR,
		dp.PingSlotFreq,
		dp.SupportsClassC,
		dp.ClassCTimeout,
		dp.MACVersion,
		dp.RegParamsRevision,
		dp.RXDelay1,
		dp.RXDROffset1,
		dp.RXDataRate2,
		dp.RXFreq2,
		pq.Array(dp.FactoryPresetFreqs),
		dp.MaxEIRP,
		dp.MaxDutyCycle,
		dp.SupportsJoin,
		dp.RFRegion,
		dp.Supports32bitFCnt,
	)
	if err != nil {
		return handlePSQLError(err, "insert error")
	}

	log.WithFields(log.Fields{
		"id": dp.ID,
	}).Info("device-profile created")

	return nil
}
1274120
func WriteProfilesToFile(filename string, profiles []*Profile) error {
	out := io.Writer(os.Stdout)
	if filename != "-" {
		f, err := os.Create(filename)
		if err != nil {
			return err
		}
		defer f.Close()
		out = f
	}

	if err := WriteProfiles(out, profiles); err != nil {
		return err
	}

	return nil
}
20497
func (n *NetworkServerAPI) DeleteServiceProfile(ctx context.Context, req *ns.DeleteServiceProfileRequest) (*empty.Empty, error) {
	var spID uuid.UUID
	copy(spID[:], req.Id)

	if err := storage.FlushServiceProfileCache(storage.RedisPool(), spID); err != nil {
		return nil, errToRPCError(err)
	}

	if err := storage.DeleteServiceProfile(storage.DB(), spID); err != nil {
		return nil, errToRPCError(err)
	}

	return &empty.Empty{}, nil
}
586798
func CreateServiceLB(stateDriver core.StateDriver, serviceLbCfg *intent.ConfigServiceLB) error {

	var providersPresent bool
	serviceIP := serviceLbCfg.IPAddress

	log.Infof("Recevied Create Service Load Balancer config {%v}", serviceLbCfg)

	//Check if service already exists.
	svcID := GetServiceID(serviceLbCfg.ServiceName, serviceLbCfg.Tenant)

	mastercfg.SvcMutex.RLock()
	oldServiceInfo := mastercfg.ServiceLBDb[svcID]
	mastercfg.SvcMutex.RUnlock()

	if oldServiceInfo != nil {
		//ServiceInfo Exists
		if reflect.DeepEqual(oldServiceInfo.Ports, serviceLbCfg.Ports) &&
			reflect.DeepEqual(oldServiceInfo.Selectors, serviceLbCfg.Selectors) &&
			serviceLbCfg.Tenant == oldServiceInfo.Tenant {
			return nil
		}
		serviceIP = oldServiceInfo.IPAddress
		DeleteServiceLB(stateDriver, oldServiceInfo.ServiceName, oldServiceInfo.Tenant)
	}

	//New Service
	serviceLbState := &mastercfg.CfgServiceLBState{}
	serviceLbState.ServiceName = serviceLbCfg.ServiceName
	serviceLbState.Tenant = serviceLbCfg.Tenant
	serviceLbState.Network = serviceLbCfg.Network
	serviceLbState.StateDriver = stateDriver
	serviceLbState.ID = GetServiceID(serviceLbCfg.ServiceName, serviceLbCfg.Tenant)
	serviceLbState.Ports = append(serviceLbState.Ports, serviceLbCfg.Ports...)
	serviceLbState.Selectors = make(map[string]string)
	serviceLbState.Providers = make(map[string]*mastercfg.Provider)
	for k, v := range serviceLbCfg.Selectors {
		serviceLbState.Selectors[k] = v
	}

	// find the network from network id
	networkID := serviceLbState.Network + "." + serviceLbState.Tenant
	nwCfg := &mastercfg.CfgNetworkState{}
	nwCfg.StateDriver = stateDriver
	err := nwCfg.Read(networkID)
	if err != nil {
		log.Errorf("network %s on tenant %s is not created %s", serviceLbState.Network, serviceLbCfg.Tenant, networkID)
		return err
	}

	// Alloc addresses
	addr, err := networkAllocAddress(nwCfg, nil, serviceIP, false)
	if err != nil {
		log.Errorf("Failed to allocate address. Err: %v", err)
		return err
	}
	serviceLbState.IPAddress = addr
	mastercfg.SvcMutex.Lock()
	err = serviceLbState.Write()

	if err != nil {
		mastercfg.SvcMutex.Unlock()
		return err
	}

	serviceID := GetServiceID(serviceLbState.ServiceName, serviceLbState.Tenant)

	mastercfg.ServiceLBDb[serviceID] = &mastercfg.ServiceLBInfo{
		IPAddress:   serviceLbState.IPAddress,
		Tenant:      serviceLbState.Tenant,
		ServiceName: serviceLbState.ServiceName,
		Network:     serviceLbState.Network,
	}
	mastercfg.ServiceLBDb[serviceID].Ports = append(mastercfg.ServiceLBDb[serviceID].Ports, serviceLbState.Ports...)
	mastercfg.ServiceLBDb[serviceID].Selectors = make(map[string]string)
	mastercfg.ServiceLBDb[serviceID].Providers = make(map[string]*mastercfg.Provider)

	for k, v := range serviceLbCfg.Selectors {
		mastercfg.ServiceLBDb[serviceID].Selectors[k] = v
	}

	//Check for containers in the tenant matching service selectors
	for _, providerInfo := range mastercfg.ProviderDb {
		if providerInfo.Tenant == serviceLbState.Tenant {
			if eq := reflect.DeepEqual(providerInfo.Labels, mastercfg.ServiceLBDb[serviceID].Selectors); eq {
				//provider matches service selectors
				providerID := getProviderID(providerInfo)
				providerDbID := getProviderDbID(providerInfo)
				providerInfo.Services = append(providerInfo.Services, serviceID)
				mastercfg.ServiceLBDb[serviceID].Providers[providerID] = providerInfo
				mastercfg.ProviderDb[providerDbID] = providerInfo
				serviceLbState.Providers[providerID] = providerInfo
				providersPresent = true
			}
		}
	}

	//Write into cluster store
	err = serviceLbState.Write()

	if err != nil {
		mastercfg.SvcMutex.Unlock()
		return err
	}

	if providersPresent {
		err = SvcProviderUpdate(serviceID, false)
		if err != nil {
			log.Errorf("Error updating Provider for service %s : %s", serviceID, err)
			return err
		}
	}
	mastercfg.SvcMutex.Unlock()

	return nil
}
1135348
func CreateServiceAccount(client clientset.Interface) error {

	return apiclient.CreateOrUpdateServiceAccount(client, &v1.ServiceAccount{
		ObjectMeta: metav1.ObjectMeta{
			Name:      KubeDNSServiceAccountName,
			Namespace: metav1.NamespaceSystem,
		},
	})
}
1260238
func UserProfile(c *MyContext) {

	id := c.Param("id")

	var profile string

	// profile = c.AppContext.DB.find(user profile by .....)

	c.AppContext.Log.Println("Found User Profile")

	c.Response().Write([]byte("Here's your profile " + profile + " user " + id))
}
437513
func (provider *OpenShiftIdentityProviderImpl) Profile(ctx context.Context, token oauth2.Token) (*UserProfile, error) {
	body, err := provider.UserProfilePayload(ctx, token)
	if err != nil {
		return nil, err
	}
	var u openshiftUser
	err = json.Unmarshal(body, &u)
	if err != nil {
		return nil, err
	}
	userProfile := &UserProfile{
		Username: u.Metadata.Name,
	}
	return userProfile, nil
}
1142538
func (e Endpoints) PutProfile(ctx context.Context, id string, p Profile) error {
	request := putProfileRequest{ID: id, Profile: p}
	response, err := e.PutProfileEndpoint(ctx, request)
	if err != nil {
		return err
	}
	resp := response.(putProfileResponse)
	return resp.Err
}
775227
func createServiceLB(ctx *cli.Context) {
	if len(ctx.Args()) != 1 {
		errExit(ctx, exitHelp, "Service name required", true)
	}

	serviceName := ctx.Args()[0]
	serviceSubnet := ctx.String("network")
	tenantName := ctx.String("tenant")
	if len(tenantName) == 0 {
		tenantName = "default"
	}
	selectors := ctx.StringSlice("selector")
	ports := ctx.StringSlice("port")
	ipAddress := ctx.String("preferred-ip")
	service := &contivClient.ServiceLB{
		ServiceName: serviceName,
		TenantName:  tenantName,
		NetworkName: serviceSubnet,
		IpAddress:   ipAddress,
	}
	service.Selectors = append(service.Selectors, selectors...)
	service.Ports = append(service.Ports, ports...)
	errCheck(ctx, getClient(ctx).ServiceLBPost(service))

	fmt.Printf("Creating ServiceLB %s:%s\n", tenantName, serviceName)
}
468294
func (s *DeviceInstance) SetInstanceProfile(v *InstanceProfile) *DeviceInstance {
	s.InstanceProfile = v
	return s
}
1248700
func NewUserProfileService(context servicecontext.ServiceContext) service.UserProfileService {
	return &userProfileService{
		client: http.DefaultClient,
	}
}