English
luckfu's notes.

Never forget your dreams!


  • Home

  • Archive

  • About

  • Page404

  • Search

Use python scripts to preemptively create Oracle VM.Standard.A1.Flex

Published at: 2021/05/11   |   Categories: cloud vps   python   oci   | Words: 605 words | Reading: 3 minutes | Visited:

Oracle cloud open registered account can apply for 4c24g free cloud server, database and other services, 1c1g x86 server is easier to apply, but the popular 4c24g Ampere A1 type of host under normal circumstances can not apply through the web, currently popular on the Internet Cybersquatting methods are nothing more than two modes:

  • Browser plug-ins or scripts or button wizards. The problem with this method is that the console is timed out. It is also easy to be judged by the server as illegal operations. Accounts are disabled. It is obviously not suitable for operations that require stable operation for several days.
  • Call the oci command script, this is the safest mode, because oci is officially provided by oracle, the principle is to use the oci command to directly apply for an instance, for example:
oci compute instance launch ....

However, according to my Hong Kong host test, this can only be refreshed every 20 seconds at most, because the complete process of the oci command execution:

  • 1、start to connect to oracle cloud
  • 2、Verify user legitimacy
  • 3、Excuting an command
  • 4、exit

Steps 1, 2, and 4 waste a lot of time in the loop. In this article, we use python to call the oci api , omit multiple verification , and execute the create instance command in loop. The refresh speed can reach 3 seconds/time. When the instance creation is successful, return ,Automatic withdrawal.

Deployment steps

1、Download oci tools

bash -c "$(curl –L https://raw.githubusercontent.com/oracle/oci-cli/master/scripts/install/install.sh)"

By default, press Enter. After the installation is complete, execute the following command to check whether it is successful

oci -v

2、Configure oci

On the oracle cloud console, click on the avatar in the upper right corner => select “User Settings” in the menu to copy the user and tenancy OCID

execute

oci setup config

Fill in the correct user and tenancy id

Enter a location for your config [/root/.oci/config]: 
Enter a user OCID: #your user ocid
Enter a tenancy OCID: #your tenancy ocid
Enter a region by index or name(e.g.
1: ap-chiyoda-1, 2: ap-chuncheon-1, 3: ap-hyderabad-1, 4: ap-melbourne-1, 5: ap-mumbai-1,
6: ap-osaka-1, 7: ap-seoul-1, 8: ap-sydney-1, 9: ap-tokyo-1, 10: ca-montreal-1,
11: ca-toronto-1, 12: eu-amsterdam-1, 13: eu-frankfurt-1, 14: eu-zurich-1, 15: me-dubai-1,
16: me-jeddah-1, 17: sa-santiago-1, 18: sa-saopaulo-1, 19: uk-cardiff-1, 20: uk-gov-cardiff-1,
21: uk-gov-london-1, 22: uk-london-1, 23: us-ashburn-1, 24: us-gov-ashburn-1, 25: us-gov-chicago-1,
26: us-gov-phoenix-1, 27: us-langley-1, 28: us-luke-1, 29: us-phoenix-1, 30: us-sanjose-1): 9  # select you regist region
Do you want to generate a new API Signing RSA key pair? (If you decline you will be asked to supply the path to an existing key.) [Y/n]: y  #y
Enter a directory for your keys to be created [/root/.oci]: 
Enter a name for your key [oci_api_key]: 
Public key written to: /root/.oci/oci_api_key_public.pem
Enter a passphrase for your private key (empty for no passphrase): 
Private key written to: /root/.oci/oci_api_key.pem
Fingerprint: 
Config written to /root/.oci/config
...

Copy the generated public key and get the command as follows:

cat /root/.oci/oci_api_key_public.pem

Copy the displayed content. And add it to Identity=>Users=>User Details=>API Keys Key»Add API Keys

3、python programe

Install python oci

Assuming you have installed the python environment

pip install oci

Login public certificate

  • Create a new or use the existing certificate of the system, this article directly check the existing certificate of this machine and record it
cat ~/.ssh/id_rsa.pub
ssh-rsa AAAAB3NzaC1yc2EAAA......local

Modify script

download:

  • link
  • Modify the parameters in the luanch.py ​​script
INSTANCE_NAME = 'apply instance name' 
#If you are a new user, create a VCN first
SUBNET_ID = "Networking=>Virtual Cloud Networks=>Virtual Cloud Network Details OCID" 
compartment_id= "tenancy OCID"
ssh_public_key="Contents of id_rsa.pub"

run script

Execute the script, when the instance apply completed, it will automatically exit

python ./luanch.py
#Oracle Cloud# #Free VPS# #python script# #Automation script # #VM.Standard.A1.Flex#

Declaration:Use python scripts to preemptively create Oracle VM.Standard.A1.Flex

Link:http://www.luckfu.com/en/post/ampere_a1_free/

Author:luckfu

Declaration: This blog post article is under the CC BY-NC-SA 3.0 license,Please indicate the source!

If it can help you, you can give tips for blogger that how much you want. ^_^
WeChat Pay

Wechat Pay

Alipay

Ali Pay

paypal Pay

PayPal

Use the docker container as a virtual machine
  • Table of Content
  • Site Information
luckfu

luckfu

In a flash, all of the past away from you, the rest of the only memories.

5 Blogs
11 Categories
14 Tags
GitHub
TagCloud
  • Oracle cloud
  • Free vps
  • Vm.standard.a1.flex
  • Automation script
  • Bluetooth pan
  • Docker
  • Financials
  • Macos
  • Metabase
  • Monterey
  • 1、Download oci tools
  • 2、Configure oci
  • 3、python programe
    • Install python oci
    • Login public certificate
    • Modify script
    • run script
© 2010 - 2025 luckfu's notes.
Powered by - Hugo v0.127.0 / Theme by - NexT
0%