本文整理汇总了Golang中github.com/wallyworld/core/state.Service.Name方法的典型用法代码示例。如果您正苦于以下问题:Golang Service.Name方法的具体用法?Golang Service.Name怎么用?Golang Service.Name使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/wallyworld/core/state.Service
的用法示例。
在下文中一共展示了Service.Name方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: processRelations
func (*statusContext) processRelations(service *state.Service) (related map[string][]string, subord []string, err error) {
// TODO(mue) This way the same relation is read twice (for each service).
// Maybe add Relations() to state, read them only once and pass them to each
// call of this function.
relations, err := service.Relations()
if err != nil {
return nil, nil, err
}
var subordSet set.Strings
related = make(map[string][]string)
for _, relation := range relations {
ep, err := relation.Endpoint(service.Name())
if err != nil {
return nil, nil, err
}
relationName := ep.Relation.Name
eps, err := relation.RelatedEndpoints(service.Name())
if err != nil {
return nil, nil, err
}
for _, ep := range eps {
if ep.Scope == charm.ScopeContainer && !service.IsPrincipal() {
subordSet.Add(ep.ServiceName)
}
related[relationName] = append(related[relationName], ep.ServiceName)
}
}
for relationName, serviceNames := range related {
sn := set.NewStrings(serviceNames...)
related[relationName] = sn.SortedValues()
}
return related, subordSet.SortedValues(), nil
}
示例2: processService
func (context *statusContext) processService(service *state.Service) (status api.ServiceStatus) {
serviceCharmURL, _ := service.CharmURL()
status.Charm = serviceCharmURL.String()
status.Exposed = service.IsExposed()
status.Life = processLife(service)
latestCharm, ok := context.latestCharms[*serviceCharmURL.WithRevision(-1)]
if ok && latestCharm != serviceCharmURL.String() {
status.CanUpgradeTo = latestCharm
}
var err error
status.Relations, status.SubordinateTo, err = context.processRelations(service)
if err != nil {
status.Err = err
return
}
includeNetworks, excludeNetworks, err := service.Networks()
if err == nil {
status.Networks = api.NetworksSpecification{
Enabled: includeNetworks,
Disabled: excludeNetworks,
}
}
if service.IsPrincipal() {
status.Units = context.processUnits(context.units[service.Name()], serviceCharmURL.String())
}
return status
}
示例3: serviceSetSettingsYAML
// serviceSetSettingsYAML updates the settings for the given service,
// taking the configuration from a YAML string.
func serviceSetSettingsYAML(service *state.Service, settings string) error {
ch, _, err := service.Charm()
if err != nil {
return err
}
changes, err := ch.Config().ParseSettingsYAML([]byte(settings), service.Name())
if err != nil {
return err
}
return service.UpdateConfigSettings(changes)
}
示例4: assertOneRelation
func assertOneRelation(c *gc.C, srv *state.Service, relId int, endpoints ...state.Endpoint) *state.Relation {
rels, err := srv.Relations()
c.Assert(err, gc.IsNil)
c.Assert(rels, gc.HasLen, 1)
rel := rels[0]
c.Assert(rel.Id(), gc.Equals, relId)
name := srv.Name()
expectEp := endpoints[0]
ep, err := rel.Endpoint(name)
c.Assert(err, gc.IsNil)
c.Assert(ep, gc.DeepEquals, expectEp)
if len(endpoints) == 2 {
expectEp = endpoints[1]
}
eps, err := rel.RelatedEndpoints(name)
c.Assert(err, gc.IsNil)
c.Assert(eps, gc.DeepEquals, []state.Endpoint{expectEp})
return rel
}
示例5: NewProReqRelation
func NewProReqRelation(c *gc.C, s *ConnSuite, scope charm.RelationScope) *ProReqRelation {
psvc := s.AddTestingService(c, "mysql", s.AddTestingCharm(c, "mysql"))
var rsvc *state.Service
if scope == charm.ScopeGlobal {
rsvc = s.AddTestingService(c, "wordpress", s.AddTestingCharm(c, "wordpress"))
} else {
rsvc = s.AddTestingService(c, "logging", s.AddTestingCharm(c, "logging"))
}
eps, err := s.State.InferEndpoints([]string{"mysql", rsvc.Name()})
c.Assert(err, gc.IsNil)
rel, err := s.State.AddRelation(eps...)
c.Assert(err, gc.IsNil)
prr := &ProReqRelation{rel: rel, psvc: psvc, rsvc: rsvc}
prr.pu0, prr.pru0 = addRU(c, psvc, rel, nil)
prr.pu1, prr.pru1 = addRU(c, psvc, rel, nil)
if scope == charm.ScopeGlobal {
prr.ru0, prr.rru0 = addRU(c, rsvc, rel, nil)
prr.ru1, prr.rru1 = addRU(c, rsvc, rel, nil)
} else {
prr.ru0, prr.rru0 = addRU(c, rsvc, rel, prr.pu0)
prr.ru1, prr.rru1 = addRU(c, rsvc, rel, prr.pu1)
}
return prr
}
示例6: AddUnits
// AddUnits starts n units of the given service and allocates machines
// to them as necessary.
func AddUnits(st *state.State, svc *state.Service, n int, machineIdSpec string) ([]*state.Unit, error) {
units := make([]*state.Unit, n)
// Hard code for now till we implement a different approach.
policy := state.AssignCleanEmpty
// All units should have the same networks as the service.
includeNetworks, excludeNetworks, err := svc.Networks()
if err != nil {
return nil, fmt.Errorf("cannot get service %q networks: %v", svc.Name(), err)
}
// TODO what do we do if we fail half-way through this process?
for i := 0; i < n; i++ {
unit, err := svc.AddUnit()
if err != nil {
return nil, fmt.Errorf("cannot add unit %d/%d to service %q: %v", i+1, n, svc.Name(), err)
}
if machineIdSpec != "" {
if n != 1 {
return nil, fmt.Errorf("cannot add multiple units of service %q to a single machine", svc.Name())
}
// machineIdSpec may be an existing machine or container, eg 3/lxc/2
// or a new container on a machine, eg lxc:3
mid := machineIdSpec
var containerType instance.ContainerType
specParts := strings.SplitN(machineIdSpec, ":", 2)
if len(specParts) > 1 {
firstPart := specParts[0]
var err error
if containerType, err = instance.ParseContainerType(firstPart); err == nil {
mid = specParts[1]
} else {
mid = machineIdSpec
}
}
if !names.IsMachine(mid) {
return nil, fmt.Errorf("invalid force machine id %q", mid)
}
var err error
var m *state.Machine
// If a container is to be used, create it.
if containerType != "" {
// Create the new machine marked as dirty so that
// nothing else will grab it before we assign the unit to it.
template := state.MachineTemplate{
Series: unit.Series(),
Jobs: []state.MachineJob{state.JobHostUnits},
Dirty: true,
IncludeNetworks: includeNetworks,
ExcludeNetworks: excludeNetworks,
}
m, err = st.AddMachineInsideMachine(template, mid, containerType)
} else {
m, err = st.Machine(mid)
}
if err != nil {
return nil, fmt.Errorf("cannot assign unit %q to machine: %v", unit.Name(), err)
}
err = unit.AssignToMachine(m)
if err != nil {
return nil, err
}
} else if err := st.AssignUnit(unit, policy); err != nil {
return nil, err
}
units[i] = unit
}
return units, nil
}