Ejemplo n.º 1
0
    def create(self,
               size,
               name,
               automount=False,
               format=None,
               location=None,
               server=None):
        if location is None and server is None:
            raise HetznerInvalidArgumentException("location_id and server")
        if automount and format is None:
            raise HetznerInvalidArgumentException(
                "Format must be specified if automount enabled")

        body = {"size": size, "name": name}
        if automount is not None:
            body["automount"] = automount
        if format is not None:
            body["format"] = format
        if location is not None:
            body["location"] = location
        if server is not None:
            body["server"] = server

        status_code, results = _get_results(self._config,
                                            "volumes",
                                            method="POST",
                                            body=body)
        if status_code != 201:
            raise HetznerActionException(results)

        return HetznerCloudVolume._load_from_json(self._config, results["volume"]), \
            HetznerCloudAction._load_from_json(self._config, results["action"])
Ejemplo n.º 2
0
    def unassign_from_server(self):
        status_code, result = _get_results(self._config, "floating_ips/%s/actions/unassign" % self.id, method="POST")
        if status_code != 201:
            raise HetznerActionException(result)

        self.server = 0

        return HetznerCloudAction._load_from_json(self._config, result["action"])
Ejemplo n.º 3
0
    def assign_to_server(self, server_id):
        if not server_id:
            raise HetznerInvalidArgumentException("server_id")

        status_code, result = _get_results(self._config, "floating_ips/%s/actions/assign" % self.id, method="POST",
                                           body={"server": server_id})
        if status_code != 201:
            raise HetznerActionException(result)

        self.server = server_id

        return HetznerCloudAction._load_from_json(self._config, result["action"])
Ejemplo n.º 4
0
    def detach_from_server(self):
        status_code, result = _get_results(self._config,
                                           "volumes/%s/actions/detach" %
                                           self.id,
                                           method="POST")
        if status_code != 201:
            raise HetznerActionException(result)

        self.server = 0

        return HetznerCloudAction._load_from_json(self._config,
                                                  result["action"])
Ejemplo n.º 5
0
    def change_reverse_dns_entry(self, ip, dns_ptr=None):
        if not ip:
            raise HetznerInvalidArgumentException("ip")

        status_code, result = _get_results(self._config, "floating_ips/%s/actions/change_dns_ptr" % self.id,
                                           method="POST", body={"ip": ip, "dns_ptr": dns_ptr})
        if status_code != 201:
            raise HetznerActionException(result)

        self.ptr_ips = [ip]
        self.ptr_dns_ptrs = [dns_ptr]

        return HetznerCloudAction._load_from_json(self._config, result["action"])
Ejemplo n.º 6
0
    def attach_to_server(self, server_id, automount):
        if not server_id:
            raise HetznerInvalidArgumentException("server_id")

        status_code, result = _get_results(self._config,
                                           "volumes/%s/actions/attach" %
                                           self.id,
                                           method="POST",
                                           body={
                                               "server": server_id,
                                               "automount": automount
                                           })
        if status_code != 201:
            raise HetznerActionException(result)

        self.server = server_id

        return HetznerCloudAction._load_from_json(self._config,
                                                  result["action"])