Skip to content

Commit dca2302

Browse files
authored
Properly pass through distro usernames, don't assume ubuntu. (canonical#302)
Currently azure and ec2 assume username "ubuntu", which breaks other distributions using pycloudlib. Fix it.
1 parent 2e53717 commit dca2302

File tree

6 files changed

+16
-9
lines changed

6 files changed

+16
-9
lines changed

VERSION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
1!2.1.1
1+
1!2.1.2

pycloudlib/azure/cloud.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ def __init__(
7171
subscription_id: Optional[str] = None,
7272
tenant_id: Optional[str] = None,
7373
region: Optional[str] = None,
74+
username: Optional[str] = None,
7475
):
7576
"""Initialize the connection to Azure.
7677
@@ -103,7 +104,7 @@ def __init__(
103104

104105
self._log.debug("logging into Azure")
105106
self.location = region or self.config.get("region") or "centralus"
106-
self.username = "ubuntu"
107+
self.username = username or "ubuntu"
107108

108109
self.registered_instances: Dict[str, AzureInstance] = {}
109110
self.registered_images: Dict[str, dict] = {}
@@ -588,6 +589,7 @@ def launch(
588589
wait=True,
589590
name=None,
590591
inbound_ports=None,
592+
username=None,
591593
**kwargs,
592594
):
593595
"""Launch virtual machine on Azure.
@@ -693,6 +695,7 @@ def launch(
693695
key_pair=self.key_pair,
694696
client=self.compute_client,
695697
instance=instance_info,
698+
username=username,
696699
)
697700

698701
if wait:

pycloudlib/azure/instance.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,15 @@ class AzureInstance(BaseInstance):
1212

1313
_type = "azure"
1414

15-
def __init__(self, key_pair, client, instance):
15+
def __init__(self, key_pair, client, instance, username=None):
1616
"""Set up instance.
1717
1818
Args:
1919
key_pair: SSH key object
2020
client: Azure compute management client
2121
instance: created azure instance object
2222
"""
23-
super().__init__(key_pair)
23+
super().__init__(key_pair, username=username)
2424

2525
self._client = client
2626
self._instance = instance

pycloudlib/ec2/cloud.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -306,6 +306,7 @@ def launch(
306306
user_data=None,
307307
wait=True,
308308
vpc=None,
309+
username=None,
309310
**kwargs,
310311
):
311312
"""Launch instance on EC2.
@@ -362,7 +363,9 @@ def launch(
362363

363364
self._log.debug("launching instance")
364365
instances = self.resource.create_instances(**args)
365-
instance = EC2Instance(self.key_pair, self.client, instances[0])
366+
instance = EC2Instance(
367+
self.key_pair, self.client, instances[0], username=username
368+
)
366369

367370
if wait:
368371
instance.wait()

pycloudlib/ec2/instance.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,15 @@ class EC2Instance(BaseInstance):
1414

1515
_type = "ec2"
1616

17-
def __init__(self, key_pair, client, instance):
17+
def __init__(self, key_pair, client, instance, username=None):
1818
"""Set up instance.
1919
2020
Args:
2121
key_pair: SSH key object
2222
client: boto3 client object
2323
instance: created boto3 instance object
2424
"""
25-
super().__init__(key_pair)
25+
super().__init__(key_pair, username)
2626

2727
self._instance = instance
2828
self._ip = None

pycloudlib/instance.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import time
77
from abc import ABC, abstractmethod
88
from contextlib import suppress
9+
from typing import Optional
910

1011
import paramiko
1112
from paramiko.ssh_exception import (
@@ -26,7 +27,7 @@ class BaseInstance(ABC):
2627

2728
_type = "base"
2829

29-
def __init__(self, key_pair):
30+
def __init__(self, key_pair, username: Optional[str] = None):
3031
"""Set up instance."""
3132
self._log = logging.getLogger(__name__)
3233
self._ssh_client = None
@@ -36,7 +37,7 @@ def __init__(self, key_pair):
3637
self.boot_timeout = 120
3738
self.key_pair = key_pair
3839
self.port = "22"
39-
self.username = "ubuntu"
40+
self.username = username or "ubuntu"
4041
self.connect_timeout = 60
4142
self.banner_timeout = 60
4243

0 commit comments

Comments
 (0)