XCP-ng
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Register
    • Login
    1. Home
    2. mbaron
    M
    Offline
    • Profile
    • Following 0
    • Followers 0
    • Topics 0
    • Posts 1
    • Groups 0

    mbaron

    @mbaron

    1
    Reputation
    2
    Profile views
    1
    Posts
    0
    Followers
    0
    Following
    Joined
    Last Online

    mbaron Unfollow Follow

    Best posts made by mbaron

    • RE: XOA json-rpc call basic exemple

      Hi @mco-system,

      I propose to you a solution to communicate from a Python program to xo-server api.

      import json
      import aiohttp
      import asyncio
      
      from jsonrpc_websocket import Server
      
      async def routine():
          async with aiohttp.ClientSession() as client:
              server = Server('ws://XO_SERVER_IP/api/', client)
      
              await server.ws_connect()
      
              # No signIn required
              methodsInfoResult = await server.system.getMethodsInfo()
              print('\n'.join([str(e) for e in methodsInfoResult.keys()]))
      
              # signIn required
              result = await server.session.signIn(username='YOUR_LOGIN', password='YOUR_PASSWORD') # email attribute is working in place of username
              result = await server.xo.getAllObjects(filter={"type": "VIF"}, limit=10)
      
              print('[')
              print(', \n'.join([str(json.dumps(e, indent=4)) for e in result.values()]))
              print(']')
      
      asyncio.get_event_loop().run_until_complete(routine())
      

      This code is using the jsonrpc_websocket library.

      A full description is available on my blog => https://mickael-baron.fr/blog/2021/05/28/xo-server-websocket-jsonrcp (in french). A Java version is also available.

      posted in Xen Orchestra
      M
      mbaron

    Latest posts made by mbaron

    • RE: XOA json-rpc call basic exemple

      Hi @mco-system,

      I propose to you a solution to communicate from a Python program to xo-server api.

      import json
      import aiohttp
      import asyncio
      
      from jsonrpc_websocket import Server
      
      async def routine():
          async with aiohttp.ClientSession() as client:
              server = Server('ws://XO_SERVER_IP/api/', client)
      
              await server.ws_connect()
      
              # No signIn required
              methodsInfoResult = await server.system.getMethodsInfo()
              print('\n'.join([str(e) for e in methodsInfoResult.keys()]))
      
              # signIn required
              result = await server.session.signIn(username='YOUR_LOGIN', password='YOUR_PASSWORD') # email attribute is working in place of username
              result = await server.xo.getAllObjects(filter={"type": "VIF"}, limit=10)
      
              print('[')
              print(', \n'.join([str(json.dumps(e, indent=4)) for e in result.values()]))
              print(']')
      
      asyncio.get_event_loop().run_until_complete(routine())
      

      This code is using the jsonrpc_websocket library.

      A full description is available on my blog => https://mickael-baron.fr/blog/2021/05/28/xo-server-websocket-jsonrcp (in french). A Java version is also available.

      posted in Xen Orchestra
      M
      mbaron