Exemplo n.º 1
0
    def rebuild(self, server, image):
        # type: (servers.domain.Server, Image) -> actions.domainAction
        """Rebuilds a server overwriting its disk with the content of an image, thereby destroying all data on the target server.

        :param server: :class:`BoundServer <hcloud.servers.client.BoundServer>` or :class:`Server <hcloud.servers.domain.Server>`
        :param image: :class:`BoundImage <hcloud.images.client.BoundImage>` or :class:`Image <hcloud.servers.domain.Image>`
        :return:  :class:`BoundAction <hcloud.actions.client.BoundAction>`
        """
        data = {
            "image": image.id_or_name
        }
        response = self._client.request(url="/servers/{server_id}/actions/rebuild".format(server_id=server.id),
                                        method="POST", json=data)
        return BoundAction(self._client.actions, response['action'])
Exemplo n.º 2
0
    def attach_iso(self, server, iso):
        # type: (servers.domain.Server, Iso) -> actions.domainAction
        """Attaches an ISO to a server.

        :param server: :class:`BoundServer <hcloud.servers.client.BoundServer>` or :class:`Server <hcloud.servers.domain.Server>`
        :param iso: :class:`BoundIso <hcloud.isos.client.BoundIso>` or :class:`Server <hcloud.isos.domain.Iso>`
        :return:  :class:`BoundAction <hcloud.actions.client.BoundAction>`
        """
        data = {
            "iso": iso.id_or_name
        }
        response = self._client.request(url="/servers/{server_id}/actions/attach_iso".format(server_id=server.id),
                                        method="POST", json=data)
        return BoundAction(self._client.actions, response['action'])
Exemplo n.º 3
0
    def reset_password(self, server):
        # type: (servers.domain.Server) -> ResetPasswordResponse
        """ Resets the root password. Only works for Linux systems that are running the qemu guest agent.

        :param server: :class:`BoundServer <hcloud.servers.client.BoundServer>` or :class:`Server <hcloud.servers.domain.Server>`
        :return: :class:`ResetPasswordResponse <hcloud.servers.domain.ResetPasswordResponse>`
        """
        response = self._client.request(
            url="/servers/{server_id}/actions/reset_password".format(
                server_id=server.id),
            method="POST")
        return ResetPasswordResponse(action=BoundAction(
            self._client.actions, response['action']),
                                     root_password=response['root_password'])
Exemplo n.º 4
0
    def disable_public_interface(self, load_balancer):
        # type: (Union[LoadBalancer, BoundLoadBalancer]) -> BoundAction
        """ Disables the public interface of a Load Balancer.

        :param load_balancer: :class:` <hcloud.load_balancers.client.BoundLoadBalancer>` or :class:`LoadBalancer <hcloud.load_balancers.domain.LoadBalancer>`

        :return: :class:`BoundAction <hcloud.actions.client.BoundAction>`
        """

        response = self._client.request(
            url="/load_balancers/{load_balancer_id}/actions/disable_public_interface".format(
                load_balancer_id=load_balancer.id),
            method="POST")
        return BoundAction(self._client.actions, response['action'])
Exemplo n.º 5
0
    def create(
            self,
            type,  # type: str
            description=None,  # type: Optional[str]
            labels=None,  # type: Optional[str]
            home_location=None,  # type: Optional[Location]
            server=None,  # type: Optional[Server]
            name=None,  # type: Optinal[str]
    ):
        # type: (...) -> CreateFloatingIPResponse
        """Creates a new Floating IP assigned to a server.

        :param type: str
               Floating IP type Choices: ipv4, ipv6
        :param description: str (optional)
        :param labels: Dict[str, str] (optional)
               User-defined labels (key-value pairs)
        :param home_location: :class:`BoundLocation <hcloud.locations.client.BoundLocation>` or :class:`Location <hcloud.locations.domain.Location>` (
               Home location (routing is optimized for that location). Only optional if server argument is passed.
        :param server: :class:`BoundServer <hcloud.servers.client.BoundServer>` or  :class:`Server <hcloud.servers.domain.Server>`
               Server to assign the Floating IP to
        :param name: str (optional)
        :return: :class:`CreateFloatingIPResponse <hcloud.floating_ips.domain.CreateFloatingIPResponse>`
        """

        data = {'type': type}
        if description is not None:
            data['description'] = description
        if labels is not None:
            data['labels'] = labels
        if home_location is not None:
            data['home_location'] = home_location.id_or_name
        if server is not None:
            data['server'] = server.id
        if name is not None:
            data['name'] = name

        response = self._client.request(url="/floating_ips",
                                        json=data,
                                        method="POST")

        action = None
        if response.get('action') is not None:
            action = BoundAction(self._client.actions, response['action'])

        result = CreateFloatingIPResponse(floating_ip=BoundFloatingIP(
            self, response['floating_ip']),
                                          action=action)
        return result
