// Starts the recurring copy state of source system into destination
func deploymentMigrationPrepareDeprecated(c *cli.Context) error {
	err := checkArgNum(c.Args(), 1, "system migration prepare <old_management_endpoint>")
	if err != nil {
		return err
	}
	sourceAddress := c.Args().First()
	client.Esxclient, err = client.GetClient(c.GlobalIsSet("non-interactive"))
	if err != nil {
		return err
	}
	deployments, err := client.Esxclient.Deployments.GetAll()
	if err != nil {
		return err
	}
	initializeMigrationSpec := photon.InitializeMigrationOperation{}
	initializeMigrationSpec.SourceLoadBalancerAddress = sourceAddress

	// Initialize deployment migration
	for _, deployment := range deployments.Items {
		initializeMigrate, err := client.Esxclient.Deployments.InitializeDeploymentMigration(&initializeMigrationSpec, deployment.ID)
		if err != nil {
			return err
		}
		_, err = pollTask(initializeMigrate.ID)
		if err != nil {
			return err
		}
		fmt.Printf("Deployment '%s' migration started [source management endpoint: '%s'].\n", deployment.ID, sourceAddress)

		return nil
	}

	return nil
}
// Starts the recurring copy state of source system into destination
func deploymentMigrationPrepare(c *cli.Context) error {
	id, err := getDeploymentId(c)
	if err != nil {
		return err
	}

	sourceAddress := c.String("endpoint")
	if len(sourceAddress) == 0 {
		return fmt.Errorf("Please provide the API endpoint of the old control plane")
	}

	client.Esxclient, err = client.GetClient(c.GlobalIsSet("non-interactive"))
	if err != nil {
		return err
	}

	deployment, err := client.Esxclient.Deployments.Get(id)
	if err != nil {
		return err
	}
	initializeMigrationSpec := photon.InitializeMigrationOperation{}
	initializeMigrationSpec.SourceLoadBalancerAddress = sourceAddress

	// Initialize deployment migration
	initializeMigrate, err := client.Esxclient.Deployments.InitializeDeploymentMigration(&initializeMigrationSpec, deployment.ID)
	if err != nil {
		return err
	}

	_, err = waitOnTaskOperation(initializeMigrate.ID, c)
	if err != nil {
		return err
	}

	fmt.Printf("Deployment '%s' migration started [source management endpoint: '%s'].\n", deployment.ID, sourceAddress)
	return nil
}