Exemple #1
0
    def __init__(self,
                 central_info,
                 token_store=None,
                 logger=None,
                 ssl_verify=True):
        """Constructor Method initializes access token. If user provides access token, use the access
        token for API calls. Otherwise try to reuse token from cache or try to generate
        new access token via OAUTH 2.0. Terminates the program if unable to initialize the access token.
        """
        self.central_info = parseInputArgs(central_info)
        self.token_store = token_store
        self.logger = None
        self.ssl_verify = ssl_verify
        # Set logger
        if logger:
            self.logger = logger
        else:
            self.logger = console_logger("ARUBA_BASE")
        # Set token
        if "token" in self.central_info and self.central_info["token"]:
            if "access_token" not in self.central_info["token"]:
                self.central_info["token"] = self.getToken()
        else:
            self.central_info["token"] = self.getToken()

        if not self.central_info["token"]:
            sys.exit("exiting.. unable to get API access token!")
Exemple #2
0
# copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.

import sys
from pycentral.url_utils import urlJoin, MonitoringUrl
from pycentral.base_utils import console_logger

urls = MonitoringUrl()
logger = console_logger("MONITORING")


class Sites(object):
    """A python class consisting of functions to manage Aruba Central Sites via REST API
    """
    def get_sites(self,
                  conn,
                  calculate_total=False,
                  offset=0,
                  limit=100,
                  sort="+site_name"):
        """Get list of sites

        :param conn: Instance of class:`pycentral.ArubaCentralBase` to make an API call.
        :type conn: class:`pycentral.ArubaCentralBase`
Exemple #3
0
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.

import sys
from pycentral.url_utils import UrlObj
from pycentral.base_utils import console_logger

urls = UrlObj()
DEVICE_TYPES = ["IAP", "ArubaSwitch", "CX", "MobilityController"]
logger = console_logger("CONFIGURATION")


class Groups(object):
    """A python class consisting of functions to manage Aruba Central Groups via REST API
    """
    def get_groups(self, conn, offset=0, limit=20):
        """Get list of groups

        :param conn: Instance of class:`pycentral.ArubaCentralBase` to make an API call.
        :type conn: class:`pycentral.ArubaCentralBase` 
        :param offset: Pagination offset, defaults to 0
        :type offset: int, optional
        :param limit: Pagination limit with Max 20, defaults to 20
        :type limit: int, optional
        :return: Response as provided by 'command' function in class:`pycentral.ArubaCentralBase`
Exemple #4
0
3. For every AP in the csv file, update AP settings via API call based on the data obtained from Step2. 

3. Display a list of failed APs at end of the script.
"""

import os, sys
import csv
from pprint import pprint

from pycentral.base import ArubaCentralBase
from pycentral.configuration import ApSettings
from pycentral.base_utils import console_logger
from pycentral.workflows.workflows_utils import get_conn_from_file, get_file_contents

LOGGER = console_logger("AP_SETTINGS_CSV")
ALL_FIELDS = [
    "serial_number", "hostname", "ip_address", "zonename", "achannel",
    "atxpower", "gchannel", "gtxpower", "dot11a_radio_disable",
    "dot11g_radio_disable", "usb_port_disable"
]


def csv_file_dict(filename: str):
    """Read the APs from the provided csv file and check if all required fieldnames are present

    :param filename: Name of the csv file to read the AP settings data
    :type filename: str
    :raises UserWarning: Raises this exception when required column names are missing from csv file 
    :return: List of Python dict where each dict is representation of a row in csv file
    :rtype: list