当前位置: 首页>>代码示例>>Golang>>正文


Golang containers.NewIdentifier函数代码示例

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


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

示例1: splitTypeHostId

func splitTypeHostId(value string) (res ResourceType, host string, id containers.Identifier, err error) {
	if value == "" {
		err = errors.New("The identifier must be specified as <host>/<id> or <id>")
		return
	}

	locatorParts := strings.SplitN(value, "://", 2)
	if len(locatorParts) == 2 {
		res = ResourceType(locatorParts[0])
		value = locatorParts[1]
	}

	sections := strings.SplitN(value, "/", 2)
	if len(sections) == 1 {
		id, err = containers.NewIdentifier(sections[0])
		return
	}
	id, err = containers.NewIdentifier(sections[1])
	if err != nil {
		return
	}
	if strings.TrimSpace(sections[0]) == "" {
		err = errors.New("You must specify <host>/<id> or <id>")
		return
	}
	host = sections[0]
	return
}
开发者ID:roacobb,项目名称:geard,代码行数:28,代码来源:remote.go

示例2: TestSamePortRejected

func (s *IntegrationTestSuite) TestSamePortRejected(c *chk.C) {
	id, err := containers.NewIdentifier("TestSamePortRejected")
	c.Assert(err, chk.IsNil)
	s.containerIds = append(s.containerIds, id)

	hostContainerId := fmt.Sprintf("%v/%v", s.daemonURI, id)

	cmd := exec.Command("/usr/bin/gear", "install", TestImage, hostContainerId, "--ports=8080:39485")
	data, err := cmd.CombinedOutput()
	c.Log(string(data))
	c.Assert(err, chk.IsNil)
	active, _ := s.unitState(id)
	c.Assert(active, chk.Equals, "inactive")

	s.assertFilePresent(c, id.UnitPathFor(), 0664, true)
	paths, err := filepath.Glob(id.VersionedUnitPathFor("*"))
	c.Assert(err, chk.IsNil)
	for _, p := range paths {
		s.assertFilePresent(c, p, 0664, true)
	}

	id2, _ := containers.NewIdentifier("TestSamePortRejected2")
	cmd = exec.Command("/usr/bin/gear", "install", TestImage, fmt.Sprintf("%v/%v", s.daemonURI, id2), "--ports=8080:39485")
	data, err = cmd.CombinedOutput()
	c.Log(string(data))
	c.Assert(err, chk.ErrorMatches, "exit status 1")
	state, substate := s.unitState(id2)
	c.Assert(state, chk.Equals, "inactive")
	c.Assert(substate, chk.Equals, "dead")
}
开发者ID:jcantrill,项目名称:geard,代码行数:30,代码来源:integration_test.go

示例3: GetDockerContainerPacketCounts

func GetDockerContainerPacketCounts(d *docker.DockerClient) (map[containers.Identifier]int, error) {
	serviceFiles, err := filepath.Glob(filepath.Join(gearconfig.ContainerBasePath(), "units", "**", containers.IdentifierPrefix+"*.service"))
	if err != nil {
		return nil, err
	}

	ids := make([]string, 0)
	packetCount := make(map[containers.Identifier]int)

	for _, s := range serviceFiles {
		id := filepath.Base(s)
		if strings.HasPrefix(id, containers.IdentifierPrefix) && strings.HasSuffix(id, ".service") {
			id = id[len(containers.IdentifierPrefix):(len(id) - len(".service"))]
			if id, err := containers.NewIdentifier(id); err == nil {
				ids = append(ids, string(id))
				packetCount[id] = 0
			}
		}
	}

	containerIPs, err := d.GetContainerIPs(ids)
	if err != nil {
		return nil, err
	}

	cmd := exec.Command("/sbin/iptables-save", "-c")
	output, err := cmd.Output()
	if err != nil {
		return nil, err
	}

	scan := bufio.NewScanner(bytes.NewBuffer(output))
	for scan.Scan() {
		line := scan.Text()
		if strings.Contains(line, "-A DOCKER ! -i docker0") && strings.Contains(line, "-j DNAT") {
			//Example: [0:0] -A DOCKER ! -i docker0 -p tcp -m tcp --dport 4000 -j DNAT --to-destination 172.17.0.3:8080
			items := strings.Fields(line)
			packets, _ := strconv.Atoi(strings.Split(items[0], ":")[0][1:])
			destIp := strings.Split(items[15], ":")[0]
			id, _ := containers.NewIdentifier(containerIPs[destIp])

			packetCount[id] = packetCount[id] + packets
		}

		if strings.Contains(line, "-A OUTPUT -d 127.0.0.1/32 -p tcp -m tcp --dport") && strings.Contains(line, "-m comment --comment ") {
			//Example: [5850:394136] -A OUTPUT -d 127.0.0.1/32 -p tcp -m tcp --dport 4000 -m comment --comment 0001 -j ACCEPT
			items := strings.Fields(line)
			packets, _ := strconv.Atoi(strings.Split(items[0], ":")[0][1:])
			if id, err := containers.NewIdentifier(items[14]); err == nil {
				packetCount[id] = packetCount[id] + packets
			}
		}
	}

	return packetCount, nil
}
开发者ID:jcantrill,项目名称:geard,代码行数:56,代码来源:rules.go