Exemplo n.º 6
0
    def change_algorithm(self, load_balancer, algorithm):
        # type: (Union[LoadBalancer, BoundLoadBalancer], Optional[bool]) -> BoundAction
        """Changes the algorithm used by the Load Balancer

        :param load_balancer: :class:` <hcloud.load_balancers.client.BoundLoadBalancer>` or :class:`LoadBalancer <hcloud.load_balancers.domain.LoadBalancer>`
        :param algorithm: :class:`LoadBalancerAlgorithm <hcloud.load_balancers.domain.LoadBalancerAlgorithm>`
                       The LoadBalancerSubnet you want to add to the Load Balancer
        :return: :class:`BoundAction <hcloud.actions.client.BoundAction>`
        """
        data = {"type": algorithm.type}

        response = self._client.request(
            url="/load_balancers/{load_balancer_id}/actions/change_algorithm".format(load_balancer_id=load_balancer.id),
            method="POST", json=data)
        return BoundAction(self._client.actions, response['action'])
Exemplo n.º 7
0
    def update_service(self, load_balancer, service):
        # type: (Union[LoadBalancer, BoundLoadBalancer], LoadBalancerService) -> List[BoundAction]
        """Updates a service of an Load Balancer.

        :param load_balancer: :class:`BoundLoadBalancer <hcloud.load_balancers.client.BoundLoadBalancer>` or :class:`LoadBalancer <hcloud.load_balancers.domain.LoadBalancer>`
        :param service: :class:`LoadBalancerService <hcloud.load_balancers.domain.LoadBalancerService>`
                       The LoadBalancerService with updated values within for the Load Balancer
        :return: :class:`BoundAction <hcloud.actions.client.BoundAction>`
        """
        data = self.get_service_parameters(service)
        response = self._client.request(
            url="/load_balancers/{load_balancer_id}/actions/update_service".format(
                load_balancer_id=load_balancer.id),
            method="POST", json=data)
        return BoundAction(self._client.actions, response['action'])
Exemplo n.º 8
0
    def resize(self, volume, size):
        # type: (Union[Volume, BoundVolume], int) -> BoundAction
        """Changes the size of a volume. Note that downsizing a volume is not possible.

        :param volume: :class:`BoundVolume <hcloud.volumes.client.BoundVolume>` or :class:`Volume <hcloud.volumes.domain.Volume>`
        :param size: int
               New volume size in GB (must be greater than current size)
        :return: :class:`BoundAction <hcloud.actions.client.BoundAction>`
        """
        data = self._client.request(
            url="/volumes/{volume_id}/actions/resize".format(
                volume_id=volume.id),
            json={'size': size},
            method="POST")
        return BoundAction(self._client.actions, data['action'])
Exemplo n.º 9
0
    def change_protection(self, image, delete=None):
        # type: (Image, Optional[bool], Optional[bool]) -> BoundAction
        """Changes the protection configuration of the image. Can only be used on snapshots.

        :param image: :class:`BoundImage <hcloud.images.client.BoundImage>` or :class:`Image <hcloud.images.domain.Image>`
        :param delete: bool
               If true, prevents the snapshot from being deleted
        :return: :class:`BoundAction <hcloud.actions.client.BoundAction>`
        """
        data = {}
        if delete is not None:
            data.update({"delete": delete})

        response = self._client.request(url="/images/{image_id}/actions/change_protection".format(image_id=image.id), method="POST", json=data)
        return BoundAction(self._client.actions, response['action'])
