def run(self): auth = Password(auth_url=self.conf.auth_url, username=self.conf.os_user, password=self.conf.os_pass, project_name="admin", user_domain_id="default", project_domain_id="default") sess = session.Session(auth=auth) keystone = keystone_client.Client(session=sess) for service in keystone.services.list(): endpoint = keystone.endpoints.find(service_id=service.id, interface='public') url = urlparse(endpoint.url) #handling different versions of identity API if url.port: new_url = "http://" + url.hostname + ":" + str(url.port) + "/" else: new_url = endpoint.url self.add_worker(do_check, (service.name, new_url, self.db_adapter)) neutron = neutron_client.Client(session=sess) for fip in neutron.list_floatingips()['floatingips']: if fip['status'] == 'ACTIVE': self.add_worker(ping, (fip['floating_ip_address'], self.db_adapter)) while True: time.sleep(3)
def session(self): if not self._session: auth_kwargs = dict(auth_url=self.auth_url, username=self.username, password=self.password, project_name=self.tenant) if self.keystone_version == 3: auth_kwargs.update(dict(user_domain_id=self.domain_id, project_domain_name=self.domain_id)) pass_auth = Password(**auth_kwargs) self._session = Session(auth=pass_auth, verify=False) return self._session
def get_keystone_client(): auth = Password(**keystone_args_from_env()) session = Session(auth=auth, app_name='keystone-init', user_agent='keystone-init', timeout=KEYSTONE_TIMEOUT, verify=KEYSTONE_VERIFY, cert=KEYSTONE_CERT) discover = Discover(session=session) return discover.create_client()
def handle_openstack(self): auth = Password(auth_url=self.conf.auth_url, username=self.conf.user, password=self.conf.password, project_name="admin", user_domain_id="default", project_domain_id="default") sess = session.Session(auth=auth) keystone = keystone_client.Client(session=sess) for service in keystone.services.list(): endpoint = keystone.endpoints.find(service_id=service.id, interface='public') url = urlparse(endpoint.url) new_url = '{0}://{1}'.format(url.scheme, url.netloc) self.add_worker(utils.do_check, (service.name, new_url, self.db_adapter)) neutron = neutron_client.Client(session=sess) for fip in neutron.list_floatingips()['floatingips']: if fip['status'] == 'ACTIVE': self.add_worker(utils.ping, (fip['floating_ip_address'], self.db_adapter))