本文整理匯總了Golang中github.com/eris-ltd/eris-cli/definitions.Operation類的典型用法代碼示例。如果您正苦於以下問題:Golang Operation類的具體用法?Golang Operation怎麽用?Golang Operation使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
在下文中一共展示了Operation類的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: parseContainers
func parseContainers(service *definitions.Service, ops *definitions.Operation, all bool) bool {
// populate service container specifics
cName := util.FindServiceContainer(service.Name, ops.ContainerNumber, all)
if cName == nil {
return false
}
ops.SrvContainerName = cName.DockersName
ops.SrvContainerID = cName.ContainerID
// populate data container specifics
if service.AutoData && ops.DataContainerID == "" {
dName := util.FindDataContainer(service.Name, ops.ContainerNumber)
if dName != nil {
ops.DataContainerName = dName.DockersName
ops.DataContainerID = dName.ContainerID
}
}
return true
}
示例2: configureServiceContainer
func configureServiceContainer(srv *def.Service, ops *def.Operation) (docker.CreateContainerOptions, error) {
if ops.ContainerNumber == 0 {
ops.ContainerNumber = 1
}
opts := docker.CreateContainerOptions{
Name: ops.SrvContainerName,
Config: &docker.Config{
Hostname: srv.HostName,
Domainname: srv.DomainName,
User: srv.User,
Memory: srv.MemLimit,
CPUShares: srv.CPUShares,
AttachStdin: false,
AttachStdout: false,
AttachStderr: false,
Tty: true,
OpenStdin: false,
Env: srv.Environment,
Labels: ops.Labels,
Cmd: strings.Fields(srv.Command),
Entrypoint: strings.Fields(srv.EntryPoint),
Image: srv.Image,
WorkingDir: srv.WorkDir,
NetworkDisabled: false,
},
HostConfig: &docker.HostConfig{
Binds: srv.Volumes,
Links: srv.Links,
PublishAllPorts: ops.PublishAllPorts,
Privileged: ops.Privileged,
ReadonlyRootfs: false,
DNS: srv.DNS,
DNSSearch: srv.DNSSearch,
VolumesFrom: srv.VolumesFrom,
CapAdd: ops.CapAdd,
CapDrop: ops.CapDrop,
RestartPolicy: docker.NeverRestart(),
NetworkMode: "bridge",
},
}
if ops.Attach {
opts.Config.AttachStdin = true
opts.Config.AttachStdout = true
opts.Config.AttachStderr = true
opts.Config.OpenStdin = true
}
if ops.Restart == "always" {
opts.HostConfig.RestartPolicy = docker.AlwaysRestart()
} else if strings.Contains(ops.Restart, "max") {
times, err := strconv.Atoi(strings.Split(ops.Restart, ":")[1])
if err != nil {
return docker.CreateContainerOptions{}, err
}
opts.HostConfig.RestartPolicy = docker.RestartOnFailure(times)
}
opts.Config.ExposedPorts = make(map[docker.Port]struct{})
opts.HostConfig.PortBindings = make(map[docker.Port][]docker.PortBinding)
opts.Config.Volumes = make(map[string]struct{})
for _, port := range srv.Ports {
pS := strings.Split(port, ":")
pC := docker.Port(util.PortAndProtocol(pS[len(pS)-1]))
if len(pS) > 1 {
pH := docker.PortBinding{
HostPort: pS[len(pS)-2],
}
if len(pS) == 3 {
// ipv4
pH.HostIP = pS[0]
} else if len(pS) > 3 {
// ipv6
pH.HostIP = strings.Join(pS[:len(pS)-2], ":")
}
opts.Config.ExposedPorts[pC] = struct{}{}
opts.HostConfig.PortBindings[pC] = []docker.PortBinding{pH}
} else {
opts.Config.ExposedPorts[pC] = struct{}{}
}
}
for _, vol := range srv.Volumes {
opts.Config.Volumes[strings.Split(vol, ":")[1]] = struct{}{}
}
return opts, nil
}
示例3: OverWriteOperations
// need to be alot smarter with this
func OverWriteOperations(opsBase, opsOver *def.Operation) {
opsBase.SrvContainerName = OverWriteString(opsBase.SrvContainerName, opsOver.SrvContainerName)
opsBase.SrvContainerID = OverWriteString(opsBase.SrvContainerID, opsOver.SrvContainerID)
opsBase.DataContainerName = OverWriteString(opsBase.DataContainerName, opsOver.DataContainerName)
opsBase.DataContainerID = OverWriteString(opsBase.DataContainerID, opsOver.DataContainerID)
opsBase.ContainerNumber = OverWriteInt(opsBase.ContainerNumber, opsOver.ContainerNumber)
opsBase.Restart = OverWriteString(opsBase.Restart, opsOver.Restart)
opsBase.Remove = OverWriteBool(opsBase.Remove, opsOver.Remove)
opsBase.Privileged = OverWriteBool(opsBase.Privileged, opsOver.Privileged)
opsBase.Attach = OverWriteBool(opsBase.Attach, opsOver.Attach)
opsBase.AppName = OverWriteString(opsBase.AppName, opsOver.AppName)
opsBase.DockerHostConn = OverWriteString(opsBase.DockerHostConn, opsOver.DockerHostConn)
opsBase.Labels = MergeMap(opsBase.Labels, opsOver.Labels)
opsBase.PublishAllPorts = OverWriteBool(opsBase.PublishAllPorts, opsOver.PublishAllPorts)
}
示例4: configureServiceContainer
func configureServiceContainer(srv *def.Service, ops *def.Operation) docker.CreateContainerOptions {
if ops.ContainerNumber == 0 {
ops.ContainerNumber = 1
}
opts := docker.CreateContainerOptions{
Name: ops.SrvContainerName,
Config: &docker.Config{
Hostname: srv.HostName,
Domainname: srv.DomainName,
User: srv.User,
Memory: srv.MemLimit,
CPUShares: srv.CPUShares,
AttachStdin: false,
AttachStdout: false,
AttachStderr: false,
Tty: true,
OpenStdin: false,
Env: srv.Environment,
Labels: ops.Labels,
Image: srv.Image,
NetworkDisabled: false,
},
HostConfig: &docker.HostConfig{
Binds: srv.Volumes,
Links: srv.Links,
PublishAllPorts: ops.PublishAllPorts,
Privileged: ops.Privileged,
ReadonlyRootfs: false,
DNS: srv.DNS,
DNSSearch: srv.DNSSearch,
VolumesFrom: srv.VolumesFrom,
CapAdd: ops.CapAdd,
CapDrop: ops.CapDrop,
RestartPolicy: docker.NeverRestart(), //default. overide below
NetworkMode: "bridge",
},
}
// some fields may be set in the dockerfile and we only want to overwrite if they are present in the service def
if srv.EntryPoint != "" {
opts.Config.Entrypoint = strings.Fields(srv.EntryPoint)
}
if srv.Command != "" {
opts.Config.Cmd = strings.Fields(srv.Command)
}
if srv.WorkDir != "" {
opts.Config.WorkingDir = srv.WorkDir
}
//[zr] used to be ops.Restart
if srv.Restart == "always" {
opts.HostConfig.RestartPolicy = docker.AlwaysRestart()
} else if strings.Contains(srv.Restart, "max") {
times, err := strconv.Atoi(strings.Split(srv.Restart, ":")[1])
if err != nil {
return docker.CreateContainerOptions{}
}
opts.HostConfig.RestartPolicy = docker.RestartOnFailure(times)
}
opts.Config.ExposedPorts = make(map[docker.Port]struct{})
opts.HostConfig.PortBindings = make(map[docker.Port][]docker.PortBinding)
opts.Config.Volumes = make(map[string]struct{})
// Don't fill in port bindings if randomizing the ports.
if !ops.PublishAllPorts {
for _, port := range srv.Ports {
pS := strings.Split(port, ":")
pC := docker.Port(util.PortAndProtocol(pS[len(pS)-1]))
opts.Config.ExposedPorts[pC] = struct{}{}
if len(pS) > 1 {
pH := docker.PortBinding{
HostPort: pS[len(pS)-2],
}
if len(pS) == 3 {
// ipv4
pH.HostIP = pS[0]
} else if len(pS) > 3 {
// ipv6
pH.HostIP = strings.Join(pS[:len(pS)-2], ":")
}
opts.HostConfig.PortBindings[pC] = []docker.PortBinding{pH}
} else {
pH := docker.PortBinding{
HostPort: pS[0],
}
opts.HostConfig.PortBindings[pC] = []docker.PortBinding{pH}
}
}
}
for _, vol := range srv.Volumes {
opts.Config.Volumes[strings.Split(vol, ":")[1]] = struct{}{}
}
return opts
//.........這裏部分代碼省略.........