// CreateGatewayTemplate creates a new child GatewayTemplate under the Me
171065
func (o *Me) CreateGatewayTemplate(child *GatewayTemplate) *bambou.Error {

	return bambou.CurrentSession().CreateChild(o, child)
}
1272377
func CreatePodTemplate(template v1.PodTemplateSpec, generation *int64, hash string) v1.PodTemplateSpec {
	newTemplate := *template.DeepCopy()

	AddOrUpdateDaemonPodTolerations(&newTemplate.Spec)

	if newTemplate.ObjectMeta.Labels == nil {
		newTemplate.ObjectMeta.Labels = make(map[string]string)
	}
	if generation != nil {
		newTemplate.ObjectMeta.Labels[extensions.DaemonSetTemplateGenerationKey] = fmt.Sprint(*generation)
	}
	// TODO: do we need to validate if the DaemonSet is RollingUpdate or not?
	if len(hash) > 0 {
		newTemplate.ObjectMeta.Labels[extensions.DefaultDaemonSetUniqueLabelKey] = hash
	}
	return newTemplate
}
135923
func (o *VLAN) CreateIKEGatewayConnection(child *IKEGatewayConnection) *bambou.Error {

	return bambou.CurrentSession().CreateChild(o, child)
}
1263223
func (c *FakeBrokerTemplateInstances) Create(brokerTemplateInstance *template.BrokerTemplateInstance) (result *template.BrokerTemplateInstance, err error) {
	obj, err := c.Fake.
		Invokes(testing.NewRootCreateAction(brokertemplateinstancesResource, brokerTemplateInstance), &template.BrokerTemplateInstance{})
	if obj == nil {
		return nil, err
	}
	return obj.(*template.BrokerTemplateInstance), err
}
327631
func (o *NSGatewayTemplate) CreateNSPortTemplate(child *NSPortTemplate) *bambou.Error {

	return bambou.CurrentSession().CreateChild(o, child)
}
1205060
func (f *Fpdf) CreateTemplate(fn func(*Tpl)) Template {
	return newTpl(PointType{0, 0}, f.curPageSize, f.defOrientation, f.unitStr, f.fontDirStr, fn, f)
}
111260
func (o *Enterprise) CreateDomainTemplate(child *DomainTemplate) *bambou.Error {

	return bambou.CurrentSession().CreateChild(o, child)
}
1135933
func (o *EgressACLTemplate) CreateEgressACLEntryTemplate(child *EgressACLEntryTemplate) *bambou.Error {

	return bambou.CurrentSession().CreateChild(o, child)
}
751683
func (a *Driver) CreateFromTemplate(id, template string, templateIDMappings *idtools.IDMappings, parent string, parentIDMappings *idtools.IDMappings, opts *graphdriver.CreateOpts, readWrite bool) error {
	return graphdriver.NaiveCreateFromTemplate(a, id, template, templateIDMappings, parent, parentIDMappings, opts, readWrite)
}
441967
func (o *Enterprise) CreateL2DomainTemplate(child *L2DomainTemplate) *bambou.Error {

	return bambou.CurrentSession().CreateChild(o, child)
}
299352
func (o *Me) CreateNSGateway(child *NSGateway) *bambou.Error {

	return bambou.CurrentSession().CreateChild(o, child)
}
92617
func (n *NetworkServerAPI) CreateGateway(ctx context.Context, req *ns.CreateGatewayRequest) (*empty.Empty, error) {
	if req.Gateway == nil {
		return nil, grpc.Errorf(codes.InvalidArgument, "gateway must not be nil")
	}

	if req.Gateway.Location == nil {
		return nil, grpc.Errorf(codes.InvalidArgument, "gateway.location must not be nil")
	}

	gw := storage.Gateway{
		Location: storage.GPSPoint{
			Latitude:  req.Gateway.Location.Latitude,
			Longitude: req.Gateway.Location.Longitude,
		},
		Altitude: req.Gateway.Location.Altitude,
	}

	// Gateway ID
	copy(gw.GatewayID[:], req.Gateway.Id)

	// Gateway-profile ID.
	if b := req.Gateway.GatewayProfileId; len(b) != 0 {
		var gpID uuid.UUID
		copy(gpID[:], b)
		gw.GatewayProfileID = &gpID
	}

	for _, board := range req.Gateway.Boards {
		var gwBoard storage.GatewayBoard

		if b := board.FpgaId; len(b) != 0 {
			var fpgaID lorawan.EUI64
			copy(fpgaID[:], b)
			gwBoard.FPGAID = &fpgaID
		}

		if b := board.FineTimestampKey; len(b) != 0 {
			var key lorawan.AES128Key
			copy(key[:], b)
			gwBoard.FineTimestampKey = &key
		}

		gw.Boards = append(gw.Boards, gwBoard)
	}

	err := storage.Transaction(func(tx sqlx.Ext) error {
		if err := storage.CreateGateway(tx, &gw); err != nil {
			return errToRPCError(err)
		}
		return nil
	})
	if err != nil {
		return nil, err
	}

	return &empty.Empty{}, nil
}
743764
func (o *NSGateway) CreateWirelessPort(child *WirelessPort) *bambou.Error {

	return bambou.CurrentSession().CreateChild(o, child)
}
1316841
func GenerateDefaultGateway(sna *net.IPNet) net.IP {
	ip := sna.IP.To4()
	return net.IPv4(ip[0], ip[1], ip[2], ip[3]|0x1)
}
625842
func MarshalGatewayConfiguration(t Type, gc gw.GatewayConfiguration) ([]byte, error) {
	var b []byte
	var err error

	switch t {
	case Protobuf:
		b, err = proto.Marshal(&gc)
	case JSON:
		var str string
		m := &jsonpb.Marshaler{
			EmitDefaults: true,
		}
		str, err = m.MarshalToString(&gc)
		b = []byte(str)
	}

	return b, err
}
841742
func (m *MockEC2) CreateLaunchTemplate(request *ec2.CreateLaunchTemplateInput) (*ec2.CreateLaunchTemplateOutput, error) {
	m.mutex.Lock()
	defer m.mutex.Unlock()

	if m.LaunchTemplates == nil {
		m.LaunchTemplates = make(map[string]*ec2.ResponseLaunchTemplateData)
	}
	if m.LaunchTemplates[aws.StringValue(request.LaunchTemplateName)] != nil {
		return nil, fmt.Errorf("duplicate LaunchTemplateName %s", aws.StringValue(request.LaunchTemplateName))
	}
	resp := &ec2.ResponseLaunchTemplateData{
		DisableApiTermination: request.LaunchTemplateData.DisableApiTermination,
		EbsOptimized:          request.LaunchTemplateData.EbsOptimized,
		ImageId:               request.LaunchTemplateData.ImageId,
		InstanceType:          request.LaunchTemplateData.InstanceType,
		KeyName:               request.LaunchTemplateData.KeyName,
		SecurityGroupIds:      request.LaunchTemplateData.SecurityGroupIds,
		SecurityGroups:        request.LaunchTemplateData.SecurityGroups,
		UserData:              request.LaunchTemplateData.UserData,
	}
	m.LaunchTemplates[aws.StringValue(request.LaunchTemplateName)] = resp

	// @GOD DAMN AWS request vs response .. fu@@@@@ .. so much typing!!#@#@#

	if request.LaunchTemplateData.Monitoring != nil {
		resp.Monitoring = &ec2.LaunchTemplatesMonitoring{Enabled: request.LaunchTemplateData.Monitoring.Enabled}
	}
	if request.LaunchTemplateData.CpuOptions != nil {
		resp.CpuOptions = &ec2.LaunchTemplateCpuOptions{
			CoreCount:      request.LaunchTemplateData.CpuOptions.CoreCount,
			ThreadsPerCore: request.LaunchTemplateData.CpuOptions.ThreadsPerCore,
		}
	}
	if len(request.LaunchTemplateData.BlockDeviceMappings) > 0 {
		for _, x := range request.LaunchTemplateData.BlockDeviceMappings {
			resp.BlockDeviceMappings = append(resp.BlockDeviceMappings, &ec2.LaunchTemplateBlockDeviceMapping{
				DeviceName: x.DeviceName,
				Ebs: &ec2.LaunchTemplateEbsBlockDevice{
					DeleteOnTermination: x.Ebs.DeleteOnTermination,
					Encrypted:           x.Ebs.Encrypted,
					Iops:                x.Ebs.Iops,
					KmsKeyId:            x.Ebs.KmsKeyId,
					SnapshotId:          x.Ebs.SnapshotId,
					VolumeSize:          x.Ebs.VolumeSize,
					VolumeType:          x.Ebs.VolumeType,
				},
				NoDevice:    x.NoDevice,
				VirtualName: x.VirtualName,
			})
		}
	}
	if request.LaunchTemplateData.CreditSpecification != nil {
		resp.CreditSpecification = &ec2.CreditSpecification{CpuCredits: request.LaunchTemplateData.CreditSpecification.CpuCredits}
	}
	if request.LaunchTemplateData.IamInstanceProfile != nil {
		resp.IamInstanceProfile = &ec2.LaunchTemplateIamInstanceProfileSpecification{
			Arn:  request.LaunchTemplateData.IamInstanceProfile.Arn,
			Name: request.LaunchTemplateData.IamInstanceProfile.Name,
		}
	}
	if request.LaunchTemplateData.InstanceMarketOptions != nil {
		resp.InstanceMarketOptions = &ec2.LaunchTemplateInstanceMarketOptions{
			MarketType: request.LaunchTemplateData.InstanceMarketOptions.MarketType,
			SpotOptions: &ec2.LaunchTemplateSpotMarketOptions{
				BlockDurationMinutes:         request.LaunchTemplateData.InstanceMarketOptions.SpotOptions.BlockDurationMinutes,
				InstanceInterruptionBehavior: request.LaunchTemplateData.InstanceMarketOptions.SpotOptions.InstanceInterruptionBehavior,
				MaxPrice:                     request.LaunchTemplateData.InstanceMarketOptions.SpotOptions.MaxPrice,
				SpotInstanceType:             request.LaunchTemplateData.InstanceMarketOptions.SpotOptions.SpotInstanceType,
				ValidUntil:                   request.LaunchTemplateData.InstanceMarketOptions.SpotOptions.ValidUntil,
			},
		}
	}
	if len(request.LaunchTemplateData.NetworkInterfaces) > 0 {
		for _, x := range request.LaunchTemplateData.NetworkInterfaces {
			resp.NetworkInterfaces = append(resp.NetworkInterfaces, &ec2.LaunchTemplateInstanceNetworkInterfaceSpecification{
				AssociatePublicIpAddress:       x.AssociatePublicIpAddress,
				DeleteOnTermination:            x.DeleteOnTermination,
				Description:                    x.Description,
				DeviceIndex:                    x.DeviceIndex,
				Groups:                         x.Groups,
				Ipv6AddressCount:               x.Ipv6AddressCount,
				NetworkInterfaceId:             x.NetworkInterfaceId,
				PrivateIpAddress:               x.PrivateIpAddress,
				PrivateIpAddresses:             x.PrivateIpAddresses,
				SecondaryPrivateIpAddressCount: x.SecondaryPrivateIpAddressCount,
				SubnetId:                       x.SubnetId,
			})
		}
	}

	return &ec2.CreateLaunchTemplateOutput{}, nil
}
661796
func CreateGateway(db sqlx.Execer, gw *Gateway) error {
	now := time.Now()
	gw.CreatedAt = now
	gw.UpdatedAt = now

	_, err := db.Exec(`
		insert into gateway (
			gateway_id,
			created_at,
			updated_at,
			first_seen_at,
			last_seen_at,
			location,
			altitude,
			gateway_profile_id
		) values ($1, $2, $3, $4, $5, $6, $7, $8)`,
		gw.GatewayID[:],
		gw.CreatedAt,
		gw.UpdatedAt,
		gw.FirstSeenAt,
		gw.LastSeenAt,
		gw.Location,
		gw.Altitude,
		gw.GatewayProfileID,
	)
	if err != nil {
		return handlePSQLError(err, "insert error")
	}

	for i, board := range gw.Boards {
		_, err := db.Exec(`
			insert into gateway_board (
				id,
				gateway_id,
				fpga_id,
				fine_timestamp_key
			) values ($1, $2, $3, $4)`,
			i,
			gw.GatewayID,
			board.FPGAID,
			board.FineTimestampKey,
		)
		if err != nil {
			return handlePSQLError(err, "insert error")
		}
	}

	log.WithField("gateway_id", gw.GatewayID).Info("gateway created")
	return nil
}