Exemple #1
0
 def changeAdminPassword(self, oldPassword):
     logger.info("Configuring the administrator password")
     endpoint = "/core/admin_cfg"
     
     logger.debug("GET to verify that old password is working")
     HTTPRequest.ISAMRestClient = ISAMRestClient("",username = self.USERNAME, password = oldPassword) 
     statusCode, contentHeader, content = ISAMRestClient.get(HTTPRequest.ISAMRestClient, self.BASEURL, endpoint, "application/json", "", "application/json", "", "")
     # sessionTimeout will be -1 if the old password is incorrect
     sessionTimeout = -1
     if statusCode == 200:
         sessionTimeout = json.loads(content)[u'sessionTimeout']  
         if(sessionTimeout > 0):
             HTTPRequest.ISAMRestClient = ISAMRestClient("",username = self.USERNAME, password = oldPassword) 
             jsonObj = {"sessionTimeout":str(sessionTimeout),"oldPassword":oldPassword,"newPassword":self.PASSWORD,"confirmPassword":self.PASSWORD} 
             data = json.dumps(jsonObj)
             logger.debug("PUT to change the password")
             statusCode, contentHeader, content = ISAMRestClient.put(HTTPRequest.ISAMRestClient, self.BASEURL, endpoint, "application/json", data)
             if statusCode == 200:
                 logger.debug("Successfully  POST to change password. Content returned : "+content+" Status Code returned : "+str(statusCode))
                 logger.info("Successfully configured the administrator password")
             else:
                 logger.error("Unsuccessful POST to change password. Content returned : "+content+" Status Code returned : "+str(statusCode))
         else:
             logger.error("A session timeout was not returned. Old password is incorrect or contact administrator")
     else: 
         logger.debug("Check if the new password is set")
         HTTPRequest.ISAMRestClient = ISAMRestClient("",username = self.USERNAME, password = self.PASSWORD)
         logger.debug("GET to verify that new password is already set and is working")
         statusCode, contentHeader, content = ISAMRestClient.get(HTTPRequest.ISAMRestClient, self.BASEURL, endpoint, "application/json", "", "application/json", "", "")
         if statusCode == 200:
             logger.debug("Successful GET. The password is set correctly. Content returned : "+content+" Status Code returned : "+str(statusCode))
         else:     
             logger.debug("Unsuccessful GET. The password is set incorrectly. Content returned : "+content+" Status Code returned : "+str(statusCode))
Exemple #2
0
    def configureDNS(self): 
        logger.debug("Configuring DNS")
        
        logger.debug("GET current DNS setting")
        
        HTTPRequest.ISAMRestClient = ISAMRestClient("",username = self.USERNAME, password = self.checkPassword())
        statusCode, contentHeader, content = ISAMRestClient.get(HTTPRequest.ISAMRestClient, self.BASEURL, self.ISAM_DNS_ENDPOINT, "application/json", "", "application/json", "", "")
                 
        if statusCode == 200:
            logger.debug("Successful GET current DNS. Content returned : "+content+" Status Code returned : "+str(statusCode))
            logger.info("Successfully configured DNS Setting")
        else:
            logger.debug("Unsuccessful GET current DNS. Content returned : "+content+" Status Code returned : "+str(statusCode))
        
        jsonObj = json.loads(content)    
        
        if jsonObj['auto'] == "True":
            logger.warn("DNS setting exists in the appliance. Exiting the DNS configuration")
        else:
            jsonObj['auto'] = False 
            jsonObj['primaryServer'] = self.DNS_STR 
            data = json.dumps(jsonObj)
            statusCode, contentHeader, content = ISAMRestClient.put(HTTPRequest.ISAMRestClient, self.BASEURL, self.ISAM_DNS_ENDPOINT, "application/json",data) 

            if statusCode == 200:
                logger.debug("Successful PUT of DNS. Content returned : "+content+" Status Code returned : "+str(statusCode))
            else:
                logger.error("Unsuccessful PUT of DNS. Content returned : "+content+" Status Code returned : "+str(statusCode))
                exit
Exemple #3
0
 def configureFirstSteps(self, username, password):
     logger.info("Configuring the appliance")
     HTTPRequest.ISAMRestClient = ISAMRestClient("",username = username, password = password) 
     statusCode, contentHeader, content = ISAMRestClient.put(HTTPRequest.ISAMRestClient, self.BASEURL, self.FIRST_STEPS, "application/json", None)
     if statusCode == 200 :
         logger.debug("SLA has been accepted, appliance has been configured")
     else:
         logger.debug("Unsuccessful PUT to configure the appliance"+content)
