Tuesday, 15 April 2014

c# - Openstack.Net SDK cannot access service with region -



c# - Openstack.Net SDK cannot access service with region -

using our own hardware, we've installed vanilla openstack components having problems accessing services other identity due part issue. code used follows called admin business relationship , admin tennant created...

public static void testaccess(string username, string password, string projectname, string projectid) { seek { uri baseurl = new uri(url_identity); cloudidentitywithproject projectcloudid = new cloudidentitywithproject(); projectcloudid.username = username; projectcloudid.password = password; projectcloudid.projectname = projectname; projectcloudid.projectid = new projectid(projectid); openstackidentityprovider idprovider = new openstackidentityprovider(baseurl, projectcloudid); useraccess useraccess = idprovider.authenticate(projectcloudid); ienumerable<extendedendpoint> eps = idprovider.listendpoints(useraccess.token.id); string reg = idprovider.defaultregion; // null servicecatalog[] scs = useraccess.servicecatalog; // list of regions regionlist = new list<string>(); foreach (servicecatalog sc in scs) { foreach (endpoint ep in sc.endpoints) { regionlist.add(ep.region); // 'regionone' in every case } } // seek stuff... foreach(string part in regionlist.distinct()) { // list of containers cloudfilesprovider cfp = new cloudfilesprovider(projectcloudid, idprovider); // line fails ienumerable<container> listofcontainers = cfp.listcontainers(region: region); foreach (container ctnr in listofcontainers) { console.writeline("container: {0}", ctnr.name); } cloudnetworksprovider cnp = new cloudnetworksprovider(identity: null, identityprovider: idprovider); ienumerable<cloudnetwork> networks = cnp.listnetworks(identity: null, region: region); foreach (cloudnetwork network in networks) { console.writeline("network[{0}] name: {1}", networkcount, network.label); console.writeline("network[{0}] id: {1}", networkcount, network.id); ++networkcount; } console.writeline("{0} networks listed.", networkcount); } } catch(exception ex) { throw; } }

the code fails @ phone call listcontainers(region: region) error... 'the user not have access requested service or region' if don't specify part error 'no part provided, service not provide region-independent endpoint, , there no default part set user's account'

we accessing our internal network @ moment regions aren't of import yet...

also of note when making phone call to...

cloudnetwork detail = cnp.shownetwork(networkguid, "regionone");

of network can see returns error 'the item not found or not exist.'

help , advice much appreciated.

i managed extend functionality of openstack.net sdk simply. code below extends include various functions tenant/project manipulations...

firstly, create newtenant container used pass info , webservices, i've set in same namespace others...

using newtonsoft.json; namespace net.openstack.core.domain { [jsonobject(memberserialization.optin)] public class newtenant { /// <summary> /// gets id new user. /// <note type="warning">the value of property not defined. not use.</note> /// </summary> [jsonproperty("id", defaultvaluehandling = defaultvaluehandling.include)] public string id { get; private set; } [jsonproperty("name")] public string name { get; private set; } [jsonproperty("description")] public string description { get; private set; } [jsonproperty("enabled")] public bool enabled { get; private set; } public newtenant(string name, string description, bool enabled = true) { name = name; description = description; enabled = enabled; } } }

now can create new request classes posting data...

using system; using newtonsoft.json; using net.openstack.core.domain; namespace net.openstack.core.request { [jsonobject(memberserialization.optin)] internal class addtenantrequest { [jsonproperty("tenant")] public newtenant tenant { get; private set; } public addtenantrequest(newtenant tenant) { if (tenant == null) throw new argumentnullexception("tenant"); tenant = tenant; } } }

now create response objects requests help retrieve data

using net.openstack.core.domain; using newtonsoft.json; namespace net.openstack.core.response { [jsonobject(memberserialization.optin)] internal class newtenantresponse { [jsonproperty("tenant")] public newtenant newtenant { get; private set; } } [jsonobject(memberserialization.optin)] internal class tenantresponse { [jsonproperty("tenant")] public tenant tenant { get; private set; } } }

now can create class inherits openstackidentityprovider additional functionality tenant/project manipulation want...

using system; using system.net; using jsistudios.simplerestservices.client; using net.openstack.core.domain; using net.openstack.core.request; using net.openstack.core.response; namespace net.openstack.core.providers { public class extendedopenstackidentityprovider : openstackidentityprovider { public extendedopenstackidentityprovider(uri urlbase) : base(urlbase) { } public extendedopenstackidentityprovider(uri urlbase, cloudidentity identity) : base(urlbase, identity) { } public extendedopenstackidentityprovider(uri urlbase, jsistudios.simplerestservices.client.irestservice restservice, net.openstack.core.caching.icache<useraccess> tokencache) : base(urlbase, restservice, tokencache) { } public extendedopenstackidentityprovider(uri urlbase, cloudidentity identity, jsistudios.simplerestservices.client.irestservice restservice, net.openstack.core.caching.icache<useraccess> tokencache) : base(urlbase, identity, restservice, tokencache) { } public newtenant addtenant(newtenant tenant, cloudidentity identity) { if (tenant == null) throw new argumentnullexception("tenant"); if (string.isnullorempty(tenant.name)) throw new argumentexception("tenant.name cannot null or empty"); if (tenant.id != null) throw new invalidoperationexception("tenant.id must null"); checkidentity(identity); var response = executerestrequest<newtenantresponse>(identity, new uri(urlbase, "/v2.0/tenants"), httpmethod.post, new addtenantrequest(tenant)); if (response == null || response.data == null) homecoming null; homecoming response.data.newtenant; } public tenant gettenant(string tenantid, cloudidentity identity) { if (tenantid == null) throw new argumentnullexception("tenantid"); checkidentity(identity); var urlpath = string.format("v2.0/tenants/{0}", tenantid); var response = executerestrequest<tenantresponse>(identity, new uri(urlbase, urlpath), httpmethod.get); if (response == null || response.data == null) homecoming null; homecoming response.data.tenant; } public bool deletetenant(string tenantid, cloudidentity identity) { if (tenantid == null) throw new argumentnullexception("tenantid"); if (string.isnullorempty(tenantid)) throw new argumentexception("tenantid cannot empty"); checkidentity(identity); var urlpath = string.format("v2.0/tenants/{0}", tenantid); var response = executerestrequest(identity, new uri(urlbase, urlpath), httpmethod.delete); if (response != null && response.statuscode == httpstatuscode.nocontent) homecoming true; homecoming false; } public bool addtenantuserrole(string tenantid, string userid, string roleid, cloudidentity identity) { if (tenantid == null) throw new argumentnullexception("tenantid"); if (string.isnullorempty(tenantid)) throw new argumentexception("tenantid cannot empty"); if (userid == null) throw new argumentnullexception("userid"); if (string.isnullorempty(userid)) throw new argumentexception("userid cannot empty"); if (roleid == null) throw new argumentnullexception("roleid"); if (string.isnullorempty(roleid)) throw new argumentexception("roleid cannot empty"); checkidentity(identity); var urlpath = string.format("v2.0/tenants/{0}/users/{1}/roles/os-ksadm/{2}", tenantid, userid, roleid); var response = executerestrequest(identity, new uri(urlbase, urlpath), httpmethod.put); if (response != null && response.statuscode == httpstatuscode.nocontent) homecoming true; homecoming false; } } }

i imagine functionality appear in github version soon, if not hope it's useful.

c# openstack rackspace-cloud keystone openstacknetsdk

No comments:

Post a Comment