Rewrite upgrade-env

This commit is contained in:
Yuriy Taraday 2015-07-20 13:19:22 +03:00
parent bf31f4e25f
commit 370bd3fd95
2 changed files with 50 additions and 2 deletions

View File

@ -10,11 +10,56 @@
# License for the specific language governing permissions and limitations
# under the License.
from __future__ import print_function
import json
import logging
import uuid
from octane.util import subprocess
from cliff import command as cmd
from fuelclient.objects import environment as environment_obj
from fuelclient.objects import release as release_obj
LOG = logging.getLogger(__name__)
def find_release(operating_system, version):
for release in release_obj.Release.get_all():
if release.data['operating_system'] == operating_system and \
release.data['version'] == version:
return release
else:
raise Exception("Release not found for os %s and version %s",
operating_system, version)
def set_cobbler_provision(env_id):
env = environment_obj.Environment(env_id)
settings = env.get_settings_data()
settings["editable"]["provision"]["method"]["value"] = "cobbler"
env.set_settings_data(settings)
def upgrade_env(orig_id):
pass
target_release = find_release("Ubuntu", "2014.2.2-6.1")
LOG.info("Cloning env %s for release %s",
orig_id, target_release.data['name'])
res, _ = subprocess.call(
["fuel2", "env", "clone", "-f", "json",
str(orig_id), uuid.uuid4().hex, str(target_release.data['id'])],
stdout=subprocess.PIPE,
)
for kv in json.loads(res):
if kv['Field'] == 'id':
seed_id = kv['Value']
break
else:
raise Exception("Couldn't find new environment ID in fuel CLI output:"
"\n%s" % res)
return seed_id
class UpgradeEnvCommand(cmd.Command):
@ -24,4 +69,6 @@ class UpgradeEnvCommand(cmd.Command):
return parser
def take_action(self, parsed_args):
upgrade_env(parsed_args.orig_id)
seed_id = upgrade_env(parsed_args.orig_id)
print(seed_id) # TODO: This shouldn't be needed
set_cobbler_provision(seed_id)

View File

@ -3,3 +3,4 @@
# examine requirements of software listed there.
pbr>=0.6,!=0.7,<1.0
cliff>=1.7.0,<=1.9.0
python-fuelclient>=6.1