本文整理匯總了Golang中github.com/eris-ltd/eris-cli/util.DataContainersName函數的典型用法代碼示例。如果您正苦於以下問題:Golang DataContainersName函數的具體用法?Golang DataContainersName怎麽用?Golang DataContainersName使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了DataContainersName函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: giveMeAllTheNames
func giveMeAllTheNames(name string, srv *def.ServiceDefinition) {
logger.Debugf("Giving myself all the names =>\t%s\n", name)
srv.Name = name
srv.Service.Name = name
srv.Operations.SrvContainerName = util.DataContainersName(srv.Name, srv.Operations.ContainerNumber)
srv.Operations.DataContainerName = util.DataContainersName(srv.Name, srv.Operations.ContainerNumber)
logger.Debugf("My service container name is =>\t%s\n", srv.Operations.SrvContainerName)
logger.Debugf("My data container name is =>\t%s\n", srv.Operations.DataContainerName)
}
示例2: giveMeAllTheNames
func giveMeAllTheNames(name string, srv *def.ServiceDefinition) {
log.WithField("=>", name).Debug("Giving myself all the names")
srv.Name = name
srv.Service.Name = name
srv.Operations.SrvContainerName = util.DataContainersName(srv.Name, srv.Operations.ContainerNumber)
srv.Operations.DataContainerName = util.DataContainersName(srv.Name, srv.Operations.ContainerNumber)
log.WithFields(log.Fields{
"data container": srv.Operations.DataContainerName,
"service container": srv.Operations.SrvContainerName,
}).Debug("Using names")
}
示例3: testExist
func testExist(t *testing.T, name string, toExist bool) {
var exist bool
logger.Infof("\nTesting whether (%s) existing? (%t)\n", name, toExist)
name = util.DataContainersName(name, 1)
do := definitions.NowDo()
do.Quiet = true
if err := ListKnown(do); err != nil {
logger.Errorln(err)
t.FailNow()
}
res := strings.Split(do.Result, "\n")
for _, r := range res {
logger.Debugf("Existing =>\t\t\t%s\n", r)
if r == util.ContainersShortName(name) {
exist = true
}
}
if toExist != exist {
if toExist {
logger.Infof("Could not find an existing =>\t%s\n", name)
} else {
logger.Infof("Found an existing instance of %s when I shouldn't have\n", name)
}
t.Fail()
}
}
示例4: LoadDataDefinition
// LoadDataDefinition returns an Operation structure for a blank data container
// specified by a name dataName and a cNum number.
func LoadDataDefinition(dataName string, cNum int) *definitions.Operation {
if cNum == 0 {
cNum = 1
}
log.WithField("=>", fmt.Sprintf("%s:%d", dataName, cNum)).Debug("Loading data definition")
ops := definitions.BlankOperation()
ops.ContainerNumber = cNum
ops.ContainerType = definitions.TypeData
ops.SrvContainerName = util.DataContainersName(dataName, cNum)
ops.DataContainerName = util.DataContainersName(dataName, cNum)
ops.Labels = util.Labels(dataName, ops)
return ops
}
示例5: LoadDataDefinition
// LoadDataDefinition returns an Operation structure for a blank data container
// specified by a name dataName and a cNum number.
func LoadDataDefinition(dataName string, cNum int) *definitions.Operation {
if cNum == 0 {
cNum = 1
}
logger.Debugf("Loading Data Definition =>\t%s:%d\n", dataName, cNum)
ops := definitions.BlankOperation()
ops.ContainerNumber = cNum
ops.ContainerType = definitions.TypeData
ops.SrvContainerName = util.DataContainersName(dataName, cNum)
ops.DataContainerName = util.DataContainersName(dataName, cNum)
ops.Labels = util.Labels(dataName, ops)
return ops
}
示例6: ImportData
// ImportData does what it says. It imports from a host's Source to a Dest
// in a data container. It returns an error.
//
// do.Name - name of the data container to use (required)
// do.Operations.ContainerNumber - container number (optional)
// do.Source - directory which should be imported (required)
// do.Destination - directory to _unload_ the payload into (required)
//
func ImportData(do *definitions.Do) error {
log.WithFields(log.Fields{
"from": do.Source,
"to": do.Destination,
}).Debug("Importing")
if util.IsDataContainer(do.Name, do.Operations.ContainerNumber) {
srv := PretendToBeAService(do.Name, do.Operations.ContainerNumber)
service, exists := perform.ContainerExists(srv.Operations)
if !exists {
return fmt.Errorf("There is no data container for that service.")
}
if err := checkErisContainerRoot(do, "import"); err != nil {
return err
}
containerName := util.DataContainersName(do.Name, do.Operations.ContainerNumber)
os.Chdir(do.Source)
reader, err := util.Tar(do.Source, 0)
if err != nil {
return err
}
defer reader.Close()
opts := docker.UploadToContainerOptions{
InputStream: reader,
Path: do.Destination,
NoOverwriteDirNonDir: true,
}
log.WithField("=>", containerName).Info("Copying into container")
log.WithField("path", do.Source).Debug()
if err := util.DockerClient.UploadToContainer(service.ID, opts); err != nil {
return err
}
doChown := definitions.NowDo()
doChown.Operations.DataContainerName = containerName
doChown.Operations.ContainerType = "data"
doChown.Operations.ContainerNumber = do.Operations.ContainerNumber
//required b/c `docker cp` (UploadToContainer) goes in as root
doChown.Operations.Args = []string{"chown", "--recursive", "eris", do.Destination}
_, err = perform.DockerRunData(doChown.Operations, nil)
if err != nil {
return fmt.Errorf("Error changing owner: %v\n", err)
}
} else {
log.WithField("name", do.Name).Info("Data container does not exist.")
ops := loaders.LoadDataDefinition(do.Name, do.Operations.ContainerNumber)
if err := perform.DockerCreateData(ops); err != nil {
return fmt.Errorf("Error creating data container %v.", err)
}
return ImportData(do)
}
do.Result = "success"
return nil
}
示例7: ImportData
func ImportData(do *definitions.Do) error {
if util.IsDataContainer(do.Name, do.Operations.ContainerNumber) {
srv := PretendToBeAService(do.Name, do.Operations.ContainerNumber)
service, exists := perform.ContainerExists(srv.Operations)
if !exists {
return fmt.Errorf("There is no data container for that service.")
}
containerName := util.DataContainersName(do.Name, do.Operations.ContainerNumber)
logger.Debugf("Importing FROM =>\t\t%s\n", do.Source)
os.Chdir(do.Source)
logger.Debugf("Importing TO =>\t\t\t%s\n", do.Destination)
reader, err := util.Tar(do.Source, 0)
if err != nil {
return err
}
defer reader.Close()
opts := docker.UploadToContainerOptions{
InputStream: reader,
Path: do.Destination,
NoOverwriteDirNonDir: true,
}
logger.Infof("Copying into Cont. ID =>\t%s\n", service.ID)
logger.Debugf("\tPath =>\t\t\t%s\n", do.Source)
if err := util.DockerClient.UploadToContainer(service.ID, opts); err != nil {
return err
}
doChown := definitions.NowDo()
doChown.Operations.DataContainerName = containerName
doChown.Operations.ContainerType = "data"
doChown.Operations.ContainerNumber = 1
doChown.Operations.Args = []string{"chown", "--recursive", "eris", do.Destination}
_, err = perform.DockerRunData(doChown.Operations, nil)
if err != nil {
return fmt.Errorf("Error changing owner: %v\n", err)
}
} else {
ops := loaders.LoadDataDefinition(do.Name, do.Operations.ContainerNumber)
if err := perform.DockerCreateData(ops); err != nil {
return fmt.Errorf("Error creating data container %v.", err)
}
return ImportData(do)
}
do.Result = "success"
return nil
}
示例8: ExecData
func ExecData(do *definitions.Do) error {
if util.IsDataContainer(do.Name, do.Operations.ContainerNumber) {
do.Name = util.DataContainersName(do.Name, do.Operations.ContainerNumber)
logger.Infoln("Running exec on container with volumes from data container " + do.Name)
if err := perform.DockerRunVolumesFromContainer(do.Name, do.Interactive, do.Args); err != nil {
return err
}
} else {
return fmt.Errorf("I cannot find that data container. Please check the data container name you sent me.")
}
do.Result = "success"
return nil
}
示例9: RegisterChain
func RegisterChain(do *definitions.Do) error {
// do.Name is mandatory
if do.Name == "" {
return fmt.Errorf("RegisterChain requires a chainame")
}
etcbChain := do.ChainID
do.ChainID = do.Name
// NOTE: registration expects you to have the data container
if !data.IsKnown(do.Name) {
return fmt.Errorf("Registration requires you to have a data container for the chain. Could not find data for %s", do.Name)
}
chain, err := loaders.LoadChainDefinition(do.Name, false, do.Operations.ContainerNumber)
if err != nil {
return err
}
logger.Debugf("Chain Loaded. Image =>\t\t%v\n", chain.Service.Image)
// set chainid and other vars
envVars := []string{
fmt.Sprintf("CHAIN_ID=%s", do.ChainID), // of the etcb chain
fmt.Sprintf("PUBKEY=%s", do.Pubkey), // pubkey to register chain with
fmt.Sprintf("ETCB_CHAIN_ID=%s", etcbChain), // chain id of the etcb chain
fmt.Sprintf("NODE_ADDR=%s", do.Gateway), // etcb node to send the register tx to
fmt.Sprintf("NEW_P2P_SEEDS=%s", do.Args[0]), // seeds to register for the chain // TODO: deal with multi seed (needs support in tendermint)
}
envVars = append(envVars, do.Env...)
logger.Debugf("Set env vars from RegisterChain =>\t%v\n", envVars)
chain.Service.Environment = append(chain.Service.Environment, envVars...)
logger.Debugf("Set links from RegisterChain =>\t%v\n", do.Links)
chain.Service.Links = append(chain.Service.Links, do.Links...)
if err := bootDependencies(chain, do); err != nil {
return err
}
logger.Debugf("Starting chain container via Docker =>\t%s\n", chain.Service.Name)
logger.Debugf("\twith Image =>\t\t%s\n", chain.Service.Image)
cmd := []string{loaders.ErisChainRegister}
dataContainerName := util.DataContainersName(chain.Name, chain.Operations.ContainerNumber)
_, err = perform.DockerRunVolumesFromContainer(dataContainerName, false, cmd, chain.Service)
return err
}
示例10: TestChainsNewConfigAndCSV
// eris chains new -c _ -csv _
func TestChainsNewConfigAndCSV(t *testing.T) {
chainID := "testChainsNewConfigAndCSV"
do := def.NowDo()
do.Name = chainID
do.ConfigFile = path.Join(common.BlockchainsPath, "config", "default", "config.toml")
do.CSV = path.Join(common.BlockchainsPath, "config", "default", "genesis.csv")
do.Operations.ContainerNumber = 1
logger.Infof("Creating chain (from tests) =>\t%s\n", do.Name)
ifExit(NewChain(do))
b, err := ioutil.ReadFile(do.ConfigFile)
if err != nil {
fatal(t, err)
}
fmt.Println("CONFIG CONFIG CONFIG:", string(b))
// remove the data container
defer removeDataContainer(t, chainID, do.Operations.ContainerNumber)
// verify the contents of config.toml
do.Name = util.DataContainersName(do.Name, do.Operations.ContainerNumber)
args := []string{"cat", fmt.Sprintf("/home/eris/.eris/blockchains/%s/config.toml", chainID)}
result := trimResult(string(runContainer(t, do.Name, args)))
contents := trimResult(ini.DefChainConfig())
if result != contents {
fatal(t, fmt.Errorf("config not properly copied. Got: %s \n Expected: %s", result, contents))
}
// verify the contents of genesis.json (should have the validator from the csv)
args = []string{"cat", fmt.Sprintf("/home/eris/.eris/blockchains/%s/genesis.json", chainID)}
result = string(runContainer(t, do.Name, args))
var found bool
for _, s := range strings.Split(result, "\n") {
if strings.Contains(s, ini.DefaultPubKeys[0]) {
found = true
break
}
}
if !found {
fatal(t, fmt.Errorf("Did not find pubkey %s in genesis.json: %s", ini.DefaultPubKeys[0], result))
}
}
示例11: ImportData
func ImportData(do *definitions.Do) error {
if util.IsDataContainer(do.Name, do.Operations.ContainerNumber) {
containerName := util.DataContainersName(do.Name, do.Operations.ContainerNumber)
importPath := filepath.Join(DataContainersPath, do.Name)
// temp until docker cp works both ways.
logger.Debugf("Importing FROM =>\t\t%s\n", importPath)
os.Chdir(importPath)
// TODO [eb]: deal with hardcoded user
// TODO [csk]: drop the whole damn cmd call
// use go's tar lib to make a tarball of the directory
// read the tar file into an io.Reader
// start a container with its Stdin open, connect to an io.Writer
// connect them up with io.Pipe
// this will free us from any quirks that the cli has
if do.Path != "" {
do.Path = do.Path
} else {
do.Path = "/home/eris/.eris"
}
logger.Debugf("Importing TO =>\t\t\t%s\n", do.Path)
cmd := "tar chf - . | docker run -i --rm --volumes-from " + containerName + " --user eris eris/data tar xf - -C " + do.Path
_, err := pipes.RunString(cmd)
if err != nil {
cmd := "tar chf - . | docker run -i --volumes-from " + containerName + " --user eris eris/data tar xf - -C " + do.Path
_, e2 := pipes.RunString(cmd)
if e2 != nil {
return fmt.Errorf("Could not import the data container.\nTried with docker --rm =>\t%v\nTried without docker --rm =>\t%v", err, e2)
}
}
} else {
if err := perform.DockerCreateDataContainer(do.Name, do.Operations.ContainerNumber); err != nil {
return fmt.Errorf("Error creating data container %v.", err)
}
return ImportData(do)
}
do.Result = "success"
return nil
}
示例12: DockerCreateDataContainer
// Build against Docker cli...
// Client version: 1.6.2, 1.7
// Client API version: 1.18, 1.19
// Verified against ...
// Client version: 1.6.2, 1.7
// Client API version: 1.18, 1.19
func DockerCreateDataContainer(srvName string, containerNumber int) error {
logger.Infof("Creating Data Container for =>\t%s\n", srvName)
srv := def.BlankServiceDefinition()
srv.Operations.DataContainerName = util.DataContainersName(srvName, containerNumber)
optsData, err := configureDataContainer(srv.Service, srv.Operations, nil)
if err != nil {
return err
}
srv.Operations.SrvContainerName = srv.Operations.DataContainerName // mock for the query function
if _, exists := ContainerExists(srv.Operations); exists {
logger.Infoln("Data container exists. Not creating.")
return nil
}
cont, err := createContainer(optsData)
if err != nil {
return err
}
logger.Infof("Data Container ID =>\t\t%s\n", cont.ID)
return nil
}
示例13: TestChainsNewConfigOpts
// eris chains new --options
func TestChainsNewConfigOpts(t *testing.T) {
// XXX: need to use a different chainID or remove the local tmp/eris/data/chainID dir with each test!
chainID := "testChainsNewConfigOpts"
do := def.NowDo()
do.Name = chainID
do.ConfigOpts = []string{"moniker=satoshi", "p2p=1.1.1.1:42", "fast-sync=true"}
do.Operations.ContainerNumber = 1
logger.Infof("Creating chain (from tests) =>\t%s\n", do.Name)
ifExit(NewChain(do))
// remove the data container
defer removeChainContainer(t, chainID, do.Operations.ContainerNumber)
// verify the contents of config.toml
do.Name = util.DataContainersName(do.Name, do.Operations.ContainerNumber)
args := []string{"cat", fmt.Sprintf("/home/eris/.eris/blockchains/%s/config.toml", chainID)}
result := string(runContainer(t, do.Name, args))
spl := strings.Split(result, "\n")
var found bool
for _, s := range spl {
if ensureTomlValue(t, s, "moniker", "satoshi") {
found = true
}
if ensureTomlValue(t, s, "node_laddr", "1.1.1.1:42") {
found = true
}
if ensureTomlValue(t, s, "fast_sync", "true") {
found = true
}
}
if !found {
fatal(t, fmt.Errorf("failed to find fields: %s", result))
}
}
示例14: checkChainNames
//----------------------------------------------------------------------
// validation funcs
func checkChainNames(chain *definitions.Chain) {
chain.Service.Name = chain.Name
chain.Operations.SrvContainerName = util.ChainContainersName(chain.Name, chain.Operations.ContainerNumber)
chain.Operations.DataContainerName = util.DataContainersName(chain.Name, chain.Operations.ContainerNumber)
}
示例15: MakeChain
// MakeChain runs the `eris-cm make` command in a docker container.
// It returns an error. Note that if do.Known, do.AccountTypes
// or do.ChainType are not set the command will run via interactive
// shell.
//
// do.Name - name of the chain to be created (required)
// do.Known - will use the mintgen tool to parse csv's and create a genesis.json (requires do.ChainMakeVals and do.ChainMakeActs) (optional)
// do.ChainMakeVals - csv file to use for validators (optional)
// do.ChainMakeActs - csv file to use for accounts (optional)
// do.AccountTypes - use eris-cm make account-types paradigm (example: Root:1,Participants:25,...) (optional)
// do.ChainType - use eris-cm make chain-types paradigm (example: simplechain) (optional)
// do.Tarball - instead of outputing raw files in directories, output packages of tarbals (optional)
// do.ZipFile - similar to do.Tarball except uses zipfiles (optional)
// do.Verbose - verbose output (optional)
// do.Debug - debug output (optional)
//
func MakeChain(do *definitions.Do) error {
do.Service.Name = do.Name
do.Service.Image = path.Join(version.ERIS_REG_DEF, version.ERIS_IMG_CM)
do.Service.User = "eris"
do.Service.AutoData = true
do.Service.Links = []string{fmt.Sprintf("%s:%s", util.ServiceContainersName("keys", do.Operations.ContainerNumber), "keys")}
do.Service.Environment = []string{
fmt.Sprintf("ERIS_KEYS_PATH=http://keys:%d", 4767), // note, needs to be made aware of keys port...
fmt.Sprintf("ERIS_CHAINMANAGER_ACCOUNTTYPES=%s", strings.Join(do.AccountTypes, ",")),
fmt.Sprintf("ERIS_CHAINMANAGER_CHAINTYPE=%s", do.ChainType),
fmt.Sprintf("ERIS_CHAINMANAGER_TARBALLS=%v", do.Tarball),
fmt.Sprintf("ERIS_CHAINMANAGER_ZIPFILES=%v", do.ZipFile),
fmt.Sprintf("ERIS_CHAINMANAGER_OUTPUT=%v", do.Output),
fmt.Sprintf("ERIS_CHAINMANAGER_VERBOSE=%v", do.Verbose),
fmt.Sprintf("ERIS_CHAINMANAGER_DEBUG=%v", do.Debug),
}
do.Operations.ContainerType = "service"
do.Operations.SrvContainerName = util.ServiceContainersName(do.Name, do.Operations.ContainerNumber)
do.Operations.DataContainerName = util.DataContainersName(do.Name, do.Operations.ContainerNumber)
if do.RmD {
do.Operations.Remove = true
}
if do.Known {
log.Debug("Using MintGen rather than eris:cm")
do.Service.EntryPoint = "mintgen"
do.Service.Command = fmt.Sprintf("known %s --csv=%s,%s > %s", do.Name, do.ChainMakeVals, do.ChainMakeActs, path.Join(ErisContainerRoot, "chains", do.Name, "genesis.json"))
} else {
log.Debug("Using eris:cm rather than MintGen")
do.Service.EntryPoint = fmt.Sprintf("eris-cm make %s", do.Name)
}
if !do.Known && len(do.AccountTypes) == 0 && do.ChainType == "" {
do.Operations.Interactive = true
do.Operations.Args = strings.Split(do.Service.EntryPoint, " ")
}
if do.Known {
do.Operations.Args = append(do.Operations.Args, strings.Split(do.Service.Command, " ")...)
do.Service.WorkDir = path.Join(ErisContainerRoot, "chains", do.Name)
}
doData := definitions.NowDo()
doData.Name = do.Name
doData.Operations.ContainerNumber = do.Operations.ContainerNumber
doData.Operations.DataContainerName = util.DataContainersName(do.Name, do.Operations.ContainerNumber)
doData.Operations.ContainerType = "service"
if !do.RmD {
defer data.RmData(doData)
}
doData.Source = AccountsTypePath
doData.Destination = path.Join(ErisContainerRoot, "chains", "account-types")
if err := data.ImportData(doData); err != nil {
return err
}
doData.Source = ChainTypePath
doData.Destination = path.Join(ErisContainerRoot, "chains", "chain-types")
if err := data.ImportData(doData); err != nil {
return err
}
chnPath := filepath.Join(ChainsPath, do.Name)
if _, err := os.Stat(chnPath); !os.IsNotExist(err) {
doData.Operations.Args = []string{"mkdir", "--parents", path.Join(ErisContainerRoot, "chains", do.Name)}
if err := data.ExecData(doData); err != nil {
return err
}
doData.Operations.Args = []string{}
doData.Source = chnPath
doData.Destination = path.Join(ErisContainerRoot, "chains", do.Name)
if err := data.ImportData(doData); err != nil {
return err
}
}
if err := perform.DockerExecService(do.Service, do.Operations); err != nil {
return err
}
doData.Source = path.Join(ErisContainerRoot, "chains")
doData.Destination = ErisRoot
return data.ExportData(doData)
}