コード例 #1
0
func (i *importer) makeUnitDoc(s description.Service, u description.Unit) (*unitDoc, error) {
	// NOTE: if we want to support units having different charms deployed
	// than the service recomments and migrate that, then we should serialize
	// the charm url for each unit rather than grabbing the services charm url.
	// Currently the units charm url matching the service is a precondiation
	// to migration.
	charmUrl, err := charm.ParseURL(s.CharmURL())
	if err != nil {
		return nil, errors.Trace(err)
	}

	var subordinates []string
	if subs := u.Subordinates(); len(subs) > 0 {
		for _, s := range subs {
			subordinates = append(subordinates, s.Id())
		}
	}

	return &unitDoc{
		Name:         u.Name(),
		Service:      s.Name(),
		Series:       s.Series(),
		CharmURL:     charmUrl,
		Principal:    u.Principal().Id(),
		Subordinates: subordinates,
		// StorageAttachmentCount int `bson:"storageattachmentcount"`
		MachineId:    u.Machine().Id(),
		Tools:        i.makeTools(u.Tools()),
		Life:         Alive,
		PasswordHash: u.PasswordHash(),
	}, nil
}
コード例 #2
0
func (i *importer) makeServiceDoc(s description.Service) (*serviceDoc, error) {
	charmUrl, err := charm.ParseURL(s.CharmURL())
	if err != nil {
		return nil, errors.Trace(err)
	}

	return &serviceDoc{
		Name:                 s.Name(),
		Series:               s.Series(),
		Subordinate:          s.Subordinate(),
		CharmURL:             charmUrl,
		Channel:              s.Channel(),
		CharmModifiedVersion: s.CharmModifiedVersion(),
		ForceCharm:           s.ForceCharm(),
		Life:                 Alive,
		UnitCount:            len(s.Units()),
		RelationCount:        i.relationCount(s.Name()),
		Exposed:              s.Exposed(),
		MinUnits:             s.MinUnits(),
		MetricCredentials:    s.MetricsCredentials(),
	}, nil
}