Exemplo n.º 10
0
    def assign(self, floating_ip, server):
        # type: (FloatingIP, Server) -> BoundAction
        """Assigns a Floating IP to a server.

        :param floating_ip: :class:`BoundFloatingIP <hcloud.floating_ips.client.BoundFloatingIP>` or  :class:`FloatingIP <hcloud.floating_ips.domain.FloatingIP>`
        :param server: :class:`BoundServer <hcloud.servers.client.BoundServer>` or  :class:`Server <hcloud.servers.domain.Server>`
               Server the Floating IP shall be assigned to
        :return: :class:`BoundAction <hcloud.actions.client.BoundAction>`
        """
        response = self._client.request(
            url="/floating_ips/{floating_ip_id}/actions/assign".format(
                floating_ip_id=floating_ip.id),
            method="POST",
            json={"server": server.id})
        return BoundAction(self._client.actions, response['action'])
Exemplo n.º 11
0
    def request_console(self, server):
        # type: (servers.domain.Server) -> RequestConsoleResponse
        """Requests credentials for remote access via vnc over websocket to keyboard, monitor, and mouse for a server.

        :param server: :class:`BoundServer <hcloud.servers.client.BoundServer>` or :class:`Server <hcloud.servers.domain.Server>`
        :return: :class:`RequestConsoleResponse <hcloud.servers.domain.RequestConsoleResponse>`
        """
        response = self._client.request(
            url="/servers/{server_id}/actions/request_console".format(
                server_id=server.id),
            method="POST")
        return RequestConsoleResponse(action=BoundAction(
            self._client.actions, response['action']),
                                      wss_url=response['wss_url'],
                                      password=response['password'])
Exemplo n.º 12
0
    def attach(self, volume, server, automount=None):
        # type: (Union[Volume, BoundVolume], Union[Server, BoundServer], Optional[bool]) -> BoundAction
        """Attaches a volume to a server. Works only if the server is in the same location as the volume.

        :param volume: :class:`BoundVolume <hcloud.volumes.client.BoundVolume>` or :class:`Volume <hcloud.volumes.domain.Volume>`
        :param server: :class:`BoundServer <hcloud.servers.client.BoundServer>` or :class:`Server <hcloud.servers.domain.Server>`
        :param automount: boolean
        :return: :class:`BoundAction <hcloud.actions.client.BoundAction>`
        """
        data = {'server': server.id}
        if automount is not None:
            data["automount"] = automount

        data = self._client.request(url="/volumes/{volume_id}/actions/attach".format(volume_id=volume.id), json=data,
                                    method="POST")
        return BoundAction(self._client.actions, data['action'])
Exemplo n.º 13
0
    def detach_from_network(self, load_balancer, network):
        # type: (Union[LoadBalancer, BoundLoadBalancer], Union[Network,BoundNetwork]) -> BoundAction
        """Detaches a Load Balancer from a Network.

        :param load_balancer: :class:` <hcloud.load_balancers.client.BoundLoadBalancer>` or :class:`LoadBalancer <hcloud.load_balancers.domain.LoadBalancer>`
        :param network: :class:`BoundNetwork <hcloud.networks.client.BoundNetwork>` or :class:`Network <hcloud.networks.domain.Network>`
        :return: :class:`BoundAction <hcloud.actions.client.BoundAction>`
        """
        data = {
            "network": network.id,
        }
        response = self._client.request(
            url="/load_balancers/{load_balancer_id}/actions/detach_from_network".format(
                load_balancer_id=load_balancer.id), method="POST",
            json=data)
        return BoundAction(self._client.actions, response['action'])
Exemplo n.º 14
0
    def delete_service(self, load_balancer, service):
        # type: (Union[LoadBalancer, BoundLoadBalancer], LoadBalancerService) -> List[BoundAction]
        """Deletes a service from a Load Balancer.

        :param load_balancer: :class:`BoundLoadBalancer <hcloud.load_balancers.client.BoundLoadBalancer>` or :class:`LoadBalancer <hcloud.load_balancers.domain.LoadBalancer>`
        :param service: :class:`LoadBalancerService <hcloud.load_balancers.domain.LoadBalancerService>`
                       The LoadBalancerService you want to delete from the Load Balancer
        :return: :class:`BoundAction <hcloud.actions.client.BoundAction>`
        """
        data = {
            "listen_port": service.listen_port,
        }

        response = self._client.request(
            url="/load_balancers/{load_balancer_id}/actions/delete_service".format(load_balancer_id=load_balancer.id),
            method="POST", json=data)
        return BoundAction(self._client.actions, response['action'])
