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 _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)
def auth(self, server, username=bsn_api.username, password=bsn_api.password): login = {"user": username, "password": password} host = "%s:%d" % (server, self.port) log.info("PRE AUTH: Host: %s\t user: %s password: %s" % (server, username, password)) ret = rest_lib.request("/api/v1/auth/login", prefix='', method='POST', data=json.dumps(login), host=host) session = json.loads(ret[2]) if ret[0] != 200: raise Exception(session["error_message"]) if ("session_cookie" not in session): raise Exception("Failed to authenticate: session cookie not set") return session["session_cookie"]
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)
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))