1818import pathlib
1919
2020from . import model , tag , utils , jasyncio
21+ from .url import URL
2122from .status import derive_status
2223from .annotationhelper import _get_annotations , _set_annotations
2324from .client import client
@@ -641,47 +642,16 @@ async def refresh(
641642 if switch is not None and revision is not None :
642643 raise ValueError ("switch and revision are mutually exclusive" )
643644
644- charms_facade = client .CharmsFacade .from_connection (self .connection )
645645 resources_facade = client .ResourcesFacade .from_connection (
646646 self .connection )
647647 app_facade = self ._facade ()
648648
649- charmstore = self .model .charmstore
650- charmstore_entity = None
651-
652- if switch is not None :
653- charm_url = switch
654- if not charm_url .startswith ('cs:' ):
655- charm_url = 'cs:' + charm_url
656- else :
657- charm_url = self .data ['charm-url' ]
658- charm_url = charm_url .rpartition ('-' )[0 ]
659- if revision is not None :
660- charm_url = "%s-%d" % (charm_url , revision )
661- else :
662- charmstore_entity = await charmstore .entity (charm_url ,
663- channel = channel )
664- charm_url = charmstore_entity ['Id' ]
665-
666- if charm_url == self .data ['charm-url' ]:
667- raise JujuError ('already running charm "%s"' % charm_url )
668-
669- # TODO (caner) : this needs to be revisited and updated with the charmhub stuff
670- origin = client .CharmOrigin (source = "charm-store" ,
671- risk = channel ,
672- )
673- # Update charm
674- await charms_facade .AddCharm (
675- url = charm_url ,
676- force = force ,
677- charm_origin = origin ,
678- )
649+ charm_url = self .data ['charm-url' ]
650+ charm_name = URL .parse (charm_url ).name
679651
680652 # Update resources
681- if not charmstore_entity :
682- charmstore_entity = await charmstore .entity (charm_url ,
683- channel = channel )
684- store_resources = charmstore_entity ['Meta' ]['resources' ]
653+ charmhub = self .model .charmhub
654+ charmhub_resources = await charmhub .list_resources (charm_name )
685655
686656 request_data = [client .Entity (self .tag )]
687657 response = await resources_facade .ListResources (entities = request_data )
@@ -691,7 +661,7 @@ async def refresh(
691661 }
692662
693663 resources_to_update = [
694- resource for resource in store_resources
664+ resource for resource in charmhub_resources
695665 if resource ['Name' ] not in existing_resources or
696666 existing_resources [resource ['Name' ]].origin != 'upload'
697667 ]
0 commit comments