How to use boot method of vmware Package

Best Syzkaller code snippet using vmware.boot

vmware_host_connector.go

Source:vmware_host_connector.go Github

copy

Full Screen

...40 COMPONENT_PREFIX = "componentName."41 COMMANDLINE_PREFIX = "commandLine."42 VIM_API_PREFIX = "Vim25Api."43 DETAILS_SUFFIX = "Details"44 BOOT_OPTIONS_PREFIX = "bootOptions."45 BOOT_SECURITY_OPTIONS_PREFIX = "bootSecurityOption."46 VIB_NAME_TYPE_ID = "0x60000001"47 COMMANDLINE_TYPE_ID = "0x60000002"48 OPTIONS_FILE_NAME_TYPE_ID = "0x60000003"49 BOOT_SECURITY_OPTION_TYPE_ID = "0x60000004"50)51func (vc *VmwareConnector) GetHostDetails() (taModel.HostInfo, error) {52 log.Trace("vmware_host_connector :GetHostDetails() Entering")53 defer log.Trace("vmware_host_connector :GetHostDetails() Leaving")54 hostInfo, err := vc.client.GetHostInfo()55 if err != nil {56 return taModel.HostInfo{}, errors.Wrap(err, "vmware_host_connector: GetHostDetails() Error getting host"+57 "info from vmware")58 }59 return hostInfo, nil60}61func (vc *VmwareConnector) GetHostManifest(pcrList []int) (hvs.HostManifest, error) {62 log.Trace("vmware_host_connector :GetHostManifest() Entering")63 defer log.Trace("vmware_host_connector :GetHostManifest() Leaving")64 var err error65 var hostManifest hvs.HostManifest66 var pcrManifest hvs.PcrManifest67 tpmAttestationReport, err := vc.client.GetTPMAttestationReport()68 if err != nil {69 return hvs.HostManifest{}, errors.Wrap(err, "vmware_host_connector: GetHostManifest() Error getting TPM "+70 "attestation report from vcenter API")71 }72 //Check if TPM log is reliable73 if !tpmAttestationReport.Returnval.TpmLogReliable {74 return hvs.HostManifest{}, errors.New("vmware_host_connector: GetHostManifest() TPM log received from" +75 "VMware host is not reliable")76 }77 pcrManifest, pcrsDigest, err := createPCRManifest(tpmAttestationReport.Returnval, pcrList)78 if err != nil {79 return hvs.HostManifest{}, errors.Wrap(err, "vmware_host_connector: GetHostManifest() Error parsing "+80 "PCR manifest from Host Attestation Report")81 }82 hostManifest.HostInfo, err = vc.client.GetHostInfo()83 log.Debugf("Host info received : %v", hostManifest.HostInfo)84 if err != nil {85 return hvs.HostManifest{}, errors.Wrap(err, "vmware_host_connector: GetHostManifest() Error getting host "+86 "info from vcenter API")87 }88 hostManifest.PcrManifest = pcrManifest89 hostManifest.QuoteDigest = pcrsDigest90 return hostManifest, nil91}92func (vc *VmwareConnector) DeployAssetTag(hardwareUUID, tag string) error {93 return errors.New("vmware_host_connector:DeployAssetTag() Operation not supported")94}95func (vc *VmwareConnector) DeploySoftwareManifest(manifest taModel.Manifest) error {96 return errors.New("vmware_host_connector :DeploySoftwareManifest() Operation not supported")97}98func (vc *VmwareConnector) GetMeasurementFromManifest(manifest taModel.Manifest) (taModel.Measurement, error) {99 return taModel.Measurement{}, errors.New("vmware_host_connector :GetMeasurementFromManifest() Operation not supported")100}101func (vc *VmwareConnector) GetClusterReference(clusterName string) ([]mo.HostSystem, error) {102 log.Trace("vmware_host_connector :GetClusterReference() Entering")103 defer log.Trace("vmware_host_connector :GetClusterReference() Leaving")104 hostInfoList, err := vc.client.GetVmwareClusterReference(clusterName)105 if err != nil {106 return nil, errors.Wrap(err, "vmware_host_connector: GetClusterReference() Error getting host"+107 "info from vmware")108 }109 return hostInfoList, nil110}111func createPCRManifest(hostTpmAttestationReport *vim25Types.HostTpmAttestationReport, pcrList []int) (hvs.PcrManifest, string, error) {112 log.Trace("vmware_host_connector :createPCRManifest() Entering")113 defer log.Trace("vmware_host_connector :createPCRManifest() Leaving")114 var pcrManifest hvs.PcrManifest115 pcrManifest.Sha256Pcrs = []hvs.HostManifestPcrs{}116 pcrManifest.Sha1Pcrs = []hvs.HostManifestPcrs{}117 pcrManifest.Sha384Pcrs = []hvs.HostManifestPcrs{}118 var pcrEventLogMap hvs.PcrEventLogMap119 cumulativePcrsValue := ""120 for _, pcrDetails := range hostTpmAttestationReport.TpmPcrValues {121 pcrIndex, err := hvs.GetPcrIndexFromString(strconv.Itoa(int(pcrDetails.PcrNumber)))122 if err != nil {123 return pcrManifest, "", err124 }125 shaAlgorithm, err := hvs.GetSHAAlgorithm(pcrDetails.DigestMethod)126 if err != nil {127 return pcrManifest, "", err128 }129 if strings.EqualFold(pcrDetails.DigestMethod, constants.SHA256) {130 pcrManifest.Sha256Pcrs = append(pcrManifest.Sha256Pcrs, hvs.HostManifestPcrs{131 Index: pcrIndex,132 Value: intArrayToHexString(pcrDetails.DigestValue),133 PcrBank: shaAlgorithm,134 })135 } else if strings.EqualFold(pcrDetails.DigestMethod, constants.SHA1) {136 pcrManifest.Sha1Pcrs = append(pcrManifest.Sha1Pcrs, hvs.HostManifestPcrs{137 Index: pcrIndex,138 Value: intArrayToHexString(pcrDetails.DigestValue),139 PcrBank: shaAlgorithm,140 })141 } else if strings.EqualFold(pcrDetails.DigestMethod, constants.SHA384) {142 pcrManifest.Sha384Pcrs = append(pcrManifest.Sha384Pcrs, hvs.HostManifestPcrs{143 Index: pcrIndex,144 Value: intArrayToHexString(pcrDetails.DigestValue),145 PcrBank: shaAlgorithm,146 })147 } else {148 log.Warn("vmware_host_connector:createPCRManifest() Result PCR invalid")149 }150 }151 pcrEventLogMap, err := getPcrEventLog(hostTpmAttestationReport.TpmEvents, pcrEventLogMap)152 if err != nil {153 log.Errorf("vmware_host_connector:createPCRManifest() Error getting PCR event log : %s", err.Error())154 return pcrManifest, "", errors.Wrap(err, "vmware_host_connector:createPCRManifest() Error getting PCR "+155 "event log")156 }157 //Evaluate digest158 pcrsDigestBytes, err := crypt.GetHashData([]byte(cumulativePcrsValue), crypto.SHA384)159 if err != nil {160 log.Errorf("vmware_host_connector:createPCRManifest() Error evaluating PCRs digest : %s", err.Error())161 return pcrManifest, "", errors.Wrap(err, "vmware_host_connector:createPCRManifest() Error evaluating "+162 "PCRs digest")163 }164 pcrsDigest := hex.EncodeToString(pcrsDigestBytes)165 pcrManifest.PcrEventLogMap = pcrEventLogMap166 return pcrManifest, pcrsDigest, nil167}168func getPcrEventLog(hostTpmEventLogEntry []vim25Types.HostTpmEventLogEntry, eventLogMap hvs.PcrEventLogMap) (hvs.PcrEventLogMap, error) {169 log.Trace("vmware_host_connector:getPcrEventLog() Entering")170 defer log.Trace("vmware_host_connector:getPcrEventLog() Leaving")171 eventLogMap.Sha1EventLogs = []hvs.TpmEventLog{}172 eventLogMap.Sha256EventLogs = []hvs.TpmEventLog{}173 eventLogMap.Sha384EventLogs = []hvs.TpmEventLog{}174 for _, eventLogEntry := range hostTpmEventLogEntry {175 pcrFound := false176 index := 0177 parsedEventLogEntry := types.TpmEvent{}178 //This is done to preserve the dynamic data i.e the info of the event details179 marshalledEntry, err := json.Marshal(eventLogEntry)180 log.Debugf("Marshalled event log : %s", string(marshalledEntry))181 if err != nil {182 return hvs.PcrEventLogMap{}, errors.Wrap(err, "vmware_host_connector:getPcrEventLog() Error "+183 "unmarshalling TPM event")184 }185 //Unmarshal to structure to get the inaccessible fields from event details JSON186 err = json.Unmarshal(marshalledEntry, &parsedEventLogEntry)187 if err != nil {188 return hvs.PcrEventLogMap{}, err189 }190 //vCenter 6.5 only supports SHA1 digest and hence do not have digest method field. Also if the hash is 0 they191 //send out 40 0s instead of 20192 if len(parsedEventLogEntry.EventDetails.DataHash) == sha1.Size || len(parsedEventLogEntry.EventDetails.DataHash) == 40 {193 parsedEventLogEntry.EventDetails.DataHashMethod = constants.SHA1194 for _, entry := range eventLogMap.Sha1EventLogs {195 if entry.Pcr.Index == parsedEventLogEntry.PcrIndex {196 pcrFound = true197 break198 }199 index++200 }201 eventLog := getEventLogInfo(parsedEventLogEntry)202 if !pcrFound {203 eventLogMap.Sha1EventLogs = append(eventLogMap.Sha1EventLogs, hvs.TpmEventLog{Pcr: hvs.Pcr{Index: parsedEventLogEntry.PcrIndex, Bank: string(parsedEventLogEntry.EventDetails.DataHashMethod)}, TpmEvent: []hvs.EventLog{eventLog}})204 } else {205 eventLogMap.Sha1EventLogs[index].TpmEvent = append(eventLogMap.Sha1EventLogs[index].TpmEvent, eventLog)206 }207 } else if len(parsedEventLogEntry.EventDetails.DataHash) == sha256.Size {208 parsedEventLogEntry.EventDetails.DataHashMethod = constants.SHA256209 for _, entry := range eventLogMap.Sha256EventLogs {210 if entry.Pcr.Index == parsedEventLogEntry.PcrIndex {211 pcrFound = true212 break213 }214 index++215 }216 eventLog := getEventLogInfo(parsedEventLogEntry)217 if !pcrFound {218 eventLogMap.Sha256EventLogs = append(eventLogMap.Sha256EventLogs,219 hvs.TpmEventLog{Pcr: hvs.Pcr{Index: parsedEventLogEntry.PcrIndex, Bank: string(parsedEventLogEntry.EventDetails.DataHashMethod)}, TpmEvent: []hvs.EventLog{eventLog}})220 } else {221 eventLogMap.Sha256EventLogs[index].TpmEvent = append(eventLogMap.Sha256EventLogs[index].TpmEvent, eventLog)222 }223 } else if len(parsedEventLogEntry.EventDetails.DataHash) == sha512.Size384 {224 parsedEventLogEntry.EventDetails.DataHashMethod = constants.SHA384225 for _, entry := range eventLogMap.Sha384EventLogs {226 if entry.Pcr.Index == parsedEventLogEntry.PcrIndex {227 pcrFound = true228 break229 }230 index++231 }232 eventLog := getEventLogInfo(parsedEventLogEntry)233 if !pcrFound {234 eventLogMap.Sha384EventLogs = append(eventLogMap.Sha384EventLogs,235 hvs.TpmEventLog{Pcr: hvs.Pcr{Index: parsedEventLogEntry.PcrIndex, Bank: string(parsedEventLogEntry.EventDetails.DataHashMethod)}, TpmEvent: []hvs.EventLog{eventLog}})236 } else {237 eventLogMap.Sha384EventLogs[index].TpmEvent = append(eventLogMap.Sha384EventLogs[index].TpmEvent, eventLog)238 }239 }240 }241 //Sort the event log map so that the PCR indices are in order242 sort.SliceStable(eventLogMap.Sha1EventLogs[:], func(i, j int) bool {243 return fmt.Sprintf("%d", eventLogMap.Sha1EventLogs[i].Pcr.Index) < fmt.Sprintf("%d", eventLogMap.Sha1EventLogs[j].Pcr.Index)244 })245 sort.SliceStable(eventLogMap.Sha256EventLogs[:], func(i, j int) bool {246 return fmt.Sprintf("%d", eventLogMap.Sha256EventLogs[i].Pcr.Index) < fmt.Sprintf("%d", eventLogMap.Sha256EventLogs[j].Pcr.Index)247 })248 sort.SliceStable(eventLogMap.Sha384EventLogs[:], func(i, j int) bool {249 return fmt.Sprintf("%d", eventLogMap.Sha384EventLogs[i].Pcr.Index) < fmt.Sprintf("%d", eventLogMap.Sha384EventLogs[j].Pcr.Index)250 })251 log.Debug("vmware_host_connector:getPcrEventLog() PCR event log created")252 return eventLogMap, nil253}254func intArrayToHexString(pcrDigestArray []int) string {255 log.Trace("vmware_host_connector:intArrayToHexString() Entering")256 defer log.Trace("vmware_host_connector:intArrayToHexString() Leaving")257 var pcrDigestString string258 //if the hash is 0 then vcenter 6.5 API sends out 40 0s instead of 20 for SHA1259 if len(pcrDigestArray) == 40 {260 pcrDigestArray = pcrDigestArray[0:20]261 }262 for _, element := range pcrDigestArray {263 if element < 0 {264 element = 256 + element265 }266 pcrDigestString += fmt.Sprintf("%02x", element)267 }268 return pcrDigestString269}270//It checks the type of TPM event and accordingly updates the event log entry values271func getEventLogInfo(parsedEventLogEntry types.TpmEvent) hvs.EventLog {272 log.Trace("vmware_host_connector:getEventLogInfo() Entering")273 defer log.Trace("vmware_host_connector:getEventLogInfo() Leaving")274 eventLog := hvs.EventLog{Measurement: intArrayToHexString(parsedEventLogEntry.EventDetails.DataHash)}275 if parsedEventLogEntry.EventDetails.VibName != nil {276 eventLog.TypeID = VIB_NAME_TYPE_ID277 eventLog.TypeName = *parsedEventLogEntry.EventDetails.ComponentName278 eventLog.Tags = append(eventLog.Tags, COMPONENT_PREFIX+*parsedEventLogEntry.EventDetails.ComponentName)279 if *parsedEventLogEntry.EventDetails.VibName != "" {280 eventLog.Tags = append(eventLog.Tags, VIM_API_PREFIX+TPM_SOFTWARE_COMPONENT_EVENT_TYPE+DETAILS_SUFFIX+"_"+*parsedEventLogEntry.EventDetails.VibName+"_"+*parsedEventLogEntry.EventDetails.VibVendor)281 } else {282 eventLog.Tags = append(eventLog.Tags, VIM_API_PREFIX+TPM_SOFTWARE_COMPONENT_EVENT_TYPE+DETAILS_SUFFIX)283 }284 } else if parsedEventLogEntry.EventDetails.CommandLine != nil {285 eventLog.TypeID = COMMANDLINE_TYPE_ID286 uuid := getBootUUIDFromCL(*parsedEventLogEntry.EventDetails.CommandLine)287 if uuid != "" {288 eventLog.Tags = append(eventLog.Tags, COMMANDLINE_PREFIX)289 } else {290 eventLog.Tags = append(eventLog.Tags, COMMANDLINE_PREFIX+*parsedEventLogEntry.EventDetails.CommandLine)291 }292 eventLog.TypeName = *parsedEventLogEntry.EventDetails.CommandLine293 eventLog.Tags = append(eventLog.Tags, VIM_API_PREFIX+TPM_COMMAND_EVENT_TYPE+DETAILS_SUFFIX)294 } else if parsedEventLogEntry.EventDetails.OptionsFileName != nil {295 eventLog.TypeID = OPTIONS_FILE_NAME_TYPE_ID296 eventLog.TypeName = *parsedEventLogEntry.EventDetails.OptionsFileName297 eventLog.Tags = append(eventLog.Tags, BOOT_OPTIONS_PREFIX+*parsedEventLogEntry.EventDetails.OptionsFileName)298 eventLog.Tags = append(eventLog.Tags, VIM_API_PREFIX+TPM_OPTION_EVENT_TYPE+DETAILS_SUFFIX)299 } else if parsedEventLogEntry.EventDetails.BootSecurityOption != nil {300 eventLog.TypeID = BOOT_SECURITY_OPTION_TYPE_ID301 eventLog.TypeName = *parsedEventLogEntry.EventDetails.BootSecurityOption302 eventLog.Tags = append(eventLog.Tags, BOOT_SECURITY_OPTIONS_PREFIX+*parsedEventLogEntry.EventDetails.BootSecurityOption)303 eventLog.Tags = append(eventLog.Tags, VIM_API_PREFIX+TPM_BOOT_SECURITY_OPTION_EVENT_TYPE+DETAILS_SUFFIX)304 } else {305 log.Warn("Unrecognized event in module event log")306 }307 return eventLog308}309func getBootUUIDFromCL(commandLine string) string {310 log.Trace("vmware_host_connector:getBootUUIDFromCL() Entering")311 defer log.Trace("vmware_host_connector:getBootUUIDFromCL() Leaving")312 for _, word := range strings.Split(commandLine, " ") {313 if strings.Contains(word, "bootUUID") {314 return strings.Split(word, "=")[1]315 }316 }317 return ""318}...

Full Screen

Full Screen

esxi_test.go

Source:esxi_test.go Github

copy

Full Screen

...6 "encoding/hex"7 "fmt"8 "reflect"9 "testing"10 "github.com/u-root/u-root/pkg/boot"11 "github.com/u-root/u-root/pkg/boot/multiboot"12 "github.com/u-root/u-root/pkg/uio"13)14func TestParse(t *testing.T) {15 for _, tt := range []struct {16 file string17 want options18 }{19 {20 file: "testdata/kernel_cmdline_mods.cfg",21 want: options{22 title: "VMware ESXi",23 kernel: "testdata/b.b00",24 args: "b.b00 zee",25 modules: []module{26 {27 path: "testdata/b.b00",28 cmdline: "b.b00 blabla",29 },30 {31 path: "testdata/k.b00",32 cmdline: "k.b00",33 },34 {35 path: "testdata/m.m00",36 cmdline: "m.m00 marg marg2",37 },38 },39 },40 },41 {42 file: "testdata/kernelopt_first.cfg",43 want: options{44 title: "VMware ESXi",45 kernel: "testdata/b.b00",46 args: "b.b00 zee",47 },48 },49 {50 file: "testdata/empty_mods.cfg",51 want: options{52 title: "VMware ESXi",53 kernel: "testdata/b.b00",54 args: "b.b00 zee",55 },56 },57 {58 file: "testdata/no_mods.cfg",59 want: options{60 title: "VMware ESXi",61 kernel: "testdata/b.b00",62 args: "b.b00 zee",63 },64 },65 {66 file: "testdata/no_cmdline.cfg",67 want: options{68 title: "VMware ESXi",69 kernel: "testdata/b.b00",70 args: "b.b00 ",71 },72 },73 {74 file: "testdata/empty_cmdline.cfg",75 want: options{76 title: "VMware ESXi",77 kernel: "testdata/b.b00",78 args: "b.b00 ",79 },80 },81 {82 file: "testdata/empty_updated.cfg",83 want: options{84 title: "VMware ESXi",85 kernel: "testdata/b.b00",86 args: "b.b00 zee",87 // Explicitly stating this as the wanted value.88 updated: 0,89 },90 },91 {92 file: "testdata/updated_twice.cfg",93 want: options{94 title: "VMware ESXi",95 kernel: "testdata/b.b00",96 args: "b.b00 zee",97 // Explicitly stating this as the wanted value.98 updated: 0,99 },100 },101 {102 file: "testdata/updated.cfg",103 want: options{104 title: "VMware ESXi",105 kernel: "testdata/b.b00",106 args: "b.b00 zee",107 updated: 4,108 },109 },110 {111 file: "testdata/empty_bootstate.cfg",112 want: options{113 title: "VMware ESXi",114 kernel: "testdata/b.b00",115 args: "b.b00 zee",116 // Explicitly stating this as the wanted value.117 bootstate: bootValid,118 },119 },120 {121 file: "testdata/bootstate_twice.cfg",122 want: options{123 title: "VMware ESXi",124 kernel: "testdata/b.b00",125 args: "b.b00 zee",126 // Explicitly stating this as the wanted value.127 bootstate: bootValid,128 },129 },130 {131 file: "testdata/bootstate.cfg",132 want: options{133 title: "VMware ESXi",134 kernel: "testdata/b.b00",135 args: "b.b00 zee",136 bootstate: bootDirty,137 },138 },139 {140 file: "testdata/bootstate_invalid.cfg",141 want: options{142 title: "VMware ESXi",143 kernel: "testdata/b.b00",144 args: "b.b00 zee",145 bootstate: bootInvalid,146 },147 },148 {149 file: "testdata/no_bootstate.cfg",150 want: options{151 title: "VMware ESXi",152 kernel: "testdata/b.b00",153 args: "b.b00 zee",154 bootstate: bootInvalid,155 },156 },157 } {158 got, err := parse(tt.file)159 if err != nil {160 t.Fatalf("cannot parse config at %s: %v", tt.file, err)161 }162 if !reflect.DeepEqual(got, tt.want) {163 t.Errorf("LoadConfig(%s) = %#v want %#v", tt.file, got, tt.want)164 }165 }166}167// This is in the second block of testdata/dev5 and testdata/dev6.168var (169 dev5GUID = "aabbccddeeff0011"170 dev6GUID = "00112233445566aa"171 uuid5 = hex.EncodeToString([]byte(dev5GUID))172 uuid6 = hex.EncodeToString([]byte(dev6GUID))173 device = "testdata/dev"174)175// Poor man's equal.176//177// the Kernel and Modules fields will be full of uio.NewLazyFiles. We just want178// them to be pointing to the same file name; we can't compare the function179// pointers obviously. Lazy files will always print their name.180func multibootEqual(a, b []*boot.MultibootImage) bool {181 return fmt.Sprintf("%v", a) == fmt.Sprintf("%v", b)182}183func TestDev5Valid(t *testing.T) {184 want := []*boot.MultibootImage{185 {186 Name: "VMware ESXi from testdata/dev5",187 Kernel: uio.NewLazyFile("testdata/k"),188 Cmdline: fmt.Sprintf(" bootUUID=%s", uuid5),189 Modules: []multiboot.Module{},190 },191 }192 opts5 := &options{193 title: "VMware ESXi",194 kernel: "testdata/k",195 updated: 1,196 bootstate: bootValid,197 }198 // No opts6 at all.199 imgs, _ := getImages(device, opts5, nil)200 if !multibootEqual(imgs, want) {201 t.Fatalf("getImages(%s, %v, %v) = %v, want %v", device, opts5, nil, imgs, want)202 }203 // Invalid opts6. Higher updated, but invalid state.204 invalidOpts6 := &options{205 title: "VMware ESXi",206 kernel: "foobar",207 updated: 2,208 bootstate: bootInvalid,209 }210 imgs, _ = getImages(device, opts5, invalidOpts6)211 if !multibootEqual(imgs, want) {212 t.Fatalf("getImages(%s, %v, %v) = %v, want %v", device, opts5, invalidOpts6, imgs, want)213 }214}215func TestDev6Valid(t *testing.T) {216 want := []*boot.MultibootImage{217 {218 Name: "VMware ESXi from testdata/dev6",219 Kernel: uio.NewLazyFile("testdata/k"),220 Cmdline: fmt.Sprintf(" bootUUID=%s", uuid6),221 Modules: []multiboot.Module{},222 },223 }224 opts6 := &options{225 title: "VMware ESXi",226 kernel: "testdata/k",227 updated: 1,228 bootstate: bootValid,229 }230 // No opts5 at all.231 imgs, err := getImages(device, nil, opts6)232 if !multibootEqual(imgs, want) {233 t.Fatalf("getImages(%s, %v, %v) = %v, want %v (err %v)", device, nil, opts6, imgs, want, err)234 }235 // Invalid opts5. Higher updated, but invalid state.236 invalidOpts5 := &options{237 title: "VMware ESXi",238 kernel: "foobar",239 updated: 2,240 bootstate: bootInvalid,241 }242 imgs, _ = getImages(device, invalidOpts5, opts6)243 if !multibootEqual(imgs, want) {244 t.Fatalf("getImages(%s, %v, %v) = %v, want %v", device, invalidOpts5, opts6, imgs, want)245 }246}247func TestImageOrder(t *testing.T) {248 prevGetBlockSize := getBlockSize249 defer func() {250 getBlockSize = prevGetBlockSize251 }()252 getBlockSize = func(dev string) (int, error) {253 return 512, nil254 }255 opt5 := &options{256 title: "VMware ESXi",257 kernel: "foobar",258 updated: 2,259 bootstate: bootValid,260 }261 want5 := &boot.MultibootImage{262 Name: "VMware ESXi from testdata/dev5",263 Kernel: uio.NewLazyFile("foobar"),264 Cmdline: fmt.Sprintf(" bootUUID=%s", uuid5),265 Modules: []multiboot.Module{},266 }267 opt6 := &options{268 title: "VMware ESXi",269 kernel: "testdata/k",270 updated: 1,271 bootstate: bootValid,272 }273 want6 := &boot.MultibootImage{274 Name: "VMware ESXi from testdata/dev6",275 Kernel: uio.NewLazyFile("testdata/k"),276 Cmdline: fmt.Sprintf(" bootUUID=%s", uuid6),277 Modules: []multiboot.Module{},278 }279 // Way 1.280 want := []*boot.MultibootImage{want5, want6}281 imgs, _ := getImages(device, opt5, opt6)282 if !multibootEqual(imgs, want) {283 t.Fatalf("getImages(%s, %v, %v) = %v, want %v", device, opt5, opt6, imgs, want)284 }285 opt5.updated = 1286 opt6.updated = 2287 // Vice versa priority.288 want = []*boot.MultibootImage{want6, want5}289 imgs, _ = getImages(device, opt5, opt6)290 if !multibootEqual(imgs, want) {291 t.Fatalf("getImages(%s, %v, %v) = %v, want %v", device, opt5, opt6, imgs, want)292 }293}...

Full Screen

Full Screen

boot.go

Source:boot.go Github

copy

Full Screen

...19 "github.com/vmware/govmomi/govc/flags"20 "github.com/vmware/govmomi/govc/vm"21 "github.com/vmware/govmomi/vim25/types"22)23type boot struct {24 *flags.VirtualMachineFlag25 firmware string26 order string27 types.VirtualMachineBootOptions28}29func init() {30 cli.Register("device.boot", &boot{})31}32func (cmd *boot) Register(ctx context.Context, f *flag.FlagSet) {33 cmd.VirtualMachineFlag, ctx = flags.NewVirtualMachineFlag(ctx)34 cmd.VirtualMachineFlag.Register(ctx, f)35 f.Int64Var(&cmd.BootDelay, "delay", 0, "Delay in ms before starting the boot sequence")36 f.StringVar(&cmd.order, "order", "", "Boot device order [-,floppy,cdrom,ethernet,disk]")37 f.Int64Var(&cmd.BootRetryDelay, "retry-delay", 0, "Delay in ms before a boot retry")38 cmd.BootRetryEnabled = types.NewBool(false)39 f.BoolVar(cmd.BootRetryEnabled, "retry", false, "If true, retry boot after retry-delay")40 cmd.EnterBIOSSetup = types.NewBool(false)41 f.BoolVar(cmd.EnterBIOSSetup, "setup", false, "If true, enter BIOS setup on next boot")42 f.Var(flags.NewOptionalBool(&cmd.EfiSecureBootEnabled), "secure", "Enable EFI secure boot")43 f.StringVar(&cmd.firmware, "firmware", vm.FirmwareTypes[0], vm.FirmwareUsage)44}45func (cmd *boot) Description() string {46 return `Configure VM boot settings.47Examples:48 govc device.boot -vm $vm -delay 1000 -order floppy,cdrom,ethernet,disk49 govc device.boot -vm $vm -order - # reset boot order50 govc device.boot -vm $vm -firmware efi -secure51 govc device.boot -vm $vm -firmware bios -secure=false`52}53func (cmd *boot) Process(ctx context.Context) error {54 if err := cmd.VirtualMachineFlag.Process(ctx); err != nil {55 return err56 }57 return nil58}59func (cmd *boot) Run(ctx context.Context, f *flag.FlagSet) error {60 vm, err := cmd.VirtualMachine()61 if err != nil {62 return err63 }64 if vm == nil {65 return flag.ErrHelp66 }67 devices, err := vm.Device(ctx)68 if err != nil {69 return err70 }71 if cmd.order != "" {72 o := strings.Split(cmd.order, ",")73 cmd.BootOrder = devices.BootOrder(o)...

Full Screen

Full Screen

boot

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 ctx, cancel := context.WithCancel(context.Background())4 defer cancel()5 username := os.Getenv("GOVC_USERNAME")6 password := os.Getenv("GOVC_PASSWORD")7 if username == "" {8 fmt.Println("GOVC_USERNAME is not set")9 os.Exit(1)10 }11 if password == "" {12 fmt.Println("GOVC_PASSWORD is not set")13 os.Exit(1)14 }15 if vmname == "" {16 fmt.Println("vmname is not set")17 os.Exit(1)18 }19 if datacenter == "" {20 fmt.Println("datacenter is not set")21 os.Exit(1)22 }23 if datastore == "" {24 fmt.Println("datastore is not set")25 os.Exit(1)26 }27 if cluster == "" {28 fmt.Println("cluster is not set")29 os.Exit(1)30 }31 if network == "" {32 fmt.Println("network is not set")33 os.Exit(1)34 }35 if datastorepath == "" {36 fmt.Println("datastorepath is not set")37 os.Exit(1)38 }39 if folder == "" {40 fmt.Println("folder is not set")41 os.Exit(1)42 }43 if resourcepool == "" {44 fmt.Println("

Full Screen

Full Screen

boot

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 var vmname = flag.String("vmname", "vmname", "vmname to boot")4 flag.Parse()5 ctx, cancel := context.WithCancel(context.Background())6 defer cancel()

Full Screen

Full Screen

boot

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 ctx, cancel := context.WithCancel(context.Background())4 defer cancel()5 c, _ := govmomi.NewClient(ctx, u, true)6 vm := c.ServiceContent.RootFolder.FindByIp(ctx, nil, "ip", true)7 task, _ := vm.PowerOn(ctx)8 task.Wait(ctx)9 fmt.Println("vm powered on")10 startTime := time.Now()11 for {12 if time.Now().Sub(startTime) > time.Minute*5 {13 }14 vm = c.ServiceContent.RootFolder.FindByIp(ctx, nil, "ip", true)15 if vm.Runtime.PowerState == types.VirtualMachinePowerStatePoweredOn {16 fmt.Println("vm powered on")17 }18 }19 task, _ = vm.RebootGuest(ctx)20 task.Wait(ctx)21 fmt.Println("vm rebooted")22 startTime = time.Now()23 for {24 if time.Now().Sub(startTime) > time.Minute*5 {25 }26 vm = c.ServiceContent.RootFolder.FindByIp(ctx, nil, "ip", true)27 if vm.Runtime.PowerState == types.VirtualMachinePowerStatePoweredOn {28 fmt.Println("vm powered on")29 }30 }31 task, _ = vm.ShutdownGuest(ctx)32 task.Wait(ctx)33 fmt.Println("vm shutdown")34 startTime = time.Now()35 for {36 if time.Now().Sub(startTime) > time.Minute*5 {37 }38 vm = c.ServiceContent.RootFolder.FindByIp(ctx, nil, "ip", true)39 if vm.Runtime.PowerState == types.VirtualMachinePowerStatePoweredOff {40 fmt.Println("vm powered off")41 }42 }43 task, _ = vm.PowerOn(ctx)44 task.Wait(ctx)45 fmt.Println("vm powered on")46 startTime = time.Now()47 for {48 if time.Now().Sub(startTime) > time.Minute*5 {49 }50 vm = c.ServiceContent.RootFolder.FindByIp(ctx, nil, "ip", true)51 if vm.Runtime.PowerState == types.VirtualMachinePowerStatePoweredOn {

Full Screen

Full Screen

boot

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 if len(os.Args) != 5 {4 fmt.Println("Usage: go run 2.go <username> <password> <vcenter_ip> <vm_name>")5 os.Exit(1)6 }7 u := url.URL{8 }9 c, err := govmomi.NewClient(context.Background(), &u, true)10 if err != nil {11 fmt.Println(err)12 os.Exit(1)13 }14 f := find.NewFinder(c.Client, true)15 dc, err := f.DefaultDatacenter(context.Background())16 if err != nil {17 fmt.Println(err)18 os.Exit(1)19 }20 f.SetDatacenter(dc)21 vm, err := f.VirtualMachine(context.Background(), os.Args[4])22 if err != nil {23 fmt.Println(err)24 os.Exit(1)25 }26 t := time.Now()27 bootOptions := &types.VirtualMachineBootOptions{28 BootOrder: []types.VirtualMachineBootOptionsBootableDevice{29 {30 },31 {32 },33 {34 },35 },36 }37 spec := types.VirtualMachineConfigSpec{38 ExtraConfig: []types.BaseOptionValue{39 &types.OptionValue{40 },41 },42 Flags: &types.VirtualMachineFlagInfo{43 ChangeTrackingEnabled: types.NewBool(false

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run Syzkaller automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful