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

Golang dao.Host类代码示例

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

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



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

示例1: TestDaoGetHostIPsWithIPs

func TestDaoGetHostIPsWithIPs(t *testing.T) {
	hostIPs := dao.HostIPs{}
	//Add host to test scenario where host exists but no IP resource registered
	host := dao.Host{}
	host.Id = HOSTID
	err = controlPlaneDao.AddHost(host, &id)
	defer controlPlaneDao.RemoveHost(HOSTID, &unused)
	if err != nil {
		t.Errorf("Unexpected error: %v", err)
		return
	}

	//store a HostIPs object
	hostIPs.Id = HOSTIPSID
	hostIPs.HostId = HOSTID
	hostIPs.IPs = []dao.HostIPResource{dao.HostIPResource{"valid", "testip", "ifname", []dao.AssignedPort{}}}
	_, err = newHostIPs(hostIPs.Id, hostIPs)
	defer deleteHostIPs(HOSTIPSID)
	if err != nil {
		t.Errorf("Error creating newHostIPs")
		return
	}

	err = controlPlaneDao.GetHostIPs(HOSTID, &hostIPs)
	if err != nil {
		t.Errorf("Unexpected error: %v", err)
		return
	}
	if hostIPs.Id != HOSTIPSID {
		t.Errorf("Expected host ips id %v , got %v", HOSTIPSID, hostIPs.Id)
	}
	if hostIPs.HostId != HOSTID {
		t.Errorf("Expected host id %v, got %v", HOSTID, hostIPs.Id)
	}
	if hostIPs.PoolId != "" {
		t.Errorf("Expected uninitialzed poolid, got %v", hostIPs.PoolId)
	}
	if hostIPs.PoolId != "" {
		t.Errorf("Expected uninitialzed id, got %v", hostIPs.Id)
	}
	if len(hostIPs.IPs) != 1 {
		t.Errorf("Expected %v IPs, got %v", 1, len(hostIPs.IPs))
	}

}
开发者ID:jhuie-zenoss,项目名称:serviced,代码行数:45,代码来源:controlplanedao_test.go


示例2: testDaoHostExists

func testDaoHostExists(t *testing.T) {
	found, err := hostExists("blam")
	if found || err != nil {
		t.Errorf("Found %v; error: %v", found, err)
		t.FailNow()
	}

	host := dao.Host{}
	host.Id = "existsTest"
	err = controlPlaneDao.AddHost(host, &id)
	defer controlPlaneDao.RemoveHost("existsTest", &unused)

	found, err = hostExists(id)
	if !found || err != nil {
		t.Errorf("Found %v; error: %v", found, err)
	}

}
开发者ID:jhuie-zenoss,项目名称:serviced,代码行数:18,代码来源:controlplanedao_test.go


示例3: TestDao_GetHost

func TestDao_GetHost(t *testing.T) {
	controlPlaneDao.RemoveHost("default", &unused)

	host := dao.NewHost()
	host.Id = "default"
	controlPlaneDao.AddHost(*host, &id)

	var result = dao.Host{}
	err := controlPlaneDao.GetHost("default", &result)
	result.CreatedAt = host.CreatedAt
	result.UpdatedAt = host.UpdatedAt
	if err == nil {
		if *host != result {
			t.Errorf("Unexpected Host: expected=%+v, actual=%+v", host, result)
		}
	} else {
		t.Errorf("Unexpected Error Retrieving Host: err=%s", err)
	}
}
开发者ID:jhuie-zenoss,项目名称:serviced,代码行数:19,代码来源:controlplanedao_test.go


示例4: TestDaoGetHostIPsNotFound

func TestDaoGetHostIPsNotFound(t *testing.T) {
	hostIPs := dao.HostIPs{}

	//Add host to test scenario where host exists but no IP resource registered
	host := dao.Host{}
	host.Id = HOSTID
	err = controlPlaneDao.AddHost(host, &id)
	defer controlPlaneDao.RemoveHost(HOSTID, &unused)
	if err != nil {
		t.Errorf("Unexpected error: %v", err)
		return
	}

	err = controlPlaneDao.GetHostIPs(HOSTID, &hostIPs)
	if err != nil {
		t.Errorf("Unexpected error: %v", err)
	}
	if hostIPs.Id != "" {
		t.Errorf("Expected uninitialzed id, got %v", hostIPs.Id)
	}
}
开发者ID:jhuie-zenoss,项目名称:serviced,代码行数:21,代码来源:controlplanedao_test.go


示例5: TestDaoRegisterHostIPs

func TestDaoRegisterHostIPs(t *testing.T) {
	//Add host to test scenario where host exists but no IP resource registered
	host := dao.Host{}
	host.Id = HOSTID
	err = controlPlaneDao.AddHost(host, &id)
	defer controlPlaneDao.RemoveHost(HOSTID, &unused)

	ips := dao.HostIPs{}
	ips.HostId = HOSTID
	ips.IPs = []dao.HostIPResource{dao.HostIPResource{"valid", "testip", "ifname", []dao.AssignedPort{}}}

	err := controlPlaneDao.RegisterHostIPs(ips, &unused)
	//remove any registered
	defer removeHostIPs(HOSTID)

	if err != nil {
		t.Errorf("Unexpected error: %v", err)
	}

	//verify registration
	ips = dao.HostIPs{}
	controlPlaneDao.GetHostIPs(HOSTID, &ips)
	if err != nil {
		t.Errorf("Unexpected error: %v", err)
	}
	if len(ips.IPs) != 1 {
		t.Errorf("Expected 1 HostIPResource, found: %v", len(ips.IPs))
	}
	ipResource := ips.IPs[0]
	if ipResource.State != "valid" {
		t.Errorf("Unexpected state: %v", ipResource.State)
	}
	if ipResource.IPAddress != "testip" {
		t.Errorf("Unexpected IPAddress: %v", ipResource.IPAddress)
	}
	if ipResource.InterfaceName != "ifname" {
		t.Errorf("Unexpected InterfaceName: %v", ipResource.InterfaceName)
	}

}
开发者ID:jhuie-zenoss,项目名称:serviced,代码行数:40,代码来源:controlplanedao_test.go


示例6: TestDao_AddHost

func TestDao_AddHost(t *testing.T) {
	host := dao.Host{}
	controlPlaneDao.RemoveHost("default", &unused)
	err := controlPlaneDao.AddHost(host, &id)
	if err == nil {
		t.Errorf("Expected failure to create host %-v", host)
		t.Fail()
	}

	host.Id = "default"
	err = controlPlaneDao.AddHost(host, &id)
	if err != nil {
		t.Errorf("Failure creating host %-v with error: %s", host, err)
		t.Fail()
	}

	err = controlPlaneDao.AddHost(host, &id)
	if err == nil {
		t.Errorf("Expected error creating redundant host %-v", host)
		t.Fail()
	}
}
开发者ID:jhuie-zenoss,项目名称:serviced,代码行数:22,代码来源:controlplanedao_test.go


示例7: RestAddHost

func RestAddHost(w *rest.ResponseWriter, r *rest.Request, client *serviced.ControlClient) {
	var payload dao.Host
	var hostId string
	err := r.DecodeJsonPayload(&payload)
	if err != nil {
		glog.V(1).Infof("Could not decode host payload: %v", err)
		RestBadRequest(w)
		return
	}
	// Save the pool ID and IP address for later. GetInfo wipes these
	pool := payload.PoolId
	ipAddr := payload.IpAddr
	remoteClient, err := serviced.NewAgentClient(payload.IpAddr)
	if err != nil {
		glog.Errorf("Could not create connection to host %s: %v", payload.IpAddr, err)
		RestServerError(w)
		return
	}

	err = remoteClient.GetInfo(0, &payload)
	if err != nil {
		glog.Errorf("Unable to get remote host info: %v", err)
		RestBadRequest(w)
		return
	}
	// Reset the pool ID and IP address
	payload.PoolId = pool
	parts := strings.Split(ipAddr, ":")
	payload.IpAddr = parts[0]

	err = client.AddHost(payload, &hostId)
	if err != nil {
		glog.Errorf("Unable to add host: %v", err)
		RestServerError(w)
		return
	}
	glog.V(0).Info("Added host ", hostId)
	w.WriteJson(&SimpleResponse{"Added host", hostLinks(hostId)})
}
开发者ID:jhuie-zenoss,项目名称:serviced,代码行数:39,代码来源:resources.go


