def _initSystem(self): logger.info("[Stage %d] Initializing system" % self._nextStage()) # Set admin password pw = urllib.quote(self.configMap[pdesc.PARAM_MASTER_PASSWORD], '') hp = json.loads( rest_lib.get("core/aaa/hash-password[password=\"%s\"]" % (pw))) if len(hp) == 0: raise Exception("Failed to update password") rest_lib.put("core/aaa/local-user[user-name=\"admin\"]/password", json.dumps(hp[0]['hashed-password'])) # Set recovery password setPass = { "user-name": "recovery", "password": self.configMap[pdesc.PARAM_RECOVERY_PASSWORD] } rest_lib.post("os/action/system-user/reset-password", json.dumps(setPass)) # Initialize SSL certificate and SSH key logger.info(" Generating cryptographic keys") regenerateKeys = {"action": ["web-ssl", "ssh"]} rest_lib.post("os/action/services/regenerate-keys", json.dumps(regenerateKeys))
def _configController(self): logger.info("[Stage %d] Configuring controller" % self._nextStage()) # Set up local node configuration if (self.configMap[pdesc.PARAM_IP_MODE] == pdesc.IP_STATIC): iface = {"type": "Ethernet", "number": 0, "config-mode": "static", "ip-address": getv(self.configMap,pdesc.PARAM_IP_ADDRESS), "netmask": getv(self.configMap,pdesc.PARAM_IP_NETMASK)} else: iface = {"type": "Ethernet", "number": 0, "config-mode": "dhcp"} networkConfig = {"default-gateway": getv(self.configMap, pdesc.PARAM_IP_GATEWAY), "domain-lookups-enabled": True, "dns-search-path": getl(self.configMap,pdesc.PARAM_DOMAIN), "dns-servers": getl(self.configMap,pdesc.PARAM_DNS), "network-interfaces": [iface]} timeConfig = {} if (self.configMap[pdesc.PARAM_CLUSTER_OPTION] == pdesc.ROLE_MASTER): timeConfig = {"ntp-servers": [self.configMap[pdesc.PARAM_NTP]]} cnode = {"network-config": networkConfig, "time-config": timeConfig} osconfig = {"local-node": cnode} #print json.dumps(osconfig, indent=2) rest_lib.put("os/config", json.dumps(osconfig)) logger.info(" Waiting for network configuration") if (not self._waitForNetwork()): raise Exception("Could not acquire a usable IP address on eth0") logger.info(" IP address on eth0 is %s" % self.ipAddr) # Retrieve time configuration from remote node and copy locally if (self.configMap[pdesc.PARAM_CLUSTER_OPTION] == pdesc.ROLE_SLAVE): mip = self.configMap[pdesc.PARAM_MASTER_IP] host = "%s:8443" % mip rest_lib.auth(host, password=self.configMap[pdesc.PARAM_MASTER_PASSWORD]) time_config = json.loads(rest_lib.request("os/config/local-node/time-config", host="%s:8443" % mip, secure=True)) if (len(time_config) == 0): raise Exception("Could not retrieve time configuration from %s" % mip) time_config = time_config[0] if ('ntp-servers' in time_config and len(time_config['ntp-servers']) > 0): self.configMap[pdesc.PARAM_NTP] = time_config['ntp-servers'][0] rest_lib.put("os/config/local-node/time-config", json.dumps(time_config)) # Set system time using ntpdate logger.info(" Retrieving time from NTP server %s" % self.configMap[pdesc.PARAM_NTP]) ntpAction = {"ntp-server": self.configMap[pdesc.PARAM_NTP]} rest_lib.post("os/action/time/ntp", json.dumps(ntpAction))
def _initSystem(self): logger.info("[Stage %d] Initializing system" % self._nextStage()) # Set admin password pw = urllib.quote(self.configMap[pdesc.PARAM_MASTER_PASSWORD], '') hp = json.loads(rest_lib.get("core/aaa/hash-password[password=\"%s\"]" % (pw))) if len(hp) == 0: raise Exception("Failed to update password") rest_lib.put("core/aaa/local-user[user-name=\"admin\"]/password", json.dumps(hp[0]['hashed-password'])) # Set recovery password setPass = {"user-name": "recovery", "password": self.configMap[pdesc.PARAM_RECOVERY_PASSWORD]} rest_lib.post("os/action/system-user/reset-password", json.dumps(setPass)) # Initialize SSL certificate and SSH key logger.info(" Generating cryptographic keys") regenerateKeys = {"action": ["web-ssl", "ssh"]} rest_lib.post("os/action/services/regenerate-keys", json.dumps(regenerateKeys))
def _configController(self): logger.info("[Stage %d] Configuring controller" % self._nextStage()) # Set up local node configuration if (self.configMap[pdesc.PARAM_IP_MODE] == pdesc.IP_STATIC): iface = { "type": "Ethernet", "number": 0, "config-mode": "static", "ip-address": getv(self.configMap, pdesc.PARAM_IP_ADDRESS), "netmask": getv(self.configMap, pdesc.PARAM_IP_NETMASK) } else: iface = {"type": "Ethernet", "number": 0, "config-mode": "dhcp"} networkConfig = { "default-gateway": getv(self.configMap, pdesc.PARAM_IP_GATEWAY), "domain-lookups-enabled": True, "dns-search-path": getl(self.configMap, pdesc.PARAM_DOMAIN), "dns-servers": getl(self.configMap, pdesc.PARAM_DNS), "network-interfaces": [iface] } timeConfig = {} if (self.configMap[pdesc.PARAM_CLUSTER_OPTION] == pdesc.ROLE_MASTER): timeConfig = {"ntp-servers": [self.configMap[pdesc.PARAM_NTP]]} cnode = {"network-config": networkConfig, "time-config": timeConfig} osconfig = {"local-node": cnode} #print json.dumps(osconfig, indent=2) rest_lib.put("os/config", json.dumps(osconfig)) logger.info(" Waiting for network configuration") if (not self._waitForNetwork()): raise Exception("Could not acquire a usable IP address on eth0") logger.info(" IP address on eth0 is %s" % self.ipAddr) # Retrieve time configuration from remote node and copy locally if (self.configMap[pdesc.PARAM_CLUSTER_OPTION] == pdesc.ROLE_SLAVE): mip = self.configMap[pdesc.PARAM_MASTER_IP] host = "%s:8443" % mip rest_lib.auth(host, password=self.configMap[pdesc.PARAM_MASTER_PASSWORD]) time_config = json.loads( rest_lib.request("os/config/local-node/time-config", host="%s:8443" % mip, secure=True)) if (len(time_config) == 0): raise Exception( "Could not retrieve time configuration from %s" % mip) time_config = time_config[0] if ('ntp-servers' in time_config and len(time_config['ntp-servers']) > 0): self.configMap[pdesc.PARAM_NTP] = time_config['ntp-servers'][0] rest_lib.put("os/config/local-node/time-config", json.dumps(time_config)) # Set system time using ntpdate logger.info(" Retrieving time from NTP server %s" % self.configMap[pdesc.PARAM_NTP]) ntpAction = {"ntp-server": self.configMap[pdesc.PARAM_NTP]} rest_lib.post("os/action/time/ntp", json.dumps(ntpAction))