Exemplo n.º 15
0
    def create(
            self,
            name,  # type: str
            rules=None,  # type: Optional[List[FirewallRule]]
            labels=None,  # type: Optional[str]
            resources=None,  # type: Optional[List[FirewallResource]]
    ):
        # type: (...) -> CreateFirewallResponse
        """Creates a new Firewall.

        :param name: str
               Firewall Name
        :param rules: List[:class:`FirewallRule <hcloud.firewalls.domain.FirewallRule>`] (optional)
        :param labels: Dict[str, str] (optional)
               User-defined labels (key-value pairs)
        :param resources: List[:class:`FirewallResource <hcloud.firewalls.domain.FirewallResource>`] (optional)
        :return: :class:`CreateFirewallResponse <hcloud.firewalls.domain.CreateFirewallResponse>`
        """

        data = {'name': name}
        if labels is not None:
            data['labels'] = labels

        if rules is not None:
            data.update({"rules": []})
            for rule in rules:
                data['rules'].append(rule.to_payload())
        if resources is not None:
            data.update({"apply_to": []})
            for resource in resources:
                data['apply_to'].append(resource.to_payload())
        response = self._client.request(url="/firewalls",
                                        json=data,
                                        method="POST")

        actions = []
        if response.get('actions') is not None:
            actions = [
                BoundAction(self._client.actions, _)
                for _ in response['actions']
            ]

        result = CreateFirewallResponse(firewall=BoundFirewall(
            self, response['firewall']),
                                        actions=actions)
        return result
Exemplo n.º 16
0
    def change_alias_ips(self, server, network, alias_ips):
        # type: (Union[Server,BoundServer], Union[Network,BoundNetwork], List[str]) -> BoundAction
        """Changes the alias IPs of an already attached network.

        :param server: :class:`BoundServer <hcloud.servers.client.BoundServer>` or :class:`Server <hcloud.servers.domain.Server>`
        :param network: :class:`BoundNetwork <hcloud.networks.client.BoundNetwork>` or :class:`Network <hcloud.networks.domain.Network>`
        :param alias_ips: List[str]
                New alias IPs to set for this server.
        :return: :class:`BoundAction <hcloud.actions.client.BoundAction>`
        """
        data = {"network": network.id, "alias_ips": alias_ips}
        response = self._client.request(
            url="/servers/{server_id}/actions/change_alias_ips".format(
                server_id=server.id),
            method="POST",
            json=data)
        return BoundAction(self._client.actions, response['action'])
Exemplo n.º 17
0
    def set_rules(self, firewall, rules):
        # type: (Firewall, List[FirewallRule]) -> List[BoundAction]
        """Sets the rules of a Firewall. All existing rules will be overwritten. Pass an empty rules array to remove all rules.

        :param firewall: :class:`BoundFirewall <hcloud.firewalls.client.BoundFirewall>` or  :class:`Firewall <hcloud.firewalls.domain.Firewall>`
        :param rules: List[:class:`FirewallRule <hcloud.firewalls.domain.FirewallRule>`]
        :return: List[:class:`BoundAction <hcloud.actions.client.BoundAction>`]
        """
        data = {
            "rules": []
        }
        for rule in rules:
            data['rules'].append(rule.to_payload())
        response = self._client.request(
            url="/firewalls/{firewall_id}/actions/set_rules".format(firewall_id=firewall.id),
            method="POST", json=data)
        return [BoundAction(self._client.actions, _) for _ in response['actions']]
