Revision c523b889

View differences:

include/Cluster.h
42 42
    }
43 43

  
44 44
    /**
45
     * Sets the SYSTEM_DS attribute
46
     *
47
     * @param ds_id The new system datastore
48
     */
49
    void set_ds_id(int ds_id)
50
    {
51
        system_ds = ds_id;
52
    }
53

  
54
    /**
55 45
     * Returns the DATASTORE_LOCATION for the hosts of the cluster. If not
56 46
     * defined that in oned.conf is returned.
57 47
     *
include/Datastore.h
57 57

  
58 58
    /**
59 59
     *  Return the string representation of a DatastoreType
60
     *    @param str_type string representing the DatastoreType
60
     *    @param str_type string representing the DatastoreTypr
61 61
     *    @return the DatastoreType (defaults to IMAGE_DS)
62 62
     */
63 63
    static DatastoreType str_to_type(string& str_type);
64 64

  
65 65
    /**
66
     *  Returns the DS type found in the string template
67
     *    @param str_template string template
68
     *    @return the DatastoreType (defaults to IMAGE_DS)
69
     */
70
    static DatastoreType type_in_template(string& str_template);
71

  
72
    /**
73 66
     * Function to print the Datastore object into a string in XML format
74 67
     *  @param xml the resulting XML string
75 68
     *  @return a reference to the generated string
include/RequestManagerUpdateTemplate.h
40 40

  
41 41
    /* -------------------------------------------------------------------- */
42 42

  
43
    virtual void request_execute(xmlrpc_c::paramList const& _paramList,
43
    void request_execute(xmlrpc_c::paramList const& _paramList,
44 44
                         RequestAttributes& att);
45 45
};
46 46

  
......
150 150
    };
151 151

  
152 152
    ~DatastoreUpdateTemplate(){};
153

  
154
    virtual void request_execute(xmlrpc_c::paramList const& _paramList,
155
                         RequestAttributes& att);
156 153
};
157 154

  
158 155
/* ------------------------------------------------------------------------- */
src/cli/one_helper/onecluster_helper.rb
96 96
    end
97 97

  
98 98
    def format_resource(cluster)
99
        str="%-18s: %-20s"
99
        str="%-15s: %-20s"
100 100
        str_h1="%-80s"
101 101

  
102 102
        CLIHelper.print_header(str_h1 % "CLUSTER #{cluster['ID']} INFORMATION")
103 103
        puts str % ["ID",   cluster.id.to_s]
104 104
        puts str % ["NAME", cluster.name]
105
        puts str % ["SYSTEM DATASTORE", cluster['SYSTEM_DS']]
106 105
        puts
107 106

  
108 107
        CLIHelper.print_header(str_h1 % "CLUSTER TEMPLATE", false)
src/datastore/Datastore.cc
122 122
/* ------------------------------------------------------------------------ */
123 123
/* ------------------------------------------------------------------------ */
124 124

  
125
Datastore::DatastoreType Datastore::type_in_template(string& str_template)
126
{
127
    string s_ds_type;
128
    string error_str;
129

  
130
    Template tmp_template;
131
    tmp_template.parse_str_or_xml(str_template, error_str);
132

  
133
    tmp_template.get("TYPE", s_ds_type);
134

  
135
    return Datastore::str_to_type(s_ds_type);
136
}
137

  
138
/* ------------------------------------------------------------------------ */
139
/* ------------------------------------------------------------------------ */
140

  
141 125
int Datastore::insert(SqlDB *db, string& error_str)
142 126
{
143 127
    int           rc;
......
447 431
    else
448 432
    {
449 433
        type = str_to_type(s_ds_type);
450
    }
451 434

  
452
    replace_template_attribute("TYPE", type_to_str(type));
435
        replace_template_attribute("TYPE", type_to_str(type));
436
    }
453 437

  
454 438
    if ( type == SYSTEM_DS )
