Пример #1
0
 def is_up(self):
     try:
         from libcloud.compute.types import NodeState
     except ImportError:
         raise ex.Error("missing required module libcloud.compute.types")
     n = self.get_node()
     if n is not None and n.state == NodeState().RUNNING:
         return True
     if n is None:
         self.status_log("state:unknown")
     else:
         self.status_log("state:" + NodeState().tostring(n.state))
     return False
Пример #2
0
    def __repr__(self):
        state = NodeState.tostring(self.state)

        return (('<Node: uuid=%s, name=%s, state=%s, public_ips=%s, '
                 'private_ips=%s, provider=%s ...>')
                % (self.uuid, self.name, state, self.public_ips,
                   self.private_ips, self.driver.name))
Пример #3
0
def print_instance_summary(instance, use_color='auto'):
    """ Print summary info line for the supplied instance """

    colorize_ = partial(colorize, use_color=use_color)

    name = colorize_(instance.name, "yellow")
    instance_type = instance.extra['gonzo_size']

    if instance.state == NodeState.RUNNING:
        status_colour = "green"
    else:
        status_colour = "red"

    instance_status = NodeState.tostring(instance.state)
    status = colorize_(instance_status, status_colour)

    if 'owner' in instance.extra['gonzo_tags']:
        owner = instance.extra['gonzo_tags']['owner']
    else:
        owner = "---"

    uptime = format_uptime(instance.extra['gonzo_created_time'])
    uptime = colorize_(uptime, "blue")

    availability_zone = instance.extra['gonzo_az']

    result_list = [
        name,
        instance_type,
        status,
        owner,
        uptime,
        availability_zone,
    ]
    return result_list
Пример #4
0
    def container_start(self):
        """
	    RUNNING = 0
	    REBOOTING = 1
	    TERMINATED = 2
	    PENDING = 3
	    UNKNOWN = 4
	    STOPPED = 5
	    SUSPENDED = 6
	    ERROR = 7
	    PAUSED = 8
        """
        try:
            from libcloud.compute.types import NodeState
        except ImportError:
            raise ex.Error("missing required module libcloud.compute.types")
        n = self.get_node()
        if n is None:
            self.provision()
            return
        elif n.state == NodeState().RUNNING:
            self.log.info("already running")
            return
        elif n.state == NodeState().PENDING:
            self.log.info("already pending. wait for running state.")
            self.wait_for_fn(self.is_up, self.start_timeout, 5)
            return
        elif n.state == NodeState().REBOOTING:
            self.log.info("currently rebooting. wait for running state.")
            self.wait_for_fn(self.is_up, self.start_timeout, 5)
            return
        elif n.state == NodeState().STOPPED:
            self.log.info("starting ebs ec2 instance through aws")
            self.cloud.driver.ex_start_node(n)
            self.log.info("wait for container up status")
            self.wait_for_fn(self.is_up, self.start_timeout, 5)
            return
        raise ex.Error("don't know what to do with node in state: %s" %
                       NodeState().tostring(n.state))
Пример #5
0
 def _to_node(self, server):
     public_ip = server['public_ip']
     private_ip = server['private_ip']
     location = server['location'] or {}
     return Node(id=server['id'],
                 name=server['name'],
                 state=NodeState.fromstring(server['state']),
                 public_ips=[public_ip['address']] if public_ip else [],
                 private_ips=[private_ip] if private_ip else [],
                 driver=self,
                 extra={'volumes': server['volumes'],
                        'tags': server['tags'],
                        'arch': server['arch'],
                        'organization': server['organization'],
                        'region': location.get('zone_id', 'par1')},
                 created_at=parse_date(server['creation_date']))
Пример #6
0
    def _basic_instance_details(self, name):
        instance = self._find_instance_by_name(name)

        if instance is not None:
            details = {
                'id': instance.id,
                'status': NodeState.tostring(instance.state),
                'ip-private': instance.private_ips,
                'ip-public': instance.public_ips,
                'security_groups': instance.extra['groups'],
                'keypair': instance.extra['key_name'],
                'instance_type': instance.extra['instance_type'],
            }
        else:
            details = {'error': 'instance named {0} not found.'.format(name)}

        return details
Пример #7
0
    def _basic_instance_details(self, name):
        instance = self._find_instance_by_name(name)

        if instance is not None:
            details = {
                'id': instance.id,
                'status': NodeState.tostring(instance.state),
                'ip-private': instance.private_ips,
                'ip-public': instance.public_ips,
                'security_groups': instance.extra['groups'],
                'keypair': instance.extra['key_name'],
                'instance_type': instance.extra['instance_type'],
            }
        else:
            details = {'error': 'instance named {0} not found.'.format(name)}

        return details
Пример #8
0
 def test_nodestate_fromstring(self):
     self.assertEqual(NodeState.fromstring("running"), NodeState.RUNNING)
Пример #9
0
 def test_nodestate_tostring(self):
     self.assertEqual(NodeState.tostring(NodeState.RUNNING), "RUNNING")
Пример #10
0
 def get_state(self, obj):
     return NodeState.tostring(obj.state)
Пример #11
0
 def list_nodes(self):
     driver = self.connect()  #get the Nova driver from the connection class
     nodes = driver.list_nodes()  #list all nodes runinng
     for node in nodes:  #for every node
         print 'Node Name: ', node.name, 'Node ID: ', node.id, 'Node State: ', NodeState.tostring(
             node.state)
Пример #12
0
 def test_nodestate_fromstring(self):
     self.assertEqual(NodeState.fromstring("running"), NodeState.RUNNING)
Пример #13
0
 def test_nodestate_tostring(self):
     self.assertEqual(NodeState.tostring(NodeState.RUNNING), "RUNNING")
Пример #14
0
 def get_state(self, obj):
     return NodeState.tostring(obj.state)