def stop_vpn_server(): try: client = hcloud.Client(HETZNER_APIKEY) client.servers.get_by_id(VPN_SERVER_ID).shutdown() return True except: return False
def _build_client(self): self.client = hcloud.Client( token=self.module.params["api_token"], api_endpoint=self.module.params["endpoint"], application_name="ansible-module", application_version=__version__, )
def cli(self): """ Access the Hetzner Cloud CLIent API """ if self.__cli: return self.__cli if len(self.conf.token) != 64: OOPS('no token', len(self.conf['token'])) self.__cli = hcloud.Client(self.conf.token, application_name=self.__APPNAME, application_version=self.__APPVERS, poll_interval=self.__poll) assert self.__cli return self.__cli
def __init__( self, cluster: str, config, env_vars: dict = None, bootstrap=None, docker_image: str = None, image: str = None, location: str = None, server_type: str = None, *args, **kwargs, ): super().__init__(*args, **kwargs) self.cluster = cluster self.config = config self.location = location self.bootstrap = bootstrap self.env_vars = env_vars self.client = hcloud.Client(self.config.get("token")) self.server_type = ServerType(server_type) self.image = Image(name=image) self.docker_image = docker_image
def _connect_client(): provider = get_configured_provider() return hcloud.Client(provider["key"])
import hcloud client = hcloud.Client( token='wEyrrJ2SUDhUfmpSEKwFMZtBb4ww2W3wkmeLI6a6xCx59E3WOyY6YqTool9pVqor') ips = [ instance.public_net.ipv4.ip for instance in client.servers.get_all() if instance.status == instance.STATUS_RUNNING ] from cluster_monitor import ClusterMonitor ClusterMonitor(ips)
def get_vpn_server_state(): try: client = hcloud.Client(HETZNER_APIKEY) return client.servers.get_by_id(VPN_SERVER_ID).status except: return False
def entity_client(self) -> SSHKeysClient: if self._cached_client is None: self._cached_client = hcloud.Client(self.token) return self._cached_client.ssh_keys
def entity_client(self) -> VolumesClient: if self._cached_client is None: self._cached_client = hcloud.Client(self.token) return self._cached_client.volumes
def _client(self) -> hcloud.Client: assert self.token if self._cached_client is None: self._cached_client = hcloud.Client(self.token) return self._cached_client
load_dotenv() os.chdir(Path(__file__).parent.absolute()) # Discord config DISCORD_TOKEN = os.getenv("DISCORD_TOKEN") ROLE = int(os.getenv("BOT_PRIVILEDGED_ROLE")) PREFIX = os.getenv("BOT_PREFIX") discord = commands.Bot(PREFIX) # Hetzner config HCLOUD_TOKEN = os.getenv("HCLOUD_TOKEN") SERVER_NAME = os.getenv("SERVER_NAME") SERVER_TYPE = ServerType(name=os.getenv("SERVER_TYPE")) SERVER_IMAGE = Image(name=os.getenv("SERVER_IMAGE")) hcloud = hcl.Client(HCLOUD_TOKEN) def get_volume() -> Volume: return hcloud.volumes.get_by_name(SERVER_NAME) def requires_role(): """Short-hand for commands.has_role(ROLE)""" return commands.has_role(ROLE) @discord.event async def on_command_error(ctx, error: commands.CommandError): if isinstance(error, commands.CheckFailure): await ctx.send("You are not allowed to use this bot")