本文整理匯總了Golang中github.com/eris-ltd/eris-cli/loaders.LoadChainDefinition函數的典型用法代碼示例。如果您正苦於以下問題:Golang LoadChainDefinition函數的具體用法?Golang LoadChainDefinition怎麽用?Golang LoadChainDefinition使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了LoadChainDefinition函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: RmChain
func RmChain(do *definitions.Do) error {
chain, err := loaders.LoadChainDefinition(do.Name, false, do.Operations.ContainerNumber)
if err != nil {
return err
}
if IsChainExisting(chain) {
if err = perform.DockerRemove(chain.Service, chain.Operations, do.RmD); err != nil {
return err
}
} else {
logger.Infoln("That chain's container does not exist.")
}
if do.File {
oldFile := util.GetFileByNameAndType("chains", do.Name)
if err != nil {
return err
}
oldFile = path.Join(BlockchainsPath, oldFile) + ".toml"
logger.Printf("Removing file =>\t\t%s\n", oldFile)
if err := os.Remove(oldFile); err != nil {
return err
}
}
return nil
}
示例2: KillChain
func KillChain(do *definitions.Do) error {
chain, err := loaders.LoadChainDefinition(do.Name, false, do.Operations.ContainerNumber)
if err != nil {
return err
}
if do.Force {
do.Timeout = 0 //overrides 10 sec default
}
if IsChainRunning(chain) {
if err := perform.DockerStop(chain.Service, chain.Operations, do.Timeout); err != nil {
return err
}
} else {
logger.Infoln("Chain not currently running. Skipping.")
}
if do.Rm {
if err := perform.DockerRemove(chain.Service, chain.Operations, do.RmD, do.Volumes); err != nil {
return err
}
}
return nil
}
示例3: bootDependencies
// boot chain dependencies
// TODO: this currently only supports simple services (with no further dependencies)
func bootDependencies(chain *definitions.Chain, do *definitions.Do) error {
if chain.Dependencies != nil {
name := do.Name
logger.Infoln("Booting chain dependencies", chain.Dependencies.Services, chain.Dependencies.Chains)
for _, srvName := range chain.Dependencies.Services {
do.Name = srvName
srv, err := loaders.LoadServiceDefinition(do.Name, false, do.Operations.ContainerNumber)
if err != nil {
return err
}
// Start corresponding service.
if !services.IsServiceRunning(srv.Service, srv.Operations) {
name := strings.ToUpper(do.Name)
logger.Infof("%s is not running. Starting now. Waiting for %s to become available \n", name, name)
if err = perform.DockerRunService(srv.Service, srv.Operations); err != nil {
return err
}
}
}
do.Name = name // undo side effects
for _, chainName := range chain.Dependencies.Chains {
chn, err := loaders.LoadChainDefinition(chainName, false, do.Operations.ContainerNumber)
if err != nil {
return err
}
if !IsChainRunning(chn) {
return fmt.Errorf("chain %s depends on chain %s but %s is not running", chain.Name, chainName, chainName)
}
}
}
return nil
}
示例4: RmChain
func RmChain(do *definitions.Do) error {
chain, err := loaders.LoadChainDefinition(do.Name, false, do.Operations.ContainerNumber)
if err != nil {
return err
}
if IsChainExisting(chain) {
if err = perform.DockerRemove(chain.Service, chain.Operations, do.RmD, do.Volumes); err != nil {
return err
}
} else {
log.Info("Chain container does not exist")
}
if do.File {
oldFile := util.GetFileByNameAndType("chains", do.Name)
if err != nil {
return err
}
log.WithField("file", oldFile).Warn("Removing file")
if err := os.Remove(oldFile); err != nil {
return err
}
}
return nil
}
示例5: GraduateChain
func GraduateChain(do *definitions.Do) error {
chain, err := loaders.LoadChainDefinition(do.Name, false, 1)
if err != nil {
return err
}
serv := loaders.ServiceDefFromChain(chain, loaders.ErisChainStart)
if err := services.WriteServiceDefinitionFile(serv, filepath.Join(ServicesPath, chain.ChainID+".toml")); err != nil {
return err
}
return nil
}
示例6: LogsChain
func LogsChain(do *definitions.Do) error {
chain, err := loaders.LoadChainDefinition(do.Name, false, do.Operations.ContainerNumber)
if err != nil {
return err
}
err = perform.DockerLogs(chain.Service, chain.Operations, do.Follow, do.Tail)
if err != nil {
return err
}
return nil
}
示例7: PortsChain
func PortsChain(do *definitions.Do) error {
chain, err := loaders.LoadChainDefinition(do.Name, false, do.Operations.ContainerNumber)
if err != nil {
return err
}
if IsChainExisting(chain) {
logger.Debugf("Chain exists, getting port mapping.\n")
return perform.PrintPortMappings(chain.Operations.SrvContainerID, do.Args)
}
return nil
}
示例8: PortsChain
func PortsChain(do *definitions.Do) error {
chain, err := loaders.LoadChainDefinition(do.Name, false, do.Operations.ContainerNumber)
if err != nil {
return err
}
if IsChainExisting(chain) {
log.WithField("=>", chain.Name).Debug("Getting chain port mapping")
return util.PrintPortMappings(chain.Operations.SrvContainerID, do.Operations.Args)
}
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 !util.IsDataContainer(do.Name, do.Operations.ContainerNumber) {
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
}
log.WithField("image", chain.Service.Image).Debug("Chain loaded")
// 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.Operations.Args[0]), // seeds to register for the chain // TODO: deal with multi seed (needs support in tendermint)
}
envVars = append(envVars, do.Env...)
log.WithFields(log.Fields{
"environment": envVars,
"links": do.Links,
}).Debug("Registering chain with")
chain.Service.Environment = append(chain.Service.Environment, envVars...)
chain.Service.Links = append(chain.Service.Links, do.Links...)
if err := bootDependencies(chain, do); err != nil {
return err
}
log.WithFields(log.Fields{
"=>": chain.Service.Name,
"image": chain.Service.Image,
}).Debug("Performing chain container start")
chain.Operations = loaders.LoadDataDefinition(chain.Service.Name, do.Operations.ContainerNumber)
chain.Operations.Args = []string{loaders.ErisChainRegister}
_, err = perform.DockerRunData(chain.Operations, chain.Service)
return err
}
示例10: ExecChain
func ExecChain(do *definitions.Do) error {
chain, err := loaders.LoadChainDefinition(do.Name, false, do.Operations.ContainerNumber)
if err != nil {
return err
}
if IsChainExisting(chain) {
logger.Infoln("Chain exists.")
return perform.DockerExec(chain.Service, chain.Operations, do.Args, do.Interactive)
} else {
return fmt.Errorf("Chain does not exist. Please start the chain container with eris chains start %s.\n", do.Name)
}
return nil
}
示例11: InspectChain
func InspectChain(do *definitions.Do) error {
chain, err := loaders.LoadChainDefinition(do.Name, false, do.Operations.ContainerNumber)
if err != nil {
return err
}
if IsChainExisting(chain) {
log.WithField("=>", chain.Service.Name).Debug("Inspecting chain")
err := services.InspectServiceByService(chain.Service, chain.Operations, do.Operations.Args[0])
if err != nil {
return err
}
}
return nil
}
示例12: InspectChain
func InspectChain(do *definitions.Do) error {
chain, err := loaders.LoadChainDefinition(do.Name, false, do.Operations.ContainerNumber)
if err != nil {
return err
}
if IsChainExisting(chain) {
logger.Debugf("Chain exists, calling services.InspectServiceByService.\n")
err := services.InspectServiceByService(chain.Service, chain.Operations, do.Args[0])
if err != nil {
return err
}
}
return nil
}
示例13: UpdateChain
func UpdateChain(do *definitions.Do) error {
chain, err := loaders.LoadChainDefinition(do.Name, false, do.Operations.ContainerNumber)
if err != nil {
return err
}
// DockerRebuild is built for services, adding false to the final
// variable will mean it pulls. But we want the opposite default
// behaviour for chains as we do for services in this regard
// so we flip the variable.
err = perform.DockerRebuild(chain.Service, chain.Operations, do.SkipPull, do.Timeout)
if err != nil {
return err
}
return nil
}
示例14: 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
}
示例15: StartChain
func StartChain(do *definitions.Do) error {
logger.Infoln("Ensuring Key Server is Started.")
//should it take a flag? keys server may be running another cNum
// XXX: currently we don't use or need a key server.
// plus this should be specified in a service def anyways
keysService, err := loaders.LoadServiceDefinition("keys", false, 1)
if err != nil {
return err
}
err = perform.DockerRun(keysService.Service, keysService.Operations)
if err != nil {
return err
}
chain, err := loaders.LoadChainDefinition(do.Name, false, do.Operations.ContainerNumber)
if err != nil {
logger.Infoln("Cannot start a chain I cannot find.")
do.Result = "no file"
return nil
}
if chain.Name == "" {
logger.Infoln("Cannot start a chain without a name.")
do.Result = "no name"
return nil
}
chain.Service.Command = loaders.ErisChainStart
if do.Run {
chain.Service.Command = loaders.ErisChainStartApi
}
util.OverWriteOperations(chain.Operations, do.Operations)
chain.Service.Environment = append(chain.Service.Environment, "CHAIN_ID="+chain.ChainID)
logger.Infof("StartChainRaw to DockerRun =>\t%s\n", chain.Service.Name)
logger.Debugf("\twith ChainID =>\t\t%v\n", chain.ChainID)
logger.Debugf("\twith Environment =>\t%v\n", chain.Service.Environment)
logger.Debugf("\twith AllPortsPublshd =>\t%v\n", chain.Operations.PublishAllPorts)
if err := perform.DockerRun(chain.Service, chain.Operations); err != nil {
do.Result = "error"
return err
}
return nil
}