import dbus
session_bus = dbus.SessionBus()
print(session_bus)
serviceName = "com.qcom.QCAT"
service = session_bus.get_object(
serviceName, # Bus name
"/Applications/QCAT/QCAT/bin/QCAT", # Object path
)
print(service)
appVersion = service.get_dbus_method('AppVersion')
print(appVersion)
I want to print appVersion at this code, but it actually print object _DeferreMethod object
How can I get the value of AppVersion.(arguemnts)
pic
You are getting information about the method in appVersion, rather than calling it and getting its return value. Try adding something like:
service_application = dbus.Interface(service, 'com.qcom.Application')
appVersion = service_application.AppVersion()
print(appVersion)
Related
What I should I do to get users uid number, mail, employeenumber?
from ldap3 import Server, Connection
# clear connection
my_server = 'XXX'
my_user = 'uid=idmsa,ou=People,ou=auth,o=csun'
my_password = 'password'
s0 = Server(my_server)
c0 = Connection(s0, my_user, my_password)
c0.bind()
c0.search("o=csun", "(cn=*)")
print(c0.entries)
OUTPUT
DN: uid=aa22342,ou=People,ou=Auth,o=CSUN - STATUS: Read - READ TIME: 2021-06-24T10:27:10.169992
You can pass in the list of attributes to be returned :
c0.search("o=csun", "(cn=*)", attributes=['uid', 'uidNumber', 'mail'])
And then you can iterate over the results with :
for entry in c0.response:
print(entry['dn'])
print(entry['attributes'])
# ...
You can specify on the search which attributes you want to be returned, default is none.
For example :
c0.search(search_base = 'o=csun',
search_filter = '(cn=*)',
search_scope = SUBTREE,
attributes = ['uid', 'uidNumber', 'mail', 'employeeNumber'])
You can find all the parameters of the search function here :
https://ldap3.readthedocs.io/en/latest/searches.html
I am trying to fetch ec2 information via python program , but i am not able to get value for public ip address..which printing as None though it has public ip attached to it (i can see from console)
What I tried:
inst_id = []
for reserv in res_inst['Reservations']:
instance = reserv['Instances']
for inst in instance:
ip_addr = inst['PrivateIpAddress']
#print(inst)
if (ip == ip_addr):
inst_id = inst['InstanceId']
inst_type = inst['InstanceType']
image_id = inst['ImageId']
vpc_id = inst['VpcId']
key_name = inst['KeyName']
#pub_ip = inst[u'PublicIpAddress']
pub_ip = inst.get(u'PublicIpAddress')
print(inst_type)
print(inst_id)
print(key_name)
print(vpc_id)
print(pub_ip)
print(image_id)
az = inst['Placement']['AvailabilityZone']
print(az)
for s1 in inst['SecurityGroups']:
sg_name = s1['GroupName']
print(sg_name)
In above code, these syntaxes are not working for public ip..its says key error
pub_ip = inst[u'PublicIpAddress']
pub_ip = inst['PublicIpAddress']
The below syntax works, but giving None as value
pub_ip = inst.get(u'PublicIpAddress')
Output: I am getting all values except print(pub_ip) which is printing as None.
I am sure when i printing whole json string of inst in above code, i see public ip value present in that json dictionary, however, when printing its saying None.
Can any one suggest what wrong thing i am doing here ...
Blockquote
Hi asp,
Please try this...
response= ec2_client.describe_instances()
for reservation in response['Reservations']:
for instance in reservation['Instances']:
print(instance)
Hope it helps..
#r0ck
I'm new to Python and programing. I need to create a Lambda function using Python 3.7 that will look for a specific tag/value combo and return the tag value along with the instance id . I can get both with my current code but I'm having a hard time figuring out how to combine these. boto3.resource gives me the tag value and boto3.client gives me the instance id.
I have EC2 instances (1000's) where we need to monitor the tag value for the tag 'expenddate' and compare the value (mm/dd/yy) to the current date (mm/dd/yy) and alert when 'expenddate' value is less than the current date.
import boto3
import collections
import datetime
import time
import sys
from datetime import date as dt
def lambda_handler(event, context):
today = datetime.date.today()
mdy = today_string = today.strftime('%m/%d/%y')
ec2 = boto3.resource('ec2')
for instance in ec2.instances.all():
if instance.tags is None:
continue
for tag in instance.tags:
if tag['Key'] == 'expenddate':
if (tag['Value']) <= mdy:
print ("Tag has expired!!!!!!!!!!!")
else:
print ("goodby")
client = boto3.client('ec2')
resp = client.describe_instances(Filters=[{
'Name': 'tag:expenddate',
'Values': ['*']
}])
for reservation in resp['Reservations']:
for instance in reservation['Instances']:
print("InstanceId is {} ".format(instance['InstanceId']))
I want to end up with a combined instance id and tag value or two variables that I can combine later.
change
print ("Tag has expired!!!!!!!!!!!")
to
# initialise array
expiredInstances=[]
.
.
.
.
.
print ("%s has expired" % instance.id)
expiredInstances.append({'instanceId':instance.id,'tag-value':tag['Value']})
That will give you an array of instanceId's with tag values
I want to create a python script where I can pass arguments/inputs to specify instance type and later attach an extra EBS (if needed).
ec2 = boto3.resource('ec2','us-east-1')
hddSize = input('Enter HDD Size if you want extra space ')
instType = input('Enter the instance type ')
def createInstance():
ec2.create_instances(
ImageId=AMI,
InstanceType = instType,
SubnetId='subnet-31d3ad3',
DisableApiTermination=True,
SecurityGroupIds=['sg-sa4q36fc'],
KeyName='key'
)
return instanceID; ## I know this does nothing
def createEBS():
ebsVol = ec2.Volume(
id = instanceID,
volume_type = 'gp2',
size = hddSize
)
Now, can ec2.create_instances() return ID or do I have to do an iteration of reservations?
or do I do an ec2.create(instance_id) / return instance_id? The documentation isn't specifically clear here.
in boto3, create_instances returns a list so to get instance id that was created in the request, following works:
ec2_client = boto3.resource('ec2','us-east-1')
response = ec2_client.create_instances(ImageId='ami-12345', MinCount=1, MaxCount=1)
instance_id = response[0].instance_id
The docs state that the call to create_instances()
https://boto3.readthedocs.io/en/latest/reference/services/ec2.html#EC2.ServiceResource.create_instances
Returns list(ec2.Instance). So you should be able to get the instance ID(s) from the 'id' property of the object(s) in the list.
you can the following
def createInstance():
instance = ec2.create_instances(
ImageId=AMI,
InstanceType = instType,
SubnetId='subnet-31d3ad3',
DisableApiTermination=True,
SecurityGroupIds=['sg-sa4q36fc'],
KeyName='key'
)
# return response
return instance.instance_id
actually create_instances returns an ec2.instance instance
I'm trying to use memcache to cache data retrevied from the datastore. Storing stings works fine. But can't one store an object? I get an error "TypeError: 'str' object is not callable" when trying to store with this:
pageData = StandardPage(page)
memcache.add(memcacheid, pageData, 60)
I've read in the documentation that it requires "The value type can be any value supported by the Python pickle module for serializing values." But don't really understand what that is. Or how to convert pageData to it.
Any ideas?
..fredrik
EDIT:
I was a bit unclear. PageType is an class that amongst other thing get data from the datastore and manipulate it. The class looks like this:
class PageType():
def __init__(self, page):
self.pageData = PageData(data.Modules.gql('WHERE page = :page', page = page.key()).fetch(100))
self.modules = []
def renderEditPage(self):
self.addModules()
return self.modules
class StandardPage(PageTypes.PageType):
templateName = 'Altan StandardPage'
templateFile = 'templates/page.html'
def __init__(self, page):
self.pageData = PageTypes.PageData(data.Modules.gql('WHERE page = :page', page = page.key()).fetch(100))
self.modules = []
self.childModules = []
for child in page.childPages:
self.childModules.append(PageTypes.PageData(data.Modules.gql('WHERE page = :page', page = child.key()).fetch(100)))
def addModules(self):
self.modules.append(PageTypes.getStandardHeading(self, 'MainHeading'))
self.modules.append(PageTypes.getStandardTextBox(self, 'FirstTextBox'))
self.modules.append(PageTypes.getStandardTextBox(self, 'SecondTextBox'))
self.modules.append(PageTypes.getStandardHeading(self, 'ListHeading'))
self.modules.append(PageTypes.getStandardTextBox(self, 'ListTextBox'))
self.modules.append(PageTypes.getDynamicModules(self))
You can use db.model_to_protobuf to turn your object into something that can be stored in memcache. Similarly, db.model_from_protobuf will get your object back.
Resource:
Datastore Functions