本文整理匯總了Golang中github.com/juju/juju/cloudconfig/instancecfg.InstanceConfig.MachineContainerHostname方法的典型用法代碼示例。如果您正苦於以下問題:Golang InstanceConfig.MachineContainerHostname方法的具體用法?Golang InstanceConfig.MachineContainerHostname怎麽用?Golang InstanceConfig.MachineContainerHostname使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/juju/juju/cloudconfig/instancecfg.InstanceConfig
的用法示例。
在下文中一共展示了InstanceConfig.MachineContainerHostname方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: CreateContainer
func (manager *containerManager) CreateContainer(
instanceConfig *instancecfg.InstanceConfig,
cons constraints.Value,
series string,
networkConfig *container.NetworkConfig,
storageConfig *container.StorageConfig,
callback container.StatusCallback,
) (_ instance.Instance, _ *instance.HardwareCharacteristics, err error) {
name, err := manager.namespace.Hostname(instanceConfig.MachineId)
if err != nil {
return nil, nil, errors.Trace(err)
}
defer func() {
if err != nil {
callback(status.ProvisioningError, fmt.Sprintf("Creating container: %v", err), nil)
}
}()
// Set the MachineContainerHostname to match the name returned by virsh list
instanceConfig.MachineContainerHostname = name
// Note here that the kvmObjectFactory only returns a valid container
// object, and doesn't actually construct the underlying kvm container on
// disk.
kvmContainer := KvmObjectFactory.New(name)
// Create the cloud-init.
directory, err := container.NewDirectory(name)
if err != nil {
return nil, nil, errors.Annotate(err, "failed to create container directory")
}
logger.Tracef("write cloud-init")
userDataFilename, err := containerinit.WriteUserData(instanceConfig, networkConfig, directory)
if err != nil {
logger.Infof("machine config api %#v", *instanceConfig.APIInfo)
err = errors.Annotate(err, "failed to write user data")
logger.Infof(err.Error())
return nil, nil, err
}
// Create the container.
startParams = ParseConstraintsToStartParams(cons)
startParams.Arch = arch.HostArch()
startParams.Series = series
startParams.Network = networkConfig
startParams.UserDataFile = userDataFilename
// If the Simplestream requested is anything but released, update
// our StartParams to request it.
if instanceConfig.ImageStream != imagemetadata.ReleasedStream {
startParams.ImageDownloadUrl = imagemetadata.UbuntuCloudImagesURL + "/" + instanceConfig.ImageStream
}
var hardware instance.HardwareCharacteristics
hardware, err = instance.ParseHardware(
fmt.Sprintf("arch=%s mem=%vM root-disk=%vG cores=%v",
startParams.Arch, startParams.Memory, startParams.RootDisk, startParams.CpuCores))
if err != nil {
return nil, nil, errors.Annotate(err, "failed to parse hardware")
}
callback(status.Allocating, "Creating container; it might take some time", nil)
logger.Tracef("create the container, constraints: %v", cons)
if err := kvmContainer.Start(startParams); err != nil {
err = errors.Annotate(err, "kvm container creation failed")
logger.Infof(err.Error())
return nil, nil, err
}
logger.Tracef("kvm container created")
return &kvmInstance{kvmContainer, name}, &hardware, nil
}
示例2: CreateContainer
func (manager *containerManager) CreateContainer(
instanceConfig *instancecfg.InstanceConfig,
series string,
networkConfig *container.NetworkConfig,
storageConfig *container.StorageConfig,
) (instance.Instance, *instance.HardwareCharacteristics, error) {
name := names.NewMachineTag(instanceConfig.MachineId).String()
if manager.name != "" {
name = fmt.Sprintf("%s-%s", manager.name, name)
}
// Set the MachineContainerHostname to match the name returned by virsh list
instanceConfig.MachineContainerHostname = name
// Note here that the kvmObjectFacotry only returns a valid container
// object, and doesn't actually construct the underlying kvm container on
// disk.
kvmContainer := KvmObjectFactory.New(name)
// Create the cloud-init.
directory, err := container.NewDirectory(name)
if err != nil {
return nil, nil, errors.Annotate(err, "failed to create container directory")
}
logger.Tracef("write cloud-init")
userDataFilename, err := containerinit.WriteUserData(instanceConfig, networkConfig, directory)
if err != nil {
logger.Infof("machine config api %#v", *instanceConfig.APIInfo)
err = errors.Annotate(err, "failed to write user data")
logger.Infof(err.Error())
return nil, nil, err
}
// Create the container.
startParams = ParseConstraintsToStartParams(instanceConfig.Constraints)
startParams.Arch = version.Current.Arch
startParams.Series = series
startParams.Network = networkConfig
startParams.UserDataFile = userDataFilename
// If the Simplestream requested is anything but released, update
// our StartParams to request it.
if instanceConfig.ImageStream != imagemetadata.ReleasedStream {
startParams.ImageDownloadUrl = imagemetadata.UbuntuCloudImagesURL + "/" + instanceConfig.ImageStream
}
var hardware instance.HardwareCharacteristics
hardware, err = instance.ParseHardware(
fmt.Sprintf("arch=%s mem=%vM root-disk=%vG cpu-cores=%v",
startParams.Arch, startParams.Memory, startParams.RootDisk, startParams.CpuCores))
if err != nil {
logger.Warningf("failed to parse hardware: %v", err)
}
logger.Tracef("create the container, constraints: %v", instanceConfig.Constraints)
if err := kvmContainer.Start(startParams); err != nil {
err = errors.Annotate(err, "kvm container creation failed")
logger.Infof(err.Error())
return nil, nil, err
}
logger.Tracef("kvm container created")
return &kvmInstance{kvmContainer, name}, &hardware, nil
}