// deleteMachineCmd returns a command to delete a machine.
487956
func deleteMachineCmd(params *Parameters) *subcommands.Command {
	return &subcommands.Command{
		UsageLine: "del-machine -name <name>",
		ShortDesc: "deletes a machine",
		LongDesc:  "Deletes a machine from the database.\n\nExample:\ncrimson del-machine -name xx11-11-720",
		CommandRun: func() subcommands.CommandRun {
			cmd := &DeleteMachineCmd{}
			cmd.Initialize(params)
			cmd.Flags.StringVar(&cmd.req.Name, "name", "", "The name of the machine to delete.")
			return cmd
		},
	}
}
916984
func deleteAgentsCommand() *cli.Command {
	return &cli.Command{
		Name:     DeleteAgentsCommandName,
		Usage:    DeleteAgentsCommandUsage,
		Action:   ActionWrapper(deleteAgentsAction),
		Category: agentCategory,
		Flags: []cli.Flag{
			cli.StringSliceFlag{Name: "uuid", Usage: "GoCD Agent UUIDs"},
		},
	}
}
469300
func (vm VirtualMachine) Delete(ctx context.Context, client *Client) error {
	_, err := client.RequestWithContext(ctx, &DestroyVirtualMachine{
		ID: vm.ID,
	})

	return err
}
349909
func (n *Netrc) RemoveMachine(name string) {
	for i, machine := range n.machines {
		if machine.Name == name {
			n.machines = append(n.machines[:i], n.machines[i+1:]...)
			// continue removing but start over since the indexes changed
			n.RemoveMachine(name)
			return
		}
	}
}
188442
func (u *Unit) MachineId() string {
	u.mu.Lock()
	defer u.mu.Unlock()
	return u.details.MachineId
}
953134
func runMachine(context machineContext, m machine, changed <-chan struct{}, died chan<- machine, clock clock.Clock) {
	defer func() {
		// We can't just send on the died channel because the
		// central loop might be trying to write to us on the
		// changed channel.
		for {
			select {
			case died <- m:
				return
			case <-changed:
			}
		}
	}()
	if err := machineLoop(context, m, changed, clock); err != nil {
		context.kill(err)
	}
}
691592
func (g *ResourceCommand) IsDeleteSubcommand(cmd string) bool {
	return cmd == g.deleteCmd.FullCommand()
}
341511
func (c *CloudAPI) RenameMachine(machineID, newName string) error {
	if err := c.ProcessFunctionHook(c, machineID, newName); err != nil {
		return err
	}

	for _, machine := range c.machines {
		if machine.Id == machineID {
			machine.Name = newName
			machine.Updated = time.Now().Format("2013-11-26T19:47:13.448Z")
			return nil
		}
	}

	return fmt.Errorf("Machine %s not found", machineID)
}
1341223
func (s *LabelCounters) SetMachineLabeled(v int64) *LabelCounters {
	s.MachineLabeled = &v
	return s
}
1325177
func (c *Client) DeleteMacro(ctx context.Context, id platform.ID) error {
	op := getOp(platform.OpDeleteMacro)
	return c.db.Update(func(tx *bolt.Tx) error {
		b := tx.Bucket(macroBucket)

		encID, err := id.Encode()
		if err != nil {
			return &platform.Error{
				Code: platform.EInvalid,
				Op:   op,
				Err:  err,
			}
		}

		d := b.Get(encID)
		if d == nil {
			return &platform.Error{
				Code: platform.ENotFound,
				Op:   op,
				Msg:  "macro not found",
			}
		}

		if err := b.Delete(encID); err != nil {
			return &platform.Error{
				Op:  op,
				Err: err,
			}
		}

		return nil
	})
}
286427
func DestroyMachine(c *kvmContainer) error {
	if c.runCmd == nil {
		c.runCmd = run
	}
	if c.pathfinder == nil {
		c.pathfinder = paths.DataDir
	}

	// We don't return errors for virsh commands because it is possible that we
	// didn't succeed in creating the domain. Additionally, we want all the
	// commands to run. If any fail it is certainly because the thing we're
	// trying to remove wasn't created. However, we still want to try removing
	// all the parts. The exception here is getting the guestBase, if that
	// fails we return the error because we cannot continue without it.

	_, err := c.runCmd("", virsh, "destroy", c.Name())
	if err != nil {
		logger.Infof("`%s destroy %s` failed: %q", virsh, c.Name(), err)
	}

	// The nvram flag here removes the pflash drive for us. There is also a
	// `remove-all-storage` flag, but it is unclear if that would also remove
	// the backing store which we don't want to do. So we remove those manually
	// after undefining.
	_, err = c.runCmd("", virsh, "undefine", "--nvram", c.Name())
	if err != nil {
		logger.Infof("`%s undefine --nvram %s` failed: %q", virsh, c.Name(), err)
	}
	guestBase, err := guestPath(c.pathfinder)
	if err != nil {
		return errors.Trace(err)
	}
	err = os.Remove(filepath.Join(guestBase, fmt.Sprintf("%s.qcow", c.Name())))
	if err != nil {
		logger.Errorf("failed to remove system disk for %q: %s", c.Name(), err)
	}
	err = os.Remove(filepath.Join(guestBase, fmt.Sprintf("%s-ds.iso", c.Name())))
	if err != nil {
		logger.Errorf("failed to remove cloud-init data disk for %q: %s", c.Name(), err)
	}

	return nil
}
1061995
func (c *CloudAPI) DeleteMachine(machineID string) error {
	if err := c.ProcessFunctionHook(c, machineID); err != nil {
		return err
	}

	for i, machine := range c.machines {
		if machine.Id == machineID {
			if machine.State == "stopped" {
				c.machines = append(c.machines[:i], c.machines[i+1:]...)
				return nil
			}

			return fmt.Errorf("Cannot Delete machine %s, machine is not stopped.", machineID)
		}
	}

	return fmt.Errorf("Machine %s not found", machineID)
}
317952
func (c *FleetClient) runCommand(cmd string, machID string) (retcode int) {
	var err error
	if machine.IsLocalMachineID(machID) {
		retcode, err = c.runner.LocalCommand(cmd)
		if err != nil {
			fmt.Fprintf(c.errWriter, "Error running local command: %v\n", err)
		}
	} else {
		ms, err := c.machineState(machID)
		if err != nil || ms == nil {
			fmt.Fprintf(c.errWriter, "Error getting machine IP: %v\n", err)
		} else {
			sshTimeout := time.Duration(Flags.SSHTimeout*1000) * time.Millisecond
			retcode, err = c.runner.RemoteCommand(cmd, ms.PublicIP, sshTimeout)
			if err != nil {
				fmt.Fprintf(c.errWriter, "Error running remote command: %v\n", err)
			}
		}
	}
	return
}
21498
func (m *networkMechanismManager) DeleteNetwork(context *NetworkManagerContext) (err error) {
	// Create new instance, that whould be readed from
	// the database
	network := new(NetworkManagerContext)

	lldriver, err := m.LinkDriver()
	if err != nil {
		return err
	}

	nldriver, err := m.Driver()
	if err != nil {
		return err
	}

	update := func(fn func() error) error {
		return m.BaseMechanismManager.Update(
			NetworkModel, network, fn,
		)
	}

	alter := func(port NetworkPort) error {
		lladdr, err := lldriver.Addr(port.Port)
		if err != nil {
			log.ErrorLog("network/DELETE_NETWORK",
				"Link layer address is not assigned to port: ", err)
			return err
		}

		// If there is no network layer address assigned to port,
		// there is nothing to do then.
		nladdr, err := nldriver.Addr(port.Port)
		if err != nil {
			log.ErrorLog("network/DELETE_NETWORK",
				"Network layer address is not assigned to port: ", err)
			return nil
		}

		// Forward event to activated mechanisms.
		err = m.do(func(nlmech NetworkMechanism) error {
			return nlmech.DeleteNetworkPreCommit(&NetworkContext{
				NetworkDriver: nldriver,
				NetworkAddr:   nladdr,
				LinkDriver:    lldriver,
				LinkAddr:      lladdr,
				Port:          port.Port,
			})
		})

		if err != nil {
			log.ErrorLog("network/DELETE_NETWORK",
				"Failed to delete network configuration: ", err)
			return err
		}

		return nldriver.DeleteAddr(port.Port)
	}

	m.lock.RLock()
	defer m.lock.RUnlock()

	return update(func() error {
		for _, port := range context.Ports {
			if err := alter(port); err != nil {
				log.ErrorLog("network/DELETE_NETWORK",
					"Network delete pre-commit failed: ", err)
				return err
			}

			// Update network layer port configuration.
			// This updated instance will be stored in a database.
			network.DelPort(port)

		}

		err := m.do(func(nlmech NetworkMechanism) error {
			return nlmech.DeleteNetworkPostCommit()
		})

		if err != nil {
			log.ErrorLog("network/DELETE_NETWORK",
				"Network delete post-commit failed: ", err)
		}

		return err
	})
}
149773
func NewDeleteCommand() *cobra.Command {
	var (
		all       bool
		completed bool
		older     string
	)

	var command = &cobra.Command{
		Use:   "delete WORKFLOW",
		Short: "delete a workflow and its associated pods",
		Run: func(cmd *cobra.Command, args []string) {
			wfClient = InitWorkflowClient()
			if all {
				deleteWorkflows(metav1.ListOptions{}, nil)
			} else if older != "" {
				olderTime, err := argotime.ParseSince(older)
				if err != nil {
					log.Fatal(err)
				}
				deleteWorkflows(completedWorkflowListOption, olderTime)
			} else if completed {
				deleteWorkflows(completedWorkflowListOption, nil)
			} else {
				if len(args) == 0 {
					cmd.HelpFunc()(cmd, args)
					os.Exit(1)
				}
				for _, wfName := range args {
					deleteWorkflow(wfName)
				}
			}
		},
	}

	command.Flags().BoolVar(&all, "all", false, "Delete all workflows")
	command.Flags().BoolVar(&completed, "completed", false, "Delete completed workflows")
	command.Flags().StringVar(&older, "older", "", "Delete completed workflows older than the specified duration (e.g. 10m, 3h, 1d)")
	return command
}
347528
func ProvisionMachine(args manual.ProvisionMachineArgs) (machineId string, err error) {
	defer func() {
		if machineId != "" && err != nil {
			logger.Errorf("provisioning failed, removing machine %v: %v", machineId, err)
			if cleanupErr := args.Client.ForceDestroyMachines(machineId); cleanupErr != nil {
				logger.Errorf("error cleaning up machine: %s", cleanupErr)
			}
			machineId = ""
		}
	}()

	// Create the "ubuntu" user and initialise passwordless sudo. We populate
	// the ubuntu user's authorized_keys file with the public keys in the current
	// user's ~/.ssh directory. The authenticationworker will later update the
	// ubuntu user's authorized_keys.
	if err = InitUbuntuUser(args.Host, args.User,
		args.AuthorizedKeys, args.Stdin, args.Stdout); err != nil {
		return "", err
	}

	machineParams, err := gatherMachineParams(args.Host)
	if err != nil {
		return "", err
	}

	// Inform Juju that the machine exists.
	machineId, err = manual.RecordMachineInState(args.Client, *machineParams)
	if err != nil {
		return "", err
	}

	provisioningScript, err := args.Client.ProvisioningScript(params.ProvisioningScriptParams{
		MachineId:              machineId,
		Nonce:                  machineParams.Nonce,
		DisablePackageCommands: !args.EnableOSRefreshUpdate && !args.EnableOSUpgrade,
	})

	if err != nil {
		logger.Errorf("cannot obtain provisioning script")
		return "", err
	}

	// Finally, provision the machine agent.
	err = runProvisionScript(provisioningScript, args.Host, args.Stderr)
	if err != nil {
		return machineId, err
	}

	logger.Infof("Provisioned machine %v", machineId)
	return machineId, nil
}
970757
func (p *Provider) DeleteMachine() (err error) {
	err = p.Host.Driver.Remove()
	defer p.Client.Close()
	return
}