def createEdge(module, stub_config): nodes_svc = Nodes(stub_config) edgeNode = EdgeNode(deployment_config=createDeploymentConfig( module, stub_config), description=module.params['description'], display_name=module.params['display_name'], tags=None) try: tmp_node = nodes_svc.create(edgeNode) node = tmp_node.convert_to(EdgeNode) status_svc = Status(stub_config) while True: node_status = status_svc.get(node.id) time.sleep(5) if node_status.mpa_connectivity_status == 'UP' and node_status.host_node_deployment_status == 'NODE_READY': module.exit_json(changed=True, id=node.id, msg="Edge VM with name %s created!" % (module.params['display_name'])) except Error as ex: api_error = ex.data.convert_to(ApiError) module.fail_json('API Error creating node: %s' % (api_error.error_message))
def main(): args = getargs.getargs() stub_config = auth.get_session_auth_stub_config(args.user, args.password, args.nsx_host, args.tcp_port) # Create the services we'll need. fabricnodes_svc = Nodes(stub_config) status_svc = Status(stub_config) # List all of the fabric nodes result = fabricnodes_svc.list() # Iterate over the results for vs in result.results: fn = vs.convert_to(Node) print("Type: %s, Name: %s, id: %s" % (fn.resource_type, fn.display_name, fn.id)) fn_status = status_svc.get(fn.id) print(" mp conn: %s, cp conn: %s" % (fn_status.mpa_connectivity_status, fn_status.lcp_connectivity_status))
def createNode(module, stub_config): if module.params['os_type'] == "ESXI": os_type = HostNode.OS_TYPE_ESXI elif module.params['os_type'] == "RHEL": os_type = HostNode.OS_TYPE_RHELKVM elif module.params['os_type'] == "UBUNTU": os_type = HostNode.OS_TYPE_UBUNTUKVM ip_addr = [] ip_addr.append(module.params['ip_address']) fnodes_svc = Nodes(stub_config) newNode = HostNode(display_name=module.params['display_name'], ip_addresses=ip_addr, os_type=os_type, os_version=module.params['os_version'], host_credential=HostNodeLoginCredential( username=module.params['node_username'], password=module.params['node_passwd'], thumbprint=module.params['thumbprint'])) try: fnodes_svc.create(newNode) except Error as ex: api_error = ex.data.convert_to(ApiError) module.fail_json(msg='API Error creating node: %s' % (api_error.error_message)) time.sleep(20) resultNode = getNodeByName(module, stub_config) status_svc = Status(stub_config) while True: fn_status = status_svc.get(resultNode.id) if fn_status.host_node_deployment_status == "INSTALL_IN_PROGRESS": time.sleep(10) elif fn_status.host_node_deployment_status == "INSTALL_SUCCESSFUL": time.sleep(5) return resultNode else: module.fail_json(msg='Error in Node status: %s' % (str(fn_status)))
def deleteNode(module, node, stub_config): fnodes_svc = Nodes(stub_config) node_id = node.id node_name = node.display_name try: fnodes_svc.delete(node_id) except Error as ex: api_error = ex.data.convert_to(ApiError) module.exit_json(changed=False, object_id=node_id, object_name=node_name, message=api_error) module.fail_json(msg='API Error Deleting node: %s' % (api_error.error_message)) status_svc = Status(stub_config) while True: try: fn_status = status_svc.get(node_id) time.sleep(10) except Error as ex: module.exit_json(changed=True, object_id=node_id, object_name=node_name)