本文整理汇总了Golang中launchpad/net/golxc.Container.Name方法的典型用法代码示例。如果您正苦于以下问题:Golang Container.Name方法的具体用法?Golang Container.Name怎么用?Golang Container.Name使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类launchpad/net/golxc.Container
的用法示例。
在下文中一共展示了Container.Name方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: createContainer
func createContainer(
lxcContainer golxc.Container,
directory string,
networkConfig *container.NetworkConfig,
extraCreateArgs, templateParams []string,
caCert []byte,
) error {
// Generate initial lxc.conf with networking settings.
netConfig := generateNetworkConfig(networkConfig)
configPath := filepath.Join(directory, "lxc.conf")
if err := ioutil.WriteFile(configPath, []byte(netConfig), 0644); err != nil {
return errors.Annotatef(err, "failed to write container config %q", configPath)
}
logger.Tracef("wrote initial config %q for container %q", configPath, lxcContainer.Name())
var err error
var execEnv []string = nil
var closer func()
if caCert != nil {
execEnv, closer, err = wgetEnvironment(caCert)
if err != nil {
return errors.Annotatef(err, "failed to get environment for wget execution")
}
defer closer()
}
// Create the container.
logger.Debugf("creating lxc container %q", lxcContainer.Name())
logger.Debugf("lxc-create template params: %v", templateParams)
if err := lxcContainer.Create(configPath, defaultTemplate, extraCreateArgs, templateParams, execEnv); err != nil {
return errors.Annotatef(err, "lxc container creation failed")
}
return nil
}
示例2: contains
func contains(lcs []golxc.Container, lc golxc.Container) bool {
for _, clc := range lcs {
if clc.Name() == lc.Name() {
return true
}
}
return false
}
示例3: CreateContainer
// CreateContainer creates or clones an LXC container.
func (manager *containerManager) CreateContainer(
instanceConfig *instancecfg.InstanceConfig,
series string,
networkConfig *container.NetworkConfig,
storageConfig *container.StorageConfig,
) (inst instance.Instance, _ *instance.HardwareCharacteristics, err error) {
// Check our preconditions
if manager == nil {
panic("manager is nil")
} else if series == "" {
panic("series not set")
} else if networkConfig == nil {
panic("networkConfig is nil")
} else if storageConfig == nil {
panic("storageConfig is nil")
}
// Log how long the start took
defer func(start time.Time) {
if err == nil {
logger.Tracef("container %q started: %v", inst.Id(), time.Now().Sub(start))
}
}(time.Now())
name := names.NewMachineTag(instanceConfig.MachineId).String()
if manager.name != "" {
name = fmt.Sprintf("%s-%s", manager.name, name)
}
// Create the cloud-init.
directory, err := container.NewDirectory(name)
if err != nil {
return nil, nil, errors.Annotate(err, "failed to create a directory for the container")
}
logger.Tracef("write cloud-init")
userDataFilename, err := containerinit.WriteUserData(instanceConfig, networkConfig, directory)
if err != nil {
return nil, nil, errors.Annotate(err, "failed to write user data")
}
var lxcContainer golxc.Container
if manager.createWithClone {
templateContainer, err := EnsureCloneTemplate(
manager.backingFilesystem,
series,
networkConfig,
instanceConfig.AuthorizedKeys,
instanceConfig.AptProxySettings,
instanceConfig.AptMirror,
instanceConfig.EnableOSRefreshUpdate,
instanceConfig.EnableOSUpgrade,
manager.imageURLGetter,
manager.useAUFS,
)
if err != nil {
return nil, nil, errors.Annotate(err, "failed to retrieve the template to clone")
}
templateParams := []string{
"--debug", // Debug errors in the cloud image
"--userdata", userDataFilename, // Our groovey cloud-init
"--hostid", name, // Use the container name as the hostid
}
var extraCloneArgs []string
if manager.backingFilesystem == Btrfs || manager.useAUFS {
extraCloneArgs = append(extraCloneArgs, "--snapshot")
}
if manager.backingFilesystem != Btrfs && manager.useAUFS {
extraCloneArgs = append(extraCloneArgs, "--backingstore", "aufs")
}
lock, err := AcquireTemplateLock(templateContainer.Name(), "clone")
if err != nil {
return nil, nil, errors.Annotate(err, "failed to acquire lock on template")
}
defer lock.Unlock()
// Ensure the run-time effective config of the template
// container has correctly ordered network settings, otherwise
// Clone() below will fail. This is needed in case we haven't
// created a new template now but are reusing an existing one.
// See LP bug #1414016.
configPath := containerConfigFilename(templateContainer.Name())
if _, err := reorderNetworkConfig(configPath); err != nil {
return nil, nil, errors.Annotate(err, "failed to reorder network settings")
}
lxcContainer, err = templateContainer.Clone(name, extraCloneArgs, templateParams)
if err != nil {
return nil, nil, errors.Annotate(err, "lxc container cloning failed")
}
} else {
// Note here that the lxcObjectFacotry only returns a valid container
// object, and doesn't actually construct the underlying lxc container on
// disk.
lxcContainer = LxcObjectFactory.New(name)
templateParams := []string{
"--debug", // Debug errors in the cloud image
"--userdata", userDataFilename, // Our groovey cloud-init
"--hostid", name, // Use the container name as the hostid
//.........这里部分代码省略.........