409 Client Error: Conflict for url while using deploy post method MAAS/api/2.0/machines/fbedpre/op-deploy

if operation_type == ‘deploy’:
system_id = request.POST.get(‘system_id’)
if not system_id:
return JsonResponse({‘error’: ‘System ID is required for deployment.’}, status=400)

        # Prepare parameters for the deploy operation
        params = {
            'agent_name': request.POST.get('agent_name', ''),
            'bridge_all': request.POST.get('bridge_all', 'false').lower() == 'true',
            'bridge_fd': int(request.POST.get('bridge_fd', '15')),
            'bridge_stp': request.POST.get('bridge_stp', 'false').lower() == 'true',
            'bridge_type': request.POST.get('bridge_type', 'standard'),
            'comment': request.POST.get('comment', ''),
            'distro_series': request.POST.get('distro_series', ''),
            'enable_hw_sync': request.POST.get('enable_hw_sync', 'false').lower() == 'true',
            'ephemeral_deploy': request.POST.get('ephemeral_deploy', 'false').lower() == 'true',
            'hwe_kernel': request.POST.get('hwe_kernel', ''),
            'install_kvm': request.POST.get('install_kvm', 'false').lower() == 'true',
            'install_rackd': request.POST.get('install_rackd', 'false').lower() == 'true',
            'register_vmhost': request.POST.get('register_vmhost', 'false').lower() == 'true',
            'user_data': request.POST.get('user_data', ''),
            'vcenter_registration': request.POST.get('vcenter_registration', 'true').lower() == 'true'
        }
        maas_api_url = f"{settings.MAAS_API_URL}/machines/{system_id}/op-deploy"
        
        # Create an OAuth1 session
        maas = OAuth1Session(
            consumer_key,
            resource_owner_key=consumer_token,
            resource_owner_secret=secret,
            signature_method=SIGNATURE_PLAINTEXT
        )
        
        try:
            # Make the request to the MAAS API with OAuth1
            response = maas.post(maas_api_url, data=params)
            print(response,'response')
            response.raise_for_status()
            return JsonResponse(response.json())
        except requests.RequestException as e:
            logger.error(f'Request exception: {e}')
            return JsonResponse({'error': str(e)}, status=500)
        except Exception as e:
            logger.error(f'Unexpected error: {e}')
            return JsonResponse({'error': 'An unexpected error occurred.'}, status=500)

I am currently encountering a 409 Conflict error when attempting to deploy a machine using the MAAS API. I would appreciate your guidance on identifying and resolving the issue.

You are probably making multiple concurrent requests on the same machine. This is why you get 409 back

When i add machine using rest api it shows only status as new, same mac id which i used to create mass web ui show commissioning after ready , so no clue about this if anything i missed to add fields please guide me
this is my payload :

hostname: maas
domain: maas
architecture: amd64/generic
min_hwe_kernel:
zone: default
pool: default
mac_addresses: 5C-60-BA-D8-0F-48
power_type: manual

response


from maas

  1. architecture: “amd64/generic”
  2. domain: {name: “maas”, authoritative: true, ttl: null, id: 0, is_default: true, resource_record_count: 0}
  3. fqdn: “maas.maas”
  4. hostname: “maas”
  5. node_type: 0
  6. power_state: “unknown”
  7. power_type: “manual”
  8. resource_uri: “/MAAS/api/2.0/machines/f7hppd/”
  9. status: 0
  10. status_action: null
  11. status_message: null
  12. status_name: “New”
  13. system_id: “f7hppd”
  14. zone: {name: “default”, description: “”, id: 1}

You have to commission it

like this right ?
data[‘commission’] = ‘true’

using the POST /MAAS/api/2.0/machines/{system_id}/op-commission endpoint. See https://maas.io/docs/api

{
“error”: “404 Client Error: Not Found for url: http://ip/MAAS/api/2.0/machines/hmhscr8/op-commission/
}
machine_uri = response_data.get(‘resource_uri’)
print(machine_uri,‘machine_uri’)
if not machine_uri:
raise ValueError(‘No resource_uri found in response’)

            # Extract system_id from the resource_uri
            system_id = machine_uri.strip('/').split('/')[-1]
            
            # Commission the machine
            commission_url = f'{maas_api_url}{system_id}/op-commission/'
              # Optional parameters for commissioning

            commissioning_params = {

                'commissioning_scripts': 'update_firmware,configure_hba',

                'enable_ssh': 1,

                'skip_bmc_config': 0,

                'skip_networking': 0,

                'skip_storage': 0,

                'testing_scripts': 'none'

            }
            



            # Initialize OAuth1 session

            maas = OAuth1Session(

                consumer_key,

                resource_owner_key=consumer_token,

                resource_owner_secret=secret,

                signature_method='PLAINTEXT'

            )
            headerss = {'Content-Type': 'application/json'}
            commission_response = maas.post(commission_url, json=commissioning_params, headers=headerss)
            print(commission_response,'commission_response')

            commission_response.raise_for_status()

             

              # Return the response from commissioning

            return JsonResponse(commission_response.json())
        
        except requests.RequestException as e:
            logger.error(f'Request exception: {e}')
            return JsonResponse({'error': str(e)}, status=500)

