本文整理匯總了Golang中github.com/juju/juju/core/description.Machine.AddNetworkPorts方法的典型用法代碼示例。如果您正苦於以下問題:Golang Machine.AddNetworkPorts方法的具體用法?Golang Machine.AddNetworkPorts怎麽用?Golang Machine.AddNetworkPorts使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/juju/juju/core/description.Machine
的用法示例。
在下文中一共展示了Machine.AddNetworkPorts方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: newMachine
func (e *exporter) newMachine(exParent description.Machine, machine *Machine, instances map[string]instanceData, portsData []portsDoc) (description.Machine, error) {
args := description.MachineArgs{
Id: machine.MachineTag(),
Nonce: machine.doc.Nonce,
PasswordHash: machine.doc.PasswordHash,
Placement: machine.doc.Placement,
Series: machine.doc.Series,
ContainerType: machine.doc.ContainerType,
}
if supported, ok := machine.SupportedContainers(); ok {
containers := make([]string, len(supported))
for i, containerType := range supported {
containers[i] = string(containerType)
}
args.SupportedContainers = &containers
}
for _, job := range machine.Jobs() {
args.Jobs = append(args.Jobs, job.MigrationValue())
}
// A null value means that we don't yet know which containers
// are supported. An empty slice means 'no containers are supported'.
var exMachine description.Machine
if exParent == nil {
exMachine = e.model.AddMachine(args)
} else {
exMachine = exParent.AddContainer(args)
}
exMachine.SetAddresses(
e.newAddressArgsSlice(machine.doc.MachineAddresses),
e.newAddressArgsSlice(machine.doc.Addresses))
exMachine.SetPreferredAddresses(
e.newAddressArgs(machine.doc.PreferredPublicAddress),
e.newAddressArgs(machine.doc.PreferredPrivateAddress))
// We fully expect the machine to have tools set, and that there is
// some instance data.
instData, found := instances[machine.doc.Id]
if !found {
return nil, errors.NotValidf("missing instance data for machine %s", machine.Id())
}
exMachine.SetInstance(e.newCloudInstanceArgs(instData))
// Find the current machine status.
globalKey := machine.globalKey()
statusArgs, err := e.statusArgs(globalKey)
if err != nil {
return nil, errors.Annotatef(err, "status for machine %s", machine.Id())
}
exMachine.SetStatus(statusArgs)
exMachine.SetStatusHistory(e.statusHistoryArgs(globalKey))
tools, err := machine.AgentTools()
if err != nil {
// This means the tools aren't set, but they should be.
return nil, errors.Trace(err)
}
exMachine.SetTools(description.AgentToolsArgs{
Version: tools.Version,
URL: tools.URL,
SHA256: tools.SHA256,
Size: tools.Size,
})
for _, args := range e.networkPortsArgsForMachine(machine.Id(), portsData) {
exMachine.AddNetworkPorts(args)
}
exMachine.SetAnnotations(e.getAnnotations(globalKey))
constraintsArgs, err := e.constraintsArgs(globalKey)
if err != nil {
return nil, errors.Trace(err)
}
exMachine.SetConstraints(constraintsArgs)
return exMachine, nil
}