def register(self, initial_status="STARTING"):
        data_center_info = {           
            '@class':'com.netflix.appinfo.InstanceInfo$DefaultDataCenterInfo',     
            'name': self.data_center        
        }
        if self.data_center == "Amazon":
            data_center_info['metadata'] = {
                'ami-launch-index': ec2metadata.get('ami-launch-index'),
                'local-hostname': ec2metadata.get('local-hostname'),
                'availability-zone': ec2metadata.get('availability-zone'),
                'instance-id': ec2metadata.get('instance-id'),
                'public-ipv4': ec2metadata.get('public-ipv4'),
                'public-hostname': ec2metadata.get('public-hostname'),
                'ami-manifest-path': ec2metadata.get('ami-manifest-path'),
                'local-ipv4': ec2metadata.get('local-ipv4'),
                'ami-id': ec2metadata.get('ami-id'),
                'instance-type': ec2metadata.get('instance-type'),
            }
        instance_data = {
            "instance": {
                "hostName": self.host_name,
                "app": self.app_name,
                "vipAddr": self.vip_address or "",
                "secureVipAddr": self.secure_vip_address or "",
                "status": initial_status,
                "port": {"$": self.port, "@enabled": "true"},
                "securePort": {"$": self.secure_port, "@enabled": "true"},
                "dataCenterInfo": data_center_info,
                "healthCheckUrl": self.health_check_url or ""
            }
        }

        success = False
        last_e = None
        
        
        temp= json.dumps(instance_data)
        print temp
        for eureka_url in self.eureka_urls:
            
            try:
             
                r = requests.post(urljoin(eureka_url, "apps/%s" % self.app_name), temp,
                                 headers={'Content-Type': 'application/json'})
                print"request"
                print r
                r.raise_for_status()
                success = True
                break
            except (EurekaHTTPException, URLError) as e:
                last_e = e
                print e
        if not success:
            raise EurekaRegistrationFailedException("Did not receive correct reply from any instances, last error: " + str(e))
Beispiel #2
0
 def register(self, initial_status="STARTING"):
     data_center_info = {
         '@class': 'com.netflix.appinfo.InstanceInfo$DefaultDataCenterInfo',
         'name': self.data_center
     }
     if self.data_center == "Amazon":
         data_center_info['metadata'] = {
             'ami-launch-index': ec2metadata.get('ami-launch-index'),
             'local-hostname': ec2metadata.get('local-hostname'),
             'availability-zone': ec2metadata.get('availability-zone'),
             'instance-id': ec2metadata.get('instance-id'),
             'public-ipv4': ec2metadata.get('public-ipv4'),
             'public-hostname': ec2metadata.get('public-hostname'),
             'ami-manifest-path': ec2metadata.get('ami-manifest-path'),
             'local-ipv4': ec2metadata.get('local-ipv4'),
             'ami-id': ec2metadata.get('ami-id'),
             'instance-type': ec2metadata.get('instance-type'),
         }
     instance_data = {
         'instance': {
             'hostName': self.host_name,
             'app': self.app_name,
             'ipAddr': self.ip_addr,
             'vipAddr': self.vip_address or '',
             'secureVipAddr': self.secure_vip_address or '',
             'status': initial_status,
             'port': {'$': self.port, '@enabled': 'true'},
             'securePort': {'$': self.secure_port, '@enabled': 'false'},
             'dataCenterInfo': data_center_info,
             'healthCheckUrl': self.health_check_url or '',
             'instanceId': self.get_instance_id(),
             'homePageUrl': self.home_page_url,
             'vipAddress': self.host_name,
             'secureVipAddress': self.host_name
         }
     }
     success = False
     last_e = None
     for eureka_url in self.eureka_urls:
         try:
             r = requests.post(urljoin(eureka_url, "apps/%s" % self.app_name), json.dumps(instance_data),
                               headers={'Content-Type': 'application/json'})
             r.raise_for_status()
             success = True
             break
         except (EurekaHTTPException, URLError) as e:
             last_e = e
     if not success:
         raise EurekaRegistrationFailedException("Did not receive correct reply from any instances, last error: " + str(last_e))