455 439
    {
src/rm/RequestManagerUpdateTemplate.cc
70 70
    return;
71 71
}
72 72

  
73
/* ------------------------------------------------------------------------- */
74
/* ------------------------------------------------------------------------- */
75

  
76
void DatastoreUpdateTemplate::request_execute(
77
        xmlrpc_c::paramList const& paramList,
78
        RequestAttributes& att)
79
{
80
    int    rc;
81
    string error_str;
82

  
83
    int    oid  = xmlrpc_c::value_int(paramList.getInt(1));
84
    string tmpl = xmlrpc_c::value_string(paramList.getString(2));
85

  
86
    Datastore * object;
87

  
88
    if ( basic_authorization(oid, att) == false )
89
    {
90
        return;
91
    }
92

  
93
    object = static_cast<DatastorePool*>(pool)->get(oid,true);
94

  
95
    if ( object == 0 )
96
    {
97
        failure_response(NO_EXISTS,
98
                get_error(object_name(auth_object),oid),
99
                att);
100

  
101
        return;
102
    }
103

  
104
    Datastore::DatastoreType prev_type = object->get_type();
105
    Datastore::DatastoreType new_type = Datastore::type_in_template(tmpl);
106

  
107
    int cluster_id = object->get_cluster_id();
108

  
109
    if ( (prev_type == Datastore::SYSTEM_DS || new_type == Datastore::SYSTEM_DS) &&
110
        prev_type != new_type &&
111
        cluster_id != ClusterPool::NONE_CLUSTER_ID )
112
    {
113
        object->unlock();
114

  
115
        Cluster *cluster = Nebula::instance().get_clpool()->get(cluster_id, true);
116

  
117
        if ( cluster == 0 )
118
        {
119
            failure_response(NO_EXISTS,
120
                    get_error(object_name(PoolObjectSQL::CLUSTER),cluster_id),
121
                    att);
122

  
123
            return;
124
        }
125

  
126
        if ( new_type == Datastore::SYSTEM_DS )
127
        {
128
            if ( cluster->get_ds_id() == DatastorePool::SYSTEM_DS_ID )
129
            {
130
                // Cluster has a new system ds
131
                cluster->set_ds_id(oid);
132
            }
133
            else
134
            {
135
                ostringstream oss;
136
                oss << "Cannot change datastore type to "
137
                    << Datastore::type_to_str(Datastore::SYSTEM_DS)
138
                    << ". Cluster " << cluster_id
139
                    << " already contains the System Datastore "
140
                    << cluster->get_ds_id() << ".";
141

  
142
                failure_response(INTERNAL,
143
                        request_error(oss.str(),error_str),
144
                        att);
145

  
146
                cluster->unlock();
147

  
148
                return;
149
            }
150
        }
151
        else if ( cluster->get_ds_id() == oid )
152
        {
153
            // This was the cluster's system DS, now it must be set to '0'
154
            cluster->set_ds_id( DatastorePool::SYSTEM_DS_ID );
155
        }
156

  
157
        Nebula::instance().get_clpool()->update(cluster);
158
        cluster->unlock();
159

  
160
        object = static_cast<DatastorePool*>(pool)->get(oid,true);
161

  
162
        if ( object == 0 )
163
        {
164
            failure_response(NO_EXISTS,
165
                    get_error(object_name(auth_object),oid),
166
                    att);
167

  
168
            return;
169
        }
170
    }
171

  
172
    rc = object->replace_template(tmpl, error_str);
173

  
174
    if ( rc != 0 )
175
    {
176
        // TODO: rollback
177

  
178
        failure_response(INTERNAL,
179
                request_error("Cannot update template",error_str),
180
                att);
181
        object->unlock();
182

  
183
        return;
184
    }
185

  
186
    pool->update(object);
187

  
188
    object->unlock();
189

  
190
    success_response(oid, att);
191

  
192
    return;
193
}
194

  
195

  

Also available in: Unified diff