def create_device_policy(self,
                             dp_name='DevicePolicyName',
                             description='automation',
                             default_action='ALLOW',
                             apzone_name='TEST',
                             domain_label='Administration Domain'):
        result = False
        dp_profile = {}

        try:
            url = ji.get_url(self.api_create_devicepolicy, self.scg_mgmt_ip,
                             self.scg_port)
            dp_profile.update(self.DPT.get_template_data_for_devicepolicy())

            dp_profile.update({
                "name": dp_name,
                "description": description,
                "defaultAction": default_action
            })

            dp_profile.update({
                "zoneUUID":
                self.get_apzone_uuid(apzone_name=apzone_name,
                                     domain_label=domain_label),
                "tenantUUID":
                self._get_tenant_uuid()
            })

            data_json = json.dumps(dp_profile)
            result = ji.post_json_data(url, self.jsessionid, data_json)

        except Exception, e:
            print traceback.format_exc()
            return False
    def cluster_backup(self):

        recvd_data = None
        validate_data = None
        self.json_url = "/wsg/api/scg/backup/cluster"
        self.validate_status = "/wsg/api/scg/patches/upgrade/status"

        try:
            data = ''
            url = ji.get_url(self.json_url, self.scg_mgmt_ip, self.scg_port)
            recvd_data = ji.post_json_data(url, self.jsessionid, data)
            #recvd_data=True
            if not recvd_data:
                return None
            else:
                while True:
                    validate_url = ji.get_url(self.validate_status,
                                              self.scg_mgmt_ip, self.scg_port)
                    validate_data = ji.get_json_data(validate_url,
                                                     self.jsessionid)
                    if "data" in validate_data.keys():
                        if validate_data["data"]["previousOperationRecord"][
                                "success"] == True:
                            return True
                    print "Backup operation is in progress. Sleeping for 30 sec..."
                    time.sleep(30)
        except Exception, e:
            #print "COMING INSIDE EXCEPTION"
            print traceback.format_exc()
            return None
 def schedule_backup(self,
                     sch_schedules=1,
                     sch_interval=None,
                     sch_dateOfMonth=None,
                     sch_dayOfWeek=None,
                     sch_hour=None,
                     sch_minute=None,
                     sch_scheduleEnabled='True'):
     result = False
     sch_backup = {}
     sch_backup1 = {}
     try:
         url = ji.get_url(self.req_schdule_back_up, self.scg_mgmt_ip,
                          self.scg_port)
         sch_backup.update({"schedules": sch_backup1})
         if sch_schedules == 1:
             sch_backup1.update({
                 "interval": sch_interval,
                 "dateOfMonth": sch_dateOfMonth,
                 "dayOfWeek": sch_dayOfWeek,
                 "hour": sch_hour,
                 "minute": sch_minute,
                 "scheduleEnabled": sch_scheduleEnabled
             })
         self.sch_backup = json.dumps(sch_backup)
         print "###", self.sch_backup
         result = ji.post_json_data(url, self.jsessionid, self.sch_backup)
     except Exception, e:
         print traceback.format_exc()
         return False
 def auto_export_backup(self, autoExportEnabled="true", ftpServerName=None):
     result = False
     aut_backup = {}
     aut_backup1 = {}
     try:
         scg_json = sjc.ScgJsonConfig(scg_mgmt_ip=self.scg_mgmt_ip,
                                      scg_port=self.scg_port)
         scg_json.set_jsessionid(self.jsessionid)
         url = ji.get_url(self.req_auto_back_up, self.scg_mgmt_ip,
                          self.scg_port)
         aut_backup1.update({
             "ftpEnabled": autoExportEnabled,
             "ftpSettingKey": "",
             "ftpSettins": None
         })
         if autoExportEnabled == "true":
             ftpServerKey, recv_data = scg_json._get_key_for_ftp_service(
                 ftpServerName)
             aut_backup.update({"key": ftpServerKey})
             aut_backup1.update({"ftpSettins": aut_backup})
             aut_backup1.update({"ftpSettingKey": ftpServerKey})
         aut_backup1 = json.dumps(aut_backup1)
         result = ji.post_json_data(url, self.jsessionid, aut_backup1)
     except Exception, e:
         print traceback.format_exc()
         return False
