• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Golang wsman.Client类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Golang中github.com/VictorLowther/wsman.Client的典型用法代码示例。如果您正苦于以下问题:Golang Client类的具体用法?Golang Client怎么用?Golang Client使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



在下文中一共展示了Client类的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。

示例1: waitForJob

func waitForJob(client *wsman.Client, jobinfo *dom.Element) bool {
	jobID := string(search.First(search.Attr("Name", "*", "InstanceID"), jobinfo.All()).Content)
	log.Printf("%s: Waiting for job %s to finish\n", client.Endpoint(), jobID)
	var code string
	ret := false
	for {
		time.Sleep(10 * time.Second)
		msg := client.Get("http://schemas.dell.com/wbem/wscim/1/cim-schema/2/DCIM_LifecycleJob")
		msg.Selectors("InstanceID", jobID)
		res, err := msg.Send()
		if err != nil {
			log.Printf("Error monitoring job: %v\n", err)
			if res != nil {
				log.Printf("Response: %s\n", res.String())
			}
			goto out
		}
		code = strings.TrimSpace(
			string(search.First(
				search.Tag("JobStatus", "*"),
				res.AllBodyElements()).Content))
		switch code {
		case "Completed":
			ret = true
			goto out
		case "Completed with Errors":
			goto out
		case "Failed":
			goto out
		}
	}
out:
	log.Printf("Job %s finished with %s\n", jobID, code)
	return ret
}
开发者ID:dell-esg,项目名称:idracula,代码行数:35,代码来源:main.go


示例2: getCPU

func getCPU(client *wsman.Client) string {
	msg := client.Enumerate("http://schemas.dell.com/wbem/wscim/1/cim-schema/2/DCIM_CPUView")
	msg.Selectors("InstanceID", "System.Embedded.1")
	res, err := msg.Send()
	if err != nil {
		log.Printf("Error getting cpus: %v\n", err)
		return "-1"
	}
	activeCores := 0
	procs := search.All(search.Tag("DCIM_CPUView", "*"), res.AllBodyElements())
	for _, proc := range procs {
		cores := search.First(search.Tag("NumberOfEnabledCores", "*"), proc.Children())
		if cores == nil {
			log.Println("Could not find number of enabled cores!")
			os.Exit(1)
		}
		count, err := strconv.Atoi(string(cores.Content))
		if err != nil {
			log.Println("Error parsing %s into an integer\n", string(cores.Content))
			os.Exit(1)
		}
		activeCores += count
	}
	return strconv.Itoa(activeCores)
}
开发者ID:dell-esg,项目名称:idracula,代码行数:25,代码来源:main.go


示例3: getDisk

func getDisk(client *wsman.Client) string {
	msg := client.Enumerate("http://schemas.dell.com/wbem/wscim/1/cim-schema/2/DCIM_VirtualDiskView")
	msg.Selectors("InstanceID", "System.Embedded.1")
	res, err := msg.Send()
	if err != nil {
		log.Printf("Error getting disks: %v\n", err)
		return "-1"
	}
	vds := search.All(search.Tag("DCIM_VirtualDiskView", "*"), res.AllBodyElements())
	return strconv.Itoa(len(vds))
}
开发者ID:cdearborn,项目名称:idracula,代码行数:11,代码来源:main.go


示例4: getMemory

func getMemory(client *wsman.Client) string {
	msg := client.Enumerate("http://schemas.dell.com/wbem/wscim/1/cim-schema/2/DCIM_SystemView")
	msg.Selectors("InstanceID", "System.Embedded.1")
	res, err := msg.Send()
	if err != nil {
		log.Printf("Error getting memory: %v\n", err)
		return "-1"
	}
	n := search.First(search.Tag("SysMemTotalSize", "*"), res.AllBodyElements())
	if n == nil {
		log.Println("Could not find total system memory")
		return "-1"
	}
	return string(n.Content)
}
开发者ID:dell-esg,项目名称:idracula,代码行数:15,代码来源:main.go


示例5: getMAC

func getMAC(client *wsman.Client) string {
	msg := client.Enumerate("http://schemas.dell.com/wbem/wscim/1/cim-schema/2/DCIM_NICView")
	msg.Selectors("InstanceID", "System.Embedded.1")
	res, err := msg.Send()
	if err != nil {
		log.Printf("Error getting nics: %v\n", err)
		return ""
	}
	bootnic := getBootNic(client,
		search.All(search.Tag("DCIM_NICView", "*"), res.AllBodyElements()))
	if bootnic == nil {
		return ""
	}
	return strings.ToLower(
		string(search.First(
			search.Tag("CurrentMACAddress", "*"),
			bootnic.Children()).Content))
}
开发者ID:dell-esg,项目名称:idracula,代码行数:18,代码来源:main.go


示例6: hasIdrac

func hasIdrac(client *wsman.Client) bool {
	res, err := client.Identify()
	if err != nil {
		log.Printf("No WSMAN endpoint at %s\n", client.Endpoint())
		return false
	}
	n := search.First(search.Tag("ProductName", "*"), res.AllBodyElements())
	if n != nil && string(n.Content) == "iDRAC" {
		log.Printf("Found iDRAC at %s\n", client.Endpoint())
		return true
	}
	log.Printf("No iDRAC at WSMAN endpoint %s\n", client.Endpoint())
	return false
}
开发者ID:dell-esg,项目名称:idracula,代码行数:14,代码来源:main.go


示例7: getDisk

