本文整理汇总了Golang中github.com/hyperhq/runv/hypervisor/pod.UserPod类的典型用法代码示例。如果您正苦于以下问题:Golang UserPod类的具体用法?Golang UserPod怎么用?Golang UserPod使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了UserPod类的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: processImageVolumes
func processImageVolumes(config *dockertypes.ContainerJSON, id string, userPod *pod.UserPod, container *pod.UserContainer) {
if config.Config.Volumes == nil {
return
}
existed := make(map[string]bool)
for _, v := range container.Volumes {
existed[v.Path] = true
}
for tgt := range config.Config.Volumes {
if _, ok := existed[tgt]; ok {
continue
}
n := id + strings.Replace(tgt, "/", "_", -1)
v := pod.UserVolume{
Name: n,
Source: "",
}
r := pod.UserVolumeReference{
Volume: n,
Path: tgt,
ReadOnly: false,
}
userPod.Volumes = append(userPod.Volumes, v)
container.Volumes = append(container.Volumes, r)
}
}
示例2: ParseServiceDiscovery
func ParseServiceDiscovery(id string, spec *pod.UserPod) error {
var containers []pod.UserContainer
var serviceType string = "service-discovery"
var serviceDir string = path.Join(utils.HYPER_ROOT, "services", id)
if len(spec.Services) == 0 || spec.Type == serviceType {
return nil
}
spec.Type = serviceType
serviceContainer := pod.UserContainer{
Name: ServiceDiscoveryContainerName(spec.Name),
Image: servicediscovery.ServiceImage,
Command: []string{"haproxy", "-D", "-f", "/usr/local/etc/haproxy/haproxy.cfg", "-p", "/var/run/haproxy.pid"},
}
serviceVolRef := pod.UserVolumeReference{
Volume: "service-volume",
Path: servicediscovery.ServiceVolume,
ReadOnly: false,
}
/* PrepareServices will check service volume */
serviceVolume := pod.UserVolume{
Name: "service-volume",
Source: serviceDir,
Driver: "vfs",
}
spec.Volumes = append(spec.Volumes, serviceVolume)
serviceContainer.Volumes = append(serviceContainer.Volumes, serviceVolRef)
containers = append(containers, serviceContainer)
for _, c := range spec.Containers {
containers = append(containers, c)
}
spec.Containers = containers
return nil
}
示例3: processImageVolumes
func processImageVolumes(config *dockertypes.ContainerJSONRaw, id string, userPod *pod.UserPod, container *pod.UserContainer) {
if config.Config.Volumes == nil {
return
}
for tgt := range config.Config.Volumes {
n := id + strings.Replace(tgt, "/", "_", -1)
v := pod.UserVolume{
Name: n,
Source: "",
}
r := pod.UserVolumeReference{
Volume: n,
Path: tgt,
ReadOnly: false,
}
userPod.Volumes = append(userPod.Volumes, v)
container.Volumes = append(container.Volumes, r)
}
}
示例4: processImageVolumes
func processImageVolumes(config *dockertypes.ContainerJSONRaw, id string, userPod *pod.UserPod, container *pod.UserContainer) {
if config.Config.Volumes == nil {
return
}
for tgt := range config.Config.Volumes {
n := id + "-" + tgt
v := pod.UserVolume{
Name: n,
Source: "",
Driver: "vfs", //will check if it should equal to the storage engine, and it should be reclaim after
//after the container finished
}
r := pod.UserVolumeReference{
Volume: n,
Path: tgt,
ReadOnly: false,
}
userPod.Volumes = append(userPod.Volumes, v)
container.Volumes = append(container.Volumes, r)
}
}
示例5: CreatePod
func (daemon *Daemon) CreatePod(podId, podArgs string, config interface{}, autoremove bool) (err error) {
glog.V(1).Infof("podArgs: %s", podArgs)
var (
userPod *pod.UserPod
containerIds []string
cId []byte
)
userPod, err = pod.ProcessPodBytes([]byte(podArgs))
if err != nil {
glog.V(1).Infof("Process POD file error: %s", err.Error())
return err
}
if err = userPod.Validate(); err != nil {
return err
}
mypod := hypervisor.NewPod(podId, userPod)
mypod.Handler.Handle = hyperHandlePodEvent
mypod.Handler.Data = daemon
mypod.Autoremove = autoremove
defer func() {
if err != nil {
if containerIds == nil {
daemon.DeletePodFromDB(podId)
if mypod != nil {
for _, c := range mypod.Containers {
glog.V(1).Infof("Ready to rm container: %s", c.Id)
if _, _, err = daemon.DockerCli.SendCmdDelete(c.Id); err != nil {
glog.Warningf("Error to rm container: %s", err.Error())
}
}
}
daemon.RemovePod(podId)
daemon.DeletePodContainerFromDB(podId)
}
}
}()
// store the UserPod into the db
if err = daemon.WritePodToDB(podId, []byte(podArgs)); err != nil {
glog.V(1).Info("Found an error while saveing the POD file")
return err
}
containerIds, err = daemon.GetPodContainersByName(podId)
if err != nil {
glog.V(1).Info(err.Error())
}
if containerIds != nil {
for _, id := range containerIds {
var (
name string
image string
)
if jsonResponse, err := daemon.DockerCli.GetContainerInfo(id); err == nil {
name = jsonResponse.Name
image = jsonResponse.Config.Image
}
mypod.AddContainer(id, name, image, []string{}, types.S_POD_CREATED)
}
} else {
// Process the 'Containers' section
glog.V(1).Info("Process the Containers section in POD SPEC\n")
for _, c := range userPod.Containers {
imgName := c.Image
cId, _, err = daemon.DockerCli.SendCmdCreate(c.Name, imgName, []string{}, nil)
if err != nil {
glog.Error(err.Error())
return err
}
var (
name string
image string
)
if jsonResponse, err := daemon.DockerCli.GetContainerInfo(string(cId)); err == nil {
name = jsonResponse.Name
image = jsonResponse.Config.Image
}
mypod.AddContainer(string(cId), name, image, []string{}, types.S_POD_CREATED)
}
}
daemon.AddPod(mypod)
if err = daemon.WritePodAndContainers(podId); err != nil {
glog.V(1).Info("Found an error while saveing the Containers info")
return err
}
return nil
}
示例6: convertToRunvPodSpec
// TODO: remove convertToRunvPodSpec after pod.UserPod is deleted from runv
func convertToRunvPodSpec(podSpec *apitypes.UserPod) (*pod.UserPod, error) {
var userPod pod.UserPod
userPod.Name = podSpec.Id
if podSpec.Id == "" {
userPod.Name = utils.RandStr(10, "alphanum")
}
if podSpec.PortmappingWhiteLists != nil {
for _, cidr := range podSpec.PortmappingWhiteLists.ExternalNetworks {
_, _, err := net.ParseCIDR(cidr)
if err != nil {
return nil, fmt.Errorf("PortmappingWhiteLists.ExternalNetwork %s format error", cidr)
}
}
filteredInternalNetworks := make([]string, 0)
for _, cidr := range podSpec.PortmappingWhiteLists.InternalNetworks {
_, _, err := net.ParseCIDR(cidr)
if err != nil {
return nil, fmt.Errorf("PortmappingWhiteLists.InternalNetworks %s format error", cidr)
}
// filter cidr out if the cidr is also in ExternalNetworks
found := false
for _, ext := range podSpec.PortmappingWhiteLists.ExternalNetworks {
if cidr == ext {
found = true
break
}
}
if !found {
filteredInternalNetworks = append(filteredInternalNetworks, cidr)
}
}
userPod.PortmappingWhiteLists = &pod.PortmappingWhiteList{
InternalNetworks: filteredInternalNetworks,
ExternalNetworks: podSpec.PortmappingWhiteLists.ExternalNetworks,
}
}
userPod.Hostname = podSpec.Hostname
userPod.Type = podSpec.Type
userPod.RestartPolicy = podSpec.RestartPolicy
userPod.Dns = podSpec.Dns
userPod.Tty = podSpec.Tty
userPod.Labels = podSpec.Labels
if podSpec.Labels == nil {
userPod.Labels = make(map[string]string)
}
if podSpec.Resource != nil {
userPod.Resource = pod.UserResource{
Vcpu: int(podSpec.Resource.Vcpu),
Memory: int(podSpec.Resource.Memory),
}
}
if userPod.Resource.Vcpu == 0 {
userPod.Resource.Vcpu = 1
}
if userPod.Resource.Memory == 0 {
userPod.Resource.Memory = 128
}
if len(podSpec.Containers) > 0 {
containers := make([]pod.UserContainer, 0, len(podSpec.Containers))
for _, v := range podSpec.Containers {
if v.Image == "" {
return nil, fmt.Errorf("Please specific your image for your container, it can not be null!\n")
}
containers = append(containers, convertToRunvContainerSpec(v, userPod.Tty))
}
userPod.Containers = containers
}
if len(podSpec.Files) > 0 {
files := make([]pod.UserFile, 0, len(podSpec.Files))
for _, f := range podSpec.Files {
files = append(files, pod.UserFile{
Name: f.Name,
Encoding: f.Encoding,
Uri: f.Uri,
Contents: f.Content,
})
}
userPod.Files = files
}
if len(podSpec.Volumes) > 0 {
vols := make([]pod.UserVolume, 0, len(podSpec.Volumes))
for _, vol := range podSpec.Volumes {
if vol.Name == "" {
return nil, fmt.Errorf("Hyper ERROR: please specific your volume name, it can not be null!\n")
}
v := pod.UserVolume{
//.........这里部分代码省略.........