Exemple #4
0
    def configureInterface(self, ipv4Address, netmask):
        
        logger.info("Configuring Runtime Interfaces")
        logger.debug("GET current Interface setting")
        
        HTTPRequest.ISAMRestClient = ISAMRestClient("",username = self.USERNAME, password = self.checkPassword())
        statusCode, contentHeader, content = ISAMRestClient.get(HTTPRequest.ISAMRestClient, self.BASEURL, self.ISAM_INTERFACES_ENDPOINT, "application/jsonConverter", "", "application/jsonConverter", "", "")
        
        if statusCode == 200:
            logger.debug("Successful GET current Interface setting. Content returned : "+content+" Status Code returned : "+str(statusCode))
        else:
            logger.error("Unsuccessful GET current Interface setting. Content returned : "+content+" Status Code returned : "+str(statusCode))
        
        jsonObj = json.loads(content)   
        interface_1_1_json = jsonObj['interfaces'][0]
        interface_1_1_ipv4_addresses_json =interface_1_1_json['ipv4']['addresses']
        
        flagInterfaceSet = False
        
        noOfAddrs = len(interface_1_1_ipv4_addresses_json)
        i = 0
        for i in range(noOfAddrs):
            if interface_1_1_ipv4_addresses_json[i]['address'] == str(ipv4Address) and interface_1_1_ipv4_addresses_json[i]['allowManagement'] == False:
                logger.debug("Interface is already configured . Content returned : "+str(interface_1_1_ipv4_addresses_json[i]))
                flagInterfaceSet = True
         
        if flagInterfaceSet == False:       
            logger.debug("Configuring interface")

            uuidStr = uuid.uuid4()
            #The payload during a PUT that creates the interface
            addressPayload = {
                "maskOrPrefix": "255.255.255.0",
                "address": "10.1.16.90",
                "allowManagement": False,
                "uuid": "e7187407-43bd-4147-97db-ee537d738877",
                "objType": "ipv4Address",
                "enabled": True
            } 
            #Modify the payload
            addressPayload['maskOrPrefix'] = netmask
            addressPayload['address'] = ipv4Address
            addressPayload['uuid'] = str(uuidStr)
            
            jsonObj = json.loads(content)    
            # The code assumes only 1.1 is enabled and used
            interface1_payload = jsonObj[u'interfaces'][0]
            interface1_1_uuid = interface1_payload[u'uuid']
            interface1_payload[u'ipv4'][u'addresses'].append(addressPayload)
            data = json.dumps(interface1_payload)
            
            endpoint = self.ISAM_INTERFACES_ENDPOINT + str(interface1_1_uuid)
            statusCode, contentHeader, content = ISAMRestClient.put(HTTPRequest.ISAMRestClient, self.BASEURL, endpoint, "application/json", data)
            if statusCode == 200:
                logger.debug("Successful PUT of Interface. Content returned : "+content+" Status Code returned : "+str(statusCode))
                logger.info("Successfully configured Runtime Interfaces")
            else:
                logger.error("Unsuccessful PUT of Interface. Content returned : "+content+" Status Code returned : "+str(statusCode))
Exemple #5
0
 def acceptLicense(self, username,password):
     logger.info("Accepting the SLA")
     HTTPRequest.ISAMRestClient = ISAMRestClient("",username = username, password = password) 
     jsonData = {"accepted":"true"}
     jsonFinal = json.dumps(jsonData)
     statusCode, contentHeader, content = ISAMRestClient.put(HTTPRequest.ISAMRestClient, self.BASEURL, self.SERVICE_AGREEMENTS_ACCEPTED, "application/json", json.dumps(jsonData))
     if statusCode == 200:                   
         logger.debug("Successfully accepted SLA")
     else:
         logger.debug("Unsuccessful in accepting License"+content)
Exemple #6
0
 def configureNTP(self,ntp_server):    
     
     logger.info("Configuring NTP server")
      
     HTTPRequest.ISAMRestClient = ISAMRestClient("",username = self.USERNAME, password = self.checkPassword()) 
     
     jsonObj = {"dateTime":"0000-00-00 00:00:00","ntpServers":str(ntp_server),"timeZone":"Australia/Brisbane","enableNtp":True}
     data = json.dumps(jsonObj)
       
     statusCode, contentHeader, content = ISAMRestClient.put(HTTPRequest.ISAMRestClient, self.BASEURL, self.ISAM_NTP_ENDPOINT, "application/json", data)
      
     if statusCode == 200:
         logger.debug("Successful PUT to configure NTP setting. Content returned : "+content+" Status Code returned : "+str(statusCode))
         logger.info("Successfully configured NTP server")
     else:
         logger.error("Unuccessful PUT to configure NTP setting. Content returned : "+content+" Status Code returned : "+str(statusCode))
Exemple #7
0
    def changeEasuserPassword(self):
        logger.info("Configuring the easuser password")
        
        endpoint = "/mga/user_registry/users/easuser/v1"


        
        HTTPRequest.ISAMRestClient = ISAMRestClient("",username = self.USERNAME, password = self.checkPassword())
        jsonObj = {"password":self.EASUSER_PASSWORD}
        data = json.dumps(jsonObj)
        logger.debug("PUT to change the password")
        statusCode, contentHeader, content = ISAMRestClient.put(HTTPRequest.ISAMRestClient, self.BASEURL, endpoint, "application/json", data)
        if statusCode == 204:
            logger.debug("Successfully  POST to change easuser password. Content returned : "+content+" Status Code returned : "+str(statusCode))
            logger.info("Successfully configured the easuser password")
        else:
            logger.error("Unsuccessful POST to change easuser password. Content returned : "+content+" Status Code returned : "+str(statusCode))