Пример #1
0
    def add(self, pool, nodes=None, **pool_props):
        """
        Add a new load balancer pool

        Arguments:
            pool (str): The name of the pool to add
            nodes (list): List of nodes for the pool
            pool_props (dict): Additional arguments to set properties of the
                pool at time of creation. Must be a dict in the form of: ::

                {'section': {'key': 'value'}}

        Returns:
            (Pool): The new pool
        """
        # Don't create empty pools
        if nodes is None:
            raise StingrayAPIClientError(
                "No nodes specified, cannot create pool")

        if nodes and type(nodes) != list:
            raise StingrayAPIClientError("Nodes must be specified as a list")

        pool_data = dict(properties=dict(basic=dict(nodes_table=[])))

        for prop in pool_props:
            pool_data['properties'].setdefault(prop, dict())
            for key, value in pool_props[prop].iteritems():
                pool_data['properties'][prop][key] = value

        for node in nodes:
            pool_data['properties']['basic']['nodes_table'].append(
                dict(node=node, state='active'))

        add_pool_response = self._api_put(
            '{0}{1}'.format(self.config_path, pool), pool_data)

        new_pool = Pool(pool, '{0}/{1}'.format(self.config_path, pool),
                        add_pool_response['properties'], self.api_host,
                        self.api_port, self.api_user, self.api_password,
                        self.api_version, self.ssl_verify)
        self.pools[pool] = new_pool.config_path

        return new_pool
    def add(self,
            group,
            ipaddresses=None,
            machines=None,
            mode='singlehosted',
            **group_props):
        """
        Add a new traffic ip group.

        Arguments:
            group (str): The traffic ip group name
            ipaddresses (list): IP addresses to assign to the group
            machines (list): Load balancers that can host the group's
                IP addresses. Default is the current load balancer (or load
                balancers if clustered).
            mode (str): Method used to distribute traffic across the cluster.
                Default is ``singlehosted``
            group_props (dict): Additional arguments to set the properties
                of the traffic ip group at time of creation. Must be a
                dict in the form of: ::

                {'section': {'key': 'value'}}

        Returns:
            (TrafficIPGroup): The new traffic ip group
        """
        if ipaddresses is None:
            raise StingrayAPIClientError(
                "No IP addresses specified, unable to create Traffic IP group")

        if machines is None:
            machines = []
            tm_list = self._api_get('config/active/traffic_managers')
            for tm in tm_list['children']:
                machines.append(tm['name'])

        traffic_ip_group_data = dict(properties=dict(
            basic=dict(ipaddresses=ipaddresses, machines=machines, mode=mode)))

        for prop in group_props:
            traffic_ip_group_data['properties'].setdefault(prop, dict())
            for key, value in group_props[prop].items():
                traffic_ip_group_data['properties'][prop][key] = value

        add_traffic_ip_group_response = self._api_put(
            '{0}{1}'.format(self.config_path, group), traffic_ip_group_data)

        tig = TrafficIPGroup.from_client(
            self,
            group,
            group_path='{0}{1}'.format(self.config_path, group),
            group_properties=add_traffic_ip_group_response['properties'])
        self.traffic_ip_groups[group] = tig.config_path

        return tig
Пример #3
0
    def get(self, pool):
        """
        Get a Pool object for the request pool.

        Arguments:
            pool (str): The name of the pool to get

        Returns:
            (Pool): The requested pool
        """
        try:
            return Pool.from_client(self, pool, self.pools[pool])
        except KeyError:
            raise StingrayAPIClientError("Pool {0} not found".format(pool))
    def get(self, group):
        """
        Get a TrafficIPGroup object for the requested traffic ip group

        Arguments:
            group (str): The name of the traffic ip group to get

        Returns:
            (TrafficIPGroup): The requested traffic ip group
        """
        try:
            return TrafficIPGroup.from_client(self, group,
                                              self.traffic_ip_groups[group])
        except KeyError:
            raise StingrayAPIClientError(
                "Traffic IP Group {0} not found".format(group))
    def get(self, server):
        """
        Get a VirtualServer object for the requested virtual server

        Arguments:
            server (str): The name of the virtual server to get

        Returns:
            (VirtualServer): The requested virtual server
        """
        try:
            return VirtualServer.from_client(self, server,
                                             self.virtual_servers[server])
        except KeyError:
            raise StingrayAPIClientError(
                "Virtual Server {0} not found".format(server))
    def __init__(self,
                 host=None,
                 port=None,
                 user=None,
                 password=None,
                 api_version=None,
                 ssl_verify=None):
        super(TrafficIPGroups, self).__init__(host, port, user, password,
                                              api_version, ssl_verify)

        if api_version == "1.0":
            raise StingrayAPIClientError(
                "API version 1.0 does not support Traffic IP Groups")

        self.config_path = '{0}/config/active/traffic_ip_groups/'.format(
            self.api_version, )
        self.traffic_ip_groups = {}
        tigs_list = self._api_get(self.config_path)
        for tig in tigs_list['children']:
            self.traffic_ip_groups[tig['name']] = tig['href']
Пример #7
0
 def _bad_node(self, node):
     raise StingrayAPIClientError(
         "Node {0} is not a member of this pool".format(node))