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.