def handle(self, *args, **kwargs): print("Starting Project expiry ...") keystone = osauth.connect() exp_days = int(settings.PROJECT_EXPIRY) date_today = datetime.date.today() disabled_date = str(date_today) proj_list = keystone.projects.list( domain=settings.OPENSTACK_SANDBOX_DOMAIN, enabled=True) for p in proj_list: if hasattr(p, 'sandbox'): proj_date = datetime.date( *[int(i) for i in p.createddate.split("-")]) if proj_date < date_today - relativedelta(days=exp_days): keystone.projects.update(p.id, enabled=False, disabled_date=disabled_date) print("Disabling Project: " + p.name) print("") print("Project expiry Complete...") print("") print("") print("Starting User expiry ...") user_list = keystone.users.list( domain=settings.OPENSTACK_SANDBOX_DOMAIN, enabled=True) for u in user_list: if hasattr(u, 'sandbox'): user_date = datetime.date( *[int(i) for i in p.createddate.split("-")]) if user_date < date_today - relativedelta(days=exp_days): keystone.users.update(u.id, enabled=False, disabled_date=disabled_date) print("Disabling User: "******"") print("User expiry Complete...")
def handle(self, *args, **kwargs): print("Starting Project delete ...") keystone = osauth.connect() del_days = int(settings.PROJECT_DELETE) date_today = datetime.date.today() disabled_proj_list = keystone.projects.list( domain=settings.OPENSTACK_SANDBOX_DOMAIN, enabled=False) for p in disabled_proj_list: if hasattr(p, 'sandbox'): proj_date = datetime.date( *[int(i) for i in p.disabled_date.split("-")]) if proj_date < date_today - relativedelta(days=del_days): keystone.projects.delete(p.id) print("Deleting Project: " + p.name) print("") print("Project delete Complete...") print("") print("") print("Starting User delete ...") disabled_user_list = keystone.users.list( domain=settings.OPENSTACK_SANDBOX_DOMAIN, enabled=False) for u in disabled_user_list: if hasattr(u, 'sandbox'): user_date = datetime.date( *[int(i) for i in p.disabled_date.split("-")]) if user_date < date_check - relativedelta(days=del_days): keystone.users.delete(u.id) print("Deleting User: "******"") print("User delete Complete...")
def home(request): # Sets up th ehome view with data from openstack keystone = osauth.connect() proj = keystone.projects.list(domain=settings.OPENSTACK_SANDBOX_DOMAIN) all_users = keystone.users.list(domain=settings.OPENSTACK_SANDBOX_DOMAIN) sandb = [] usrs = [] number_sandb = 0 number_usrs = 0 # returns the number of sandbox projects for p in proj: if hasattr(p, 'sandbox'): sandb.append(p) number_sandb = len(sandb) # returns the number of sandbox users for u in all_users: if hasattr(u, 'sandbox'): usrs.append(p) number_usrs = len(usrs) home_static = SandbStatic.objects.get(name='HomeStatic') return render( request, 'home.html', { 'sandboxes': number_sandb, 'sandbox_users': number_usrs, 'home_static': home_static })
def project_list(request): keystone = osauth.connect() proj = keystone.projects.list(domain=settings.OPENSTACK_SANDBOX_DOMAIN) projects = [] for p in proj: if hasattr(p, 'sandbox'): projects.append(p) return render(request, 'project_list.html', {'projects': projects})
def sandbox_user_list(request): keystone = osauth.connect() sandbox_user = keystone.users.list( domain=settings.OPENSTACK_SANDBOX_DOMAIN) sandbox_users = [] for u in sandbox_user: if hasattr(u, 'sandbox'): sandbox_users.append(u) return render(request, 'sandbox_user_list.html', {'sandbox_users': sandbox_users})
def handle(self, *args, **kwargs): print("Starting Portal OpenStack Dev population script...") for p in range(0, 20): projectname = chance.word().upper() projectdescription = chance.sentence(language='en') department = chance.word().upper() username = chance.first().upper() password = pwdgen.get_random_string() firstname = username familyname = chance.last() emailaddress = chance.email() telephone = chance.phone(formatted=False) tos = True date_now = datetime.date.today() date = str(date_now) keystone = osauth.connect() keystone.projects.create(name=projectname, domain=settings.OPENSTACK_SANDBOX_DOMAIN, description=projectdescription, enabled=True, department=department, username=username, firstname=firstname, familyname=familyname, emailaddress=emailaddress, telephone=telephone, tos=tos, createddate=date, sandbox=True) project_id = keystone.projects.find(name=projectname).id keystone.users.create(name=username, domain=settings.OPENSTACK_SANDBOX_DOMAIN, default_project=project_id, password=password, email=emailaddress, description="Sandbox User", firstname=firstname, familyname=familyname, emailaddress=emailaddress, telephone=telephone, enabled=True, createddate=date, sandbox=True) role_id = keystone.roles.find(name='Member') user_id = keystone.users.find(name=username).id keystone.roles.grant(role_id, user=user_id, project=project_id)
def handle(self, *args, **kwargs): print("Starting Portal OpenStack Dev deletion script...") keystone = osauth.connect() sand_proj = keystone.projects.list( domain=settings.OPENSTACK_SANDBOX_DOMAIN) sand_users = keystone.users.list( domain=settings.OPENSTACK_SANDBOX_DOMAIN) for u in sand_users: if hasattr(u, 'sandbox'): keystone.users.delete(u) self.stdout.write( self.style.SUCCESS('User "%s" deleted with success!' % u.name)) for p in sand_proj: if hasattr(p, 'sandbox'): keystone.projects.delete(p) self.stdout.write( self.style.SUCCESS('Project "%s" deleted with success!' % p.name))
def request_project(request): form = CreateOpenstackSandboxProjectForm # Gets all the information from the form and creates the project and user if request.method == 'POST': form = form(data=request.POST) if form.is_valid(): projectname = request.POST.get('projectname', '').upper() projectdescription = request.POST.get('projectdescription', '') department = request.POST.get('department', '') username = request.POST.get('username', '').upper() password = pwdgen.get_random_string() firstname = request.POST.get('firstname', '') familyname = request.POST.get('familyname', '') emailaddress = request.POST.get('emailaddress', '') telephone = request.POST.get('telephone', '') tos = request.POST.get('tos', '') date_now = datetime.date.today() date = str(date_now) keystone = osauth.connect() keystone.projects.create(name=projectname, domain=settings.OPENSTACK_SANDBOX_DOMAIN, description=projectdescription, enabled=True, department=department, username=username, firstname=firstname, familyname=familyname, emailaddress=emailaddress, telephone=telephone, tos=tos, createddate=date, sandbox=True) project_id = keystone.projects.find(name=projectname).id keystone.users.create(name=username, domain=settings.OPENSTACK_SANDBOX_DOMAIN, default_project=project_id, password=password, email=emailaddress, description="Sandbox User", firstname=firstname, familyname=familyname, emailaddress=emailaddress, telephone=telephone, enabled=True, createddate=date, sandbox=True) role_id = keystone.roles.find(name='Member') user_id = keystone.users.find(name=username).id keystone.roles.grant(role_id, user=user_id, project=project_id) # Emails the user and the support team mail.send_email(settings.FROM_EMAIL, emailaddress, firstname, familyname, username, password, settings.OPENSTACK_HORIZONURL, settings.OPENSTACK_SANDBOX_DOMAIN) mail.send_support_team_email(settings.FROM_EMAIL, settings.SUPPORT_EMAIL, firstname, familyname, projectname, projectdescription, telephone) return redirect('request_project') tos_content = SandbStatic.objects.get(name='Tos') return render(request, 'request_project.html', { 'form': form, 'tos_content': tos_content })
def project_detail(request): proj_id = request.GET.get('proj') keystone = osauth.connect() project = keystone.projects.get(proj_id) return render(request, 'project_detail.html', {'project': project})