Skip to content
This repository was archived by the owner on Sep 18, 2020. It is now read-only.

Commit 6e9109e

Browse files
committed
Merge pull request #417 from crawford/vmware
datasource/vmware: allow building on arm systems
2 parents b3f805d + b1bfeed commit 6e9109e

File tree

3 files changed

+126
-82
lines changed

3 files changed

+126
-82
lines changed

datasource/vmware/vmware.go

Lines changed: 0 additions & 82 deletions
Original file line numberDiff line numberDiff line change
@@ -16,18 +16,10 @@ package vmware
1616

1717
import (
1818
"fmt"
19-
"io/ioutil"
20-
"log"
2119
"net"
22-
"os"
2320

2421
"github.com/coreos/coreos-cloudinit/config"
2522
"github.com/coreos/coreos-cloudinit/datasource"
26-
"github.com/coreos/coreos-cloudinit/pkg"
27-
28-
"github.com/coreos/coreos-cloudinit/Godeps/_workspace/src/github.com/sigma/vmw-guestinfo/rpcvmx"
29-
"github.com/coreos/coreos-cloudinit/Godeps/_workspace/src/github.com/sigma/vmw-guestinfo/vmcheck"
30-
"github.com/coreos/coreos-cloudinit/Godeps/_workspace/src/github.com/sigma/vmw-ovflib"
3123
)
3224

3325
type readConfigFunction func(key string) (string, error)
@@ -39,65 +31,6 @@ type vmware struct {
3931
urlDownload urlDownloadFunction
4032
}
4133

