Skip to content

Commit 3238f3d

Browse files
committed
Add shared manipulation
1 parent d565641 commit 3238f3d

File tree

5 files changed

+125
-1
lines changed

5 files changed

+125
-1
lines changed

dataikuapi/dss/dataset.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -536,6 +536,26 @@ def move_to_zone(self, zone):
536536
zone = self.project.get_flow().get_zone(zone)
537537
zone.add_item(self)
538538

539+
def share_to_zone(self, zone):
540+
"""
541+
Share this object to a flow zone
542+
543+
:param object zone: a :class:`dataikuapi.dss.flow.DSSFlowZone` where to share the object
544+
"""
545+
if isinstance(zone, basestring):
546+
zone = self.project.get_flow().get_zone(zone)
547+
zone.add_shared(self)
548+
549+
def unshare_from_zone(self, zone):
550+
"""
551+
Unshare this object from a flow zone
552+
553+
:param object zone: a :class:`dataikuapi.dss.flow.DSSFlowZone` from where to unshare the object
554+
"""
555+
if isinstance(zone, basestring):
556+
zone = self.project.get_flow().get_zone(zone)
557+
zone.remove_shared(self)
558+
539559
def get_usages(self):
540560
"""
541561
Get the recipes or analyses referencing this dataset

dataikuapi/dss/flow.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,10 @@ def id(self):
189189
def name(self):
190190
return self._raw["name"]
191191

192+
@property
193+
def color(self):
194+
return self._raw["color"]
195+
192196
def __repr__(self):
193197
return "<dataikuapi.dss.flow.DSSFlowZone (id=%s, name=%s)>" % (self.id, self.name)
194198

@@ -248,6 +252,28 @@ def items(self):
248252
"""
249253
return [self._to_native_obj(i) for i in self._raw["items"]]
250254

255+
def add_shared(self, obj):
256+
"""
257+
Share an item to this zone.
258+
259+
The item will not be automatically unshared from its existing zone.
260+
261+
:param object obj: A :class:`dataikuapi.dss.dataset.DSSDataset`, :class:`dataikuapi.dss.managedfolder.DSSManagedFolder`,
262+
or :class:`dataikuapi.dss.savedmodel.DSSSavedModel` to share to the zone
263+
"""
264+
self._raw = self.client._perform_json("POST", "/projects/%s/flow/zones/%s/shared" % (self.flow.project.project_key, self.id),
265+
body=self.flow._to_smart_ref(obj))
266+
267+
def remove_shared(self, obj):
268+
"""
269+
Remove a shared item from this zone.
270+
271+
:param object obj: A :class:`dataikuapi.dss.dataset.DSSDataset`, :class:`dataikuapi.dss.managedfolder.DSSManagedFolder`,
272+
or :class:`dataikuapi.dss.savedmodel.DSSSavedModel` to share to the zone
273+
"""
274+
smartRef = self.flow._to_smart_ref(obj)
275+
self._raw = self.client._perform_json("DELETE", "/projects/%s/flow/zones/%s/shared/%s/%s" % (self.flow.project.project_key, self.id, smartRef['objectType'], smartRef['objectId']))
276+
251277
@property
252278
def shared(self):
253279
"""

dataikuapi/dss/managedfolder.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,26 @@ def move_to_zone(self, zone):
177177
zone = self.project.get_flow().get_zone(zone)
178178
zone.add_item(self)
179179

180+
def share_to_zone(self, zone):
181+
"""
182+
Share this object to a flow zone
183+
184+
:param object zone: a :class:`dataikuapi.dss.flow.DSSFlowZone` where to share the object
185+
"""
186+
if isinstance(zone, basestring):
187+
zone = self.project.get_flow().get_zone(zone)
188+
zone.add_shared(self)
189+
190+
def unshare_from_zone(self, zone):
191+
"""
192+
Unshare this object from a flow zone
193+
194+
:param object zone: a :class:`dataikuapi.dss.flow.DSSFlowZone` from where to unshare the object
195+
"""
196+
if isinstance(zone, basestring):
197+
zone = self.project.get_flow().get_zone(zone)
198+
zone.remove_shared(self)
199+
180200
def get_usages(self):
181201
"""
182202
Get the recipes referencing this folder

dataikuapi/dss/savedmodel.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,26 @@ def move_to_zone(self, zone):
145145
zone = self.project.get_flow().get_zone(zone)
146146
zone.add_item(self)
147147

148+
def share_to_zone(self, zone):
149+
"""
150+
Share this object to a flow zone
151+
152+
:param object zone: a :class:`dataikuapi.dss.flow.DSSFlowZone` where to share the object
153+
"""
154+
if isinstance(zone, basestring):
155+
zone = self.project.get_flow().get_zone(zone)
156+
zone.add_shared(self)
157+
158+
def unshare_from_zone(self, zone):
159+
"""
160+
Unshare this object from a flow zone
161+
162+
:param object zone: a :class:`dataikuapi.dss.flow.DSSFlowZone` from where to unshare the object
163+
"""
164+
if isinstance(zone, basestring):
165+
zone = self.project.get_flow().get_zone(zone)
166+
zone.remove_shared(self)
167+
148168
def get_usages(self):
149169
"""
150170
Get the recipes referencing this model

dataikuapi/dss/streaming_endpoint.py

Lines changed: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,9 +136,47 @@ def set_schema(self, schema):
136136
body=schema)
137137

138138
########################################################
139-
# Usages
139+
# Misc
140140
########################################################
141141

142+
def get_zone(self):
143+
"""
144+
Gets the flow zone of this streaming endpoint
145+
146+
:rtype: :class:`dataikuapi.dss.flow.DSSFlowZone`
147+
"""
148+
return self.project.get_flow().get_zone_of_object(self)
149+
150+
def move_to_zone(self, zone):
151+
"""
152+
Moves this object to a flow zone
153+
154+
:param object zone: a :class:`dataikuapi.dss.flow.DSSFlowZone` where to move the object
155+
"""
156+
if isinstance(zone, basestring):
157+
zone = self.project.get_flow().get_zone(zone)
158+
zone.add_item(self)
159+
160+
def share_to_zone(self, zone):
161+
"""
162+
Share this object to a flow zone
163+
164+
:param object zone: a :class:`dataikuapi.dss.flow.DSSFlowZone` where to share the object
165+
"""
166+
if isinstance(zone, basestring):
167+
zone = self.project.get_flow().get_zone(zone)
168+
zone.add_shared(self)
169+
170+
def unshare_from_zone(self, zone):
171+
"""
172+
Unshare this object from a flow zone
173+
174+
:param object zone: a :class:`dataikuapi.dss.flow.DSSFlowZone` from where to unshare the object
175+
"""
176+
if isinstance(zone, basestring):
177+
zone = self.project.get_flow().get_zone(zone)
178+
zone.remove_shared(self)
179+
142180
def get_usages(self):
143181
"""
144182
Get the recipes or analyses referencing this streaming endpoint

0 commit comments

Comments
 (0)