當前位置: 首頁>>代碼示例>>Golang>>正文


Golang state.Service類代碼示例

本文整理匯總了Golang中github.com/wallyworld/core/state.Service的典型用法代碼示例。如果您正苦於以下問題:Golang Service類的具體用法?Golang Service怎麽用?Golang Service使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


在下文中一共展示了Service類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1: 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
}
開發者ID:jameinel,項目名稱:core,代碼行數:28,代碼來源:status.go

示例2: assertForceMachine

// assertForceMachine ensures that the result of assigning a unit with --to
// is as expected.
func (s *AddUnitSuite) assertForceMachine(c *gc.C, svc *state.Service, expectedNumMachines, unitNum int, machineId string) {
    units, err := svc.AllUnits()
    c.Assert(err, gc.IsNil)
    c.Assert(units, gc.HasLen, expectedNumMachines)
    mid, err := units[unitNum].AssignedMachineId()
    c.Assert(err, gc.IsNil)
    c.Assert(mid, gc.Equals, machineId)
}
開發者ID:jameinel,項目名稱:core,代碼行數:10,代碼來源:addunit_test.go

示例3: assertSetSuccess

// assertSetSuccess sets configuration options and checks the expected settings.
func assertSetSuccess(c *gc.C, dir string, svc *state.Service, args []string, expect charm.Settings) {
    ctx := coretesting.ContextForDir(c, dir)
    code := cmd.Main(&SetCommand{}, ctx, append([]string{"dummy-service"}, args...))
    c.Check(code, gc.Equals, 0)
    settings, err := svc.ConfigSettings()
    c.Assert(err, gc.IsNil)
    c.Assert(settings, gc.DeepEquals, expect)
}
開發者ID:jameinel,項目名稱:core,代碼行數:9,代碼來源:set_test.go

示例4: removeAllUnits

func removeAllUnits(c *gc.C, s *state.Service) {
    us, err := s.AllUnits()
    c.Assert(err, gc.IsNil)
    for _, u := range us {
        err = u.EnsureDead()
        c.Assert(err, gc.IsNil)
        err = u.Remove()
        c.Assert(err, gc.IsNil)
    }
}
開發者ID:jameinel,項目名稱:core,代碼行數:10,代碼來源:service_test.go

示例5: serviceSetSettingsStrings

// serviceSetSettingsStrings updates the settings for the given service,
// taking the configuration from a map of strings.
func serviceSetSettingsStrings(service *state.Service, settings map[string]string) error {
    ch, _, err := service.Charm()
    if err != nil {
        return err
    }
    // Parse config in a compatible way (see function comment).
    changes, err := parseSettingsCompatible(ch, settings)
    if err != nil {
        return err
    }
    return service.UpdateConfigSettings(changes)
}
開發者ID:jameinel,項目名稱:core,代碼行數:14,代碼來源:client.go

示例6: addUnit

func (s *runSuite) addUnit(c *gc.C, service *state.Service) *state.Unit {
    unit, err := service.AddUnit()
    c.Assert(err, gc.IsNil)
    err = unit.AssignToNewMachine()
    c.Assert(err, gc.IsNil)
    mId, err := unit.AssignedMachineId()
    c.Assert(err, gc.IsNil)
    machine, err := s.State.Machine(mId)
    c.Assert(err, gc.IsNil)
    machine.SetAddresses(instance.NewAddress("10.3.2.1", instance.NetworkUnknown))
    return unit
}
開發者ID:jameinel,項目名稱:core,代碼行數:12,代碼來源:run_test.go

示例7: AddUnit

func (s *HookContextSuite) AddUnit(c *gc.C, svc *state.Service) *state.Unit {
    unit, err := svc.AddUnit()
    c.Assert(err, gc.IsNil)
    s.machine, err = s.State.AddMachine("quantal", state.JobHostUnits)
    c.Assert(err, gc.IsNil)
    err = unit.AssignToMachine(s.machine)
    c.Assert(err, gc.IsNil)
    name := strings.Replace(unit.Name(), "/", "-", 1)
    privateAddr := instance.NewAddress(name+".testing.invalid", instance.NetworkCloudLocal)
    err = s.machine.SetAddresses(privateAddr)
    c.Assert(err, gc.IsNil)
    return unit
}
開發者ID:jameinel,項目名稱:core,代碼行數:13,代碼來源:context_test.go

示例8: newServiceSetSettingsStringsForClientAPI

