'Add the proper predicates to the contract builder for a given
upsert description.'

def _add_contract_clauses(self, contract_builder, upsert):

    host_rules = upsert['hostRules']
    backend_services = [upsert['defaultService']]
    for host_rule in host_rules:
        path_matcher = host_rule['pathMatcher']
        backend_services.append(path_matcher['defaultService'])
        for path_rule in path_matcher['pathRules']:
            backend_services.append(path_rule['backendService'])
    health_checks = [service['healthCheck'] for service in backend_services]
    hc_clause_builder = contract_builder.new_clause_builder('Health    Checks    Created', retryable_for_secs=30).list_resource('httpHealthChecks')
    for hc in health_checks:
        hc_clause_builder.AND(ov_factory.value_list_contains(jp.DICT_MATCHES({'name': jp.STR_EQ(hc['name']), 'requestPath': jp.STR_EQ(hc['requestPath']), 'port': jp.NUM_EQ(hc['port'])})))
    bs_clause_builder = contract_builder.new_clause_builder('Backend    Services    Created', retryable_for_secs=30).list_resource('backendServices')
    for bs in backend_services:
        bs_clause_builder.AND(ov_factory.value_list_contains(jp.DICT_MATCHES({'name': jp.STR_EQ(bs['name']), 'portName': jp.STR_EQ('http'), 'healthChecks': jp.LIST_MATCHES([jp.STR_EQ(self._get_hc_link(bs['healthCheck']['name']))])})))
    url_map_clause_builder = contract_builder.new_clause_builder('Url    Map    Created', retryable_for_secs=30).list_resource('urlMaps')
    for hr in host_rules:
        pm = hr['pathMatcher']
        path_rules_spec = [jp.DICT_MATCHES({'service': jp.STR_EQ(self._get_bs_link(pr['backendService']['name'])), 'paths': jp.LIST_MATCHES([jp.STR_EQ(path) for path in pr['paths']])}) for pr in pm['pathRules']]
        path_matchers_spec = {'defaultService': jp.STR_EQ(self._get_bs_link(pm['defaultService']['name'])), 'pathRules': jp.LIST_MATCHES(path_rules_spec)}
        url_map_clause_builder.AND(ov_factory.value_list_contains(jp.DICT_MATCHES({'name': jp.STR_EQ(self.__lb_name), 'defaultService': jp.STR_EQ(self._get_bs_link(upsert['defaultService']['name'])), 'hostRules/hosts': jp.LIST_MATCHES([jp.STR_SUBSTR(host) for host in hr['hostPatterns']]), 'pathMatchers': jp.LIST_MATCHES([jp.DICT_MATCHES(path_matchers_spec)])})))
    port_string = '443-443'
    if (upsert['certificate'] == ''):
        port_string = ('%s-%s' % (upsert['portRange'], upsert['portRange']))
    contract_builder.new_clause_builder('Forwarding    Rule    Created', retryable_for_secs=30).list_resource('globalForwardingRules').EXPECT(ov_factory.value_list_contains(jp.DICT_MATCHES({'name': jp.STR_EQ(self.__lb_name), 'portRange': jp.STR_EQ(port_string)})))
    proxy_clause_builder = contract_builder.new_clause_builder('Target    Proxy    Created', retryable_for_secs=30)
    self._add_proxy_clause(upsert['certificate'], proxy_clause_builder)
