Skip to content
This repository has been archived by the owner on Jun 18, 2022. It is now read-only.

Commit

Permalink
Merge pull request #62 from StrongMonkey/windows-demo
Browse files Browse the repository at this point in the history
Windows support
  • Loading branch information
Craig Jellick authored Oct 28, 2016
2 parents 4143098 + c4d3596 commit 94d5555
Show file tree
Hide file tree
Showing 78 changed files with 4,494 additions and 32 deletions.
2 changes: 1 addition & 1 deletion core/compute/compute.go
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ func DoInstanceActivate(instance model.Instance, host model.Host, progress *prog
containerID := container.ID
created := false
if containerID == "" {
newID, err := createContainer(dockerClient, &config, &hostConfig, imageTag, instance, name, progress)
newID, err := createContainer(dockerClient, &config, &hostConfig, &networkConfig, imageTag, instance, name, progress)
if err != nil {
return errors.Wrap(err, constants.DoInstanceActivateError+"failed to create container")
}
Expand Down
7 changes: 3 additions & 4 deletions core/compute/compute_common.go
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import (
"time"
)

func createContainer(dockerClient *client.Client, config *container.Config, hostConfig *container.HostConfig,
func createContainer(dockerClient *client.Client, config *container.Config, hostConfig *container.HostConfig, networkConfig *network.NetworkingConfig,
imageTag string, instance model.Instance, name string, progress *progress.Progress) (string, error) {
labels := config.Labels
if labels[constants.PullImageLabels] == "always" {
Expand All @@ -43,13 +43,13 @@ func createContainer(dockerClient *client.Client, config *container.Config, host
dockerImage := utils.ParseRepoTag(imageTag)
config.Image = dockerImage.UUID

containerResponse, err := dockerClient.ContainerCreate(context.Background(), config, hostConfig, nil, name)
containerResponse, err := dockerClient.ContainerCreate(context.Background(), config, hostConfig, networkConfig, name)
// if image doesn't exist
if client.IsErrImageNotFound(err) {
if err := storage.PullImage(instance.Image, progress, dockerClient, imageTag); err != nil {
return "", errors.Wrap(err, constants.CreateContainerError+"failed to pull image")
}
containerResponse, err1 := dockerClient.ContainerCreate(context.Background(), config, hostConfig, nil, name)
containerResponse, err1 := dockerClient.ContainerCreate(context.Background(), config, hostConfig, networkConfig, name)
if err1 != nil {
return "", errors.Wrap(err1, constants.CreateContainerError+"failed to create container")
}
Expand Down Expand Up @@ -253,7 +253,6 @@ func setupLegacyCommand(config *container.Config, fields model.InstanceFields, c
}

func setupNetworkingConfig(networkConfig *network.NetworkingConfig, instance model.Instance) {

}

func setupLabels(labels map[string]string, config *container.Config) {
Expand Down
2 changes: 1 addition & 1 deletion core/compute/compute_record.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ func RecordState(client *client.Client, instance model.Instance, dockerID string
}

if ok := utils.IsPathExist(contDir); !ok {
mkErr := os.MkdirAll(contDir, 777)
mkErr := os.MkdirAll(contDir, 644)
if mkErr != nil {
return errors.Wrap(mkErr, constants.RecordStateError+"failed to make directory")
}
Expand Down
Empty file modified core/compute/compute_unix.go
100644 → 100755
Empty file.
4 changes: 4 additions & 0 deletions core/compute/compute_windows.go
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -41,3 +41,7 @@ func setupFieldsHostConfig(fields model.InstanceFields, hostConfig *container.Ho

func setupDeviceOptions(hostConfig *container.HostConfig, instance model.Instance, infoData model.InfoData) {
}

func setupComputeResourceFields(hostConfig *container.HostConfig, instance model.Instance) {

}
2 changes: 0 additions & 2 deletions core/hostInfo/cpu_info.go
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
// +build linux freebsd solaris openbsd darwin

package hostInfo

import (
Expand Down
2 changes: 0 additions & 2 deletions core/hostInfo/disk_info.go
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
// +build linux freebsd solaris openbsd darwin

package hostInfo

import (
Expand Down
2 changes: 1 addition & 1 deletion core/hostInfo/os_c.go
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ func (o OSCollector) KeyName() string {
func (o OSCollector) getOS(infoData model.InfoData) (map[string]string, error) {
data := map[string]string{}
data["operatingSystem"] = infoData.Info.OperatingSystem
kernelVersion, err := utils.GetKernelVersion()
kernelVersion, err := getKernelVersion()
if err != nil {
return map[string]string{}, errors.Wrap(err, constants.GetOSError+"failed to get kernel version")
}
Expand Down
27 changes: 27 additions & 0 deletions core/hostInfo/os_c_unix.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
//+build !windows

package hostInfo

import (
"bufio"
"github.com/pkg/errors"
"github.com/rancher/agent/utilities/constants"
"os"
"regexp"
)

func getKernelVersion() (string, error) {
file, err := os.Open("/proc/version")
defer file.Close()
data := []string{}
if err != nil {
return "", errors.Wrap(err, constants.GetKernelVersionError+"failed to open process version file")
}
scanner := bufio.NewScanner(file)
scanner.Split(bufio.ScanLines)
for scanner.Scan() {
data = append(data, scanner.Text())
}
version := regexp.MustCompile("\\d+.\\d+.\\d+").FindString(data[0])
return version, nil
}
7 changes: 7 additions & 0 deletions core/hostInfo/os_c_windows.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
//+build windows

package hostInfo

func getKernelVersion() (string, error) {
return "", nil
}
1 change: 1 addition & 0 deletions core/storage/storage.go
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package storage

import (
"fmt"

"github.com/Sirupsen/logrus"
engineCli "github.com/docker/engine-api/client"
"github.com/docker/engine-api/types"
Expand Down
Empty file modified handlers/common.go
100644 → 100755
Empty file.
2 changes: 1 addition & 1 deletion service/hostapi/path_windows.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
package hostapi

const execPath string = "c:\\agent\\src\\github.com\\rancher\\host-api\\host-api.exe"
const execPath string = "c:\\host-api.exe"
8 changes: 7 additions & 1 deletion trash.yml
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -57,4 +57,10 @@ import:
version: af2b5127ea65bc380b2e07f2f27829aac2640d65

- package: github.com/ShowMax/go-fqdn
version: 2501cdd51ef4c60dd727c58b2199e1a09466b10f
version: 2501cdd51ef4c60dd727c58b2199e1a09466b10f

- package: github.com/StackExchange/wmi
version: e54cbda6595d7293a7a468ccf9525f6bc8887f99

- package: github.com/go-ole/go-ole
version: 7dfdcf409020452e29b4babcbb22f984d2aa308a
39 changes: 38 additions & 1 deletion utilities/docker/launch_windows.go
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,53 @@ package docker
import (
"fmt"
"github.com/docker/engine-api/client"
dclient "github.com/docker/engine-api/client"
"github.com/docker/go-connections/tlsconfig"
"github.com/pkg/errors"
"github.com/rancher/agent/utilities/constants"
"net/http"
"os"
"path/filepath"
"time"
)

func launchDefaultClient(version string) (*client.Client, error) {
ip := fmt.Sprintf("tcp://%v:2375", os.Getenv("CATTLE_AGENT_IP"))
ip := fmt.Sprintf("tcp://%v:2375", os.Getenv("DEFAULT_GATEWAY"))
cliFromAgent, cerr := client.NewClient(ip, version, nil, nil)
if cerr != nil {
return nil, errors.Wrap(cerr, constants.LaunchDefaultClientError)
}
return cliFromAgent, nil
}

func NewEnvClientWithTimeout(timeout time.Duration) (*dclient.Client, error) {
var client *http.Client
if dockerCertPath := os.Getenv("DOCKER_CERT_PATH"); dockerCertPath != "" {
options := tlsconfig.Options{
CAFile: filepath.Join(dockerCertPath, "ca.pem"),
CertFile: filepath.Join(dockerCertPath, "cert.pem"),
KeyFile: filepath.Join(dockerCertPath, "key.pem"),
InsecureSkipVerify: os.Getenv("DOCKER_TLS_VERIFY") == "",
}
tlsc, err := tlsconfig.Client(options)
if err != nil {
return nil, err
}

client = &http.Client{
Transport: &http.Transport{
TLSClientConfig: tlsc,
},
Timeout: timeout,
}
}

host := fmt.Sprintf("tcp://%v:2375", os.Getenv("DEFAULT_GATEWAY"))

version := os.Getenv("DOCKER_API_VERSION")
if version == "" {
version = dclient.DefaultVersion
}

return dclient.NewClient(host, version, client, nil)
}
2 changes: 1 addition & 1 deletion utilities/utils/response.go
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ func getInstanceHostMapData(event *revents.Event, client *client.Client) (map[st
if err != nil {
return map[string]interface{}{}, errors.Wrap(err, constants.GetInstanceHostMapDataError+"failed to get mount data")
}
dockerIP := inspect.NetworkSettings.IPAddress
dockerIP := getIP(inspect)
if container.Ports != nil && len(container.Ports) > 0 {
for _, port := range container.Ports {
privatePort := fmt.Sprintf("%v/%v", port.PrivatePort, port.Type)
Expand Down
11 changes: 11 additions & 0 deletions utilities/utils/response_unix.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
//+build !windows

package utils

import (
"github.com/docker/engine-api/types"
)

func getIP(inspect types.ContainerJSON) string {
return inspect.NetworkSettings.IPAddress
}
51 changes: 51 additions & 0 deletions utilities/utils/response_windows.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
//+build windows

package utils

import (
"bufio"
"github.com/Sirupsen/logrus"
"github.com/docker/engine-api/types"
"github.com/rancher/agent/utilities/constants"
"github.com/rancher/agent/utilities/docker"
"golang.org/x/net/context"
"regexp"
"strings"
"time"
)

func getIP(inspect types.ContainerJSON) string {
containerID := inspect.ID
client := docker.GetClient(constants.DefaultVersion)
execConfig := types.ExecConfig{
AttachStdout: true,
AttachStdin: true,
AttachStderr: true,
Privileged: true,
Tty: false,
Detach: false,
Cmd: []string{"powershell", "ipconfig"},
}
ip := ""
// waiting for the DHCP to assign IP address. Testing purpose. May try multiple times until ip address arrives
time.Sleep(time.Duration(2) * time.Second)
execObj, err := client.ContainerExecCreate(context.Background(), containerID, execConfig)
if err != nil {
logrus.Error(err)
return ""
}
hijack, err := client.ContainerExecAttach(context.Background(), execObj.ID, execConfig)
if err != nil {
logrus.Error(err)
return ""
}
scanner := bufio.NewScanner(hijack.Reader)
for scanner.Scan() {
output := scanner.Text()
if strings.Contains(output, "IPv4 Address") {
ip = regexp.MustCompile("(?:[0-9]{1,3}\\.){3}[0-9]{1,3}$").FindString(output)
}
}
hijack.Close()
return ip
}
17 changes: 0 additions & 17 deletions utilities/utils/utils.go
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package utils

import (
"bufio"
"encoding/json"
"fmt"
engineCli "github.com/docker/engine-api/client"
Expand Down Expand Up @@ -454,22 +453,6 @@ func SemverTrunk(version string, vals int) string {
return version
}

func GetKernelVersion() (string, error) {
file, err := os.Open("/proc/version")
defer file.Close()
data := []string{}
if err != nil {
return "", errors.Wrap(err, constants.GetKernelVersionError+"failed to open process version file")
}
scanner := bufio.NewScanner(file)
scanner.Split(bufio.ScanLines)
for scanner.Scan() {
data = append(data, scanner.Text())
}
version := regexp.MustCompile("\\d+.\\d+.\\d+").FindString(data[0])
return version, nil
}

func NameFilter(name string, container types.Container) bool {
names := container.Names
if names == nil || len(names) == 0 {
Expand Down
20 changes: 20 additions & 0 deletions vendor/github.com/StackExchange/wmi/LICENSE

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions vendor/github.com/StackExchange/wmi/README.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 94d5555

Please sign in to comment.