@@ -140,6 +140,7 @@ def instance_create(
140140 region ,
141141 image = None ,
142142 authorized_keys = None ,
143+ root_pass = None ,
143144 firewall : Optional [Union [Firewall , int ]] = None ,
144145 backup : Optional [Union [Backup , int ]] = None ,
145146 stackscript : Optional [Union [StackScript , int ]] = None ,
@@ -280,10 +281,18 @@ def instance_create(
280281 :type ltype: str or Type
281282 :param region: The Region in which we are creating the Instance
282283 :type region: str or Region
283- :param image: The Image to deploy to this Instance. If this is provided
284- and no root_pass is given, a password will be generated
285- and returned along with the new Instance.
284+ :param image: The Image to deploy to this Instance.
286285 :type image: str or Image
286+ :param authorized_keys: The ssh public keys to install in the linode's
287+ /root/.ssh/authorized_keys file. Each entry may
288+ be a single key, or a path to a file containing
289+ the key. At least one of authorized_keys or
290+ root_pass is required.
291+ :type authorized_keys: list or str
292+ :param root_pass: The root password for the new Instance. At least one
293+ of root_pass or authorized_keys is required. Both may
294+ be provided.
295+ :type root_pass: str
287296 :param stackscript: The StackScript to deploy to the new Instance. If
288297 provided, "image" is required and must be compatible
289298 with the chosen StackScript.
@@ -295,11 +304,6 @@ def instance_create(
295304 :param backup: The Backup to restore to the new Instance. May not be
296305 provided if "image" is given.
297306 :type backup: int of Backup
298- :param authorized_keys: The ssh public keys to install in the linode's
299- /root/.ssh/authorized_keys file. Each entry may
300- be a single key, or a path to a file containing
301- the key.
302- :type authorized_keys: list or str
303307 :param label: The display label for the new Instance
304308 :type label: str
305309 :param group: The display group for the new Instance
@@ -337,25 +341,27 @@ def instance_create(
337341 If not provided, the default policy (linode/migrate) will be applied.
338342 :type maintenance_policy: str
339343
340- :returns: A new Instance object, or a tuple containing the new Instance and
341- the generated password.
342- :rtype: Instance or tuple(Instance, str)
344+ :returns: A new Instance object.
345+ :rtype: Instance
346+ :raises ValueError: If neither root_pass nor authorized_keys is provided.
343347 :raises ApiError: If contacting the API fails
344348 :raises UnexpectedResponseError: If the API response is somehow malformed.
345349 This usually indicates that you are using
346350 an outdated library.
347351 """
348352
349- ret_pass = None
350- if image and not "root_pass" in kwargs :
351- ret_pass = Instance .generate_root_password ()
352- kwargs ["root_pass" ] = ret_pass
353+ # Validation: require at least one of root_pass or authorized_keys
354+ if not root_pass and not authorized_keys :
355+ raise ValueError (
356+ "At least one of root_pass or authorized_keys is required."
357+ )
353358
354359 params = {
355360 "type" : ltype ,
356361 "region" : region ,
357362 "image" : image ,
358363 "authorized_keys" : load_and_validate_keys (authorized_keys ),
364+ "root_pass" : root_pass ,
359365 # These will automatically be flattened below
360366 "firewall_id" : firewall ,
361367 "backup_id" : backup ,
@@ -388,9 +394,7 @@ def instance_create(
388394 )
389395
390396 l = Instance (self .client , result ["id" ], result )
391- if not ret_pass :
392- return l
393- return l , ret_pass
397+ return l
394398
395399 @staticmethod
396400 def build_instance_metadata (user_data = None , encode_user_data = True ):
0 commit comments