FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
linuxkit/src/cmd/linuxkit/run_gcp.go at master · linuxkit/linuxkit · GitHub
Uh oh!
There was an error while loading.
Please reload this page
.
linuxkit
/
linuxkit
Public
Notifications
You must be signed in to change notification settings
Fork
1k
Star
8.6k
Code
Issues
330
Pull requests
48
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Issues
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
linuxkit
/
src
/
cmd
/
linuxkit
/
run_gcp.go
Copy path
More file actions
More file actions
Latest commit
History
History
History
108 lines (91 loc) · 3.16 KB
Breadcrumbs
linuxkit
/
src
/
cmd
/
linuxkit
/
run_gcp.go
Copy path
File metadata and controls
108 lines (91 loc) · 3.16 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
package
main
import
(
"errors"
"fmt"
"os"
"github.com/spf13/cobra"
)
const
(
defaultZone
=
"europe-west1-d"
defaultMachine
=
"g1-small"
// Environment variables. Some are non-standard
zoneVar
=
"CLOUDSDK_COMPUTE_ZONE"
machineVar
=
"CLOUDSDK_COMPUTE_MACHINE"
// non-standard
keysVar
=
"CLOUDSDK_COMPUTE_KEYS"
// non-standard
projectVar
=
"CLOUDSDK_CORE_PROJECT"
bucketVar
=
"CLOUDSDK_IMAGE_BUCKET"
// non-standard
familyVar
=
"CLOUDSDK_IMAGE_FAMILY"
// non-standard
publicVar
=
"CLOUDSDK_IMAGE_PUBLIC"
// non-standard
nameVar
=
"CLOUDSDK_IMAGE_NAME"
// non-standard
)
func
runGCPCmd
()
*
cobra.
Command
{
var
(
name
string
zoneFlag
string
machineFlag
string
keysFlag
string
projectFlag
string
skipCleanup
bool
nestedVirt
bool
vTPM
bool
data
string
dataPath
string
)
cmd
:=
&
cobra.
Command
{
Use
:
"gcp"
,
Short
:
"launch a GCP instance"
,
Long
:
`Launch a GCP instance.
'image' specifies either the name of an already uploaded GCP image,
or the full path to a image file which will be uploaded before it is run.
`
,
Args
:
cobra
.
ExactArgs
(
1
),
Example
:
"linuxkit run gcp [options] [image]"
,
RunE
:
func
(
cmd
*
cobra.
Command
,
args
[]
string
)
error
{
image
:=
args
[
0
]
if
data
!=
""
&&
dataPath
!=
""
{
return
errors
.
New
(
"cannot specify both -data and -data-file"
)
}
if
name
==
""
{
name
=
image
}
if
dataPath
!=
""
{
dataB
,
err
:=
os
.
ReadFile
(
dataPath
)
if
err
!=
nil
{
return
fmt
.
Errorf
(
"unable to read metadata file: %v"
,
err
)
}
data
=
string
(
dataB
)
}
zone
:=
getStringValue
(
zoneVar
,
zoneFlag
,
defaultZone
)
machine
:=
getStringValue
(
machineVar
,
machineFlag
,
defaultMachine
)
keys
:=
getStringValue
(
keysVar
,
keysFlag
,
""
)
project
:=
getStringValue
(
projectVar
,
projectFlag
,
""
)
client
,
err
:=
NewGCPClient
(
keys
,
project
)
if
err
!=
nil
{
return
fmt
.
Errorf
(
"unable to connect to GCP: %v"
,
err
)
}
if
err
=
client
.
CreateInstance
(
name
,
image
,
zone
,
machine
,
disks
,
&
data
,
nestedVirt
,
vTPM
,
true
);
err
!=
nil
{
return
err
}
if
err
=
client
.
ConnectToInstanceSerialPort
(
name
,
zone
);
err
!=
nil
{
return
err
}
if
!
skipCleanup
{
if
err
=
client
.
DeleteInstance
(
name
,
zone
,
true
);
err
!=
nil
{
return
err
}
}
return
nil
},
}
cmd
.
Flags
().
StringVar
(
&
name
,
"name"
,
""
,
"Machine name"
)
cmd
.
Flags
().
StringVar
(
&
zoneFlag
,
"zone"
,
defaultZone
,
"GCP Zone"
)
cmd
.
Flags
().
StringVar
(
&
machineFlag
,
"machine"
,
defaultMachine
,
"GCP Machine Type"
)
cmd
.
Flags
().
StringVar
(
&
keysFlag
,
"keys"
,
""
,
"Path to Service Account JSON key file"
)
cmd
.
Flags
().
StringVar
(
&
projectFlag
,
"project"
,
""
,
"GCP Project Name"
)
cmd
.
Flags
().
BoolVar
(
&
skipCleanup
,
"skip-cleanup"
,
false
,
"Don't remove images or VMs"
)
cmd
.
Flags
().
BoolVar
(
&
nestedVirt
,
"nested-virt"
,
false
,
"Enabled nested virtualization"
)
cmd
.
Flags
().
BoolVar
(
&
vTPM
,
"vtpm"
,
false
,
"Enable vTPM device"
)
cmd
.
Flags
().
StringVar
(
&
data
,
"data"
,
""
,
"String of metadata to pass to VM; error to specify both -data and -data-file"
)
cmd
.
Flags
().
StringVar
(
&
dataPath
,
"data-file"
,
""
,
"Path to file containing metadata to pass to VM; error to specify both -data and -data-file"
)
return
cmd
}
Back
|
FazBrowse Home
|
New Git URL