本文整理汇总了Golang中github.com/wallyworld/core/state.State.AddService方法的典型用法代码示例。如果您正苦于以下问题:Golang State.AddService方法的具体用法?Golang State.AddService怎么用?Golang State.AddService使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/wallyworld/core/state.State
的用法示例。
在下文中一共展示了State.AddService方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: DeployService
// DeployService takes a charm and various parameters and deploys it.
func DeployService(st *state.State, args DeployServiceParams) (*state.Service, error) {
if args.NumUnits > 1 && args.ToMachineSpec != "" {
return nil, errors.New("cannot use --num-units with --to")
}
settings, err := args.Charm.Config().ValidateSettings(args.ConfigSettings)
if err != nil {
return nil, err
}
if args.Charm.Meta().Subordinate {
if args.NumUnits != 0 || args.ToMachineSpec != "" {
return nil, fmt.Errorf("subordinate service must be deployed without units")
}
if !constraints.IsEmpty(&args.Constraints) {
return nil, fmt.Errorf("subordinate service must be deployed without constraints")
}
}
if args.ServiceOwner == "" {
args.ServiceOwner = "user-admin"
}
// TODO(fwereade): transactional State.AddService including settings, constraints
// (minimumUnitCount, initialMachineIds?).
service, err := st.AddService(
args.ServiceName,
args.ServiceOwner,
args.Charm,
args.IncludeNetworks,
args.ExcludeNetworks,
)
if err != nil {
return nil, err
}
if len(settings) > 0 {
if err := service.UpdateConfigSettings(settings); err != nil {
return nil, err
}
}
if args.Charm.Meta().Subordinate {
return service, nil
}
if !constraints.IsEmpty(&args.Constraints) {
if err := service.SetConstraints(args.Constraints); err != nil {
return nil, err
}
}
if args.NumUnits > 0 {
if _, err := AddUnits(st, service, args.NumUnits, args.ToMachineSpec); err != nil {
return nil, err
}
}
return service, nil
}