def drop_all(self):
        if boolean_input('Are you ABSOLUTELY sure you want to do this', default=False):
            if boolean_input('Once again, ABSOLUTELY sure', default=False):
                self.manager.drop(boolean_input('Do you want to clean up the deployed data also (Y)'
                                                ' or is pure db clear sufficient (n)'))
                output('All data is cleared.')
                return

        # else
        output('Aborted.')
Beispiel #2
0
 def obtain_update_data(self, entity):
     data = None
     if entity.ext_cloud_net_id is None:
         if boolean_input('Do you want to attach this router to an external network'):
             ext_net = self.obtain_entity_from_manager(
                 self.network_manager,
                 'Please enter the network name', self.network_manager.external,
                 skip_questioning_if_only_one_entity=True)
             if ext_net:
                 data = dict(name=entity.name, ext_cloud_net_id=ext_net.cloud_network['id'])
     elif boolean_input('Do you want to detach this router from its external network'):
         data = dict(name=entity.name, ext_cloud_net_id=None)
     return data
Beispiel #3
0
    def connect(self):
        output('\nPlease enter the name of the instance you would like to connect to.')
        try:
            fip = None
            instance = self.obtain_entity(filter_f=self.is_active)
            if instance:
                fip = self.manager.get_instance_fip(instance)
                if fip is None:
                    if boolean_input('This instance is not publicly routable yet.\n'
                                     'Do you want to make it routable'):
                        fip = self.make_instance_routable(instance)

            if fip is None:
                output('No instance connected to.')
                return

            output('%s is publicly routable via %s', instance.name, fip)
            output()

            suggested_username, suggested_password = self.get_suggested_instance_credentials(instance)

            output('Connecting to %s...', fip)
            username = string_input('Username', default=suggested_username)
            password = string_input('Password', default=suggested_password)

            # connect
            self.manager.connect_to_instance(instance, username, password)
            output()
            output('Successfully established a connection.\n'
                   'Returning to MiniCloud now.')

        except DoesNotExistException:
            output('No instance connected to.')
        except MiniCloudException:
            error('Connecting to the instance failed.')
Beispiel #4
0
    def add_entity(self):
        def_os_auth_url = shell_variable('OS_AUTH_URL', 'http://x86.trystack.org:5000/v2.0')
        def_tenant_name = shell_variable('OS_TENANT_NAME', 'your-tenant>')
        def_username = shell_variable('OS_USERNAME', 'your-username>')
        def_password = shell_variable('OS_PASSWORD', 'your-password>')

        if boolean_input('Do you want a REAL cloud to be added (Y), or STUB (n)'):
            cloud = Cloud(
                string_input('Name', default='trystack'),
                string_input('Type', default='OPENSTACK'),
                string_input('Type', default='Kilo'),
                string_input('Location', default='trystack'),
                string_input('Path', default=def_os_auth_url),
                string_input('Tenant', default=def_tenant_name),
                string_input('Username', default=def_username),
                string_input('Password', default=def_password))

            return self.manager.add(cloud)

        else:
            cloud = StubCloud()
 
            self.manager.add(cloud)

            new_cluster = Cluster(StubDriverContext.CLUSTER_NAME, cloud.name)
            return self.minicloud.cluster_manager.add(new_cluster)
    def get_topology(self, indent=''):
        deep_topology = self.first_topology
        show_empty_compute_entities = False
        show_empty_network_entities = True

        if not boolean_input('Default topology parameters' + (' (DEEP fetch)' if deep_topology else '')):
            deep_topology = self.force_deep_topology()
            show_empty_compute_entities = boolean_input(
                'Show empty compute entities', show_empty_compute_entities)
            show_empty_network_entities = boolean_input(
                'Show empty network entities', show_empty_network_entities)

        self.first_topology = False
        return self.build_topology(deep_topology, 'MiniCloud', indent, indent,
                                   show_empty_compute_entities=show_empty_compute_entities,
                                   show_empty_network_entities=show_empty_network_entities)
Beispiel #6
0
    def make_network_routable(self, network):
        router = None
        if self.router_manager.list() and boolean_input('Do you want to attach to existing router'):
            router = self.obtain_entity_from_manager(
                self.router_manager,
                'Please enter the name of the router to attach to',
                skip_questioning_if_only_one_entity=True)

        elif boolean_input('Do you want to create a router'):
            name = string_input('Name')
            output('Creating router.')
            router = Router(name, cloud_manager=network.cloud_manager)
            self.router_manager.add(router)

        if router:
            output('Attaching network.')
            self.network_manager.attach_network_to_router(network, router)

        return router
Beispiel #7
0
    def make_instance_routable(self, instance):
        fip = self.manager.get_instance_fip(instance)
        if fip:
            output('The instance is already routable as %s', fip)
            return fip

        network = self.manager.get_instance_network(instance)
        routers = self.network_manager.get_routers(network)
        if routers:
            router = routers[0]
        else:
            output('The instance\'s network (\'' + network.name + '\') has no router attached to it.')
            router = self.make_network_routable(network)
            if not router:
                return None

        external_networks = self.network_manager.external_networks(router)
        if not external_networks:
            if not self.network_manager.external_networks():
                error('You unfortunately have no external networks')
                if boolean_input('Do you want to create an external network'):
                    new_name = string_input('Please enter the network name')
                    new_cidr = '169.169.10.0/24' # fixed for now
                    external_network = Network(new_name, new_cidr, True, router, instance.cloud_manager)
                    self.network_manager.add(external_network)
                else:
                    return None

            external_network = self.obtain_entity_from_manager(
                self.network_manager,
                'Please enter the name of the external network you want to route from',
                self.network_manager.external,
                skip_questioning_if_only_one_entity=True)

            if external_network:
                output('Uplinking router.')
                self.router_manager.uplink(router, external_network)

        elif len(external_networks) == 1:
            external_network = external_networks[0]

        else:
            output('\nWhich network do you want to make the instance routable to?')
            network_idx = self.network_manager.obtain_entity_name(filter=self.network_manager.external)
            external_network = external_networks[network_idx]

        if external_network and self.check_instance_is_ready(instance):
            fip = self.manager.make_routable(instance, external_network)

        return fip
