본문 바로가기
망각을위한노트

Python Script for creating Oracle Cloud Ampere free Instance, 오라클 클라우드 무료인스턴스 자동생성 스크립트

by RNE21 2023. 1. 15.
반응형

Oracle Cloud provides A1 Ampere instance up to 4 cores and 24G memory for free.
You can create 2 Core x 2 instances, or 1 Core x 4 instances.
Alternatively, 4 Core x 1 instance can be created.

 

In most regions, the free instance quota has already been exhausted, so it is not possible to allocate a free instance only by clicking the mouse.

 

The script below is publicly available on the Internet, so anyone can use it.


클라우드 CSP 업체들 중에서 '완전 무료 instance'를 제공하는 업체로는, 구글 GCP와 오라클 클라우드 OCI가 있습니다.
이 중에서, 오늘 이야기하려는 클라우드 인스턴스는 오라클 클라우드 A1 Ampere 입니다.

 

오라클은 A1 Ampere 인스턴스를 무료로 제공하고 있는데, 사양이 예사롭지 않습니다. CPU 코어는 최대 4 core, 메모리는 최대 24G를 무료로 제공하고 있죠.

 

예사롭지 않은 혜자로움 때문에 많은 사람들이 몰려들었고, 이미 대부분의 region에서 무료 instance 할당량이 소진되었습니다.
이제는, 마우스 클릭으로는 무료 인스턴스를 할당받을 수가 없게 되었죠.

 

So,
부지런한 누군가가 '24시간 내내 instance 할당 요청을 하도록' 만든, script를 짰습니다. 아래 스크립트는 인터넷에 공개된 것이니, 누구든지 고쳐 사용해도 됩니다. 제가 약간 수정한 부분도 있고요.


Reference(original text)

이 스크립트는 다음의 URL에서 가져왔습니다.

https://luckfu.com/en/post/ampere_a1_free/


Steps

  1. Download oci tools
  2. Get OCID values
  3. install python38, python3-pip
  4. oci setup
  5. download and modify the script
  6. run the script

Step 1. Download oci tools

1st, you need root privilege. so, run below 'sudo su -' command.

sudo su -

and, download oci tools.

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

Step 2. Get OCID values

2.1 Get User OCID (from OCI web management page)

oracle cloud web UI > Go to Profile > My Profile > click user OCID COPY link > note

2.2 Get Tenency OCID (from OCI web management page)

oracle cloud web UI > Go to Profile > Tenency: xxxxx > click tenency OCID COPY link > note


Step 3. install python38, python3-pip

dnf install python38
dnf install python3-pip
pip3 install oci

Step 4. oci setup

oci setup config

아래 # select you registed region 부분에서, 원하는 region 번호를 입력하면 된다. 만약 ap-chuncheon-1 에 생성하려면, region 번호는 2번이다.

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): 2  # select you registed 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
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

Step 5. Register api key into 'Oracle api key management UI'

5.1 display your api key

반응형
cat /root/.oci/oci_api_key_public.pem

Copy displayed key

5.2 add api key into OCI UI

goto OCI web UI > Identity&Security > Domains > Default Domains > Users > select user ID > API Keys Key > Add API Key > select 'Paste a public key' radio button > paste your displayed key here > click 'Close' button


Step 6. download and modify the script

6.1 download the script

wget https://luckfu.com/post/ampere_a1_free/luanch.py

6.2 get your ssh public key

cat ~/.ssh/id_rsa.pub

or

cat ~/.ssh/authorized_keys

6.3 modify the script

INSTANCE_NAME = 'instance name for A1' 
#If you are a new user, create a VCN and Subnet first

SUBNET_ID = "paste subnet OCID here, Networking > Virtual Cloud Networks > Virtual Cloud Network Details > Subnets > select your subnet > "subnet's OCID" //not VCN OCID!
compartment_id= "paste tenancy OCID here"
ssh_public_key="paste contents of id_rsa.pub or authorized_keys here"

Step 7. run the script

python3 luanch.py

Appendix

A1. Troubleshooting

If you get "400 VFIO network is not supported by instance shape" error, you need to set additional options.
The oracle Ampere A1 does not support SR-IOV(Single Root I/O Virtualization) yet.

So, modify your script.
Create LaunchOptions and add to launch_instance_details
like this..

A1.1 Create new LaunchOptions object

    launchOptions = oci.core.models.LaunchOptions (
        boot_volume_type="PARAVIRTUALIZED",
        network_type="PARAVIRTUALIZED"
    )

A1.2 add LaunchOptions object to launch_instance_details

    launch_instance_details = oci.core.models.LaunchInstanceDetails(
        display_name=instance_name,
        compartment_id=compartment_id,
        availability_domain=availability_domain.name,
        shape=shape.shape,
        metadata=instance_metadata,
        #extended_metadata=instance_extended_metadata,
        source_details=instance_source_via_image_details,
        create_vnic_details=create_vnic_details,
        launch_options=launchOptions
    )

EOF

반응형