예제 #5
0
    def create_pmipv6_service_profile(self,
                                      pmipv6_name="Auto_PMIPv6_Profile",
                                      description='Automation PMIPv6',
                                      lma_primary_ip="1.1.1.1",
                                      lma_secondary_ip="2.2.2.2",
                                      mnid_type="NAI_From_Authentication",
                                      mac48_type=None,
                                      lma_apn="ruckus.com",
                                      mac48_hex_delimiter="No"):
        """ 
        Creates the PMIPv6 service profile
        
        URI: POST /wsg/api/scg/serviceProfiles/forwarding?

        :param str pmipv6_name: PMIPv6 Profile Name
        :param str lma_primary_ip: Primary IP Address of LMA
        :param str lma_secondary_ip: Secondary IP Address of LMA
        :param str mnid_type: NAI_From_Authentication | MAC48_At_APN 
        :param mac48_type: Decimal | Hexadecimal
        :param lma_apn: APN name 
        :return: True if PMIPv6 created else False
        :rtype: boolean
        """

        lma_profile = {}
        result = False
        try:
            url = ji.get_url(self.req_api_lma, self.scg_mgmt_ip, self.scg_port)
            lma_profile.update(self.SJT.get_lma_template_data())

            lma_profile.update({
                "name": pmipv6_name,
                "description": description,
                "lmaPrimaryIp": lma_primary_ip,
                "lmaSecondaryIp": lma_secondary_ip,
                "mnIdType": mnid_type,
                "apn": lma_apn
            })

            if lma_profile["mnIdType"] == "MAC48_At_APN":
                lma_profile.update({"mac48Type": mac48_type})
                if lma_profile["mac48Type"] == "Hexadecimal":
                    lma_profile.update({"delimiter": mac48_hex_delimiter})

            data_json = json.dumps(lma_profile)
            result = ji.post_json_data(url, self.jsessionid, data_json)

        except Exception, e:
            print traceback.format_exc()
            return False
예제 #6
0
    def create_ftp(self,ftp_ip="",ftp_username="",ftp_password="",ftp_directory=""):

        url = ji.get_url(self.FTP_API, self.scg_mgmt_ip, self.scg_port)
        data = {"key":"","ftpName":"auto_sp","ftpProtocol":"FTP",
	"ftpHost":ftp_ip,"ftpPort":"21",
	"ftpUserName":ftp_username,"ftpPassword":ftp_password,
	"ftpRemoteDirectory":ftp_directory
	}

        data_json = json.dumps(data)
        try: 
            result = ji.post_json_data(url,self.jsessionid, data_json)
        except Exception:
            print traceback.format_exc()
            return False, None

        return True