示例4: TestInstallEnvFile

func (s *IntegrationTestSuite) TestInstallEnvFile(c *chk.C) {
	id, err := containers.NewIdentifier("TestInstallEnvFile")
	c.Assert(err, chk.IsNil)
	s.containerIds = append(s.containerIds, id)

	hostContainerId := fmt.Sprintf("%v/%v", s.daemonURI, id)

	// get the full path to this .go file so we can get the correct path to the
	// simple.env file
	_, filename, _, _ := runtime.Caller(0)
	envFile := path.Join(path.Dir(filename), "..", "deployment", "fixtures", "simple.env")
	cmd := exec.Command("/usr/bin/gear", "install", EnvImage, hostContainerId, "--env-file="+envFile, "--start")
	data, err := cmd.CombinedOutput()
	c.Log(cmd.Args)
	c.Log(string(data))
	c.Assert(err, chk.IsNil)
	s.assertContainerStarts(c, id)

	cmd = exec.Command("/usr/bin/gear", "status", hostContainerId)
	data, err = cmd.CombinedOutput()
	c.Assert(err, chk.IsNil)
	c.Log(string(data))
	c.Assert(strings.Contains(string(data), "TEST=value"), chk.Equals, true)
	c.Assert(strings.Contains(string(data), "QUOTED=\\\"foo\\\""), chk.Equals, true)
	c.Assert(strings.Contains(string(data), "IGNORED"), chk.Equals, false)
}
开发者ID:jcantrill,项目名称:geard,代码行数:26,代码来源:integration_test.go

示例5: IdentifierFor

func (p Port) IdentifierFor() (containers.Identifier, error) {
	_, portPath := p.PortPathsFor()

	r, err := os.Open(portPath)
	if err != nil {
		return "", err
	}
	defer r.Close()

	scan := bufio.NewScanner(r)
	for scan.Scan() {
		line := scan.Text()
		if strings.HasPrefix(line, "X-ContainerId=") {
			id, err := containers.NewIdentifier(strings.TrimPrefix(line, "X-ContainerId="))
			if err != nil {
				return "", err
			}
			return id, nil
		}
	}
	if scan.Err() != nil {
		return "", scan.Err()
	}
	return "", fmt.Errorf("Container ID not found")
}
开发者ID:roacobb,项目名称:geard,代码行数:25,代码来源:port.go

示例6: TestShouldSendRemoteJob

func TestShouldSendRemoteJob(t *testing.T) {
	trans := &testTransport{}
	localhost := &testLocator{"localhost"}
	initCalled := false
	locator := &ResourceLocator{"ctr", "foobar", localhost}

	Executor{
		On: Locators{locator},
		Serial: func(on Locator) JobRequest {
			if on != locator {
				t.Fatalf("Expected locator passed to Serial() to be identical to %+v", locator)
			}
			id, _ := containers.NewIdentifier(on.(*ResourceLocator).Id)
			return &cjobs.StoppedContainerStateRequest{
				Id: id,
			}
		},
		Transport: trans,
	}.Gather()

	if initCalled {
		t.Errorf("Local initialization should be bypassed for remote transports")
	}
	if _, ok := trans.Translated["localhost"]; !ok {
		t.Errorf("Job for localhost was not enqueued in %+v", trans.Invoked)
	}
	if _, ok := trans.Invoked["localhost"]; !ok {
		t.Errorf("Job for localhost was not enqueued in %+v", trans.Invoked)
	}
}
开发者ID:jcantrill,项目名称:geard,代码行数:30,代码来源:executor_test.go

