@@ -570,9 +570,10 @@ def set_definition(self, definition):
570570
571571class DSSCluster (object ):
572572 """
573- A cluster on the DSS instance
573+ A handle to interact with a cluster on the DSS instance
574574 """
575575 def __init__ (self , client , cluster_id ):
576+ """Do not call that directly, use :meth:`dataikuapi.dss.DSSClient.get_cluster`"""
576577 self .client = client
577578 self .cluster_id = cluster_id
578579
@@ -582,7 +583,7 @@ def __init__(self, client, cluster_id):
582583
583584 def delete (self ):
584585 """
585- Delete the cluster ( not stopping it)
586+ Deletes the cluster. This does not previously stop it.
586587 """
587588 self .client ._perform_empty (
588589 "DELETE" , "/admin/clusters/%s" % (self .cluster_id ))
@@ -592,26 +593,26 @@ def delete(self):
592593 # Cluster description
593594 ########################################################
594595
595- def get_definition (self ):
596+ def get_settings (self ):
596597 """
597- Get the cluster's definition
598-
599- Returns:
600- the cluster definition, as a JSON object
598+ Get the cluster's settings. This includes opaque data for the cluster if this is
599+ a started managed cluster.
600+
601+ The returned object can be used to save settings.
602+
603+ :returns: a :class:`DSSClusterSettings` object to interact with cluster settings
604+ :rtype: :class:`DSSClusterSettings`
601605 """
602- return self .client ._perform_json (
606+ settings = self .client ._perform_json (
603607 "GET" , "/admin/clusters/%s" % (self .cluster_id ))
608+ return DSSClusterSettings (self .client , self .cluster_id , settings )
604609
605610 def set_definition (self , cluster ):
606611 """
607612 Set the cluster's definition. The definition should come from a call to the get_definition()
608613 method.
609614
610- Fields that can be updated :
611-
612- * cluster.permissions, cluster.usableByAll, cluster.owner
613- * cluster.params
614-
615+
615616 :param cluster: a cluster definition
616617
617618 Returns:
@@ -622,41 +623,87 @@ def set_definition(self, cluster):
622623
623624 def get_status (self ):
624625 """
625- Get the cluster's status and usages
626-
627- Returns:
628- the cluster status, as a JSON object
629- """
630- return self .client ._perform_json (
631- "GET" , "/admin/clusters/%s/status" % (self .cluster_id ))
626+ Get the cluster's status and usage
632627
628+ :returns: The cluster status, as a :class:`DSSClusterStatus` object
629+ :rtype: :class:`DSSClusterStatus`
630+ """
631+ status = self .client ._perform_json ("GET" , "/admin/clusters/%s/status" % (self .cluster_id ))
632+ return DSSClusterStatus (self .client , self .cluster_id , status )
633633
634634 ########################################################
635635 # Cluster actions
636636 ########################################################
637637
638638 def start (self ):
639639 """
640- Starts the cluster
640+ Starts or attaches the cluster.
641+
642+ This operation is only valid for a managed cluster.
641643 """
642644 resp = self .client ._perform_json (
643- "POST" , "/admin/clusters/%s/start" % (self .cluster_id ))
645+ "POST" , "/admin/clusters/%s/actions/ start" % (self .cluster_id ))
644646 if resp is None :
645647 raise Exception ('Env update returned no data' )
646648 if resp .get ('messages' , {}).get ('error' , False ):
647649 raise Exception ('Cluster operation failed : %s' % (json .dumps (resp .get ('messages' , {}).get ('messages' , {}))))
648650 return resp
649651
650-
651652 def stop (self ):
652653 """
653- Stops the cluster
654+ Stops or detaches the cluster
655+
656+ This operation is only valid for a managed cluster.
654657 """
655658 resp = self .client ._perform_json (
656- "POST" , "/admin/clusters/%s/stop" % (self .cluster_id ))
659+ "POST" , "/admin/clusters/%s/actions/ stop" % (self .cluster_id ))
657660 if resp is None :
658661 raise Exception ('Env update returned no data' )
659662 if resp .get ('messages' , {}).get ('error' , False ):
660663 raise Exception ('Cluster operation failed : %s' % (json .dumps (resp .get ('messages' , {}).get ('messages' , {}))))
661664 return resp
662665
666+ class DSSClusterSettings (object ):
667+ def __init__ (self , client , cluster_id , settings ):
668+ """Do not call directly, use :meth:`DSSCluster.get_settings`"""
669+ self .client = client
670+ self .cluster_id = cluster_id
671+ self .settings = settings
672+
673+ def get_raw (self ):
674+ """
675+ Gets all settings as a raw dictionary. This returns a reference to the raw settings, not a copy,
676+ so changes made to the returned object will be reflected when saving.
677+
678+ Fields that can be updated:
679+ - permissions, usableByAll, owner
680+ - params
681+ """
682+ return self .settings
683+
684+ def get_plugin_data (self ):
685+ """
686+ If this is a managed attached cluster, returns the opaque data returned by the cluster's start
687+ operation. Else, returns None.
688+
689+ You should generally not modify this
690+ """
691+ return self .settings .get ("data" , None )
692+
693+ def save (self ):
694+ """Saves back the settings to the cluster"""
695+ return self .client ._perform_json (
696+ "PUT" , "/admin/clusters/%s" % (self .cluster_id ), body = self .settings )
697+
698+ class DSSClusterStatus (object ):
699+ def __init__ (self , client , cluster_id , settings ):
700+ """Do not call directly, use :meth:`DSSCluster.get_Status`"""
701+ self .client = client
702+ self .cluster_id = cluster_id
703+ self .status = status
704+
705+ def get_raw (self ):
706+ """
707+ Gets the whole status as a raw dictionary.
708+ """
709+ return self .status
0 commit comments