Skip to content

Instantly share code, notes, and snippets.

@bluesid
Last active February 18, 2024 03:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bluesid/3cdfa59dff4444f41d950576e5b10d42 to your computer and use it in GitHub Desktop.
Save bluesid/3cdfa59dff4444f41d950576e5b10d42 to your computer and use it in GitHub Desktop.
#오라클 #프리티어 #oracle #freetier #oci
# inspired by https://github.com/jaehwan1912/oci_instance_creation_script
import requests
from oci.signer import Signer
import time
from datetime import datetime
endpoint = 'https://iaas.<region>.oraclecloud.com/20160918/instances/'
auth = Signer(
tenancy="ocid1.tenancy.oc1..<tenancy>",
user="ocid1.user.oc1..<user>",
fingerprint="<fingerprint>",
private_key_file_location="<private_key_file_location>.pem"
)
def listit():
# body
body = {
"compartmentId":"ocid1.tenancy.oc1..<compartmentId>"
}
# request 보내기, 해당 API는 get method를 요구합니다.
response = requests.get(endpoint, params=body, auth=auth)
# 대충 instance 갯수가 0인 compartment에 만들고 길이로 판별하겠습니다.
return len(response.json())
def makeit():
# body
body = {
"metadata": {
"ssh_authorized_keys": "<ssh-rsa key>"
},
"shape": "VM.Standard.A1.Flex",
"compartmentId": "ocid1.tenancy.oc1..<compartmentId>",
"displayName": "<displayName>",
"availabilityDomain": "YbKK:<availabilityDomain>-AD-1",
"sourceDetails": {
"sourceType": "image",
"imageId": "ocid1.image.oc1.<region>.<imageId>",
"bootVolumeSizeInGBs": 200
},
"isPvEncryptionInTransitEnabled": 1,
"createVnicDetails": {
"assignPublicIp": 0,
"subnetId": "ocid1.subnet.oc1.<region>.<subnetId>",
"assignPrivateDnsRecord": 1
},
"agentConfig": {
"pluginsConfig": [
{
"name": "Vulnerability Scanning",
"desiredState": "DISABLED"
},
{
"name": "Oracle Java Management Service",
"desiredState": "DISABLED"
},
{
"name": "Oracle Autonomous Linux",
"desiredState": "DISABLED"
},
{
"name": "OS Management Service Agent",
"desiredState": "ENABLED"
},
{
"name": "Compute Instance Run Command",
"desiredState": "ENABLED"
},
{
"name": "Compute Instance Monitoring",
"desiredState": "ENABLED"
},
{
"name": "Block Volume Management",
"desiredState": "DISABLED"
},
{
"name": "Bastion",
"desiredState": "DISABLED"
}
],
"isMonitoringDisabled": 0,
"isManagementDisabled": 0
},
"definedTags": {},
"freeformTags": {},
"instanceOptions": {
"areLegacyImdsEndpointsDisabled": 0
},
"availabilityConfig": {
"recoveryAction": "RESTORE_INSTANCE"
},
"shapeConfig": {
"ocpus": 4,
"memoryInGBs": 24
}
}
# request 보내기, 해당 API는 post method를 요구합니다.
return requests.post(endpoint, json=body, auth=auth)
if __name__=='__main__':
print(listit())
# print(datetime.now())
error_msg = "Out of host capacity."
run = 1
while(run):
res = makeit()
if res.status_code == 500:
if error_msg == res.json()["message"]:
print(datetime.now(), error_msg)
time.sleep(60)
else:
print(res.json())
run = 0
else:
print(res.json())
run = 0
# 실행 화면
# instance 갯수 표시
# 0
# 시간, 실페 메시지
# 2022-07-23 13:00:46.407151 Out of host capacity.
# ...
# 성공 메세지, 보냈던 데이터가 거의 그대로 다시 확인됨
# {'availabilityDomain': 'YbKK:<availabilityDomain>-AD-1', 'capacityReservationId': None, 'compartmentId': 'ocid1.tenancy.oc1..<tenancy>', 'dedicatedVmHostId': None, 'definedTags': {'Oracle-Tags': {'CreatedBy': 'default/<account>', 'CreatedOn': '2022-07-23T14:41:31.549Z'}}, 'displayName': '<displayName>', 'extendedMetadata': {}, 'faultDomain': 'FAULT-DOMAIN-1', 'freeformTags': {}, 'id': 'ocid1.instance.oc1.<region>.<instance_id>', 'imageId': 'ocid1.image.oc1.<region>.<imageId>', 'ipxeScript': None, 'launchMode': 'PARAVIRTUALIZED', 'launchOptions': {'bootVolumeType': 'PARAVIRTUALIZED', 'firmware': 'UEFI_64', 'networkType': 'PARAVIRTUALIZED', 'remoteDataVolumeType': 'PARAVIRTUALIZED', 'isPvEncryptionInTransitEnabled': True, 'isConsistentVolumeNamingEnabled': True}, 'instanceOptions': {'areLegacyImdsEndpointsDisabled': False}, 'availabilityConfig': {'isLiveMigrationPreferred': None, 'recoveryAction': 'RESTORE_INSTANCE'}, 'preemptibleInstanceConfig': None, 'lifecycleState': 'PROVISIONING', 'metadata': {'ssh_authorized_keys': '<ssh-rsa key>'}, 'region': '<region>', 'shape': 'VM.Standard.A1.Flex', 'shapeConfig': {'ocpus': 4.0, 'memoryInGBs': 24.0, 'baselineOcpuUtilization': None, 'processorDescription': '3.0 GHz Ampere® Altra™', 'networkingBandwidthInGbps': 4.0, 'maxVnicAttachments': 4, 'gpus': 0, 'gpuDescription': None, 'localDisks': 0, 'localDisksTotalSizeInGBs': None, 'localDiskDescription': None}, 'sourceDetails': {'sourceType': 'image', 'bootVolumeSizeInGBs': None, 'imageId': 'ocid1.image.oc1.<region>.<imageId>', 'kmsKeyId': None, 'bootVolumeVpusPerGB': None}, 'systemTags': {}, 'timeCreated': '2022-07-23T14:41:32.080Z', 'agentConfig': {'isMonitoringDisabled': False, 'isManagementDisabled': False, 'areAllPluginsDisabled': False, 'pluginsConfig': [{'name': 'Vulnerability Scanning', 'desiredState': 'DISABLED'}, {'name': 'Oracle Java Management Service', 'desiredState': 'DISABLED'}, {'name': 'Oracle Autonomous Linux', 'desiredState': 'DISABLED'}, {'name': 'OS Management Service Agent', 'desiredState': 'ENABLED'}, {'name': 'Compute Instance Run Command', 'desiredState': 'ENABLED'}, {'name': 'Compute Instance Monitoring', 'desiredState': 'ENABLED'}, {'name': 'Block Volume Management', 'desiredState': 'DISABLED'}, {'name': 'Bastion', 'desiredState': 'DISABLED'}]}, 'timeMaintenanceRebootDue': None, 'timeStopScheduled': None, 'preferredMaintenanceAction': None, 'platformConfig': None}
# 접속
$ ssh -i {ssh-key-filename}.key ubuntu@{SERVER_IP}
# ex) ssh -i ssh-key-2022-07-01.key ubuntu@192.168.0.1
# 타임존 서울로 변경
$ sudo timedatectl set-timezone Asia/Seoul
# 타임존 확인
$ date
# docker 스크립트 다운 및 설치
$ curl -fsSL https://get.docker.com -o get-docker.sh
$ bash get-docker.sh
# docker status 실행 확인
$ service docker status
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment