I have managed to undeploy a model from an endpoint using UndeployModelRequest:
model_name = f'projects/{project}/locations/{location}/models/{model_id}'
model_request = aiplatform_v1.types.GetModelRequest(name=model_name)
model_info = client_model.get_model(request=model_request)
deployed_models_info = model_info.deployed_models
deployed_model_id=model_info.deployed_models[0].deployed_model_id
undeploy_request = aiplatform_v1.types.UndeployModelRequest
(endpoint=end_point, deployed_model_id=deployed_model_id)
client.undeploy_model(request=undeploy_request)
but all this depends on knowing model_id. I want to be able to just undeploy a model from an endpoint without knowing the model's id (there will only be one model per endpoint ever). Is that possible or can I get the model id from the endpoint somehow?
You can undeploy all the models from an endpoint by calling the method
undeploy_all()(see cleaning up portion).Here you don’t need to pass the model id. This method will be more useful for you since you will be having only one model in an endpoint.Below is an example of undeploying all the models from a specific endpoint:
If you wish to undeploy all the models from all the endpoints simply remove the
ifcondition