Manage Pro sites programmatically

Let say I want to change the level or extend a pro site, I can manually do it in "Manage Sites", by clicking the Extend button.

Is it possible to automated that by coding? I notice there is an extend() function in pro-sites.php but not sure how to call it from outside.