예제 #1
0
파일: vm.go 프로젝트: juito/hyper
func (daemon *Daemon) WaitVmStart(vm *hypervisor.Vm) error {
	Status, err := vm.GetResponseChan()
	if err != nil {
		return err
	}
	defer vm.ReleaseResponseChan(Status)

	vmResponse := <-Status
	glog.V(1).Infof("Get the response from VM, VM id is %s, response code is %d!", vmResponse.VmId, vmResponse.Code)
	if vmResponse.Code != types.E_VM_RUNNING {
		return fmt.Errorf("Vbox does not start successfully")
	}
	return nil
}
예제 #2
0
파일: pod.go 프로젝트: juito/hyper
func (d Docker) ContainerStart(cId string, hostConfig *containertypes.HostConfig) (err error) {
	var vm *hypervisor.Vm

	podId := ""
	if _, ok := d.hyper.CopyPods[cId]; ok {
		podId = d.hyper.CopyPods[cId]
	} else if _, ok := d.hyper.BasicPods[cId]; ok {
		podId = d.hyper.BasicPods[cId]
	} else {
		return fmt.Errorf("container %s doesn't belong to pod", cId)
	}

	defer func() {
		d.hyper.Ready <- true
		if err != nil && d.hyper.Vm != nil {
			if d.hyper.Status != nil {
				d.hyper.Vm.ReleaseResponseChan(d.hyper.Status)
				d.hyper.Status = nil
			}
			glog.Infof("ContainerStart failed, KillVm")
			d.Daemon.KillVm(d.hyper.Vm.Id)
			d.hyper.Vm = nil
		}
	}()

	vmId := "buildevm-" + utils.RandStr(10, "number")
	if vm, err = d.Daemon.StartVm(vmId, 1, 512, false); err != nil {
		return
	}
	d.hyper.Vm = vm

	if d.hyper.Status, err = vm.GetResponseChan(); err != nil {
		return
	}

	if _, _, err = d.Daemon.StartPod(nil, nil, podId, vm.Id, false); err != nil {
		return
	}

	return nil
}