示例7: HandleDeleteContainerRequest

func HandleDeleteContainerRequest(conf *http.HttpConfiguration, context *http.HttpContext, r *rest.Request) (interface{}, error) {
	id, errg := containers.NewIdentifier(r.PathParam("id"))
	if errg != nil {
		return nil, errg
	}
	return &cjobs.DeleteContainerRequest{Id: id}, nil
}
开发者ID:jcantrill,项目名称:geard,代码行数:7,代码来源:handlers.go

示例8: TestInstallEnv

func (s *IntegrationTestSuite) TestInstallEnv(c *chk.C) {
	id, err := containers.NewIdentifier("TestInstallEnv")
	c.Assert(err, chk.IsNil)
	s.containerIds = append(s.containerIds, id)

	hostContainerId := fmt.Sprintf("%v/%v", s.daemonURI, id)
	hostEnvId := fmt.Sprintf("%v/%v", s.daemonURI, "foobar")

	cmd := exec.Command("/usr/bin/gear", "install", EnvImage, hostContainerId, "--env-id=foobar", "A=B", "C=D", "--start")
	data, err := cmd.CombinedOutput()
	c.Log(cmd.Args)
	c.Log(string(data))
	c.Assert(err, chk.IsNil)
	s.assertContainerStarts(c, id)

	cmd = exec.Command("/usr/bin/gear", "status", hostContainerId)
	data, err = cmd.CombinedOutput()
	c.Assert(err, chk.IsNil)
	c.Log(string(data))
	c.Assert(strings.Contains(string(data), "A=B"), chk.Equals, true)
	c.Assert(strings.Contains(string(data), "C=D"), chk.Equals, true)

	cmd = exec.Command("/usr/bin/gear", "env", hostEnvId)
	data, err = cmd.CombinedOutput()
	c.Assert(err, chk.IsNil)
	c.Log(string(data))
	c.Assert(string(data), chk.Equals, "A=B\nC=D\n")
}
开发者ID:jcantrill,项目名称:geard,代码行数:28,代码来源:integration_test.go

示例9: TestStartStopContainer

func (s *IntegrationTestSuite) TestStartStopContainer(c *chk.C) {
	id, err := containers.NewIdentifier("IntTest003")
	c.Assert(err, chk.IsNil)
	s.containerIds = append(s.containerIds, id)

	hostContainerId := fmt.Sprintf("%v/%v", s.daemonURI, id)

	cmd := exec.Command("/usr/bin/gear", "install", TestImage, hostContainerId, "--ports=8080:4001", "--isolate")
	data, err := cmd.CombinedOutput()
	c.Log(string(data))
	c.Assert(err, chk.IsNil)
	s.assertFilePresent(c, id.UnitPathFor(), 0664, true)

	cmd = exec.Command("/usr/bin/gear", "start", hostContainerId)
	data, err = cmd.CombinedOutput()
	c.Log(string(data))
	c.Assert(err, chk.IsNil)
	s.assertContainerState(c, id, CONTAINER_STARTED)
	s.assertFilePresent(c, filepath.Join(id.HomePath(), "container-init.sh"), 0700, false)

	ports, err := containers.GetExistingPorts(id)
	c.Assert(err, chk.IsNil)
	c.Assert(len(ports), chk.Equals, 1)

	resp, err := http.Get(fmt.Sprintf("http://0.0.0.0:%v", ports[0].External))
	c.Assert(err, chk.IsNil)
	c.Assert(resp.StatusCode, chk.Equals, 200)

	cmd = exec.Command("/usr/bin/gear", "stop", hostContainerId)
	data, err = cmd.CombinedOutput()
	c.Log(string(data))
	c.Assert(err, chk.IsNil)
	s.assertContainerState(c, id, CONTAINER_STOPPED)
}
开发者ID:roacobb,项目名称:geard,代码行数:34,代码来源:integration_test.go

示例10: TestSimpleInstallWithEnv