Exemplo n.º 18
0
    def detach_from_network(self, server, network):
        # type: (Union[Server,BoundServer], Union[Network,BoundNetwork]) -> BoundAction
        """Detaches a server from a network.

        :param server: :class:`BoundServer <hcloud.servers.client.BoundServer>` or :class:`Server <hcloud.servers.domain.Server>`
        :param network: :class:`BoundNetwork <hcloud.networks.client.BoundNetwork>` or :class:`Network <hcloud.networks.domain.Network>`
        :return: :class:`BoundAction <hcloud.actions.client.BoundAction>`
        """
        data = {
            "network": network.id,
        }
        response = self._client.request(
            url="/servers/{server_id}/actions/detach_from_network".format(
                server_id=server.id),
            method="POST",
            json=data)
        return BoundAction(self._client.actions, response['action'])
Exemplo n.º 19
0
    def remove_from_resources(self, firewall, resources):
        # type: (Firewall, List[FirewallResource]) -> List[BoundAction]
        """Removes one Firewall from multiple resources.

        :param firewall: :class:`BoundFirewall <hcloud.firewalls.client.BoundFirewall>` or  :class:`Firewall <hcloud.firewalls.domain.Firewall>`
        :param rules: List[:class:`FirewallResource <hcloud.firewalls.domain.FirewallResource>`]
        :return: List[:class:`BoundAction <hcloud.actions.client.BoundAction>`]
        """
        data = {
            "remove_from": []
        }
        for resource in resources:
            data['remove_from'].append(resource.to_payload())
        response = self._client.request(
            url="/firewalls/{firewall_id}/actions/remove_from_resources".format(firewall_id=firewall.id),
            method="POST", json=data)
        return [BoundAction(self._client.actions, _) for _ in response['actions']]
Exemplo n.º 20
0
    def change_protection(self, volume, delete=None):
        # type: (Union[Volume, BoundVolume], Optional[bool]) -> BoundAction
        """Changes the protection configuration of a volume.

        :param volume: :class:`BoundVolume <hcloud.volumes.client.BoundVolume>` or :class:`Volume <hcloud.volumes.domain.Volume>`
        :param delete: boolean
               If True, prevents the volume from being deleted
        :return: :class:`BoundAction <hcloud.actions.client.BoundAction>`
        """
        data = {} # type: Dict[str, Any]
        if delete is not None:
            data.update({"delete": delete})

        response = self._client.request(
            url="/volumes/{volume_id}/actions/change_protection".format(volume_id=volume.id),
            method="POST", json=data)
        return BoundAction(self._client.actions, response['action'])
Exemplo n.º 21
0
    def change_type(self, load_balancer, load_balancer_type):
        # type: ([LoadBalancer, BoundLoadBalancer], [LoadBalancerType, BoundLoadBalancerType]) ->BoundAction
        """Changes the type of a Load Balancer.

        :param load_balancer: :class:`BoundLoadBalancer <hcloud.load_balancers.client.BoundLoadBalancer>` or :class:`LoadBalancer <hcloud.load_balancers.domain.LoadBalancer>`
        :param load_balancer_type: :class:`BoundLoadBalancerType <hcloud.load_balancer_types.client.BoundLoadBalancerType>` or :class:`LoadBalancerType <hcloud.load_balancer_types.domain.LoadBalancerType>`
               Load Balancer type the Load Balancer should migrate to
        :return:  :class:`BoundAction <hcloud.actions.client.BoundAction>`
        """
        data = {
            "load_balancer_type": load_balancer_type.id_or_name,
        }
        response = self._client.request(
            url="/load_balancers/{load_balancer_id}/actions/change_type".
            format(load_balancer_id=load_balancer.id),
            method="POST",
            json=data)
        return BoundAction(self._client.actions, response['action'])
Exemplo n.º 22
0
    def change_protection(self, load_balancer, delete=None):
        # type: (Union[LoadBalancer, BoundLoadBalancer], Optional[bool]) -> BoundAction
        """Changes the protection configuration of a Load Balancer.

        :param load_balancer: :class:` <hcloud.load_balancers.client.BoundLoadBalancer>` or :class:`LoadBalancer <hcloud.load_balancers.domain.LoadBalancer>`
        :param delete: boolean
               If True, prevents the Load Balancer from being deleted
        :return: :class:`BoundAction <hcloud.actions.client.BoundAction>`
        """
        data = {}
        if delete is not None:
            data.update({"delete": delete})

        response = self._client.request(
            url="/load_balancers/{load_balancer_id}/actions/change_protection".format(
                load_balancer_id=load_balancer.id),
            method="POST", json=data)
        return BoundAction(self._client.actions, response['action'])
