本文整理匯總了Golang中github.com/juju/juju/api/uniter.Unit.PrivateAddress方法的典型用法代碼示例。如果您正苦於以下問題:Golang Unit.PrivateAddress方法的具體用法?Golang Unit.PrivateAddress怎麽用?Golang Unit.PrivateAddress使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/juju/juju/api/uniter.Unit
的用法示例。
在下文中一共展示了Unit.PrivateAddress方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: NewHookContext
func NewHookContext(
unit *uniter.Unit,
id,
uuid,
envName string,
relationId int,
remoteUnitName string,
relations map[int]*ContextRelation,
apiAddrs []string,
serviceOwner string,
proxySettings proxy.Settings,
actionParams map[string]interface{},
) (*HookContext, error) {
ctx := &HookContext{
unit: unit,
id: id,
uuid: uuid,
envName: envName,
relationId: relationId,
remoteUnitName: remoteUnitName,
relations: relations,
apiAddrs: apiAddrs,
serviceOwner: serviceOwner,
proxySettings: proxySettings,
actionParams: actionParams,
}
// Get and cache the addresses.
var err error
ctx.publicAddress, err = unit.PublicAddress()
if err != nil && !params.IsCodeNoAddressSet(err) {
return nil, err
}
ctx.privateAddress, err = unit.PrivateAddress()
if err != nil && !params.IsCodeNoAddressSet(err) {
return nil, err
}
return ctx, nil
}
示例2: NewHookContext
func NewHookContext(
unit *uniter.Unit,
state *uniter.State,
id,
uuid,
envName string,
relationId int,
remoteUnitName string,
relations map[int]*ContextRelation,
apiAddrs []string,
serviceOwner names.UserTag,
proxySettings proxy.Settings,
canAddMetrics bool,
metrics *charm.Metrics,
actionData *ActionData,
assignedMachineTag names.MachineTag,
paths Paths,
) (*HookContext, error) {
ctx := &HookContext{
unit: unit,
state: state,
id: id,
uuid: uuid,
envName: envName,
unitName: unit.Name(),
relationId: relationId,
remoteUnitName: remoteUnitName,
relations: relations,
apiAddrs: apiAddrs,
serviceOwner: serviceOwner,
proxySettings: proxySettings,
metricsRecorder: nil,
definedMetrics: metrics,
metricsSender: unit,
actionData: actionData,
pendingPorts: make(map[PortRange]PortRangeInfo),
assignedMachineTag: assignedMachineTag,
}
if canAddMetrics {
charmURL, err := unit.CharmURL()
if err != nil {
return nil, err
}
ctx.metricsRecorder, err = NewJSONMetricsRecorder(paths.GetMetricsSpoolDir(), charmURL.String())
if err != nil {
return nil, err
}
ctx.metricsReader, err = NewJSONMetricsReader(paths.GetMetricsSpoolDir())
if err != nil {
return nil, err
}
}
// Get and cache the addresses.
var err error
ctx.publicAddress, err = unit.PublicAddress()
if err != nil && !params.IsCodeNoAddressSet(err) {
return nil, err
}
ctx.privateAddress, err = unit.PrivateAddress()
if err != nil && !params.IsCodeNoAddressSet(err) {
return nil, err
}
ctx.availabilityzone, err = unit.AvailabilityZone()
if err != nil {
return nil, err
}
ctx.machinePorts, err = state.AllMachinePorts(ctx.assignedMachineTag)
if err != nil {
return nil, errors.Trace(err)
}
statusCode, statusInfo, err := unit.MeterStatus()
if err != nil {
return nil, errors.Annotate(err, "could not retrieve meter status for unit")
}
ctx.meterStatus = &meterStatus{
code: statusCode,
info: statusInfo,
}
return ctx, nil
}