func (cmd *setcert) Run(ctx context.Context, f *flag.FlagSet) error { c, err := cmd.Client() if err != nil { return err } m, err := object.GetExtensionManager(c) if err != nil { return err } if f.NArg() != 1 { return flag.ErrHelp } key := f.Arg(0) if cmd.cert == "-" { b, err := ioutil.ReadAll(os.Stdin) if err != nil { return err } cmd.cert = string(b) } else if cmd.cert == "+" { if err := cmd.create(key); err != nil { return fmt.Errorf("creating certificate: %s", err) } cmd.cert = cmd.encodedCert.String() } return m.SetCertificate(ctx, key, cmd.cert) }
func (cmd *insert) Run(f *flag.FlagSet) error { vm, err := cmd.VirtualMachine() if err != nil { return err } if vm == nil || f.NArg() != 1 { return flag.ErrHelp } devices, err := vm.Device(context.TODO()) if err != nil { return err } c, err := devices.FindCdrom(cmd.device) if err != nil { return err } iso, err := cmd.DatastorePath(f.Arg(0)) if err != nil { return nil } return vm.EditDevice(context.TODO(), devices.InsertIso(c, iso)) }
func (cmd *ovfx) Prepare(f *flag.FlagSet) (string, error) { var err error args := f.Args() if len(args) != 1 { return "", errors.New("no file specified") } cmd.Client, err = cmd.DatastoreFlag.Client() if err != nil { return "", err } cmd.Datacenter, err = cmd.DatastoreFlag.Datacenter() if err != nil { return "", err } cmd.Datastore, err = cmd.DatastoreFlag.Datastore() if err != nil { return "", err } cmd.ResourcePool, err = cmd.ResourcePoolFlag.ResourcePool() if err != nil { return "", err } return f.Arg(0), nil }
func multisnapshotCmd(mysqld *mysqlctl.Mysqld, subFlags *flag.FlagSet, args []string) { concurrency := subFlags.Int("concurrency", 8, "how many compression jobs to run simultaneously") spec := subFlags.String("spec", "-", "shard specification") tablesString := subFlags.String("tables", "", "dump only this comma separated list of tables") skipSlaveRestart := subFlags.Bool("skip-slave-restart", false, "after the snapshot is done, do not restart slave replication") maximumFilesize := subFlags.Uint64("maximum-file-size", 128*1024*1024, "the maximum size for an uncompressed data file") subFlags.Parse(args) if subFlags.NArg() != 2 { relog.Fatal("action multisnapshot requires <db name> <key name>") } shards, err := key.ParseShardingSpec(*spec) if err != nil { relog.Fatal("multisnapshot failed: %v", err) } var tables []string if *tablesString != "" { tables = strings.Split(*tablesString, ",") } filenames, err := mysqld.CreateMultiSnapshot(shards, subFlags.Arg(0), subFlags.Arg(1), tabletAddr, false, *concurrency, tables, *skipSlaveRestart, *maximumFilesize, nil) if err != nil { relog.Fatal("multisnapshot failed: %v", err) } else { relog.Info("manifest locations: %v", filenames) } }
func (cmd *service) Run(ctx context.Context, f *flag.FlagSet) error { if f.NArg() != 2 { return flag.ErrHelp } service := f.Arg(0) device := f.Arg(1) host, err := cmd.HostSystem() if err != nil { return err } m, err := host.ConfigManager().VirtualNicManager(ctx) if err != nil { return err } var method func(context.Context, string, string) error if cmd.Enable { method = m.SelectVnic } else if cmd.Disable { method = m.DeselectVnic } if method == nil { return flag.ErrHelp } return method(ctx, service, device) }
func commandVtTabletRollback(ctx context.Context, wr *wrangler.Wrangler, subFlags *flag.FlagSet, args []string) error { connectTimeout := subFlags.Duration("connect_timeout", 30*time.Second, "Connection timeout for vttablet client") if err := subFlags.Parse(args); err != nil { return err } if subFlags.NArg() != 2 { return fmt.Errorf("the <tablet_alias> and <transaction_id> arguments are required for the VtTabletRollback command") } transactionID, err := strconv.ParseInt(subFlags.Arg(1), 10, 64) if err != nil { return err } tabletAlias, err := topoproto.ParseTabletAlias(subFlags.Arg(0)) if err != nil { return err } tabletInfo, err := wr.TopoServer().GetTablet(ctx, tabletAlias) if err != nil { return err } conn, err := tabletconn.GetDialer()(tabletInfo.Tablet, *connectTimeout) if err != nil { return fmt.Errorf("cannot connect to tablet %v: %v", tabletAlias, err) } defer conn.Close(ctx) return conn.Rollback(ctx, &querypb.Target{ Keyspace: tabletInfo.Tablet.Keyspace, Shard: tabletInfo.Tablet.Shard, TabletType: tabletInfo.Tablet.Type, }, transactionID) }
func commandSplitClone(wi *Instance, wr *wrangler.Wrangler, subFlags *flag.FlagSet, args []string) (Worker, error) { online := subFlags.Bool("online", defaultOnline, "do online copy (optional approximate copy, source and destination tablets will not be put out of serving, minimizes downtime during offline copy)") offline := subFlags.Bool("offline", defaultOffline, "do offline copy (exact copy at a specific GTID, required before shard migration, source and destination tablets will be put out of serving during copy)") excludeTables := subFlags.String("exclude_tables", "", "comma separated list of tables to exclude") strategy := subFlags.String("strategy", "", "which strategy to use for restore, use 'vtworker SplitClone --strategy=-help k/s' for more info") sourceReaderCount := subFlags.Int("source_reader_count", defaultSourceReaderCount, "number of concurrent streaming queries to use on the source") writeQueryMaxRows := subFlags.Int("write_query_max_rows", defaultWriteQueryMaxRows, "maximum number of rows per write query") writeQueryMaxSize := subFlags.Int("write_query_max_size", defaultWriteQueryMaxSize, "maximum size (in bytes) per write query") writeQueryMaxRowsDelete := subFlags.Int("write_query_max_rows_delete", defaultWriteQueryMaxRows, "maximum number of rows per DELETE FROM write query") minTableSizeForSplit := subFlags.Int("min_table_size_for_split", defaultMinTableSizeForSplit, "tables bigger than this size on disk in bytes will be split into source_reader_count chunks if possible") destinationWriterCount := subFlags.Int("destination_writer_count", defaultDestinationWriterCount, "number of concurrent RPCs to execute on the destination") minHealthyRdonlyTablets := subFlags.Int("min_healthy_rdonly_tablets", defaultMinHealthyRdonlyTablets, "minimum number of healthy RDONLY tablets in the source and destination shard at start") maxTPS := subFlags.Int64("max_tps", defaultMaxTPS, "if non-zero, limit copy to maximum number of (write) transactions/second on the destination (unlimited by default)") if err := subFlags.Parse(args); err != nil { return nil, err } if subFlags.NArg() != 1 { subFlags.Usage() return nil, fmt.Errorf("command SplitClone requires <keyspace/shard>") } keyspace, shard, err := topoproto.ParseKeyspaceShard(subFlags.Arg(0)) if err != nil { return nil, err } var excludeTableArray []string if *excludeTables != "" { excludeTableArray = strings.Split(*excludeTables, ",") } worker, err := NewSplitCloneWorker(wr, wi.cell, keyspace, shard, *online, *offline, excludeTableArray, *strategy, *sourceReaderCount, *writeQueryMaxRows, *writeQueryMaxSize, *writeQueryMaxRowsDelete, uint64(*minTableSizeForSplit), *destinationWriterCount, *minHealthyRdonlyTablets, *maxTPS) if err != nil { return nil, fmt.Errorf("cannot create split clone worker: %v", err) } return worker, nil }
func (cmd *env) Run(ctx context.Context, f *flag.FlagSet) error { env := envResult(cmd.ClientFlag.Environ(cmd.extra)) if f.NArg() > 1 { return flag.ErrHelp } // Option to just output the value, example use: // password=$(govc env GOVC_PASSWORD) if f.NArg() == 1 { var output []string prefix := fmt.Sprintf("%s=", f.Arg(0)) for _, e := range env { if strings.HasPrefix(e, prefix) { output = append(output, e[len(prefix):]) break } } return cmd.WriteResult(envResult(output)) } return cmd.WriteResult(env) }
func commandVtGateExecute(ctx context.Context, wr *wrangler.Wrangler, subFlags *flag.FlagSet, args []string) error { server := subFlags.String("server", "", "VtGate server to connect to") bindVariables := newBindvars(subFlags) connectTimeout := subFlags.Duration("connect_timeout", 30*time.Second, "Connection timeout for vtgate client") tabletType := subFlags.String("tablet_type", "master", "tablet type to query") json := subFlags.Bool("json", false, "Output JSON instead of human-readable table") if err := subFlags.Parse(args); err != nil { return err } if subFlags.NArg() != 1 { return fmt.Errorf("the <sql> argument is required for the VtGateExecute command") } t, err := parseTabletType(*tabletType, []topodatapb.TabletType{topodatapb.TabletType_MASTER, topodatapb.TabletType_REPLICA, topodatapb.TabletType_RDONLY}) if err != nil { return err } vtgateConn, err := vtgateconn.Dial(ctx, *server, *connectTimeout) if err != nil { return fmt.Errorf("error connecting to vtgate '%v': %v", *server, err) } defer vtgateConn.Close() qr, err := vtgateConn.Execute(ctx, subFlags.Arg(0), *bindVariables, t) if err != nil { return fmt.Errorf("Execute failed: %v", err) } if *json { return printJSON(wr.Logger(), qr) } printQueryResult(loggerWriter{wr.Logger()}, qr) return nil }
func (cmd *revert) Run(ctx context.Context, f *flag.FlagSet) error { if f.NArg() > 1 { return flag.ErrHelp } vm, err := cmd.VirtualMachine() if err != nil { return err } if vm == nil { return flag.ErrHelp } var task *object.Task if f.NArg() == 1 { task, err = vm.RevertToSnapshot(ctx, f.Arg(0), cmd.suppressPowerOn) } else { task, err = vm.RevertToCurrentSnapshot(ctx, cmd.suppressPowerOn) } if err != nil { return err } return task.Wait(ctx) }
func (cmd *upload) Run(ctx context.Context, f *flag.FlagSet) error { if f.NArg() != 2 { return flag.ErrHelp } m, err := cmd.FileManager() if err != nil { return err } src := f.Arg(0) dst := f.Arg(1) var size int64 var buf *bytes.Buffer if src == "-" { buf = new(bytes.Buffer) size, err = io.Copy(buf, os.Stdin) if err != nil { return err } } else { s, err := os.Stat(src) if err != nil { return err } size = s.Size() } url, err := m.InitiateFileTransferToGuest(ctx, cmd.Auth(), dst, cmd.Attr(), size, cmd.overwrite) if err != nil { return err } u, err := cmd.ParseURL(url) if err != nil { return err } c, err := cmd.Client() if err != nil { return nil } p := soap.DefaultUpload if buf != nil { p.ContentLength = size return c.Client.Upload(buf, u, &p) } if cmd.OutputFlag.TTY { logger := cmd.ProgressLogger("Uploading... ") p.Progress = logger defer logger.Wait() } return c.Client.UploadFile(src, u, nil) }
func (cmd *add) Run(ctx context.Context, f *flag.FlagSet) error { if f.NArg() == 0 { return flag.ErrHelp } name := f.Arg(0) finder, err := cmd.Finder() if err != nil { return err } net, err := finder.Network(ctx, cmd.path) if err != nil { return err } dvs, ok := net.(*object.DistributedVirtualSwitch) if !ok { return fmt.Errorf("%s (%T) is not of type %T", cmd.path, net, dvs) } cmd.DVPortgroupConfigSpec.Name = name task, err := dvs.AddPortgroup(ctx, []types.DVPortgroupConfigSpec{cmd.DVPortgroupConfigSpec}) if err != nil { return err } logger := cmd.ProgressLogger(fmt.Sprintf("adding %s portgroup to dvs %s... ", name, dvs.InventoryPath)) defer logger.Wait() _, err = task.WaitForResult(ctx, logger) return err }
func commandRestoreFromBackup(ctx context.Context, wr *wrangler.Wrangler, subFlags *flag.FlagSet, args []string) error { if err := subFlags.Parse(args); err != nil { return err } if subFlags.NArg() != 1 { return fmt.Errorf("The RestoreFromBackup command requires the <tablet alias> argument.") } tabletAlias, err := topoproto.ParseTabletAlias(subFlags.Arg(0)) if err != nil { return err } tabletInfo, err := wr.TopoServer().GetTablet(ctx, tabletAlias) if err != nil { return err } stream, err := wr.TabletManagerClient().RestoreFromBackup(ctx, tabletInfo.Tablet) if err != nil { return err } for { e, err := stream.Recv() switch err { case nil: logutil.LogEvent(wr.Logger(), e) case io.EOF: return nil default: return err } } }
func commandListBackups(ctx context.Context, wr *wrangler.Wrangler, subFlags *flag.FlagSet, args []string) error { if err := subFlags.Parse(args); err != nil { return err } if subFlags.NArg() != 1 { return fmt.Errorf("action ListBackups requires <keyspace/shard>") } keyspace, shard, err := topoproto.ParseKeyspaceShard(subFlags.Arg(0)) if err != nil { return err } bucket := fmt.Sprintf("%v/%v", keyspace, shard) bs, err := backupstorage.GetBackupStorage() if err != nil { return err } defer bs.Close() bhs, err := bs.ListBackups(bucket) if err != nil { return err } for _, bh := range bhs { wr.Logger().Printf("%v\n", bh.Name()) } return nil }
func commandVtGateExecuteShards(ctx context.Context, wr *wrangler.Wrangler, subFlags *flag.FlagSet, args []string) error { server := subFlags.String("server", "", "VtGate server to connect to") bindVariables := newBindvars(subFlags) connectTimeout := subFlags.Duration("connect_timeout", 30*time.Second, "Connection timeout for vtgate client") tabletType := subFlags.String("tablet_type", "master", "tablet type to query") keyspace := subFlags.String("keyspace", "", "keyspace to send query to") shardsStr := subFlags.String("shards", "", "comma-separated list of shards to send query to") if err := subFlags.Parse(args); err != nil { return err } if subFlags.NArg() != 1 { return fmt.Errorf("the <sql> argument is required for the VtGateExecuteShards command") } t, err := parseTabletType(*tabletType, []pb.TabletType{pb.TabletType_MASTER, pb.TabletType_REPLICA, pb.TabletType_RDONLY}) if err != nil { return err } var shards []string if *shardsStr != "" { shards = strings.Split(*shardsStr, ",") } vtgateConn, err := vtgateconn.Dial(ctx, *server, *connectTimeout) if err != nil { return fmt.Errorf("error connecting to vtgate '%v': %v", *server, err) } defer vtgateConn.Close() qr, err := vtgateConn.ExecuteShards(ctx, subFlags.Arg(0), *keyspace, shards, *bindVariables, t) if err != nil { return fmt.Errorf("Execute failed: %v", err) } return printJSON(wr, qr) }
func (cmd *create) Run(ctx context.Context, f *flag.FlagSet) error { if f.NArg() != 1 { return flag.ErrHelp } name := f.Arg(0) cmd.configSpec.Name = name folder, err := cmd.FolderOrDefault("network") if err != nil { return err } task, err := folder.CreateDVS(ctx, cmd.DVSCreateSpec) if err != nil { return err } logger := cmd.ProgressLogger(fmt.Sprintf("adding %s to folder %s... ", name, folder.InventoryPath)) defer logger.Wait() _, err = task.WaitForResult(ctx, logger) return err }
func commandVtGateSplitQuery(ctx context.Context, wr *wrangler.Wrangler, subFlags *flag.FlagSet, args []string) error { server := subFlags.String("server", "", "VtGate server to connect to") bindVariables := newBindvars(subFlags) connectTimeout := subFlags.Duration("connect_timeout", 30*time.Second, "Connection timeout for vtgate client") splitColumn := subFlags.String("split_column", "", "force the use of this column to split the query") splitCount := subFlags.Int("split_count", 16, "number of splits to generate") keyspace := subFlags.String("keyspace", "", "keyspace to send query to") if err := subFlags.Parse(args); err != nil { return err } if subFlags.NArg() != 1 { return fmt.Errorf("the <sql> argument is required for the VtGateSplitQuery command") } vtgateConn, err := vtgateconn.Dial(ctx, *server, *connectTimeout, "") if err != nil { return fmt.Errorf("error connecting to vtgate '%v': %v", *server, err) } defer vtgateConn.Close() r, err := vtgateConn.SplitQuery(ctx, *keyspace, subFlags.Arg(0), *bindVariables, *splitColumn, int64(*splitCount)) if err != nil { return fmt.Errorf("SplitQuery failed: %v", err) } return printJSON(wr.Logger(), r) }
func (cmd *add) Run(f *flag.FlagSet) error { if f.NArg() != 1 { return flag.ErrHelp } ctx := context.TODO() c, err := cmd.Client() if err != nil { return err } m, err := object.GetCustomFieldsManager(c) if err != nil { return err } name := f.Arg(0) def, err := m.Add(ctx, name, "", nil, nil) if err != nil { return err } fmt.Printf("%d\n", def.Key) return nil }
func commandEmergencyReparentShard(ctx context.Context, wr *wrangler.Wrangler, subFlags *flag.FlagSet, args []string) error { waitSlaveTimeout := subFlags.Duration("wait_slave_timeout", 30*time.Second, "time to wait for slaves to catch up in reparenting") keyspaceShard := subFlags.String("keyspace_shard", "", "keyspace/shard of the shard that needs to be reparented") newMaster := subFlags.String("new_master", "", "alias of a tablet that should be the new master") if err := subFlags.Parse(args); err != nil { return err } if subFlags.NArg() == 2 { // Legacy syntax: "<keyspace/shard> <tablet alias>". if *newMaster != "" { return fmt.Errorf("cannot use legacy syntax and flag -new_master for action EmergencyReparentShard at the same time") } *keyspaceShard = subFlags.Arg(0) *newMaster = subFlags.Arg(1) } else if subFlags.NArg() != 0 { return fmt.Errorf("action EmergencyReparentShard requires -keyspace_shard=<keyspace/shard> -new_master=<tablet alias>") } keyspace, shard, err := topoproto.ParseKeyspaceShard(*keyspaceShard) if err != nil { return err } tabletAlias, err := topoproto.ParseTabletAlias(*newMaster) if err != nil { return err } return wr.EmergencyReparentShard(ctx, keyspace, shard, tabletAlias, *waitSlaveTimeout) }
func (cmd *mv) Run(ctx context.Context, f *flag.FlagSet) error { if f.NArg() < 2 { return flag.ErrHelp } finder, err := cmd.Finder() if err != nil { return err } n := f.NArg() - 1 folder, err := finder.Folder(ctx, f.Arg(n)) if err != nil { return err } objs, err := cmd.ManagedObjects(ctx, f.Args()[:n]) if err != nil { return err } task, err := folder.MoveInto(ctx, objs) if err != nil { return err } logger := cmd.ProgressLogger(fmt.Sprintf("moving %d objects to %s... ", len(objs), folder.InventoryPath)) _, err = task.WaitForResult(ctx, logger) logger.Wait() return err }
func (cmd *install) Run(ctx context.Context, f *flag.FlagSet) error { host, err := cmd.HostSystem() if err != nil { return err } m, err := host.ConfigManager().CertificateManager(ctx) if err != nil { return err } var cert string name := f.Arg(0) if name == "-" || name == "" { var buf bytes.Buffer if _, err := io.Copy(&buf, os.Stdin); err != nil { return err } cert = buf.String() } else { b, err := ioutil.ReadFile(name) if err != nil { return err } cert = string(b) } return m.InstallServerCertificate(ctx, cert) }
func commandVtGateExecute(ctx context.Context, wr *wrangler.Wrangler, subFlags *flag.FlagSet, args []string) error { server := subFlags.String("server", "", "VtGate server to connect to") bindVariables := newBindvars(subFlags) connectTimeout := subFlags.Duration("connect_timeout", 30*time.Second, "Connection timeout for vtgate client") tabletType := subFlags.String("tablet_type", "master", "tablet type to query") if err := subFlags.Parse(args); err != nil { return err } if subFlags.NArg() != 1 { return fmt.Errorf("the <sql> argument is required for the VtGateExecute command") } t, err := parseTabletType(*tabletType, []topo.TabletType{topo.TYPE_MASTER, topo.TYPE_REPLICA, topo.TYPE_RDONLY}) if err != nil { return err } vtgateConn, err := vtgateconn.Dial(ctx, *server, *connectTimeout) if err != nil { return fmt.Errorf("error connecting to vtgate '%v': %v", *server, err) } defer vtgateConn.Close() qr, err := vtgateConn.Execute(ctx, subFlags.Arg(0), *bindVariables, t) if err != nil { return fmt.Errorf("Execute failed: %v", err) } wr.Logger().Printf("%v\n", jscfg.ToJSON(qr)) return nil }
func mainReqs(args []string, flags *flag.FlagSet) { flags.Usage = func() { fmt.Fprintf(os.Stderr, "Usage: %s %s <package-name>\n", os.Args[0], args[0]) flags.PrintDefaults() } file := flags.String("graphfile", "", fmt.Sprintf("Path to PyPI dependency graph file. Defaults to $GOPATH/src/github.com/beyang/cheerio/data/pypi_graph")) flags.Parse(args[1:]) if flags.NArg() < 1 { flags.Usage() os.Exit(1) } pkg := cheerio.NormalizedPkgName(flags.Arg(0)) var pypiG *cheerio.PyPIGraph if *file == "" { pypiG = cheerio.DefaultPyPIGraph } else { var err error pypiG, err = cheerio.NewPyPIGraph(*file) if err != nil { fmt.Printf("Error creating PyPI graph: %s\n", err) os.Exit(1) } } pkgReq := pypiG.Requires(pkg) pkgReqBy := pypiG.RequiredBy(pkg) fmt.Printf("pkg %s uses (%d):\n %s\nand is used by (%d):\n %s\n", pkg, len(pkgReq), strings.Join(pkgReq, " "), len(pkgReqBy), strings.Join(pkgReqBy, " ")) }
// Create an ephemeral node an just wait. func cmdElock(subFlags *flag.FlagSet, args []string) error { subFlags.Parse(args) zkPath := fixZkPath(subFlags.Arg(0)) // Speed up case where we die nicely, otherwise you have to wait for // the server to notice the client's demise. sigRecv := make(chan os.Signal, 1) signal.Notify(sigRecv, os.Interrupt) for { _, err := zconn.Create(zkPath, "", zookeeper.EPHEMERAL, zookeeper.WorldACL(zookeeper.PERM_ALL)) if err != nil { return fmt.Errorf("elock: error %v: %v", zkPath, err) } watchLoop: for { _, _, watch, err := zconn.GetW(zkPath) if err != nil { return fmt.Errorf("elock: error %v: %v", zkPath, err) } select { case <-sigRecv: zconn.Delete(zkPath, -1) return nil case event := <-watch: log.Infof("elock: event %v: %v", zkPath, event) if !event.Ok() { //return fmt.Errorf("elock: error %v: %v", zkPath, event) break watchLoop } } } } }
func (cmd *download) Run(f *flag.FlagSet) error { m, err := cmd.FileManager() if err != nil { return err } src := f.Arg(0) dst := f.Arg(1) _, err = os.Stat(dst) if err == nil && !cmd.overwrite { return os.ErrExist } info, err := m.InitiateFileTransferFromGuest(context.TODO(), cmd.Auth(), src) if err != nil { return err } u, err := cmd.ParseURL(info.Url) if err != nil { return err } c, err := cmd.Client() if err != nil { return nil } return c.Client.DownloadFile(dst, u, nil) }
func (cmd *insert) Run(ctx context.Context, f *flag.FlagSet) error { vm, err := cmd.VirtualMachine() if err != nil { return err } if vm == nil || f.NArg() != 1 { return flag.ErrHelp } devices, err := vm.Device(ctx) if err != nil { return err } c, err := devices.FindFloppy(cmd.device) if err != nil { return err } img, err := cmd.DatastorePath(f.Arg(0)) if err != nil { return nil } return vm.EditDevice(ctx, devices.InsertImg(c, img)) }
func (cmd *rename) Run(f *flag.FlagSet) error { if f.NArg() != 2 { return flag.ErrHelp } ctx := context.TODO() c, err := cmd.Client() if err != nil { return err } m, err := object.GetCustomFieldsManager(c) if err != nil { return err } key, err := m.FindKey(ctx, f.Arg(0)) if err != nil { return err } name := f.Arg(1) return m.Rename(ctx, key, name) }
func (cmd *ls) Run(ctx context.Context, f *flag.FlagSet) error { m, err := cmd.FileManager() if err != nil { return err } var offset int32 tw := tabwriter.NewWriter(os.Stdout, 3, 0, 2, ' ', 0) for { info, err := m.ListFiles(ctx, cmd.Auth(), f.Arg(0), offset, 0, f.Arg(1)) if err != nil { return err } for _, f := range info.Files { attr := f.Attributes.GetGuestFileAttributes() // TODO: GuestPosixFileAttributes fmt.Fprintf(tw, "%d\t%s\t%s\n", f.Size, attr.ModificationTime.Format("Mon Jan 2 15:04:05 2006"), f.Path) } _ = tw.Flush() if info.Remaining == 0 { break } offset += int32(len(info.Files)) } return nil }
func commandVerticalSplitClone(wi *Instance, wr *wrangler.Wrangler, subFlags *flag.FlagSet, args []string) (Worker, error) { tables := subFlags.String("tables", "", "comma separated list of tables to replicate (used for vertical split)") strategy := subFlags.String("strategy", "", "which strategy to use for restore, use 'mysqlctl multirestore -strategy=-help' for more info") sourceReaderCount := subFlags.Int("source_reader_count", defaultSourceReaderCount, "number of concurrent streaming queries to use on the source") destinationPackCount := subFlags.Int("destination_pack_count", defaultDestinationPackCount, "number of packets to pack in one destination insert") minTableSizeForSplit := subFlags.Int("min_table_size_for_split", defaultMinTableSizeForSplit, "tables bigger than this size on disk in bytes will be split into source_reader_count chunks if possible") destinationWriterCount := subFlags.Int("destination_writer_count", defaultDestinationWriterCount, "number of concurrent RPCs to execute on the destination") if err := subFlags.Parse(args); err != nil { return nil, err } if subFlags.NArg() != 1 { subFlags.Usage() return nil, fmt.Errorf("command VerticalSplitClone requires <destination keyspace/shard>") } keyspace, shard, err := topo.ParseKeyspaceShardString(subFlags.Arg(0)) if err != nil { return nil, err } var tableArray []string if *tables != "" { tableArray = strings.Split(*tables, ",") } worker, err := NewVerticalSplitCloneWorker(wr, wi.cell, keyspace, shard, tableArray, *strategy, *sourceReaderCount, *destinationPackCount, uint64(*minTableSizeForSplit), *destinationWriterCount) if err != nil { return nil, fmt.Errorf("cannot create worker: %v", err) } return worker, nil }
func commandWorkflowCreate(ctx context.Context, wr *wrangler.Wrangler, subFlags *flag.FlagSet, args []string) error { if WorkflowManager == nil { return fmt.Errorf("no workflow.Manager registered") } skipStart := subFlags.Bool("skip_start", false, "If set, the workflow will not be started.") if err := subFlags.Parse(args); err != nil { return err } if subFlags.NArg() < 1 { return fmt.Errorf("the <factoryName> argument is required for the WorkflowCreate command") } factoryName := subFlags.Arg(0) uuid, err := WorkflowManager.Create(ctx, factoryName, subFlags.Args()[1:]) if err != nil { return err } wr.Logger().Printf("uuid: %v\n", uuid) if !*skipStart { return WorkflowManager.Start(ctx, uuid) } return nil }