コード例 #1
0
    def show(self, request, instance):
        """Detailed view of a single instance."""
        server = {
            "server": {
                "id": instance["uuid"],
                "name": instance["display_name"],
                "status": self._get_vm_state(instance),
                "tenant_id": instance.get("project_id") or "",
                "user_id": instance.get("user_id") or "",
                "metadata": self._get_metadata(instance),
                "hostId": self._get_host_id(instance) or "",
                "image": self._get_image(request, instance),
                "flavor": self._get_flavor(request, instance),
                "created": utils.isotime(instance["created_at"]),
                "updated": utils.isotime(instance["updated_at"]),
                "addresses": self._get_addresses(request, instance),
                "accessIPv4": instance.get("access_ip_v4") or "",
                "accessIPv6": instance.get("access_ip_v6") or "",
                "key_name": instance.get("key_name") or "",
                "config_drive": instance.get("config_drive"),
                "links": self._get_links(request, instance["uuid"]),
            },
        }
        _inst_fault = self._get_fault(request, instance)
        if server["server"]["status"] in self._fault_statuses and _inst_fault:
            server['server']['fault'] = _inst_fault

        if server["server"]["status"] in self._progress_statuses:
            server["server"]["progress"] = instance.get("progress", 0)

        return server
コード例 #2
0
ファイル: servers.py プロジェクト: wendy-king/x7_compute_venv
    def show(self, request, instance):
        """Detailed view of a single instance."""
        server = {
            "server": {
                "id": instance["uuid"],
                "name": instance["display_name"],
                "status": self._get_vm_state(instance),
                "tenant_id": instance.get("project_id") or "",
                "user_id": instance.get("user_id") or "",
                "metadata": self._get_metadata(instance),
                "hostId": self._get_host_id(instance) or "",
                "image": self._get_image(request, instance),
                "flavor": self._get_flavor(request, instance),
                "created": utils.isotime(instance["created_at"]),
                "updated": utils.isotime(instance["updated_at"]),
                "addresses": self._get_addresses(request, instance),
                "accessIPv4": instance.get("access_ip_v4") or "",
                "accessIPv6": instance.get("access_ip_v6") or "",
                "key_name": instance.get("key_name") or "",
                "config_drive": instance.get("config_drive"),
                "links": self._get_links(request, instance["uuid"]),
            },
        }
        _inst_fault = self._get_fault(request, instance)
        if server["server"]["status"] in self._fault_statuses and _inst_fault:
            server['server']['fault'] = _inst_fault

        if server["server"]["status"] in self._progress_statuses:
            server["server"]["progress"] = instance.get("progress", 0)

        return server
コード例 #3
0
    def test_vpn_dict_state_running(self):
        isonow = datetime.datetime.utcnow()
        vpn_instance = {
            'id': 1,
            'created_at': isonow,
            'fixed_ip': {
                'address': '127.0.0.1'
            }
        }

        project = type('Project', (object, ), {
            'id': 'project',
            'vpn_ip': '127.0.0.1',
            'vpn_port': 1234
        })

        # Returns state running for 127.0.0.1 - look at class setup
        expected_vpn_dict = {
            'project_id': 'project',
            'public_ip': '127.0.0.1',
            'public_port': 1234,
            'internal_ip': '127.0.0.1',
            'instance_id': ec2utils.id_to_ec2_id(1),
            'created_at': utils.isotime(isonow),
            'state': 'running'
        }

        self.assertEqual(expected_vpn_dict,
                         admin.vpn_dict(project, vpn_instance))
コード例 #4
0
 def test_index_serializer(self):
     serializer = cloudpipe.CloudpipesTemplate()
     exemplar = dict(cloudpipes=[
         dict(cloudpipe=dict(project_id='1234',
                             public_ip='1.2.3.4',
                             public_port='321',
                             instance_id='1234-1234-1234-1234',
                             created_at=utils.isotime(
                                 datetime.datetime.utcnow()),
                             state='running')),
         dict(cloudpipe=dict(project_id='4321',
                             public_ip='4.3.2.1',
                             public_port='123',
                             state='pending'))
     ])
     text = serializer.serialize(exemplar)
     tree = etree.fromstring(text)
     self.assertEqual('cloudpipes', tree.tag)
     self.assertEqual(len(exemplar['cloudpipes']), len(tree))
     for idx, cl_pipe in enumerate(tree):
         self.assertEqual('cloudpipe', cl_pipe.tag)
         kp_data = exemplar['cloudpipes'][idx]['cloudpipe']
         for child in cl_pipe:
             self.assertTrue(child.tag in kp_data)
             self.assertEqual(child.text, kp_data[child.tag])
