Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
K
k3s
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Jacklull
k3s
Commits
3acb81c7
Commit
3acb81c7
authored
Mar 04, 2019
by
Ben Moss
Committed by
Ryler Hockenbury
Mar 26, 2019
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix Windows to read VM UUIDs from serial numbers
Certain versions of vSphere do not have the same value for product_uuid and product_serial. This mimics the change in #59519. Fixes #74888
parent
b805719a
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
41 additions
and
31 deletions
+41
-31
vsphere_util.go
pkg/cloudprovider/providers/vsphere/vsphere_util.go
+23
-0
vsphere_util_linux.go
pkg/cloudprovider/providers/vsphere/vsphere_util_linux.go
+4
-24
vsphere_util_unsupported.go
...oudprovider/providers/vsphere/vsphere_util_unsupported.go
+1
-1
vsphere_util_windows.go
pkg/cloudprovider/providers/vsphere/vsphere_util_windows.go
+13
-6
No files found.
pkg/cloudprovider/providers/vsphere/vsphere_util.go
View file @
3acb81c7
...
@@ -48,6 +48,7 @@ const (
...
@@ -48,6 +48,7 @@ const (
DummyDiskName
=
"kube-dummyDisk.vmdk"
DummyDiskName
=
"kube-dummyDisk.vmdk"
ProviderPrefix
=
"vsphere://"
ProviderPrefix
=
"vsphere://"
vSphereConfFileEnvVar
=
"VSPHERE_CONF_FILE"
vSphereConfFileEnvVar
=
"VSPHERE_CONF_FILE"
UUIDPrefix
=
"VMware-"
)
)
// GetVSphere reads vSphere configuration from system environment and construct vSphere object
// GetVSphere reads vSphere configuration from system environment and construct vSphere object
...
@@ -675,3 +676,25 @@ func GetNodeUUID(node *v1.Node) (string, error) {
...
@@ -675,3 +676,25 @@ func GetNodeUUID(node *v1.Node) (string, error) {
}
}
return
GetUUIDFromProviderID
(
node
.
Spec
.
ProviderID
),
nil
return
GetUUIDFromProviderID
(
node
.
Spec
.
ProviderID
),
nil
}
}
func
GetVMUUID
()
(
string
,
error
)
{
uuidFromFile
,
err
:=
getRawUUID
()
if
err
!=
nil
{
return
""
,
fmt
.
Errorf
(
"error retrieving vm uuid: %s"
,
err
)
}
//strip leading and trailing white space and new line char
uuid
:=
strings
.
TrimSpace
(
uuidFromFile
)
// check the uuid starts with "VMware-"
if
!
strings
.
HasPrefix
(
uuid
,
UUIDPrefix
)
{
return
""
,
fmt
.
Errorf
(
"Failed to match Prefix, UUID read from the file is %v"
,
uuidFromFile
)
}
// Strip the prefix and white spaces and -
uuid
=
strings
.
Replace
(
uuid
[
len
(
UUIDPrefix
)
:
(
len
(
uuid
))],
" "
,
""
,
-
1
)
uuid
=
strings
.
Replace
(
uuid
,
"-"
,
""
,
-
1
)
if
len
(
uuid
)
!=
32
{
return
""
,
fmt
.
Errorf
(
"Length check failed, UUID read from the file is %v"
,
uuidFromFile
)
}
// need to add dashes, e.g. "564d395e-d807-e18a-cb25-b79f65eb2b9f"
uuid
=
fmt
.
Sprintf
(
"%s-%s-%s-%s-%s"
,
uuid
[
0
:
8
],
uuid
[
8
:
12
],
uuid
[
12
:
16
],
uuid
[
16
:
20
],
uuid
[
20
:
32
])
return
uuid
,
nil
}
pkg/cloudprovider/providers/vsphere/vsphere_util_linux.go
View file @
3acb81c7
...
@@ -19,35 +19,15 @@ limitations under the License.
...
@@ -19,35 +19,15 @@ limitations under the License.
package
vsphere
package
vsphere
import
(
import
(
"fmt"
"io/ioutil"
"io/ioutil"
"strings"
)
)
const
(
const
UUIDPath
=
"/sys/class/dmi/id/product_serial"
UUIDPath
=
"/sys/class/dmi/id/product_serial"
UUIDPrefix
=
"VMware-"
)
func
GetVM
UUID
()
(
string
,
error
)
{
func
getRaw
UUID
()
(
string
,
error
)
{
id
,
err
:=
ioutil
.
ReadFile
(
UUIDPath
)
id
,
err
:=
ioutil
.
ReadFile
(
UUIDPath
)
if
err
!=
nil
{
if
err
!=
nil
{
return
""
,
fmt
.
Errorf
(
"error retrieving vm uuid: %s"
,
err
)
return
""
,
err
}
uuidFromFile
:=
string
(
id
[
:
])
//strip leading and trailing white space and new line char
uuid
:=
strings
.
TrimSpace
(
uuidFromFile
)
// check the uuid starts with "VMware-"
if
!
strings
.
HasPrefix
(
uuid
,
UUIDPrefix
)
{
return
""
,
fmt
.
Errorf
(
"Failed to match Prefix, UUID read from the file is %v"
,
uuidFromFile
)
}
// Strip the prefix and white spaces and -
uuid
=
strings
.
Replace
(
uuid
[
len
(
UUIDPrefix
)
:
(
len
(
uuid
))],
" "
,
""
,
-
1
)
uuid
=
strings
.
Replace
(
uuid
,
"-"
,
""
,
-
1
)
if
len
(
uuid
)
!=
32
{
return
""
,
fmt
.
Errorf
(
"Length check failed, UUID read from the file is %v"
,
uuidFromFile
)
}
}
// need to add dashes, e.g. "564d395e-d807-e18a-cb25-b79f65eb2b9f"
return
string
(
id
),
nil
uuid
=
fmt
.
Sprintf
(
"%s-%s-%s-%s-%s"
,
uuid
[
0
:
8
],
uuid
[
8
:
12
],
uuid
[
12
:
16
],
uuid
[
16
:
20
],
uuid
[
20
:
32
])
return
uuid
,
nil
}
}
pkg/cloudprovider/providers/vsphere/vsphere_util_unsupported.go
View file @
3acb81c7
...
@@ -20,6 +20,6 @@ package vsphere
...
@@ -20,6 +20,6 @@ package vsphere
import
"fmt"
import
"fmt"
func
GetVM
UUID
()
(
string
,
error
)
{
func
getRaw
UUID
()
(
string
,
error
)
{
return
""
,
fmt
.
Errorf
(
"Retrieving VM UUID on this build is not implemented."
)
return
""
,
fmt
.
Errorf
(
"Retrieving VM UUID on this build is not implemented."
)
}
}
pkg/cloudprovider/providers/vsphere/vsphere_util_windows.go
View file @
3acb81c7
...
@@ -24,14 +24,21 @@ import (
...
@@ -24,14 +24,21 @@ import (
"strings"
"strings"
)
)
func
GetVM
UUID
()
(
string
,
error
)
{
func
getRaw
UUID
()
(
string
,
error
)
{
result
,
err
:=
exec
.
Command
(
"wmic"
,
"
csproduct"
,
"get"
,
"UUID
"
)
.
Output
()
result
,
err
:=
exec
.
Command
(
"wmic"
,
"
bios"
,
"get"
,
"serialnumber
"
)
.
Output
()
if
err
!=
nil
{
if
err
!=
nil
{
return
""
,
fmt
.
Errorf
(
"error retrieving vm uuid: %s"
,
err
)
return
""
,
err
}
}
fields
:=
strings
.
Fields
(
string
(
result
))
lines
:=
strings
.
FieldsFunc
(
string
(
result
),
func
(
r
rune
)
bool
{
if
len
(
fields
)
!=
2
{
switch
r
{
case
'\n'
,
'\r'
:
return
true
default
:
return
false
}
})
if
len
(
lines
)
!=
2
{
return
""
,
fmt
.
Errorf
(
"received unexpected value retrieving vm uuid: %q"
,
string
(
result
))
return
""
,
fmt
.
Errorf
(
"received unexpected value retrieving vm uuid: %q"
,
string
(
result
))
}
}
return
field
s
[
1
],
nil
return
line
s
[
1
],
nil
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment