Skip to content

Commit

Permalink
Add support for import/export operations
Browse files Browse the repository at this point in the history
This closes #161

Export operation allows to also export ssh keys, although since they contain
sensible information, confirmation is asked to the user.

During the import operation, all attributes that need to be changed are
updated. Also, if ssh keys are imported, their paths in the Cluster and Node
classes is updated accordingly.
  • Loading branch information
arcimboldo committed May 25, 2015
1 parent b042a1d commit f1e874c
Show file tree
Hide file tree
Showing 5 changed files with 302 additions and 48 deletions.
8 changes: 5 additions & 3 deletions elasticluster/cluster.py
Original file line number Diff line number Diff line change
Expand Up @@ -307,14 +307,16 @@ def add_node(self, kind, image_id, image_user, flavor,
'cluster_name' : self.name,
'kind': kind,
'cloud_provider': self._cloud_provider,
'user_key_public': self.user_key_public,
'user_key_private': self.user_key_private,
'user_key_name': self.user_key_name,
'image_user': image_user,
'security_group': security_group,
'image_id': image_id,
'flavor': flavor,
'image_userdata':image_userdata})
for attr in ('user_key_public', 'user_key_private', 'user_key_name',
'security_group', 'image_user', 'image_id', 'flavor',
'image_userdata'):
if attr not in extra:
extra[attr] = getattr(self, attr)
node = Node(**extra)

self.nodes[kind].append(node)
Expand Down
5 changes: 5 additions & 0 deletions elasticluster/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,8 @@ class will be instantiated.
# FIXME: This is not python3 compatible!
if isinstance(configfiles, basestring):
configfiles = [configfiles]
# Also, expand any possible user variable
configfiles = [os.path.expanduser(cfg) for cfg in configfiles]
for cfgfile in configfiles[:]:
cfgdir = cfgfile + '.d'
if os.path.isfile(cfgfile) and os.path.isdir(cfgdir):
Expand All @@ -138,6 +140,9 @@ class will be instantiated.
config_reader = ConfigReader(configfiles)
(conf, storage_conf) = config_reader.read_config()

# FIXME: We shouldn't need this ugly fix
if storage_path:
storage_conf['storage_path'] = storage_path
return Configurator(conf, **storage_conf)

def create_cloud_provider(self, cluster_template):
Expand Down
4 changes: 4 additions & 0 deletions elasticluster/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@
from elasticluster.subcommands import SftpFrontend
from elasticluster.subcommands import GC3PieConfig
from elasticluster.subcommands import RemoveNode
from elasticluster.subcommands import ExportCluster
from elasticluster.subcommands import ImportCluster
from elasticluster.conf import Configurator
from elasticluster.exceptions import ConfigurationError
from elasticluster.migration_tools import MigrationCommand
Expand Down Expand Up @@ -73,6 +75,8 @@ def setup(self):
GC3PieConfig(self.params),
MigrationCommand(self.params),
RemoveNode(self.params),
ExportCluster(self.params),
ImportCluster(self.params),
]

# global parameters
Expand Down
11 changes: 2 additions & 9 deletions elasticluster/repository.py
Original file line number Diff line number Diff line change
Expand Up @@ -258,10 +258,6 @@ class JsonRepository(DiskRepository):

def load(self, fp):
dcluster = json.load(fp)
# Backward compatibility fix
for key in ['user_key_name', 'user_key_public']:
if '_'+key in dcluster:
dcluster[key] = dcluster['_'+key]
from elasticluster import Cluster
cluster = Cluster(**dcluster)

Expand All @@ -287,10 +283,6 @@ class YamlRepository(DiskRepository):

def load(self, fp):
dcluster = yaml.load(fp)
# Backward compatibility fix
for key in ['user_key_name', 'user_key_public']:
if '_'+key in dcluster:
dcluster[key] = dcluster['_'+key]
from elasticluster import Cluster
cluster = Cluster(**dcluster)

Expand All @@ -299,7 +291,8 @@ def load(self, fp):

@staticmethod
def dump(cluster, fp):
# To only save stuff we need, it's actually easier to serialize with json first :)
# To only save stuff we need, it's actually easier to
# serialize with json first :)
state = json.loads(json.dumps(dict(cluster), default=dict))
yaml.safe_dump(state, fp, default_flow_style=False, indent=4)

Expand Down

0 comments on commit f1e874c

Please sign in to comment.