MCPcopy Index your code
hub / github.com/linuxkit/linuxkit / pushVCenterCmd

Function pushVCenterCmd

src/cmd/linuxkit/push_vcenter.go:17–76  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

15)
16
17func pushVCenterCmd() *cobra.Command {
18 var (
19 url string
20 datacenter string
21 datastore string
22 hostname string
23 folder string
24 )
25 cmd := &cobra.Command{
26 Use: "vcenter",
27 Short: "push image to Azure",
28 Long: `Push image to Azure.
29 First argument specifies the full path of an ISO image. It will be pushed to a vCenter cluster.
30 `,
31 Args: cobra.ExactArgs(1),
32 RunE: func(cmd *cobra.Command, args []string) error {
33 filepath := args[0]
34
35 newVM := vmConfig{
36 vCenterURL: &url,
37 dcName: &datacenter,
38 dsName: &datastore,
39 vSphereHost: &hostname,
40 path: &filepath,
41 vmFolder: &folder,
42 }
43
44 ctx, cancel := context.WithCancel(context.Background())
45 defer cancel()
46 // Ensure an iso has been passed to the vCenter push Command
47 if !strings.HasSuffix(*newVM.path, ".iso") {
48 log.Fatalln("Please specify an '.iso' file")
49 }
50
51 // Test any passed in files before uploading image
52 checkFile(*newVM.path)
53
54 // Connect to VMware vCenter and return the values needed to upload image
55 c, dss, _, _, _, _ := vCenterConnect(ctx, newVM)
56
57 // Create a folder from the uploaded image name if needed
58 if *newVM.vmFolder == "" {
59 *newVM.vmFolder = strings.TrimSuffix(path.Base(*newVM.path), ".iso")
60 }
61
62 // The CreateFolder method isn't necessary as the *newVM.vmname will be created automatically
63 uploadFile(c, newVM, dss)
64
65 return nil
66 },
67 }
68
69 cmd.Flags().StringVar(&url, "url", os.Getenv("VCURL"), "URL of VMware vCenter in the format of https://username:password@VCaddress/sdk")
70 cmd.Flags().StringVar(&datacenter, "datacenter", os.Getenv("VCDATACENTER"), "The name of the DataCenter to host the image")
71 cmd.Flags().StringVar(&datastore, "datastore", os.Getenv("VCDATASTORE"), "The name of the DataStore to host the image")
72 cmd.Flags().StringVar(&hostname, "hostname", os.Getenv("VCHOST"), "The server that will host the image")
73 cmd.Flags().StringVar(&folder, "folder", "", "A folder on the datastore to push the image too")
74

Callers 1

pushCmdFunction · 0.85

Calls 3

checkFileFunction · 0.85
vCenterConnectFunction · 0.85
uploadFileFunction · 0.85

Tested by

no test coverage detected