def add_update_tenant(tenant_id): tenant_lease = request.get_json()["vm_lease_policy"] if request.method == "POST": lease_manager.add_tenant_lease(get_context(), tenant_lease) else: lease_manager.update_tenant_lease(get_context(), tenant_lease) return jsonify({'success': True}), 200, {'ContentType': 'application/json'}
def add_update_vm_lease(tenant_id, instance_id): lease_obj = request.get_json() # ds = '2012-03-01T10:00:00Z' # or any date sting of differing formats. date = datetime.strptime(lease_obj['expiry'], DATE_FORMAT) lease_obj['expiry'] = date if request.method == "POST": lease_manager.add_instance_lease(get_context(), tenant_id, lease_obj) else: lease_manager.update_instance_lease(get_context(), tenant_id, lease_obj) return jsonify({'success': True}), 200, {'ContentType': 'application/json'}
def get_tenant(tenant_id): tenant_lease = lease_manager.get_tenant_lease(get_context(), tenant_id) if not tenant_lease: return jsonify({'success': False}), 404, { 'ContentType': 'application/json' } return jsonify(tenant_lease)
def get_tenant_and_instances(tenant_id): instances = lease_manager.get_tenant_and_associated_instance_leases( get_context(), tenant_id) if not instances: return jsonify({'success': False}), 404, { 'ContentType': 'application/json' } return jsonify(instances)
def get_vm_lease(tenant_id, instance_id): lease_info = lease_manager.get_instance_lease(get_context(), instance_id) if lease_info: return jsonify(lease_info), 200, {'ContentType': 'application/json'} else: return jsonify({'error': 'Not found'}), 404, { 'ContentType': 'application/json' }
def delete_tenant_lease(tenant_id): lease_manager.delete_tenant_lease(get_context(), tenant_id) return jsonify({'success': True}), 200, {'ContentType': 'application/json'}
def get_all_tenants(): all_tenants = lease_manager.get_tenant_leases(get_context()) if all_tenants: return jsonify({"all_tenants": all_tenants}) else: return jsonify({}), 200, {'ContentType': 'application/json'}
def get_vm_lease(tenant_id, instance_id): lease_info = lease_manager.get_instance_lease(get_context(), instance_id) if lease_info: return jsonify(lease_info), 200, {'ContentType': 'application/json'} else: return jsonify({'error': 'Not found'}), 404, {'ContentType': 'application/json'}
def get_tenant_and_instances(tenant_id): instances = lease_manager.get_tenant_and_associated_instance_leases(get_context(), tenant_id) if not instances: return jsonify({'success': False}), 404, {'ContentType': 'application/json'} return jsonify(instances)
def get_tenant(tenant_id): tenant_lease = lease_manager.get_tenant_lease(get_context(), tenant_id) if not tenant_lease: return jsonify({'success': False}), 404, {'ContentType': 'application/json'} return jsonify(tenant_lease)
def get_all_tenants(): all_tenants = lease_manager.get_tenant_leases(get_context()) if all_tenants: return jsonify({"all_tenants":all_tenants}) else: return jsonify({}), 200, {'ContentType': 'application/json'}