def create_user(request): user = User() form = CloudUserCreateFormWithoutCapatcha(data=request.POST, instance=user) if not form.is_valid(): return Response({"success": False, "msg": _("Data is not valid")}) user = form.save() # If workflow is disabled, then only resrouce user can be created, # otherwise admin can create resource user and workflow approver user. if not settings.WORKFLOW_ENABLED: link_user_to_dc_task(user, DataCenter.get_default()) else: if 'is_resource_user' in request.data and \ request.data['is_resource_user'] == 'true': link_user_to_dc_task(user, DataCenter.get_default()) if 'is_approver' in request.data and \ request.data['is_approver'] == 'true': UserProxy.grant_workflow_approve(user) return Response({ "success": True, "msg": _("User is created successfully!") })
def create_user(request): user = User() form = CloudUserCreateFormWithoutCapatcha(data=request.POST, instance=user) if not form.is_valid(): return Response({"success": False, "msg": _("Data is not valid")}) user = form.save() # If workflow is disabled, then only resrouce user can be created, # otherwise admin can create resource user and workflow approver user. if not settings.WORKFLOW_ENABLED: link_user_to_dc_task(user, DataCenter.get_default()) else: if 'is_resource_user' in request.data and \ request.data['is_resource_user'] == 'true': link_user_to_dc_task(user, DataCenter.get_default()) if 'is_approver' in request.data and \ request.data['is_approver'] == 'true': UserProxy.grant_workflow_approve(user) return Response({"success": True, "msg": _("User is created successfully!")})
def first_activate_user(request, code): try: activate_url = ActivateUrl.objects.get(code=code) except ActivateUrl.DoesNotExist: return _resend_email_response(request, _("This activate url is not valid, " "you can resend activate email.")) if activate_url.expire_date < timezone.now(): activate_url.delete() return _resend_email_response(request, _("This activate url is not valid, " "you can resend activate email.")) try: link_user_to_dc_task(activate_url.user, DataCenter.get_default()) except: return render(request, 'info.html', { 'message': _("Failed to activate your account, you can try later.") }) else: activate_url.delete() messages.add_message(request, messages.INFO, _("Your account is activated successfully, " "please login.")) return redirect('login')
def add_user_role(keystone_user, role, user_tenant_id): LOG.info("ddddddddd") datacenter = DataCenter.get_default() rc = create_rc_by_dc(datacenter) LOG.info("********* keystone_user is *********" + str(keystone_user)) LOG.info("********* role is *********" + str(role)) LOG.info("********* user_tenant_id is *********" + str(user_tenant_id)) # get user_id users = keystone.user_list(rc, project=user_tenant_id) LOG.info("******* users are ******" + str(users)) user_id = None for u in users: if u.username == keystone_user: user_id = u.id LOG.info("****** user_id is *********" + str(user_id)) role_id = None roles = keystone.role_list(rc) for r in roles: if r.name == role: role_id = r.id LOG.info("******** role_id is ********" + str(role_id)) try: keystone.add_tenant_user_role(rc, project=user_tenant_id, user=user_id, role=role_id) except: pass return False
def hypervisor_stats(request): user = request.user user_ = UserProxy.objects.get(pk=user.pk) if request.user.is_superuser or user_.is_system_user or user_.is_safety_user or user_.is_audit_user: data_center = DataCenter.get_default() stats = hypervisor_stats_task(data_center) if stats: result = { "vcpus": stats.vcpus, "vcpus_used": stats.vcpus_used, "memory_mb": stats.memory_mb, "memory_mb_used": stats.memory_mb_used, "local_gb": stats.local_gb, "local_gb_used": stats.local_gb_used, } return Response({"success": True, "stats": result}) else: return Response({"success": False, "msg": _("Hypervisor status is none.")}) else: return Response({ "success": False, "msg": _("Only super user can view the hypervisor status.")})
def add_user_tenants(request, tenant_id, ID): datacenter = DataCenter.get_default() rc = create_rc_by_dc(datacenter) roles = keystone.role_list(rc) LOG.info("------------------roles are----------------" + str(roles)) #member_role = filter(lambda r: r.name.lower() == "_member_", roles)[0] # Grant basic role to user roles_id = [] for role in roles: if role.name in ['SwiftOperator', '_member_', 'heat_stack_owner']: roles_id.append(role) #member_role = filter(lambda r: r.name.lower() == "_member_", roles)[0] #LOG.info("------------------ member role is ----------------" + str(member_role.id)) #LOG.info("------------------ user id is ----------------" + str(u.id)) for role in roles_id: try: keystone.add_tenant_user_role(rc, project=tenant_id, user=ID, role=role.id) except: pass return True
def change_user_keystone_passwd(user_id, username, tenant_id, new_passwd): datacenter = DataCenter.get_default() rc = create_rc_by_dc(datacenter) users = keystone.user_list(rc, project=tenant_id) LOG.info("*** rc is ***" + str(rc)) LOG.info("******* users are ******" + str(users)) udc_user_id = user_id LOG.info("*** udc_user_id is ***" + str(udc_user_id)) user_id = None for u in users: if u.username == username: user_id = u.id LOG.info("**** user_id is ****" + str(user_id)) try: keystone.user_update_password(rc, user_id, new_passwd, admin=True) LOG.info("**** user password updated ****") udc = UserDataCenter.objects.get(user_id=udc_user_id) LOG.info("**** user password updated ****") udc.keystone_password = new_passwd LOG.info("**** user password updated ****") udc.save() LOG.info("**** user password updated ****") except: raise return True
def init_images(request): data = request.data names = data.getlist('names[]') login_names = data.getlist('login_names[]') uuids = data.getlist('uuids[]') os_types = data.getlist('os_types[]') disk_sizes = data.getlist('disk_sizes[]') data_center = DataCenter.get_default() try: for i in range(len(names)): Image.objects.create(name=names[i], login_name=login_names[i], uuid=uuids[i], os_type=os_types[i], data_center=data_center, disk_size=disk_sizes[i]) except Exception as e: LOG.exception("Failed to create images") return Response({'success': False, "msg": _("Unknown Error happened when creating images!")}, status=status.HTTP_200_OK) else: return Response({"success": True, "msg": _("Images are initialized successfully!")})
def post(self, request): user = User() form = CloudUserCreateForm(data=request.POST, instance=user) LOG.info("post start") tenant_id = request.POST.get("project") password = request.POST.get("password2") LOG.info("post start") if form.is_valid(): form.save() LOG.info("1") if settings.REGISTER_ACTIVATE_EMAIL_ENABLED: LOG.info("2") _send_activate_email(user) msg = _("Your registration successed, we send you one " "activate email, please check your input box.") else: LOG.info("start to run celery") link_user_to_dc_task(user, DataCenter.get_default(), tenant_id, password) LOG.info("end") msg = _("Your registration successed!") return render(request, 'info.html', {'message': msg}) return self.response(request, form, form.errors)
def hypervisor_stats(request): if request.user.is_superuser: data_center = DataCenter.get_default() stats = hypervisor_stats_task(data_center) if stats: result = { "vcpus": stats.vcpus, "vcpus_used": stats.vcpus_used, "memory_mb": stats.memory_mb, "memory_mb_used": stats.memory_mb_used, "local_gb": stats.local_gb, "local_gb_used": stats.local_gb_used, } return Response({"success": True, "stats": result}) else: return Response({ "success": False, "msg": _("Hypervisor status is none.") }) else: return Response({ "success": False, "msg": _("Only super user can view the hypervisor status.") })
def first_activate_user(request, code): try: activate_url = ActivateUrl.objects.get(code=code) except ActivateUrl.DoesNotExist: return _resend_email_response( request, _("This activate url is not valid, " "you can resend activate email.")) if activate_url.expire_date < timezone.now(): activate_url.delete() return _resend_email_response( request, _("This activate url is not valid, " "you can resend activate email.")) try: link_user_to_dc_task(activate_url.user, DataCenter.get_default()) except: return render(request, 'info.html', { 'message': _("Failed to activate your account, you can try later.") }) else: activate_url.delete() messages.add_message( request, messages.INFO, _("Your account is activated successfully, " "please login.")) return redirect('login')
def init_images(request): data = request.data names = data.getlist('names[]') login_names = data.getlist('login_names[]') uuids = data.getlist('uuids[]') os_types = data.getlist('os_types[]') disk_sizes = data.getlist('disk_sizes[]') data_center = DataCenter.get_default() try: for i in range(len(names)): Image.objects.create(name=names[i], login_name=login_names[i], uuid=uuids[i], os_type=os_types[i], data_center=data_center, disk_size=disk_sizes[i]) except Exception as e: LOG.exception("Failed to create images") return Response( { 'success': False, "msg": _("Unknown Error happened when creating images!") }, status=status.HTTP_200_OK) else: return Response({ "success": True, "msg": _("Images are initialized successfully!") })
def hypervisor_stats(request): user = request.user user_ = UserProxy.objects.get(pk=user.pk) #if request.user.is_superuser or user_.is_system_user or user_.is_safety_user or user_.is_audit_user: if True: data_center = DataCenter.get_default() stats = hypervisor_stats_task(data_center) if stats: result = { "vcpus": stats.vcpus, "vcpus_used": stats.vcpus_used, "memory_mb": stats.memory_mb, "memory_mb_used": stats.memory_mb_used, "local_gb": stats.local_gb, "local_gb_used": stats.local_gb_used, } return Response({"success": True, "stats": result}) else: return Response({ "success": False, "msg": _("Hypervisor status is none.") }) else: return Response({ "success": False, "msg": _("Only super user can view the hypervisor status.") })
def initialize_user(request): user_id = request.data['user_id'] user = User.objects.get(pk=user_id) link_user_to_dc_task(user, DataCenter.get_default()) return Response({ "success": True, "msg": _("Initialization is successful.") })
def batch_delete(request): LOG.info("**** start to delete network ****") datacenter = DataCenter.get_default() rc = create_rc_by_dc(datacenter) LOG.info(request.data) network_id = request.data['ids[]'] LOG.info(network_id) neutron.network_delete(rc, network_id) return Response({"OPERATION_STATUS": 1, "MSG": _("Creating network")})
def list(self, request): datacenter = DataCenter.get_default() LOG.info("****** signup get method ********") rc = create_rc_by_dc(datacenter) LOG.info("****** signup get method ********") tenants = keystone.keystoneclient(rc).tenants.list() tenants_id = [] for tenant in tenants: if str(tenant.name) not in ["admin", "demo", "services"]: tenants_id.append({'name': tenant.name, 'id': tenant.id}) LOG.info("********* tenants_id is **************" + str(tenants_id)) return Response(tenants_id)
def update_user(request): LOG.info("******* data is ******" + str(request.data)) LOG.info("****** username is ******" + str(request.data['username'])) posted_username = request.data['username'] email = request.data['email'] mobile = request.data['mobile'] user_id = request.data['id'] user = User.objects.all().get(id = request.data['id']) userprofile = UserProfile.objects.all().get(user = user) LOG.info(user_id) if User.objects.filter(username = posted_username).exists(): if User.objects.get(username = posted_username).id != int(user_id): return Response({"success": False, "msg": _("Duplicated user name.Please enter another user name.")}) if User.objects.filter(email = email).exists(): if User.objects.get(email = email).id != int(user_id): return Response({"success": False, "msg": _("Duplicated email.Please enter another email address.")}) if UserProfile.objects.filter(mobile = mobile).exists(): if UserProfile.objects.get(mobile = mobile).user != user: return Response({"success": False, "msg": _("Duplicated mobile.Please enter another mobile.")}) if str(posted_username) in ['neutron', 'cinder', 'keystone', 'nova', 'glance', 'heat', 'swift', 'admin', 'ceilometer']: return Response({"success": False, "msg": _("Service user must not be created.")}) LOG.info("uuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuu") LOG.info("uuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuu") LOG.info("uuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuu") try: user_data_center = UserDataCenter.objects.all().get(user = user) keystone_user_id = user_data_center.keystone_user_id rc = create_rc_by_dc(DataCenter.get_default()) keystone_user = keystone.user_get(rc, keystone_user_id) LOG.info(keystone_user) manager = keystone.keystoneclient(rc, admin=True).users update_user = manager.update(keystone_user, name = posted_username, email = email) #keystone.user_update(rc, keystone_user, name = posted_username, email = email) keystone_user = keystone.user_get(rc, keystone_user_id) LOG.info(keystone_user) except Exception as e: traceback.print_exc() return Response({"success":False, "msg":str(e)}) try: user.username = posted_username user.email = email userprofile.mobile = mobile user.save() userprofile.save() except: traceback.print_exc() return Response({"success":True})
def save(self, commit=True): user = super(CloudUserCreateForm, self).save(commit=False) user.set_password(self.cleaned_data["password1"]) user.email = self.cleaned_data["username"] if commit: r = user.save() UserProfile.objects.create( user=user, user_type=self.cleaned_data["user_type"], mobile=self.cleaned_data["mobile"] ) link_user_to_dc_task.delay(user, dc.get_default()) return user
def delete_keystone_user(tenant_id, username): datacenter = DataCenter.get_default() rc = create_rc_by_dc(datacenter) users = keystone.user_list(rc, project=tenant_id) LOG.info("******* users are ******" + str(users)) user_id = None for u in users: if u.username == username: user_id = u.id try: keystone.user_delete(rc, user_id) except: pass return True
def get(self, request): LOG.info("****** signup get method ********") datacenter = DataCenter.get_default() LOG.info("****** signup get method ********") rc = create_rc_by_dc(datacenter) LOG.info("****** signup get method ********") tenants = keystone.keystoneclient(rc).tenants.list() tenants_id = {} for tenant in tenants: if str(tenant.name) not in ["admin", "demo", "services"]: tenants_id[tenant.id] = tenant.name LOG.info("********* tenants_id is **************" + str(tenants_id)) return self.response(request, CloudUserCreateForm( initial={'username': '', 'email': '', 'mobile': ''}), tenants_id)
def list(self, reqeust): datacenter = DataCenter.get_default() LOG.info("ccc") rc = create_rc_by_dc(datacenter) LOG.info("ccc") tenants = keystone.keystoneclient(rc).tenants.list() LOG.info("cccccccc") tenants_id = [] for tenant in tenants: if str(tenant.name) not in ["admin", "demo", "services"]: tenants_id.append({'tenant_id': tenant.id, 'tenant_name':tenant.name, 'description': tenant.description}) LOG.info("tenants_id is" + str(tenants_id)) return Response(tenants_id)
def list(self, reqeust): datacenter = DataCenter.get_default() LOG.info("ccc") rc = create_rc_by_dc(datacenter) LOG.info("ccc") tenants = keystone.keystoneclient(rc).tenants.list() LOG.info("cccccccc") tenants_id = [] for tenant in tenants: if str(tenant.name) not in ["admin", "demo", "services"]: tenants_id.append({ 'tenant_id': tenant.id, 'tenant_name': tenant.name, 'description': tenant.description }) LOG.info("tenants_id is" + str(tenants_id)) return Response(tenants_id)
def delete_snapshots(request): LOG.info("request data is ids") ids = request.data.getlist('ids[]') datacenter = DataCenter.get_default() rc = create_rc_by_dc(datacenter) LOG.info(settings.GLANCE_ENDPOINT) url = settings.GLANCE_ENDPOINT try: client = glance.glanceclient(rc, url) for snapshot in Snapshot.objects.filter(pk__in=ids): image_id = snapshot.snapshot_id LOG.info(image_id) try: client.images.delete(image_id) except Exception as e: LOG.info(str(e)) Snapshot.objects.filter(pk__in=ids).delete() LOG.info("dddd") Image.objects.filter(uuid=image_id).delete() LOG.info("dddd") continue return Response( { 'success': False, "msg": _('Snapshots have not been deleted!') }, status=status.HTTP_201_CREATED) LOG.info("dddd") Snapshot.objects.filter(pk__in=ids).delete() LOG.info("dddd") Image.objects.filter(uuid=image_id).delete() LOG.info("dddd") return Response( { 'success': True, "msg": _('Snapshots have been deleted!') }, status=status.HTTP_201_CREATED) except: traceback.print_exc() return Response({ 'success': False, "msg": _('Failed to delete Snapshots!') })
def post(self, request): user = User() form = CloudUserCreateForm(data=request.POST, instance=user) if form.is_valid(): form.save() if settings.REGISTER_ACTIVATE_EMAIL_ENABLED: _send_activate_email(user) msg = _("Your registration successed, we send you one " "activate email, please check your input box.") else: link_user_to_dc_task.delay(user, DataCenter.get_default()) msg = _("Your registration successed!") return render(request, 'info.html', {'message': msg}) return self.response(request, form, form.errors)
def get(self, request): LOG.info("****** signup get method ********") datacenter = DataCenter.get_default() LOG.info("****** signup get method ********") rc = create_rc_by_dc(datacenter) LOG.info("****** signup get method ********") tenants = keystone.keystoneclient(rc).tenants.list() tenants_id = {} for tenant in tenants: if str(tenant.name) not in ["admin", "demo", "services"]: tenants_id[tenant.id] = tenant.name LOG.info("********* tenants_id is **************" + str(tenants_id)) return self.response( request, CloudUserCreateForm(initial={ 'username': '', 'email': '', 'mobile': '' }), tenants_id)
def list(self, request): datacenter = DataCenter.get_default() rc = create_rc_by_dc(datacenter) networks = neutron.network_list(rc) data = [] for network in networks: LOG.info("1") admin_state_up = network.admin_state_up LOG.info("1") if admin_state_up: admin_state_up = "启用" data.append({ "id": network.id, "name": network.name, "admin_state_up": admin_state_up, "tenant_id": network.tenant_id }) LOG.info("1") LOG.info(" data is " + str(data)) return Response(data)
def response(self, request, form, tenants_id=None, errors=None): LOG.info("****** signup get method ********") datacenter = DataCenter.get_default() LOG.info("****** signup get method ********") rc = create_rc_by_dc(datacenter) LOG.info("****** signup get method ********") tenants = keystone.keystoneclient(rc).tenants.list() tenants_id = {} for tenant in tenants: if str(tenant.name) not in ["admin", "demo", "services"]: tenants_id[tenant.id] = tenant.name LOG.info("********* tenants_id is **************" + str(tenants_id)) context = { "BRAND": settings.BRAND, "form": form, "errors": errors, "tenants_id": tenants_id } return render(request, 'signup.html', context)
def user_delete(request, tenant_id, ID): datacenter = DataCenter.get_default() rc = create_rc_by_dc(datacenter) keystone.remove_tenant_user(rc, project=tenant_id, user=ID) return True
def create_user(request): LOG.info("****** start to create user *****") LOG.info("******* data is ******" + str(request.data)) LOG.info("****** username is ******" + str(request.data['username'])) posted_username = request.data['username'] if str(posted_username) in ['neutron', 'cinder', 'keystone', 'nova', 'glance', 'heat', 'swift', 'admin', 'ceilometer']: return Response({"success": False, "msg": _("Service user must not be created.")}) LOG.info("****** password is ******" + str(request.data['password1'])) user = User() LOG.info("ccccccccccccc") form = CloudUserCreateFormWithoutCapatcha(data=request.POST, instance=user) LOG.info("ddddddddddddd") if not form.is_valid(): LOG.info("form is not valid") return Response({"success": False, "msg": _("Data is not valid")}) user = form.save() #update start if settings.TRI_ENABLED and request.data['is_system_user'] == 'true': LOG.info("******** I am systemuser ***************") #user = User.objects.create_superuser(username=username, email=email, password=password1) UserProxy.grant_system_user(user) LOG.info("fffffffffff") #return Response({"success": True, # "msg": _("User is created successfully!")}) if settings.TRI_ENABLED and request.data['is_safety_user'] == 'true': LOG.info("******** I am safetyuser ***************") #user = User.objects.create_superuser(username=username, email=email, password=password1) LOG.info("******** SUPERUSER CREATE SUCCESS **********") UserProxy.grant_safety_user(user) LOG.info("fffffffffff") #return Response({"success": True, # "msg": _("User is created successfully!")}) if settings.TRI_ENABLED and request.data['is_audit_user'] == 'true': LOG.info("******** I am audituser ***************") #user = User.objects.create_superuser(username=username, email=email, password=password1) LOG.info("******** SUPERUSER CREATE SUCCESS **********") UserProxy.grant_audit_user(user) LOG.info("fffffffffff") #return Response({"success": True, # "msg": _("User is created successfully!")}) # If workflow is disabled, then only resrouce user can be created, # otherwise admin can create resource user and workflow approver user. if not settings.WORKFLOW_ENABLED: tenant_id = request.data['tenant'] LOG.info("tennat_id is " + str(tenant_id)) password = request.data['password1'] link_user_to_dc_task.delay(user, DataCenter.get_default(), tenant_id, password) try: operation = Operation(user=request.user, udc_id=request.session['UDC_ID'], resource='用户', resource_id=1, resource_name='用户',action="创建用户", result=1) operation.save() except Exception as e: LOG.info(str(e)) else: if 'is_resource_user' in request.data and \ request.data['is_resource_user'] == 'true': tenant_id = request.data['tenant'] link_user_to_dc_task(user, DataCenter.get_default(), tenant_id, password) if 'is_approver' in request.data and \ request.data['is_approver'] == 'true': UserProxy.grant_workflow_approve(user) return Response({"success": True, "msg": _("User is created successfully!")})
def create_user(request): LOG.info("****** start to create user *****") LOG.info("******* data is ******" + str(request.data)) LOG.info("****** username is ******" + str(request.data['username'])) LOG.info("****** password is ******" + str(request.data['password1'])) user = User() LOG.info("ccccccccccccc") form = CloudUserCreateFormWithoutCapatcha(data=request.POST, instance=user) LOG.info("ddddddddddddd") if not form.is_valid(): LOG.info("form is not valid") return Response({"success": False, "msg": _("Data is not valid")}) user = form.save() #update start if settings.TRI_ENABLED and request.data['is_system_user'] == 'true': LOG.info("******** I am systemuser ***************") #user = User.objects.create_superuser(username=username, email=email, password=password1) UserProxy.grant_system_user(user) LOG.info("fffffffffff") #return Response({"success": True, # "msg": _("User is created successfully!")}) if settings.TRI_ENABLED and request.data['is_safety_user'] == 'true': LOG.info("******** I am safetyuser ***************") #user = User.objects.create_superuser(username=username, email=email, password=password1) LOG.info("******** SUPERUSER CREATE SUCCESS **********") UserProxy.grant_safety_user(user) LOG.info("fffffffffff") #return Response({"success": True, # "msg": _("User is created successfully!")}) if settings.TRI_ENABLED and request.data['is_audit_user'] == 'true': LOG.info("******** I am audituser ***************") #user = User.objects.create_superuser(username=username, email=email, password=password1) LOG.info("******** SUPERUSER CREATE SUCCESS **********") UserProxy.grant_audit_user(user) LOG.info("fffffffffff") #return Response({"success": True, # "msg": _("User is created successfully!")}) # If workflow is disabled, then only resrouce user can be created, # otherwise admin can create resource user and workflow approver user. if not settings.WORKFLOW_ENABLED: tenant_id = request.data['tenant'] LOG.info("tennat_id is " + str(tenant_id)) password = request.data['password1'] link_user_to_dc_task.delay(user, DataCenter.get_default(), tenant_id, password) else: if 'is_resource_user' in request.data and \ request.data['is_resource_user'] == 'true': tenant_id = request.data['tenant'] link_user_to_dc_task(user, DataCenter.get_default(), tenant_id, password) if 'is_approver' in request.data and \ request.data['is_approver'] == 'true': UserProxy.grant_workflow_approve(user) return Response({"success": True, "msg": _("User is created successfully!")})
def create_network(request): #udc_id = request.session['UDC_ID'] #UDC = UserDataCenter.objects.get(pk=udc_id) #tenant_id = UDC.tenant_uuid #rc = create_rc_by_udc(UDC) datacenter = DataCenter.get_default() rc = create_rc_by_dc(datacenter) LOG.info("*********** data is *************" + str(request.data)) network_name = request.data['network_name'] LOG.info(network_name) tenant = request.data['tenant'] LOG.info(tenant) physnet = request.data['physnet'] LOG.info(physnet) seg_id = request.data['seg_id'] LOG.info(seg_id) subnet_name = request.data['subnet_name'] LOG.info(subnet_name) status = request.data['status'] or 'up' LOG.info("**** status is ****" + str(status)) cidr = request.data['cidr'] LOG.info(cidr) ip_version = request.data['ip_version'] or 'ipv4' LOG.info(ip_version) gateway = request.data['gateway'] LOG.info(gateway) enable_gateway = request.data['enable_gateway'] or 'up' LOG.info(enable_gateway) enable_dhcp = request.data['enable_dhcp'] or 'up' LOG.info(enable_dhcp) allocation_polls = request.data['allocation_polls'] LOG.info(allocation_polls) dns_server = request.data['dns_server'] LOG.info(dns_server) host_router = request.data['host_router'] LOG.info(host_router) admin_state_up = status network_type = "vlan" network = _create_network(rc, network_name, admin_state_up, physnet, seg_id, tenant, network_type) LOG.info("**** network is ****" + str(network)) network_id = network.id LOG.info(network_id) network_name = network.name LOG.info(network_name) LOG.info(tenant) try: subnet = _create_subnet(rc, subnet_name, cidr, ip_version, gateway, enable_gateway, enable_dhcp, allocation_polls, dns_server, network_id, network_name, host_router, tenant) except Exception as e: LOG.info(e) LOG.info("*** subnet is ***" + str(subnet)) if not subnet: neutron.network_delete(rc, network.id) return Response({ "OPERATION_STATUS": 0, "MSG": _('Network address exists') }) LOG.info(" start to save network info in db *****") return Response({"OPERATION_STATUS": 1, "MSG": _("Creating network")})
def summary(request): LOG.info('-------------------- this is for admin UDC -------------------') try: user = User.objects.filter(username=request.user)[0] if user.is_superuser: dc = DataCenter.get_default() rc = create_rc_by_dc(dc) if not UserDataCenter.objects.filter(data_center=dc, user=user).exists(): initcloud_tenant = "initcloud_" + user.username LOG.info(initcloud_tenant) tenant = keystone.tenant_create(rc, name=initcloud_tenant) LOG.info("--------- create tenant for superuser ---------") LOG.info(tenant) users = keystone.user_list(rc) for admin_user in users: if admin_user.name == settings.ADMIN_NAME: keystone_user_id = admin_user.id keystone.user_update_tenant(rc, admin_user, tenant) for role in keystone.role_list(rc): if role.name == 'admin': role_id = role.id keystone.add_tenant_user_role(rc, user=admin_user, role=role_id, project=tenant) #tenants = keystone.keystoneclient(rc).tenants.list() #for tenant in tenants: # if tenant.name == settings.ADMIN_TENANT_NAME: # admin_tenant_id = tenant.id # admin_tenant_name = tenant.name # LOG.info(tenant.name) # LOG.info(tenant.id) admin_UDC = UserDataCenter.objects.create( data_center=dc, user=user, tenant_name=tenant.name, tenant_uuid=tenant.id, keystone_user=settings.ADMIN_NAME, keystone_password=settings.ADMIN_PASS, keystone_user_id=keystone_user_id) Contract.objects.create(user=user, udc=admin_UDC, name=user.username, customer=user.username, start_date=datetime.datetime.now(), end_date=datetime.datetime.now(), deleted=False) #if not Contract.objects.filter(user=user).exists(): #admin_UDC = UserDataCenter.objects.filter(data_center=dc, user=user)[0] #Contract.objects.create(user=user,udc=admin_UDC,name=user.username,customer=user.username,start_date=datetime.datetime.now(),end_date=datetime.datetime.now(),deleted=False) except: traceback.print_exc() return Response({ "user_num": User.objects.filter(is_superuser=False).count(), "instance_num": Instance.objects.filter(deleted=False).count(), "flavor_num": Flavor.objects.count(), "data_center_num": DataCenter.objects.count(), "contract_num": Contract.objects.filter(deleted=False).count(), "image_num": Image.objects.count() })
def initialize_user(request): user_id = request.data['user_id'] user = User.objects.get(pk=user_id) link_user_to_dc_task(user, DataCenter.get_default()) return Response({"success": True, "msg": _("Initialization is successful.")})
def create_user(request): LOG.info("****** start to create user *****") LOG.info("******* data is ******" + str(request.data)) LOG.info("****** username is ******" + str(request.data['username'])) LOG.info("****** password is ******" + str(request.data['password1'])) user = User() LOG.info("ccccccccccccc") form = CloudUserCreateFormWithoutCapatcha(data=request.POST, instance=user) LOG.info("ddddddddddddd") if not form.is_valid(): LOG.info("form is not valid") return Response({"success": False, "msg": _("Data is not valid")}) user = form.save() #update start if settings.TRI_ENABLED and request.data['is_system_user'] == 'true': LOG.info("******** I am systemuser ***************") #user = User.objects.create_superuser(username=username, email=email, password=password1) UserProxy.grant_system_user(user) LOG.info("fffffffffff") #return Response({"success": True, # "msg": _("User is created successfully!")}) if settings.TRI_ENABLED and request.data['is_safety_user'] == 'true': LOG.info("******** I am safetyuser ***************") #user = User.objects.create_superuser(username=username, email=email, password=password1) LOG.info("******** SUPERUSER CREATE SUCCESS **********") UserProxy.grant_safety_user(user) LOG.info("fffffffffff") #return Response({"success": True, # "msg": _("User is created successfully!")}) if settings.TRI_ENABLED and request.data['is_audit_user'] == 'true': LOG.info("******** I am audituser ***************") #user = User.objects.create_superuser(username=username, email=email, password=password1) LOG.info("******** SUPERUSER CREATE SUCCESS **********") UserProxy.grant_audit_user(user) LOG.info("fffffffffff") #return Response({"success": True, # "msg": _("User is created successfully!")}) # If workflow is disabled, then only resrouce user can be created, # otherwise admin can create resource user and workflow approver user. if not settings.WORKFLOW_ENABLED: tenant_id = request.data['tenant'] LOG.info("tennat_id is " + str(tenant_id)) password = request.data['password1'] link_user_to_dc_task.delay(user, DataCenter.get_default(), tenant_id, password) else: if 'is_resource_user' in request.data and \ request.data['is_resource_user'] == 'true': tenant_id = request.data['tenant'] link_user_to_dc_task(user, DataCenter.get_default(), tenant_id, password) if 'is_approver' in request.data and \ request.data['is_approver'] == 'true': UserProxy.grant_workflow_approve(user) return Response({ "success": True, "msg": _("User is created successfully!") })