def add_kubernetes(self, *args, **kwargs): banner("PCC.K8s Create Cluster") self._load_kwargs(kwargs) conn = BuiltIn().get_variable_value("${PCC_CONN}") tmp_node = [] for node_name in eval(str(self.nodes)): node_id = easy.get_node_id_by_name(conn, node_name) tmp_node.append({"id": node_id}) self.nodes = tmp_node tmp_pool = [] if self.pools: for pool in eval(str(self.pools)): tmp_pool.append(easy.get_ceph_pool_id_by_name(conn, pool)) self.pools = tmp_pool if self.networkClusterName: self.networkClusterId = easy.get_network_clusters_id_by_name( conn, self.networkClusterName) payload = { "id": int(self.id), "k8sVersion": self.k8sVersion, "cniPlugin": self.cniPlugin, "name": self.name, "nodes": self.nodes, "pools": self.pools, "networkClusterId": self.networkClusterId } print("paylod:-" + str(payload)) return pcc.add_kubernetes(conn, payload)
def add_ceph_cluster(self, *args, **kwargs): banner("PCC.Ceph Create Cluster") self._load_kwargs(kwargs) print("Kwargs:" + str(kwargs)) conn = BuiltIn().get_variable_value("${PCC_CONN}") tmp_node = [] for node_name in eval(str(self.nodes)): print("Getting Node Id for -" + str(node_name)) node_id = easy.get_node_id_by_name(conn, node_name) print(" Node Id retrieved -" + str(node_id)) tmp_node.append({"id": node_id}) self.nodes = tmp_node if self.tags: self.tags = eval(str(self.tags)) self.networkClusterId = easy.get_network_clusters_id_by_name( conn, self.networkClusterName) payload = { "name": self.name, "nodes": self.nodes, "tags": self.tags, "networkClusterId": self.networkClusterId } print("Payload:-" + str(payload)) return pcc.add_ceph_cluster(conn, payload)
def upgrade_kubernetes_by_id(self, *args, **kwargs): banner("PCC.K8s Upgrade Cluster") self._load_kwargs(kwargs) conn = BuiltIn().get_variable_value("${PCC_CONN}") tmp_pool = [] if self.pools: for pool in eval(str(self.pools)): tmp_pool.append(easy.get_ceph_pool_id_by_name(conn, pool)) self.pools = tmp_pool if self.networkClusterName: self.networkClusterId = easy.get_network_clusters_id_by_name( conn, self.networkClusterName) payload = { "k8sVersion": self.k8sVersion, "pools": self.pools, "networkClusterId": self.networkClusterId } if self.cluster_id == None: raise Exception( "[PCC.Upgrade Cluster]: cluster id is not specified.") else: return pcc.upgrade_kubernetes_by_id(conn, str(self.cluster_id), payload)
def modify_ceph_clusters(self, *args, **kwargs): self._load_kwargs(kwargs) print("Kwargs:" + str(kwargs)) conn = BuiltIn().get_variable_value("${PCC_CONN}") time.sleep(60) tmp_node = [] payload_nodes = [] for node_name in eval(str(self.nodes)): node_id = easy.get_node_id_by_name(conn, node_name) tmp_node.append(node_id) self.nodes = [] response = pcc.get_ceph_clusters(conn) for data in get_response_data(response): if str(data['name']).lower() == str(self.name).lower(): payload_nodes = eval(str(data['nodes'])) if not self.tags: self.tags = data['tags'] if not self.name: self.name = data['name'] if not self.networkClusterName: self.networkClusterId = data['networkClusterId'] else: self.networkClusterId = easy.get_network_clusters_id_by_name( conn, self.networkClusterName) for id in tmp_node: count = 0 for data in payload_nodes: if int(data['id']) == int(id): self.nodes.append(data) count = 1 if count == 0: self.nodes.append({"id": int(id)}) if self.tags: self.tags = eval(str(self.tags)) try: payload = { "id": self.id, "name": self.name, "nodes": self.nodes, "tags": self.tags, "networkClusterId": self.networkClusterId } print("Payload:-" + str(payload)) except Exception as e: trace("[update_cluster] EXCEPTION: %s" % str(e)) raise Exception(e) return pcc.modify_ceph_clusters(conn, payload)