// CreateMulticastGroup creates the given multi-cast group.
8746
func CreateMulticastGroup(db sqlx.Execer, mg *MulticastGroup) error {
	now := time.Now()
	mg.CreatedAt = now
	mg.UpdatedAt = now

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

	_, err := db.Exec(`
		insert into multicast_group (
			id,
			created_at,
			updated_at,
			mc_addr,
			mc_nwk_s_key,
			f_cnt,
			group_type,
			dr,
			frequency,
			ping_slot_period,
			service_profile_id,
			routing_profile_id
		) values ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12)`,
		mg.ID,
		mg.CreatedAt,
		mg.UpdatedAt,
		mg.MCAddr[:],
		mg.MCNwkSKey[:],
		mg.FCnt,
		mg.GroupType,
		mg.DR,
		mg.Frequency,
		mg.PingSlotPeriod,
		mg.ServiceProfileID,
		mg.RoutingProfileID,
	)
	if err != nil {
		return handlePSQLError(err, "insert error")
	}

	log.WithFields(log.Fields{
		"id": mg.ID,
	}).Info("multicast-group created")

	return nil
}
862182
func AddDeviceToMulticastGroup(db sqlx.Execer, devEUI lorawan.EUI64, multicastGroupID uuid.UUID) error {
	_, err := db.Exec(`
		insert into device_multicast_group (
			dev_eui,
			multicast_group_id,
			created_at
		) values ($1, $2, $3)`,
		devEUI, multicastGroupID, time.Now())
	if err != nil {
		return handlePSQLError(err, "insert error")
	}

	log.WithFields(log.Fields{
		"dev_eui":            devEUI,
		"multicast_group_id": multicastGroupID,
	}).Info("device added to multicast-group")

	return nil
}
713582
func (gce *Cloud) CreateInstanceGroup(name string, zone string) (*compute.InstanceGroup, error) {
	op, err := gce.service.InstanceGroups.Insert(
		gce.projectID, zone, &compute.InstanceGroup{Name: name}).Do()
	if err != nil {
		return nil, err
	}
	if err = gce.waitForZoneOp(op, zone); err != nil {
		return nil, err
	}
	return gce.GetInstanceGroup(name, zone)
}
135257
func NewMultiNotifyWatcher(w ...NotifyWatcher) *MultiNotifyWatcher {
	m := &MultiNotifyWatcher{
		watchers: w,
		changes:  make(chan struct{}),
	}
	var wg sync.WaitGroup
	wg.Add(len(w))
	staging := make(chan struct{})
	for _, w := range w {
		// Consume the first event of each watcher.
		<-w.Changes()
		go func(wCopy NotifyWatcher) {
			defer wg.Done()
			wCopy.Wait()
		}(w)
		// Copy events from the watcher to the staging channel.
		go copyEvents(staging, w.Changes(), &m.tomb)
	}
	m.tomb.Go(func() error {
		m.loop(staging)
		wg.Wait()
		return nil
	})
	return m
}
355023
func FlushMulticastQueueForMulticastGroup(db sqlx.Execer, multicastGroupID uuid.UUID) error {
	_, err := db.Exec(`
		delete from
			multicast_queue
		where
			multicast_group_id = $1
	`, multicastGroupID)
	if err != nil {
		return handlePSQLError(err, "delete error")
	}

	log.WithFields(log.Fields{
		"multicast_group_id": multicastGroupID,
	}).Info("multicast-group queue flushed")

	return nil
}
789034
func (n *NetworkServerAPI) GetMulticastGroup(ctx context.Context, req *ns.GetMulticastGroupRequest) (*ns.GetMulticastGroupResponse, error) {
	var mgID uuid.UUID
	copy(mgID[:], req.Id)

	mg, err := storage.GetMulticastGroup(storage.DB(), mgID, false)
	if err != nil {
		return nil, errToRPCError(err)
	}

	resp := ns.GetMulticastGroupResponse{
		MulticastGroup: &ns.MulticastGroup{
			Id:               mg.ID.Bytes(),
			McAddr:           mg.MCAddr[:],
			McNwkSKey:        mg.MCNwkSKey[:],
			FCnt:             mg.FCnt,
			Dr:               uint32(mg.DR),
			Frequency:        uint32(mg.Frequency),
			PingSlotPeriod:   uint32(mg.PingSlotPeriod),
			ServiceProfileId: mg.ServiceProfileID.Bytes(),
			RoutingProfileId: mg.RoutingProfileID.Bytes(),
		},
	}

	switch mg.GroupType {
	case storage.MulticastGroupB:
		resp.MulticastGroup.GroupType = ns.MulticastGroupType_CLASS_B
	case storage.MulticastGroupC:
		resp.MulticastGroup.GroupType = ns.MulticastGroupType_CLASS_C
	default:
		return nil, grpc.Errorf(codes.Internal, "invalid group-type: %s", mg.GroupType)
	}

	resp.CreatedAt, err = ptypes.TimestampProto(mg.CreatedAt)
	if err != nil {
		return nil, errToRPCError(err)
	}

	resp.UpdatedAt, err = ptypes.TimestampProto(mg.UpdatedAt)
	if err != nil {
		return nil, errToRPCError(err)
	}

	return &resp, nil
}
693776
func NewGroup(parent *Groups) *Group {
	group := &Group{
		parent: parent,
	}
	group.Init()
	return group
}
1123898
func (groups *Groups) AddGroup(newGroup *Group) {
	if newGroup.GroupID != "" {
		for key, group := range groups.Groups.Items {
			if group.GroupID == newGroup.GroupID {
				groups.Groups.Items[key] = newGroup
				return
			}
		}
	}

	newGroup.parent = groups

	groups.Groups.Items = append(groups.Groups.Items, newGroup)
}
105836
func (c *VFSClientset) CreateCluster(cluster *kops.Cluster) (*kops.Cluster, error) {
	return c.clusters().Create(cluster)
}
1347997
func (api *Client) CreateUserGroup(userGroup UserGroup) (UserGroup, error) {
	return api.CreateUserGroupContext(context.Background(), userGroup)
}
994031
func GetMulticastGroupsForDevEUI(db sqlx.Queryer, devEUI lorawan.EUI64) ([]uuid.UUID, error) {
	var out []uuid.UUID

	err := sqlx.Select(db, &out, `
		select
			multicast_group_id
		from
			device_multicast_group
		where
			dev_eui = $1`,
		devEUI[:])
	if err != nil {
		return nil, handlePSQLError(err, "select error")
	}

	return out, nil
}
1055820
func (c *Client) CreateAffinityGroup(p *CreateAffinityGroupParameter) (*AffinityGroup, error) {
	obj, err := c.Request("createAffinityGroup", convertParamToMap(p))
	if err != nil {
		return nil, err
	}
	return obj.(*AffinityGroup), err
}
939124
func createMultiSig(icmd interface{}, w *wallet.Wallet) (interface{}, error) {
	cmd := icmd.(*btcjson.CreateMultisigCmd)

	script, err := makeMultiSigScript(w, cmd.Keys, cmd.NRequired)
	if err != nil {
		return nil, ParseError{err}
	}

	address, err := btcutil.NewAddressScriptHash(script, w.ChainParams())
	if err != nil {
		// above is a valid script, shouldn't happen.
		return nil, err
	}

	return btcjson.CreateMultiSigResult{
		Address:      address.EncodeAddress(),
		RedeemScript: hex.EncodeToString(script),
	}, nil
}
1304626
func (s *VMGroupService) CreateInstanceGroup(p *CreateInstanceGroupParams) (*CreateInstanceGroupResponse, error) {
	resp, err := s.cs.newRequest("createInstanceGroup", p.toURLValues())
	if err != nil {
		return nil, err
	}

	var r CreateInstanceGroupResponse
	if err := json.Unmarshal(resp, &r); err != nil {
		return nil, err
	}

	return &r, nil
}
1276875
func (o *MultiCastList) AssignMultiCastChannelMaps(children MultiCastChannelMapsList) *bambou.Error {

	list := []bambou.Identifiable{}
	for _, c := range children {
		list = append(list, c)
	}

	return bambou.CurrentSession().AssignChildren(o, list, MultiCastChannelMapIdentity)
}
77445
func (o *Enterprise) CreateSaaSApplicationGroup(child *SaaSApplicationGroup) *bambou.Error {

	return bambou.CurrentSession().CreateChild(o, child)
}
553416
func (api *Client) CreateGroup(group string) (*Group, error) {
	return api.CreateGroupContext(context.Background(), group)
}