42-
type ovfWrapper struct {
43-
env *ovf.OvfEnvironment
44-
}
45-
46-
func (ovf ovfWrapper) readConfig(key string) (string, error) {
47-
return ovf.env.Properties["guestinfo."+key], nil
48-
}
49-
50-
func NewDatasource(fileName string) *vmware {
51-
getOvfReadConfig := func(ovfEnv []byte) readConfigFunction {
52-
env := &ovf.OvfEnvironment{}
53-
if len(ovfEnv) != 0 {
54-
env = ovf.ReadEnvironment(ovfEnv)
55-
}
56-
57-
wrapper := ovfWrapper{env}
58-
return wrapper.readConfig
59-
}
60-
61-
// read from provided ovf environment document (typically /media/ovfenv/ovf-env.xml)
62-
if fileName != "" {
63-
log.Printf("Using OVF environment from %s\n", fileName)
64-
ovfEnv, err := ioutil.ReadFile(fileName)
65-
if err != nil {
66-
ovfEnv = make([]byte, 0)
67-
}
68-
return &vmware{
69-
ovfFileName: fileName,
70-
readConfig: getOvfReadConfig(ovfEnv),
71-
urlDownload: urlDownload,
72-
}
73-
}
74-
75-
// try to read ovf environment from VMware tools
76-
data, err := readConfig("ovfenv")
77-
if err == nil && data != "" {
78-
log.Printf("Using OVF environment from guestinfo\n")
79-
return &vmware{
80-
readConfig: getOvfReadConfig([]byte(data)),
81-
urlDownload: urlDownload,
82-
}
83-
}
84-
85-
// if everything fails, fallback to directly reading variables from the backdoor
86-
log.Printf("Using guestinfo variables\n")
87-
return &vmware{
88-
readConfig: readConfig,
89-
urlDownload: urlDownload,
90-
}
91-
}
92-
93-
func (v vmware) IsAvailable() bool {
94-
if v.ovfFileName != "" {
95-
_, err := os.Stat(v.ovfFileName)
96-
return !os.IsNotExist(err)
97-
}
98-
return vmcheck.IsVirtualWorld()
99-
}
100-
10134
func (v vmware) AvailabilityChanges() bool {
10235
return false
10336
}
@@ -218,18 +151,3 @@ func (v vmware) FetchUserdata() ([]byte, error) {
218151
func (v vmware) Type() string {
219152
return "vmware"
220153
}
221-
222-
func urlDownload(url string) ([]byte, error) {
223-
client := pkg.NewHttpClient()
224-
return client.GetRetry(url)
225-
}
226-
227-
func readConfig(key string) (string, error) {
228-
data, err := rpcvmx.NewConfig().String(key, "")
229-
if err == nil {
230-
log.Printf("Read from %q: %q\n", key, data)
231-
} else {
232-
log.Printf("Failed to read from %q: %v\n", key, err)
233-
}
234-
return data, err
235-
}

datasource/vmware/vmware_amd64.go

Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
// Copyright 2015 CoreOS, Inc.
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
package vmware
16+
17+
import (
18+
"io/ioutil"
19+
"log"
20+
"os"
21+
22+
"github.com/coreos/coreos-cloudinit/pkg"
23+
24+
"github.com/coreos/coreos-cloudinit/Godeps/_workspace/src/github.com/sigma/vmw-guestinfo/rpcvmx"
25+
"github.com/coreos/coreos-cloudinit/Godeps/_workspace/src/github.com/sigma/vmw-guestinfo/vmcheck"
26+
"github.com/coreos/coreos-cloudinit/Godeps/_workspace/src/github.com/sigma/vmw-ovflib"
27+
)
28+
29+
type ovfWrapper struct {
30+
env *ovf.OvfEnvironment
31+
}
32+
33+
func (ovf ovfWrapper) readConfig(key string) (string, error) {
34+
return ovf.env.Properties["guestinfo."+key], nil
35+
}
36+
37+
func NewDatasource(fileName string) *vmware {
38+
// read from provided ovf environment document (typically /media/ovfenv/ovf-env.xml)
39+
if fileName != "" {
40+
log.Printf("Using OVF environment from %s\n", fileName)
41+
ovfEnv, err := ioutil.ReadFile(fileName)
42+
if err != nil {
43+
ovfEnv = make([]byte, 0)
44+
}
45+
return &vmware{
46+
ovfFileName: fileName,
47+
readConfig: getOvfReadConfig(ovfEnv),
48+
urlDownload: urlDownload,
49+
}
50+
}
51+
52+
// try to read ovf environment from VMware tools
53+
data, err := readConfig("ovfenv")
54+
if err == nil && data != "" {
55+
log.Printf("Using OVF environment from guestinfo\n")
56+
return &vmware{
57+
readConfig: getOvfReadConfig([]byte(data)),
58+
urlDownload: urlDownload,
59+
}
60+
}
61+
62+
// if everything fails, fallback to directly reading variables from the backdoor
63+
log.Printf("Using guestinfo variables\n")
64+
return &vmware{
65+
readConfig: readConfig,
66+
urlDownload: urlDownload,
67+
}
68+
}
69+
70+
func (v vmware) IsAvailable() bool {
71+
if v.ovfFileName != "" {
72+
_, err := os.Stat(v.ovfFileName)
73+
return !os.IsNotExist(err)
74+
}
75+
return vmcheck.IsVirtualWorld()
76+
}
77+
78+
func readConfig(key string) (string, error) {
79+
data, err := rpcvmx.NewConfig().String(key, "")
80+
if err == nil {
81+
log.Printf("Read from %q: %q\n", key, data)
82+
} else {
83+
log.Printf("Failed to read from %q: %v\n", key, err)
84+
}
85+
return data, err
86+
}
87+
88+
func getOvfReadConfig (ovfEnv []byte) readConfigFunction {
89+
env := &ovf.OvfEnvironment{}
90+
if len(ovfEnv) != 0 {
91+
env = ovf.ReadEnvironment(ovfEnv)
92+
}
93+
94+
wrapper := ovfWrapper{env}
95+
return wrapper.readConfig
96+
}
97+
98+
func urlDownload(url string) ([]byte, error) {
99+
client := pkg.NewHttpClient()
100+
return client.GetRetry(url)
101+
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
// Copyright 2015 CoreOS, Inc.
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
// +build !amd64
16+
17+
package vmware
18+
19+
func NewDatasource(fileName string) *vmware {
20+
return &vmware{}
21+
}
22+
23+
func (v vmware) IsAvailable() bool {
24+
return false
25+
}

0 commit comments

Comments
 (0)