#!/usr/bin/env python
#
# Created as part of the StratusLab project (http://stratuslab.eu),
# co-funded by the European Commission under the Grant Agreement
# INFSO-RI-261552."
#
# Copyright (c) 2010, SixSq Sarl
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#   http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#

import os
import sys

sys.path.append('/var/lib/stratuslab/python')

from stratuslab.Runner import Runner
from stratuslab.Runnable import Runnable
from stratuslab.ConfigHolder import ConfigHolder
from stratuslab.Util import printAction
from stratuslab.Util import printStep
from stratuslab.commandbase.StorageCommand import StorageCommand

class MainProgram(Runnable):
    '''A command-line program to run a virtual machine.'''

    def parse(self):

        self.parser.usage='''%prog [options] <vm-id>'''

        self.parser.add_option('--author-email', dest='authorEmail',
                help='Email address of the author of ' \
                'the new image. After image is saved a notification is sent ' \
                'with further instructions.',
                default='', metavar='EMAIL')

        self.parser.add_option('--description', dest='newImageDescription',
                help='String containing the description of the new image,\
                to be inserted in the manifest.',
                metavar='TEXT', default=None)
        
        super(MainProgram, self).parse()


    def checkOptions(self):

        super(MainProgram, self).checkOptions()

        if self.options.saveDisk == True and not self.options.authorEmail:
            self.parser.error('Provide a valid Email address of the author of the image.')

    def doWork(self):
        configHolder = ConfigHolder(self.options.__dict__)
        runner = Runner(self.image, configHolder)
        runner.save_instance_as_new_image()

if __name__ == '__main__':
    print 'Sorry, this command is not yet implemented'
    sys.exit()
    try:
        MainProgram()
    except KeyboardInterrupt:
        print '\n\nExecution interrupted by the user... goodbye!'