예제 #7
0
    def create_save_report(self, ftp_name="", leader_name="", follower_name=""):

        url = ji.get_url(self.SAVE_REPORT,self.scg_mgmt_ip,self.scg_port)
        data = {"title":"auto_sp_report",
	"description":"",
	"reportType":"Active TTG Sessions",
	"domainUUID":self.get_domain_uuid(),
	"pdfFormat":True,"csvFormat":True,
	"timeFilter":{"interval":"FIFTEEN_MIN","timeUtil":"HOURS","timeSpan":8},
	"deviceFilter":{"resourceType":"PLANE",
		"resourceEntity":[{"label":leader_name + "-C","value":self.get_cblade_id(leader_name)},
			{"label":follower_name + "-C","value":self.get_cblade_id(follower_name)}]},
	"scheduleEnable":True,
	"schedules":[{"interval":"DAILY"}],"notificationEnable":False,"notifiedMailList":[],"ftpEnable":"true",
	"ftpServer":{"key":self.get_ftp(ftp_name)}
	}
        data_json = json.dumps(data)

        try: 
            result = ji.post_json_data(url,self.jsessionid, data_json)
        except Exception:
            print traceback.format_exc()
            return False, None
    def create_report(self,
                      report_title='myreport',
                      report_type='Client Number',
                      output_format='csv',
                      time_filter_interval='FIFTEEN_MIN',
                      time_filter_value=8,
                      time_filter_units='HOURS',
                      is_device_filter=True,
                      device_category='Management Domains',
                      domain_label='Administration Domain',
                      ap_zone=None,
                      ap_label=None,
                      ap_ip=None,
                      cblade_label=None,
                      is_ssid_filter=False,
                      ssid=None,
                      is_radio_filter=False,
                      radio=None,
                      enable_schedules=True,
                      schedule_interval='DAILY',
                      schedule_day=8,
                      schedule_week='MONDAY',
                      schedule_hour=0,
                      schedule_min=0,
                      enable_email_notifications=False,
                      email_id='*****@*****.**',
                      enable_export_results=False,
                      ftp_host='1.2.3.4',
                      ftp_port='21',
                      ftp_username='******',
                      ftp_password='******',
                      ftp_remote_dir=None):
        """
        API is used to Create Report

        URI POST: '/wsg/api/scg/reports'

        :Param str report_title: Report Title
        :Param str report_type: Report Type Client Number | Client Number Vs Air Time | Active TTG Sessions | Continuously Disconnected APs 
        :Param str output_format: Output Format  csv | pdf  
        :Param str time_filter_interval: FIFTEEN_MIN | DAILY | HOURLY | MONTHLY
        :Param str time_filter_value: from 1 to 48
        :Param str time_filter_units: HOURS | DAYS |  MONTHS
        :Param str is_device_filter: Resource Filter - True
        :Param str device_category: Management Domains | APZONE | Access Point
        :Param str domain_label: Domain Label Name
        :Param str ap_zone: Ap Zone Name
        :Param str ap_label: Ap Zone Name
        :Param str ap_ip: Access Point IP
        :Param str cblade_label: Cblade Label Name
        :Param str is_ssid_filter: True | False
        :Param str ssid: SSID
        :Param str is_radio_filter: True | False
        :Param str radio: 2.5G | 5G
        :Param str enable_schedules:  True | False
        :Param str schedule_interval : DAILY | MONTHLY | WEEKLY | HOURLY
        :Param str schedule_day: schedule Day
        :Param str schedule_week: schedule Week
        :Param str schedule_hour: from 0 to 23
        :Param str schedule_min: from 0 to 59 
        :Param str enable_email_notifications: True | False
        :Param str email_id: Email ID
        :Param str enable_export_results: True | False
        :Param str ftp_host: FTP Host IP Address
        :Param str ftp_port: FTP Port Address
        :Param str ftp_username: FTP User Name
        :Param str ftp_password: FTP Password
        :Param str ftp_remote_dir: FTP Remote Directory
        :return: Trur if Report is created else False
        :rtype: boolean

        """
        try:
            domain_uuid = None
            apzone_uuid = None
            ap_info = None
            ap_mac = None

            report_data = self.SJT.get_report_template_data()

            report_data['title'] = report_title
            report_data['reportType'] = report_type
            if output_format == 'csv':
                report_data['csvFormat'] = True
            elif output_format == 'pdf':
                report_data['pdfFormat'] = True
            else:
                print "create_report(): Invalid output_format: %s" % output_format
                return False
            report_data['timeFilter']['interval'] = time_filter_interval
            report_data['timeFilter']['timeSpan'] = int(time_filter_value)
            report_data['timeFilter']['timeUtil'] = time_filter_units

            self._create_apzone_info_api(jsessionid=self.jsessionid)

            if is_device_filter or is_ssid_filter or is_radio_filter:
                domain_uuid = self._get_domain_uuid(domain_label=domain_label)
                if not domain_uuid:
                    print "create_report(): _get_domain_uuid() failed. domain_label: %s" % (
                        domain_label)
                    return False

                report_data['domainUUID'] = domain_uuid
            else:
                print "create_report(): atleast one resource_filter_criteria shall be enabled by user"
                return False

            if is_device_filter:
                device_filter = self.SJT.get_filter_template_data()

                if device_category == 'Management Domains':
                    device_filter['resourceType'] = 'DOMAIN'
                    device_filter['resourceEntity'][0]['label'] = domain_label
                    device_filter['resourceEntity'][0]['value'] = domain_uuid
                elif device_category == 'AP Zone':
                    apzone_uuid = self._get_apzone_uuid(
                        domain_label=domain_label, ap_zone=ap_zone)
                    if not apzone_uuid:
                        print "create_report(): _get_apzone_uuid() failed. ap_zone: %s" % ap_zone
                        return False
                    device_filter['resourceType'] = 'APZONE'
                    device_filter['resourceEntity'][0]['label'] = ap_zone
                    device_filter['resourceEntity'][0]['value'] = apzone_uuid
                elif device_category == 'Access Point':
                    ap_info = self._get_ap_info(domain_label=domain_label,
                                                ap_ip=ap_ip)
                    if not ap_info:
                        print "create_report(): _get_ap_info() failed. ap_ip: %s" % ap_ip
                        return False
                    ap_mac = ap_info['apMac']
                    device_filter['resourceType'] = 'AP'
                    device_filter['resourceEntity'][0]['label'] = ap_label
                    device_filter['resourceEntity'][0]['value'] = ap_mac
                elif device_category == 'PLANE':
                    self._create_admin_api(jsessionid=self.jsessionid)
                    cblade_uuid = self._get_control_blade_uuid(
                        cblade_label=cblade_label)
                    if not cblade_uuid:
                        print "create_report(): _get_control_blade_uuid() failed. cblade_label: %s" % cblade_label
                        return False
                    device_filter['resourceType'] = 'PLANE'
                    device_filter['resourceEntity'][0]['label'] = cblade_label
                    device_filter['resourceEntity'][0]['value'] = cblade_uuid
                else:
                    print "create_report(): Invalid device_category: %s" % device_category
                    return False

                report_data['deviceFilter'] = device_filter

            if is_ssid_filter:
                ssid_filter = self.SJT.get_filter_template_data()
                device_filter['resourceType'] = 'SSID'
                device_filter['resourceEntity'][0]['label'] = ssid
                device_filter['resourceEntity'][0]['value'] = ssid

                report_data['ssidFilter'] = ssid_filter

            if is_radio_filter:
                radio_filter = self.SJT.get_filter_template_data()
                device_filter['resourceType'] = 'RADIO'
                device_filter['resourceEntity'][0][
                    'label'] = "1" if radio == '5G' else "0"
                device_filter['resourceEntity'][0][
                    'value'] = "1" if radio == '5G' else "0"

                report_data['radioFilter'] = radio_filter

            if enable_schedules:
                report_data['scheduleEnable'] = True
                report_data['schedules'][0]['interval'] = schedule_interval
                report_data['schedules'][0]['dateOfMonth'] = int(schedule_day)
                report_data['schedules'][0]['dayOfWeek'] = schedule_week
                report_data['schedules'][0]['hour'] = int(schedule_hour)
                report_data['schedules'][0]['minute'] = int(schedule_min)

            if enable_email_notifications:
                report_data['notificationEnable'] = True
                report_data['notifiedMailList'].append(email_id)

            if enable_export_results:
                report_data['ftpEnable'] = "true"
                report_data["ftpServer"] = {
                    "ftpHost": ftp_host,
                    "ftpPort": ftp_port,
                    "ftpUserName": ftp_username,
                    "ftpPassword": ftp_password,
                    "key": "",
                    "ftpRemoteDirectory":
                    ftp_remote_dir if ftp_remote_dir else "",
                }

            data_json = json.dumps(report_data)

            url = ji.get_url(self.req_api_reports, self.scg_mgmt_ip,
                             self.scg_port)
            result = ji.post_json_data(url, self.jsessionid, data_json)

            return result

        except Exception, e:
            print traceback.format_exc()
            return False