XCP-ng
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Register
    • Login

    APIs SDKs and Xen-ng

    Scheduled Pinned Locked Moved REST API
    22 Posts 3 Posters 2.6k Views 2 Watching
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • V Offline
      vahric 0 @Danp
      last edited by

      @Danp Okay, don't worry then without rest api , how could i automate this ? How XO doing it and how can i say to XO do it for out of REST ? @olivierlambert @julien-f

      DanpD 1 Reply Last reply Reply Quote 0
      • DanpD Offline
        Danp Pro Support Team @vahric 0
        last edited by

        @vahric-0 See @julien-f response here -- https://xcp-ng.org/forum/post/75050

        Once you know the JSON-RPC API syntax, then you should be able to automate it using xo-cli.

        V 1 Reply Last reply Reply Quote 0
        • V Offline
          vahric 0 @Danp
          last edited by Danp

          @Danp

          I used the ?debug and from console i got the json call , thats okay.

          6cf563c8-cd9b-4619-9fcf-9ac96d4c10d4-image.png

          Using @mbaron script , i get the methods and try to create network and looks like i could. Thank you very much

          import json
          import aiohttp
          import asyncio
          
          from jsonrpc_websocket import Server
          
          async def routine():
              async with aiohttp.ClientSession() as client:
                  server = Server('ws://XO ip address/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='username', password='password') # email attribute is working in place of username
                  result = await server.network.create (pif='8369d867-a6f8-61f2-8132-3b485c3b3a63',pool='dd74abdd-7dd9-e95b-a241-dbd5b12b3ae1',name='deneme3',vlan=2346)
                  print('[')
                  print(', \n'.join([str(json.dumps(e, indent=4)) for e in result.values()]))
                  print(']')
          
          asyncio.get_event_loop().run_until_complete(routine())
          
          result = await server.network.create (pif='8369d867-a6f8-61f2-8132-3b485c3b3a63',pool='dd74abdd-7dd9-e95b-a241-dbd5b12b3ae1',name='deneme3',vlan=2346)
          

          11679d0f-1dc6-4e7b-93a9-514146f575d8-image.png

          I guess its will be perfect to move everything rest api and have well documentation.

          One thing, i can not delete created test network because of HA, is it normal ?

          Regards
          VM

          DanpD 1 Reply Last reply Reply Quote 0
          • DanpD Offline
            Danp Pro Support Team @vahric 0
            last edited by

            @vahric-0 said in APIs SDKs and Xen-ng:

            One thing, i can not delete created test network because of HA, is it normal ?

            IDK. What error did you receive?

            V 1 Reply Last reply Reply Quote 0
            • V Offline
              vahric 0 @Danp
              last edited by Danp

              @Danp I was getting error like below but right now i can delete it ? How it could happen ?

              network.delete
              {
                "network": "7d1cd2b9-15a3-6aa5-20bf-ac22e8ad362f"
              }
              {
                "code": "HA_IS_ENABLED",
                "params": [],
                "task": {
                  "uuid": "f8c23f0a-7525-c5b7-07e3-923d431acccc",
                  "name_label": "Async.VLAN.destroy",
                  "name_description": "",
                  "allowed_operations": [],
                  "current_operations": {},
                  "created": "20240521T08:40:24Z",
                  "finished": "20240521T08:40:24Z",
                  "status": "failure",
                  "resident_on": "OpaqueRef:c790d455-3678-4ae0-a02f-40a16bb0f394",
                  "progress": 1,
                  "type": "<none/>",
                  "result": "",
                  "error_info": [
                    "HA_IS_ENABLED"
                  ],
                  "other_config": {},
                  "subtask_of": "OpaqueRef:NULL",
                  "subtasks": [],
                  "backtrace": "(((process xapi)(filename ocaml/xapi/rbac.ml)(line 205))((process xapi)(filename ocaml/xapi/server_helpers.ml)(line 95)))"
                },
                "message": "HA_IS_ENABLED()",
                "name": "XapiError",
                "stack": "XapiError: HA_IS_ENABLED()
                  at Function.wrap (file:///usr/local/lib/node_modules/xo-server/node_modules/xen-api/_XapiError.mjs:16:12)
                  at default (file:///usr/local/lib/node_modules/xo-server/node_modules/xen-api/_getTaskResult.mjs:11:29)
                  at Xapi._addRecordToCache (file:///usr/local/lib/node_modules/xo-server/node_modules/xen-api/index.mjs:1029:24)
                  at file:///usr/local/lib/node_modules/xo-server/node_modules/xen-api/index.mjs:1063:14
                  at Array.forEach (<anonymous>)
                  at Xapi._processEvents (file:///usr/local/lib/node_modules/xo-server/node_modules/xen-api/index.mjs:1053:12)
                  at Xapi._watchEvents (file:///usr/local/lib/node_modules/xo-server/node_modules/xen-api/index.mjs:1226:14)"
              }
              
              DanpD 1 Reply Last reply Reply Quote 0
              • DanpD Offline
                Danp Pro Support Team @vahric 0
                last edited by

                @vahric-0 You're saying that it worked in one instance but failed in a prior attempt? Did something change in the environment in between the attempts? Was the vlan in use by any VMs?

                V 1 Reply Last reply Reply Quote 0
                • V Offline
                  vahric 0 @Danp
                  last edited by

                  @Danp No, vlans was created only for test no any vm is attached
                  XO should not say to me this is used , you can not delete it ?
                  why its generating HA_IS_ENABLED message ?

                  DanpD 1 Reply Last reply Reply Quote 0
                  • DanpD Offline
                    Danp Pro Support Team @vahric 0
                    last edited by

                    @vahric-0 Sorry, but I'm not sure that I understand your setup. Perhaps it would help if you restated the issue making sure to address the following items --

                    • Is HA enabled on your pool?
                    • Are you able to delete the VLAN using XOA web interface?
                    • Are you able to delete the VLAN using XOA API?
                    • etc
                    V 1 Reply Last reply Reply Quote 0
                    • V Offline
                      vahric 0 @Danp
                      last edited by

                      @Danp

                      HA is enabled for the pool
                      After first creation network via api , i can not deleye it from gui
                      i did not tried delete vlan via api

                      I will try to reproduce

                      V 1 Reply Last reply Reply Quote 0
                      • V Offline
                        vahric 0 @vahric 0
                        last edited by

                        yeap , i did it again 😄

                        V 1 Reply Last reply Reply Quote 0
                        • V Offline
                          vahric 0 @vahric 0
                          last edited by

                          43a695a0-89ca-4534-ac4b-48016d3c6194-image.png

                          DanpD 1 Reply Last reply Reply Quote 0
                          • DanpD Offline
                            Danp Pro Support Team @vahric 0
                            last edited by

                            @vahric-0 It is recommended to disable HA whenever you are performing maintenance (adjusting networking, applying updates, etc) on your pool.

                            V 1 Reply Last reply Reply Quote 0
                            • V Offline
                              vahric 0 @Danp
                              last edited by

                              @Danp if this is the rule , what i can say.
                              I will try one thing more because to create xostore step by step I shutdown servers and add disks after that i could delete the network

                              DanpD 1 Reply Last reply Reply Quote 0
                              • DanpD Offline
                                Danp Pro Support Team @vahric 0
                                last edited by

                                @vahric-0 I didn't understand what you were trying to say above. Are you unable to temporarily disable HA to perform maintenance?

                                V 1 Reply Last reply Reply Quote 0
                                • V Offline
                                  vahric 0 @Danp
                                  last edited by

                                  @Danp No of course i can disable it , okay i will not struggle with it
                                  After disable HA , i could delete it , thanks

                                  1 Reply Last reply Reply Quote 0
                                  • First post
                                    Last post