def build(self, hosts): ips = {} for h, v in hosts.items(): if v['enabled']: vm = None try: vm = self.vmClient.virtual_machines.get(v['resource_group'], h) click.echo(" - Already up host: {} ".format(vm.name)) except CloudError as e: if str(e).startswith("Azure Error: ResourceNotFound"): click.echo(" - Creating host: {} ".format(h)) nic = self.create_nic(h, v) vm = self.create_vm(h, v, nic) ips[vm.name] = None 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 if v.get('external_dns', False): pipInfo = parse_resource_id(ip_configurations[0].public_ip_address.id) pip = self.netClient.public_ip_addresses.get(pipInfo['resource_group'], pipInfo['resource_name']) ips[vm.name] = pip.ip_address else: ips[vm.name] = ip_configurations[0].private_ip_address dnsUpdate(ips)
def build(self, hosts): ops = {} ips = {} for h, v in self._getVMs(hosts).items(): if v['status'] is None: click.echo(" - Creating host: {} ".format(h)) r = v['insert'].execute() ops[h] = {'name': r['name'], 'project': hosts[h]['project'], 'zone': hosts[h]['zone']} ips[h] = None elif v['status'] == 'TERMINATED': click.echo(" - Booting host: {} ".format(h)) self.compute.instances().start(project=hosts[h]['project'], zone=hosts[h]['zone'], instance=v['name']).execute() elif v['status'] == "RUNNING": click.echo(" - Already up host: {} ".format(h)) else: click.echo(" - Status of host: {} is {}".format(h, v['status'])) self._waitDone(ops, " - Host {} created") for h, v in self._getVMs(hosts).items(): if v['values'].get('dns_external', False): ips[h] = v['networkInterfaces'][0]['accessConfigs'][0]['natIP'] else: ips[h] = v['networkInterfaces'][0]['networkIP'] dnsUpdate(ips)
def dnsupdate(self, hosts): ips = {} for h, v in self._getVMs(hosts).items(): if v['values'].get('dns_external', False): ips[h] = v['networkInterfaces'][0]['accessConfigs'][0]['natIP'] else: ips[h] = v['networkInterfaces'][0]['networkIP'] dnsUpdate(ips)
def build(self, hosts): ips = {} for h, v in self._getVMs(hosts).items(): if v['status'] is None: click.echo(" - Creating host: {} ".format(h)) self.ec2.create_instances(BlockDeviceMappings=[ { 'DeviceName': '/dev/sda1', 'Ebs': { 'DeleteOnTermination': True, 'VolumeSize': v['values'].get('disksize', 20), 'VolumeType': 'standard', }, }, ], TagSpecifications=[{ 'ResourceType': 'instance', 'Tags': [{ 'Key': 'Name', 'Value': h }] }], ImageId=v['values']['ami'], MinCount=1, MaxCount=1, InstanceType=v['values']['vmtype'], KeyName=v['values']['key'], SecurityGroupIds=v['values']['sg'], SubnetId=v['values']['subnet'], UserData="""#cloud-config fqdn: {} manage_etc_hosts: true """.format(h)) else: click.echo(" - Status of host: {} is {}".format( h, v['status'])) for h, v in self._getVMs(hosts).items(): if v['status'] is not None: v['vm'].wait_until_running() v['vm'].reload() ips[h] = v['vm'].public_ip_address dnsUpdate(ips)
def build(self, hosts): ips = {} for h, v in self._getVMs(hosts).items(): if v['found']: click.echo(" - Status of host: {} is {}".format(h, v['run_state'])) ips[h] = self._findIP(v['nics'][0]) else: click.echo(" - Creating host: {} ".format(h)) url = "{}/2/instances".format(self.url) r = requests.post(url, auth=(self.user, self.apikey), verify=self.verify, json=v['api']) if r.status_code != requests.codes.ok: j = r.json() click.echo('Failed: [{v[message]} :: {v[explain]}]'.format(v=j)) jobid = r.text.rstrip('\n') j = self._getJob(jobid) j = self._getInfoVM(h) ips[h] = self._findIP(j['nics'][0]) dnsUpdate(ips)
def dnsupdate(self, hosts): ips = {} for h, v in hosts.items(): if hosts[h]['enabled']: 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 if v.get('external_dns', False): pipInfo = parse_resource_id(ip_configurations[0].public_ip_address.id) pip = self.netClient.public_ip_addresses.get(pipInfo['resource_group'], pipInfo['resource_name']) 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"): pass dnsUpdate(ips)
def build(self, hosts): ips = {} for k, d in self.getDroplets(hosts).items(): if d.status is None: click.echo(" - Creating host: {} ".format(d.name)) d.create() ips[d.name] = None elif d.status == 'off': click.echo(" - Booting host: {} ".format(d.name)) d.power_on() elif d.status == 'active': click.echo(" - Already up host: {} ".format(d.name)) else: click.echo(" - Status of host: {} is {}".format( d.name, d.status)) self.waitStatus(hosts, 'active') for k, d in self.getDroplets(hosts).items(): if d.ip_address: ips[d.name] = d.ip_address dnsUpdate(ips)
def dnsupdate(self, hosts): ips = {} for h, v in self._getVMs(hosts).items(): if hosts[h]['enabled']: ips[h] = v['vm'].public_ip_address dnsUpdate(ips)
def dnsupdate(self, hosts): ips = {} for k, d in self.getDroplets(hosts).items(): if d.ip_address: ips[d.name] = d.ip_address dnsUpdate(ips)
def dnsupdate(self, hosts): ips = {} for h, v in self._getVMs(hosts).items(): if 'ip-address' in v: ips[h] = v['ip-address'] dnsUpdate(ips)