def main(): parser = argparse.ArgumentParser( description='Automate the creation of Vultr VPS') parser.add_argument('api_key', type=str, help='API key for Vultr') args = parser.parse_args() vultr_api_key = args.api_key vultr_client = vultr.Vultr(vultr_api_key) # Make sure we really only have one server to prevent overbilling. servers_dict = vultr_client.server.list() get_limit_running_servers(servers_dict) # Get the current ID for required instantiation variables. plans_dict = vultr_client.plans.list() os_dict = vultr_client.os.list() regions_dict = vultr_client.regions.list() ssh_keys_dict = vultr_client.sshkey.list() target_plan = get_plan(plans_dict) target_os = get_os(os_dict) target_datacenter = get_datacenter(regions_dict) target_ssh_key = get_ssh_key(ssh_keys_dict) # Create the server print("Creating server now") server = vultr_client.server.create( target_datacenter['DCID'], target_plan['VPSPLANID'], target_os['OSID'], { 'hostname': HOSTNAME, 'label': HOSTNAME, 'SSHKEYID': target_ssh_key['SSHKEYID'] }) poll_server(vultr_client)
def __fetch_from_cloud__(token, platform, default_user='******'): response = {} if 'digitalocean' in platform.lower(): import digitalocean try: [response.update({droplet.name: {"user": default_user, "host": droplet.ip_address}}) for droplet in digitalocean.Manager(token=token).get_all_droplets()] except digitalocean.baseapi.DataReadError: raise KeyError elif 'vultr' in platform.lower(): import vultr try: [response.update({vc2['label']: {"user:"******"host": vc2['main_ip']}}) for vc2 in vultr.Vultr(token).server.list().values()] except vultr.utils.VultrError: raise KeyError return response
def update_all_from_vultr(cls, instance_id: typing.Optional[int] = None ) -> None: vultr_client = vultr.Vultr(settings.VULTR_API_KEY) for tag in cls.TAGS: for new_instance_id, data in vultr_client.server.list(params=dict( tag=tag)).items(): new_instance_id = int(new_instance_id) if instance_id and instance_id != new_instance_id: continue cls.objects.update_or_create( instance_id=new_instance_id, defaults=dict( label=data['label'], os=data['os'], status=data['power_status'], ip_address=data['main_ip'], password=data['default_password'], tag=data['tag'], data=json.dumps(data), ))
# This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation, either version 3 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program. If not, see <https://www.gnu.org/licenses/>. """Main module.""" import json from pathlib import PosixPath from typing import Dict, Union import vultr from vultr import Vultr PATH_PROJECT_ROOT: object = PosixPath(__file__).parents[1] with open(PATH_PROJECT_ROOT / "data" / "Settings.json") as f: CONFIG: Dict[str, Union[str, int]] = json.load(f) with open(PATH_PROJECT_ROOT / "data" / "api_key_vultr.txt") as file: VULTR: Vultr = vultr.Vultr(file.read().strip())
from pexpect import pxssh # 벌터 초기 설정 시작 -------------------------------- # 벌터 API key 불러오기 keyFile = open('./.config', 'r') line = keyFile.readlines() API_KEY = "" for i in line: ParsedLine = i.split('=') # apikey 일 경우 vultr의 api임에 유의한다. method = ParsedLine[0] if (method == "apikey"): API_KEY = ParsedLine[1].strip() os.putenv("VULTR_KEY", API_KEY) # 환경변수 등록 #os.system("echo $VULTR_KEY") # 프로그램이 실행되지 않으면 이 라인을 확인하십시오. Vultr = vultr.Vultr(API_KEY) # 벌터 API 등록 # 벌터 초기 설정 종료 ----------------------------------- * def Create(dcid, vpslanid, osid): return Vultr.server.create(dcid, vpslanid, osid) #return "{u'SUBID': u'17910597'}" def ListAll(): # 서버 리스트가 아님에 주의하십시오. print(GetDcids()) print('\n\n') print(GetVPSPIDs()) print('\n\n') print(GetOSIDs())
import vultr a = vultr.Vultr('D3IN2WAMKMKQBUNBRGHTODHGO3GKOBYPCWBQ') a.server.list()