示例8: TestDao_UpdateHost

func TestDao_UpdateHost(t *testing.T) {
	controlPlaneDao.RemoveHost("default", &unused)

	host := dao.NewHost()
	host.Id = "default"
	controlPlaneDao.AddHost(*host, &id)

	host.Name = "hostname"
	host.IpAddr = "127.0.0.1"
	err := controlPlaneDao.UpdateHost(*host, &unused)
	if err != nil {
		t.Errorf("Failure updating host %-v with error: %s", host, err)
		t.Fail()
	}

	var result = dao.Host{}
	controlPlaneDao.GetHost("default", &result)
	result.CreatedAt = host.CreatedAt
	result.UpdatedAt = host.UpdatedAt
	if *host != result {
		t.Errorf("%+v != %+v", result, host)
		t.Fail()
	}
}
开发者ID:jhuie-zenoss,项目名称:serviced,代码行数:24,代码来源:controlplanedao_test.go


示例9: TestDaoRegisterHostIPsMerge

func TestDaoRegisterHostIPsMerge(t *testing.T) {
	//Add host to test scenario where host exists but no IP resource registered
	host := dao.Host{}
	host.Id = HOSTID
	err = controlPlaneDao.AddHost(host, &id)
	defer controlPlaneDao.RemoveHost(HOSTID, &unused)

	ips := dao.HostIPs{}
	ips.HostId = HOSTID
	ips.IPs = []dao.HostIPResource{
		dao.HostIPResource{"valid", "testip", "ifname", []dao.AssignedPort{}},
		dao.HostIPResource{"deleted", "testip1", "ifname", []dao.AssignedPort{}},
	}

	err := controlPlaneDao.RegisterHostIPs(ips, &unused)
	//remove any registered
	defer removeHostIPs(HOSTID)
	if err != nil {
		t.Errorf("Unexpected error: %v", err)
	}

	ips.IPs = []dao.HostIPResource{
		dao.HostIPResource{"valid", "testip2", "ifname2", []dao.AssignedPort{}},
		dao.HostIPResource{"valid", "testip1", "ifname", []dao.AssignedPort{}},
	}
	err = controlPlaneDao.RegisterHostIPs(ips, &unused)
	if err != nil {
		t.Errorf("Unexpected error: %v", err)
	}

	//verify registration
	ips = dao.HostIPs{}
	controlPlaneDao.GetHostIPs(HOSTID, &ips)
	if err != nil {
		t.Errorf("Unexpected error: %v", err)
	}
	if len(ips.IPs) != 3 {
		t.Errorf("Expected 3 HostIPResources, found: %v", len(ips.IPs))
	}
	for _, ipResource := range ips.IPs {
		addr := ipResource.IPAddress
		switch addr {
		case "testip":
			{
				if ipResource.State != "deleted" {
					t.Errorf("Unexpected state: %v", ipResource.State)
				}

				if ipResource.InterfaceName != "ifname" {
					t.Errorf("Unexpected InterfaceName: %v", ipResource.InterfaceName)
				}
			}
		case "testip1":
			{
				if ipResource.State != "valid" {
					t.Errorf("Unexpected state: %v", ipResource.State)
				}

				if ipResource.InterfaceName != "ifname" {
					t.Errorf("Unexpected InterfaceName: %v", ipResource.InterfaceName)
				}
			}
		case "testip2":
			{
				if ipResource.State != "valid" {
					t.Errorf("Unexpected state: %v", ipResource.State)
				}

				if ipResource.InterfaceName != "ifname2" {
					t.Errorf("Unexpected InterfaceName: %v", ipResource.InterfaceName)
				}
			}
		default:
			{
				t.Errorf("Unexpected IP resource %v", ipResource)
			}
		}

	}
}
开发者ID:jhuie-zenoss,项目名称:serviced,代码行数:80,代码来源:controlplanedao_test.go



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
Golang ast.Node类代码示例发布时间:2022-05-28
下一篇:
Golang serviced.ControlClient类代码示例发布时间: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