本文整理汇总了Golang中github.com/juju/juju/state.Unit类的典型用法代码示例。如果您正苦于以下问题:Golang Unit类的具体用法?Golang Unit怎么用?Golang Unit使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Unit类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: unitMatchExposure
func unitMatchExposure(u *state.Unit, patterns []string) (bool, bool, error) {
s, err := u.Service()
if err != nil {
return false, false, err
}
return matchExposure(patterns, s)
}
开发者ID:imoapps,项目名称:juju,代码行数:7,代码来源:filtering.go
示例2: HasSubordinates
// HasSubordinates returns the whether each given unit has any subordinates.
func (u *UniterAPIV3) HasSubordinates(args params.Entities) (params.BoolResults, error) {
result := params.BoolResults{
Results: make([]params.BoolResult, len(args.Entities)),
}
canAccess, err := u.accessUnit()
if err != nil {
return params.BoolResults{}, err
}
for i, entity := range args.Entities {
tag, err := names.ParseUnitTag(entity.Tag)
if err != nil {
result.Results[i].Error = common.ServerError(common.ErrPerm)
continue
}
err = common.ErrPerm
if canAccess(tag) {
var unit *state.Unit
unit, err = u.getUnit(tag)
if err == nil {
subordinates := unit.SubordinateNames()
result.Results[i].Result = len(subordinates) > 0
}
}
result.Results[i].Error = common.ServerError(err)
}
return result, nil
}
开发者ID:bac,项目名称:juju,代码行数:28,代码来源:uniter.go
示例3: Resolved
// Resolved returns the current resolved setting for each given unit.
func (u *UniterAPIV3) Resolved(args params.Entities) (params.ResolvedModeResults, error) {
result := params.ResolvedModeResults{
Results: make([]params.ResolvedModeResult, len(args.Entities)),
}
canAccess, err := u.accessUnit()
if err != nil {
return params.ResolvedModeResults{}, err
}
for i, entity := range args.Entities {
tag, err := names.ParseUnitTag(entity.Tag)
if err != nil {
result.Results[i].Error = common.ServerError(common.ErrPerm)
continue
}
err = common.ErrPerm
if canAccess(tag) {
var unit *state.Unit
unit, err = u.getUnit(tag)
if err == nil {
result.Results[i].Mode = params.ResolvedMode(unit.Resolved())
}
}
result.Results[i].Error = common.ServerError(err)
}
return result, nil
}
开发者ID:bac,项目名称:juju,代码行数:27,代码来源:uniter.go
示例4: getMachineForUnit
func (s *SSHCommonSuite) getMachineForUnit(c *gc.C, u *state.Unit) *state.Machine {
machineId, err := u.AssignedMachineId()
c.Assert(err, jc.ErrorIsNil)
m, err := s.State.Machine(machineId)
c.Assert(err, jc.ErrorIsNil)
return m
}
开发者ID:bac,项目名称:juju,代码行数:7,代码来源:ssh_common_test.go
示例5: PrivateAddress
// PrivateAddress returns the private address for each given unit, if set.
func (u *UniterAPIV3) PrivateAddress(args params.Entities) (params.StringResults, error) {
result := params.StringResults{
Results: make([]params.StringResult, len(args.Entities)),
}
canAccess, err := u.accessUnit()
if err != nil {
return params.StringResults{}, err
}
for i, entity := range args.Entities {
tag, err := names.ParseUnitTag(entity.Tag)
if err != nil {
result.Results[i].Error = common.ServerError(common.ErrPerm)
continue
}
err = common.ErrPerm
if canAccess(tag) {
var unit *state.Unit
unit, err = u.getUnit(tag)
if err == nil {
var address network.Address
address, err = unit.PrivateAddress()
if err == nil {
result.Results[i].Result = address.Value
} else if network.IsNoAddressError(err) {
err = common.NoAddressSetError(tag, "private")
}
}
}
result.Results[i].Error = common.ServerError(err)
}
return result, nil
}
开发者ID:bac,项目名称:juju,代码行数:33,代码来源:uniter.go
示例6: ConfigSettings
// ConfigSettings returns the complete set of service charm config
// settings available to each given unit.
func (u *UniterAPIV3) ConfigSettings(args params.Entities) (params.ConfigSettingsResults, error) {
result := params.ConfigSettingsResults{
Results: make([]params.ConfigSettingsResult, len(args.Entities)),
}
canAccess, err := u.accessUnit()
if err != nil {
return params.ConfigSettingsResults{}, err
}
for i, entity := range args.Entities {
tag, err := names.ParseUnitTag(entity.Tag)
if err != nil {
result.Results[i].Error = common.ServerError(common.ErrPerm)
continue
}
err = common.ErrPerm
if canAccess(tag) {
var unit *state.Unit
unit, err = u.getUnit(tag)
if err == nil {
var settings charm.Settings
settings, err = unit.ConfigSettings()
if err == nil {
result.Results[i].Settings = params.ConfigSettings(settings)
}
}
}
result.Results[i].Error = common.ServerError(err)
}
return result, nil
}
开发者ID:bac,项目名称:juju,代码行数:32,代码来源:uniter.go
示例7: ClosePorts
// ClosePorts sets the policy of the port range with protocol to be
// closed, for all given units.
func (u *UniterAPIV3) ClosePorts(args params.EntitiesPortRanges) (params.ErrorResults, error) {
result := params.ErrorResults{
Results: make([]params.ErrorResult, len(args.Entities)),
}
canAccess, err := u.accessUnit()
if err != nil {
return params.ErrorResults{}, err
}
for i, entity := range args.Entities {
tag, err := names.ParseUnitTag(entity.Tag)
if err != nil {
result.Results[i].Error = common.ServerError(common.ErrPerm)
continue
}
err = common.ErrPerm
if canAccess(tag) {
var unit *state.Unit
unit, err = u.getUnit(tag)
if err == nil {
err = unit.ClosePorts(entity.Protocol, entity.FromPort, entity.ToPort)
}
}
result.Results[i].Error = common.ServerError(err)
}
return result, nil
}
开发者ID:bac,项目名称:juju,代码行数:28,代码来源:uniter.go
示例8: waitForUnitStarted
func waitForUnitStarted(stateConn *state.State, unit *state.Unit, c *gc.C) {
timeout := time.After(5 * time.Second)
for {
select {
case <-timeout:
c.Fatalf("no activity detected")
case <-time.After(coretesting.ShortWait):
err := unit.Refresh()
c.Assert(err, gc.IsNil)
st, info, data, err := unit.Status()
c.Assert(err, gc.IsNil)
switch st {
case params.StatusPending, params.StatusInstalled:
c.Logf("waiting...")
continue
case params.StatusStarted:
c.Logf("started!")
return
case params.StatusDown:
stateConn.StartSync()
c.Logf("unit is still down")
default:
c.Fatalf("unexpected status %s %s %v", st, info, data)
}
}
}
}
开发者ID:zhouqt,项目名称:juju,代码行数:28,代码来源:unit_test.go
示例9: waitProvisioned
func (s *MachineSuite) waitProvisioned(c *gc.C, unit *state.Unit) (*state.Machine, instance.Id) {
c.Logf("waiting for unit %q to be provisioned", unit)
machineId, err := unit.AssignedMachineId()
c.Assert(err, gc.IsNil)
m, err := s.State.Machine(machineId)
c.Assert(err, gc.IsNil)
w := m.Watch()
defer w.Stop()
timeout := time.After(coretesting.LongWait)
for {
select {
case <-timeout:
c.Fatalf("timed out waiting for provisioning")
case _, ok := <-w.Changes():
c.Assert(ok, jc.IsTrue)
err := m.Refresh()
c.Assert(err, gc.IsNil)
if instId, err := m.InstanceId(); err == nil {
c.Logf("unit provisioned with instance %s", instId)
return m, instId
} else {
c.Check(err, jc.Satisfies, state.IsNotProvisionedError)
}
}
}
}
开发者ID:klyachin,项目名称:juju,代码行数:26,代码来源:machine_test.go
示例10: unitMatchPort
func unitMatchPort(u *state.Unit, patterns []string) (bool, bool, error) {
portRanges, err := u.OpenedPorts()
if err != nil {
return false, false, err
}
return matchPortRanges(patterns, portRanges...)
}
开发者ID:imoapps,项目名称:juju,代码行数:7,代码来源:filtering.go
示例11: SetCharmURL
// SetCharmURL sets the charm URL for each given unit. An error will
// be returned if a unit is dead, or the charm URL is not know.
func (u *UniterAPIV3) SetCharmURL(args params.EntitiesCharmURL) (params.ErrorResults, error) {
result := params.ErrorResults{
Results: make([]params.ErrorResult, len(args.Entities)),
}
canAccess, err := u.accessUnit()
if err != nil {
return params.ErrorResults{}, err
}
for i, entity := range args.Entities {
tag, err := names.ParseUnitTag(entity.Tag)
if err != nil {
result.Results[i].Error = common.ServerError(common.ErrPerm)
continue
}
err = common.ErrPerm
if canAccess(tag) {
var unit *state.Unit
unit, err = u.getUnit(tag)
if err == nil {
var curl *charm.URL
curl, err = charm.ParseURL(entity.CharmURL)
if err == nil {
err = unit.SetCharmURL(curl)
}
}
}
result.Results[i].Error = common.ServerError(err)
}
return result, nil
}
开发者ID:bac,项目名称:juju,代码行数:32,代码来源:uniter.go
示例12: unitStatus
func unitStatus(u *state.Unit, statusInfo status.StatusInfo) func(*gc.C) bool {
return func(c *gc.C) bool {
sInfo, err := u.Status()
c.Assert(err, jc.ErrorIsNil)
return sInfo.Status == statusInfo.Status && sInfo.Message == statusInfo.Message
}
}
开发者ID:bac,项目名称:juju,代码行数:7,代码来源:deployer_test.go
示例13: PublicAddress
// PublicAddress returns the public address for each given unit, if set.
func (u *uniterBaseAPI) PublicAddress(args params.Entities) (params.StringResults, error) {
result := params.StringResults{
Results: make([]params.StringResult, len(args.Entities)),
}
canAccess, err := u.accessUnit()
if err != nil {
return params.StringResults{}, err
}
for i, entity := range args.Entities {
tag, err := names.ParseUnitTag(entity.Tag)
if err != nil {
result.Results[i].Error = common.ServerError(common.ErrPerm)
continue
}
err = common.ErrPerm
if canAccess(tag) {
var unit *state.Unit
unit, err = u.getUnit(tag)
if err == nil {
address, ok := unit.PublicAddress()
if ok {
result.Results[i].Result = address
} else {
err = common.NoAddressSetError(tag, "public")
}
}
}
result.Results[i].Error = common.ServerError(err)
}
return result, nil
}
开发者ID:claudiu-coblis,项目名称:juju,代码行数:32,代码来源:uniter_base.go
示例14: newAgent
func (s *UnitSuite) newAgent(c *gc.C, unit *state.Unit) *UnitAgent {
a := NewUnitAgent(nil, nil)
s.InitAgent(c, a, "--unit-name", unit.Name(), "--log-to-stderr=true")
err := a.ReadConfig(unit.Tag().String())
c.Assert(err, jc.ErrorIsNil)
return a
}
开发者ID:imoapps,项目名称:juju,代码行数:7,代码来源:unit_test.go
示例15: PrivateAddress
// PrivateAddress returns the private address for each given unit, if set.
func (u *UniterAPI) PrivateAddress(args params.Entities) (params.StringResults, error) {
result := params.StringResults{
Results: make([]params.StringResult, len(args.Entities)),
}
canAccess, err := u.accessUnit()
if err != nil {
return params.StringResults{}, err
}
for i, entity := range args.Entities {
err := common.ErrPerm
if canAccess(entity.Tag) {
var unit *state.Unit
unit, err = u.getUnit(entity.Tag)
if err == nil {
address, ok := unit.PrivateAddress()
if ok {
result.Results[i].Result = address
} else {
err = common.NoAddressSetError(entity.Tag, "private")
}
}
}
result.Results[i].Error = common.ServerError(err)
}
return result, nil
}
开发者ID:rogpeppe,项目名称:juju,代码行数:27,代码来源:uniter.go
示例16: newAgent
func (s *UnitSuite) newAgent(c *gc.C, unit *state.Unit) *UnitAgent {
a := &UnitAgent{}
s.initAgent(c, a, "--unit-name", unit.Name())
err := a.ReadConfig(unit.Tag().String())
c.Assert(err, gc.IsNil)
return a
}
开发者ID:zhouqt,项目名称:juju,代码行数:7,代码来源:unit_test.go
示例17: GetPrincipal
// GetPrincipal returns the result of calling PrincipalName() and
// converting it to a tag, on each given unit.
func (u *UniterAPIV3) GetPrincipal(args params.Entities) (params.StringBoolResults, error) {
result := params.StringBoolResults{
Results: make([]params.StringBoolResult, len(args.Entities)),
}
canAccess, err := u.accessUnit()
if err != nil {
return params.StringBoolResults{}, err
}
for i, entity := range args.Entities {
tag, err := names.ParseUnitTag(entity.Tag)
if err != nil {
result.Results[i].Error = common.ServerError(common.ErrPerm)
continue
}
err = common.ErrPerm
if canAccess(tag) {
var unit *state.Unit
unit, err = u.getUnit(tag)
if err == nil {
principal, ok := unit.PrincipalName()
if principal != "" {
result.Results[i].Result = names.NewUnitTag(principal).String()
}
result.Results[i].Ok = ok
}
}
result.Results[i].Error = common.ServerError(err)
}
return result, nil
}
开发者ID:bac,项目名称:juju,代码行数:32,代码来源:uniter.go
示例18: unitMatchAgentStatus
func unitMatchAgentStatus(u *state.Unit, patterns []string) (bool, bool, error) {
statusInfo, err := u.AgentStatus()
if err != nil {
return false, false, err
}
return matchAgentStatus(patterns, statusInfo.Status)
}
开发者ID:imoapps,项目名称:juju,代码行数:7,代码来源:filtering.go
示例19: TestWatchMeterStatus
// TestWatchMeterStatus tests the meter status watcher functionality.
func TestWatchMeterStatus(c *gc.C, status meterstatus.MeterStatus, unit *jujustate.Unit, state *jujustate.State, resources *common.Resources) {
c.Assert(resources.Count(), gc.Equals, 0)
args := params.Entities{Entities: []params.Entity{
{Tag: unit.UnitTag().String()},
{Tag: "unit-foo-42"},
}}
result, err := status.WatchMeterStatus(args)
c.Assert(err, jc.ErrorIsNil)
c.Assert(result, gc.DeepEquals, params.NotifyWatchResults{
Results: []params.NotifyWatchResult{
{NotifyWatcherId: "1"},
{Error: apiservertesting.ErrUnauthorized},
},
})
// Verify the resource was registered and stop when done
c.Assert(resources.Count(), gc.Equals, 1)
resource := resources.Get("1")
defer statetesting.AssertStop(c, resource)
// Check that the Watch has consumed the initial event ("returned" in
// the Watch call)
wc := statetesting.NewNotifyWatcherC(c, state, resource.(jujustate.NotifyWatcher))
wc.AssertNoChange()
err = unit.SetMeterStatus("GREEN", "No additional information.")
c.Assert(err, jc.ErrorIsNil)
wc.AssertOneChange()
}
开发者ID:howbazaar,项目名称:juju,代码行数:31,代码来源:tests.go
示例20: unitMatchSubnet
func unitMatchSubnet(u *state.Unit, patterns []string) (bool, bool, error) {
pub, pubOK := u.PublicAddress()
priv, privOK := u.PrivateAddress()
if !pubOK && !privOK {
return true, false, nil
}
return matchSubnet(patterns, pub, priv)
}
开发者ID:Pankov404,项目名称:juju,代码行数:8,代码来源:filtering.go
注:本文中的github.com/juju/juju/state.Unit类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论