def update_records(self): ''' Run route53 updates based on nventory ''' nvd = Nventory(ini_file=self.options.nv_ini) conn = self.cmgr.get_connection(self.account, service='route53') self.dns = HostedZone(conn, self.account, self.options.comment, domain=self.options.domain) data = { 'loc': '', 'env': '', 'sclass': '', 'acct': self.account, 'domain': self.options.domain} nodes = nvd.get_nodes(data) nvec2nodes = dict() for node in nodes: if node['name'] and node['ec2_instance_id']: nvec2nodes[node['name']] = { 'type': 'CNAME', 'ttl': self.options.ttl, 'resource': [node['ec2_public_hostname']]} if nvec2nodes: self.dns.add_update_records( nvec2nodes, record_type='CNAME', ttl=self.options.ttl) else: print 'INFO: No nodes found in external data source.'
def find_available_hostnames(group, count=1, account=None, region=None, domain=None, node_db=None): ''' Return the first <count> appropriate hostnames not already in node_db ''' retnodes = list() nodes = list() if node_db is None: node_db = Nventory(url='http://fakehost') if account is None: return False data = { 'loc': get_aws_dc(region), 'env': group[:3], 'sclass': group[3:], 'acct': account, 'domain': domain} node_data = node_db.get_nodes(data) if node_data: for node in node_data: nodes.append(node['name']) num = 1 while len(retnodes) != count: possible = gen_hostname(group, num, account, region, domain) if possible not in nodes: retnodes.append(possible) num += 1 return retnodes
def nv_connect(nv_ini): """ Get a Nventory connection object. """ try: node_db = Nventory(ini_file=nv_ini) node_db.login() except Exception: raise return node_db