// newServiceSetSettingsStringsForClientAPI updates the settings for the given
// service, taking the configuration from a map of strings.
//
// TODO(Nate): replace serviceSetSettingsStrings with this onces the GUI no
// longer expects to be able to unset values by sending an empty string.
func newServiceSetSettingsStringsForClientAPI(service *state.Service, settings map[string]string) error {
    ch, _, err := service.Charm()
    if err != nil {
        return err
    }

    // Validate the settings.
    changes, err := ch.Config().ParseSettingsStrings(settings)
    if err != nil {
        return err
    }

    return service.UpdateConfigSettings(changes)
}
開發者ID:jameinel,項目名稱:core,代碼行數:19,代碼來源:client.go

示例9: assertServiceRelations

func (s *ServiceSuite) assertServiceRelations(c *gc.C, svc *state.Service, expectedKeys ...string) []*state.Relation {
    rels, err := svc.Relations()
    c.Assert(err, gc.IsNil)
    if len(rels) == 0 {
        return nil
    }
    relKeys := make([]string, len(expectedKeys))
    for i, rel := range rels {
        relKeys[i] = rel.String()
    }
    sort.Strings(relKeys)
    c.Assert(relKeys, gc.DeepEquals, expectedKeys)
    return rels
}
開發者ID:jameinel,項目名稱:core,代碼行數:14,代碼來源:service_test.go

示例10: 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
}
開發者ID:jameinel,項目名稱:core,代碼行數:33,代碼來源:status.go

示例11: assertMachines

func (s *DeployLocalSuite) assertMachines(c *gc.C, service *state.Service, expectCons constraints.Value, expectIds ...string) {
    units, err := service.AllUnits()
    c.Assert(err, gc.IsNil)
    c.Assert(units, gc.HasLen, len(expectIds))
    unseenIds := set.NewStrings(expectIds...)
    for _, unit := range units {
        id, err := unit.AssignedMachineId()
        c.Assert(err, gc.IsNil)
        unseenIds.Remove(id)
        machine, err := s.State.Machine(id)
        c.Assert(err, gc.IsNil)
        cons, err := machine.Constraints()
        c.Assert(err, gc.IsNil)
        c.Assert(cons, gc.DeepEquals, expectCons)
    }
    c.Assert(unseenIds, gc.DeepEquals, set.NewStrings())
}
開發者ID:jameinel,項目名稱:core,代碼行數:17,代碼來源:conn_test.go

示例12: serviceSetCharm

// serviceSetCharm sets the charm for the given service.
func (c *Client) serviceSetCharm(service *state.Service, url string, force bool) error {
    curl, err := charm.ParseURL(url)
    if err != nil {
        return err
    }
    sch, err := c.api.state.Charm(curl)
    if errors.IsNotFound(err) {
        // Charms should be added before trying to use them, with
        // AddCharm or AddLocalCharm API calls. When they're not,
        // we're reverting to 1.16 compatibility mode.
        return c.serviceSetCharm1dot16(service, curl, force)
    }
    if err != nil {
        return err
    }
    return service.SetCharm(sch, force)
}
開發者ID:jameinel,項目名稱:core,代碼行數:18,代碼來源:client.go

示例13: serviceSetCharm1dot16

// serviceSetCharm1dot16 sets the charm for the given service in 1.16
// compatibility mode. Remove this when support for 1.16 is dropped.
func (c *Client) serviceSetCharm1dot16(service *state.Service, curl *charm.URL, force bool) error {
    if curl.Schema != "cs" {
        return fmt.Errorf(`charm url has unsupported schema %q`, curl.Schema)
    }
    if curl.Revision < 0 {
        return fmt.Errorf("charm url must include revision")
    }
    err := c.AddCharm(params.CharmURL{curl.String()})
    if err != nil {
        return err
    }
    ch, err := c.api.state.Charm(curl)
    if err != nil {
        return err
    }
    return service.SetCharm(ch, force)
}
開發者ID:jameinel,項目名稱:core,代碼行數:19,代碼來源:client.go

示例14: GetExposed

// GetExposed returns the exposed flag value for each given service.
func (f *FirewallerAPI) GetExposed(args params.Entities) (params.BoolResults, error) {
    result := params.BoolResults{
        Results: make([]params.BoolResult, len(args.Entities)),
    }
    canAccess, err := f.accessService()
    if err != nil {
        return params.BoolResults{}, err
    }
    for i, entity := range args.Entities {
        var service *state.Service
        service, err = f.getService(canAccess, entity.Tag)
        if err == nil {
            result.Results[i].Result = service.IsExposed()
        }
        result.Results[i].Error = common.ServerError(err)
    }
    return result, nil
}
開發者ID:jameinel,項目名稱:core,代碼行數:19,代碼來源:firewaller.go

示例15: 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
}
開發者ID:jameinel,項目名稱:core,代碼行數:19,代碼來源:relation_test.go


注:本文中的github.com/wallyworld/core/state.Service類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。