Created
March 28, 2020 11:03
-
-
Save HauptJ/57e2d1ce2dfbb80a836894d32f06da86 to your computer and use it in GitHub Desktop.
OVH API Re-Imaging Script
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python3 | |
import ovh | |
import json | |
import argparse | |
def reimage(ovhClient, ovhServerName, sshKeyName, hostName, ovhTemplateName, useDistribKernel=False): | |
result = ovhClient.post( | |
'/dedicated/server/'+ ovhServerName + '/install/start', | |
details={ | |
"noRaid":False, | |
"sshKeyName":sshKeyName, | |
"language":"en", | |
"useSpla":False, | |
"diskGroupId": 1, | |
"resetHwRaid":False, | |
"customHostname":hostName, | |
"installSqlServer":False, | |
"useDistribKernel":useDistribKernel | |
}, | |
templateName=ovhTemplateName, | |
) | |
return result | |
def printResult(result): | |
print(json.dumps(result, indent=4)) | |
def client(): | |
# create a client instance using configuration in ovh.conf | |
ovhClient = ovh.Client() | |
return ovhClient | |
def main(argv): | |
option = '' | |
ovhServerName = '' | |
sshKeyName = '' | |
sshKeyName = '' | |
hostName = '' | |
ovhTemplateName = '' | |
useDistribKernel = 'true' | |
parser = argparse.ArgumentParser() | |
parser.add_argument() | |
# Function return output | |
ovhClient = client() | |
if(option == "reinstall"): | |
result = reimage(ovhClient, ovhServerName, sshKeyName, hostName, ovhTemplateName, useDistribKernel) | |
printResult(result) | |
else: | |
print("Invalid option paramater passed in.") | |
if __name__== "__main__": | |
main(sys.argv[1:]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment