本文整理汇总了Golang中github.com/juju/juju/api/uniter.Unit.CharmURL方法的典型用法代码示例。如果您正苦于以下问题:Golang Unit.CharmURL方法的具体用法?Golang Unit.CharmURL怎么用?Golang Unit.CharmURL使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/juju/juju/api/uniter.Unit
的用法示例。
在下文中一共展示了Unit.CharmURL方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: 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
}