import random
import subprocess
import time
import json
from collections import namedtuple
from configparser import NoOptionError
from os.path import expanduser, isfile
from pprint import pformat

try:
    from http.client import NOT_FOUND, UNPROCESSABLE_ENTITY
except ImportError:
    from httplib import NOT_FOUND, UNPROCESSABLE_ENTITY

from requests import Session as _Session
from requests.adapters import HTTPAdapter

from vpsutil.config import Providers, config
from vpsutil.logger import logger


_PowerState = namedtuple("PowerStates", ("ON", "OFF", "RESET"))
PowerState = _PowerState(ON="on", OFF="off", RESET="reset")


class Base(_Session):
    URL = "https://api.digitalocean.com/v2"

    def __init__(self):
        super(Base, self).__init__()
        self.mount("https://", HTTPAdapter(max_retries=5))