Skip to content

Commit

Permalink
'success' attribute in result message should return 1 on failure so we
Browse files Browse the repository at this point in the history
can use that as an exit code in the client applications
  • Loading branch information
dnaeon committed Apr 4, 2014
1 parent 3ad7d9c commit 16188aa
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 19 deletions.
16 changes: 8 additions & 8 deletions src/vpoller/agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ def _discover_objects(self, properties, obj_type):
path_set=properties
)
except Exception as e:
return { 'success': -1, 'msg': 'Cannot collect properties: %s' % e }
return { 'success': 1, 'msg': 'Cannot collect properties: %s' % e }

result = {
'success': 0,
Expand Down Expand Up @@ -126,10 +126,10 @@ def _get_object_properties(self, properties, obj_type, obj_property_name, obj_pr
obj_type=obj_type
)
except Exception as e:
return { 'success': -1, 'msg': 'Cannot collect properties: %s' % e }
return { 'success': 1, 'msg': 'Cannot collect properties: %s' % e }

if not obj:
return { 'success': -1, 'msg': 'Cannot find object %s' % obj_property_value }
return { 'success': 1, 'msg': 'Cannot find object %s' % obj_property_value }

# Create a list view for this object and collect properties
view_ref = self.get_list_view(obj=[obj])
Expand All @@ -142,7 +142,7 @@ def _get_object_properties(self, properties, obj_type, obj_property_name, obj_pr
include_mors=include_mors
)
except Exception as e:
return { 'success': -1, 'msg': 'Cannot collect properties: %s' % e }
return { 'success': 1, 'msg': 'Cannot collect properties: %s' % e }

result = {
'success': 0,
Expand Down Expand Up @@ -1222,7 +1222,7 @@ def vm_disk_get(self, msg):
if disk['diskPath'] == disk_path:
break
else:
return { 'success': -1, 'msg': 'Unable to find guest disk %s' % disk_path }
return { 'success': 1, 'msg': 'Unable to find guest disk %s' % disk_path }

result = {}
result['name'] = msg['name']
Expand Down Expand Up @@ -1294,11 +1294,11 @@ def vm_process_get(self, msg):

# Check if we have VMware Tools installed and running first as we depend on it
if vm_tools_is_running != 'guestToolsRunning':
return { 'success': -1, 'msg': 'VirtualMachine %s is not running VMware Tools' % msg['name'] }
return { 'success': 1, 'msg': 'VirtualMachine %s is not running VMware Tools' % msg['name'] }

# Prepare credentials used for authentication in the guest system
if not msg['username'] or not msg['password']:
return { 'success': -1, 'msg': 'Need username and password for authentication in guest system %s' % msg['name'] }
return { 'success': 1, 'msg': 'Need username and password for authentication in guest system %s' % msg['name'] }

vm_creds = pyVmomi.vim.vm.guest.NamePasswordAuthentication(
username=msg['username'],
Expand All @@ -1311,7 +1311,7 @@ def vm_process_get(self, msg):
auth=vm_creds
)
except Exception as e:
return { 'success': -1, 'msg': 'Cannot get guest processes: %s' % e }
return { 'success': 1, 'msg': 'Cannot get guest processes: %s' % e }

# Properties to be collected for the guest processes
properties = ['name']
Expand Down
2 changes: 1 addition & 1 deletion src/vpoller/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ def run(self, msg):
# Did we have any result reply at all?
if not result:
logging.error('Did not receive a reply from the server, aborting...')
return { 'success': -1, 'msg': 'Did not receive reply from the server, aborting...' }
return { 'success': 1, 'msg': 'Did not receive reply from the server, aborting...' }

logging.debug('Received reply was: %s', result)

Expand Down
4 changes: 2 additions & 2 deletions src/vpoller/proxy.py
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ def process_mgmt_msg(self):

# Check if we have a command to process
if 'method' not in msg:
return { 'success': -1, 'msg': 'Missing method name' }
return { 'success': 1, 'msg': 'Missing method name' }

# Methods the vPoller Proxy supports and processes
methods = {
Expand All @@ -250,7 +250,7 @@ def process_mgmt_msg(self):
}

if msg['method'] not in methods:
return { 'success': -1, 'msg': 'Unknown method received' }
return { 'success': 1, 'msg': 'Unknown method received' }

# Process the requested method
result = methods[msg['method']](msg)
Expand Down
16 changes: 8 additions & 8 deletions src/vpoller/worker.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ def run(self, config):
self.worker_socket.send_json(result)
except TypeError as e:
logging.warning('Cannot serialize result: %s', e)
self.worker_socket.send_json({ 'success': -1, 'msg': 'Cannot serialize result: %s' % e})
self.worker_socket.send_json({ 'success': 1, 'msg': 'Cannot serialize result: %s' % e})

# Management socket
if socks.get(self.mgmt_socket) == zmq.POLLIN:
Expand Down Expand Up @@ -285,12 +285,12 @@ def process_client_msg(self, msg):
logging.debug('Processing client message: %s', msg)

if not isinstance(msg, dict):
return { 'success': -1, 'msg': 'Expected a JSON message, received %s' % msg.__class__ }
return { 'success': 1, 'msg': 'Expected a JSON message, received %s' % msg.__class__ }

vsphere_host = msg.get('hostname')

if not self.agents.get(vsphere_host):
return { 'success': -1, 'msg': 'Unknown or missing vSphere Agent requested' }
return { 'success': 1, 'msg': 'Unknown or missing vSphere Agent requested' }

# The methods that the vSphere Agents support and process
# In the below dict the key is the method name requested by the client,
Expand Down Expand Up @@ -413,7 +413,7 @@ def process_client_msg(self, msg):
}

if msg['method'] not in methods:
return { 'success': -1, 'msg': 'Unknown method received' }
return { 'success': 1, 'msg': 'Unknown method received' }

agent_method = methods[msg['method']]

Expand All @@ -432,12 +432,12 @@ def process_client_msg(self, msg):

# Check if we have the required message attributes
if not all (k in msg for k in agent_method['msg_attr']):
return { 'success': -1, 'msg': 'Missing message attributes' }
return { 'success': 1, 'msg': 'Missing message attributes' }

# Check if we have correct types of the message attributes
for k in msg.keys():
if not isinstance(msg[k], msg_attr_types[k]):
return { 'success': -1, 'msg': 'Incorrect message attribute type received' }
return { 'success': 1, 'msg': 'Incorrect message attribute type received' }

# Process client request
result = agent_method['method'](msg)
Expand Down Expand Up @@ -467,7 +467,7 @@ def process_mgmt_msg(self, msg):
logging.debug('Processing management message: %s', msg)

if 'method' not in msg:
return { 'success': -1, 'msg': 'Missing method name' }
return { 'success': 1, 'msg': 'Missing method name' }

# The vPoller Worker management methods we support and process
methods = {
Expand All @@ -476,7 +476,7 @@ def process_mgmt_msg(self, msg):
}

if msg['method'] not in methods:
return { 'success': -1, 'msg': 'Unknown method received' }
return { 'success': 1, 'msg': 'Unknown method received' }

# Process management request and return result to client
result = methods[msg['method']](msg)
Expand Down

0 comments on commit 16188aa

Please sign in to comment.