Exemplo n.º 23
0
    def change_dns_ptr(self, server, ip, dns_ptr):
        # type: (servers.domain.Server, str, str) -> actions.domainAction
        """Changes the hostname that will appear when getting the hostname belonging to the primary IPs (ipv4 and ipv6) of this server.

        :param server: :class:`BoundServer <hcloud.servers.client.BoundServer>` or :class:`Server <hcloud.servers.domain.Server>`
        :param ip: str
                   The IP address for which to set the reverse DNS entry
        :param dns_ptr:
                  Hostname to set as a reverse DNS PTR entry, will reset to original default value if `None`
        :return:  :class:`BoundAction <hcloud.actions.client.BoundAction>`
        """
        data = {"ip": ip, "dns_ptr": dns_ptr}
        response = self._client.request(
            url="/servers/{server_id}/actions/change_dns_ptr".format(
                server_id=server.id),
            method="POST",
            json=data)
        return BoundAction(self._client.actions, response['action'])
Exemplo n.º 24
0
    def change_type(self, server, server_type, upgrade_disk):
        # type: (servers.domain.Server, BoundServerType, bool) -> actions.domainAction
        """Changes the type (Cores, RAM and disk sizes) of a server.

        :param server: :class:`BoundServer <hcloud.servers.client.BoundServer>` or :class:`Server <hcloud.servers.domain.Server>`
        :param server_type: :class:`BoundServerType <hcloud.server_types.client.BoundServerType>` or :class:`ServerType <hcloud.server_types.domain.ServerType>`
               Server type the server should migrate to
        :param upgrade_disk: boolean
               If false, do not upgrade the disk. This allows downgrading the server type later.
        :return:  :class:`BoundAction <hcloud.actions.client.BoundAction>`
        """
        data = {
            "server_type": server_type.id_or_name,
            "upgrade_disk": upgrade_disk
        }
        response = self._client.request(url="/servers/{server_id}/actions/change_type".format(server_id=server.id),
                                        method="POST", json=data)
        return BoundAction(self._client.actions, response['action'])
Exemplo n.º 25
0
    def remove_target(self, load_balancer, target):
        # type: (Union[LoadBalancer, BoundLoadBalancer], LoadBalancerTarget) -> List[BoundAction]
        """Removes a target from a Load Balancer.

        :param load_balancer: :class:`BoundLoadBalancer <hcloud.load_balancers.client.BoundLoadBalancer>` or :class:`LoadBalancer <hcloud.load_balancers.domain.LoadBalancer>`
        :param target: :class:`LoadBalancerTarget <hcloud.load_balancers.domain.LoadBalancerTarget>`
                       The LoadBalancerTarget you want to remove from the Load Balancer
        :return: :class:`BoundAction <hcloud.actions.client.BoundAction>`
        """
        data = {
            "type": target.type,
            "server": {"id": target.server.id},
        }

        response = self._client.request(
            url="/load_balancers/{load_balancer_id}/actions/remove_target".format(load_balancer_id=load_balancer.id),
            method="POST", json=data)
        return BoundAction(self._client.actions, response['action'])
Exemplo n.º 26
0
    def change_protection(self, network, delete=None):
        # type: (Union[Network, BoundNetwork], Optional[bool]) -> BoundAction
        """Changes the protection configuration of a network.

        :param network: :class:`BoundNetwork <hcloud.networks.client.BoundNetwork>` or :class:`Network <hcloud.networks.domain.Network>`
        :param delete: boolean
               If True, prevents the network from being deleted
        :return: :class:`BoundAction <hcloud.actions.client.BoundAction>`
        """
        data = {}
        if delete is not None:
            data.update({"delete": delete})

        response = self._client.request(
            url="/networks/{network_id}/actions/change_protection".format(
                network_id=network.id),
            method="POST",
            json=data)
        return BoundAction(self._client.actions, response['action'])