コード例 #5
0
 def test_index_serializer(self):
     serializer = cloudpipe.CloudpipesTemplate()
     exemplar = dict(cloudpipes=[
             dict(cloudpipe=dict(
                     project_id='1234',
                     public_ip='1.2.3.4',
                     public_port='321',
                     instance_id='1234-1234-1234-1234',
                     created_at=utils.isotime(datetime.datetime.utcnow()),
                     state='running')),
             dict(cloudpipe=dict(
                     project_id='4321',
                     public_ip='4.3.2.1',
                     public_port='123',
                     state='pending'))])
     text = serializer.serialize(exemplar)
     tree = etree.fromstring(text)
     self.assertEqual('cloudpipes', tree.tag)
     self.assertEqual(len(exemplar['cloudpipes']), len(tree))
     for idx, cl_pipe in enumerate(tree):
         self.assertEqual('cloudpipe', cl_pipe.tag)
         kp_data = exemplar['cloudpipes'][idx]['cloudpipe']
         for child in cl_pipe:
             self.assertTrue(child.tag in kp_data)
             self.assertEqual(child.text, kp_data[child.tag])
コード例 #6
0
ファイル: limits.py プロジェクト: wendy-king/x7_venv
 def _build_rate_limit(self, rate_limit):
     next_avail = \
         datetime.datetime.utcfromtimestamp(rate_limit["resetTime"])
     return {
         "verb": rate_limit["verb"],
         "value": rate_limit["value"],
         "remaining": int(rate_limit["remaining"]),
         "unit": rate_limit["unit"],
         "next-available": utils.isotime(at=next_avail),
     }
コード例 #7
0
ファイル: servers.py プロジェクト: wendy-king/x7_compute_venv
    def _get_fault(self, request, instance):
        fault = instance.get("fault", None)

        if not fault:
            return None

        return {
            "code": fault["code"],
            "created": utils.isotime(fault["created_at"]),
            "message": fault["message"],
            "details": fault["details"],
        }
コード例 #8
0
    def _get_fault(self, request, instance):
        fault = instance.get("fault", None)

        if not fault:
            return None

        return {
            "code": fault["code"],
            "created": utils.isotime(fault["created_at"]),
            "message": fault["message"],
            "details": fault["details"],
        }
コード例 #9
0
ファイル: admin.py プロジェクト: wendy-king/x7_compute_venv
def vpn_dict(project, vpn_instance):
    rv = {'project_id': project.id,
          'public_ip': project.vpn_ip,
          'public_port': project.vpn_port}
    if vpn_instance:
        rv['instance_id'] = ec2utils.id_to_ec2_id(vpn_instance['id'])
        rv['created_at'] = utils.isotime(vpn_instance['created_at'])
        address = vpn_instance.get('fixed_ip', None)
        if address:
            rv['internal_ip'] = address['address']
        if project.vpn_ip and project.vpn_port:
            if utils.vpn_ping(project.vpn_ip, project.vpn_port):
                rv['state'] = 'running'
            else:
                rv['state'] = 'down'
        else:
            rv['state'] = 'down - invalid project vpn config'
    else:
        rv['state'] = 'pending'
    return rv
コード例 #10
0
    def test_vpn_dict_state_running(self):
        isonow = datetime.datetime.utcnow()
        vpn_instance = {'id': 1,
                        'created_at': isonow,
                        'fixed_ip': {'address': '127.0.0.1'}}

        project = type('Project', (object,), {'id': 'project',
                                              'vpn_ip': '127.0.0.1',
                                              'vpn_port': 1234})

        # Returns state running for 127.0.0.1 - look at class setup
        expected_vpn_dict = {'project_id': 'project',
                             'public_ip': '127.0.0.1',
                             'public_port': 1234,
                             'internal_ip': '127.0.0.1',
                             'instance_id':
                                ec2utils.id_to_ec2_id(1),
                             'created_at': utils.isotime(isonow),
                             'state': 'running'}

        self.assertEqual(expected_vpn_dict,
                         admin.vpn_dict(project, vpn_instance))
コード例 #11
0
def vpn_dict(project, vpn_instance):
    rv = {
        'project_id': project.id,
        'public_ip': project.vpn_ip,
        'public_port': project.vpn_port
    }
    if vpn_instance:
        rv['instance_id'] = ec2utils.id_to_ec2_id(vpn_instance['id'])
        rv['created_at'] = utils.isotime(vpn_instance['created_at'])
        address = vpn_instance.get('fixed_ip', None)
        if address:
            rv['internal_ip'] = address['address']
        if project.vpn_ip and project.vpn_port:
            if utils.vpn_ping(project.vpn_ip, project.vpn_port):
                rv['state'] = 'running'
            else:
                rv['state'] = 'down'
        else:
            rv['state'] = 'down - invalid project vpn config'
    else:
        rv['state'] = 'pending'
    return rv