def make_image_public(username, image_id, region_name): sess = admin_session(region_name) glance = Client('2', session=sess) logger.info( ('User: {} requesting visibility=public for image id: {} in region: {}' .format(username, image_id, region_name))) glance.images.update(image_id, visibility='public') logger.info(('User: {} image status after update: {}'.format( username, glance.images.get(image_id))))
def _make_headers(self): # It doesn't really matter which region we use when generating the # authentication token; all the balance service cares about is that # it is valid. sess = admin_session(settings.OPENSTACK_TACC_REGION) headers = sess.session.get_auth_headers() headers["Accept"] = "application/json" headers["Content-Type"] = "application/json" return headers
def get_openstack_data(username, region, projects): admin_client = admin_ks_client(region) admin_sess = admin_session(region) current_region = {} current_region["name"] = region current_region["projects"] = [] # we know there is only going to be one domain domains = list(admin_client.domains.list(name="chameleon")) if not domains: LOG.error('Didn\'t find the domain "chameleon", skipping this site') return current_region domain_id = domains[0].id ks_users_list = list( admin_client.users.list(name=username, domain=domain_id)) if len(ks_users_list) > 1: LOG.warning( f"Found {len(ks_users_list)} users for {username}, using the first." ) ks_user = ks_users_list[0] all_ks_projects = { ks_p.name: ks_p for ks_p in admin_client.projects.list(domain=domain_id) } for project in projects: charge_code = project["name"] # Project doesn't exist for this region if charge_code not in all_ks_projects: continue ks_project_id = all_ks_projects[charge_code].id project_qs = Project.objects.filter(charge_code=charge_code) project_list = list(project_qs) if len(project_list) > 1: raise Exception( f"More than one project found with charge code {charge_code}") project = project_list[0] current_project = {} current_project["charge_code"] = project.charge_code current_project["id"] = ks_project_id current_region["projects"].append(current_project) try: current_project["leases"] = get_lease_info(admin_sess, ks_user.id, ks_project_id) except Exception as err: current_project["lease_error"] = True LOG.error( f"Failed to get leases in {region} for {project.title}: {err}") try: current_project["servers"] = get_server_info( admin_sess, ks_project_id) except Exception as err: current_project["server_error"] = True LOG.error( f"Failed to get active servers in {region} for {project.title}: {err}" ) return current_region