func getDisk(client *wsman.Client) string {
	msg := client.Enumerate("http://schemas.dell.com/wbem/wscim/1/cim-schema/2/DCIM_VirtualDiskView")
	msg.Selectors("InstanceID", "System.Embedded.1")
	res, err := msg.Send()
	if err != nil {
		log.Printf("Error getting disks: %v\n", err)
		return "-1"
	}
	vd := search.First(search.Tag("DCIM_VirtualDiskView", "*"), res.AllBodyElements())
	if vd == nil {
		log.Printf("Error getting first disk information\n")
		return "-1"
	}
	sizeBytes := search.First(search.Tag("SizeInBytes", "*"), vd.Children())
	if sizeBytes == nil {
		log.Printf("Error getting first disk size\n")
		return "-1"
	}
	count, err := strconv.Atoi(string(sizeBytes.Content))
	sizeGBytes := count / (1024 * 1024 * 1024)
	return strconv.Itoa(sizeGBytes)
}
开发者ID:dell-esg,项目名称:idracula,代码行数:22,代码来源:main.go


示例8: getBootNic

func getBootNic(client *wsman.Client, nics []*dom.Element) *dom.Element {
	fqdds := []string{}
	for _, nic := range nics {
		n := search.First(search.Tag("FQDD", "*"), nic.Children())
		if n == nil {
			log.Printf("Nic did not contain an FQDD")
			os.Exit(1)
		}
		fqdd := string(n.Content) // Only care about integrated nics
		if !strings.HasPrefix(fqdd, "NIC.Integrated.") {
			log.Printf("%s is not integrated, skipping\n", fqdd)
			continue
		}
		speed := search.First(search.Tag("LinkSpeed", "*"), nic.Children())
		// If there is not speed setting, then the server is too old to report it.
		// Happily enough, that also means it is too old for 10 gig ports to be a thing.
		if speed != nil && string(speed.Content) != "3" {
			log.Printf("%s is not a gigabit Ethernet port\n", fqdd)
			continue
		}
		fqdds = append(fqdds, fqdd)
	}
	if len(fqdds) < 1 {
		log.Printf("No integrated 1 GB nics!")
		os.Exit(1)
	}
	sort.Strings(fqdds)
	bootnic := fqdds[0]
	result := search.First(search.Content([]byte(bootnic)), nics[0].Parent().All()).Parent()
	if result == nil {
		log.Printf("Unable to find NIC with FQDD %s\n", bootnic)
		return nil
	}
	// Now, make sure it can PXE boot
	msg := client.Get("http://schemas.dell.com/wbem/wscim/1/cim-schema/2/DCIM_NICEnumeration")
	msg.Selectors("InstanceID", bootnic+":LegacyBootProto")
	res, err := msg.Send()
	if err != nil {
		log.Printf("Error checking whether %s can PXE boot: %v\n", bootnic, err)
		return result
	}
	currentval := string(search.First(search.Tag("CurrentValue", "*"), res.AllBodyElements()).Content)
	if currentval == "PXE" {
		return result
	}
	msg = client.Invoke("http://schemas.dell.com/wbem/wscim/1/cim-schema/2/DCIM_NICService", "SetAttribute")
	msg.Selectors(
		"SystemCreationClassName", "DCIM_ComputerSystem",
		"CreationClassName", "DCIM_NICService",
		"SystemName", "DCIM:ComputerSystem",
		"Name", "DCIM:NICService")
	msg.Parameters(
		"Target", bootnic,
		"AttributeName", "LegacyBootProto",
		"AttributeValue", "PXE")
	res, err = msg.Send()
	if err != nil {
		log.Printf("Error ensuring %s can PXE boot: %v\n", bootnic, err)
		return result
	}
	retvals := search.First(search.Tag("SetAttribute_OUTPUT", "*"), res.AllBodyElements())
	if retvals == nil {
		log.Printf("Method invocation result did not return an output element!\n%s\n", res.String())
		return result
	}
	code := search.First(search.Tag("ReturnValue", "*"), retvals.Children())
	if string(code.Content) != "0" {
		log.Printf("Error ensuring NIC %s can PXE boot:\n%s\n", bootnic, res.String())
		return result
	}
	needReboot := string(search.First(search.Tag("RebootRequired", "*"), retvals.Children()).Content)
	if needReboot != "Yes" {
		return result
	}
	// Create the config job.
	msg = client.Invoke("http://schemas.dell.com/wbem/wscim/1/cim-schema/2/DCIM_NICService", "CreateTargetedConfigJob")
	msg.Selectors(
		"SystemCreationClassName", "DCIM_ComputerSystem",
		"CreationClassName", "DCIM_NICService",
		"SystemName", "DCIM:ComputerSystem",
		"Name", "DCIM:NICService")
	msg.Parameters(
		"Target", bootnic,
		"RebootJobType", "1",
		"ScheduledStartTime", "TIME_NOW")
	res, err = msg.Send()
	if err != nil {
		log.Printf("Error ensuring %s can PXE boot: %v\n", bootnic, err)
		return result
	}
	retvals = search.First(search.Tag("CreateTargetedConfigJob_OUTPUT", "*"), res.AllBodyElements())
	if retvals == nil {
		log.Printf("Method invocation result did not return an output element!\n%s\n", res.String())
		return result
	}
	code = search.First(search.Tag("ReturnValue", "*"), retvals.Children())
	if string(code.Content) != "4096" {
		log.Printf("Error ensuring NIC %s can PXE boot:\n%s\n", bootnic, res.String())
		return result
	}
//.........这里部分代码省略.........
开发者ID:dell-esg,项目名称:idracula,代码行数:101,代码来源:main.go



注:本文中的github.com/VictorLowther/wsman.Client类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Golang cascadia.MustCompile函数代码示例发布时间:2022-05-28
下一篇:
Golang iniflags.Parse函数代码示例发布时间:2022-05-28
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap