diff --git a/dataikuapi/fm/instances.py b/dataikuapi/fm/instances.py index 51301f21..93b2e92e 100644 --- a/dataikuapi/fm/instances.py +++ b/dataikuapi/fm/instances.py @@ -229,6 +229,44 @@ def delete(self): ) return FMFuture.from_resp(self.client, future) + def get_initial_password(self): + """ + Get the initial DSS admin password. + + Can only be called once + + :return: a password for the 'admin' user. + """ + return self.client._perform_tenant_json( + "GET", "/instances/%s/actions/get-initial-password" % self.id + ) + + def reset_user_password(self, username, password): + """ + Reset the password for a user on the DSS instance + + :param string username: login + :param string password: new password + :return: A :class:`~dataikuapi.fm.future.FMFuture` representing the password reset process + :rtype: :class:`~dataikuapi.fm.future.FMFuture` + """ + future = self.client._perform_tenant_json( + "GET", "/instances/%s/actions/reset-user-password" % self.id, params={ 'userName':username, 'password':password } + ) + return FMFuture.from_resp(self.client, future) + + def replay_setup_actions(self): + """ + Replay the setup actions on the DSS instance + + :return: A :class:`~dataikuapi.fm.future.FMFuture` representing the replay process + :rtype: :class:`~dataikuapi.fm.future.FMFuture` + """ + future = self.client._perform_tenant_json( + "GET", "/instances/%s/actions/replay-setup-actions" % self.id + ) + return FMFuture.from_resp(self.client, future) + def set_automated_snapshots(self, enable, period, keep=0): """ Set the automated snapshots policy for this instance @@ -254,6 +292,43 @@ def set_custom_certificate(self, pem_data): return self + ######################################################## + # Snapshots + ######################################################## + + def list_snapshots(self): + """ + List all snapshots of this instance + + :return: list of snapshots + :rtype: list of :class:`dataikuapi.fm.instances.FMSnapshot` + """ + snapshots = self.client._perform_tenant_json("GET", "/instances/%s/snapshots" % self.id) + return [FMSnapshot(self.client, self.id, x["id"], x) for x in snapshots] + + def get_snapshot(self, snapshot_id): + """ + Get a snapshot of this instance + + :param str snapshot_id: identifier of the snapshot + + :return: Snapshot + :rtype: :class:`dataikuapi.fm.instances.FMSnapshot` + """ + return FMSnapshot(self.client, self.id, snapshot_id) + + def snapshot(self, reason_for_snapshot=None): + """ + Create a snapshot of the DSS instance + + :return: Snapshot + :rtype: :class:`dataikuapi.fm.instances.FMSnapshot` + """ + snapshot = self.client._perform_tenant_json( + "POST", "/instances/%s/snapshots" % self.id, params={ "reasonForSnapshot":reason_for_snapshot } + ) + return FMSnapshot(self.client, self.id, snapshot["id"], snapshot) + class FMAWSInstance(FMInstance): def set_elastic_ip(self, enable, elasticip_allocation_id): """ @@ -295,3 +370,53 @@ class FMInstanceStatus(dict): def __init__(self, data): """Do not call this directly, use :meth:`FMInstance.get_status`""" super(FMInstanceStatus, self).__init__(data) + + +class FMSnapshot(object): + """ + A handle to interact with a snapshot of a DSS instance. + Do not create this directly, use :meth:`FMInstance.snapshot` + """ + + def __init__(self, client, instance_id, snapshot_id, snapshot_data=None): + self.client = client + self.instance_id = instance_id + self.snapshot_id = snapshot_id + self.snapshot_data = snapshot_data + + def get_info(self): + """ + Get the information about this snapshot + + :return: a dict + """ + if self.snapshot_data is None: + self.snapshot_data = self.client._perform_tenant_json( + "GET", "/instances/%s/snapshots/%s" % (self.instance_id, self.snapshot_id) + ) + return self.snapshot_data + + def reprovision(self): + """ + Reprovision the physical DSS instance from this snapshot + + :return: A :class:`~dataikuapi.fm.future.FMFuture` representing the reprovision process + :rtype: :class:`~dataikuapi.fm.future.FMFuture` + """ + future = self.client._perform_tenant_json( + "POST", "/instances/%s/snapshots/%s/reprovision" % (self.instance_id, self.snapshot_id) + ) + return FMFuture.from_resp(self.client, future) + + def delete(self): + """ + Delete the snapshot + + :return: A :class:`~dataikuapi.fm.future.FMFuture` representing the deletion process + :rtype: :class:`~dataikuapi.fm.future.FMFuture` + """ + future = self.client._perform_tenant_json( + "DELETE", "/instances/%s/snapshots/%s" % (self.instance_id, self.snapshot_id) + ) + return FMFuture.from_resp(self.client, future) + diff --git a/dataikuapi/fm/virtualnetworks.py b/dataikuapi/fm/virtualnetworks.py index 35aae048..3419f420 100644 --- a/dataikuapi/fm/virtualnetworks.py +++ b/dataikuapi/fm/virtualnetworks.py @@ -10,6 +10,7 @@ def __init__(self, client, label): """ self.client = client self.data = {} + self.use_default_values = False self.data["label"] = label self.data["mode"] = "EXISTING_MONOTENANT" @@ -25,6 +26,13 @@ def with_internet_access_mode(self, internet_access_mode): self.data["internetAccessMode"] = internet_access_mode return self + def with_default_values(self): + """ + Setup the VPC and Subnet to with the default values: the vpc and subnet of the FM instance + """ + self.use_default_values = True + return self + class FMAWSVirtualNetworkCreator(FMVirtualNetworkCreator): def with_vpc(self, aws_vpc_id, aws_subnet_id): @@ -63,7 +71,7 @@ def create(self): :rtype: :class:`dataikuapi.fm.virtualnetworks.FMAWSVirtualNetwork` """ vn = self.client._perform_tenant_json( - "POST", "/virtual-networks", body=self.data + "POST", "/virtual-networks", body=self.data, params={ 'useDefaultValues':self.use_default_values } ) return FMAWSVirtualNetwork(self.client, vn) @@ -97,7 +105,7 @@ def create(self): :rtype: :class:`dataikuapi.fm.virtualnetworks.FMAzureVirtualNetwork` """ vn = self.client._perform_tenant_json( - "POST", "/virtual-networks", body=self.data + "POST", "/virtual-networks", body=self.data, params={ 'useDefaultValues':self.use_default_values } ) return FMAzureVirtualNetwork(self.client, vn) diff --git a/dataikuapi/fmclient.py b/dataikuapi/fmclient.py index 1b8bc2db..ca88d807 100644 --- a/dataikuapi/fmclient.py +++ b/dataikuapi/fmclient.py @@ -185,6 +185,14 @@ def get_instance(self, instance_id): instance = self._perform_tenant_json("GET", "/instances/%s" % instance_id) return self._make_instance(instance) + def list_instance_images(self): + """ + List all available images to create new instances + + :return: list of images, as a pair of id and label + """ + return self._perform_tenant_json("GET", "/images") + ######################################################## # Internal Request handling ########################################################