Пример #1
0
    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))
Пример #2
0
    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))
Пример #3
0
    def _configCluster(self):
        logger.info("[Stage %d] Configuring cluster" % self._nextStage())
        if self._clusterConfigured():
            logger.info("  Cluster is already configured")
            return

        # Set up controller cluster
        if (self.configMap[pdesc.PARAM_CLUSTER_OPTION] == pdesc.ROLE_MASTER):
            cconfig = {
                "seeds": "",
                "local-domain-id": 1,
                "local-node-auth": {
                    "cluster-secret": ""
                }
            }
            rest_lib.post("cluster/config", json.dumps(cconfig))

        elif (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])

            # Retrieve cluster secret
            secret = \
                json.loads(rest_lib.request("cluster/config/local-node-auth/cluster-secret",
                                            host=host, secure=True))
            if (len(secret) == 0):
                raise Exception("Could not retrieve cluster secret from %s" %
                                mip)
            secret = secret[0]

            # Join cluster
            cconfig = {
                "seeds": "%s:6642" % mip,
                "local-domain-id": 1,
                "local-node-auth": {
                    "cluster-secret": secret
                }
            }

            rest_lib.post("cluster/config", json.dumps(cconfig))

        if self._waitForCluster():
            self._displayCluster()
        else:
            raise Exception("Failed to configure clustering: %s" %
                            self.clusterError)
Пример #4
0
    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))
Пример #5
0
    def _configCluster(self):
        logger.info("[Stage %d] Configuring cluster" % self._nextStage())
        if self._clusterConfigured():
            logger.info("  Cluster is already configured")
            return

        # Set up controller cluster
        if (self.configMap[pdesc.PARAM_CLUSTER_OPTION] == pdesc.ROLE_MASTER):
            cconfig = {"seeds": "", 
                       "local-domain-id": 1,
                       "local-node-auth": {"cluster-secret": ""}}
            rest_lib.post("cluster/config", json.dumps(cconfig))
            
        elif (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])

            # Retrieve cluster secret
            secret = \
                json.loads(rest_lib.request("cluster/config/local-node-auth/cluster-secret",
                                            host=host, secure=True))
            if (len(secret) == 0):
                raise Exception("Could not retrieve cluster secret from %s" % mip)
            secret = secret[0]

            # Join cluster
            cconfig = {"seeds": "%s:6642" % mip,
                       "local-domain-id": 1,
                       "local-node-auth": {"cluster-secret": secret}}
            
            rest_lib.post("cluster/config", json.dumps(cconfig))
            
        if self._waitForCluster():
            self._displayCluster()
        else:
            raise Exception("Failed to configure clustering: %s" % self.clusterError)
Пример #6
0
 def _configAdminUser(self):
     setShell = {"user-name": "admin",
                 "shell": "cli"}
     rest_lib.post("os/action/system-user/set-shell", json.dumps(setShell))
Пример #7
0
    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))
Пример #8
0
 def _configAdminUser(self):
     setShell = {"user-name": "admin", "shell": "cli"}
     rest_lib.post("os/action/system-user/set-shell", json.dumps(setShell))