func (s *IntegrationTestSuite) TestSimpleInstallWithEnv(c *chk.C) {
	if !*hasEnvFile {
		c.Skip("-env-file not specified")
	}

	id, err := containers.NewIdentifier("IntTest008")
	c.Assert(err, chk.IsNil)
	s.containerIds = append(s.containerIds, id)

	hostContainerId := fmt.Sprintf("%v/%v", s.daemonURI, id)

	cmd := exec.Command("/usr/bin/gear", "install", EnvImage, hostContainerId, "--env-file=deployment/fixtures/simple.env", "--start")
	data, err := cmd.CombinedOutput()
	c.Log(cmd.Args)
	c.Log(string(data))
	c.Assert(err, chk.IsNil)
	time.Sleep(time.Second * 5) // startup time is indeterminate unfortunately because gear init --post continues to run

	cmd = exec.Command("/usr/bin/gear", "status", hostContainerId)
	data, err = cmd.CombinedOutput()
	c.Assert(err, chk.IsNil)
	c.Log(string(data))
	c.Assert(strings.Contains(string(data), "TEST=\"value\""), chk.Equals, true)
	c.Assert(strings.Contains(string(data), "QUOTED=\"foo\""), chk.Equals, true)
}
开发者ID:roacobb,项目名称:geard,代码行数:25,代码来源:integration_test.go

示例11: CreatePermission

func (r repositoryPermission) CreatePermission(locator ssh.KeyLocator, value *utils.RawMessage) error {
	p := RepositoryPermission{}
	if value != nil {
		if err := json.Unmarshal(*value, &p); err != nil {
			return err
		}
	}

	id, err := containers.NewIdentifier(p.Id)
	if err != nil {
		return err
	}
	repoId := RepoIdentifier(id)

	if _, err := os.Stat(repoId.RepositoryPathFor()); err != nil {
		return err
	}
	accessPath := repoId.GitAccessPathFor(locator.NameForKey(), p.Write)

	if err := os.Symlink(locator.PathToKey(), accessPath); err != nil && !os.IsExist(err) {
		return err
	}
	negAccessPath := repoId.GitAccessPathFor(locator.NameForKey(), !p.Write)
	if err := os.Remove(negAccessPath); err != nil && !os.IsNotExist(err) {
		return err
	}
	if _, err := os.Stat(repoId.AuthKeysPathFor()); err == nil {
		if err := os.Remove(repoId.AuthKeysPathFor()); err != nil && !os.IsNotExist(err) {
			return err
		}
	}
	return nil
}
开发者ID:jcantrill,项目名称:geard,代码行数:33,代码来源:permission.go

示例12: TestLongContainerName

func (s *IntegrationTestSuite) TestLongContainerName(c *chk.C) {
	id, err := containers.NewIdentifier("IntTest006xxxxxxxxxxxxxx")
	c.Assert(err, chk.IsNil)
	s.containerIds = append(s.containerIds, id)

	hostContainerId := fmt.Sprintf("%v/%v", s.daemonURI, id)

	cmd := exec.Command("/usr/bin/gear", "install", TestImage, hostContainerId, "--start", "--ports=8080:4003", "--isolate")
	data, err := cmd.CombinedOutput()
	c.Log(string(data))
	c.Assert(err, chk.IsNil)
	s.assertContainerState(c, id, CONTAINER_STARTED)

	s.assertFilePresent(c, id.UnitPathFor(), 0664, true)
	s.assertFilePresent(c, filepath.Join(id.HomePath(), "container-init.sh"), 0700, false)

	ports, err := containers.GetExistingPorts(id)
	c.Assert(err, chk.IsNil)
	c.Assert(len(ports), chk.Equals, 1)

	t := time.NewTicker(time.Second / 10)
	defer t.Stop()
	select {
	case <-t.C:
		resp, err := http.Get(fmt.Sprintf("http://0.0.0.0:%v", ports[0].External))
		if err == nil {
			c.Assert(resp.StatusCode, chk.Equals, 200)
		}
	case <-time.After(time.Second * 15):
		c.Fail()
	}
}
开发者ID:roacobb,项目名称:geard,代码行数:32,代码来源:integration_test.go

示例13: TestSimpleInstallAndStartImage

