本文整理汇总了Python中pyvcloud.vcd.org.Org.create_user方法的典型用法代码示例。如果您正苦于以下问题:Python Org.create_user方法的具体用法?Python Org.create_user怎么用?Python Org.create_user使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pyvcloud.vcd.org.Org
的用法示例。
在下文中一共展示了Org.create_user方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: create_users
# 需要导入模块: from pyvcloud.vcd.org import Org [as 别名]
# 或者: from pyvcloud.vcd.org.Org import create_user [as 别名]
def create_users(cls):
"""Creates users for each of the roles in CommonRoles.
Skips creating users which are already present in the organization.
:raises: Exception: if the class variable _org_href is not populated.
"""
cls._basic_check()
if cls._org_href is None:
raise Exception('Org ' + cls._config['vcd']['default_org_name'] +
' doesn\'t exist.')
org = Org(cls._sys_admin_client, href=cls._org_href)
for role_enum in cls._user_name_for_roles.keys():
user_name = cls._user_name_for_roles[role_enum]
user_records = list(
org.list_users(name_filter=('name', user_name)))
if len(user_records) > 0:
cls._logger.debug('Reusing existing user ' + user_name + '.')
cls._user_href_for_user_names[user_name] = \
user_records[0].get('href')
continue
role = org.get_role_record(role_enum.value)
cls._logger.debug('Creating user ' + user_name + '.')
user_resource = org.create_user(
user_name=user_name,
password=cls._config['vcd']['default_org_user_password'],
role_href=role.get('href'),
is_enabled=True)
cls._user_href_for_user_names[user_name] = \
user_resource.get('href')
示例2: create
# 需要导入模块: from pyvcloud.vcd.org import Org [as 别名]
# 或者: from pyvcloud.vcd.org.Org import create_user [as 别名]
def create(ctx, user_name, password, role_name, full_name, description, email,
telephone, im, enabled, alert_enabled, alert_email,
alert_email_prefix, external, default_cached, group_role,
stored_vm_quota, deployed_vm_quota):
try:
if len(password) < 6:
raise Exception('Password must be at least 6 characters long.')
restore_session(ctx)
client = ctx.obj['client']
in_use_org_href = ctx.obj['profiles'].get('org_href')
org = Org(client, in_use_org_href)
role = org.get_role_record(role_name)
role_href = role.get('href')
result = org.create_user(
user_name=user_name,
password=password,
role_href=role_href,
full_name=full_name,
description=description,
email=email,
telephone=telephone,
im=im,
alert_email=alert_email,
alert_email_prefix=alert_email_prefix,
stored_vm_quota=stored_vm_quota,
deployed_vm_quota=deployed_vm_quota,
is_group_role=group_role,
is_default_cached=default_cached,
is_external=external,
is_alert_enabled=alert_enabled,
is_enabled=enabled)
stdout('User \'%s\' is successfully created.' % result.get('name'),
ctx)
except Exception as e:
stderr(e, ctx)
示例3: create_user
# 需要导入模块: from pyvcloud.vcd.org import Org [as 别名]
# 或者: from pyvcloud.vcd.org.Org import create_user [as 别名]
def create_user(self, user_name, enabled=False):
logged_in_org = self.client.get_org()
org = Org(self.client, resource=logged_in_org)
role = org.get_role_record(self.config['vcd']['role_name'])
role_href = role.get('href')
return org.create_user(user_name, "password", role_href, "Full Name",
"Description", "[email protected]", "408-487-9087",
"test_user_im", "[email protected]", "Alert Vcd:",
is_enabled=enabled)
示例4: create
# 需要导入模块: from pyvcloud.vcd.org import Org [as 别名]
# 或者: from pyvcloud.vcd.org.Org import create_user [as 别名]
def create(self,
description='',
full_name='',
email='',
telephone='',
im='',
alert_email='',
alert_email_prefix='',
stored_vm_quota=0,
deployed_vm_quota=0,
is_group_role=False,
is_default_cached=False,
is_external=False,
is_alert_enabled=False):
logging.info("__INIT__create[User]")
res = user_pb2.CreateUserResult()
res.created = False
context = self.context
logged_in_org = self.client.get_org()
org = Org(self.client, resource=logged_in_org)
logging.info("__role_name__ %s org[%s]", self.role_name, org)
role = org.get_role_record(self.role_name)
role_href = role.get('href')
try:
result = org.create_user(
self.name, self.password, role_href, full_name, description,
email, telephone, im, alert_email, alert_email_prefix,
stored_vm_quota, deployed_vm_quota, is_group_role,
is_default_cached, is_external, is_alert_enabled,
self.is_enabled)
res.created = True
except Exception as e:
error_message = '__ERROR_create[user] failed for user {0}. __ErrorMessage__ {1}'.format(
self.name, str(e))
logging.warn(error_message)
context.set_code(grpc.StatusCode.INVALID_ARGUMENT)
context.set_details(error_message)
return res
logging.info("__DONE__create[User]")
return res
示例5: System
# 需要导入模块: from pyvcloud.vcd.org import Org [as 别名]
# 或者: from pyvcloud.vcd.org.Org import create_user [as 别名]
sys_admin_resource = client.get_admin()
system = System(client, admin_resource=sys_admin_resource)
admin_org_resource = system.create_org(cfg.org, "Test Org", True)
org_record = client.get_org_by_name(cfg.org)
org = Org(client, href=org_record.get('href'))
print("Org now exists: {0}".format(org.get_name()))
# Ensure user exists on the org.
try:
user_resource = org.get_user(cfg.user['name'])
print("User already exists: {0}".format(cfg.user['name']))
except Exception:
print("User does not exist, creating: {0}".format(cfg.user['name']))
role_record = org.get_role_record(cfg.user['role'])
user_resource = org.create_user(user_name=cfg.user['name'],
password=cfg.user['password'],
role_href=role_record.get('href'))
print("User now exists: {0}".format(user_resource.get('name')))
# Ensure the user is enabled. We could also do so when creating the user
# but this approach will also fix an existing user who is disabled.
user_dict = to_dict(user_resource)
if user_dict.get('IsEnabled') == 'true':
print("User is enabled: {0}".format(user_dict.get('name')))
else:
print("User is not enabled, enabling...")
org.update_user(user_name=user_dict.get('name'), is_enabled=True)
print("User is now enabled: {0}".format(user_dict.get('name')))
# Ensure VDC exists. If we create it reload the org as it affects
# org resource contents and future calls might fail otherwise.
示例6: User
# 需要导入模块: from pyvcloud.vcd.org import Org [as 别名]
# 或者: from pyvcloud.vcd.org.Org import create_user [as 别名]
class User(VcdAnsibleModule):
def __init__(self, **kwargs):
super(User, self).__init__(**kwargs)
logged_in_org = self.client.get_org()
self.org = Org(self.client, resource=logged_in_org)
def manage_states(self):
state = self.params.get('state')
if state == "present":
return self.create()
if state == "absent":
return self.delete()
if state == "update":
return self.update()
def create(self):
params = self.params
role = self.org.get_role_record(params.get('role_name'))
role_href = role.get('href')
username = params.get('username')
userpassword = params.get('userpassword')
full_username = params.get('full_username')
description = params.get('description')
email = params.get('email')
telephone = params.get('telephone')
im = params.get('im')
alert_email = params.get('alert_email')
alert_email_prefix = params.get('alert_email_prefix')
stored_vm_quota = params.get('stored_vm_quota')
deployed_vm_quota = params.get('deployed_vm_quota')
is_group_role = params.get('is_group_role')
is_default_cached = params.get('is_default_cached')
is_external = params.get('is_external')
is_alert_enabled = params.get('is_alert_enabled')
is_enabled = params.get('is_enabled')
response = dict()
response['changed'] = False
try:
self.org.get_user(username)
except EntityNotFoundException:
self.org.create_user(
username, userpassword, role_href, full_username, description,
email, telephone, im, alert_email, alert_email_prefix,
stored_vm_quota, deployed_vm_quota, is_group_role,
is_default_cached, is_external, is_alert_enabled,
is_enabled)
response['msg'] = "User {} has been created.".format(username)
response['changed'] = True
else:
response['warnings'] = "User {} is already present.".format(username)
return response
def delete(self):
username = self.params.get('username')
response = dict()
response['changed'] = False
try:
self.org.get_user(username)
except EntityNotFoundException:
response['warnings'] = "User {} is not present.".format(username)
else:
self.org.delete_user(username)
response['msg'] = "User {} has been deleted.".format(username)
response['changed'] = True
return response
def update(self):
username = self.params.get('username')
enabled = self.params.get('is_enabled')
response = dict()
response['changed'] = False
self.org.get_user(username)
self.org.update_user(username, enabled)
response['msg'] = "User {} has been updated".format(username)
response['changed'] = True
return response