本文整理匯總了Golang中github.com/docker/swarmkit/cmd/swarmctl/common.Dial函數的典型用法代碼示例。如果您正苦於以下問題:Golang Dial函數的具體用法?Golang Dial怎麽用?Golang Dial使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了Dial函數的6個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: changeNodeRole
func changeNodeRole(cmd *cobra.Command, args []string, role api.NodeRole) error {
if len(args) == 0 {
return errors.New("missing node ID")
}
c, err := common.Dial(cmd)
if err != nil {
return err
}
node, err := getNode(common.Context(cmd), c, args[0])
if err != nil {
return err
}
spec := &node.Spec
if spec.Role == role {
return errNoChange
}
spec.Role = role
_, err = c.UpdateNode(common.Context(cmd), &api.UpdateNodeRequest{
NodeID: node.ID,
NodeVersion: &node.Meta.Version,
Spec: spec,
})
if err != nil {
return err
}
return nil
}
示例2: updateNode
func updateNode(cmd *cobra.Command, args []string) error {
if len(args) == 0 {
return errors.New("node ID missing")
}
c, err := common.Dial(cmd)
if err != nil {
return err
}
node, err := getNode(common.Context(cmd), c, args[0])
if err != nil {
return err
}
spec := node.Spec.Copy()
flags := cmd.Flags()
if flags.Changed(flagLabel) {
labels, err := flags.GetStringSlice(flagLabel)
if err != nil {
return err
}
// overwrite existing labels
spec.Annotations.Labels = map[string]string{}
for _, l := range labels {
parts := strings.SplitN(l, "=", 2)
if len(parts) != 2 {
return fmt.Errorf("malformed label for node %s", l)
}
spec.Annotations.Labels[strings.TrimSpace(parts[0])] = strings.TrimSpace(parts[1])
}
}
if reflect.DeepEqual(spec, &node.Spec) {
return errNoChange
}
_, err = c.UpdateNode(common.Context(cmd), &api.UpdateNodeRequest{
NodeID: node.ID,
NodeVersion: &node.Meta.Version,
Spec: spec,
})
if err != nil {
return err
}
return nil
}
示例3: changeNodeMembership
func changeNodeMembership(cmd *cobra.Command, args []string, membership api.NodeSpec_Membership) error {
if len(args) == 0 {
return errors.New("missing node ID")
}
if len(args) > 1 {
return errors.New("command takes exactly 1 argument")
}
c, err := common.Dial(cmd)
if err != nil {
return err
}
node, err := getNode(common.Context(cmd), c, args[0])
if err != nil {
return err
}
spec := &node.Spec
if spec.Membership == membership {
return errNoChange
}
spec.Membership = membership
_, err = c.UpdateNode(common.Context(cmd), &api.UpdateNodeRequest{
NodeID: node.ID,
NodeVersion: &node.Meta.Version,
Spec: spec,
})
if err != nil {
return err
}
return nil
}
示例4:
"github.com/docker/swarmkit/api"
"github.com/docker/swarmkit/cmd/swarmctl/common"
"github.com/spf13/cobra"
)
var removeCmd = &cobra.Command{
Use: "remove <secret ID or name>",
Short: "Remove a secret",
Aliases: []string{"rm"},
RunE: func(cmd *cobra.Command, args []string) error {
if len(args) == 0 {
return errors.New("remove command takes a single secret ID or name")
}
client, err := common.Dial(cmd)
if err != nil {
return err
}
secret, err := getSecret(common.Context(cmd), client, args[0])
if err != nil {
return err
}
_, err = client.RemoveSecret(common.Context(cmd), &api.RemoveSecretRequest{SecretID: secret.ID})
if err != nil {
return err
}
fmt.Println(secret.ID)
return nil
示例5:
"github.com/spf13/cobra"
)
var (
listCmd = &cobra.Command{
Use: "ls",
Short: "List clusters",
RunE: func(cmd *cobra.Command, args []string) error {
flags := cmd.Flags()
quiet, err := flags.GetBool("quiet")
if err != nil {
return err
}
c, err := common.Dial(cmd)
if err != nil {
return err
}
r, err := c.ListClusters(common.Context(cmd), &api.ListClustersRequest{})
if err != nil {
return err
}
var output func(j *api.Cluster)
if !quiet {
w := tabwriter.NewWriter(os.Stdout, 0, 4, 2, ' ', 0)
defer func() {
// Ignore flushing errors - there's nothing we can do.
_ = w.Flush()
示例6: ParseAddSecret
// ParseAddSecret validates secrets passed on the command line
func ParseAddSecret(cmd *cobra.Command, spec *api.ServiceSpec, flagName string) error {
flags := cmd.Flags()
if flags.Changed(flagName) {
secrets, err := flags.GetStringSlice(flagName)
if err != nil {
return err
}
container := spec.Task.GetContainer()
if container == nil {
spec.Task.Runtime = &api.TaskSpec_Container{
Container: &api.ContainerSpec{},
}
}
lookupSecretNames := []string{}
var needSecrets []*api.SecretReference
for _, secret := range secrets {
n, p, err := parseSecretString(secret)
if err != nil {
return err
}
// TODO(diogo): defaults to File targets, but in the future will take different types
secretRef := &api.SecretReference{
SecretName: n,
Target: &api.SecretReference_File{
File: &api.SecretReference_FileTarget{
Name: p,
Mode: 0444,
},
},
}
lookupSecretNames = append(lookupSecretNames, n)
needSecrets = append(needSecrets, secretRef)
}
client, err := common.Dial(cmd)
if err != nil {
return err
}
r, err := client.ListSecrets(common.Context(cmd),
&api.ListSecretsRequest{Filters: &api.ListSecretsRequest_Filters{Names: lookupSecretNames}})
if err != nil {
return err
}
foundSecrets := make(map[string]*api.Secret)
for _, secret := range r.Secrets {
foundSecrets[secret.Spec.Annotations.Name] = secret
}
for _, secretRef := range needSecrets {
secret, ok := foundSecrets[secretRef.SecretName]
if !ok {
return fmt.Errorf("secret not found: %s", secretRef.SecretName)
}
secretRef.SecretID = secret.ID
container.Secrets = append(container.Secrets, secretRef)
}
}
return nil
}