func (s *IntegrationTestSuite) TestSimpleInstallAndStartImage(c *chk.C) {
	id, err := containers.NewIdentifier("IntTest000")
	c.Assert(err, chk.IsNil)
	s.containerIds = append(s.containerIds, id)

	hostContainerId := fmt.Sprintf("%v/%v", s.daemonURI, id)

	cmd := exec.Command("/usr/bin/gear", "install", TestImage, hostContainerId)
	data, err := cmd.CombinedOutput()
	c.Log(string(data))
	c.Assert(err, chk.IsNil)
	s.assertContainerState(c, id, CONTAINER_STOPPED)

	s.assertFilePresent(c, id.UnitPathFor(), 0664, true)
	paths, err := filepath.Glob(id.VersionedUnitPathFor("*"))
	c.Assert(err, chk.IsNil)
	for _, p := range paths {
		s.assertFilePresent(c, p, 0664, true)
	}
	s.assertFileAbsent(c, filepath.Join(id.HomePath(), "container-init.sh"))

	ports, err := containers.GetExistingPorts(id)
	c.Assert(err, chk.IsNil)
	c.Assert(len(ports), chk.Equals, 0)

	cmd = exec.Command("/usr/bin/gear", "status", hostContainerId)
	data, err = cmd.CombinedOutput()
	c.Assert(err, chk.IsNil)
	c.Log(string(data))
	c.Assert(strings.Contains(string(data), "Loaded: loaded (/var/lib/containers/units/In/ctr-IntTest000.service; enabled)"), chk.Equals, true)
	s.assertContainerState(c, id, CONTAINER_STOPPED)
}
开发者ID:roacobb,项目名称:geard,代码行数:32,代码来源:integration_test.go

示例14: TestContainerNetLinks

func (s *IntegrationTestSuite) TestContainerNetLinks(c *chk.C) {
	id, err := containers.NewIdentifier("IntTest007")
	c.Assert(err, chk.IsNil)
	s.containerIds = append(s.containerIds, id)

	hostContainerId := fmt.Sprintf("%v/%v", s.daemonURI, id)

	cmd := exec.Command("/usr/bin/gear", "install", TestImage, hostContainerId, "--ports=8080:4004", "--isolate")
	data, err := cmd.CombinedOutput()
	c.Log(string(data))
	c.Assert(err, chk.IsNil)
	s.assertFilePresent(c, id.UnitPathFor(), 0664, true)

	cmd = exec.Command("/usr/bin/gear", "link", "-n", "127.0.0.1:8081:74.125.239.114:80", hostContainerId)
	data, err = cmd.CombinedOutput()
	c.Log(string(data))
	c.Assert(err, chk.IsNil)

	cmd = exec.Command("/usr/bin/gear", "start", hostContainerId)
	data, err = cmd.CombinedOutput()
	s.assertContainerState(c, id, CONTAINER_STARTED)
	s.assertFilePresent(c, filepath.Join(id.HomePath(), "container-init.sh"), 0700, false)

	cmd = exec.Command("/usr/bin/switchns", "--container="+id.ContainerFor(), "--", "/sbin/iptables", "-t", "nat", "-L")
	data, err = cmd.CombinedOutput()
	c.Log(string(data))
	c.Assert(strings.Contains(string(data), "tcp dpt:tproxy to:74.125.239.114"), chk.Equals, true)

	cmd = exec.Command("/usr/bin/gear", "stop", hostContainerId)
	data, err = cmd.CombinedOutput()
	c.Log(string(data))
	c.Assert(err, chk.IsNil)
	s.assertContainerState(c, id, CONTAINER_STOPPED)
}
开发者ID:roacobb,项目名称:geard,代码行数:34,代码来源:integration_test.go

示例15: createInstances

func (d *Deployment) createInstances(c *Container) error {
	for i := len(c.instances); i < c.Count; i++ {
		var id containers.Identifier
		var err error
		if d.RandomizeIds {
			id, err = containers.NewRandomIdentifier(d.IdPrefix)
		} else {
			id, err = containers.NewIdentifier(d.IdPrefix + c.Name + "-" + strconv.Itoa(i+1))
		}
		if err != nil {
			return err
		}
		instance := &Instance{
			Id:    id,
			From:  c.Name,
			Image: c.Image,
			Ports: newPortMappings(c.PublicPorts),

			container: c,
			add:       true,
		}
		c.AddInstance(instance)
	}
	return nil
}
开发者ID:jhadvig,项目名称:geard,代码行数:25,代码来源:deployment.go


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