Esempio n. 1
0
func (dp *doProvider) DeleteInstance(info providers.ClusterInstanceInfo, dnsProvider providers.DnsProvider) error {
	fullName := info.String()
	droplets, err := dp.getInstances(info.ClusterInfo)
	if err != nil {
		return err
	}
	client := NewDOClient(dp.token)
	for _, d := range droplets {
		if d.Name == fullName {
			// Delete DNS instance records
			instance := dp.clusterInstance(d)
			if err := providers.UnRegisterInstance(dp.Logger, dnsProvider, instance, info.Domain); err != nil {
				return maskAny(err)
			}

			// Delete droplet
			_, err := client.Droplets.Delete(d.ID)
			if err != nil {
				return err
			}
			return nil
		}
	}

	return maskAny(NotFoundError)
}
Esempio n. 2
0
func (vp *vultrProvider) DeleteInstance(info providers.ClusterInstanceInfo, dnsProvider providers.DnsProvider) error {
	fullName := info.String()
	servers, err := vp.getInstances(info.ClusterInfo)
	if err != nil {
		return err
	}
	for _, s := range servers {
		if s.Name == fullName {
			// Delete DNS instance records
			instance := vp.clusterInstance(s)
			if err := providers.UnRegisterInstance(vp.Logger, dnsProvider, instance, info.Domain); err != nil {
				return maskAny(err)
			}

			// Delete droplet
			err := vp.client.DeleteServer(s.ID)
			if err != nil {
				return err
			}
			return nil
		}
	}

	return maskAny(NotFoundError)
}
Esempio n. 3
0
func (vp *scalewayProvider) deleteServer(s api.ScalewayServer, dnsProvider providers.DnsProvider, domain string) error {
	if s.State == "running" {
		vp.Logger.Infof("Stopping server %s", s.Name)
		if err := vp.client.PostServerAction(s.Identifier, "terminate"); err != nil {
			return maskAny(err)
		}
		api.WaitForServerStopped(vp.client, s.Identifier)
	} else {
		vp.Logger.Infof("Server %s is at state '%s'", s.Name, s.State)
	}

	// Delete DNS instance records
	vp.Logger.Infof("Unregistering DNS for %s", s.Name)
	instance := vp.clusterInstance(s, false)
	if err := providers.UnRegisterInstance(vp.Logger, dnsProvider, instance, domain); err != nil {
		return maskAny(err)
	}

	// Delete server
	/*err := vp.client.DeleteServer(s.Identifier)
	if err != nil {
		vp.Logger.Errorf("Failed to delete server %s: %#v", s.Name, err)
		return maskAny(err)
	}*/

	// Delete volume
	/*for _, v := range s.Volumes {
		if err := vp.client.DeleteVolume(v.Identifier); err != nil {
		vp.Logger.Errorf("Failed to delete volume %s: %#v", v.Identifier, err)
			return maskAny(err)
		}
	}*/

	// Delete IP
	if (s.PublicAddress.Dynamic != nil) && !(*s.PublicAddress.Dynamic) {
		if err := vp.client.DeleteIP(s.PublicAddress.Identifier); err != nil {
			vp.Logger.Errorf("Failed to delete IP %s: %#v", s.PublicAddress.Identifier, err)
			return maskAny(err)
		}
	}

	return nil
}
Esempio n. 4
0
// Remove all instances of a cluster
func (vp *vultrProvider) DeleteCluster(info providers.ClusterInfo, dnsProvider providers.DnsProvider) error {
	servers, err := vp.getInstances(info)
	if err != nil {
		return err
	}
	for _, s := range servers {
		// Delete DNS instance records
		instance := vp.clusterInstance(s)
		if err := providers.UnRegisterInstance(vp.Logger, dnsProvider, instance, info.Domain); err != nil {
			return maskAny(err)
		}

		// Delete droplet
		err := vp.client.DeleteServer(s.ID)
		if err != nil {
			return err
		}
	}

	return nil
}
Esempio n. 5
0
func (this *doProvider) DeleteCluster(info providers.ClusterInfo, dnsProvider providers.DnsProvider) error {
	droplets, err := this.getInstances(info)
	if err != nil {
		return err
	}
	client := NewDOClient(this.token)
	for _, d := range droplets {
		// Delete DNS instance records
		instance := this.clusterInstance(d)
		if err := providers.UnRegisterInstance(this.Logger, dnsProvider, instance, info.Domain); err != nil {
			return maskAny(err)
		}

		// Delete droplet
		_, err := client.Droplets.Delete(d.ID)
		if err != nil {
			return err
		}
	}

	return nil
}