Giter Club home page Giter Club logo

sarvdata's Introduction

Python SarvData API Client


SarvData


Installing

Clone code:

git clone https://github.com/Moein-Akbari/SarvData.git && cd SarvData

After cloning the project install python required libraries using this command:

pip install -r requirements.txt

Now you need yo get <TOKEN> from https://portal.sarvdata.com/ApiManager

Documentation https://sarvdata.com/blog/instructions-for-using-the-rest-api-web-service

Getting Started

SarvDataClient Object:

from SarvDataClient import SarvDataClient
sarv_client = SarvDataClient("<TOKEN>")

Get account information:

sarv_client.account.who_am_i()

Get VM list

virtual_machines = sarv_client.vms.vm_list() # Returns a list of <VM>s
my_vm = virtual_machines[0]

Parameters For Creating VM

Period Types Parameters could be changed, Check docs.

  • 0 for Monthly
  • 1 for Weekly
  • 2 for Daily
  • 3 for Hourly.
period_type = 3 # Hourly

Count of period.

# 2 Hours
count = 2

Location

locations = sarv_client.vms.locations()
for location in locations:
    if location["Title"] == "آمریکا | سرور های مجازی SSD":
        location_id = location["Id"]
        break

Plans

plans = sarv_client.vms.plans(location_id, period_type)
for plan in plans:
    if plan["StartupMemory"] == 2048 and plan["CpuCores"] == 2:
        plan_id = plan["Id"]
        break

Operating System (disk)

disks = sarv_client.vms.disks(location_id, period_type, plan_id)
for disk in disks:
    if disk["Title"] == "Win Server 2019 x64":
        disk_id = disk["Id"]
        break

Create a VM

  • ⚠️ THIS MAY COST YOU MONEY! ⚠️
sarv_client.vms.create(location_id, plan_id, period_type, disk_id, count)
virtual_machines = sarv_client.vms.vm_list() # Update VM list

VM Attributes

# VM ID
my_vm.identity

# VM OS
my_vm.disk_name

# VM IP Address : ipaddress.IPv4Address
my_vm.external_IP_address 

# VM Authentication Default Values
my_vm.default_username
my_vm.default_password

# VM Expire Date : datetime
my_vm.expire_moment

# VM Details
my_vm.plan_name
my_vm.startup_memory # MB
my_vm.cpu_cores
my_vm.disk_size # GB
my_vm.state

VM Methods

# shutdown
my_vm.stop()

# start
my_vm.start()

# restart
my_vm.restart()

# pause
my_vm.pause()

# save
my_vm.save()

# check status
my_vm.check()

# renew
period_type = 2 # Daily
count = 2 # 2 Days
coupon = "" # Discount code
my_vm.renew(period_type, count, coupon)
  • ⚠️ <VM>.reload Method changes os and DELETES all data on your VM. ⚠️
# change OS
disk_id = 1012 # VM OS, use disks method to get available Operating Systems.
my_vm.reload(disk_id)

More Examples

Use <VM>.get_vm_by_ip method to access your VM by IP. It returns you a object and you can use methods on it.

sarv_client = SarvDataClient("<TOKEN>")
backup_server = sarv_client.vms.get_vm_by_ip("142.251.36.46")
print(
f"""
    BACKUP Server \ {backup_server.disk_name}
    ID : {backup_server.identity}
    CPU Cores : {backup_server.cpu_cores}
    MEMORY : {backup_server.startup_memory}
    STATE : {backup_server.state}
""")

Output

BACKUP Server \ Win Server 2019 x64
ID : 10796
CPU Cores : 2
MEMORY : 2048
STATE : Installed

sarvdata's People

Contributors

moein-akbari avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.