XCP-ng
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Register
    • Login
    1. Home
    2. Studmuffn1134
    S
    Offline
    • Profile
    • Following 0
    • Followers 0
    • Topics 3
    • Posts 21
    • Groups 0

    Studmuffn1134

    @Studmuffn1134

    0
    Reputation
    4
    Profile views
    21
    Posts
    0
    Followers
    0
    Following
    Joined
    Last Online

    Studmuffn1134 Unfollow Follow

    Latest posts made by Studmuffn1134

    • RE: Python help

      @Studmuffn1134 I changed my link from ws:// to https:// and it now gives me this error File "Z:\Valera\School\Lakeland University\Finished\Programming 2\Python Programs\StudsPrograms.venv\Lib\site-packages\jsonrpc_base\jsonrpc.py", line 213, in parse_response
      raise ProtocolError(code, message, data)
      jsonrpc_base.jsonrpc.ProtocolError: (10, 'invalid parameters', {'error': {'message': 'invalid parameters', 'code': 10, 'data': {'errors': [{'instancePath': '/id', 'schemaPath': '#/properties/id/type', 'keyword': 'type', 'params': {'type': 'string'}, 'message': 'must be string'}]}}, 'id': '0a11ec72-9300-4030-a5d2-a5c0286f3811', 'jsonrpc': '2.0'})

      posted in REST API
      S
      Studmuffn1134
    • RE: Python help

      @Gurve '''def shutdown_vm_hosts(host_id,xo_url,auth_token,use_force):

      async def routine():
          async with aiohttp.ClientSession() as client:
              server = Server('ws://192.168.100.30:2223/api/', client)
              await server.ws_connect()
              # signIn required
              result = await server.session.signIn(username='ThePlague', password='No') # email attribute is working in place of username
              hostUUID ="d2f1374c-728d-4905-85cc-e0d7166a3fbf"
              #hard shutdown VM
              #result = await server.vm.stop(id='3f32beeb-ab3f-a8ac-087d-fdc7ed061b58', force=(bool(1)))
              #clean Shutdown VM
              #result = await server.vm.stop(id='3f32beeb-ab3f-a8ac-087d-fdc7ed061b58', force=(bool(0)))
              #bypassbackup and bypassevacuate set off by default but include for wholeness of parameters
              result = await server.host.stop(id=[hostUUID],bypassBackupCheck=(bool(0)),bypassEvacuate=bool(0))
              print (result)''' Traceback (most recent call last):
              
                File "z:\Valera\School\Lakeland University\Finished\Programming 2\Python Programs\StudsPrograms\Shutdowntest.py", line 72, in <module>
              
                  main() # second part of calling the main function
              
                  ~~~~^^
              
                File "z:\Valera\School\Lakeland University\Finished\Programming 2\Python Programs\StudsPrograms\Shutdowntest.py", line 70, in main
              
                  shutdown_vm_hosts(l,XO_URL,AUTH_TOKEN,use_force=False)
              
                  ~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
              
                File "z:\Valera\School\Lakeland University\Finished\Programming 2\Python Programs\StudsPrograms\Shutdowntest.py", line 29, in shutdown_vm_hosts
              
                  asyncio.get_event_loop().run_until_complete(routine())
              
                  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^
              
                File "C:\Users\ThePlague\AppData\Local\Programs\Python\Python313\Lib\asyncio\base_events.py", line 725, in run_until_complete
              
                  return future.result()
              
                         ~~~~~~~~~~~~~^^
              
                File "z:\Valera\School\Lakeland University\Finished\Programming 2\Python Programs\StudsPrograms\Shutdowntest.py", line 13, in routine
              
                  await server.ws_connect()
              
                File "Z:\Valera\School\Lakeland University\Finished\Programming 2\Python Programs\StudsPrograms\.venv\Lib\site-packages\jsonrpc_websocket\jsonrpc.py", line 68, in ws_connect
              
                  raise TransportError('Error connecting to server', None, exc)
              
              jsonrpc_base.jsonrpc.TransportError: ('Error connecting to server', ServerDisconnectedError('Server disconnected'))
      

      I tried that and that is the error code I get

      posted in REST API
      S
      Studmuffn1134
    • RE: Python help

      @Gurve Do i have to enable the xo-cli?

      posted in REST API
      S
      Studmuffn1134
    • RE: Python help

      @Gurve Is this for the vm's on the server or the host itself i need the host itself

      posted in REST API
      S
      Studmuffn1134
    • RE: Python help

      @TheNorthernLight Well could you do it in a language you know and maybe i would be able to convert it>?

      posted in REST API
      S
      Studmuffn1134
    • RE: Python help

      @TheNorthernLight Finally someone gets the reference But what do u think I am doing wrong

      posted in REST API
      S
      Studmuffn1134
    • RE: Python help

      @Studmuffn1134 That is what i did and it still does not work I get a status code 200 but it never shuts the host off

      posted in REST API
      S
      Studmuffn1134
    • RE: Python help

      @Butcat def shutdown_vm_hosts(host_id,xo_url,auth_token,use_force):
      root_dir = os.path.dirname(os.path.abspath(file))
      file_path = os.path.join((root_dir),"Certs\fullchain.pem")

      headers = {
          'Content-Type':'application/json',
          'Authorization':f'Bearer {auth_token}'
      }
      data = {
          "jsonrpc":"2.0",
          "method":"host.shutdown",
          "params":[host_id],
          "id":1
      }
      try:
          response = requests.post(
              xo_url,
              headers=headers,data=json.dumps(data),
              verify=file_path
          )
          print(f"Status code: {response.status_code}")
          
          if response.status_code in [200, 202, 204]:
              print(f"✓ Successfully initiated {'force' if use_force else 'clean'} shutdown")
              return True
          else:
              print(f"Error: {response.text}")
              return False
      except requests.exceptions.RequestException as e:
          print(f"Request failed: {e}")
          return False
      
      posted in REST API
      S
      Studmuffn1134
    • RE: Python help

      @Butcat This was very very very helpful. https://192.168.100.30:2223/rest/v0/host/d2f1374c-728d-4905-85cc-e0d7166a3fbf/actions is there no way to turn off a single host through the api. The interesting part is I have no actions in the host section with that host id?

      posted in REST API
      S
      Studmuffn1134
    • RE: Python help

      @Studmuffn1134 said in Python help:

      Reply

      Is it the same code for the hosts or do I have to use different api links for host actions can you help me with that?

      posted in REST API
      S
      Studmuffn1134