I'm trying to create instances using openstacksdk python api everything is ok but even when i use:
conn2 = conn.connect_as_project(proj.name)
server = conn2.create_server(......)
the server is being created under property of admin project, not the project mentioned in proj.name I even tried project.id but didn't worked.
Finally instead of:
conn2 = conn.connect_as_project(project_id)
I used:
conn2 = openstack.connection.Connection(
region_name='RegionOne',
auth=dict(
auth_url='http://controller:5000/v3',
username=u_name,
password=password,
project_id=project_id,
user_domain_id='default'),
compute_api_version='2',
identity_interface='internal')
and it worked.
I did this just fine...the only difference is that the project is a new project and I have to give credentials to the user I was using.
It was something like that:
project = sconn.create_project(
name=name, domain_id='default')
user_id = conn.current_user_id
user = conn.get_user(user_id)
roles = conn.list_roles()
for r in roles:
conn.identity.assign_project_role_to_user(
project.id, user.id, r.id
)
# Make sure the roles are correctly assigned to the user before proceed
conn2 = self.conn.connect_as_project(project.name)
After that, anything created (servers, keypairs, networks, etc) is under the new project.
Related
I'm trying to modify an user account password in but it doesn't work, I've tried it directly in AD and it does work. I'm using ldap3 to do it, here's the steps I do.
First I do the app operation like this
from ldap3 import Server, Connection, ALL
s = Server("ldap://192.168.x.xx", use_ssl=True)
c = Connection(s, user='adminldap', password='xxxxxxx')
c.bind()
c.add('cn=jtest,ou=users,ou=MJC,dc=mjc,dc=lan', ['user', 'posixGroup', 'top'], {'cn': 'jtest', 'sAMAccountName':'jtest', 'mail':'jtest#gmail.com','telephoneNumber':'0102030405','displayName':'jtest'})
This one works.
Then I try to set the password
Path_Root = "ou=users,ou=MJC,DC=mjc,DC=lan"
Filter = "(&(objectclass=user)(&(sAMAccountName=jtest)(!(objectclass=computer))))"
c.search(search_base = Path_Root,search_filter = Filter,attributes = ["cn", "sAMAccountName", "displayName"])
if len(c.entries) == 1:
USER_DN = c.response[0].get("dn")
c.extend.microsoft.modify_password(USER_DN, 'Formation123')
Like this but the last line keeps returning False.
Have you got an idea why ? Thank you.
According to this:
I looked into the source and it says old password must be None to reset password with sufficient privileges
This should work:
c.extend.microsoft.modify_password(USER_DN, 'Formation123', old_password=None)
And the connection has to be encrypted. You may have to specify ldaps:// even though you specified use_ssl, since the LDAPS port (636) is different than the regular LDAP port (389).
s = Server("ldaps://192.168.x.xx", use_ssl=True)
the solution was setting ssl on my ldap and it worked.
I'm trying to list the subscriptions in an Azure account using azure-python-sdk.
I have followed this link in documentation.
https://learn.microsoft.com/en-us/python/api/azure-mgmt-subscription/azure.mgmt.subscription.operations.subscriptionsoperations?view=azure-python#list-custom-headers-none--raw-false----operation-config-
from azure.mgmt.subscription import SubscriptionClient
from msrestazure.azure_active_directory import UserPassCredentials
credentials = UserPassCredentials(username='xxxx', password='xxxx')
sub_client = SubscriptionClient(credentials)
subs = [sub.as_dict() for sub in sub_client.subscriptions.list()]
print(subs)
It is supposed to return a list of subscriptions.
However, I see only empty list returned every time I try the above code.
Can anybody help?
Try this code,
def list_subscriptions():
try:
sub_client = get_client_from_cli_profile(SubscriptionClient)
except CLIError:
logger.info("Not logged in, running az login")
_run_az_cli_login()
sub_client = get_client_from_cli_profile(SubscriptionClient)
return [["Subscription_name", "Subscription ID"]] + [
[sub.display_name, sub.subscription_id]
for sub in sub_client.subscriptions.list()
]
You can find the handy tool from here
If the list is empty and you get not exception, it's likely your credentials are correct (no exception), but your user doesn't have access to subscriptions (no permissions)
In the Azure portal, in the subscription panel you have a button "Access control (IAM)" to define what users are allowed to a given subscription.
https://learn.microsoft.com/azure/role-based-access-control/role-assignments-portal
https://learn.microsoft.com/azure/role-based-access-control/rbac-and-directory-admin-roles
(I work at MS in the SDK team)
I think I solved the issue using Azure CLI. Yet, I still wonder why it didn't work as supposed using azure-python-sdk.
Here is the code:
import subprocess
import json
subscriptions = json.loads(subprocess.check_output('az account list', shell=True).decode('utf-8'))
print(subscriptions)
Thank you for your responses.
I have a similar problem, so I have used AzureCliCredential and it simply worked.
The code is this:
def subscription_list():
credential = AzureCliCredential()
subscription_client = SubscriptionClient(credential)
sub_list = subscription_client.subscriptions.list()
column_width = 40
print("Subscription ID".ljust(column_width) + "Display name")
print("-" * (column_width * 2))
for group in list(sub_list):
print(f'{group.subscription_id:<{column_width}}{group.display_name}')
Before trying this code, you have to log to Azure through the command line in your dev environment.
Here i'm attached the python files to create user and authenticating user in windows active Directory 2008 r2
create.py
import ldap
import ldap.modlist as modlist
name='testing3'
password='p#ssw0rd'
l = ldap.initialize('ldap://##2.168.3#.##')
l.simple_bind_s('Administrator#example.local', 'p#ssw0rd1')
dn="cn="+name+",ou=oli,dc=example,dc=local"
attrs = {}
attrs['objectclass'] = ['Top','person','organizationalPerson','user']
attrs['cn'] = name
attrs['displayName'] = name
attrs['name'] = name
attrs['givenName'] = name
attrs['mail'] = name
attrs['ou'] = "Users"
#attrs['pwdLastSet'] = "-1"
attrs['userPrincipalName'] = name + "#naanal.local
attrs['userAccountControl'] = '514'
attrs['sAMAccountName'] = name
attrs['userPassword'] = password
ldif = modlist.addModlist(attrs)
l.add_s(dn,ldif)
l.unbind_s()
Using this program create user in the Active directory but unable to create the enabled user account. i can user the userAccountcontrol=''512` but it not working .userAccountcontrol='514' its working but user account was disabled.
using ldap modify change the userAccountcontrol getting error "when i'm try to enable the user account getting error "{'info': '0000052D: SvcErr: DSID-031A120C, problem 5003 (WILL_NOT_PERFORM), data 0\n', 'desc': 'Server is unwilling to perform'}""
Authe.py
import ldap
username='shan'
password='p#ssw0rd'
LDAP_SERVER = 'ldap://###.##.##.##'
LDAP_USERNAME = '%s#example.local' % username
LDAP_PASSWORD = password
base_dn = 'DC=example,DC=example'
ldap_filter = 'userPrincipalName=%s#example.local' % username
attrs = ['memberOf']
try:
ldap_client = ldap.initialize(LDAP_SERVER)
ldap_client.set_option(ldap.OPT_REFERRALS,0)
ldap_client.simple_bind_s(LDAP_USERNAME, LDAP_PASSWORD)
print 'successfull'
except ldap.INVALID_CREDENTIALS:
ldap_client.unbind()
print 'Wrong username ili password'
except ldap.SERVER_DOWN:
print 'AD server not awailable'
create the user account using create.py .then enable the user account manually in the active directory.after i'm try to authenticate the created user account not detected.but manually created account detected by using authe.py file
i'm using Ubuntu 14.04 64 bit
There are two problems with your code:
Active Directory stores the password in the unicodePwd attribute and not userPassword. See this link for more details. This article also explains how the value for unicodePwd must be encoded (UTF-16)
The other problem (this is also explained in the referenced article) is that you must connect over a secure connection to Active Directory whenever you are making changes to the password attribute (including creating a user). The URL starting with ldap:// makes me believe that your connection is not secure.
I hope this helps.
I can create blog post in confluence using the script below:
import sys
from xmlrpclib import Server
user = "user"
passwd = "pass"
serverurl = "<blah-blah>/xmlrpc"
spacekey = "DEV"
s = Server( serverurl )
token = s.confluence1.login( user, passwd )
newblogpostdata = {"title":"title",
"content":"content",
"space":spacekey}
newblogpostdata = s.confluence1.storeBlogEntry(token, newblogpostdata)
But couldn't find how to add some labels to the blog post?
Update. Finally I used the following solution:
id = newblogpost['id']
s.confluence1.addLabelByName(token, "ctrm", id)
Have you tried using macros in your content?
https://confluence.atlassian.com/display/DOC/Using+Label+Macros+to+Categorise+Wiki+Content
https://confluence.atlassian.com/display/DOC/Confluence+Wiki+Markup+for+Macros
But you would have to experiment to find proper syntax I am afraid.
I am creating a integration tool to integrate with rally and my web application. I decided to use Python to run in my web-server to retrieve the contents from rally.
In one of the scenario, I need to get the last modified task from a story. I don't know the ID, Name or anything, but I know the story name. Using the story name, how can I get the last modified task(s)?
Here's an example of how to set up Kyle's query in pyral:
server = "rally1.rallydev.com"
user = "user#company.com"
password = "topsecret"
workspace = "My Workspace"
project = "My Project"
rally = Rally(server, user, password, workspace=workspace, project=project)
rally.enableLogging("rally.history.showtasks")
fields = "FormattedID,State,Name,WorkProduct,Name,LastUpdateDate",
criterion = 'Workproduct.Name = "My Tasks User Story"'
response = rally.get('Task', fetch=fields, query=criterion, order="LastUpdateDate Desc",pagesize=200, limit=400)
most_current_task = response.next()
print "%-8.8s %-52.52s %s" % (most_current_task.FormattedID, most_current_task.Name, most_current_task.State)
I'm not super familiar with how to use pyral but you should be able to get what you'd like by querying against the task wsapi endpoint like so:
/slm/webservice/1.40/task.js?query=(WorkProduct.Name = "Story Name")&order=LastUpdateDate DESC
Now you just need to get pyral to generate that request. :-)