def _register_right(client, right_name, description, category, bundle_key, msg_update_callback=utils.NullPrinter()): """Register a right for CSE. :param pyvcloud.vcd.client.Client client: :param str right_name: the name of the new right to be registered. :param str description: brief description about the new right. :param str category: add the right in existing categories in vCD Roles and Rights or specify a new category name. :param str bundle_key: is used to identify the right name and change its value to different languages using localization bundle. :param utils.ConsoleMessagePrinter msg_update_callback: Callback object. :raises BadRequestException: if a right with given name already exists in vCD. """ ext = APIExtension(client) # Since the client is a sys admin, org will hold a reference to System org system_org = Org(client, resource=client.get_org()) try: right_name_in_vcd = f"{{{server_constants.CSE_SERVICE_NAME}}}:{right_name}" # noqa: E501 # TODO(): When org.get_right_record() is moved outside the org scope in # pyvcloud, update the code below to adhere to the new method names. system_org.get_right_record(right_name_in_vcd) msg = f"Right: {right_name} already exists in vCD" msg_update_callback.general(msg) INSTALL_LOGGER.info(msg) # Presence of the right in vCD is not a guarantee that the right will # be assigned to system org too. rights_in_system = system_org.list_rights_of_org() for dikt in rights_in_system: # TODO(): When localization support comes in, this check should be # ditched for a better one. if dikt['name'] == right_name_in_vcd: msg = f"Right: {right_name} already assigned to System " \ f"organization." msg_update_callback.general(msg) INSTALL_LOGGER.info(msg) return # Since the right is not assigned to system org, we need to add it. msg = f"Assigning Right: {right_name} to System organization." msg_update_callback.general(msg) INSTALL_LOGGER.info(msg) system_org.add_rights([right_name_in_vcd]) except EntityNotFoundException: # Registering a right via api extension end point, auto assigns it to # System org. msg = f"Registering Right: {right_name} in vCD" msg_update_callback.general(msg) INSTALL_LOGGER.info(msg) ext.add_service_right(right_name, server_constants.CSE_SERVICE_NAME, server_constants.CSE_SERVICE_NAMESPACE, description, category, bundle_key)
def add(ctx, rights, org_name): try: client = ctx.obj['client'] if org_name is not None: org_href = client.get_org_by_name(org_name).get('href') else: org_href = ctx.obj['profiles'].get('org_href') org = Org(client, href=org_href) org.add_rights(rights) stdout("Rights added to the Org \'%s\'" % org_name, ctx) except Exception as e: stderr(e, ctx)
def test_11_add_rights_to_org(self): org_in_use = self.config['vcd']['org_in_use'] org = Org(self.client, href=self.client.get_org_by_name(org_in_use).get('href')) role_name = self.config['vcd']['role_name'] right_name = self.config['vcd']['right_name'] right_record_list = org.list_rights_of_org() no_of_rights_before = len(right_record_list) org.add_rights([right_name]) org.reload() right_record_list = org.list_rights_of_org() no_of_rights_after = len(right_record_list) assert no_of_rights_before < no_of_rights_after
def add_rights(self): org_name = self.params.get('org_name') org_rights = self.params.get('org_rights') response = dict() response['changed'] = False resource = self.client.get_org_by_name(org_name) org = Org(self.client, resource=resource) org.add_rights(org_rights) response['msg'] = "Rights has been added to org successfully." response['changed'] = True return response
def add(ctx, rights, org_name): try: restore_session(ctx) client = ctx.obj['client'] if org_name is not None: org_href = client.get_org_by_name(org_name).get('href') else: org_href = ctx.obj['profiles'].get('org_href') org_name = ctx.obj['profiles'].get('org_in_use') org = Org(client, href=org_href) org.add_rights(rights) stdout("Rights added to the Org \'%s\'" % org_name, ctx) except Exception as e: stderr(e, ctx)