Exemplo n.º 27
0
    def change_ip_range(self, network, ip_range):
        # type: (Union[Network, BoundNetwork], str) -> List[BoundAction]
        """Changes the IP range of a network.

        :param network: :class:`BoundNetwork <hcloud.networks.client.BoundNetwork>` or :class:`Network <hcloud.networks.domain.Network>`
        :param ip_range: str
                    The new prefix for the whole network.
        :return: :class:`BoundAction <hcloud.actions.client.BoundAction>`
        """
        data = {
            "ip_range": ip_range,
        }

        response = self._client.request(
            url="/networks/{network_id}/actions/change_ip_range".format(
                network_id=network.id),
            method="POST",
            json=data)
        return BoundAction(self._client.actions, response['action'])
Exemplo n.º 28
0
    def delete_subnet(self, network, subnet):
        # type: (Union[Network, BoundNetwork], NetworkSubnet) -> List[BoundAction]
        """Removes a subnet entry from a network

        :param network: :class:`BoundNetwork <hcloud.networks.client.BoundNetwork>` or :class:`Network <hcloud.networks.domain.Network>`
        :param subnet: :class:`NetworkSubnet <hcloud.networks.domain.NetworkSubnet>`
                       The NetworkSubnet you want to remove from the Network
        :return: :class:`BoundAction <hcloud.actions.client.BoundAction>`
        """
        data = {
            "ip_range": subnet.ip_range,
        }

        response = self._client.request(
            url="/networks/{network_id}/actions/delete_subnet".format(
                network_id=network.id),
            method="POST",
            json=data)
        return BoundAction(self._client.actions, response['action'])
Exemplo n.º 29
0
    def change_protection(self, floating_ip, delete=None):
        # type: (FloatingIP, Optional[bool]) -> BoundAction
        """Changes the protection configuration of the Floating IP.

        :param floating_ip: :class:`BoundFloatingIP <hcloud.floating_ips.client.BoundFloatingIP>` or  :class:`FloatingIP <hcloud.floating_ips.domain.FloatingIP>`
        :param delete: boolean
               If true, prevents the Floating IP from being deleted
        :return: :class:`BoundAction <hcloud.actions.client.BoundAction>`
        """
        data = {}
        if delete is not None:
            data.update({"delete": delete})

        response = self._client.request(
            url="/floating_ips/{floating_ip_id}/actions/change_protection".
            format(floating_ip_id=floating_ip.id),
            method="POST",
            json=data)
        return BoundAction(self._client.actions, response['action'])
Exemplo n.º 30
0
    def get_actions_list(
            self,
            floating_ip,  # type: FloatingIP
            status=None,  # type: Optional[List[str]]
            sort=None,  # type: Optional[List[str]]
            page=None,  # type: Optional[int]
            per_page=None,  # type: Optional[int]
    ):
        # type: (...) -> PageResults[List[BoundAction], Meta]
        """Returns all action objects for a Floating IP.

        :param floating_ip: :class:`BoundFloatingIP <hcloud.floating_ips.client.BoundFloatingIP>` or  :class:`FloatingIP <hcloud.floating_ips.domain.FloatingIP>`
        :param status: List[str] (optional)
               Response will have only actions with specified statuses. Choices: `running` `success` `error`
        :param sort: List[str] (optional)
               Specify how the results are sorted. Choices: `id` `id:asc` `id:desc` `command` `command:asc` `command:desc` `status` `status:asc` `status:desc` `progress` `progress:asc` `progress:desc` `started` `started:asc` `started:desc` `finished` `finished:asc` `finished:desc`
        :param page: int (optional)
               Specifies the page to fetch
        :param per_page: int (optional)
               Specifies how many results are returned by page
        :return: (List[:class:`BoundAction <hcloud.actions.client.BoundAction>`], :class:`Meta <hcloud.core.domain.Meta>`)
        """
        params = {}  # type: Dict[str, Any]
        if status is not None:
            params["status"] = status
        if sort is not None:
            params["sort"] = sort
        if page is not None:
            params["page"] = page
        if per_page is not None:
            params["per_page"] = per_page
        response = self._client.request(
            url="/floating_ips/{floating_ip_id}/actions".format(
                floating_ip_id=floating_ip.id),
            method="GET",
            params=params,
        )
        actions = [
            BoundAction(self._client.actions, action_data)
            for action_data in response["actions"]
        ]
        return add_meta_to_result(actions, response, "actions")