本文整理汇总了Golang中launchpad/net/juju-core/state.State.Service方法的典型用法代码示例。如果您正苦于以下问题:Golang State.Service方法的具体用法?Golang State.Service怎么用?Golang State.Service使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类launchpad/net/juju-core/state.State
的用法示例。
在下文中一共展示了State.Service方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: ServiceGet
// ServiceGet returns the configuration for the named service.
func ServiceGet(st *state.State, p params.ServiceGet) (params.ServiceGetResults, error) {
service, err := st.Service(p.ServiceName)
if err != nil {
return params.ServiceGetResults{}, err
}
settings, err := service.ConfigSettings()
if err != nil {
return params.ServiceGetResults{}, err
}
charm, _, err := service.Charm()
if err != nil {
return params.ServiceGetResults{}, err
}
configInfo := describe(settings, charm.Config())
var constraints constraints.Value
if service.IsPrincipal() {
constraints, err = service.Constraints()
if err != nil {
return params.ServiceGetResults{}, err
}
}
return params.ServiceGetResults{
Service: p.ServiceName,
Charm: charm.Meta().Name,
Config: configInfo,
Constraints: constraints,
}, nil
}
示例2: SetServiceConstraints
// SetServiceContstraints sets the constraints for a given service
func SetServiceConstraints(st *state.State, args params.SetServiceConstraints) error {
svc, err := st.Service(args.ServiceName)
if err != nil {
return err
}
return svc.SetConstraints(args.Constraints)
}
示例3: GetServiceConstraints
// GetServiceConstraints returns the constraints for a given service
func GetServiceConstraints(st *state.State, args params.GetServiceConstraints) (params.GetServiceConstraintsResults, error) {
svc, err := st.Service(args.ServiceName)
if err != nil {
return params.GetServiceConstraintsResults{constraints.Value{}}, err
}
constraints, err := svc.Constraints()
return params.GetServiceConstraintsResults{constraints}, err
}
示例4: opClientServiceExpose
func opClientServiceExpose(c *C, st *api.State, mst *state.State) (func(), error) {
err := st.Client().ServiceExpose("wordpress")
if err != nil {
return func() {}, err
}
return func() {
svc, err := mst.Service("wordpress")
c.Assert(err, IsNil)
svc.ClearExposed()
}, nil
}
示例5: ServiceUnexpose
// ServiceUnexpose changes the juju-managed firewall to unexpose any ports that
// were also explicitly marked by units as open.
func ServiceUnexpose(state *state.State, args params.ServiceUnexpose) error {
svc, err := state.Service(args.ServiceName)
if err != nil {
return err
}
return svc.ClearExposed()
}
示例6: ServiceDestroy
// ServiceDestroy destroys a given service along with all its units and relations.
func ServiceDestroy(state *state.State, args params.ServiceDestroy) error {
svc, err := state.Service(args.ServiceName)
if err != nil {
return err
}
return svc.Destroy()
}
示例7: AddServiceUnits
// AddServiceUnits adds a given number of units to a service.
func AddServiceUnits(state *state.State, args params.AddServiceUnits) ([]*state.Unit, error) {
conn, err := juju.NewConnFromState(state)
if err != nil {
return nil, err
}
service, err := state.Service(args.ServiceName)
if err != nil {
return nil, err
}
if args.NumUnits < 1 {
return nil, errors.New("must add at least one unit")
}
if args.NumUnits > 1 && args.ToMachineSpec != "" {
return nil, errors.New("cannot use --num-units with --to")
}
return conn.AddUnits(service, args.NumUnits, args.ToMachineSpec)
}