Beispiel #3
0
 def register(self, initial_status="STARTING"):
     data_center_info = {
         'name': self.data_center,
         '@class': 'com.netflix.appinfo.InstanceInfo$DefaultDataCenterInfo'
     }
     if self.data_center == "Amazon":
         data_center_info['metadata'] = {
             'ami-launch-index': ec2metadata.get('ami-launch-index'),
             'local-hostname': ec2metadata.get('local-hostname'),
             'availability-zone': ec2metadata.get('availability-zone'),
             'instance-id': ec2metadata.get('instance-id'),
             'public-ipv4': ec2metadata.get('public-ipv4'),
             'public-hostname': ec2metadata.get('public-hostname'),
             'ami-manifest-path': ec2metadata.get('ami-manifest-path'),
             'local-ipv4': ec2metadata.get('local-ipv4'),
             'ami-id': ec2metadata.get('ami-id'),
             'instance-type': ec2metadata.get('instance-type'),
         }
     instance_data = {
         'instance': {
             'instanceId': self.host_name + ":" + self.app_name + ":" + str(self.port),
             'hostName': self.host_name,
             'app': self.app_name,
             'ipAddr': self.ip_address,
             'status': initial_status,
             'port': self.composed_port,
             'securePort': self.composed_secure_port,
             'dataCenterInfo': data_center_info,
             "leaseInfo": self.lease_info,
             "homePageUrl":  "http://" + self.host_name + ":" + str(self.port) + "/",
             "statusPageUrl": "http://" + self.host_name + ":" + str(self.port) + "/info",
             "healthCheckUrl": "http://" + self.host_name + ":" + str(self.port) + "/health",
             'vipAddress': self.vip_address or '',
             'secureVipAddress': self.secure_vip_address or ''
         }
     }
     success = False
     last_e = None
     for eureka_url in self.eureka_urls:
         try:
             r = requests.post(urljoin(eureka_url, "apps/%s" % self.app_name), json.dumps(instance_data),
                               headers={'Content-Type': 'application/json'})
             r.raise_for_status()
             success = True
             break
         except (EurekaHTTPException, URLError) as e:
             last_e = e
     if not success:
         raise EurekaRegistrationFailedException("Did not receive correct reply from any instances, last error: " + str(e))
Beispiel #4
0
 def register(self, initial_status="STARTING"):
     data_center_info = {
         'name': self.data_center
     }
     if self.data_center == "Amazon":
         data_center_info['metadata'] = {
             'ami-launch-index': ec2metadata.get('ami-launch-index'),
             'local-hostname': ec2metadata.get('local-hostname'),
             'availability-zone': ec2metadata.get('availability-zone'),
             'instance-id': ec2metadata.get('instance-id'),
             'public-ipv4': ec2metadata.get('public-ipv4'),
             'public-hostname': ec2metadata.get('public-hostname'),
             'ami-manifest-path': ec2metadata.get('ami-manifest-path'),
             'local-ipv4': ec2metadata.get('local-ipv4'),
             'ami-id': ec2metadata.get('ami-id'),
             'instance-type': ec2metadata.get('instance-type'),
         }
     instance_data = {
         'instance': {
             'hostName': self.host_name,
             'app': self.app_name,
             'vipAddr': self.vip_address or '',
             'secureVipAddr': self.secure_vip_address or '',
             'status': initial_status,
             'port': self.port,
             'dataCenterInfo': data_center_info,
             'healthCheckUrl': self.health_check_url or ''
         }
     }
     if self.secure_port: # or Eureka POST call crashes if no secure port
         instance_data['instance']['securePort'] = self.secure_port
     success = False
     last_e = None
     for eureka_url in self.eureka_urls:
         try:
             r = requests.post(urljoin(eureka_url, "apps/%s" % self.app_name), json.dumps(instance_data),
                               headers={'Content-Type': 'application/json'})
             r.raise_for_status()
             success = True
             break
         except (EurekaHTTPException, URLError) as e:
             last_e = e
     if not success:
         raise EurekaRegistrationFailedException("Did not receive correct reply from any instances, last error: " + str(e))
Beispiel #5
0
 def register(self, initial_status="STARTING"):
     data_center_info = {'name': self.data_center}
     if self.data_center == "Amazon":
         data_center_info['metadata'] = {
             'ami-launch-index': ec2metadata.get('ami-launch-index'),
             'local-hostname': ec2metadata.get('local-hostname'),
             'availability-zone': ec2metadata.get('availability-zone'),
             'instance-id': ec2metadata.get('instance-id'),
             'public-ipv4': ec2metadata.get('public-ipv4'),
             'public-hostname': ec2metadata.get('public-hostname'),
             'ami-manifest-path': ec2metadata.get('ami-manifest-path'),
             'local-ipv4': ec2metadata.get('local-ipv4'),
             'ami-id': ec2metadata.get('ami-id'),
             'instance-type': ec2metadata.get('instance-type'),
         }
     success = False
     for eureka_url in self.eureka_urls:
         try:
             r = requests.post(urljoin(eureka_url,
                                       "apps/%s" % self.app_name),
                               json.dumps({
                                   'instance': {
                                       'hostName': self.host_name,
                                       'app': self.app_name,
                                       'vipAddr': self.vip_address,
                                       'secureVipAddr':
                                       self.secure_vip_address,
                                       'status': initial_status,
                                       'port': self.port,
                                       'securePort': self.secure_port,
                                       'dataCenterInfo': data_center_info
                                   }
                               }),
                               headers={'Content-Type': 'application/json'})
             r.raise_for_status()
             success = True
             break
         except (EurekaHTTPException, URLError) as e:
             pass
     if not success:
         raise EurekaRegistrationFailedException(
             "Did not receive correct reply from any instances")