code: def stop_instance(self, instance_id):
          
          self._init_az_api()
  
          cluster_name, node_name = instance_id
          self._init_inventory(cluster_name)
  
          for name, api_version in [
                  # we must delete resources in a specific order: e.g.,
                  # a public IP address cannot be deleted if it's still
                  # in use by a NIC...
                  (node_name,                '2018-06-01'),
                  (node_name + '-nic',       '2018-10-01'),
                  (node_name + '-public-ip', '2018-10-01'),
                  (node_name + '-disk',      '2018-09-30'),
              (self._make_storage_account_name(
                      cluster_name, node_name),
                                             '2018-07-01'),
          ]:
              rsc_id = self._inventory[name]
              log.debug("Deleting resource %s (`%s`) ...", name, rsc_id)
              oper = self._resource_client.resources.delete_by_id(rsc_id, api_version)
              oper.wait()
              del self._inventory[name]
  
          self._vm_details.pop(node_name, None)
  
          # if this was the last VM to be deleted, clean up leftover resource group
          with self.__lock:
              if len(self._inventory) == 2:
                  log.debug("Cleaning up leftover resource group ...")
                  oper = self._resource_client.resource_groups.delete(cluster_name)
                  oper.wait()
                  self._inventory = {}
docs: Stops the instance gracefully.
  
          :param str instance_id: instance identifier