after add machine i get the machine_uri
then used to hit this commission_url = f’{maas_api_url}{system_id}/op-commission/’
but i got this error {
“error”: “404 Client Error: Not Found for url: http://ip/MAAS/api/2.0/machines/hmhscr8/op-commission/
}
404

the endpoint is /op-commission, not /op-commission/

maas.js:1075 Error: Error: Network response was not ok: {“error”: “400 Client Error: Bad Request for url: http://ip/MAAS/api/2.0/machines/mqnfdy/op-commission”}
at HTMLFormElement. (maas.js:1064:27)

try:
# Make the request to the MAAS API to add the machine
response = requests.post(maas_api_url, data=data, headers=headers)
response.raise_for_status()

            # Get the machine resource URI from the response
            response_data = response.json()
            print(response_data, 'response_data')
            machine_uri = response_data.get('resource_uri')
            print(machine_uri, 'machine_uri')
            if not machine_uri:
                raise ValueError('No resource_uri found in response')
            
            # Extract system_id from the resource_uri
            system_id = machine_uri.strip('/').split('/')[-1]
            
            # Commission the machine
            commission_url = f"{settings.MAAS_API_URL}/machines/{system_id}/op-commission"
            
            # Initialize OAuth1 session
            maas = OAuth1Session(
                consumer_key,
                resource_owner_key=consumer_token,
                resource_owner_secret=secret,
                signature_method='PLAINTEXT'
            )

            # Optional commissioning parameters
            commissioning_params = {
                'commissioning_scripts': 'update_firmware,configure_hba',
                'enable_ssh': 1,
                'skip_bmc_config': 0,
                'skip_networking': 0,
                'skip_storage': 0,
                'testing_scripts': 'none'
            }
            
            # Make the POST request to commission the machine
            commission_response = maas.post(commission_url, data=commissioning_params, headers=headers)
            print(commission_response, 'commission_response')

            commission_response.raise_for_status()
            
            # Return the response from commissioning
            return JsonResponse(commission_response.json())

        except requests.RequestException as e:
            logger.error(f'Request exception: {e}')
            if e.response:
                logger.error(f'Response content: {e.response.content}')
            return JsonResponse({'error': str(e)}, status=500)

i have no clue kindly please help me

sorry atm I don’t have much time to review your snippet. An example with curl is

curl  -X POST --header "Authorization: OAuth oauth_version=1.0, oauth_signature_method=PLAINTEXT, oauth_consumer_key=w2Ubk7Dc67XurxtpZf, oauth_token=sx6ut9CBZMKdN3qrfz, oauth_signature=&fvgKG5Kfz6rPB5MUfBsmTbMtSX9gYjrD, oauth_nonce=$(uuidgen), oauth_timestamp=$(date +%s)" http://localhost:5240/MAAS/api/2.0/machines/wnrcp4/op-commission

you can then adapt it to your python script, after having adjusted the api keys and the system id of the machine you want to commission

Authorization Error: ‘Invalid signature. Expected signature base string: &NCYg8FKxeKfEpgFkaweBe8cWkawg5D8z’

Failed to add machine: Network response was not ok: {“error”: "400 Client Error: Bad Request for url: http://ip/MAAS/api/2.0/machines/yg6fee/op-commission"}

If you modify the curl command above with your data, does it work?

now is commissionig but still nor ready
commissioning_params = {
‘commissioning_scripts’: ‘update_firmware,configure_hba’,
‘enable_ssh’: 1,
‘skip_bmc_config’: 0,
‘skip_networking’: 0,
‘skip_storage’: 0,
‘testing_scripts’: ‘none’
}
headerss = {‘Content-Type’: ‘application/json’}
print(‘commissioning_params’,commissioning_params)
# Make the POST request to commission the machine
commission_response = maas.post(commission_url, params=commissioning_params)
this thing i do for commissioning

well the power driver for that machine is “Manual” which means you have to start it manually. Also you have to ensure you have enabled DHCP on that subnet and that you do not have any other DHCP server on the network. Also, your machine should have PXE as first boot entry

Also, I’d suggest you make everything working with the UI and then you can write some scripts to interact with the API.

I need to make some code changes or set up some network configuration, I need more details on this

https://maas.io/docs

We are adding machine commissioning perfectly using Maas ui but I am using my web ui to connect to Maas and that time only is still commisioning pending

Did you power on the machine?