本文整理汇总了Python中pyon.agent.agent.ResourceAgentClient.get_resource方法的典型用法代码示例。如果您正苦于以下问题:Python ResourceAgentClient.get_resource方法的具体用法?Python ResourceAgentClient.get_resource怎么用?Python ResourceAgentClient.get_resource使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pyon.agent.agent.ResourceAgentClient
的用法示例。
在下文中一共展示了ResourceAgentClient.get_resource方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: get_resource
# 需要导入模块: from pyon.agent.agent import ResourceAgentClient [as 别名]
# 或者: from pyon.agent.agent.ResourceAgentClient import get_resource [as 别名]
def get_resource(self, resource_id='', params=None):
"""Return the value of the given resource parameter.
@param resource_id The id of the resource agennt.
@param params A list of parameters names to query.
@retval A dict of parameter name-value pairs.
@throws BadRequest if the command was malformed.
@throws NotFound if the resource does not support the parameter.
@param resource_id str
@param params list
@retval result AgentCommandResult
@throws NotFound if the parameter does not exist.
"""
res_type = self._get_resource_type(resource_id)
if self._has_agent(res_type):
rac = ResourceAgentClient(resource_id=resource_id)
return rac.get_resource(resource_id=resource_id, params=params)
res_interface = self._get_type_interface(res_type)
get_result = {}
for param in params:
getter = get_safe(res_interface, "params.%s.get" % param, None)
if getter:
get_res = self._call_getter(getter, resource_id, res_type)
get_result['param'] = get_res
else:
get_result['param'] = None
return get_result
示例2: get_resource
# 需要导入模块: from pyon.agent.agent import ResourceAgentClient [as 别名]
# 或者: from pyon.agent.agent.ResourceAgentClient import get_resource [as 别名]
def get_resource(self, resource_id='', params=None):
"""Return the value of the given resource parameter.
"""
res_type = self._get_resource_type(resource_id)
if self._has_agent(res_type):
rac = ResourceAgentClient(resource_id=resource_id)
return rac.get_resource(resource_id=resource_id, params=params)
res_interface = self._get_type_interface(res_type)
get_result = {}
for param in params:
getter = get_safe(res_interface, "params.%s.get" % param, None)
if getter:
get_res = self._call_getter(getter, resource_id, res_type)
get_result[param] = get_res
else:
get_result[param] = None
return get_result
示例3: TestAgentPersistence
# 需要导入模块: from pyon.agent.agent import ResourceAgentClient [as 别名]
# 或者: from pyon.agent.agent.ResourceAgentClient import get_resource [as 别名]
#.........这里部分代码省略.........
# Ping the agent.
retval = self._ia_client.ping_agent()
log.info(retval)
# Initialize the agent.
# The agent is spawned with a driver config, but you can pass one in
# optinally with the initialize command. This validates the driver
# config, launches a driver process and connects to it via messaging.
# If successful, we switch to the inactive state.
cmd = AgentCommand(command=ResourceAgentEvent.INITIALIZE)
retval = self._ia_client.execute_agent(cmd)
state = self._ia_client.get_agent_state()
self.assertEqual(state, ResourceAgentState.INACTIVE)
# Ping the driver proc.
retval = self._ia_client.ping_resource()
log.info(retval)
cmd = AgentCommand(command=ResourceAgentEvent.GO_ACTIVE)
retval = self._ia_client.execute_agent(cmd)
state = self._ia_client.get_agent_state()
self.assertEqual(state, ResourceAgentState.IDLE)
cmd = AgentCommand(command=ResourceAgentEvent.RUN)
retval = self._ia_client.execute_agent(cmd)
state = self._ia_client.get_agent_state()
self.assertEqual(state, ResourceAgentState.COMMAND)
params = [
SBE37Parameter.OUTPUTSV,
SBE37Parameter.NAVG,
SBE37Parameter.TA0
]
retval = self._ia_client.get_resource(params)
orig_params = retval
new_params = {
SBE37Parameter.OUTPUTSV : not orig_params[SBE37Parameter.OUTPUTSV],
SBE37Parameter.NAVG : orig_params[SBE37Parameter.NAVG] + 1,
SBE37Parameter.TA0 : orig_params[SBE37Parameter.TA0] * 2
}
#print '########### orig params'
#print str(orig_params)
self._ia_client.set_resource(new_params)
retval = self._ia_client.get_resource(params)
self.assertEqual(retval[SBE37Parameter.OUTPUTSV],
new_params[SBE37Parameter.OUTPUTSV])
self.assertEqual(retval[SBE37Parameter.NAVG],
new_params[SBE37Parameter.NAVG])
delta = max(retval[SBE37Parameter.TA0],
new_params[SBE37Parameter.TA0])*.01
self.assertAlmostEqual(retval[SBE37Parameter.TA0],
new_params[SBE37Parameter.TA0], delta=delta)
#print '########### new params'
#print str(retval)
# Now stop and restart the agent.
self._stop_agent()
self._support.stop_pagent()
gevent.sleep(10)
self._start_pagent()
gevent.sleep(10)
示例4: RunInstrument
# 需要导入模块: from pyon.agent.agent import ResourceAgentClient [as 别名]
# 或者: from pyon.agent.agent.ResourceAgentClient import get_resource [as 别名]
#.........这里部分代码省略.........
for subscriber in self._data_subscribers:
pubsub_client = PubsubManagementServiceClient()
if hasattr(subscriber,'subscription_id'):
try:
pubsub_client.deactivate_subscription(subscriber.subscription_id)
except:
pass
pubsub_client.delete_subscription(subscriber.subscription_id)
subscriber.stop()
def bring_instrument_active(self):
"""
@brief Bring the agent up to COMMAND state,
"""
"""
DHE: Don't have an event subscriber yet
# Set up a subscriber to collect error events.
#self._start_event_subscriber('ResourceAgentResourceStateEvent', 6)
#self.addCleanup(self._stop_event_subscriber)
"""
try:
state = self._ia_client.get_agent_state()
print "AgentState: " + str(state)
cmd = AgentCommand(command=ResourceAgentEvent.INITIALIZE)
retval = self._ia_client.execute_agent(cmd)
state = self._ia_client.get_agent_state()
print "AgentState: " + str(state)
res_state = self._ia_client.get_resource_state()
print "DriverState: " + str(res_state)
cmd = AgentCommand(command=ResourceAgentEvent.GO_ACTIVE)
retval = self._ia_client.execute_agent(cmd)
state = self._ia_client.get_agent_state()
print "AgentState: " + str(state)
res_state = self._ia_client.get_resource_state()
print "DriverState: " + str(res_state)
"""
If the agent is in STREAMING state, it will not accept the run
command.
"""
if state != ResourceAgentState.STREAMING:
cmd = AgentCommand(command=ResourceAgentEvent.RUN)
retval = self._ia_client.execute_agent(cmd)
state = self._ia_client.get_agent_state()
print "AgentState: " + str(state)
res_state = self._ia_client.get_resource_state()
print "DriverState: " + str(res_state)
except:
log.error("bring_instrument_active(): Exception occurred; shutting down.", exc_info=True)
return False
else:
return True
示例5: ExternalDatasetAgentTestBase
# 需要导入模块: from pyon.agent.agent import ResourceAgentClient [as 别名]
# 或者: from pyon.agent.agent.ResourceAgentClient import get_resource [as 别名]
#.........这里部分代码省略.........
cmd = AgentCommand(command=DriverEvent.STOP_AUTOSAMPLE)
self._ia_client.execute_resource(cmd)
state = self._ia_client.get_agent_state()
self.assertEqual(state, ResourceAgentState.COMMAND)
cmd = AgentCommand(command=ResourceAgentEvent.RESET)
self._ia_client.execute_agent(cmd)
state = self._ia_client.get_agent_state()
self.assertEqual(state, ResourceAgentState.UNINITIALIZED)
def test_command(self):
# Test instrument driver get and set interface.
state = self._ia_client.get_agent_state()
self.assertEqual(state, ResourceAgentState.UNINITIALIZED)
cmd = AgentCommand(command=ResourceAgentEvent.INITIALIZE)
self._ia_client.execute_agent(cmd)
state = self._ia_client.get_agent_state()
self.assertEqual(state, ResourceAgentState.INACTIVE)
cmd = AgentCommand(command=ResourceAgentEvent.GO_ACTIVE)
self._ia_client.execute_agent(cmd)
state = self._ia_client.get_agent_state()
self.assertEqual(state, ResourceAgentState.IDLE)
cmd = AgentCommand(command=ResourceAgentEvent.RUN)
self._ia_client.execute_agent(cmd)
state = self._ia_client.get_agent_state()
self.assertEqual(state, ResourceAgentState.COMMAND)
# Retrieve all resource parameters.
reply = self._ia_client.get_resource(params=['DRIVER_PARAMETER_ALL'])
self.assertParamDict(reply, True)
## Retrieve a subset of resource parameters.
params = [
'POLLING_INTERVAL'
]
reply = self._ia_client.get_resource(params=params)
self.assertParamDict(reply)
orig_params = reply
# Set a subset of resource parameters.
new_params = {
'POLLING_INTERVAL': (orig_params['POLLING_INTERVAL'] * 2),
}
self._ia_client.set_resource(params=new_params)
check_new_params = self._ia_client.get_resource(params)
self.assertParamVals(check_new_params, new_params)
cmd = AgentCommand(command=ResourceAgentEvent.RESET)
self._ia_client.execute_agent(cmd)
state = self._ia_client.get_agent_state()
self.assertEqual(state, ResourceAgentState.UNINITIALIZED)
def test_get_set_resource(self):
cmd = AgentCommand(command=ResourceAgentEvent.INITIALIZE)
self._ia_client.execute_agent(cmd)
cmd = AgentCommand(command=ResourceAgentEvent.GO_ACTIVE)
self._ia_client.execute_agent(cmd)
cmd = AgentCommand(command=ResourceAgentEvent.RUN)
self._ia_client.execute_agent(cmd)