Example #1
0
    def dnsremove(self, hosts):
        ips = {}
        for h in hosts:
            if hosts[h]['enabled']:
                ips[h] = None

        dnsRemove(ips)
Example #2
0
    def destroy(self, hosts):
        updateHosts = {}
        for h, v in self._getVMs(hosts).items():
            if v['status'] is not None:
                click.echo("  - Destroying host: {} ".format(h))
                v['vm'].terminate()
                updateHosts[h] = {}
            else:
                click.echo("  - Host does not exists : {}".format(h))

        dnsRemove(updateHosts)
Example #3
0
    def destroy(self, hosts):
        updateHosts = {}
        for k, d in self.getDroplets(hosts).items():
            if d.status is not None:
                click.echo("  - Destroying host: {} ".format(d.name))
                d.destroy()
                updateHosts[d.name] = {}
            else:
                click.echo("  - Host does not exists : {}".format(d.name))

        dnsRemove(updateHosts)
Example #4
0
    def destroy(self, hosts):
        ips = {}
        for h, v in hosts.items():
            if hosts[h]['enabled']:
                vm = None
                try:
                    vm = self.vmClient.virtual_machines.get(v['resource_group'], h)

                    interface = vm.network_profile.network_interfaces[0]
                    nicInfo = parse_resource_id(interface.id)
                    ip_configurations = self.netClient.network_interfaces.get(nicInfo['resource_group'], nicInfo['resource_name']).ip_configurations
                    click.echo("  - Destroying host: {} ".format(vm.name))

                    async_vm_delete = self.vmClient.virtual_machines.delete(v['resource_group'], h)
                    async_vm_delete.wait()

                    click.echo("    Removing nic: {} ".format(nicInfo['resource_name']))
                    net_del_poller = self.netClient.network_interfaces.delete(nicInfo['resource_group'], nicInfo['resource_name'])
                    net_del_poller.wait()

                    pipInfo = parse_resource_id(ip_configurations[0].public_ip_address.id)
                    pip = self.netClient.public_ip_addresses.get(pipInfo['resource_group'], pipInfo['resource_name'])
                    if pip.id:
                        click.echo("    Removing public ip: {} ".format(pip.name))
                        ip_del_poller = self.netClient.public_ip_addresses.delete(pipInfo['resource_group'], pipInfo['resource_name'])
                        ip_del_poller.wait()

                    if v.get('external_dns', False):
                        ips[vm.name] = pip.ip_address
                    else:
                        ips[vm.name] = ip_configurations[0].private_ip_address

                except CloudError as e:
                    if str(e).startswith("Azure Error: ResourceNotFound"):
                        click.echo("  - Host does not exists : {}".format(h))

                try:
                    disks_list = self.vmClient.disks.list_by_resource_group(v['resource_group'])
                    disk_handle_list = []
                    async_disk_handle_list = []
                    for disk in disks_list:
                        if h in disk.name:
                            click.echo("    Removing disk: {} ".format(disk.name))
                            async_disk_delete = self.vmClient.disks.delete(v['resource_group'], disk.name)
                            async_disk_handle_list.append(async_disk_delete)
                    for async_disk_delete in disk_handle_list:
                        async_disk_delete.wait()
                except CloudError as e:
                    click.echo("    Error while removing disk: {}".format(e))

        dnsRemove(ips)
Example #5
0
    def destroy(self, hosts):
        updateHosts = {}
        ops = {}
        for h, v in self._getVMs(hosts).items():
            if v['status'] is not None:
                click.echo("  - Destroying host: {} ".format(h))
                r = self.compute.instances().delete(project=hosts[h]['project'], zone=hosts[h]['zone'], instance=v['name']).execute()
                ops[h] = {'name': r['name'], 'project': hosts[h]['project'], 'zone': hosts[h]['zone']}
                updateHosts[h] = {}
            else:
                click.echo("  - Host does not exists : {}".format(h))

        self._waitDone(ops, "  - Host {} destroyed")
        dnsRemove(updateHosts)
Example #6
0
    def destroy(self, hosts):
        updateHosts = {}
        for h, v in self._getVMs(hosts).items():
            if v['found']:
                click.echo("  - Destroying host: {} ".format(h))
                updateHosts[h] = {}
                url = "{}/2/instances/{}".format(self.url, h)
                r = requests.delete(url, auth=(self.user, self.apikey), verify=self.verify)

                jobid = r.text.rstrip('\n')
                j = self._getJob(jobid)

                if r.status_code != requests.codes.ok:
                    j = r.json()
                    click.echo('Failed: [{v[message]} :: {v[explain]}]'.format(v=j))
            else:
                click.echo("  - Host does not exists : {}".format(h))

        dnsRemove(updateHosts)