Beispiel #8
0
    def obtain_entity_to_add(self):
        name = string_input('Name')
        cloud_manager = self.obtain_entity_from_manager(self.minicloud.cloud_manager)
        if cloud_manager:
            ext_net = None

            if boolean_input('Do you want to attach this router to an external network'):
                ext_net = self.obtain_entity_from_manager(
                    self.network_manager,
                    'Please enter the network name', self.network_manager.external,
                    skip_questioning_if_only_one_entity=True)

            return Router(name, cloud_manager=cloud_manager, ext_network=ext_net)
        else:
            return None
Beispiel #9
0
    def obtain_entity_to_add(self):
        name = string_input('Name')
        external = False  # boolean_input('Do you want this network to be external (mind policies!)', default=False)
        cidr = self.obtain_cidr()
        cloud_manager = self.obtain_entity_from_manager(self.minicloud.cloud_manager)

        if cloud_manager:
            router = None
            if not external:
                if self.router_manager.list():
                    router = self.obtain_entity_from_manager(self.router_manager,
                                                             'Router to attach to, if any (else give none)')
                elif boolean_input('Do you want this network to be connected to a router', default=False):
                    router_name = string_input('Enter the router name')
                    router = Router(router_name, cloud_manager)
                    self.router_manager.add_entity(router)

            return Network(name, cidr, external, router, cloud_manager)
        else:
            return None
Beispiel #10
0
    def add_entity(self):
        name = string_input('Name')
        cluster_name = self.obtain_entity_name(self.cluster_manager, choose_from_display=True, allow_none=True)
        flavor = self.obtain_entity_from_manager(
            self.manager.flavor_manager,
            'Which flavor do you want to boot?',
            choose_from_display=True, return_immediately_if_no_entity=True)
        if not flavor:
            error('No flavor found.')
            return None

        image = self.obtain_entity_from_manager(
            self.manager.image_manager,
            'Which image do you want to boot?',
            choose_from_display=True, return_immediately_if_no_entity=True)
        if not image:
            error('No image found.')
            return None

        output('\nScanning security groups.')
        nova_sgs = self.manager.nova_sg_manager.list()
        public_ssh_sg = None
        for sg in nova_sgs:
            if sg.name == "public_ssh":
                public_ssh_sg = sg
                break

        if not public_ssh_sg and boolean_input("No public_ssh security group was found. Would you like to create it"):
            sg = NovaSg('public_ssh', 'sg for ssh access', self.manager.get_cloud_manager(cluster_name))
            sg.add_rule(NovaSgRule('tcp', 22, 22, '0.0.0.0/0'))
            self.manager.nova_sg_manager.add(sg)

        nova_sg = self.obtain_entity_from_manager(
            self.manager.nova_sg_manager,
            'Which nova security group do you want to boot with?',
            choose_from_display=True, return_immediately_if_no_entity=True)
        if not nova_sg:
            error('No Nova Security Group found.')
            return None

        network = self.obtain_entity_from_manager(
            self.network_manager,
            'Which network do you want to boot in?',
            self.network_manager.non_external,
            choose_from_display=True, return_immediately_if_no_entity=True)
        if not network:
            error('No network found.')
            return None

        make_routable = boolean_input('\nDo you want this instance to be routable')

        output()
        instance = Instance(name, cluster_name, flavor, image, nova_sg, network)
        self.manager.add(instance)

        if make_routable:
            fip = self.make_instance_routable(instance)
            if fip:
                output('Instance is routable as %s.', fip)

        return instance
Beispiel #11
0
 def show_empty_entities():
     return boolean_input('Show empty entities', False)
Beispiel #12
0
 def force_deep_topology():
     return boolean_input('Force deep fetch', False)
Beispiel #13
0
 def check_for_remove(self, entity):
     if self.manager.get_children(entity.name):
         return boolean_input('Entity ' + entity.name + ' has data contained. '
                                                        'Still delete, together with all data', default=False)
     else:
         return True
Beispiel #14
0
    from keystoneclient.openstack.common.apiclient.exceptions import \
        Forbidden, AuthorizationFailure, Unauthorized
    from neutronclient.v2_0 import client as neutron_client
    from neutronclient.common.exceptions import NetworkInUseClient, BadRequest, NotFound, \
        IpAddressGenerationFailureClient, Conflict, OverQuotaClient, Forbidden
    from novaclient import client as nova_client
    from novaclient.exceptions import OverLimit
    from novaclient.exceptions import Forbidden as NovaForbidden
    from novaclient.exceptions import ClientException as NovaClientException
    from novaclient.exceptions import BadRequest as NovaBadRequest

except ImportError as exc:
    print "ERROR: %s: Can\'t import python clients for OpenStack." % exc
    print "ERROR: Please install them e.g. giving 'sudo pip install python-openstackclient'"
    print "ERROR: Meanwhile, continuing with dummy stub clients; THOSE WILL NOT FUNCTION PROPERLY!"
    if boolean_input("ERROR: Are you sure you want to continue experimenting with this software"):
        class keystone_client:
            pass

        class neutron_client:
            pass

        class nova_client:
            pass

        class Forbidden:
            pass

        class AuthorizationFailure:
            pass